ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adorosz...@apache.org
Subject [35/46] ambari git commit: AMBARI-22253. Make ScaleClusterRequestTest, TopologyManagerTest work (adoroszlai)
Date Fri, 08 Dec 2017 19:26:35 GMT
AMBARI-22253. Make ScaleClusterRequestTest, TopologyManagerTest work (adoroszlai)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/d7610d11
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/d7610d11
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/d7610d11

Branch: refs/heads/branch-feature-AMBARI-14714-blueprintv2
Commit: d7610d11a277bb7435e2569e68d1eaf8e29dc21c
Parents: c8f4645
Author: Doroszlai, Attila <adoroszlai@hortonworks.com>
Authored: Mon Dec 4 18:20:27 2017 +0100
Committer: Doroszlai, Attila <adoroszlai@hortonworks.com>
Committed: Fri Dec 8 20:24:25 2017 +0100

----------------------------------------------------------------------
 .../ambari/server/topology/AmbariContext.java   |   6 +-
 .../ambari/server/topology/BlueprintV2Impl.java |   2 +-
 .../server/topology/ClusterTopologyImpl.java    |   8 +-
 .../ambari/server/topology/HostGroupV2.java     |   6 +-
 .../ambari/server/topology/HostGroupV2Impl.java |  15 ++-
 .../tasks/PersistHostResourcesTask.java         |  12 +-
 .../internal/ScaleClusterRequestTest.java       |  28 ++---
 .../server/topology/TopologyManagerTest.java    | 114 +++++++++++--------
 8 files changed, 105 insertions(+), 86 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/d7610d11/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java
b/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java
index a12f61b..f63c121 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java
@@ -302,7 +302,7 @@ public class AmbariContext {
     }
   }
 
-  public void createAmbariHostResources(long  clusterId, String hostName, Map<Service,
Collection<ComponentV2>> components)  {
+  public void createAmbariHostResources(long clusterId, String hostName, Map<Service,
? extends Iterable<ComponentV2>> components)  {
     Host host;
     try {
       host = getController().getClusters().getHost(hostName);
@@ -312,7 +312,7 @@ public class AmbariContext {
           "Unable to obtain host instance '%s' when persisting host resources", hostName));
     }
 
-    Cluster cluster = null;
+    Cluster cluster;
     try {
       cluster = getController().getClusters().getClusterById(clusterId);
     } catch (AmbariException e) {
@@ -336,7 +336,7 @@ public class AmbariContext {
 
     final Set<ServiceComponentHostRequest> requests = new HashSet<>();
 
-    for (Map.Entry<Service, Collection<ComponentV2>> entry : components.entrySet())
{
+    for (Map.Entry<Service, ? extends Iterable<ComponentV2>> entry : components.entrySet())
{
       Service service = entry.getKey();
       for (ComponentV2 component : entry.getValue()) {
         //todo: handle this in a generic manner.  These checks are all over the code

http://git-wip-us.apache.org/repos/asf/ambari/blob/d7610d11/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 224e6b7..0fef526 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
@@ -248,7 +248,7 @@ public class BlueprintV2Impl implements BlueprintV2 {
   @Override
   @JsonIgnore
   public Collection<HostGroupV2> getHostGroupsForService(ServiceId serviceId) {
-    return getHostGroups().values().stream().filter(hg -> !hg.getComponentsByServiceId(serviceId).isEmpty()).collect(toList());
+    return getHostGroups().values().stream().filter(hg -> !hg.getComponentsForService(serviceId).isEmpty()).collect(toList());
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/ambari/blob/d7610d11/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopologyImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopologyImpl.java
b/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopologyImpl.java
index 33673be..e32551a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopologyImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopologyImpl.java
@@ -32,6 +32,7 @@ import java.util.Map;
 import java.util.Set;
 
 import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.controller.AmbariManagementController;
 import org.apache.ambari.server.controller.RequestStatusResponse;
 import org.apache.ambari.server.controller.internal.ConfigurationContext;
 import org.apache.ambari.server.controller.internal.ProvisionAction;
@@ -408,8 +409,11 @@ public class ClusterTopologyImpl implements ClusterTopology {
   }
 
   private static Map<String, String> getDefaultClusterSettings() { // TODO temporary
-    return AmbariContext.getController().getAmbariMetaInfo().getClusterProperties().stream()
-      .collect(toMap(PropertyInfo::getName, PropertyInfo::getValue));
+    AmbariManagementController controller = AmbariContext.getController();
+    return controller != null
+      ? controller.getAmbariMetaInfo().getClusterProperties().stream()
+        .collect(toMap(PropertyInfo::getName, PropertyInfo::getValue))
+      : Collections.emptyMap();
   }
 
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/d7610d11/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2.java
b/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2.java
index f08085f..9ac7cb1 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/HostGroupV2.java
@@ -19,6 +19,7 @@
 package org.apache.ambari.server.topology;
 
 import java.util.Collection;
+import java.util.List;
 import java.util.Map;
 import java.util.regex.Pattern;
 
@@ -61,6 +62,7 @@ public interface HostGroupV2 {
    * @return collection of component instances
    */
   Collection<ComponentV2> getComponents();
+  Map<Service, List<ComponentV2>> getComponentsByService();
 
   /**
    * Get all of the host group component names
@@ -88,9 +90,9 @@ public interface HostGroupV2 {
    *
    * @return collection of component names for the specified service; will not return null
    */
-  Collection<ComponentV2> getComponentsByServiceId(ServiceId serviceId);
+  Collection<ComponentV2> getComponentsForService(ServiceId serviceId);
 
-  Collection<ComponentV2> getComponents(Service serviceId);
+  Collection<ComponentV2> getComponentsForService(Service service);
 
   /**
    * Determine if the host group contains a master component.

http://git-wip-us.apache.org/repos/asf/ambari/blob/d7610d11/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 2d6abf7..918b3b8 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
@@ -17,9 +17,11 @@
  */
 package org.apache.ambari.server.topology;
 
+import static java.util.stream.Collectors.groupingBy;
 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;
@@ -66,6 +68,13 @@ public class HostGroupV2Impl implements HostGroupV2, Configurable {
 
   @Override
   @JsonIgnore
+  public Map<Service, List<ComponentV2>> getComponentsByService() {
+    return components.stream()
+      .collect(groupingBy(ComponentV2::getService));
+  }
+
+  @Override
+  @JsonIgnore
   public Collection<String> getComponentNames() {
     return components.stream()
       .map(ComponentV2::getName)
@@ -82,12 +91,12 @@ public class HostGroupV2Impl implements HostGroupV2, Configurable {
   }
 
   @Override
-  public Collection<ComponentV2> getComponents(Service service) {
-    return getComponentsByServiceId(service.getId());
+  public Collection<ComponentV2> getComponentsForService(Service service) {
+    return getComponentsForService(service.getId());
   }
 
   @Override
-  public Collection<ComponentV2> getComponentsByServiceId(ServiceId serviceId) {
+  public Collection<ComponentV2> getComponentsForService(ServiceId serviceId) {
     return components.stream().filter(c -> c.getServiceId().equals(serviceId)).collect(toList());
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/d7610d11/ambari-server/src/main/java/org/apache/ambari/server/topology/tasks/PersistHostResourcesTask.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/tasks/PersistHostResourcesTask.java
b/ambari-server/src/main/java/org/apache/ambari/server/topology/tasks/PersistHostResourcesTask.java
index 00eb706..0a7d14c 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/tasks/PersistHostResourcesTask.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/tasks/PersistHostResourcesTask.java
@@ -17,9 +17,7 @@
  */
 package org.apache.ambari.server.topology.tasks;
 
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.ambari.server.topology.ClusterTopology;
@@ -52,12 +50,8 @@ public class PersistHostResourcesTask extends TopologyHostTask  {
     LOG.info("HostRequest: Executing RESOURCE_CREATION task for host: {}", hostRequest.getHostName());
 
     HostGroupV2 group = hostRequest.getHostGroup();
-    Map<Service, Collection<ComponentV2>> serviceComponents = new HashMap<>();
-    for (Service service : group.getServices()) {
-      serviceComponents.put(service, new HashSet(group.getComponents(service)));
-    }
-    clusterTopology.getAmbariContext().createAmbariHostResources(hostRequest.getClusterId(),
-      hostRequest.getHostName(), serviceComponents);
+    Map<Service, List<ComponentV2>> serviceComponents = group.getComponentsByService();
+    clusterTopology.getAmbariContext().createAmbariHostResources(hostRequest.getClusterId(),
hostRequest.getHostName(), serviceComponents);
 
     LOG.info("HostRequest: Exiting RESOURCE_CREATION task for host: {}", hostRequest.getHostName());
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/d7610d11/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ScaleClusterRequestTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ScaleClusterRequestTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ScaleClusterRequestTest.java
index b1e52cc..17a3bbb 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ScaleClusterRequestTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ScaleClusterRequestTest.java
@@ -30,7 +30,6 @@ import static org.powermock.api.easymock.PowerMock.createStrictMock;
 import static org.powermock.api.easymock.PowerMock.replay;
 import static org.powermock.api.easymock.PowerMock.reset;
 
-import java.lang.reflect.Field;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
@@ -39,11 +38,11 @@ import java.util.Map;
 import java.util.Set;
 
 import org.apache.ambari.server.controller.spi.ResourceProvider;
-import org.apache.ambari.server.topology.Blueprint;
-import org.apache.ambari.server.topology.BlueprintFactory;
+import org.apache.ambari.server.topology.BlueprintV2;
+import org.apache.ambari.server.topology.BlueprintV2Factory;
 import org.apache.ambari.server.topology.Configuration;
-import org.apache.ambari.server.topology.HostGroup;
 import org.apache.ambari.server.topology.HostGroupInfo;
+import org.apache.ambari.server.topology.HostGroupV2;
 import org.apache.ambari.server.topology.InvalidTopologyTemplateException;
 import org.apache.ambari.server.topology.TopologyRequest;
 import org.junit.After;
@@ -53,7 +52,6 @@ import org.junit.Test;
 /**
  * Unit tests for ScaleClusterRequest.
  */
-@SuppressWarnings("unchecked")
 public class ScaleClusterRequestTest {
 
   private static final String CLUSTER_NAME = "cluster_name";
@@ -65,22 +63,16 @@ public class ScaleClusterRequestTest {
   private static final String GROUP3_NAME = "group3";
   private static final String PREDICATE = "test/prop=foo";
 
-  private static final BlueprintFactory blueprintFactory = createStrictMock(BlueprintFactory.class);
-  private static final Blueprint blueprint = createNiceMock(Blueprint.class);
+  private static final BlueprintV2Factory blueprintFactory = createStrictMock(BlueprintV2Factory.class);
+  private static final BlueprintV2 blueprint = createNiceMock(BlueprintV2.class);
   private static final ResourceProvider hostResourceProvider = createMock(ResourceProvider.class);
-  private static final HostGroup hostGroup1 = createNiceMock(HostGroup.class);
-  private static final Configuration blueprintConfig = new Configuration(
-      Collections.emptyMap(),
-      Collections.emptyMap());
+  private static final HostGroupV2 hostGroup1 = createNiceMock(HostGroupV2.class);
+  private static final Configuration blueprintConfig = Configuration.createEmpty();
 
   @Before
   public void setUp() throws Exception {
-    ScaleClusterRequest.init(null);
-    // set host resource provider field
-    Class clazz = BaseClusterRequest.class;
-    Field f = clazz.getDeclaredField("hostResourceProvider");
-    f.setAccessible(true);
-    f.set(null, hostResourceProvider);
+    BaseClusterRequest.setBlueprintFactory(blueprintFactory);
+    BaseClusterRequest.setHostResourceProvider(hostResourceProvider);
 
     expect(blueprintFactory.getBlueprint(BLUEPRINT_NAME)).andReturn(blueprint).anyTimes();
     expect(blueprint.getConfiguration()).andReturn(blueprintConfig).anyTimes();
@@ -304,7 +296,7 @@ public class ScaleClusterRequestTest {
   }
 
 
-  @Test(expected = InvalidTopologyTemplateException.class)
+  @Test(expected = IllegalArgumentException.class)
   public void testInvalidPredicateProperty() throws Exception {
     reset(hostResourceProvider);
     // checkPropertyIds() returns invalid property names

http://git-wip-us.apache.org/repos/asf/ambari/blob/d7610d11/ambari-server/src/test/java/org/apache/ambari/server/topology/TopologyManagerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/topology/TopologyManagerTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/topology/TopologyManagerTest.java
index e370df6..152a257 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/topology/TopologyManagerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/topology/TopologyManagerTest.java
@@ -20,6 +20,7 @@ package org.apache.ambari.server.topology;
 
 import static org.easymock.EasyMock.anyObject;
 import static org.easymock.EasyMock.capture;
+import static org.easymock.EasyMock.createNiceMock;
 import static org.easymock.EasyMock.eq;
 import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.expectLastCall;
@@ -49,11 +50,11 @@ import org.apache.ambari.server.controller.ClusterRequest;
 import org.apache.ambari.server.controller.ConfigurationRequest;
 import org.apache.ambari.server.controller.RequestStatusResponse;
 import org.apache.ambari.server.controller.ShortTaskStatus;
+import org.apache.ambari.server.controller.StackV2;
 import org.apache.ambari.server.controller.internal.BaseClusterRequest;
 import org.apache.ambari.server.controller.internal.HostResourceProvider;
 import org.apache.ambari.server.controller.internal.ProvisionClusterRequest;
 import org.apache.ambari.server.controller.internal.ScaleClusterRequest;
-import org.apache.ambari.server.controller.internal.Stack;
 import org.apache.ambari.server.controller.spi.ClusterController;
 import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.controller.spi.ResourceProvider;
@@ -116,7 +117,7 @@ public class TopologyManagerTest {
   private BlueprintV2 blueprint;
 
   @Mock(type = MockType.NICE)
-  private Stack stack;
+  private StackV2 stack;
 
   @Mock(type = MockType.NICE)
   private ProvisionClusterRequest request;
@@ -167,21 +168,14 @@ public class TopologyManagerTest {
   @Mock
   private TopologyValidatorService topologyValidatorService;
 
-  private final Configuration stackConfig = new Configuration(new HashMap<>(),
-    new HashMap<>());
-  private final Configuration bpConfiguration = new Configuration(new HashMap<>(),
-    new HashMap<>(), stackConfig);
-  private final Configuration topoConfiguration = new Configuration(new HashMap<>(),
-    new HashMap<>(), bpConfiguration);
-  private final Configuration bpGroup1Config = new Configuration(new HashMap<>(),
-    new HashMap<>(), bpConfiguration);
-  private final Configuration bpGroup2Config = new Configuration(new HashMap<>(),
-    new HashMap<>(), bpConfiguration);
+  private final Configuration stackConfig = Configuration.createEmpty();
+  private final Configuration bpConfiguration = new Configuration(new HashMap<>(),
new HashMap<>(), stackConfig);
+  private final Configuration topoConfiguration = new Configuration(new HashMap<>(),
new HashMap<>(), bpConfiguration);
+  private final Configuration bpGroup1Config = new Configuration(new HashMap<>(), new
HashMap<>(), bpConfiguration);
+  private final Configuration bpGroup2Config = new Configuration(new HashMap<>(), new
HashMap<>(), bpConfiguration);
   //todo: topo config hierarchy is wrong: bpGroupConfigs should extend topo cluster config
-  private final Configuration topoGroup1Config = new Configuration(new HashMap<>(),
-    new HashMap<>(), bpGroup1Config);
-  private final Configuration topoGroup2Config = new Configuration(new HashMap<>(),
-    new HashMap<>(), bpGroup2Config);
+  private final Configuration topoGroup1Config = new Configuration(new HashMap<>(),
new HashMap<>(), bpGroup1Config);
+  private final Configuration topoGroup2Config = new Configuration(new HashMap<>(),
new HashMap<>(), bpGroup2Config);
 
   private HostGroupInfo group1Info = new HostGroupInfo("group1");
   private HostGroupInfo group2Info = new HostGroupInfo("group2");
@@ -209,6 +203,10 @@ public class TopologyManagerTest {
   private Capture<Map<String, Object>> configRequestPropertiesCapture3;
   private Capture<ClusterRequest> updateClusterConfigRequestCapture;
   private Capture<Runnable> updateConfigTaskCapture;
+  private final ServiceId serviceId1 = ServiceId.of("service1", "CORE");
+  private final ServiceId serviceId2 = ServiceId.of("service2", "CORE");
+  private final Service service1 = createNiceMock(Service.class);
+  private final Service service2 = createNiceMock(Service.class);
 
   @Before
   public void setup() throws Exception {
@@ -237,8 +235,6 @@ public class TopologyManagerTest {
 
     Map<String, HostGroupV2> groupMap = ImmutableMap.of("group1", group1, "group2",
group2);
 
-    ServiceId serviceId1 = ServiceId.of("service1", "CORE");
-    ServiceId serviceId2 = ServiceId.of("service2", "CORE");
     component1.setType("component1");
     component1.setServiceGroup(serviceId1.getServiceGroup());
     component1.setServiceName(serviceId1.getName());
@@ -260,25 +256,10 @@ public class TopologyManagerTest {
     group2ServiceComponents.put("service1", Collections.singleton(component3));
     group2ServiceComponents.put("service2", Collections.singleton(component4));
 
-    expect(blueprint.getHostGroup("group1")).andReturn(group1).anyTimes();
-    expect(blueprint.getHostGroup("group2")).andReturn(group2).anyTimes();
-    expect(blueprint.getComponents(serviceId1)).andReturn(Arrays.asList(component1, component3)).anyTimes();
-    expect(blueprint.getComponents(serviceId2)).andReturn(Arrays.asList(component2, component4)).anyTimes();
-    expect(blueprint.getConfiguration()).andReturn(bpConfiguration).anyTimes();
-    expect(blueprint.getHostGroups()).andReturn(groupMap).anyTimes();
-    expect(blueprint.getHostGroupsForComponent(component1)).andReturn(Collections.singleton(group1)).anyTimes();
-    expect(blueprint.getHostGroupsForComponent(component2)).andReturn(Collections.singleton(group1)).anyTimes();
-    expect(blueprint.getHostGroupsForComponent(component3)).andReturn(Arrays.asList(group1,
group2)).anyTimes();
-    expect(blueprint.getHostGroupsForComponent(component4)).andReturn(Collections.singleton(group2)).anyTimes();
-    expect(blueprint.getHostGroupsForService(serviceId1)).andReturn(Arrays.asList(group1,
group2)).anyTimes();
-    expect(blueprint.getHostGroupsForService(serviceId2)).andReturn(Arrays.asList(group1,
group2)).anyTimes();
-    expect(blueprint.getName()).andReturn(BLUEPRINT_NAME).anyTimes();
-    expect(blueprint.getAllServiceNames()).andReturn(Arrays.asList("service1", "service2")).anyTimes();
-    expect(blueprint.getRepositorySettings()).andReturn(new ArrayList<>()).anyTimes();
-    // don't expect toEntity()
-
     expect(stack.getAllConfigurationTypes("service1")).andReturn(Arrays.asList("service1-site",
"service1-env")).anyTimes();
     expect(stack.getAllConfigurationTypes("service2")).andReturn(Arrays.asList("service2-site",
"service2-env")).anyTimes();
+    expect(stack.getConfigurationTypes("service1")).andReturn(Arrays.asList("service1-site",
"service1-env")).anyTimes();
+    expect(stack.getConfigurationTypes("service2")).andReturn(Arrays.asList("service2-site",
"service2-env")).anyTimes();
     expect(stack.getAutoDeployInfo("component1")).andReturn(null).anyTimes();
     expect(stack.getAutoDeployInfo("component2")).andReturn(null).anyTimes();
     expect(stack.getAutoDeployInfo("component3")).andReturn(null).anyTimes();
@@ -295,10 +276,47 @@ public class TopologyManagerTest {
     expect(stack.getConfiguration()).andReturn(stackConfig).anyTimes();
     expect(stack.getName()).andReturn(STACK_NAME).anyTimes();
     expect(stack.getVersion()).andReturn(STACK_VERSION).anyTimes();
-    expect(stack.getExcludedConfigurationTypes("service1")).andReturn(new HashSet<String>()).anyTimes();
-    expect(stack.getExcludedConfigurationTypes("service2")).andReturn(new HashSet<String>()).anyTimes();
+    expect(stack.getExcludedConfigurationTypes("service1")).andReturn(new HashSet<>()).anyTimes();
+    expect(stack.getExcludedConfigurationTypes("service2")).andReturn(new HashSet<>()).anyTimes();
+
+    Configuration c1 = Configuration.createEmpty();
+    expect(service1.getId()).andReturn(serviceId1).anyTimes();
+    expect(service1.getName()).andReturn(serviceId1.getName()).anyTimes();
+    expect(service1.getServiceGroupId()).andReturn(serviceId1.getServiceGroup()).anyTimes();
+    expect(service1.getServiceGroupName()).andReturn(serviceId1.getServiceGroup()).anyTimes();
+    expect(service1.getStack()).andReturn(stack).anyTimes();
+    expect(service1.getType()).andReturn("service1").anyTimes();
+    expect(service1.getConfiguration()).andReturn(c1).anyTimes();
+    Configuration c2 = Configuration.createEmpty();
+    expect(service2.getName()).andReturn(serviceId2.getName()).anyTimes();
+    expect(service2.getServiceGroupId()).andReturn(serviceId2.getServiceGroup()).anyTimes();
+    expect(service2.getServiceGroupName()).andReturn(serviceId2.getServiceGroup()).anyTimes();
+    expect(service2.getStack()).andReturn(stack).anyTimes();
+    expect(service2.getType()).andReturn("service2").anyTimes();
+    expect(service2.getConfiguration()).andReturn(c2).anyTimes();
+
+    expect(blueprint.getHostGroup("group1")).andReturn(group1).anyTimes();
+    expect(blueprint.getHostGroup("group2")).andReturn(group2).anyTimes();
+    expect(blueprint.getComponents(serviceId1)).andReturn(Arrays.asList(component1, component3)).anyTimes();
+    expect(blueprint.getComponents(serviceId2)).andReturn(Arrays.asList(component2, component4)).anyTimes();
+    expect(blueprint.getConfiguration()).andReturn(bpConfiguration).anyTimes();
+    expect(blueprint.getHostGroups()).andReturn(groupMap).anyTimes();
+    expect(blueprint.getHostGroupsForComponent(component1)).andReturn(Collections.singleton(group1)).anyTimes();
+    expect(blueprint.getHostGroupsForComponent(component2)).andReturn(Collections.singleton(group1)).anyTimes();
+    expect(blueprint.getHostGroupsForComponent(component3)).andReturn(Arrays.asList(group1,
group2)).anyTimes();
+    expect(blueprint.getHostGroupsForComponent(component4)).andReturn(Collections.singleton(group2)).anyTimes();
+    expect(blueprint.getHostGroupsForService(serviceId1)).andReturn(Arrays.asList(group1,
group2)).anyTimes();
+    expect(blueprint.getHostGroupsForService(serviceId2)).andReturn(Arrays.asList(group1,
group2)).anyTimes();
+    expect(blueprint.getName()).andReturn(BLUEPRINT_NAME).anyTimes();
+    expect(blueprint.getAllServiceNames()).andReturn(Arrays.asList("service1", "service2")).anyTimes();
+    expect(blueprint.getAllServices()).andReturn(Arrays.asList(service1, service2)).anyTimes();
+    expect(blueprint.getRepositorySettings()).andReturn(new ArrayList<>()).anyTimes();
+    expect(blueprint.getServicesByType("HDFS")).andReturn(Collections.emptyList()).anyTimes();
+    expect(blueprint.isValidConfigType("cluster-env")).andReturn(true).anyTimes();
+    expect(blueprint.getStacks()).andReturn(Collections.singleton(stack)).anyTimes();
+    // don't expect toEntity()
 
-    expect(request.getBlueprint()).andReturn(null).anyTimes();
+    expect(request.getBlueprint()).andReturn(blueprint).anyTimes();
     expect(request.getClusterId()).andReturn(CLUSTER_ID).anyTimes();
     expect(request.getClusterName()).andReturn(CLUSTER_NAME).anyTimes();
     expect(request.getDescription()).andReturn("Provision Cluster Test").anyTimes();
@@ -311,8 +329,8 @@ public class TopologyManagerTest {
     expect(group1.getCardinality()).andReturn("test cardinality").anyTimes();
     expect(group1.containsMasterComponent()).andReturn(true).anyTimes();
     expect(group1.getComponents()).andReturn(group1Components).anyTimes();
-    expect(group1.getComponentsByServiceId(serviceId1)).andReturn(group1ServiceComponents.get("service1")).anyTimes();
-    expect(group1.getComponentsByServiceId(serviceId2)).andReturn(group1ServiceComponents.get("service1")).anyTimes();
+    expect(group1.getComponentsForService(serviceId1)).andReturn(group1ServiceComponents.get("service1")).anyTimes();
+    expect(group1.getComponentsForService(serviceId2)).andReturn(group1ServiceComponents.get("service1")).anyTimes();
     expect(group1.getConfiguration()).andReturn(topoGroup1Config).anyTimes();
     expect(group1.getName()).andReturn("group1").anyTimes();
     expect(group1.getServiceNames()).andReturn(Arrays.asList("service1", "service2")).anyTimes();
@@ -321,8 +339,8 @@ public class TopologyManagerTest {
     expect(group2.getCardinality()).andReturn("test cardinality").anyTimes();
     expect(group2.containsMasterComponent()).andReturn(false).anyTimes();
     expect(group2.getComponents()).andReturn(group2Components).anyTimes();
-    expect(group2.getComponentsByServiceId(serviceId1)).andReturn(group2ServiceComponents.get("service1")).anyTimes();
-    expect(group2.getComponentsByServiceId(serviceId2)).andReturn(group2ServiceComponents.get("service2")).anyTimes();
+    expect(group2.getComponentsForService(serviceId1)).andReturn(group2ServiceComponents.get("service1")).anyTimes();
+    expect(group2.getComponentsForService(serviceId2)).andReturn(group2ServiceComponents.get("service2")).anyTimes();
     expect(group2.getConfiguration()).andReturn(topoGroup2Config).anyTimes();
     expect(group2.getName()).andReturn("group2").anyTimes();
     expect(group2.getServiceNames()).andReturn(Arrays.asList("service1", "service2")).anyTimes();
@@ -388,12 +406,12 @@ public class TopologyManagerTest {
   @After
   public void tearDown() {
     PowerMock.verify(System.class);
-    verify(blueprint, stack, request, group1, group2, ambariContext, logicalRequestFactory,
+    verify(blueprint, stack, request, group1, group2, ambariContext, logicalRequestFactory,
service1, service2,
         logicalRequest, configurationRequest, configurationRequest2, configurationRequest3,
         requestStatusResponse, executor, persistedState, clusterTopologyMock, mockFuture,
settingDAO);
 
     PowerMock.reset(System.class);
-    reset(blueprint, stack, request, group1, group2, ambariContext, logicalRequestFactory,
+    reset(blueprint, stack, request, group1, group2, ambariContext, logicalRequestFactory,
service1, service2,
         logicalRequest, configurationRequest, configurationRequest2, configurationRequest3,
         requestStatusResponse, executor, persistedState, clusterTopologyMock, mockFuture,
settingDAO);
   }
@@ -417,7 +435,7 @@ public class TopologyManagerTest {
     expect(requestStatusResponse.getTasks()).andReturn(new ArrayList<ShortTaskStatus>()).anyTimes();
     expect(clusterTopologyMock.isClusterKerberosEnabled()).andReturn(true);
     expect(clusterTopologyMock.getClusterId()).andReturn(CLUSTER_ID).anyTimes();
-    expect(clusterTopologyMock.getBlueprint()).andReturn(null).anyTimes();
+    expect(clusterTopologyMock.getBlueprint()).andReturn(blueprint).anyTimes();
     expect(persistedState.getAllRequests()).andReturn(allRequests).anyTimes();
     expect(persistedState.getProvisionRequest(CLUSTER_ID)).andReturn(logicalRequest).anyTimes();
     expect(ambariContext.isTopologyResolved(CLUSTER_ID)).andReturn(true).anyTimes();
@@ -520,7 +538,7 @@ public class TopologyManagerTest {
     Map<ClusterTopology,List<LogicalRequest>> allRequests = new HashMap<>();
     List<LogicalRequest> logicalRequests = new ArrayList<>();
     logicalRequests.add(logicalRequest);
-    ClusterTopology clusterTopologyMock = EasyMock.createNiceMock(ClusterTopology.class);
+    ClusterTopology clusterTopologyMock = createNiceMock(ClusterTopology.class);
     expect(clusterTopologyMock.getClusterId()).andReturn(CLUSTER_ID).anyTimes();
 
     expect(ambariContext.isTopologyResolved(EasyMock.anyLong())).andReturn(true).anyTimes();
@@ -542,7 +560,7 @@ public class TopologyManagerTest {
   }
 
   private void replayAll() {
-    replay(blueprint, stack, request, group1, group2, ambariContext, logicalRequestFactory,
+    replay(blueprint, stack, request, group1, group2, ambariContext, logicalRequestFactory,
service1, service2,
             configurationRequest, configurationRequest2, configurationRequest3, executor,
             persistedState, clusterTopologyMock, securityConfigurationFactory, credentialStoreService,
             clusterController, resourceProvider, mockFuture, requestStatusResponse, logicalRequest,
settingDAO,
@@ -558,7 +576,7 @@ public class TopologyManagerTest {
     properties.put(HostResourceProvider.HOST_CLUSTER_NAME_PROPERTY_ID, CLUSTER_NAME);
     properties.put(HostResourceProvider.BLUEPRINT_PROPERTY_ID, BLUEPRINT_NAME);
     propertySet.add(properties);
-    BlueprintV2Factory bpfMock = EasyMock.createNiceMock(BlueprintV2Factory.class);
+    BlueprintV2Factory bpfMock = createNiceMock(BlueprintV2Factory.class);
     EasyMock.expect(bpfMock.getBlueprint(BLUEPRINT_NAME)).andReturn(blueprint).anyTimes();
     BaseClusterRequest.setBlueprintFactory(bpfMock);
     replay(bpfMock);


Mime
View raw message