ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aonis...@apache.org
Subject [11/50] [abbrv] ambari git commit: AMBARI-21996 Provide maintenance mode off count for components (dsen)
Date Thu, 28 Sep 2017 13:25:00 GMT
AMBARI-21996 Provide maintenance mode off count for components (dsen)


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

Branch: refs/heads/branch-3.0-perf
Commit: 986a65dbf4fbf36dac7073418ef368c2c207b123
Parents: 311c7bb
Author: Dmytro Sen <dsen@apache.org>
Authored: Mon Sep 25 16:32:46 2017 +0300
Committer: Dmytro Sen <dsen@apache.org>
Committed: Mon Sep 25 16:32:46 2017 +0300

----------------------------------------------------------------------
 .../internal/ComponentResourceProvider.java     |  4 ++++
 .../server/state/ServiceComponentImpl.java      | 25 ++++++++++++++++++++
 .../internal/ComponentResourceProviderTest.java |  6 +++++
 .../server/state/ServiceComponentTest.java      | 21 +++++++++++++---
 4 files changed, 53 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/986a65db/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ComponentResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ComponentResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ComponentResourceProvider.java
index ebbf169..2e86b2d 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ComponentResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ComponentResourceProvider.java
@@ -85,6 +85,8 @@ public class ComponentResourceProvider extends AbstractControllerResourceProvide
   protected static final String COMPONENT_TOTAL_COUNT_PROPERTY_ID     = "ServiceComponentInfo/total_count";
   protected static final String COMPONENT_STARTED_COUNT_PROPERTY_ID   = "ServiceComponentInfo/started_count";
   protected static final String COMPONENT_INSTALLED_COUNT_PROPERTY_ID = "ServiceComponentInfo/installed_count";
+  protected static final String COMPONENT_INSTALLED_AND_MAINTENANCE_OFF_COUNT_PROPERTY_ID
+                                                                      = "ServiceComponentInfo/installed_and_maintenance_off_count";
   protected static final String COMPONENT_INIT_COUNT_PROPERTY_ID      = "ServiceComponentInfo/init_count";
   protected static final String COMPONENT_UNKNOWN_COUNT_PROPERTY_ID   = "ServiceComponentInfo/unknown_count";
   protected static final String COMPONENT_INSTALL_FAILED_COUNT_PROPERTY_ID = "ServiceComponentInfo/install_failed_count";
@@ -124,6 +126,7 @@ public class ComponentResourceProvider extends AbstractControllerResourceProvide
     PROPERTY_IDS.add(COMPONENT_TOTAL_COUNT_PROPERTY_ID);
     PROPERTY_IDS.add(COMPONENT_STARTED_COUNT_PROPERTY_ID);
     PROPERTY_IDS.add(COMPONENT_INSTALLED_COUNT_PROPERTY_ID);
+    PROPERTY_IDS.add(COMPONENT_INSTALLED_AND_MAINTENANCE_OFF_COUNT_PROPERTY_ID);
 
     PROPERTY_IDS.add(COMPONENT_INIT_COUNT_PROPERTY_ID);
     PROPERTY_IDS.add(COMPONENT_UNKNOWN_COUNT_PROPERTY_ID);
@@ -220,6 +223,7 @@ public class ComponentResourceProvider extends AbstractControllerResourceProvide
       setResourceProperty(resource, COMPONENT_TOTAL_COUNT_PROPERTY_ID, response.getServiceComponentStateCount().get("totalCount"),
requestedIds);
       setResourceProperty(resource, COMPONENT_STARTED_COUNT_PROPERTY_ID, response.getServiceComponentStateCount().get("startedCount"),
requestedIds);
       setResourceProperty(resource, COMPONENT_INSTALLED_COUNT_PROPERTY_ID, response.getServiceComponentStateCount().get("installedCount"),
requestedIds);
+      setResourceProperty(resource, COMPONENT_INSTALLED_AND_MAINTENANCE_OFF_COUNT_PROPERTY_ID,
response.getServiceComponentStateCount().get("installedAndMaintenanceOffCount"), requestedIds);
       setResourceProperty(resource, COMPONENT_INSTALL_FAILED_COUNT_PROPERTY_ID, response.getServiceComponentStateCount().get("installFailedCount"),
requestedIds);
       setResourceProperty(resource, COMPONENT_INIT_COUNT_PROPERTY_ID, response.getServiceComponentStateCount().get("initCount"),
requestedIds);
       setResourceProperty(resource, COMPONENT_UNKNOWN_COUNT_PROPERTY_ID, response.getServiceComponentStateCount().get("unknownCount"),
requestedIds);

http://git-wip-us.apache.org/repos/asf/ambari/blob/986a65db/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
index 5f85e38..22c97ed 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
@@ -31,6 +31,7 @@ import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.ObjectNotFoundException;
 import org.apache.ambari.server.ServiceComponentHostNotFoundException;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
+import org.apache.ambari.server.controller.MaintenanceStateHelper;
 import org.apache.ambari.server.controller.ServiceComponentResponse;
 import org.apache.ambari.server.events.ServiceComponentRecoveryChangedEvent;
 import org.apache.ambari.server.events.listeners.upgrade.StackVersionListener;
@@ -97,6 +98,9 @@ public class ServiceComponentImpl implements ServiceComponent {
   @Inject
   private HostComponentStateDAO hostComponentDAO;
 
+  @Inject
+  private MaintenanceStateHelper maintenanceStateHelper;
+
   @AssistedInject
   public ServiceComponentImpl(@Assisted Service service, @Assisted String componentName,
       AmbariMetaInfo ambariMetaInfo,
@@ -724,10 +728,31 @@ public class ServiceComponentImpl implements ServiceComponent {
     return count;
   }
 
+  /**
+   * Count the ServiceComponentHosts that have given state and are effectively not in maintenanceMode
+   * @param state
+   * @return
+   */
+  private int getMaintenanceOffSCHCountByState(State state) {
+    int count = 0;
+    for (ServiceComponentHost sch : hostComponents.values()) {
+      try {
+        MaintenanceState effectiveMaintenanceState = maintenanceStateHelper.getEffectiveState(sch,
sch.getHost());
+        if (sch.getState() == state && effectiveMaintenanceState == MaintenanceState.OFF)
{
+          count++;
+        }
+      } catch (AmbariException e) {
+        e.printStackTrace();
+      }
+    }
+    return count;
+  }
+
   private Map <String, Integer> getServiceComponentStateCount() {
     Map <String, Integer> serviceComponentStateCountMap = new HashMap<>();
     serviceComponentStateCountMap.put("startedCount", getSCHCountByState(State.STARTED));
     serviceComponentStateCountMap.put("installedCount", getSCHCountByState(State.INSTALLED));
+    serviceComponentStateCountMap.put("installedAndMaintenanceOffCount", getMaintenanceOffSCHCountByState(State.INSTALLED));
     serviceComponentStateCountMap.put("installFailedCount", getSCHCountByState(State.INSTALL_FAILED));
     serviceComponentStateCountMap.put("initCount", getSCHCountByState(State.INIT));
     serviceComponentStateCountMap.put("unknownCount", getSCHCountByState(State.UNKNOWN));

http://git-wip-us.apache.org/repos/asf/ambari/blob/986a65db/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java
index 80cd1da..110e359 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java
@@ -217,6 +217,7 @@ public class ComponentResourceProviderTest {
     Map <String, Integer> serviceComponentStateCountMap = new HashMap<>();
     serviceComponentStateCountMap.put("startedCount", 1);
     serviceComponentStateCountMap.put("installedCount", 0);
+    serviceComponentStateCountMap.put("installedAndMaintenanceOffCount", 0);
     serviceComponentStateCountMap.put("installFailedCount", 0);
     serviceComponentStateCountMap.put("initCount", 0);
     serviceComponentStateCountMap.put("unknownCount", 1);
@@ -280,6 +281,7 @@ public class ComponentResourceProviderTest {
     propertyIds.add(ComponentResourceProvider.COMPONENT_TOTAL_COUNT_PROPERTY_ID);
     propertyIds.add(ComponentResourceProvider.COMPONENT_STARTED_COUNT_PROPERTY_ID);
     propertyIds.add(ComponentResourceProvider.COMPONENT_INSTALLED_COUNT_PROPERTY_ID);
+    propertyIds.add(ComponentResourceProvider.COMPONENT_INSTALLED_AND_MAINTENANCE_OFF_COUNT_PROPERTY_ID);
     propertyIds.add(ComponentResourceProvider.COMPONENT_INSTALL_FAILED_COUNT_PROPERTY_ID);
     propertyIds.add(ComponentResourceProvider.COMPONENT_INIT_COUNT_PROPERTY_ID);
     propertyIds.add(ComponentResourceProvider.COMPONENT_UNKNOWN_COUNT_PROPERTY_ID);
@@ -311,6 +313,8 @@ public class ComponentResourceProviderTest {
       Assert.assertEquals(0, resource.getPropertyValue(
         ComponentResourceProvider.COMPONENT_INSTALLED_COUNT_PROPERTY_ID));
       Assert.assertEquals(0, resource.getPropertyValue(
+        ComponentResourceProvider.COMPONENT_INSTALLED_AND_MAINTENANCE_OFF_COUNT_PROPERTY_ID));
+      Assert.assertEquals(0, resource.getPropertyValue(
           ComponentResourceProvider.COMPONENT_INSTALL_FAILED_COUNT_PROPERTY_ID));
       Assert.assertEquals(0, resource.getPropertyValue(
           ComponentResourceProvider.COMPONENT_INIT_COUNT_PROPERTY_ID));
@@ -379,6 +383,7 @@ public class ComponentResourceProviderTest {
     Map <String, Integer> serviceComponentStateCountMap = new HashMap<>();
     serviceComponentStateCountMap.put("startedCount", 0);
     serviceComponentStateCountMap.put("installedCount", 1);
+    serviceComponentStateCountMap.put("installedAndMaintenanceOffCount", 0);
     serviceComponentStateCountMap.put("installFailedCount", 0);
     serviceComponentStateCountMap.put("initCount", 0);
     serviceComponentStateCountMap.put("unknownCount", 0);
@@ -691,6 +696,7 @@ public class ComponentResourceProviderTest {
     Map <String, Integer> serviceComponentStateCountMap = new HashMap<>();
     serviceComponentStateCountMap.put("startedCount", 0);
     serviceComponentStateCountMap.put("installedCount", 1);
+    serviceComponentStateCountMap.put("installedAndMaintenanceOffCount", 0);
     serviceComponentStateCountMap.put("installFailedCount", 0);
     serviceComponentStateCountMap.put("initCount", 0);
     serviceComponentStateCountMap.put("unknownCount", 0);

http://git-wip-us.apache.org/repos/asf/ambari/blob/986a65db/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java
index 6320f35..c753f49 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java
@@ -273,15 +273,28 @@ public class ServiceComponentTest {
     service.addServiceComponent(component);
 
     addHostToCluster("h1", service.getCluster().getClusterName());
+    addHostToCluster("h2", service.getCluster().getClusterName());
+    addHostToCluster("h3", service.getCluster().getClusterName());
     ServiceComponentHost sch =
       serviceComponentHostFactory.createNew(component, "h1");
+    ServiceComponentHost sch2 =
+      serviceComponentHostFactory.createNew(component, "h2");
+    ServiceComponentHost sch3 =
+      serviceComponentHostFactory.createNew(component, "h3");
     sch.setState(State.INSTALLED);
+    sch2.setState(State.INSTALLED);
+    sch3.setState(State.INSTALLED);
 
     Map<String, ServiceComponentHost> compHosts =
       new HashMap<>();
     compHosts.put("h1", sch);
+    compHosts.put("h2", sch2);
+    compHosts.put("h3", sch3);
     component.addServiceComponentHosts(compHosts);
-    Assert.assertEquals(1, component.getServiceComponentHosts().size());
+    Assert.assertEquals(3, component.getServiceComponentHosts().size());
+
+    component.getServiceComponentHost("h2").setMaintenanceState(MaintenanceState.ON);
+    sch3.setMaintenanceState(MaintenanceState.ON);
 
     ServiceComponent sc = service.getServiceComponent(componentName);
     Assert.assertNotNull(sc);
@@ -298,9 +311,11 @@ public class ServiceComponentTest {
     int totalCount = r.getServiceComponentStateCount().get("totalCount");
     int startedCount = r.getServiceComponentStateCount().get("startedCount");
     int installedCount = r.getServiceComponentStateCount().get("installedCount");
-    Assert.assertEquals(1, totalCount);
+    int installedAndMaintenanceOffCount = r.getServiceComponentStateCount().get("installedAndMaintenanceOffCount");
+    Assert.assertEquals(3, totalCount);
     Assert.assertEquals(0, startedCount);
-    Assert.assertEquals(1, installedCount);
+    Assert.assertEquals(3, installedCount);
+    Assert.assertEquals(1, installedAndMaintenanceOffCount);
 
     // TODO check configs
     // r.getConfigVersions()


Mime
View raw message