You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ad...@apache.org on 2017/11/24 12:40:09 UTC
[27/39] ambari git commit: AMBARI-22297. getComponents returns
components of all services (adoroszlai)
AMBARI-22297. getComponents returns components of all services (adoroszlai)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/d9a4cabc
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/d9a4cabc
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/d9a4cabc
Branch: refs/heads/branch-feature-AMBARI-14714-blueprintv2
Commit: d9a4cabc2afce4ef94d58f9c66c78acb25e3dbcf
Parents: b49f78a
Author: Attila Doroszlai <ad...@hortonworks.com>
Authored: Tue Nov 21 12:33:40 2017 +0100
Committer: Doroszlai, Attila <ad...@hortonworks.com>
Committed: Fri Nov 24 13:30:46 2017 +0100
----------------------------------------------------------------------
.../ambari/server/topology/BlueprintV2Impl.java | 20 ++--
.../ambari/server/topology/ComponentV2.java | 9 ++
.../ambari/server/topology/HostGroupV2Impl.java | 5 +-
.../ambari/server/topology/ServiceGroup.java | 1 -
.../server/topology/BlueprintV2ImplTest.java | 108 +++++++++++++++++++
5 files changed, 131 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/d9a4cabc/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2Impl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2Impl.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2Impl.java
index 66ca85d..b27ab79 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2Impl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintV2Impl.java
@@ -222,22 +222,27 @@ public class BlueprintV2Impl implements BlueprintV2 {
@Override
@JsonIgnore
public Collection<ComponentV2> getComponents(Service service) {
- return getHostGroupsForService(service.getId()).stream().flatMap(
- hg -> hg.getComponents().stream()).
- collect(toList());
+ return getHostGroupsForService(service.getId()).stream()
+ .flatMap(hg -> hg.getComponents().stream())
+ .filter(c -> c.getServiceId().equals(service.getId()))
+ .collect(toList());
}
@Override
@JsonIgnore
public Collection<ComponentV2> getComponentsByType(Service service, String componentType) {
- return getComponents(service).stream().filter(
- compnoent -> compnoent.getType().equalsIgnoreCase(componentType)).collect(toList());
+ return getComponents(service).stream()
+ .filter(c -> c.getType().equalsIgnoreCase(componentType))
+ .collect(toList());
}
@Override
@JsonIgnore
public Collection<ComponentV2> getComponents(ServiceId serviceId) {
- return getHostGroupsForService(serviceId).stream().flatMap(hg -> hg.getComponents().stream()).collect(toSet());
+ return getHostGroupsForService(serviceId).stream()
+ .flatMap(hg -> hg.getComponents().stream())
+ .filter(c -> c.getServiceId().equals(serviceId))
+ .collect(toSet());
}
@Override
@@ -361,8 +366,7 @@ public class BlueprintV2Impl implements BlueprintV2 {
this.services = getAllServiceIds().stream().collect(toMap(
Function.identity(),
serviceId -> {
- ServiceGroup sg = getServiceGroup(serviceId.getServiceGroup());
- Service service = null != sg ? sg.getServiceByName(serviceId.getName()) : null;
+ Service service = getServiceGroup(serviceId.getServiceGroup()).getServiceByName(serviceId.getName());
if (null == service) {
throw new IllegalStateException("Cannot find service for service id: " + serviceId);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/d9a4cabc/ambari-server/src/main/java/org/apache/ambari/server/topology/ComponentV2.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/ComponentV2.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/ComponentV2.java
index 42158f4..8a488b6a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/ComponentV2.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/ComponentV2.java
@@ -140,4 +140,13 @@ public class ComponentV2 implements Configurable {
public void setService(Service service) {
this.service = service;
}
+
+ @Override
+ public String toString() {
+ return "Component{" +
+ "serviceGroup=" + serviceId.getServiceGroup() + " " +
+ "service=" + serviceId.getName() + " " +
+ "component=" + type +
+ "}";
+ }
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/d9a4cabc/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2Impl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2Impl.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2Impl.java
index ff82ecf..2d6abf7 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2Impl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2Impl.java
@@ -20,7 +20,6 @@ package org.apache.ambari.server.topology;
import static java.util.stream.Collectors.toList;
import java.util.Collection;
-import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
@@ -34,7 +33,7 @@ public class HostGroupV2Impl implements HostGroupV2, Configurable {
private String name;
private String blueprintName;
- private List<ComponentV2> components;
+ private Collection<ComponentV2> components;
private Set<ServiceId> serviceIds;
private Configuration configuration;
private String cardinality;
@@ -148,7 +147,7 @@ public class HostGroupV2Impl implements HostGroupV2, Configurable {
this.blueprintName = blueprintName;
}
- public void setComponents(List<ComponentV2> components) {
+ public void setComponents(Collection<ComponentV2> components) {
this.components = components;
this.containsMasterComponent = components.stream().anyMatch(ComponentV2::isMasterComponent);
this.serviceIds = components.stream().map(ComponentV2::getServiceId).collect(Collectors.toSet());
http://git-wip-us.apache.org/repos/asf/ambari/blob/d9a4cabc/ambari-server/src/main/java/org/apache/ambari/server/topology/ServiceGroup.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/ServiceGroup.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/ServiceGroup.java
index a5ba2d4..c680747 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/ServiceGroup.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/ServiceGroup.java
@@ -79,7 +79,6 @@ public class ServiceGroup {
services.forEach(s -> s.setServiceGroup(this));
this.servicesByName = services.stream().collect(Collectors.toMap(Service::getName, Function.identity()));
this.servicesByType = Multimaps.index(services, Service::getType);
- services.forEach(s -> s.setServiceGroup(this));
}
public void setConfiguration(Configuration configuration) {
http://git-wip-us.apache.org/repos/asf/ambari/blob/d9a4cabc/ambari-server/src/test/java/org/apache/ambari/server/topology/BlueprintV2ImplTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/topology/BlueprintV2ImplTest.java b/ambari-server/src/test/java/org/apache/ambari/server/topology/BlueprintV2ImplTest.java
new file mode 100644
index 0000000..8efa53f
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/topology/BlueprintV2ImplTest.java
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.server.topology;
+
+import static java.util.stream.Collectors.toSet;
+import static org.junit.Assert.assertEquals;
+
+import java.util.Collections;
+import java.util.Set;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.collect.Sets;
+
+public class BlueprintV2ImplTest {
+
+ private ServiceGroup serviceGroup;
+ private HostGroupV2Impl hostGroup;
+
+ @Before
+ public void setUp() throws Exception {
+ serviceGroup = new ServiceGroup();
+ serviceGroup.setName("CORE");
+
+ hostGroup = new HostGroupV2Impl();
+ hostGroup.setName("node");
+ hostGroup.setBlueprintName("blue");
+ hostGroup.setCardinality("1");
+ }
+
+ @Test
+ public void getComponentsForServiceId() {
+ Set<ComponentV2> components = Sets.newHashSet(
+ createZookeeperServer(serviceGroup, "ZK1"),
+ createZookeeperServer(serviceGroup, "ZK2")
+ );
+ BlueprintV2Impl bp = createBlueprint(components);
+
+ Set<ServiceId> serviceIds = serviceGroup.getServices().stream()
+ .map(Service::getId)
+ .collect(toSet());
+ for (ServiceId serviceId : serviceIds) {
+ Set<ComponentV2> expectedComponents = components.stream()
+ .filter(c -> c.getServiceId().equals(serviceId))
+ .collect(toSet());
+ assertEquals(expectedComponents, Sets.newHashSet(bp.getComponents(serviceId)));
+ }
+ }
+
+ @Test
+ public void getComponentsForService() {
+ Set<ComponentV2> components = Sets.newHashSet(
+ createZookeeperServer(serviceGroup, "ZK1"),
+ createZookeeperServer(serviceGroup, "ZK2")
+ );
+ BlueprintV2Impl bp = createBlueprint(components);
+
+ for (Service service : serviceGroup.getServices()) {
+ Set<ComponentV2> expectedComponents = components.stream()
+ .filter(c -> c.getService().equals(service))
+ .collect(toSet());
+ assertEquals(expectedComponents, Sets.newHashSet(bp.getComponents(service)));
+ }
+ }
+
+ private BlueprintV2Impl createBlueprint(Set<ComponentV2> components) {
+ Set<Service> services = components.stream()
+ .map(ComponentV2::getService)
+ .collect(toSet());
+ serviceGroup.setServices(services);
+ hostGroup.setComponents(components);
+
+ BlueprintV2Impl bp = new BlueprintV2Impl();
+ bp.setHostGroups(Collections.singleton(hostGroup));
+ bp.setServiceGroups(Collections.singleton(serviceGroup));
+ bp.postDeserialization();
+ return bp;
+ }
+
+ private ComponentV2 createZookeeperServer(ServiceGroup serviceGroup, String serviceName) {
+ Service service = new Service();
+ service.setName(serviceName);
+ service.setServiceGroup(serviceGroup);
+ service.setType("ZOOKEEPER");
+ ComponentV2 component = new ComponentV2();
+ component.setType("ZOOKEEPER_SERVER");
+ component.setService(service);
+ component.setServiceGroup(serviceGroup.getName());
+ component.setServiceName(serviceName);
+ return component;
+ }
+}