ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dmitriu...@apache.org
Subject [1/2] git commit: AMBARI-5182. Retrieve registered host from API throws exception (dlysnichenko)
Date Fri, 21 Mar 2014 20:39:17 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-1.5.0 075cec562 -> 982c6075d
  refs/heads/trunk 8d58c3262 -> a3410253c


AMBARI-5182. Retrieve registered host from API throws exception (dlysnichenko)


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

Branch: refs/heads/trunk
Commit: a3410253caaec3527792a71f02bdc5e5cecef29a
Parents: 8d58c32
Author: Lisnichenko Dmitro <dlysnichenko@hortonworks.com>
Authored: Fri Mar 21 22:36:29 2014 +0200
Committer: Lisnichenko Dmitro <dlysnichenko@hortonworks.com>
Committed: Fri Mar 21 22:36:29 2014 +0200

----------------------------------------------------------------------
 .../nagios/NagiosPropertyProvider.java          |  8 +++++--
 .../nagios/NagiosPropertyProviderTest.java      | 23 ++++++++++++++++++++
 2 files changed, 29 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/a3410253/ambari-server/src/main/java/org/apache/ambari/server/controller/nagios/NagiosPropertyProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/nagios/NagiosPropertyProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/nagios/NagiosPropertyProvider.java
index f80d4a6..4dc8f16 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/nagios/NagiosPropertyProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/nagios/NagiosPropertyProvider.java
@@ -164,8 +164,12 @@ public class NagiosPropertyProvider extends BaseProvider implements PropertyProv
       
       if (null == matchValue)
         continue;
-      
-      String clusterName = res.getPropertyValue(clusterNameProperty).toString();
+
+      Object clusterPropertyValue = res.getPropertyValue(clusterNameProperty);
+      if (null == clusterPropertyValue)
+        continue;
+
+      String clusterName = clusterPropertyValue.toString();
       if (null == clusterName)
         continue;
       

http://git-wip-us.apache.org/repos/asf/ambari/blob/a3410253/ambari-server/src/test/java/org/apache/ambari/server/controller/nagios/NagiosPropertyProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/nagios/NagiosPropertyProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/nagios/NagiosPropertyProviderTest.java
index 9c6977d..9f3ff85 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/nagios/NagiosPropertyProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/nagios/NagiosPropertyProviderTest.java
@@ -120,6 +120,29 @@ public class NagiosPropertyProviderTest {
     
     Assert.assertFalse("Expected no alerts", values.containsKey("alerts"));
   }
+
+
+  @Test
+  public void testClusterDoesNotExistNPE() throws Exception {
+    TestStreamProvider streamProvider = new TestStreamProvider("nagios_alerts.txt");
+
+    NagiosPropertyProvider npp = new NagiosPropertyProvider(Resource.Type.Service,
+        streamProvider,
+        "ServiceInfo/cluster_name",
+        "ServiceInfo/service_name");
+
+    Resource resource = new ResourceImpl(Resource.Type.Service);
+    resource.setProperty("ServiceInfo/cluster_name", null);
+    resource.setProperty("ServiceInfo/service_name", "HBASE");
+
+    // request with an empty set should get all supported properties
+    Request request = PropertyHelper.getReadRequest(Collections.<String>emptySet(),
+            new HashMap<String, TemporalInfo>());
+
+    Set<Resource> set = npp.populateResources(Collections.singleton(resource), request,
null);
+    Assert.assertEquals(1, set.size());
+
+  }
   
   @Test
   public void testNoNagiosServerCompoonent() throws Exception {


Mime
View raw message