Kaynağa Gözat

AMBARI-1526 - State fields are not returned by default for services.

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/trunk@1451463 13f79535-47bb-0310-9956-ffa450edef68
Tom Beerbower 12 yıl önce
ebeveyn
işleme
b8caaf8c44

+ 8 - 3
CHANGES.txt

@@ -387,7 +387,10 @@ Trunk (unreleased changes):
 
  BUG FIXES
 
- AMBARI-1527. Allow loading of custom configurations in 
+ AMBARI-1526. State fields are not returned by default for services.
+ (tbeerbower)
+
+ AMBARI-1527. Allow loading of custom configurations in
  step7 : "Customize Services" (regression). (jaimin)
 
  AMBARI-1525. ambari.properties file has an invalid character causing
@@ -399,7 +402,8 @@ Trunk (unreleased changes):
  AMBARI-1520. Alerts take around 20-30 seconds to show up everytime you
  refresh the dashboad. (srimanth via yusaku)
 
- AMBARI-1523. Ambari API: Resources doesn't always honor partial response fields restrictions. (tbeerbower)
+ AMBARI-1523. Ambari API: Resources doesn't always honor partial response
+ fields restrictions. (tbeerbower)
 
  AMBARI-1519. Ambari Web goes back and forth between frozen and usable state
  peridocially on a large cluster. (yusaku)
@@ -411,7 +415,8 @@ Trunk (unreleased changes):
  AMBARI-1503. Ajax call sometimes adds multiple question marks in the query
  causing bad requests. (yusaku)
 
- AMBARI-1463. State of HBase region server not updated when instance is shut down on a cluster not installed via Ambari. (tbeerbower)
+ AMBARI-1463. State of HBase region server not updated when instance is shut
+ down on a cluster not installed via Ambari. (tbeerbower)
  
  AMBARI-1494. Browser memory consumption issues. (jaimin)
 

+ 1 - 1
ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerComponentProvider.java

@@ -57,7 +57,7 @@ public class GSInstallerComponentProvider extends GSInstallerResourceProvider{
   public void updateProperties(Resource resource, Request request, Predicate predicate) {
 
     Set<String> propertyIds = getRequestPropertyIds(request, predicate);
-    if (propertyIds.contains(COMPONENT_STATE_PROPERTY_ID)) {
+    if (contains(propertyIds, COMPONENT_STATE_PROPERTY_ID)) {
       String serviceName   = (String) resource.getPropertyValue(COMPONENT_SERVICE_NAME_PROPERTY_ID);
       String componentName = (String) resource.getPropertyValue(COMPONENT_COMPONENT_NAME_PROPERTY_ID);
       resource.setProperty(COMPONENT_STATE_PROPERTY_ID, getClusterDefinition().getComponentState(serviceName, componentName));

+ 2 - 2
ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostComponentProvider.java

@@ -58,8 +58,8 @@ public class GSInstallerHostComponentProvider extends GSInstallerResourceProvide
   @Override
   public void updateProperties(Resource resource, Request request, Predicate predicate) {
     Set<String> propertyIds = getRequestPropertyIds(request, predicate);
-    if (propertyIds.contains(HOST_COMPONENT_STATE_PROPERTY_ID) ||
-        propertyIds.contains(HOST_COMPONENT_DESIRED_STATE_PROPERTY_ID)) {
+    if (contains(propertyIds, HOST_COMPONENT_STATE_PROPERTY_ID) ||
+        contains(propertyIds, HOST_COMPONENT_DESIRED_STATE_PROPERTY_ID)) {
       String serviceName   = (String) resource.getPropertyValue(HOST_COMPONENT_SERVICE_NAME_PROPERTY_ID);
       String componentName = (String) resource.getPropertyValue(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID);
       String hostName      = (String) resource.getPropertyValue(HOST_COMPONENT_HOST_NAME_PROPERTY_ID);

+ 1 - 1
ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostProvider.java

@@ -58,7 +58,7 @@ public class GSInstallerHostProvider extends GSInstallerResourceProvider{
   @Override
   public void updateProperties(Resource resource, Request request, Predicate predicate) {
     Set<String> propertyIds = getRequestPropertyIds(request, predicate);
-    if (propertyIds.contains(HOST_STATE_PROPERTY_ID)) {
+    if (contains(propertyIds, HOST_STATE_PROPERTY_ID)) {
       String hostName = (String) resource.getPropertyValue(HOST_NAME_PROPERTY_ID);
       resource.setProperty(HOST_STATE_PROPERTY_ID, getClusterDefinition().getHostState(hostName));
     }

+ 21 - 0
ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerResourceProvider.java

@@ -167,6 +167,27 @@ public abstract class GSInstallerResourceProvider implements ResourceProvider {
     return propertyIds;
   }
 
+  /**
+   * Check to see if the given set contains a property or category id that matches the given property id.
+   *
+   * @param ids         the set of property/category ids
+   * @param propertyId  the property id
+   *
+   * @return true if the given set contains a property id or category that matches the given property id
+   */
+  protected static boolean contains(Set<String> ids, String propertyId) {
+    boolean contains = ids.contains(propertyId);
+
+    if (!contains) {
+      String category = PropertyHelper.getPropertyCategory(propertyId);
+      while (category != null && !contains) {
+        contains = ids.contains(category);
+        category = PropertyHelper.getPropertyCategory(category);
+      }
+    }
+    return contains;
+  }
+
   /**
   * Add a resource to the set of resources provided by this provider.
   *

+ 1 - 1
ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerServiceProvider.java

@@ -55,7 +55,7 @@ public class GSInstallerServiceProvider extends GSInstallerResourceProvider{
   @Override
   public void updateProperties(Resource resource, Request request, Predicate predicate) {
     Set<String> propertyIds = getRequestPropertyIds(request, predicate);
-    if (propertyIds.contains(SERVICE_SERVICE_STATE_PROPERTY_ID)) {
+    if (contains(propertyIds, SERVICE_SERVICE_STATE_PROPERTY_ID)) {
       String serviceName = (String) resource.getPropertyValue(SERVICE_SERVICE_NAME_PROPERTY_ID);
       resource.setProperty(SERVICE_SERVICE_STATE_PROPERTY_ID, getClusterDefinition().getServiceState(serviceName));
     }

+ 26 - 0
ambari-server/src/test/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostComponentProviderTest.java

@@ -80,6 +80,32 @@ public class GSInstallerHostComponentProviderTest {
     }
   }
 
+  @Test
+  public void testGetResourcesCheckStateFromCategory() throws Exception {
+    TestGSInstallerStateProvider stateProvider = new TestGSInstallerStateProvider();
+    ClusterDefinition clusterDefinition = new ClusterDefinition(stateProvider, 500);
+    GSInstallerResourceProvider provider = new GSInstallerHostComponentProvider(clusterDefinition);
+    Predicate predicate = new PredicateBuilder().property(GSInstallerHostComponentProvider.HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID).equals("HBASE_REGIONSERVER").toPredicate();
+    Set<Resource> resources = provider.getResources(PropertyHelper.getReadRequest("HostRoles"), predicate);
+    Assert.assertEquals(3, resources.size());
+
+    for (Resource resource : resources) {
+      Assert.assertEquals("STARTED", resource.getPropertyValue(GSInstallerHostComponentProvider.HOST_COMPONENT_STATE_PROPERTY_ID));
+    }
+
+    stateProvider.setHealthy(false);
+
+    // need to wait for old state value to expire
+    Thread.sleep(501);
+
+    resources = provider.getResources(PropertyHelper.getReadRequest(), predicate);
+    Assert.assertEquals(3, resources.size());
+
+    for (Resource resource : resources) {
+      Assert.assertEquals("INIT", resource.getPropertyValue(GSInstallerHostComponentProvider.HOST_COMPONENT_STATE_PROPERTY_ID));
+    }
+  }
+
   @Test
   public void testCreateResources() throws Exception {
     ClusterDefinition clusterDefinition = new ClusterDefinition(new TestGSInstallerStateProvider());

+ 25 - 0
ambari-server/src/test/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostProviderTest.java

@@ -84,6 +84,31 @@ public class GSInstallerHostProviderTest {
     Assert.assertEquals("INIT", resource.getPropertyValue(GSInstallerHostProvider.HOST_STATE_PROPERTY_ID));
   }
 
+  @Test
+  public void testGetResourcesCheckStateFromCategory() throws Exception {
+    TestGSInstallerStateProvider stateProvider = new TestGSInstallerStateProvider();
+    ClusterDefinition clusterDefinition = new ClusterDefinition(stateProvider, 500);
+    GSInstallerResourceProvider provider = new GSInstallerHostProvider(clusterDefinition);
+    Predicate predicate = new PredicateBuilder().property(GSInstallerHostProvider.HOST_NAME_PROPERTY_ID).equals("ip-10-190-97-104.ec2.internal").toPredicate();
+    Set<Resource> resources = provider.getResources(PropertyHelper.getReadRequest("Hosts"), predicate);
+    Assert.assertEquals(1, resources.size());
+
+    Resource resource = resources.iterator().next();
+
+    Assert.assertEquals("HEALTHY", resource.getPropertyValue(GSInstallerHostProvider.HOST_STATE_PROPERTY_ID));
+
+    stateProvider.setHealthy(false);
+
+    // need to wait for old state value to expire
+    Thread.sleep(501);
+
+    resources = provider.getResources(PropertyHelper.getReadRequest(), predicate);
+    Assert.assertEquals(1, resources.size());
+
+    resource = resources.iterator().next();
+    Assert.assertEquals("INIT", resource.getPropertyValue(GSInstallerHostProvider.HOST_STATE_PROPERTY_ID));
+  }
+
   @Test
   public void testCreateResources() throws Exception {
     ClusterDefinition clusterDefinition = new ClusterDefinition(new TestGSInstallerStateProvider());

+ 25 - 0
ambari-server/src/test/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerServiceProviderTest.java

@@ -84,6 +84,31 @@ public class GSInstallerServiceProviderTest {
     Assert.assertEquals("INIT", resource.getPropertyValue(GSInstallerServiceProvider.SERVICE_SERVICE_STATE_PROPERTY_ID));
   }
 
+  @Test
+  public void testGetResourcesCheckStateFromCategory() throws Exception {
+    TestGSInstallerStateProvider stateProvider = new TestGSInstallerStateProvider();
+    ClusterDefinition clusterDefinition = new ClusterDefinition(stateProvider, 500);
+    GSInstallerResourceProvider provider = new GSInstallerServiceProvider(clusterDefinition);
+    Predicate predicate = new PredicateBuilder().property(GSInstallerServiceProvider.SERVICE_SERVICE_NAME_PROPERTY_ID).equals("MAPREDUCE").toPredicate();
+    Set<Resource> resources = provider.getResources(PropertyHelper.getReadRequest("ServiceInfo"), predicate);
+    Assert.assertEquals(1, resources.size());
+
+    Resource resource = resources.iterator().next();
+
+    Assert.assertEquals("STARTED", resource.getPropertyValue(GSInstallerServiceProvider.SERVICE_SERVICE_STATE_PROPERTY_ID));
+
+    stateProvider.setHealthy(false);
+
+    // need to wait for old state value to expire
+    Thread.sleep(501);
+
+    resources = provider.getResources(PropertyHelper.getReadRequest(), predicate);
+    Assert.assertEquals(1, resources.size());
+
+    resource = resources.iterator().next();
+    Assert.assertEquals("INIT", resource.getPropertyValue(GSInstallerServiceProvider.SERVICE_SERVICE_STATE_PROPERTY_ID));
+  }
+
   @Test
   public void testCreateResources() throws Exception {
     ClusterDefinition clusterDefinition = new ClusterDefinition(new TestGSInstallerStateProvider());