Repository: ambari Updated Branches: refs/heads/trunk a55c81267 -> a93c5d289
AMBARI-12686. [RM HA] YARN service shows RED when one of RM goes down but the active RM works fine (Vishal Ghugare via rlevas) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/a93c5d28 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/a93c5d28 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/a93c5d28 Branch: refs/heads/trunk Commit: a93c5d2892b92ae22b3d1b7f7967dc43d45f6740 Parents: a55c812 Author: Vishal Ghugare <[email protected]> Authored: Thu Dec 17 09:43:33 2015 -0500 Committer: Robert Levas <[email protected]> Committed: Thu Dec 17 09:44:02 2015 -0500 ---------------------------------------------------------------------- .../internal/ServiceResourceProvider.java | 72 ++++ .../internal/ServiceResourceProviderTest.java | 342 +++++++++++++++++++ 2 files changed, 414 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/a93c5d28/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java index 7a3d330..815f006 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java @@ -117,6 +117,7 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider serviceStateMap.put("FLUME", new FlumeServiceState()); serviceStateMap.put("HIVE", new HiveServiceState()); serviceStateMap.put("OOZIE", new OozieServiceState()); + serviceStateMap.put("YARN", new YARNServiceState()); } private static final ServiceState DEFAULT_SERVICE_STATE = new DefaultServiceState(); @@ -1385,6 +1386,77 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider return State.UNKNOWN; } } + + /** + * Calculator of YARN service state. + */ + protected static class YARNServiceState implements ServiceState { + @Override + public State getState(AmbariManagementController controller,String clusterName, String serviceName) { + AmbariMetaInfo ambariMetaInfo = controller.getAmbariMetaInfo(); + Clusters clusters = controller.getClusters(); + + if (clusterName != null && clusterName.length() > 0) { + try { + Cluster cluster = clusters.getCluster(clusterName); + if (cluster != null) { + StackId stackId = cluster.getDesiredStackVersion(); + + ServiceComponentHostRequest request = new ServiceComponentHostRequest(clusterName, + serviceName, null, null, null); + + Set<ServiceComponentHostResponse> hostComponentResponses = + controller.getHostComponents(Collections.singleton(request)); + + int resourceManagerActiveCount = 0; + boolean isAppTimeLineServerActive = false; + State nonStartedState = null; + + for (ServiceComponentHostResponse hostComponentResponse : hostComponentResponses ) { + try { + ComponentInfo componentInfo = ambariMetaInfo.getComponent(stackId.getStackName(), + stackId.getStackVersion(), hostComponentResponse.getServiceName(), + hostComponentResponse.getComponentName()); + + if (componentInfo.isMaster()) { + String componentName = hostComponentResponse.getComponentName(); + + State state = getHostComponentState(hostComponentResponse); + + switch (state) { + case STARTED: + case DISABLED: + if (componentName.equals("RESOURCEMANAGER")) { + ++resourceManagerActiveCount; + } else if (componentName.equals("APP_TIMELINE_SERVER")) { + isAppTimeLineServerActive = true; + } + break; + default: + nonStartedState = state; + } + } + } catch (ObjectNotFoundException e) { + // component doesn't exist, nothing to do + } + } + + if ( nonStartedState == null || // all started + (isAppTimeLineServerActive && + resourceManagerActiveCount > 0)) { // at least one active resource manager + return State.STARTED; + } + return nonStartedState; + } + } catch (AmbariException e) { + LOG.error("Can't determine service state.", e); + } + } + return State.UNKNOWN; + } + + } + /** * Determine whether a service state change is valid. http://git-wip-us.apache.org/repos/asf/ambari/blob/a93c5d28/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceResourceProviderTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceResourceProviderTest.java index f067f49..a89b96a 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceResourceProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceResourceProviderTest.java @@ -1430,7 +1430,349 @@ public class ServiceResourceProviderTest { // verify verify(managementController, clusters, cluster, ambariMetaInfo, stackId, componentInfo); } + + @Test + public void testYARNServiceState_STARTED_HA1() throws Exception{ + AmbariManagementController managementController = createMock(AmbariManagementController.class); + Clusters clusters = createNiceMock(Clusters.class); + Cluster cluster = createNiceMock(Cluster.class); + AmbariMetaInfo ambariMetaInfo = createNiceMock(AmbariMetaInfo.class); + StackId stackId = createNiceMock(StackId.class); + ComponentInfo componentInfo = createNiceMock(ComponentInfo.class); + + ServiceComponentHostResponse shr1 = new ServiceComponentHostResponse("C1", "YARN", "APP_TIMELINE_SERVER", "Host100", "STARTED", "", null, null, null); + ServiceComponentHostResponse shr2 = new ServiceComponentHostResponse("C1", "YARN", "RESOURCEMANAGER", "Host100", "STARTED", "", null, null, null); + ServiceComponentHostResponse shr3 = new ServiceComponentHostResponse("C1", "YARN", "RESOURCEMANAGER", "Host101", "STARTED", "", null, null, null); + ServiceComponentHostResponse shr4 = new ServiceComponentHostResponse("C1", "YARN", "YARN_CLIENT", "Host100", "INSTALLED", "", null, null, null); + ServiceComponentHostResponse shr5 = new ServiceComponentHostResponse("C1", "YARN", "NODEMANAGER", "Host100", "STARTED", "", null, null, null); + ServiceComponentHostResponse shr6 = new ServiceComponentHostResponse("C1", "YARN", "YARN_CLIENT", "Host101", "INSTALLED", "", null, null, null); + ServiceComponentHostResponse shr7 = new ServiceComponentHostResponse("C1", "YARN", "NODEMANAGER", "Host101", "STARTED", "", null, null, null); + + + Set<ServiceComponentHostResponse> responses = new LinkedHashSet<ServiceComponentHostResponse>(); + responses.add(shr1); + responses.add(shr2); + responses.add(shr3); + responses.add(shr4); + responses.add(shr5); + responses.add(shr6); + responses.add(shr7); + + // set expectations + expect(managementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes(); + expect(managementController.getClusters()).andReturn(clusters).anyTimes(); + expect(clusters.getCluster("C1")).andReturn(cluster).anyTimes(); + expect(managementController.getHostComponents((Set<ServiceComponentHostRequest>) anyObject())).andReturn(responses).anyTimes(); + expect(cluster.getDesiredStackVersion()).andReturn(stackId); + + expect(stackId.getStackName()).andReturn("S1").anyTimes(); + expect(stackId.getStackVersion()).andReturn("V1").anyTimes(); + + + expect(ambariMetaInfo.getComponent((String) anyObject(), (String) anyObject(), + (String) anyObject(), (String) anyObject())).andReturn(componentInfo).anyTimes(); + + expect(componentInfo.isMaster()).andReturn(true); + expect(componentInfo.isMaster()).andReturn(true); + expect(componentInfo.isMaster()).andReturn(true); + expect(componentInfo.isMaster()).andReturn(false); + expect(componentInfo.isMaster()).andReturn(false); + expect(componentInfo.isMaster()).andReturn(false); + expect(componentInfo.isMaster()).andReturn(false); + + // replay + replay(managementController, clusters, cluster, ambariMetaInfo, stackId, componentInfo); + + ServiceResourceProvider.ServiceState serviceState = new ServiceResourceProvider.YARNServiceState(); + + State state = serviceState.getState(managementController, "C1", "YARN"); + Assert.assertEquals(State.STARTED, state); + + // verify + verify(managementController, clusters, cluster, ambariMetaInfo, stackId, componentInfo); + } + + @Test + public void testYARNServiceState_STARTED_HA2() throws Exception{ + AmbariManagementController managementController = createMock(AmbariManagementController.class); + Clusters clusters = createNiceMock(Clusters.class); + Cluster cluster = createNiceMock(Cluster.class); + AmbariMetaInfo ambariMetaInfo = createNiceMock(AmbariMetaInfo.class); + StackId stackId = createNiceMock(StackId.class); + ComponentInfo componentInfo = createNiceMock(ComponentInfo.class); + + ServiceComponentHostResponse shr1 = new ServiceComponentHostResponse("C1", "YARN", "APP_TIMELINE_SERVER", "Host100", "STARTED", "", null, null, null); + ServiceComponentHostResponse shr2 = new ServiceComponentHostResponse("C1", "YARN", "RESOURCEMANAGER", "Host100", "STARTED", "", null, null, null); + ServiceComponentHostResponse shr3 = new ServiceComponentHostResponse("C1", "YARN", "RESOURCEMANAGER", "Host101", "INSTALLED", "", null, null, null); + ServiceComponentHostResponse shr4 = new ServiceComponentHostResponse("C1", "YARN", "YARN_CLIENT", "Host100", "INSTALLED", "", null, null, null); + ServiceComponentHostResponse shr5 = new ServiceComponentHostResponse("C1", "YARN", "NODEMANAGER", "Host100", "STARTED", "", null, null, null); + ServiceComponentHostResponse shr6 = new ServiceComponentHostResponse("C1", "YARN", "YARN_CLIENT", "Host101", "INSTALLED", "", null, null, null); + ServiceComponentHostResponse shr7 = new ServiceComponentHostResponse("C1", "YARN", "NODEMANAGER", "Host101", "STARTED", "", null, null, null); + + Set<ServiceComponentHostResponse> responses = new LinkedHashSet<ServiceComponentHostResponse>(); + responses.add(shr1); + responses.add(shr2); + responses.add(shr3); + responses.add(shr4); + responses.add(shr5); + responses.add(shr6); + responses.add(shr7); + + // set expectations + expect(managementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes(); + expect(managementController.getClusters()).andReturn(clusters).anyTimes(); + expect(clusters.getCluster("C1")).andReturn(cluster).anyTimes(); + expect(managementController.getHostComponents((Set<ServiceComponentHostRequest>) anyObject())).andReturn(responses).anyTimes(); + expect(cluster.getDesiredStackVersion()).andReturn(stackId); + + expect(stackId.getStackName()).andReturn("S1").anyTimes(); + expect(stackId.getStackVersion()).andReturn("V1").anyTimes(); + + + expect(ambariMetaInfo.getComponent((String) anyObject(), (String) anyObject(), + (String) anyObject(), (String) anyObject())).andReturn(componentInfo).anyTimes(); + + expect(componentInfo.isMaster()).andReturn(true); + expect(componentInfo.isMaster()).andReturn(true); + expect(componentInfo.isMaster()).andReturn(true); + expect(componentInfo.isMaster()).andReturn(false); + expect(componentInfo.isMaster()).andReturn(false); + expect(componentInfo.isMaster()).andReturn(false); + expect(componentInfo.isMaster()).andReturn(false); + + // replay + replay(managementController, clusters, cluster, ambariMetaInfo, stackId, componentInfo); + + ServiceResourceProvider.ServiceState serviceState = new ServiceResourceProvider.YARNServiceState(); + + State state = serviceState.getState(managementController, "C1", "YARN"); + Assert.assertEquals(State.STARTED, state); + + // verify + verify(managementController, clusters, cluster, ambariMetaInfo, stackId, componentInfo); + } + + @Test + public void testYARNServiceState_INSTALLED_HA3() throws Exception{ + AmbariManagementController managementController = createMock(AmbariManagementController.class); + Clusters clusters = createNiceMock(Clusters.class); + Cluster cluster = createNiceMock(Cluster.class); + AmbariMetaInfo ambariMetaInfo = createNiceMock(AmbariMetaInfo.class); + StackId stackId = createNiceMock(StackId.class); + ComponentInfo componentInfo = createNiceMock(ComponentInfo.class); + + ServiceComponentHostResponse shr1 = new ServiceComponentHostResponse("C1", "YARN", "APP_TIMELINE_SERVER", "Host100", "INSTALLED", "", null, null, null); + ServiceComponentHostResponse shr2 = new ServiceComponentHostResponse("C1", "YARN", "RESOURCEMANAGER", "Host100", "INSTALLED", "", null, null, null); + ServiceComponentHostResponse shr3 = new ServiceComponentHostResponse("C1", "YARN", "RESOURCEMANAGER", "Host101", "INSTALLED", "", null, null, null); + ServiceComponentHostResponse shr4 = new ServiceComponentHostResponse("C1", "YARN", "YARN_CLIENT", "Host100", "INSTALLED", "", null, null, null); + ServiceComponentHostResponse shr5 = new ServiceComponentHostResponse("C1", "YARN", "NODEMANAGER", "Host100", "INSTALLED", "", null, null, null); + ServiceComponentHostResponse shr6 = new ServiceComponentHostResponse("C1", "YARN", "YARN_CLIENT", "Host101", "INSTALLED", "", null, null, null); + ServiceComponentHostResponse shr7 = new ServiceComponentHostResponse("C1", "YARN", "NODEMANAGER", "Host101", "INSTALLED", "", null, null, null); + + Set<ServiceComponentHostResponse> responses = new LinkedHashSet<ServiceComponentHostResponse>(); + responses.add(shr1); + responses.add(shr2); + responses.add(shr3); + responses.add(shr4); + responses.add(shr5); + responses.add(shr6); + responses.add(shr7); + + // set expectations + expect(managementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes(); + expect(managementController.getClusters()).andReturn(clusters).anyTimes(); + expect(clusters.getCluster("C1")).andReturn(cluster).anyTimes(); + expect(managementController.getHostComponents((Set<ServiceComponentHostRequest>) anyObject())).andReturn(responses).anyTimes(); + expect(cluster.getDesiredStackVersion()).andReturn(stackId); + + expect(stackId.getStackName()).andReturn("S1").anyTimes(); + expect(stackId.getStackVersion()).andReturn("V1").anyTimes(); + + expect(ambariMetaInfo.getComponent((String) anyObject(), (String) anyObject(), + (String) anyObject(), (String) anyObject())).andReturn(componentInfo).anyTimes(); + + expect(componentInfo.isMaster()).andReturn(true); + expect(componentInfo.isMaster()).andReturn(true); + expect(componentInfo.isMaster()).andReturn(true); + expect(componentInfo.isMaster()).andReturn(false); + expect(componentInfo.isMaster()).andReturn(false); + expect(componentInfo.isMaster()).andReturn(false); + expect(componentInfo.isMaster()).andReturn(false); + + // replay + replay(managementController, clusters, cluster, ambariMetaInfo, stackId, componentInfo); + + ServiceResourceProvider.ServiceState serviceState = new ServiceResourceProvider.YARNServiceState(); + State state = serviceState.getState(managementController, "C1", "YARN"); + Assert.assertEquals(State.INSTALLED, state); + + // verify + verify(managementController, clusters, cluster, ambariMetaInfo, stackId, componentInfo); + } + + @Test + public void testYARNServiceState_INSTALLED_HA4() throws Exception{ + AmbariManagementController managementController = createMock(AmbariManagementController.class); + Clusters clusters = createNiceMock(Clusters.class); + Cluster cluster = createNiceMock(Cluster.class); + AmbariMetaInfo ambariMetaInfo = createNiceMock(AmbariMetaInfo.class); + StackId stackId = createNiceMock(StackId.class); + ComponentInfo componentInfo = createNiceMock(ComponentInfo.class); + + ServiceComponentHostResponse shr1 = new ServiceComponentHostResponse("C1", "YARN", "APP_TIMELINE_SERVER", "Host100", "STARTED", "", null, null, null); + ServiceComponentHostResponse shr2 = new ServiceComponentHostResponse("C1", "YARN", "RESOURCEMANAGER", "Host100", "INSTALLED", "", null, null, null); + ServiceComponentHostResponse shr3 = new ServiceComponentHostResponse("C1", "YARN", "RESOURCEMANAGER", "Host101", "INSTALLED", "", null, null, null); + ServiceComponentHostResponse shr4 = new ServiceComponentHostResponse("C1", "YARN", "YARN_CLIENT", "Host100", "INSTALLED", "", null, null, null); + ServiceComponentHostResponse shr5 = new ServiceComponentHostResponse("C1", "YARN", "NODEMANAGER", "Host100", "INSTALLED", "", null, null, null); + ServiceComponentHostResponse shr6 = new ServiceComponentHostResponse("C1", "YARN", "YARN_CLIENT", "Host101", "INSTALLED", "", null, null, null); + ServiceComponentHostResponse shr7 = new ServiceComponentHostResponse("C1", "YARN", "NODEMANAGER", "Host101", "INSTALLED", "", null, null, null); + + Set<ServiceComponentHostResponse> responses = new LinkedHashSet<ServiceComponentHostResponse>(); + responses.add(shr1); + responses.add(shr2); + responses.add(shr3); + responses.add(shr4); + responses.add(shr5); + responses.add(shr6); + responses.add(shr7); + + // set expectations + expect(managementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes(); + expect(managementController.getClusters()).andReturn(clusters).anyTimes(); + expect(clusters.getCluster("C1")).andReturn(cluster).anyTimes(); + expect(managementController.getHostComponents((Set<ServiceComponentHostRequest>) anyObject())).andReturn(responses).anyTimes(); + expect(cluster.getDesiredStackVersion()).andReturn(stackId); + + expect(stackId.getStackName()).andReturn("S1").anyTimes(); + expect(stackId.getStackVersion()).andReturn("V1").anyTimes(); + + + expect(ambariMetaInfo.getComponent((String) anyObject(), (String) anyObject(), + (String) anyObject(), (String) anyObject())).andReturn(componentInfo).anyTimes(); + + expect(componentInfo.isMaster()).andReturn(true); + expect(componentInfo.isMaster()).andReturn(true); + expect(componentInfo.isMaster()).andReturn(true); + expect(componentInfo.isMaster()).andReturn(false); + expect(componentInfo.isMaster()).andReturn(false); + expect(componentInfo.isMaster()).andReturn(false); + expect(componentInfo.isMaster()).andReturn(false); + + // replay + replay(managementController, clusters, cluster, ambariMetaInfo, stackId, componentInfo); + + ServiceResourceProvider.ServiceState serviceState = new ServiceResourceProvider.YARNServiceState(); + + State state = serviceState.getState(managementController, "C1", "YARN"); + Assert.assertEquals(State.INSTALLED, state); + + // verify + verify(managementController, clusters, cluster, ambariMetaInfo, stackId, componentInfo); + } + + @Test + public void testYARNServiceState_INSTALLED() throws Exception{ + AmbariManagementController managementController = createMock(AmbariManagementController.class); + Clusters clusters = createNiceMock(Clusters.class); + Cluster cluster = createNiceMock(Cluster.class); + AmbariMetaInfo ambariMetaInfo = createNiceMock(AmbariMetaInfo.class); + StackId stackId = createNiceMock(StackId.class); + ComponentInfo componentInfo = createNiceMock(ComponentInfo.class); + + ServiceComponentHostResponse shr1 = new ServiceComponentHostResponse("C1", "YARN", "APP_TIMELINE_SERVER", "Host100", "STARTED", "", null, null, null); + ServiceComponentHostResponse shr2 = new ServiceComponentHostResponse("C1", "YARN", "RESOURCEMANAGER", "Host100", "INSTALLED", "", null, null, null); + ServiceComponentHostResponse shr3 = new ServiceComponentHostResponse("C1", "YARN", "YARN_CLIENT", "Host100", "INSTALLED", "", null, null, null); + ServiceComponentHostResponse shr4 = new ServiceComponentHostResponse("C1", "YARN", "NODEMANAGER", "Host100", "INSTALLED", "", null, null, null); + + Set<ServiceComponentHostResponse> responses = new LinkedHashSet<ServiceComponentHostResponse>(); + responses.add(shr1); + responses.add(shr2); + responses.add(shr3); + responses.add(shr4); + + // set expectations + expect(managementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes(); + expect(managementController.getClusters()).andReturn(clusters).anyTimes(); + expect(clusters.getCluster("C1")).andReturn(cluster).anyTimes(); + expect(managementController.getHostComponents((Set<ServiceComponentHostRequest>) anyObject())).andReturn(responses).anyTimes(); + expect(cluster.getDesiredStackVersion()).andReturn(stackId); + + expect(stackId.getStackName()).andReturn("S1").anyTimes(); + expect(stackId.getStackVersion()).andReturn("V1").anyTimes(); + + + expect(ambariMetaInfo.getComponent((String) anyObject(), (String) anyObject(), + (String) anyObject(), (String) anyObject())).andReturn(componentInfo).anyTimes(); + + expect(componentInfo.isMaster()).andReturn(true); + expect(componentInfo.isMaster()).andReturn(true); + expect(componentInfo.isMaster()).andReturn(false); + expect(componentInfo.isMaster()).andReturn(false); + + // replay + replay(managementController, clusters, cluster, ambariMetaInfo, stackId, componentInfo); + + ServiceResourceProvider.ServiceState serviceState = new ServiceResourceProvider.YARNServiceState(); + + State state = serviceState.getState(managementController, "C1", "YARN"); + Assert.assertEquals(State.INSTALLED, state); + + // verify + verify(managementController, clusters, cluster, ambariMetaInfo, stackId, componentInfo); + } + + @Test + public void testYARNServiceState_STARTED() throws Exception{ + AmbariManagementController managementController = createMock(AmbariManagementController.class); + Clusters clusters = createNiceMock(Clusters.class); + Cluster cluster = createNiceMock(Cluster.class); + AmbariMetaInfo ambariMetaInfo = createNiceMock(AmbariMetaInfo.class); + StackId stackId = createNiceMock(StackId.class); + ComponentInfo componentInfo = createNiceMock(ComponentInfo.class); + + ServiceComponentHostResponse shr1 = new ServiceComponentHostResponse("C1", "YARN", "APP_TIMELINE_SERVER", "Host100", "STARTED", "", null, null, null); + ServiceComponentHostResponse shr2 = new ServiceComponentHostResponse("C1", "YARN", "RESOURCEMANAGER", "Host100", "STARTED", "", null, null, null); + ServiceComponentHostResponse shr3 = new ServiceComponentHostResponse("C1", "YARN", "YARN_CLIENT", "Host100", "INSTALLED", "", null, null, null); + ServiceComponentHostResponse shr4 = new ServiceComponentHostResponse("C1", "YARN", "NODEMANAGER", "Host100", "STARTED", "", null, null, null); + + Set<ServiceComponentHostResponse> responses = new LinkedHashSet<ServiceComponentHostResponse>(); + responses.add(shr1); + responses.add(shr2); + responses.add(shr3); + responses.add(shr4); + + // set expectations + expect(managementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes(); + expect(managementController.getClusters()).andReturn(clusters).anyTimes(); + expect(clusters.getCluster("C1")).andReturn(cluster).anyTimes(); + expect(managementController.getHostComponents((Set<ServiceComponentHostRequest>) anyObject())).andReturn(responses).anyTimes(); + expect(cluster.getDesiredStackVersion()).andReturn(stackId); + + expect(stackId.getStackName()).andReturn("S1").anyTimes(); + expect(stackId.getStackVersion()).andReturn("V1").anyTimes(); + + + expect(ambariMetaInfo.getComponent((String) anyObject(), (String) anyObject(), + (String) anyObject(), (String) anyObject())).andReturn(componentInfo).anyTimes(); + + expect(componentInfo.isMaster()).andReturn(true); + expect(componentInfo.isMaster()).andReturn(true); + expect(componentInfo.isMaster()).andReturn(false); + expect(componentInfo.isMaster()).andReturn(false); + + // replay + replay(managementController, clusters, cluster, ambariMetaInfo, stackId, componentInfo); + + ServiceResourceProvider.ServiceState serviceState = new ServiceResourceProvider.YARNServiceState(); + + State state = serviceState.getState(managementController, "C1", "YARN"); + Assert.assertEquals(State.STARTED, state); + + // verify + verify(managementController, clusters, cluster, ambariMetaInfo, stackId, componentInfo); + } + @Test public void testHiveServiceState_INSTALLED() throws Exception { AmbariManagementController managementController = createMock(AmbariManagementController.class);
