ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathanhur...@apache.org
Subject [29/50] [abbrv] git commit: AMBARI-6918. After putting RM in MaintMode (and stopping component), service shows stopped (dlysnichenko)
Date Wed, 20 Aug 2014 15:30:30 GMT
AMBARI-6918. After putting RM in MaintMode (and stopping component), service shows stopped
(dlysnichenko)


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

Branch: refs/heads/branch-alerts-dev
Commit: 4644a826ba2b9a13a0815c356faaa9529e1922bc
Parents: 5aaa32c
Author: Lisnichenko Dmitro <dlysnichenko@hortonworks.com>
Authored: Tue Aug 19 17:47:16 2014 +0300
Committer: Lisnichenko Dmitro <dlysnichenko@hortonworks.com>
Committed: Tue Aug 19 22:03:28 2014 +0300

----------------------------------------------------------------------
 .../internal/ServiceResourceProvider.java       |  52 +++++----
 .../internal/ServiceResourceProviderTest.java   | 113 +++++++++++++++++++
 2 files changed, 146 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/4644a826/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 c77b8d6..f8a362d 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
@@ -992,34 +992,48 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider
 
               if (componentInfo != null) {
                 State state = getHostComponentState(hostComponentResponse);
+                // Components in MM should not affect service status,
+                // so we tend to ignore them
+                boolean isInMaintenance = ! MaintenanceState.OFF.toString().
+                        equals(hostComponentResponse.getMaintenanceState());
 
-                if (state.equals(State.DISABLED)) {
+                if (state.equals(State.DISABLED) || isInMaintenance) {
                   hasDisabled = true;
-                } else {
-                  if (componentInfo.isMaster()) {
+                }
+
+                if (componentInfo.isMaster()) {
+                  if (state.equals(State.STARTED) || ! isInMaintenance) {
+                    // We rely on master's state to determine service state
                     hasMaster = true;
-                    if(!state.equals(State.STARTED) &&
-                        ( masterState == null || state.ordinal() > masterState.ordinal()))
{
-                      masterState = state;
-                    }
-                  } else if (componentInfo.isClient()) {
-                    hasClient = true;
-                    if (!state.equals(State.INSTALLED) &&
-                        (clientState == null || state.ordinal() > clientState.ordinal()))
{
-                      clientState = state;
-                    }
-                  } else {
-                    hasOther  = true;
-                    if (otherState == null || state.ordinal() > otherState.ordinal())
{
-                      otherState = state;
-                    }
+                  }
+
+                  if (! state.equals(State.STARTED) &&
+                      ! isInMaintenance &&  // Ignore status of MM component
+                      ( masterState == null || state.ordinal() > masterState.ordinal()))
{
+                    masterState = state;
+                  }
+                } else if (componentInfo.isClient()) {
+                  hasClient = true;
+                  if (!state.equals(State.INSTALLED) &&
+                      (clientState == null || state.ordinal() > clientState.ordinal()))
{
+                    clientState = state;
+                  }
+                } else {
+                  if (state.equals(State.STARTED) || ! isInMaintenance) {
+                    // We rely on slaves's state to determine service state
+                    hasOther = true;
+                  }
+                  if (! state.equals(State.STARTED) &&
+                      ! isInMaintenance && // Ignore status of MM component
+                      ( otherState == null || state.ordinal() > otherState.ordinal()))
{
+                    otherState = state;
                   }
                 }
               }
             }
 
             return hasMaster   ? masterState == null ? State.STARTED : masterState :
-                   hasOther    ? otherState :
+                   hasOther    ? otherState == null ? State.STARTED : otherState :
                    hasClient   ? clientState == null ? State.INSTALLED : clientState :
                    hasDisabled ? State.DISABLED : State.UNKNOWN;
           }

http://git-wip-us.apache.org/repos/asf/ambari/blob/4644a826/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 f37dea8..7dbc38b 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
@@ -23,6 +23,7 @@ import static org.easymock.EasyMock.anyObject;
 import static org.easymock.EasyMock.capture;
 import static org.easymock.EasyMock.createMock;
 import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.createStrictMock;
 import static org.easymock.EasyMock.eq;
 import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.isNull;
@@ -61,6 +62,7 @@ import org.apache.ambari.server.metadata.RoleCommandOrder;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.ComponentInfo;
+import org.apache.ambari.server.state.MaintenanceState;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.ServiceComponentHost;
@@ -674,8 +676,11 @@ public class ServiceResourceProviderTest {
     ComponentInfo componentInfo = createNiceMock(ComponentInfo.class);
 
     ServiceComponentHostResponse shr1 = new ServiceComponentHostResponse("C1", "MAPREDUCE",
"JOBTRACKER", "Host100", "UNKNOWN", "", null, null, null);
+    shr1.setMaintenanceState(MaintenanceState.OFF.toString());
     ServiceComponentHostResponse shr2 = new ServiceComponentHostResponse("C1", "MAPREDUCE",
"MAPREDUCE_CLIENT", "Host100", "STARTED", "", null, null, null);
+    shr2.setMaintenanceState(MaintenanceState.OFF.toString());
     ServiceComponentHostResponse shr3 = new ServiceComponentHostResponse("C1", "MAPREDUCE",
"TASKTRACKER", "Host100", "STARTED", "", null, null, null);
+    shr3.setMaintenanceState(MaintenanceState.OFF.toString());
 
     Set<ServiceComponentHostResponse> responses = new LinkedHashSet<ServiceComponentHostResponse>();
     responses.add(shr1);
@@ -720,8 +725,11 @@ public class ServiceResourceProviderTest {
     ComponentInfo componentInfo = createNiceMock(ComponentInfo.class);
 
     ServiceComponentHostResponse shr1 = new ServiceComponentHostResponse("C1", "MAPREDUCE",
"JOBTRACKER", "Host100", "STARTING", "", null, null, null);
+    shr1.setMaintenanceState(MaintenanceState.OFF.toString());
     ServiceComponentHostResponse shr2 = new ServiceComponentHostResponse("C1", "MAPREDUCE",
"MAPREDUCE_CLIENT", "Host100", "STARTED", "", null, null, null);
+    shr2.setMaintenanceState(MaintenanceState.OFF.toString());
     ServiceComponentHostResponse shr3 = new ServiceComponentHostResponse("C1", "MAPREDUCE",
"TASKTRACKER", "Host100", "STARTED", "", null, null, null);
+    shr3.setMaintenanceState(MaintenanceState.OFF.toString());
 
     Set<ServiceComponentHostResponse> responses = new LinkedHashSet<ServiceComponentHostResponse>();
     responses.add(shr1);
@@ -766,8 +774,11 @@ public class ServiceResourceProviderTest {
     ComponentInfo componentInfo = createNiceMock(ComponentInfo.class);
 
     ServiceComponentHostResponse shr1 = new ServiceComponentHostResponse("C1", "MAPREDUCE",
"JOBTRACKER", "Host100", "INSTALLED", "", null, null, null);
+    shr1.setMaintenanceState(MaintenanceState.OFF.toString());
     ServiceComponentHostResponse shr2 = new ServiceComponentHostResponse("C1", "MAPREDUCE",
"MAPREDUCE_CLIENT", "Host100", "STARTED", "", null, null, null);
+    shr2.setMaintenanceState(MaintenanceState.OFF.toString());
     ServiceComponentHostResponse shr3 = new ServiceComponentHostResponse("C1", "MAPREDUCE",
"TASKTRACKER", "Host100", "STARTED", "", null, null, null);
+    shr3.setMaintenanceState(MaintenanceState.OFF.toString());
 
     Set<ServiceComponentHostResponse> responses = new LinkedHashSet<ServiceComponentHostResponse>();
     responses.add(shr1);
@@ -1269,6 +1280,108 @@ public class ServiceResourceProviderTest {
     verify(managementController, clusters, cluster);
   }
 
+  @Test
+  @SuppressWarnings("unchecked")
+  public void testDefaultServiceState_Master_In_MM() 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 = createStrictMock(ComponentInfo.class);
+
+    ServiceComponentHostResponse shr1 = new ServiceComponentHostResponse("C1", "YARN", "RESOURCEMANAGER",
"Host100", "INSTALLED", "", null, null, null);
+    shr1.setMaintenanceState(MaintenanceState.ON.toString());
+    ServiceComponentHostResponse shr2 = new ServiceComponentHostResponse("C1", "YARN", "RESOURCEMANAGER",
"Host101", "STARTED", "", null, null, null);
+    shr2.setMaintenanceState(MaintenanceState.OFF.toString());
+    ServiceComponentHostResponse shr3 = new ServiceComponentHostResponse("C1", "YARN", "NODEMANAGER",
"Host100", "STARTED", "", null, null, null);
+    shr3.setMaintenanceState(MaintenanceState.OFF.toString());
+
+    Set<ServiceComponentHostResponse> responses = new LinkedHashSet<ServiceComponentHostResponse>();
+    responses.add(shr1);
+    responses.add(shr2);
+    responses.add(shr3);
+
+    // 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.isMaster()).andReturn(true).times(2);
+    expect(componentInfo.isMaster()).andReturn(false);
+
+    expect(componentInfo.isClient()).andReturn(false);
+
+    // replay
+    replay(managementController, clusters, cluster, ambariMetaInfo, stackId, componentInfo);
+
+    ServiceResourceProvider.ServiceState serviceState = new ServiceResourceProvider.DefaultServiceState();
+
+    State state = serviceState.getState(managementController, "C1", "YARN");
+    Assert.assertEquals(State.STARTED, state);
+
+    // verify
+    verify(managementController, clusters, cluster, ambariMetaInfo, stackId, componentInfo);
+  }
+
+  @Test
+  @SuppressWarnings("unchecked")
+  public void testDefaultServiceState_Slave_In_MM() 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", "NODEMANAGER",
"Host100", "INSTALLED", "", null, null, null);
+    shr1.setMaintenanceState(MaintenanceState.ON.toString());
+    ServiceComponentHostResponse shr2 = new ServiceComponentHostResponse("C1", "YARN", "NODEMANAGER",
"Host101", "STARTED", "", null, null, null);
+    shr2.setMaintenanceState(MaintenanceState.OFF.toString());
+
+    Set<ServiceComponentHostResponse> responses = new LinkedHashSet<ServiceComponentHostResponse>();
+    responses.add(shr1);
+    responses.add(shr2);
+
+    // 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.isMaster()).andReturn(false).anyTimes();
+
+    expect(componentInfo.isClient()).andReturn(false).anyTimes();
+
+    // replay
+    replay(managementController, clusters, cluster, ambariMetaInfo, stackId, componentInfo);
+
+    ServiceResourceProvider.ServiceState serviceState = new ServiceResourceProvider.DefaultServiceState();
+
+    State state = serviceState.getState(managementController, "C1", "YARN");
+    Assert.assertEquals(State.STARTED, state);
+
+    // verify
+    verify(managementController, clusters, cluster, ambariMetaInfo, stackId, componentInfo);
+  }
+
 
   /**
    * This factory method creates default MaintenanceStateHelper mock.


Mime
View raw message