Author: smohanty
Date: Fri Mar 29 17:19:48 2013
New Revision: 1462547
URL: http://svn.apache.org/r1462547
Log:
AMBARI-1561. API should return nagios_alerts as a JSON, not a stringified JSON.
(smohanty)
Modified:
incubator/ambari/trunk/CHANGES.txt
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java
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
incubator/ambari/trunk/contrib/addons/src/addOns/nagios/scripts/nagios_alerts.php
Modified: incubator/ambari/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1462547&r1=1462546&r2=1462547&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Fri Mar 29 17:19:48 2013
@@ -534,6 +534,9 @@ Trunk (unreleased changes):
BUG FIXES
+ AMBARI-1561. API should return nagios_alerts as a JSON, not a stringified
+ JSON. (smohanty)
+
AMBARI-1507. Should not install HDPHBaseMaster, HDPNameNode and HDPJobTracker
ganglia configs on every node. (smohanty)
Modified:
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java?rev=1462547&r1=1462546&r2=1462547&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java
Fri Mar 29 17:19:48 2013
@@ -294,12 +294,6 @@ public abstract class AbstractProviderMo
PropertyHelper.getPropertyId("HostRoles", "host_name"),
PropertyHelper.getPropertyId("HostRoles", "component_name")));
- providers.add(new HttpProxyPropertyProvider(
- new URLStreamProvider(1500),
- PropertyHelper.getPropertyId("HostRoles", "cluster_name"),
- PropertyHelper.getPropertyId("HostRoles", "host_name"),
- PropertyHelper.getPropertyId("HostRoles", "component_name")));
-
break;
default :
break;
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=1462547&r1=1462546&r2=1462547&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
Fri Mar 29 17:19:48 2013
@@ -19,15 +19,12 @@ package org.apache.ambari.server.control
import java.io.IOException;
import java.io.InputStream;
+import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-import org.apache.ambari.server.api.services.NamedPropertySet;
-import org.apache.ambari.server.api.services.RequestBody;
-import org.apache.ambari.server.api.services.parsers.BodyParseException;
-import org.apache.ambari.server.api.services.parsers.JsonRequestBodyParser;
import org.apache.ambari.server.controller.spi.Predicate;
import org.apache.ambari.server.controller.spi.PropertyProvider;
import org.apache.ambari.server.controller.spi.Request;
@@ -39,6 +36,9 @@ import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
+
/**
* Property provider that is used to read HTTP data from another server.
*/
@@ -108,32 +108,25 @@ public class HttpProxyPropertyProvider e
return resources;
}
- private void getHttpResponse(Resource r, String url, String propertyIdToSet)
{
+ private void getHttpResponse(Resource r, String url, String propertyIdToSet)
throws SystemException {
InputStream in = null;
try {
in = streamProvider.readFrom(url);
- //todo: should not use JsonRequestBodyParser as this is intended only
for parsing http bodies.
- RequestBody body = (new
JsonRequestBodyParser().parse(IOUtils.toString(in, "UTF-8")));
- Set<NamedPropertySet> setNamedProps = body.getNamedPropertySets();
- Set<Map<String,Object>> setProps = new HashSet<Map<String,
Object>>(setNamedProps.size());
- for (NamedPropertySet ps : setNamedProps) {
- setProps.add(ps.getProperties());
- }
- r.setProperty(propertyIdToSet, setProps);
+ Type mapType = new TypeToken<Map<String, Object>>(){}.getType();
+ Map<String, Object> propertyValueFromJson = new
Gson().fromJson(IOUtils.toString(in, "UTF-8"), mapType);
+ r.setProperty(propertyIdToSet, propertyValueFromJson);
}
catch (IOException ioe) {
- //todo: should not eat exception
LOG.error("Error reading HTTP response from " + url);
- } catch (BodyParseException e) {
- LOG.error("Error Parsing Json.", e);
+ throw new SystemException("Unable to get property " + propertyIdToSet +
"from URL " + url, ioe);
} finally {
- if (null != in) {
+ if (in != null) {
try {
in.close();
}
catch (IOException ioe) {
- //
+ throw new SystemException("Unable to close input stream", ioe);
}
}
}
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=1462547&r1=1462546&r2=1462547&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
Fri Mar 29 17:19:48 2013
@@ -23,6 +23,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -75,22 +76,37 @@ public class HttpPropertyProviderTest {
resource.getPropertyValue(PROPERTY_ID_NAGIOS_ALERTS));
}
+ @SuppressWarnings("rawtypes")
@Test
public void testReadWithRequestedJson() 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);
- Object propertyValue = resource.getPropertyValue(PROPERTY_ID_NAGIOS_ALERTS);
-
- Assert.assertNotNull("Expected non-null for 'nagios_alerts'", propertyValue);
- Assert.assertTrue("Expected Set for parsed JSON", propertyValue instanceof
Set);
-
- Object propertyEntry = ((Set) propertyValue).iterator().next();
-
- Assert.assertTrue(propertyEntry instanceof Map);
- Assert.assertEquals("Alert Body", ((Map) propertyEntry).get("nagios_alert"));
+ 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);
+ Object propertyValue =
resource.getPropertyValue(PROPERTY_ID_NAGIOS_ALERTS);
+
+ Assert.assertNotNull("Expected non-null for 'nagios_alerts'",
propertyValue);
+ Assert.assertTrue("Expected Map for parsed JSON", propertyValue instanceof
Map);
+
+ Object alertsEntry = ((Map) propertyValue).get("alerts");
+ Object hostcountsEntry = ((Map) propertyValue).get("hostcounts");
+
+ Assert.assertNotNull("Expected non-null for 'alerts' entry", alertsEntry);
+ Assert.assertNotNull("Expected non-null for 'hostcounts' entry",
hostcountsEntry);
+ Assert.assertTrue("Expected List type for 'alerts' entry", alertsEntry
instanceof List);
+ Assert.assertTrue("Expected Map type for 'hostcounts' entry",
hostcountsEntry instanceof Map);
+
+ List alertsList = (List) alertsEntry;
+ Map hostcountsMap = (Map) hostcountsEntry;
+
+ Assert.assertEquals("Expected number of entries in 'alerts' is 1", 1,
alertsList.size());
+ Assert.assertTrue("Expected Map type for 'alerts' element",
alertsList.get(0) instanceof Map);
+ Assert.assertEquals("Body", ((Map) alertsList.get(0)).get("Alert Body"));
+
+ Assert.assertEquals("Expected number of entries in 'hostcounts' is 2", 2,
hostcountsMap.size());
+ Assert.assertEquals("1", hostcountsMap.get("up_hosts"));
+ Assert.assertEquals("0", hostcountsMap.get("down_hosts"));
}
@Test
@@ -130,7 +146,8 @@ public class HttpPropertyProviderTest {
@Override
public InputStream readFrom(String spec) throws IOException {
- String responseStr = "[{\"nagios_alert\": \"Alert Body\"}]";
+ String responseStr = "{\"alerts\": [{\"Alert Body\": \"Body\"}],"
+ + " \"hostcounts\": {\"up_hosts\":\"1\", \"down_hosts\":\"0\"}}";
return new ByteArrayInputStream(responseStr.getBytes("UTF-8"));
}
}
Modified:
incubator/ambari/trunk/contrib/addons/src/addOns/nagios/scripts/nagios_alerts.php
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/contrib/addons/src/addOns/nagios/scripts/nagios_alerts.php?rev=1462547&r1=1462546&r2=1462547&view=diff
==============================================================================
---
incubator/ambari/trunk/contrib/addons/src/addOns/nagios/scripts/nagios_alerts.php
(original)
+++
incubator/ambari/trunk/contrib/addons/src/addOns/nagios/scripts/nagios_alerts.php
Fri Mar 29 17:19:48 2013
@@ -224,6 +224,7 @@ function hdp_mon_generate_response( $res
if ($services_object["PUPPET"] >= 1) {
$services_object["PUPPET"] = 1;
}
+ $services_object = array_map('strval', $services_object);
return $services_object;
}
@@ -242,6 +243,7 @@ function hdp_mon_generate_response( $res
}
$hostcounts_object['up_hosts'] = $up_hosts;
$hostcounts_object['down_hosts'] = $down_hosts;
+ $hostcounts_object = array_map('strval', $hostcounts_object);
return $hostcounts_object;
}