|
@@ -24,15 +24,10 @@ import org.apache.ambari.server.controller.spi.PropertyProvider;
|
|
|
import org.apache.ambari.server.controller.spi.Request;
|
|
|
import org.apache.ambari.server.controller.spi.Resource;
|
|
|
import org.apache.ambari.server.controller.utilities.PropertyHelper;
|
|
|
-import org.apache.ambari.server.controller.utilities.StreamProvider;
|
|
|
import org.junit.Assert;
|
|
|
import org.junit.Test;
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
-import java.io.InputStream;
|
|
|
import java.util.Collections;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
|
|
|
/**
|
|
@@ -40,24 +35,7 @@ import java.util.Set;
|
|
|
*/
|
|
|
public class JMXPropertyProviderTest {
|
|
|
|
|
|
- private static Map<String, String> HOST_MAPPING = new HashMap<String, String>();
|
|
|
-
|
|
|
- static {
|
|
|
- HOST_MAPPING.put("domU-12-31-39-0E-34-E1.compute-1.internal", "ec2-50-17-129-192.compute-1.amazonaws.com");
|
|
|
- HOST_MAPPING.put("ip-10-190-186-15.ec2.internal", "ec2-23-21-8-226.compute-1.amazonaws.com");
|
|
|
- HOST_MAPPING.put("domU-12-31-39-14-EE-B3.compute-1.internal", "ec2-23-23-71-42.compute-1.amazonaws.com");
|
|
|
- HOST_MAPPING.put("ip-10-110-157-51.ec2.internal", "ec2-107-22-121-67.compute-1.amazonaws.com");
|
|
|
- }
|
|
|
-
|
|
|
- private static Map<String, String> FILE_MAPPING = new HashMap<String, String>();
|
|
|
-
|
|
|
- static {
|
|
|
- FILE_MAPPING.put("http://ec2-23-21-8-226.compute-1.amazonaws.com:50070/jmx?qry=Hadoop:*", "hdfs_namenode_jmx.json");
|
|
|
- FILE_MAPPING.put("http://ec2-23-23-71-42.compute-1.amazonaws.com:50075/jmx?qry=Hadoop:*", "hdfs_datanode_jmx.json");
|
|
|
- FILE_MAPPING.put("http://ec2-23-23-71-42.compute-1.amazonaws.com:50030/jmx?qry=Hadoop:*", "mapreduce_jobtracker_jmx.json");
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
+ @Test
|
|
|
public void testGetResources() throws Exception {
|
|
|
|
|
|
Set< PropertyId > propertyIds = PropertyHelper.getPropertyIds(Resource.Type.HostComponent, "JMX");
|
|
@@ -71,7 +49,7 @@ public class JMXPropertyProviderTest {
|
|
|
// namenode
|
|
|
Resource resource = new ResourceImpl(Resource.Type.HostComponent);
|
|
|
|
|
|
- resource.setProperty(JMXPropertyProvider.HOST_COMPONENT_HOST_NAME_PROPERTY_ID, "ip-10-190-186-15.ec2.internal");
|
|
|
+ resource.setProperty(JMXPropertyProvider.HOST_COMPONENT_HOST_NAME_PROPERTY_ID, "domU-12-31-39-0E-34-E1.compute-1.internal");
|
|
|
resource.setProperty(JMXPropertyProvider.HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID, "NAMENODE");
|
|
|
|
|
|
// request with an empty set should get all supported properties
|
|
@@ -79,7 +57,7 @@ public class JMXPropertyProviderTest {
|
|
|
|
|
|
Assert.assertEquals(1, propertyProvider.populateResources(Collections.singleton(resource), request, null).size());
|
|
|
|
|
|
- Assert.assertEquals(JMXPropertyProvider.getSpec("ec2-23-21-8-226.compute-1.amazonaws.com:50070"), streamProvider.getLastSpec());
|
|
|
+ Assert.assertEquals(JMXPropertyProvider.getSpec("ec2-50-17-129-192.compute-1.amazonaws.com:50070"), streamProvider.getLastSpec());
|
|
|
|
|
|
// see test/resources/hdfs_namenode_jmx.json for values
|
|
|
Assert.assertEquals("1084287", resource.getPropertyValue(PropertyHelper.getPropertyId("ReceivedBytes", "rpc")));
|
|
@@ -124,31 +102,4 @@ public class JMXPropertyProviderTest {
|
|
|
Assert.assertEquals("59", resource.getPropertyValue(PropertyHelper.getPropertyId("threadsWaiting", "jvm")));
|
|
|
Assert.assertNull(resource.getPropertyValue(PropertyHelper.getPropertyId("gcCount", "jvm")));
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- public static class TestStreamProvider implements StreamProvider {
|
|
|
- private String lastSpec;
|
|
|
-
|
|
|
- @Override
|
|
|
- public InputStream readFrom(String spec) throws IOException {
|
|
|
- lastSpec = spec;
|
|
|
- String filename = FILE_MAPPING.get(spec);
|
|
|
- if (filename == null) {
|
|
|
- throw new IOException("Can't find JMX source for " + spec);
|
|
|
- }
|
|
|
- InputStream resourceAsStream = ClassLoader.getSystemResourceAsStream(filename);
|
|
|
- return resourceAsStream;
|
|
|
- }
|
|
|
-
|
|
|
- public String getLastSpec() {
|
|
|
- return lastSpec;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public static class TestHostMappingProvider implements HostMappingProvider {
|
|
|
- @Override
|
|
|
- public Map<String, String> getHostMap() {
|
|
|
- return HOST_MAPPING;
|
|
|
- }
|
|
|
- }
|
|
|
}
|