Browse Source

AMBARI-6263 API call to /hosts to get information about 10 hosts takes more than 30 seconds on 2K-node cluster (dsen)

Dmytro Sen 11 years ago
parent
commit
a17359c97c
22 changed files with 256 additions and 137 deletions
  1. 25 20
      ambari-server/src/main/java/org/apache/ambari/server/api/query/QueryImpl.java
  2. 2 2
      ambari-server/src/main/java/org/apache/ambari/server/api/services/BaseRequest.java
  3. 32 30
      ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProvider.java
  4. 4 0
      ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaReportPropertyProvider.java
  5. 16 16
      ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java
  6. 19 5
      ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterControllerImpl.java
  7. 26 0
      ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ResourceImpl.java
  8. 24 21
      ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProvider.java
  9. 3 1
      ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXPropertyProvider.java
  10. 10 6
      ambari-server/src/main/java/org/apache/ambari/server/controller/nagios/NagiosPropertyProvider.java
  11. 9 4
      ambari-server/src/main/java/org/apache/ambari/server/controller/spi/ClusterController.java
  12. 13 0
      ambari-server/src/main/java/org/apache/ambari/server/controller/spi/Resource.java
  13. 3 3
      ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java
  14. 2 2
      ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyListAdapter.java
  15. 3 3
      ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyMapAdapter.java
  16. 2 2
      ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyValAdapter.java
  17. 15 0
      ambari-server/src/test/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProviderTest.java
  18. 1 0
      ambari-server/src/test/java/org/apache/ambari/server/controller/ganglia/GangliaReportPropertyProviderTest.java
  19. 13 13
      ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterControllerImplTest.java
  20. 16 9
      ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProviderTest.java
  21. 10 0
      ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/JMXPropertyProviderTest.java
  22. 8 0
      ambari-server/src/test/java/org/apache/ambari/server/controller/nagios/NagiosPropertyProviderTest.java

+ 25 - 20
ambari-server/src/main/java/org/apache/ambari/server/api/query/QueryImpl.java

@@ -337,10 +337,9 @@ public class QueryImpl implements Query, ResourceInstance {
     Request       request     = createRequest();
     Set<Resource> resourceSet = new LinkedHashSet<Resource>();
 
-    for (Resource queryResource : doQuery(resourceType, request, queryPredicate)) {
-      providerResourceSet.add(queryResource);
-      resourceSet.add(queryResource);
-    }
+    Set<Resource> queryResources = doQuery(resourceType, request, queryPredicate, pageRequest, sortRequest);
+    providerResourceSet.addAll(queryResources);
+    resourceSet.addAll(queryResources);
 
     queryResults.put(null, new QueryResult(
         request, queryPredicate, userPredicate, getKeyValueMap(), resourceSet));
@@ -367,21 +366,23 @@ public class QueryImpl implements Query, ResourceInstance {
 
       for (QueryResult queryResult : queryResults.values()) {
         for (Resource resource : queryResult.getProviderResourceSet()) {
-          Map<Resource.Type, String> map = getKeyValueMap(resource, queryResult.getKeyValueMap());
-
-          Predicate     queryPredicate = subResource.createPredicate(map, subResource.processedPredicate);
-          Set<Resource> resourceSet    = new LinkedHashSet<Resource>();
-
-          try {
-            for (Resource queryResource : subResource.doQuery(resourceType, request, queryPredicate)) {
-              providerResourceSet.add(queryResource);
-              resourceSet.add(queryResource);
+          if (resource.getPopulateRequiredFlag()) {
+            Map<Resource.Type, String> map = getKeyValueMap(resource, queryResult.getKeyValueMap());
+
+            Predicate     queryPredicate = subResource.createPredicate(map, subResource.processedPredicate);
+            Set<Resource> resourceSet    = new LinkedHashSet<Resource>();
+
+            try {
+              Set<Resource> queryResources =
+              subResource.doQuery(resourceType, request, queryPredicate, null, null);
+              providerResourceSet.addAll(queryResources);
+              resourceSet.addAll(queryResources);
+            } catch (NoSuchResourceException e) {
+              // do nothing ...
             }
-          } catch (NoSuchResourceException e) {
-            // do nothing ...
+            subResource.queryResults.put(resource,
+                new QueryResult(request, queryPredicate, subResourcePredicate, map, resourceSet));
           }
-          subResource.queryResults.put(resource,
-              new QueryResult(request, queryPredicate, subResourcePredicate, map, resourceSet));
         }
       }
       clusterController.populateResources(resourceType, providerResourceSet, request, null);
@@ -392,7 +393,8 @@ public class QueryImpl implements Query, ResourceInstance {
   /**
    * Query the cluster controller for the resources.
    */
-  private Set<Resource> doQuery(Resource.Type type, Request request, Predicate predicate)
+  private Set<Resource> doQuery(Resource.Type type, Request request,
+      Predicate predicate, PageRequest pageRequest, SortRequest sortRequest)
       throws UnsupportedPropertyException,
       SystemException,
       NoSuchResourceException,
@@ -401,8 +403,11 @@ public class QueryImpl implements Query, ResourceInstance {
     if (LOG.isDebugEnabled()) {
       LOG.debug("Executing resource query: " + request + " where " + predicate);
     }
-
-    return clusterController.getResources(type, request, predicate);
+    if (userPredicate != null) {
+      pageRequest = null;
+      sortRequest = null;
+    }
+    return clusterController.getResources(type, request, predicate, pageRequest, sortRequest);
   }
 
   /**

+ 2 - 2
ambari-server/src/main/java/org/apache/ambari/server/api/services/BaseRequest.java

@@ -244,14 +244,14 @@ public abstract class BaseRequest implements Request {
       if(from.equals("start")) {
         startingPoint = PageRequest.StartingPoint.Beginning;
       } else {
-        offset = Integer.valueOf(from);
+        offset = Integer.parseInt(from);
         startingPoint = PageRequest.StartingPoint.OffsetStart;
       }
     } else if (to != null ) {
       if (to.equals("end")) {
         startingPoint = PageRequest.StartingPoint.End;
       } else {
-        offset = Integer.valueOf(to);
+        offset = Integer.parseInt(to);
         startingPoint = PageRequest.StartingPoint.OffsetEnd;
       }
     } else {

+ 32 - 30
ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProvider.java

@@ -205,47 +205,49 @@ public abstract class GangliaPropertyProvider extends AbstractPropertyProvider {
         new HashMap<String, Map<TemporalInfo, RRDRequest>>();
 
     for (Resource resource : resources) {
-      String clusterName = (String) resource.getPropertyValue(clusterNamePropertyId);
-      Map<TemporalInfo, RRDRequest> requests = requestMap.get(clusterName);
-      if (requests == null) {
-        requests = new HashMap<TemporalInfo, RRDRequest>();
-        requestMap.put(clusterName, requests);
-      }
+      if (resource.getPopulateRequiredFlag()) {
+        String clusterName = (String) resource.getPropertyValue(clusterNamePropertyId);
+        Map<TemporalInfo, RRDRequest> requests = requestMap.get(clusterName);
+        if (requests == null) {
+          requests = new HashMap<TemporalInfo, RRDRequest>();
+          requestMap.put(clusterName, requests);
+        }
 
-      Set<String> gangliaClusterNames = getGangliaClusterNames(resource, clusterName);
+        Set<String> gangliaClusterNames = getGangliaClusterNames(resource, clusterName);
 
-      for (String gangliaClusterName : gangliaClusterNames) {
-        ResourceKey key =
+        for (String gangliaClusterName : gangliaClusterNames) {
+          ResourceKey key =
             new ResourceKey(getHostName(resource), gangliaClusterName);
 
-        for (String id : ids) {
-          Map<String, PropertyInfo> propertyInfoMap = new HashMap<String, PropertyInfo>();
+          for (String id : ids) {
+            Map<String, PropertyInfo> propertyInfoMap = new HashMap<String, PropertyInfo>();
 
-          Map<String, PropertyInfo> componentMetricMap =
-            getComponentMetrics().get(getComponentName(resource));
+            Map<String, PropertyInfo> componentMetricMap =
+              getComponentMetrics().get(getComponentName(resource));
 
-          // Not all components have metrics
-          if (componentMetricMap != null &&
+            // Not all components have metrics
+            if (componentMetricMap != null &&
               !componentMetricMap.containsKey(id)) {
-            updateComponentMetricMap(componentMetricMap, id);
-          }
+              updateComponentMetricMap(componentMetricMap, id);
+            }
 
-          getPropertyInfoMap(getComponentName(resource), id, propertyInfoMap);
+            getPropertyInfoMap(getComponentName(resource), id, propertyInfoMap);
 
-          for (Map.Entry<String, PropertyInfo> entry : propertyInfoMap.entrySet()) {
-            String propertyId = entry.getKey();
-            PropertyInfo propertyInfo = entry.getValue();
+            for (Map.Entry<String, PropertyInfo> entry : propertyInfoMap.entrySet()) {
+              String propertyId = entry.getKey();
+              PropertyInfo propertyInfo = entry.getValue();
 
-            TemporalInfo temporalInfo = request.getTemporalInfo(id);
+              TemporalInfo temporalInfo = request.getTemporalInfo(id);
 
-            if ((temporalInfo == null && propertyInfo.isPointInTime()) || (temporalInfo != null && propertyInfo.isTemporal())) {
-              RRDRequest rrdRequest = requests.get(temporalInfo);
-              if (rrdRequest == null) {
-                rrdRequest = new RRDRequest(clusterName, temporalInfo);
-                requests.put(temporalInfo, rrdRequest);
+              if ((temporalInfo == null && propertyInfo.isPointInTime()) || (temporalInfo != null && propertyInfo.isTemporal())) {
+                RRDRequest rrdRequest = requests.get(temporalInfo);
+                if (rrdRequest == null) {
+                  rrdRequest = new RRDRequest(clusterName, temporalInfo);
+                  requests.put(temporalInfo, rrdRequest);
+                }
+                rrdRequest.putResource(key, resource);
+                rrdRequest.putPropertyId(propertyInfo.getPropertyId(), propertyId);
               }
-              rrdRequest.putResource(key, resource);              
-              rrdRequest.putPropertyId(propertyInfo.getPropertyId(), propertyId);
             }
           }
         }
@@ -502,7 +504,7 @@ public abstract class GangliaPropertyProvider extends AbstractPropertyProvider {
 
           while(val!=null && !"[~EOM]".equals(val)) {
             if (val.startsWith("[~r]")) {
-              Integer repeat = Integer.valueOf(val.substring(4)) - 1;
+              int repeat = Integer.parseInt(val.substring(4)) - 1;
               for (int i = 0; i < repeat; ++i) {
                 if (! "[~n]".equals(lastVal)) {
                   GangliaMetric.TemporalMetric tm = new GangliaMetric.TemporalMetric(lastVal, time);

+ 4 - 0
ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaReportPropertyProvider.java

@@ -104,6 +104,10 @@ public class GangliaReportPropertyProvider extends AbstractPropertyProvider {
   private boolean populateResource(Resource resource, Request request, Predicate predicate)
       throws SystemException {
 
+    if (!resource.getPopulateRequiredFlag()) {
+      return false;
+    }
+
     Set<String> propertyIds = getPropertyIds();
 
     if (propertyIds.isEmpty()) {

+ 16 - 16
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java

@@ -70,8 +70,8 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
   private static final String GANGLIA_SERVER                            = "GANGLIA_SERVER";
   private static final String PROPERTIES_CATEGORY = "properties";
   private static final Map<Service.Type, String> serviceConfigVersions = new ConcurrentHashMap<Service.Type, String>();
-  private static final Map<Service.Type, String> serviceConfigTypes = new HashMap<Service.Type, String>();
-  private static final Map<Service.Type, Map<String, String[]>> serviceDesiredProperties = new HashMap<Service.Type, Map<String, String[]>>();
+  private static final Map<Service.Type, String> serviceConfigTypes = new EnumMap<Service.Type, String>(Service.Type.class);
+  private static final Map<Service.Type, Map<String, String[]>> serviceDesiredProperties = new EnumMap<Service.Type, Map<String, String[]>>(Service.Type.class);
   private static final Map<String, Service.Type> componentServiceMap = new HashMap<String, Service.Type>();
   
   private static final Map<String, Map<String, String[]>> jmxDesiredProperties = new HashMap<String, Map<String,String[]>>();
@@ -244,12 +244,12 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
             currVersion, serviceConfigTypes.get(service),
             serviceDesiredProperties.get(service));
           
-          for (String compName : portMap.keySet()) {
+          for (Entry<String, String> entry : portMap.entrySet()) {
             // portString will be null if the property defined for the component doesn't exist
             // this will trigger using the default port for the component
-            String portString = getPortString(portMap.get(compName));
+            String portString = getPortString(entry.getValue());
             if (null != portString)
-              clusterJmxPorts.put(compName, portString);
+              clusterJmxPorts.put(entry.getKey(), portString);
           }
         }
       } catch (Exception e) {
@@ -279,17 +279,17 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
           Map<String, String> refMap = new HashMap<String, String>();
           while(refValueString.contains("${")) {
               int startValueRef = refValueString.indexOf("${") + 2;
-              int endValueRef = refValueString.indexOf("}");
+              int endValueRef = refValueString.indexOf('}');
               String valueRef = refValueString.substring(startValueRef, endValueRef);
               refValueString = refValueString.substring(endValueRef+1);
               String trueValue = (String) postProcessPropertyValue(valueRef, properties.get(valueRef), properties, prevProps);
               if (trueValue != null){
-               refMap.put("${"+valueRef+"}", trueValue);
+               refMap.put("${"+valueRef+ '}', trueValue);
               } 
           }
-          for (String keyRef : refMap.keySet()){
-            refValueString = refMap.get(keyRef);
-            value = ((String)value).replace(keyRef, refValueString);
+          for (Entry<String, String> entry : refMap.entrySet()){
+            refValueString = entry.getValue();
+            value = ((String)value).replace(entry.getKey(), refValueString);
           }
           properties.put(key, value);
     }
@@ -655,7 +655,7 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
     Map<String, String> mConfigs = new HashMap<String, String>();
     if (configResources != null) {
       for (Resource res : configResources) {
-       Map<String, String> evalutedProperties = null;                      
+       Map<String, String> evaluatedProperties = null;
         for (Entry<String,String[]> entry : keys.entrySet()) {
           String propName = null;
           String value = null;
@@ -669,8 +669,8 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
           }
           
           if (value != null && value.contains("${")) {
-            if (evalutedProperties == null){
-              evalutedProperties = new HashMap<String, String>();
+            if (evaluatedProperties == null){
+              evaluatedProperties = new HashMap<String, String>();
               Map<String, Object> properties = res.getPropertiesMap().get(PROPERTIES_CATEGORY);
               for (Map.Entry<String, Object> subentry : properties.entrySet()) {
                 String keyString = subentry.getKey();
@@ -678,13 +678,13 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
                 String valueString;
                 if (object != null && object instanceof String){
                   valueString = (String)object;
-                  evalutedProperties.put(keyString, valueString);
-                  postProcessPropertyValue(keyString, valueString, evalutedProperties, null);
+                  evaluatedProperties.put(keyString, valueString);
+                  postProcessPropertyValue(keyString, valueString, evaluatedProperties, null);
                 }
               }              
             }
           }
-          value = postProcessPropertyValue(propName, value, evalutedProperties, null);
+          value = postProcessPropertyValue(propName, value, evaluatedProperties, null);
           LOG.debug("PROPERTY -> key: " + propName + ", " + "value: " + value);
           
           mConfigs.put(entry.getKey(), value);

+ 19 - 5
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterControllerImpl.java

@@ -110,7 +110,8 @@ public class ClusterControllerImpl implements ClusterController {
   // ----- ClusterController -------------------------------------------------
 
   @Override
-  public Set<Resource> getResources(Type type, Request request, Predicate predicate)
+  public Set<Resource> getResources(Type type, Request request,
+      Predicate predicate, PageRequest pageRequest, SortRequest sortRequest)
       throws UnsupportedPropertyException, NoSuchResourceException,
              NoSuchParentResourceException, SystemException {
     Set<Resource> resources;
@@ -132,6 +133,17 @@ public class ClusterControllerImpl implements ClusterController {
 
       // get the resources
       resources = provider.getResources(request, predicate);
+      Iterable<Resource> resourceIterable = resources;
+
+      //populate only resources in pageRequest
+      if ((pageRequest != null) || (sortRequest != null)) {
+        PageResponse page = getPage(type, resources, request, predicate, pageRequest, sortRequest);
+        resourceIterable = page.getIterable();
+      }
+
+      for (Resource resource: resourceIterable) {
+        resource.setPopulateRequiredFlag(true);
+      }
     }
     return resources;
   }
@@ -360,7 +372,7 @@ public class ClusterControllerImpl implements ClusterController {
       SystemException,
       NoSuchParentResourceException,
       NoSuchResourceException {
-    return getResources(type, request, predicate, null, null).getIterable();
+    return getPageResponse(type, request, predicate, null, null).getIterable();
   }
 
   /**
@@ -371,6 +383,7 @@ public class ClusterControllerImpl implements ClusterController {
    * @param request      the request
    * @param predicate    the predicate object which filters which resources are returned
    * @param pageRequest  the page request for a paginated response
+   * @param sortRequest  the sortRequest object which defines if the resources need to be sorted
    *
    * @return a page response representing the requested page of resources
    *
@@ -380,14 +393,15 @@ public class ClusterControllerImpl implements ClusterController {
    * @throws NoSuchResourceException no matching resource(s) found
    * @throws NoSuchParentResourceException a specified parent resource doesn't exist
    */
-  protected  PageResponse getResources(Type type, Request request, Predicate predicate,
-                                       PageRequest pageRequest, SortRequest sortRequest)
+  protected  PageResponse getPageResponse(Type type, Request request, Predicate predicate,
+                                          PageRequest pageRequest, SortRequest sortRequest)
       throws UnsupportedPropertyException,
       SystemException,
       NoSuchResourceException,
       NoSuchParentResourceException {
 
-    Set<Resource> providerResources = getResources(type, request, predicate);
+    Set<Resource> providerResources =
+      getResources(type, request, predicate, pageRequest, sortRequest);
     populateResources(type, providerResources, request, predicate);
     return getPage(type, providerResources, request, predicate, pageRequest, sortRequest);
   }

+ 26 - 0
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ResourceImpl.java

@@ -36,6 +36,11 @@ public class ResourceImpl implements Resource {
    */
   private final Type type;
 
+  /**
+   * The resource populateRequiredFlag
+   */
+  private boolean populateRequiredFlag;
+
   /**
    * The map of property maps keyed by property category.
    */
@@ -131,6 +136,25 @@ public class ResourceImpl implements Resource {
         null : properties.get(PropertyHelper.getPropertyName(id));
   }
 
+  /**
+   * Get the populateRequiredFlag
+   *
+   * @return the resource populateRequiredFlag
+   */
+  @Override
+  public boolean getPopulateRequiredFlag() {
+    return populateRequiredFlag;
+  }
+
+  /**
+   * Set a populateRequiredFlag on this resource.
+   *
+   * @param populateRequiredFlag
+   */
+  @Override
+  public void setPopulateRequiredFlag(boolean populateRequiredFlag) {
+    this.populateRequiredFlag = populateRequiredFlag;
+  }
 
   // ----- Object overrides --------------------------------------------------
 
@@ -166,4 +190,6 @@ public class ResourceImpl implements Resource {
   private String getCategoryKey(String category) {
     return category == null ? "" : category;
   }
+
+
 }

+ 24 - 21
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProvider.java

@@ -128,30 +128,33 @@ public class StackDefinedPropertyProvider implements PropertyProvider {
     
     try {
       for (Resource r : resources) {
-        String clusterName = r.getPropertyValue(clusterNamePropertyId).toString();
-        String componentName = r.getPropertyValue(componentNamePropertyId).toString();
-        
-        Cluster cluster = clusters.getCluster(clusterName);
-        StackId stack = cluster.getDesiredStackVersion();
-        String svc = metaInfo.getComponentToService(stack.getStackName(),
+        if (r.getPopulateRequiredFlag()) {
+          String clusterName = r.getPropertyValue(clusterNamePropertyId).toString();
+          String componentName = r.getPropertyValue(componentNamePropertyId).toString();
+
+          Cluster cluster = clusters.getCluster(clusterName);
+          StackId stack = cluster.getDesiredStackVersion();
+          String svc = metaInfo.getComponentToService(stack.getStackName(),
             stack.getStackVersion(), componentName);
-        
-        List<MetricDefinition> defs = metaInfo.getMetrics(
+
+          List<MetricDefinition> defs = metaInfo.getMetrics(
             stack.getStackName(), stack.getStackVersion(), svc, componentName, type.name());
-        
-        if (null == defs || 0 == defs.size())
-          continue;
-        
-        for (MetricDefinition m : defs) {
-          if (m.getType().equals("ganglia")) {
-            gangliaMap.put(componentName, getPropertyInfo(m));
-          } else if (m.getType().equals("jmx")) {
-            jmxMap.put(componentName, getPropertyInfo(m));
-          } else {
-            PropertyProvider pp = getDelegate(m);
-            if (null != pp)
-              additional.add(pp);
+
+          if (null == defs || 0 == defs.size())
+            continue;
+
+          for (MetricDefinition m : defs) {
+            if (m.getType().equals("ganglia")) {
+              gangliaMap.put(componentName, getPropertyInfo(m));
+            } else if (m.getType().equals("jmx")) {
+              jmxMap.put(componentName, getPropertyInfo(m));
+            } else {
+              PropertyProvider pp = getDelegate(m);
+              if (null != pp)
+                additional.add(pp);
+            }
           }
+
         }
       }
         

+ 3 - 1
ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXPropertyProvider.java

@@ -193,7 +193,9 @@ public class JMXPropertyProvider extends AbstractPropertyProvider {
     // In a large cluster we could have thousands of resources to populate here.
     // Distribute the work across multiple threads.
     for (Resource resource : resources) {
-      completionService.submit(getPopulateResourceCallable(resource, request, predicate));
+      if (resource.getPopulateRequiredFlag()) {
+        completionService.submit(getPopulateResourceCallable(resource, request, predicate));
+      }
     }
 
     Set<Resource> keepers = new HashSet<Resource>();

+ 10 - 6
ambari-server/src/main/java/org/apache/ambari/server/controller/nagios/NagiosPropertyProvider.java

@@ -177,8 +177,12 @@ public class NagiosPropertyProvider extends BaseProvider implements PropertyProv
     Set<String> propertyIds = getRequestPropertyIds(request, predicate);
     
     for (Resource res : resources) {
+      if (!res.getPopulateRequiredFlag()) {
+        continue;
+      }
+
       String matchValue = res.getPropertyValue(resourceTypeProperty).toString();
-      
+
       if (null == matchValue)
         continue;
 
@@ -189,18 +193,18 @@ public class NagiosPropertyProvider extends BaseProvider implements PropertyProv
       final String clusterName = clusterPropertyValue.toString();
       if (null == clusterName)
         continue;
-      
+
       if (!CLUSTER_ALERTS.containsKey(clusterName)) {
         // prevent endless looping for the first-time collection
         CLUSTER_ALERTS.put(clusterName, Collections.<NagiosAlert>emptyList());
-        
+
         Future<List<NagiosAlert>> f = scheduler.submit(new Callable<List<NagiosAlert>>() {
           @Override
           public List<NagiosAlert> call() throws Exception {
             return populateAlerts(clusterName);
           }
         });
-        
+
         if (waitOnFirstCall) {
           try {
             CLUSTER_ALERTS.put(clusterName, f.get());
@@ -210,9 +214,9 @@ public class NagiosPropertyProvider extends BaseProvider implements PropertyProv
           }
         }
       }
-      
+
       CLUSTER_NAMES.add(clusterName);
-      
+
       List<NagiosAlert> alerts = CLUSTER_ALERTS.get(clusterName);
       if (null != alerts) {
         updateAlerts (res, matchValue, alerts, propertyIds);

+ 9 - 4
ambari-server/src/main/java/org/apache/ambari/server/controller/spi/ClusterController.java

@@ -33,9 +33,11 @@ public interface ClusterController extends SchemaFactory {
    * Get the resources of the given type filtered by the given request and
    * predicate objects.
    *
-   * @param type      the type of the requested resources
-   * @param request   the request object which defines the desired set of properties
-   * @param predicate the predicate object which filters which resources are returned
+   * @param type        the type of the requested resources
+   * @param request     the request object which defines the desired set of properties
+   * @param predicate   the predicate object which filters which resources are returned
+   * @param pageRequest the page request for a paginated response
+   * @param sortRequest the sortRequest object which defines if the resources need to be sorted
    *
    * @return an iterable object of the requested resources
    *
@@ -45,7 +47,8 @@ public interface ClusterController extends SchemaFactory {
    * @throws NoSuchResourceException no matching resource(s) found
    * @throws NoSuchParentResourceException a specified parent resource doesn't exist
    */
-  Set<Resource> getResources(Resource.Type type, Request request, Predicate predicate)
+  Set<Resource> getResources(Resource.Type type, Request request,
+      Predicate predicate, PageRequest pageRequest, SortRequest sortRequest)
       throws UnsupportedPropertyException,
       NoSuchResourceException,
       NoSuchParentResourceException,
@@ -78,6 +81,8 @@ public interface ClusterController extends SchemaFactory {
    * @param providerResources  set of populated Resources
    * @param request            the request
    * @param predicate          the predicate object which filters which resources are returned
+   * @param pageRequest        the page request for a paginated response
+   * @param sortRequest        the sortRequest object which defines if the resources need to be sorted
    *
    * @return a page response representing the requested page of resources
    *

+ 13 - 0
ambari-server/src/main/java/org/apache/ambari/server/controller/spi/Resource.java

@@ -67,6 +67,19 @@ public interface Resource {
    */
   public Object getPropertyValue(String id);
 
+  /**
+   * Get the populateRequiredFlag
+   *
+   * @return the resource populateRequiredFlag
+   */
+  public boolean getPopulateRequiredFlag();
+
+  /**
+   * Set a populateRequiredFlag on this resource.
+   *
+   * @param populateRequiredFlag
+   */
+  public void setPopulateRequiredFlag(boolean populateRequiredFlag);
 
   // ----- Enum : InternalType -----------------------------------------------
 

+ 3 - 3
ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java

@@ -89,7 +89,7 @@ public class HostImpl implements Host {
   private static final String TIMEZONE = "timezone";
   private static final String OS_RELEASE_VERSION = "os_release_version";
 
-  
+
   private final Gson gson;
 
   private static final Type hostAttributesType =
@@ -97,7 +97,7 @@ public class HostImpl implements Host {
   private static final Type maintMapType =
       new TypeToken<Map<Long, MaintenanceState>>() {}.getType();
 
-  ReadWriteLock rwLock;
+  private final ReadWriteLock rwLock;
   private final Lock readLock;
   private final Lock writeLock;
 
@@ -361,7 +361,7 @@ public class HostImpl implements Host {
   }
 
   /**
-   * @param hostInfo
+   * @param hostInfo to be imported
    */
   @Override
   public void importHostInfo(HostInfo hostInfo) {

+ 2 - 2
ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyListAdapter.java

@@ -34,8 +34,8 @@ public class JaxbMapKeyListAdapter extends
     }
     JaxbMapKeyList[] list = new JaxbMapKeyList[map.size()] ;
     int index = 0;
-    for (String key : map.keySet()) {
-      JaxbMapKeyList jaxbMap = new JaxbMapKeyList(key, map.get(key));
+    for (Map.Entry<String, List<String>> stringListEntry : map.entrySet()) {
+      JaxbMapKeyList jaxbMap = new JaxbMapKeyList(stringListEntry.getKey(), stringListEntry.getValue());
       list[index++] = jaxbMap;
     }
     return list;

+ 3 - 3
ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyMapAdapter.java

@@ -35,10 +35,10 @@ public class JaxbMapKeyMapAdapter extends
     }
     JaxbMapKeyMap[] list = new JaxbMapKeyMap[map.size()];
     int index=0;
-    for (String key : map.keySet()) {
-      Map<String, String> value = map.get(key);
+    for (Map.Entry<String, Map<String, String>> stringMapEntry : map.entrySet()) {
+      Map<String, String> value = stringMapEntry.getValue();
       JaxbMapKeyVal[] keyValList = mapAdapter.marshal(value);
-      list[index++] = new JaxbMapKeyMap(key, keyValList);
+      list[index++] = new JaxbMapKeyMap(stringMapEntry.getKey(), keyValList);
     }
     return list;
   }

+ 2 - 2
ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyValAdapter.java

@@ -32,8 +32,8 @@ public class JaxbMapKeyValAdapter extends
     }
     JaxbMapKeyVal[] list = new JaxbMapKeyVal[m.size()] ;
     int index = 0;
-    for (String key : m.keySet()) {
-      JaxbMapKeyVal jaxbMap = new JaxbMapKeyVal(key, m.get(key));
+    for (Map.Entry<String, String> entry : m.entrySet()) {
+      JaxbMapKeyVal jaxbMap = new JaxbMapKeyVal(entry.getKey(), entry.getValue());
       list[index++] = jaxbMap;
     }
     return list;

+ 15 - 0
ambari-server/src/test/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProviderTest.java

@@ -115,6 +115,7 @@ public class GangliaPropertyProviderTest {
 
     resource.setProperty(HOST_NAME_PROPERTY_ID, "domU-12-31-39-0E-34-E1.compute-1.internal");
     resource.setProperty(COMPONENT_NAME_PROPERTY_ID, "DATANODE");
+    resource.setPopulateRequiredFlag(true);
 
     // only ask for one property
     Map<String, TemporalInfo> temporalInfoMap = new HashMap<String, TemporalInfo>();
@@ -136,6 +137,7 @@ public class GangliaPropertyProviderTest {
     resource = new ResourceImpl(Resource.Type.HostComponent);
     resource.setProperty(HOST_NAME_PROPERTY_ID, "domU-12-31-39-0E-34-E1.compute-1.internal");
     resource.setProperty(COMPONENT_NAME_PROPERTY_ID, "TASKTRACKER");
+    resource.setPopulateRequiredFlag(true);
 
     // only ask for one property
     temporalInfoMap = new HashMap<String, TemporalInfo>();
@@ -228,6 +230,7 @@ public class GangliaPropertyProviderTest {
 
     resource.setProperty(HOST_NAME_PROPERTY_ID, "domU-12-31-39-0E-34-E1.compute-1.internal");
     resource.setProperty(COMPONENT_NAME_PROPERTY_ID, "DATANODE");
+    resource.setPopulateRequiredFlag(true);
 
     // only ask for one property
     Map<String, TemporalInfo> temporalInfoMap = new HashMap<String, TemporalInfo>();
@@ -266,6 +269,7 @@ public class GangliaPropertyProviderTest {
     // host
     Resource resource = new ResourceImpl(Resource.Type.Host);
     resource.setProperty(HOST_NAME_PROPERTY_ID, "corp-hadoopda05.client.ext");
+    resource.setPopulateRequiredFlag(true);
 
     // only ask for one property
     Map<String, TemporalInfo> temporalInfoMap = new HashMap<String, TemporalInfo>();
@@ -301,13 +305,16 @@ public class GangliaPropertyProviderTest {
     // host
     Resource resource = new ResourceImpl(Resource.Type.Host);
     resource.setProperty(HOST_NAME_PROPERTY_ID, "domU-12-31-39-0E-34-E1.compute-1.internal");
+    resource.setPopulateRequiredFlag(true);
     resources.add(resource);
 
     resource = new ResourceImpl(Resource.Type.Host);
     resource.setProperty(HOST_NAME_PROPERTY_ID, "domU-12-31-39-0E-34-E2.compute-1.internal");
+    resource.setPopulateRequiredFlag(true);
     resources.add(resource);
 
     resource = new ResourceImpl(Resource.Type.Host);
+    resource.setPopulateRequiredFlag(true);
     resource.setProperty(HOST_NAME_PROPERTY_ID, "domU-12-31-39-0E-34-E3.compute-1.internal");
     resources.add(resource);
 
@@ -361,6 +368,7 @@ public class GangliaPropertyProviderTest {
     for (int i = 0; i < 150; ++i) {
       Resource resource = new ResourceImpl(Resource.Type.Host);
       resource.setProperty(HOST_NAME_PROPERTY_ID, "host" + i);
+      resource.setPopulateRequiredFlag(true);
       resources.add(resource);
       
       if (hostsList.length() != 0)
@@ -419,6 +427,7 @@ public class GangliaPropertyProviderTest {
 
     resource.setProperty(HOST_NAME_PROPERTY_ID, "ip-10-39-113-33.ec2.internal");
     resource.setProperty(COMPONENT_NAME_PROPERTY_ID, "FLUME_HANDLER");
+    resource.setPopulateRequiredFlag(true);
 
     // only ask for one property
     Map<String, TemporalInfo> temporalInfoMap = new HashMap<String, TemporalInfo>();
@@ -477,6 +486,7 @@ public class GangliaPropertyProviderTest {
 
     resource.setProperty(HOST_NAME_PROPERTY_ID, "ip-10-39-113-33.ec2.internal");
     resource.setProperty(COMPONENT_NAME_PROPERTY_ID, "FLUME_HANDLER");
+    resource.setPopulateRequiredFlag(true);
 
     // only ask for one property
     Map<String, TemporalInfo> temporalInfoMap = new HashMap<String, TemporalInfo>();
@@ -539,6 +549,7 @@ public class GangliaPropertyProviderTest {
 
     resource.setProperty(HOST_NAME_PROPERTY_ID, "ip-10-39-113-33.ec2.internal");
     resource.setProperty(COMPONENT_NAME_PROPERTY_ID, "FLUME_HANDLER");
+    resource.setPopulateRequiredFlag(true);
 
     Map<String, TemporalInfo> temporalInfoMap = new HashMap<String, TemporalInfo>();
     Request  request = PropertyHelper.getReadRequest(Collections.<String>emptySet(), temporalInfoMap);
@@ -574,6 +585,7 @@ public class GangliaPropertyProviderTest {
 
     resource.setProperty(HOST_NAME_PROPERTY_ID, "ip-10-39-113-33.ec2.internal");
     resource.setProperty(COMPONENT_NAME_PROPERTY_ID, "FLUME_HANDLER");
+    resource.setPopulateRequiredFlag(true);
 
     // only ask for one property
     Map<String, TemporalInfo> temporalInfoMap = new HashMap<String, TemporalInfo>();
@@ -632,6 +644,7 @@ public class GangliaPropertyProviderTest {
 
     resource.setProperty(HOST_NAME_PROPERTY_ID, "ip-10-39-113-33.ec2.internal");
     resource.setProperty(COMPONENT_NAME_PROPERTY_ID, "FLUME_HANDLER");
+    resource.setPopulateRequiredFlag(true);
 
     // only ask for one property
     Map<String, TemporalInfo> temporalInfoMap = new HashMap<String, TemporalInfo>();
@@ -690,6 +703,7 @@ public class GangliaPropertyProviderTest {
 
     resource.setProperty(HOST_NAME_PROPERTY_ID, "ip-10-39-113-33.ec2.internal");
     resource.setProperty(COMPONENT_NAME_PROPERTY_ID, "FLUME_HANDLER");
+    resource.setPopulateRequiredFlag(true);
 
     // only ask for one property
     Map<String, TemporalInfo> temporalInfoMap = new HashMap<String, TemporalInfo>();
@@ -749,6 +763,7 @@ public class GangliaPropertyProviderTest {
 
     resource.setProperty(HOST_NAME_PROPERTY_ID, "ip-10-39-113-33.ec2.internal");
     resource.setProperty(COMPONENT_NAME_PROPERTY_ID, "FLUME_HANDLER");
+    resource.setPopulateRequiredFlag(true);
 
     // only ask for one property
     Map<String, TemporalInfo> temporalInfoMap = new HashMap<String, TemporalInfo>();

+ 1 - 0
ambari-server/src/test/java/org/apache/ambari/server/controller/ganglia/GangliaReportPropertyProviderTest.java

@@ -86,6 +86,7 @@ public class GangliaReportPropertyProviderTest {
     Resource resource = new ResourceImpl(Resource.Type.Cluster);
 
     resource.setProperty(CLUSTER_NAME_PROPERTY_ID, "c1");
+    resource.setPopulateRequiredFlag(true);
 
     // only ask for one property
     Map<String, TemporalInfo> temporalInfoMap = new HashMap<String, TemporalInfo>();

+ 13 - 13
ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterControllerImplTest.java

@@ -138,7 +138,7 @@ public class ClusterControllerImplTest {
 
     // get the first two
     PageRequest pageRequest = new PageRequestImpl(PageRequest.StartingPoint.Beginning, 2, 0, null, null);
-    PageResponse pageResponse = controller.getResources(Resource.Type.Host, request, null, pageRequest, null);
+    PageResponse pageResponse = controller.getPageResponse(Resource.Type.Host, request, null, pageRequest, null);
 
     Iterable<Resource> iterable = pageResponse.getIterable();
     List<Resource> list = new LinkedList<Resource>();
@@ -156,7 +156,7 @@ public class ClusterControllerImplTest {
 
     // get the first three
     pageRequest = new PageRequestImpl(PageRequest.StartingPoint.Beginning, 3, 0, null, null);
-    pageResponse = controller.getResources(Resource.Type.Host, request, null, pageRequest, null);
+    pageResponse = controller.getPageResponse(Resource.Type.Host, request, null, pageRequest, null);
 
     iterable = pageResponse.getIterable();
     list = new LinkedList<Resource>();
@@ -193,7 +193,7 @@ public class ClusterControllerImplTest {
       Collections.singletonList(new SortRequestProperty("Hosts/host_name", SortRequest.Order.ASC));
     SortRequest sortRequest = new SortRequestImpl(sortRequestProperties);
 
-    Iterable<Resource> iterable = controller.getResources(Resource.Type.Host,
+    Iterable<Resource> iterable = controller.getPageResponse(Resource.Type.Host,
       request, null, null, sortRequest).getIterable();
 
     List<Resource> list = new LinkedList<Resource>();
@@ -213,7 +213,7 @@ public class ClusterControllerImplTest {
       new SortRequestProperty("Hosts/host_name", SortRequest.Order.DESC));
     sortRequest = new SortRequestImpl(sortRequestProperties);
 
-    iterable = controller.getResources(Resource.Type.Host,
+    iterable = controller.getPageResponse(Resource.Type.Host,
       request, null, null, sortRequest).getIterable();
 
     list = new LinkedList<Resource>();
@@ -248,7 +248,7 @@ public class ClusterControllerImplTest {
       }};
     SortRequest sortRequest = new SortRequestImpl(sortRequestProperties);
 
-    Iterable<Resource> iterable = controller.getResources(Resource.Type.Host,
+    Iterable<Resource> iterable = controller.getPageResponse(Resource.Type.Host,
       request, null, null, sortRequest).getIterable();
 
     List<Resource> list = new LinkedList<Resource>();
@@ -274,7 +274,7 @@ public class ClusterControllerImplTest {
 
     // get the middle two (1 - 2)
     PageRequest pageRequest = new PageRequestImpl(PageRequest.StartingPoint.OffsetStart, 2, 1, null, null);
-    PageResponse pageResponse = controller.getResources(Resource.Type.Host, request, null, pageRequest, null);
+    PageResponse pageResponse = controller.getPageResponse(Resource.Type.Host, request, null, pageRequest, null);
 
     Assert.assertEquals(1, pageResponse.getOffset());
     Assert.assertEquals("host:0", pageResponse.getPreviousResource().getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
@@ -296,7 +296,7 @@ public class ClusterControllerImplTest {
 
     // get the last three (0 - 2)
     pageRequest = new PageRequestImpl(PageRequest.StartingPoint.OffsetStart, 3, 0, null, null);
-    pageResponse = controller.getResources(Resource.Type.Host, request, null, pageRequest, null);
+    pageResponse = controller.getPageResponse(Resource.Type.Host, request, null, pageRequest, null);
 
     Assert.assertEquals(0, pageResponse.getOffset());
     Assert.assertNull(pageResponse.getPreviousResource());
@@ -329,7 +329,7 @@ public class ClusterControllerImplTest {
 
     // get the last two
     PageRequest pageRequest = new PageRequestImpl(PageRequest.StartingPoint.End, 2, 0, null, null);
-    PageResponse pageResponse = controller.getResources(Resource.Type.Host, request, null, pageRequest, null);
+    PageResponse pageResponse = controller.getPageResponse(Resource.Type.Host, request, null, pageRequest, null);
 
     Iterable<Resource> iterable = pageResponse.getIterable();
     List<Resource> list = new LinkedList<Resource>();
@@ -347,7 +347,7 @@ public class ClusterControllerImplTest {
 
     // get the last three
     pageRequest = new PageRequestImpl(PageRequest.StartingPoint.End, 3, 0, null, null);
-    pageResponse = controller.getResources(Resource.Type.Host, request, null, pageRequest, null);
+    pageResponse = controller.getPageResponse(Resource.Type.Host, request, null, pageRequest, null);
 
     iterable = pageResponse.getIterable();
     list = new LinkedList<Resource>();
@@ -376,7 +376,7 @@ public class ClusterControllerImplTest {
 
     // get the middle two (1 - 2)
     PageRequest pageRequest = new PageRequestImpl(PageRequest.StartingPoint.OffsetEnd, 2, 2, null, null);
-    PageResponse pageResponse = controller.getResources(Resource.Type.Host, request, null, pageRequest, null);
+    PageResponse pageResponse = controller.getPageResponse(Resource.Type.Host, request, null, pageRequest, null);
 
     Assert.assertEquals(1, pageResponse.getOffset());
     Assert.assertEquals("host:0", pageResponse.getPreviousResource().getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
@@ -398,7 +398,7 @@ public class ClusterControllerImplTest {
 
     // get the last three (0 - 2)
     pageRequest = new PageRequestImpl(PageRequest.StartingPoint.OffsetEnd, 3, 2, null, null);
-    pageResponse = controller.getResources(Resource.Type.Host, request, null, pageRequest, null);
+    pageResponse = controller.getPageResponse(Resource.Type.Host, request, null, pageRequest, null);
 
     Assert.assertEquals(0, pageResponse.getOffset());
     Assert.assertNull(pageResponse.getPreviousResource());
@@ -556,7 +556,7 @@ public class ClusterControllerImplTest {
     PageRequest pageRequest =
       new PageRequestImpl(PageRequest.StartingPoint.Beginning, 1, 0, null, null);
     PageResponse pageResponse =
-      controller.getResources(Resource.Type.Host, request, predicate, pageRequest, sortRequest);
+      controller.getPageResponse(Resource.Type.Host, request, predicate, pageRequest, sortRequest);
 
     Iterable<Resource> iterable = pageResponse.getIterable();
     List<Resource> list = new LinkedList<Resource>();
@@ -574,7 +574,7 @@ public class ClusterControllerImplTest {
 
     pageRequest =
       new PageRequestImpl(PageRequest.StartingPoint.OffsetStart, 1, 1, null, null);
-    pageResponse = controller.getResources(
+    pageResponse = controller.getPageResponse(
       Resource.Type.Host, request, predicate, pageRequest, sortRequest);
 
     iterable = pageResponse.getIterable();

+ 16 - 9
ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProviderTest.java

@@ -26,12 +26,8 @@ import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.Map.Entry;
 
-import org.apache.ambari.server.controller.ganglia.GangliaHostComponentPropertyProvider;
-import org.apache.ambari.server.controller.ganglia.GangliaPropertyProvider;
 import org.apache.ambari.server.controller.ganglia.GangliaPropertyProviderTest.TestGangliaHostProvider;
-import org.apache.ambari.server.controller.jmx.JMXPropertyProvider;
 import org.apache.ambari.server.controller.jmx.TestStreamProvider;
 import org.apache.ambari.server.controller.jmx.JMXPropertyProviderTest.TestJMXHostProvider;
 import org.apache.ambari.server.controller.spi.Predicate;
@@ -49,7 +45,6 @@ import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Host;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.stack.Metric;
-import org.apache.http.client.utils.URIBuilder;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
@@ -116,7 +111,8 @@ public class StackDefinedPropertyProviderTest {
     resource.setProperty("HostRoles/host_name", "h1");
     resource.setProperty("HostRoles/component_name", "NAMENODE");
     resource.setProperty("HostRoles/state", "STARTED");
-    
+    resource.setPopulateRequiredFlag(true);
+
     // request with an empty set should get all supported properties
     Request request = PropertyHelper.getReadRequest(Collections.<String>emptySet(), new HashMap<String, TemporalInfo>());
 
@@ -147,7 +143,8 @@ public class StackDefinedPropertyProviderTest {
     resource.setProperty("HostRoles/host_name", "h1");
     resource.setProperty("HostRoles/component_name", "DATANODE");
     resource.setProperty("HostRoles/state", "STARTED");
-    
+    resource.setPopulateRequiredFlag(true);
+
     // request with an empty set should get all supported properties
     Request request = PropertyHelper.getReadRequest(Collections.<String>emptySet(), new HashMap<String, TemporalInfo>());
 
@@ -313,6 +310,7 @@ public class StackDefinedPropertyProviderTest {
     resource.setProperty(HOST_COMPONENT_HOST_NAME_PROPERTY_ID, "domu-12-31-39-0e-34-e1.compute-1.internal");
     resource.setProperty(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID, "RESOURCEMANAGER");
     resource.setProperty(HOST_COMPONENT_STATE_PROPERTY_ID, "STARTED");
+    resource.setPopulateRequiredFlag(true);
 
     // request with an empty set should get all supported properties
     Request request = PropertyHelper.getReadRequest(Collections.<String>emptySet());
@@ -372,6 +370,7 @@ public class StackDefinedPropertyProviderTest {
     resource.setProperty(HOST_COMPONENT_HOST_NAME_PROPERTY_ID, "h1");
     resource.setProperty(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID, "RESOURCEMANAGER");
     resource.setProperty(HOST_COMPONENT_STATE_PROPERTY_ID, "STARTED");
+    resource.setPopulateRequiredFlag(true);
 
     // request with an empty set should get all supported properties
     Request request = PropertyHelper.getReadRequest(Collections.<String>emptySet());
@@ -423,6 +422,7 @@ public class StackDefinedPropertyProviderTest {
     resource.setProperty(HOST_COMPONENT_HOST_NAME_PROPERTY_ID, "h1");
     resource.setProperty(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID, "RESOURCEMANAGER");
     resource.setProperty(HOST_COMPONENT_STATE_PROPERTY_ID, "STARTED");
+    resource.setPopulateRequiredFlag(true);
 
     // only ask for one property
     Map<String, TemporalInfo> temporalInfoMap = new HashMap<String, TemporalInfo>();
@@ -459,6 +459,7 @@ public class StackDefinedPropertyProviderTest {
     resource.setProperty(HOST_COMPONENT_HOST_NAME_PROPERTY_ID, "h1");
     resource.setProperty(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID, "RESOURCEMANAGER");
     resource.setProperty(HOST_COMPONENT_STATE_PROPERTY_ID, "STARTED");
+    resource.setPopulateRequiredFlag(true);
 
     // only ask for one property
     Map<String, TemporalInfo> temporalInfoMap = new HashMap<String, TemporalInfo>();
@@ -510,6 +511,7 @@ public class StackDefinedPropertyProviderTest {
     resource.setProperty(HOST_COMPONENT_HOST_NAME_PROPERTY_ID, "h1");
     resource.setProperty(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID, "RESOURCEMANAGER");
     resource.setProperty(HOST_COMPONENT_STATE_PROPERTY_ID, "STARTED");
+    resource.setPopulateRequiredFlag(true);
 
     // only ask for one property
     Map<String, TemporalInfo> temporalInfoMap = new HashMap<String, TemporalInfo>();
@@ -567,6 +569,7 @@ public class StackDefinedPropertyProviderTest {
     resource.setProperty(HOST_COMPONENT_HOST_NAME_PROPERTY_ID, "domu-12-31-39-0e-34-e1.compute-1.internal");
     resource.setProperty(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID, "JOURNALNODE");
     resource.setProperty(HOST_COMPONENT_STATE_PROPERTY_ID, "STARTED");
+    resource.setPopulateRequiredFlag(true);
 
     // request with an empty set should get all supported properties
     Request request = PropertyHelper.getReadRequest(Collections.<String>emptySet());
@@ -691,6 +694,7 @@ public class StackDefinedPropertyProviderTest {
     resource.setProperty(HOST_COMPONENT_HOST_NAME_PROPERTY_ID, "domu-12-31-39-0e-34-e1.compute-1.internal");
     resource.setProperty(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID, "STORM_REST_API");
     resource.setProperty(HOST_COMPONENT_STATE_PROPERTY_ID, "STARTED");
+    resource.setPopulateRequiredFlag(true);
 
     // request with an empty set should get all supported properties
     Request request = PropertyHelper.getReadRequest(Collections.<String>emptySet());
@@ -767,7 +771,7 @@ public class StackDefinedPropertyProviderTest {
     resource.setProperty(HOST_COMPONENT_HOST_NAME_PROPERTY_ID, "domu-12-31-39-0e-34-e1.compute-1.internal");
     resource.setProperty(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID, "HBASE_MASTER");
     resource.setProperty(HOST_COMPONENT_STATE_PROPERTY_ID, "STARTED");
-
+    resource.setPopulateRequiredFlag(true);
     
     // request with an empty set should get all supported properties
     Request request = PropertyHelper.getReadRequest(Collections.<String>emptySet());
@@ -809,6 +813,7 @@ public class StackDefinedPropertyProviderTest {
     resource.setProperty("HostRoles/cluster_name", "c1");
     resource.setProperty(HOST_COMPONENT_HOST_NAME_PROPERTY_ID, "dev01.ambari.apache.org");
     resource.setProperty(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID, "RESOURCEMANAGER");
+    resource.setPopulateRequiredFlag(true);
 
     String RM_CATEGORY_1 = "metrics/yarn/Queue/root/default";
     String RM_AVAILABLE_MEMORY_PROPERTY = PropertyHelper.getPropertyId(RM_CATEGORY_1, "AvailableMB");
@@ -855,6 +860,7 @@ public class StackDefinedPropertyProviderTest {
     resource.setProperty("HostRoles/cluster_name", "c1");
     resource.setProperty(HOST_COMPONENT_HOST_NAME_PROPERTY_ID, "ip-10-39-113-33.ec2.internal");
     resource.setProperty(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID, "JOURNALNODE");
+    resource.setPopulateRequiredFlag(true);
 
 
     Object[][] testData = {
@@ -977,7 +983,8 @@ public class StackDefinedPropertyProviderTest {
       resource.setProperty("HostRoles/cluster_name", "c1");
       resource.setProperty(HOST_COMPONENT_HOST_NAME_PROPERTY_ID, "ip-10-39-113-33.ec2.internal");
       resource.setProperty(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID, "RESOURCEMANAGER");
-      
+      resource.setPopulateRequiredFlag(true);
+
       // only ask for one property
       Map<String, TemporalInfo> temporalInfoMap = new HashMap<String, TemporalInfo>();
       temporalInfoMap.put(metric, new TemporalInfoImpl(10L, 20L, 1L));

+ 10 - 0
ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/JMXPropertyProviderTest.java

@@ -65,6 +65,7 @@ public class JMXPropertyProviderTest {
     resource.setProperty(HOST_COMPONENT_HOST_NAME_PROPERTY_ID, "domu-12-31-39-0e-34-e1.compute-1.internal");
     resource.setProperty(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID, "NAMENODE");
     resource.setProperty(HOST_COMPONENT_STATE_PROPERTY_ID, "STARTED");
+    resource.setPopulateRequiredFlag(true);
 
     // request with an empty set should get all supported properties
     Request request = PropertyHelper.getReadRequest(Collections.<String>emptySet());
@@ -90,6 +91,7 @@ public class JMXPropertyProviderTest {
 
     resource.setProperty(HOST_COMPONENT_HOST_NAME_PROPERTY_ID, "domu-12-31-39-14-ee-b3.compute-1.internal");
     resource.setProperty(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID, "DATANODE");
+    resource.setPopulateRequiredFlag(true);
 
     // request with an empty set should get all supported properties
     request = PropertyHelper.getReadRequest(Collections.<String>emptySet());
@@ -111,6 +113,7 @@ public class JMXPropertyProviderTest {
 
     resource.setProperty(HOST_COMPONENT_HOST_NAME_PROPERTY_ID, "domu-12-31-39-14-ee-b3.compute-1.internal");
     resource.setProperty(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID, "JOBTRACKER");
+    resource.setPopulateRequiredFlag(true);
 
     // only ask for specific properties
     Set<String> properties = new HashSet<String>();
@@ -153,6 +156,7 @@ public class JMXPropertyProviderTest {
 
     resource.setProperty(HOST_COMPONENT_HOST_NAME_PROPERTY_ID, "domu-12-31-39-14-ee-b3.compute-1.internal");
     resource.setProperty(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID, "TASKTRACKER");
+    resource.setPopulateRequiredFlag(true);
 
     // only ask for specific properties
     properties = new HashSet<String>();
@@ -206,6 +210,7 @@ public class JMXPropertyProviderTest {
     resource.setProperty(HOST_COMPONENT_HOST_NAME_PROPERTY_ID, "domu-12-31-39-14-ee-b3.compute-1.internal");
     resource.setProperty(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID, "HBASE_MASTER");
     resource.setProperty(HOST_COMPONENT_STATE_PROPERTY_ID, "STARTED");
+    resource.setPopulateRequiredFlag(true);
 
     // only ask for specific properties
     properties = new HashSet<String>();
@@ -251,6 +256,7 @@ public class JMXPropertyProviderTest {
     resource.setProperty(HOST_COMPONENT_HOST_NAME_PROPERTY_ID, "domu-12-31-39-0e-34-e1.compute-1.internal");
     resource.setProperty(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID, "NAMENODE");
     resource.setProperty(HOST_COMPONENT_STATE_PROPERTY_ID, "STARTED");
+    resource.setPopulateRequiredFlag(true);
 
     // only ask for one property
     Map<String, TemporalInfo> temporalInfoMap = new HashMap<String, TemporalInfo>();
@@ -286,6 +292,7 @@ public class JMXPropertyProviderTest {
     resource.setProperty(HOST_COMPONENT_HOST_NAME_PROPERTY_ID, "domu-12-31-39-0e-34-e1.compute-1.internal");
     resource.setProperty(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID, "NAMENODE");
     resource.setProperty(HOST_COMPONENT_STATE_PROPERTY_ID, "STARTED");
+    resource.setPopulateRequiredFlag(true);
 
     // request with an empty set should get all supported properties
     // only ask for one property
@@ -322,6 +329,7 @@ public class JMXPropertyProviderTest {
 
     resource.setProperty(HOST_COMPONENT_HOST_NAME_PROPERTY_ID, "domu-12-31-39-0e-34-e1.compute-1.internal");
     resource.setProperty(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID, "NAMENODE");
+    resource.setPopulateRequiredFlag(true);
 
     // request with an empty set should get all supported properties
     Request request = PropertyHelper.getReadRequest(Collections.<String>emptySet());
@@ -363,6 +371,7 @@ public class JMXPropertyProviderTest {
     resource.setProperty(HOST_COMPONENT_HOST_NAME_PROPERTY_ID, "domu-12-31-39-0e-34-e1.compute-1.internal");
     resource.setProperty(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID, "NAMENODE");
     resource.setProperty(HOST_COMPONENT_STATE_PROPERTY_ID, "INSTALLED");
+    resource.setPopulateRequiredFlag(true);
 
     // request with an empty set should get all supported properties
     Request request = PropertyHelper.getReadRequest(Collections.<String>emptySet());
@@ -397,6 +406,7 @@ public class JMXPropertyProviderTest {
       resource.setProperty(HOST_COMPONENT_HOST_NAME_PROPERTY_ID, "domu-12-31-39-14-ee-b3.compute-1.internal");
       resource.setProperty(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID, "DATANODE");
       resource.setProperty("unique_id", i);
+      resource.setPopulateRequiredFlag(true);
 
       resources.add(resource);
     }

+ 8 - 0
ambari-server/src/test/java/org/apache/ambari/server/controller/nagios/NagiosPropertyProviderTest.java

@@ -164,6 +164,7 @@ public class NagiosPropertyProviderTest {
     Resource resource = new ResourceImpl(Resource.Type.Cluster);
     resource.setProperty("Clusters/cluster_name", "c1");
     resource.setProperty("Clusters/version", "HDP-2.0.6");
+    resource.setPopulateRequiredFlag(true);
 
     // request with an empty set should get all supported properties
     Request request = PropertyHelper.getReadRequest(Collections.<String>emptySet(), new HashMap<String, TemporalInfo>());
@@ -246,6 +247,7 @@ public class NagiosPropertyProviderTest {
     Resource resource = new ResourceImpl(Resource.Type.Service);
     resource.setProperty("ServiceInfo/cluster_name", "c1");
     resource.setProperty("ServiceInfo/service_name", "HBASE");
+    resource.setPopulateRequiredFlag(true);
     
     // request with an empty set should get all supported properties
     Request request = PropertyHelper.getReadRequest(Collections.<String>emptySet(), new HashMap<String, TemporalInfo>());
@@ -297,6 +299,7 @@ public class NagiosPropertyProviderTest {
     Resource resource = new ResourceImpl(Resource.Type.Service);
     resource.setProperty("Hosts/cluster_name", "c1");
     resource.setProperty("Hosts/host_name", "c6403.ambari.apache.org");
+    resource.setPopulateRequiredFlag(true);
     
     // request with an empty set should get all supported properties
     Request request = PropertyHelper.getReadRequest(Collections.<String>emptySet(), new HashMap<String, TemporalInfo>());
@@ -348,6 +351,7 @@ public class NagiosPropertyProviderTest {
     Resource resource = new ResourceImpl(Resource.Type.Service);
     resource.setProperty("Hosts/cluster_name", "c1");
     resource.setProperty("Hosts/host_name", "c6401.ambari.apache.org");
+    resource.setPopulateRequiredFlag(true);
     
     // request with an empty set should get all supported properties
     Request request = PropertyHelper.getReadRequest(Collections.<String>emptySet(), new HashMap<String, TemporalInfo>());
@@ -403,6 +407,7 @@ public class NagiosPropertyProviderTest {
     Resource resource = new ResourceImpl(Resource.Type.Service);
     resource.setProperty("ServiceInfo/cluster_name", "c1");
     resource.setProperty("ServiceInfo/service_name", "HBASE");
+    resource.setPopulateRequiredFlag(true);
     
     // request with an empty set should get all supported properties
     Request request = PropertyHelper.getReadRequest(Collections.<String>emptySet(), new HashMap<String, TemporalInfo>());
@@ -476,6 +481,7 @@ public class NagiosPropertyProviderTest {
     Resource resource = new ResourceImpl(Resource.Type.Service);
     resource.setProperty("ServiceInfo/cluster_name", "c1");
     resource.setProperty("ServiceInfo/service_name", "GANGLIA");
+    resource.setPopulateRequiredFlag(true);
     
     // request with an empty set should get all supported properties
     Request request = PropertyHelper.getReadRequest(Collections.<String>emptySet(), new HashMap<String, TemporalInfo>());
@@ -529,6 +535,7 @@ public class NagiosPropertyProviderTest {
     Resource resource = new ResourceImpl(Resource.Type.Host);
     resource.setProperty("Hosts/cluster_name", "c1");
     resource.setProperty("Hosts/host_name", "c6404.ambari.apache.org");
+    resource.setPopulateRequiredFlag(true);
     
     // request with an empty set should get all supported properties
     Request request = PropertyHelper.getReadRequest(Collections.<String>emptySet(), new HashMap<String, TemporalInfo>());
@@ -617,6 +624,7 @@ public class NagiosPropertyProviderTest {
     Resource resource = new ResourceImpl(Resource.Type.Service);
     resource.setProperty("ServiceInfo/cluster_name", "c1");
     resource.setProperty("ServiceInfo/service_name", "GANGLIA");
+    resource.setPopulateRequiredFlag(true);
     
     // request with an empty set should get all supported properties
     Request request = PropertyHelper.getReadRequest(Collections.<String>emptySet(), new HashMap<String, TemporalInfo>());