You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by tb...@apache.org on 2014/02/25 23:08:55 UTC

git commit: AMBARI-4760 : Client-only services transition to the STARTED state

Repository: ambari
Updated Branches:
  refs/heads/trunk 66478e112 -> 6d522cb9d


AMBARI-4760 : Client-only services transition to the STARTED state


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

Branch: refs/heads/trunk
Commit: 6d522cb9d62c7f6775c7ec4ae9bd04aff3d5da4e
Parents: 66478e1
Author: tbeerbower <tb...@hortonworks.com>
Authored: Tue Feb 25 16:38:35 2014 -0500
Committer: tbeerbower <tb...@hortonworks.com>
Committed: Tue Feb 25 17:08:26 2014 -0500

----------------------------------------------------------------------
 .../internal/ServiceResourceProvider.java       | 53 +++++++++---
 .../internal/ServiceResourceProviderTest.java   | 85 +++++++++++++++++++-
 2 files changed, 127 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/6d522cb9/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 204d14c..8a8b435 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
@@ -801,6 +801,14 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider
 
   /**
    * Default calculator of service state.
+   * The following rules should apply :
+   * For services that have all components DISABLED, the service state should be DISABLED.
+   * For services that have any master components, the service state should
+   * be STARTED if all master components are STARTED.
+   * For services that have all client components, the service state should
+   * be INSTALLED if all of the components are INSTALLED.
+   * For all other cases the state of the service should match the highest state of all
+   * of its component states or UNKNOWN if the component states can not be determined.
    */
   protected static class DefaultServiceState implements ServiceState {
 
@@ -821,25 +829,50 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider
             Set<ServiceComponentHostResponse> hostComponentResponses =
                 controller.getHostComponents(Collections.singleton(request));
 
+            State   serviceState = null;
+            boolean hasDisabled  = false;
+            boolean hasMaster    = false;
+            boolean hasOther     = false;
+            boolean hasClient    = false;
+
             for (ServiceComponentHostResponse hostComponentResponse : hostComponentResponses ) {
               ComponentInfo componentInfo = ambariMetaInfo.getComponentCategory(stackId.getStackName(),
                   stackId.getStackVersion(), hostComponentResponse.getServiceName(),
                   hostComponentResponse.getComponentName());
 
-              if (componentInfo != null) {
-                if (componentInfo.isMaster()) {
-                  State state = getHostComponentState(hostComponentResponse);
-                  switch (state) {
-                    case STARTED:
-                    case DISABLED:
-                      break;
-                    default:
-                      return state;
+            if (componentInfo != null) {
+                State state = getHostComponentState(hostComponentResponse);
+
+                if (state.equals(State.DISABLED)) {
+                  hasDisabled = true;
+                } else {
+                  if (componentInfo.isMaster()) {
+                    hasMaster = true;
+                    if(!state.equals(State.STARTED) &&
+                        ( serviceState == null || state.ordinal() > serviceState.ordinal())) {
+                      serviceState = state;
+                    }
+                  } else if (componentInfo.isClient()) {
+                    hasClient = true;
+                    if (!(hasMaster || hasOther) && !state.equals(State.INSTALLED) &&
+                        (serviceState == null || state.ordinal() > serviceState.ordinal())) {
+                      serviceState = state;
+                    }
+                  } else {
+                    hasOther  = true;
+                    if (!hasMaster &&
+                        (serviceState == null || state.ordinal() > serviceState.ordinal())) {
+                      serviceState = state;
+                    }
                   }
                 }
               }
             }
-            return State.STARTED;
+
+            return hasMaster   ? serviceState == null ? State.STARTED : serviceState :
+                   hasOther    ? serviceState :
+                   hasClient   ? serviceState == null ? State.INSTALLED : serviceState :
+                   hasDisabled ? State.DISABLED : State.UNKNOWN;
           }
         } catch (AmbariException e) {
           LOG.error("Can't determine service state.", e);

http://git-wip-us.apache.org/repos/asf/ambari/blob/6d522cb9/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 9f68b0a..2bc51bb 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
@@ -700,7 +700,6 @@ public class ServiceResourceProviderTest {
     expect(ambariMetaInfo.getComponentCategory((String) anyObject(), (String) anyObject(),
         (String) anyObject(), (String) anyObject())).andReturn(componentInfo).anyTimes();
 
-    expect(componentInfo.isMaster()).andReturn(true);
     expect(componentInfo.isMaster()).andReturn(false);
     expect(componentInfo.isMaster()).andReturn(false);
 
@@ -860,6 +859,90 @@ public class ServiceResourceProviderTest {
     verify(managementController, clusters, cluster, ambariMetaInfo, stackId, componentInfo);
   }
 
+  @Test
+  public void testDefaultServiceState_ClientOnly_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", "PIG", "PIG", "Host100", "INSTALLED", "", null, null, null);
+
+    Set<ServiceComponentHostResponse> responses = new LinkedHashSet<ServiceComponentHostResponse>();
+    responses.add(shr1);
+
+    // 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.getComponentCategory((String) anyObject(), (String) anyObject(),
+        (String) anyObject(), (String) anyObject())).andReturn(componentInfo).anyTimes();
+
+    expect(componentInfo.isClient()).andReturn(true);
+
+    // replay
+    replay(managementController, clusters, cluster, ambariMetaInfo, stackId, componentInfo);
+
+    ServiceResourceProvider.ServiceState serviceState = new ServiceResourceProvider.DefaultServiceState();
+
+    State state = serviceState.getState(managementController, "C1", "PIG");
+    Assert.assertEquals(State.INSTALLED, state);
+
+    // verify
+    verify(managementController, clusters, cluster, ambariMetaInfo, stackId, componentInfo);
+  }
+
+  @Test
+  public void testDefaultServiceState_ClientOnly_INSTALL_FAILED() 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", "PIG", "PIG", "Host100", "INSTALL_FAILED", "", null, null, null);
+
+    Set<ServiceComponentHostResponse> responses = new LinkedHashSet<ServiceComponentHostResponse>();
+    responses.add(shr1);
+
+    // 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.getComponentCategory((String) anyObject(), (String) anyObject(),
+        (String) anyObject(), (String) anyObject())).andReturn(componentInfo).anyTimes();
+
+    expect(componentInfo.isClient()).andReturn(true);
+
+    // replay
+    replay(managementController, clusters, cluster, ambariMetaInfo, stackId, componentInfo);
+
+    ServiceResourceProvider.ServiceState serviceState = new ServiceResourceProvider.DefaultServiceState();
+
+    State state = serviceState.getState(managementController, "C1", "PIG");
+    Assert.assertEquals(State.INSTALL_FAILED, state);
+
+    // verify
+    verify(managementController, clusters, cluster, ambariMetaInfo, stackId, componentInfo);
+  }
+
   public static ServiceResourceProvider getServiceProvider(AmbariManagementController managementController) {
     Resource.Type type = Resource.Type.Service;
     return new ServiceResourceProvider(PropertyHelper.getPropertyIds(type),