incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tbeerbo...@apache.org
Subject [1/3] git commit: AMBARI-2711 - Get call on host resource at api/v1/hosts/(hostname) returns empty response
Date Tue, 23 Jul 2013 20:22:24 GMT
Updated Branches:
  refs/heads/trunk 0368796c5 -> aa31e2ccb


AMBARI-2711 - Get call on host resource at api/v1/hosts/(hostname) returns empty response


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

Branch: refs/heads/trunk
Commit: 6e2fa0343ae507e7f776da39c321ab18024957c9
Parents: e163b0e
Author: tbeerbower <tbeerbower@hortonworks.com>
Authored: Tue Jul 23 13:00:00 2013 -0400
Committer: tbeerbower <tbeerbower@hortonworks.com>
Committed: Tue Jul 23 16:10:48 2013 -0400

----------------------------------------------------------------------
 .../internal/AbstractProviderModule.java        | 41 +++++++++++++-------
 .../internal/VersioningPropertyProvider.java    | 24 ++++++++----
 .../VersioningPropertyProviderTest.java         | 17 +++++++-
 3 files changed, 57 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/6e2fa034/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java
index 1a93737..77556f0 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java
@@ -530,14 +530,16 @@ public abstract class AbstractProviderModule implements ProviderModule,
Resource
 
     Map<PropertyHelper.MetricsVersion, AbstractPropertyProvider> providers =
         new HashMap<PropertyHelper.MetricsVersion, AbstractPropertyProvider>();
+    AbstractPropertyProvider lastProvider = null;
 
     for (PropertyHelper.MetricsVersion version : PropertyHelper.MetricsVersion.values())
{
 
-      providers.put(version, new JMXPropertyProvider(PropertyHelper.getJMXPropertyIds(type,
version), streamProvider,
-          jmxHostProvider, clusterNamePropertyId, hostNamePropertyId, componentNamePropertyId,
statePropertyId, healthyStates));
+      lastProvider = new JMXPropertyProvider(PropertyHelper.getJMXPropertyIds(type, version),
streamProvider,
+          jmxHostProvider, clusterNamePropertyId, hostNamePropertyId, componentNamePropertyId,
statePropertyId, healthyStates);
+      providers.put(version, lastProvider);
     }
 
-    return new VersioningPropertyProvider(clusterVersionsMap, providers, clusterNamePropertyId);
+    return new VersioningPropertyProvider(clusterVersionsMap, providers, lastProvider, clusterNamePropertyId);
   }
 
   /**
@@ -551,14 +553,16 @@ public abstract class AbstractProviderModule implements ProviderModule,
Resource
 
     Map<PropertyHelper.MetricsVersion, AbstractPropertyProvider> providers =
         new HashMap<PropertyHelper.MetricsVersion, AbstractPropertyProvider>();
+    AbstractPropertyProvider lastProvider = null;
 
     for (PropertyHelper.MetricsVersion version : PropertyHelper.MetricsVersion.values())
{
 
-      providers.put(version, new GangliaReportPropertyProvider(PropertyHelper.getGangliaPropertyIds(type,
version), streamProvider,
-          configuration, hostProvider, clusterNamePropertyId));
+      lastProvider = new GangliaReportPropertyProvider(PropertyHelper.getGangliaPropertyIds(type,
version), streamProvider,
+          configuration, hostProvider, clusterNamePropertyId);
+      providers.put(version, lastProvider);
     }
 
-    return new VersioningPropertyProvider(clusterVersionsMap, providers, clusterNamePropertyId);
+    return new VersioningPropertyProvider(clusterVersionsMap, providers, lastProvider, clusterNamePropertyId);
   }
 
   /**
@@ -573,14 +577,16 @@ public abstract class AbstractProviderModule implements ProviderModule,
Resource
 
     Map<PropertyHelper.MetricsVersion, AbstractPropertyProvider> providers =
         new HashMap<PropertyHelper.MetricsVersion, AbstractPropertyProvider>();
+    AbstractPropertyProvider lastProvider = null;
 
     for (PropertyHelper.MetricsVersion version : PropertyHelper.MetricsVersion.values())
{
 
-      providers.put(version, new GangliaHostPropertyProvider(PropertyHelper.getGangliaPropertyIds(type,
version), streamProvider,
-          configuration, hostProvider, clusterNamePropertyId, hostNamePropertyId));
+      lastProvider = new GangliaHostPropertyProvider(PropertyHelper.getGangliaPropertyIds(type,
version), streamProvider,
+          configuration, hostProvider, clusterNamePropertyId, hostNamePropertyId);
+      providers.put(version, lastProvider);
     }
 
-    return new VersioningPropertyProvider(clusterVersionsMap, providers, clusterNamePropertyId);
+    return new VersioningPropertyProvider(clusterVersionsMap, providers, lastProvider, clusterNamePropertyId);
   }
 
   /**
@@ -595,14 +601,17 @@ public abstract class AbstractProviderModule implements ProviderModule,
Resource
 
     Map<PropertyHelper.MetricsVersion, AbstractPropertyProvider> providers =
         new HashMap<PropertyHelper.MetricsVersion, AbstractPropertyProvider>();
+    AbstractPropertyProvider lastProvider = null;
 
     for (PropertyHelper.MetricsVersion version : PropertyHelper.MetricsVersion.values())
{
+      lastProvider =
+          new GangliaComponentPropertyProvider(PropertyHelper.getGangliaPropertyIds(type,
version),
+              streamProvider, configuration, hostProvider, clusterNamePropertyId, componentNamePropertyId);
 
-      providers.put(version, new GangliaComponentPropertyProvider(PropertyHelper.getGangliaPropertyIds(type,
version), streamProvider,
-          configuration, hostProvider, clusterNamePropertyId, componentNamePropertyId));
+      providers.put(version, lastProvider);
     }
 
-    return new VersioningPropertyProvider(clusterVersionsMap, providers, clusterNamePropertyId);
+    return new VersioningPropertyProvider(clusterVersionsMap, providers, lastProvider, clusterNamePropertyId);
   }
 
   /**
@@ -618,13 +627,15 @@ public abstract class AbstractProviderModule implements ProviderModule,
Resource
 
     Map<PropertyHelper.MetricsVersion, AbstractPropertyProvider> providers =
         new HashMap<PropertyHelper.MetricsVersion, AbstractPropertyProvider>();
+    AbstractPropertyProvider lastProvider = null;
 
     for (PropertyHelper.MetricsVersion version : PropertyHelper.MetricsVersion.values())
{
 
-      providers.put(version, new GangliaHostComponentPropertyProvider(PropertyHelper.getGangliaPropertyIds(type,
version), streamProvider,
-          configuration, hostProvider, clusterNamePropertyId, hostNamePropertyId, componentNamePropertyId));
+      lastProvider = new GangliaHostComponentPropertyProvider(PropertyHelper.getGangliaPropertyIds(type,
version), streamProvider,
+          configuration, hostProvider, clusterNamePropertyId, hostNamePropertyId, componentNamePropertyId);
+      providers.put(version, lastProvider);
     }
 
-    return new VersioningPropertyProvider(clusterVersionsMap, providers, clusterNamePropertyId);
+    return new VersioningPropertyProvider(clusterVersionsMap, providers, lastProvider, clusterNamePropertyId);
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/6e2fa034/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/VersioningPropertyProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/VersioningPropertyProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/VersioningPropertyProvider.java
index 9c94ece..b1b1d5c 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/VersioningPropertyProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/VersioningPropertyProvider.java
@@ -38,6 +38,7 @@ public class VersioningPropertyProvider extends BaseProvider implements
Property
 
   private final Map<String, PropertyHelper.MetricsVersion> clusterVersions;
   private final Map<PropertyHelper.MetricsVersion, AbstractPropertyProvider> providers;
+  private final AbstractPropertyProvider defaultProvider;
   private final String clusterNamePropertyId;
 
   /**
@@ -45,11 +46,13 @@ public class VersioningPropertyProvider extends BaseProvider implements
Property
    */
   public VersioningPropertyProvider(Map<String, PropertyHelper.MetricsVersion> clusterVersions,
                                     Map<PropertyHelper.MetricsVersion, AbstractPropertyProvider>
providers,
+                                    AbstractPropertyProvider defaultProvider,
                                     String clusterNamePropertyId) {
     super(getComponentMetrics(providers));
 
     this.clusterVersions       = clusterVersions;
     this.providers             = providers;
+    this.defaultProvider       = defaultProvider;
     this.clusterNamePropertyId = clusterNamePropertyId;
   }
 
@@ -77,18 +80,23 @@ public class VersioningPropertyProvider extends BaseProvider implements
Property
     // give each set of resources to the underlying provider that matches the
     // metrics version of the associated cluster
     for (Map.Entry<String, Set<Resource>> entry : resourcesByCluster.entrySet())
{
-      String clusterName = entry.getKey();
-      Set<Resource> resourceSet = entry.getValue();
+      String                   clusterName = entry.getKey();
+      Set<Resource>            resourceSet = entry.getValue();
+      AbstractPropertyProvider provider    = null;
 
-      PropertyHelper.MetricsVersion version = clusterVersions.get(clusterName);
+      if (clusterName == null) {
+        provider = defaultProvider;
+      } else {
+        PropertyHelper.MetricsVersion version = clusterVersions.get(clusterName);
 
-      if (version != null) {
-
-        AbstractPropertyProvider provider = providers.get(version);
-        if (provider != null) {
-          keepers.addAll(provider.populateResources(resourceSet, request, predicate));
+        if (version != null) {
+          provider = providers.get(version);
         }
       }
+
+      if (provider != null) {
+        keepers.addAll(provider.populateResources(resourceSet, request, predicate));
+      }
     }
     return keepers;
   }

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/6e2fa034/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/VersioningPropertyProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/VersioningPropertyProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/VersioningPropertyProviderTest.java
index b881c41..1db4e0b 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/VersioningPropertyProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/VersioningPropertyProviderTest.java
@@ -69,8 +69,9 @@ public class VersioningPropertyProviderTest {
 
     providers.put(PropertyHelper.MetricsVersion.HDP2, propertyProvider2);
 
-
-    VersioningPropertyProvider provider = new VersioningPropertyProvider(clusterVersionsMap,
providers, PropertyHelper.getPropertyId("HostRoles", "cluster_name"));
+    // set propertyProvider2 as the default provider
+    VersioningPropertyProvider provider = new VersioningPropertyProvider(clusterVersionsMap,
providers,
+        propertyProvider2, PropertyHelper.getPropertyId("HostRoles", "cluster_name"));
 
 
     Request request = PropertyHelper.getReadRequest();
@@ -106,6 +107,18 @@ public class VersioningPropertyProviderTest {
 
     Assert.assertEquals(resource1, propertyProvider1.getResource());
     Assert.assertEquals(resource2, propertyProvider2.getResource());
+
+
+    // test resource with no associated cluster ... should go to default provider2
+    propertyProvider1.setResource(null);
+    propertyProvider2.setResource(null);
+
+    Resource resource3 = new ResourceImpl(Resource.Type.HostComponent);
+
+    provider.populateResources(Collections.singleton(resource3), request, null);
+
+    Assert.assertNull(propertyProvider1.getResource());
+    Assert.assertEquals(resource3, propertyProvider2.getResource());
   }
 
   private class TestJMXPropertyProvider extends JMXPropertyProvider {


Mime
View raw message