Author: ncole
Date: Thu Apr 18 22:37:55 2013
New Revision: 1469611
URL: http://svn.apache.org/r1469611
Log:
AMBARI-1980. Fix for nagios_alerts element when there is an Exception
Modified:
incubator/ambari/trunk/CHANGES.txt
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HttpProxyPropertyProvider.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HttpPropertyProviderTest.java
Modified: incubator/ambari/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1469611&r1=1469610&r2=1469611&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Thu Apr 18 22:37:55 2013
@@ -427,7 +427,7 @@ Trunk (unreleased changes):
AMBARI-1546. Improve Cluster Management loading screen. (Xi Wang via yusaku)
- ABMARI-1975. Add Clover coverage (ncole)
+ AMBARI-1975. Add Clover coverage (ncole)
AMBARI-1537. Constrain the width of all wizard popups. (Xi Wang via yusaku)
@@ -1186,6 +1186,8 @@ Trunk (unreleased changes):
AMBARI-1657. User directories on HDFS do not get created with custom names
provided from Ambari UI. (swagle)
+ AMBARI-1980. Fix for nagios_alerts element when there is an error. (ncole)
+
AMBARI-1865. Fix for upgrade script to copy configurations. (ncole)
AMBARI-1703. Fix for smoke tests getting configurations. (ncole)
Modified:
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HttpProxyPropertyProvider.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HttpProxyPropertyProvider.java?rev=1469611&r1=1469610&r2=1469611&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HttpProxyPropertyProvider.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HttpProxyPropertyProvider.java
Thu Apr 18 22:37:55 2013
@@ -109,7 +109,6 @@ public class HttpProxyPropertyProvider e
}
private void getHttpResponse(Resource r, String url, String propertyIdToSet)
throws SystemException {
-
InputStream in = null;
try {
in = streamProvider.readFrom(url);
@@ -119,14 +118,14 @@ public class HttpProxyPropertyProvider e
}
catch (IOException ioe) {
LOG.error("Error reading HTTP response from " + url);
- throw new SystemException("Unable to get property " + propertyIdToSet +
"from URL " + url, ioe);
+ r.setProperty(propertyIdToSet, null);
} finally {
if (in != null) {
try {
in.close();
}
catch (IOException ioe) {
- throw new SystemException("Unable to close input stream", ioe);
+ LOG.error("Error closing HTTP response stream " + url);
}
}
}
Modified:
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HttpPropertyProviderTest.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HttpPropertyProviderTest.java?rev=1469611&r1=1469610&r2=1469611&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HttpPropertyProviderTest.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HttpPropertyProviderTest.java
Thu Apr 18 22:37:55 2013
@@ -75,6 +75,19 @@ public class HttpPropertyProviderTest {
Assert.assertNotNull("Expected non-null for 'nagios_alerts'",
resource.getPropertyValue(PROPERTY_ID_NAGIOS_ALERTS));
}
+
+ @Test
+ public void testReadWithRequestedFail() throws Exception {
+
+ Set<String> propertyIds = new HashSet<String>();
+ propertyIds.add(PropertyHelper.getPropertyId("HostRoles", "nagios_alerts"));
+ propertyIds.add(PROPERTY_ID_COMPONENT_NAME);
+
+ Resource resource = doPopulate("NAGIOS_SERVER", propertyIds, true);
+
+ Assert.assertNull("Expected null for 'nagios_alerts'",
+ resource.getPropertyValue(PROPERTY_ID_NAGIOS_ALERTS));
+ }
@SuppressWarnings("rawtypes")
@Test
@@ -121,9 +134,14 @@ public class HttpPropertyProviderTest {
}
private Resource doPopulate(String componentName, Set<String>
requestProperties) throws Exception {
+ return doPopulate(componentName, requestProperties, false);
+ }
+
+ private Resource doPopulate(String componentName,
+ Set<String> requestProperties, boolean throwException) throws Exception {
HttpProxyPropertyProvider propProvider = new HttpProxyPropertyProvider(
- new TestStreamProvider(),
+ new TestStreamProvider(throwException),
PROPERTY_ID_CLUSTER_NAME,
PROPERTY_ID_HOST_NAME,
PROPERTY_ID_COMPONENT_NAME);
@@ -140,15 +158,23 @@ public class HttpPropertyProviderTest {
return resource;
}
-
-
private static class TestStreamProvider implements StreamProvider {
-
+ private boolean throwError = false;
+
+ private TestStreamProvider(boolean throwErr) {
+ throwError = throwErr;
+ }
+
@Override
public InputStream readFrom(String spec) throws IOException {
+ if (throwError) {
+ throw new IOException("Fake error");
+ }
+
String responseStr = "{\"alerts\": [{\"Alert Body\": \"Body\"}],"
+ " \"hostcounts\": {\"up_hosts\":\"1\", \"down_hosts\":\"0\"}}";
return new ByteArrayInputStream(responseStr.getBytes("UTF-8"));
}
}
+
}