You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ma...@apache.org on 2013/02/07 08:59:33 UTC
svn commit: r1443344 - in /incubator/ambari/trunk: ./
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/
ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/
ambari-server/src/main/java/org/apache/ambari/server/st...
Author: mahadev
Date: Thu Feb 7 07:59:32 2013
New Revision: 1443344
URL: http://svn.apache.org/viewvc?rev=1443344&view=rev
Log:
AMBARI-1260. Remove hard coded JMX port mappings. (Siddharth Wagle via mahadev)
Added:
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JMXHostProviderTest.java
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/jmx/JMXHostProvider.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXPropertyProvider.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/JMXPropertyProviderTest.java
Modified: incubator/ambari/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1443344&r1=1443343&r2=1443344&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Thu Feb 7 07:59:32 2013
@@ -253,6 +253,9 @@ Trunk (unreleased changes):
AMBARI-1287. Monitor for component/service state for gsInstaller resource provider. (tbeerbower)
+ AMBARI-1260. Remove hard coded JMX port mappings. (Siddharth Wagle via
+ mahadev)
+
BUG FIXES
AMBARI-1356. Error in filtering Configuration properties maintained at UI for
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=1443344&r1=1443343&r2=1443344&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 Thu Feb 7 07:59:32 2013
@@ -30,16 +30,12 @@ import org.apache.ambari.server.controll
import org.apache.ambari.server.controller.utilities.PredicateBuilder;
import org.apache.ambari.server.controller.utilities.PropertyHelper;
import org.apache.ambari.server.controller.AmbariManagementController;
-
import com.google.inject.Inject;
+import org.apache.ambari.server.state.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
/**
* An abstract provider module implementation.
@@ -51,6 +47,38 @@ public abstract class AbstractProviderMo
private static final String HOST_COMPONENT_HOST_NAME_PROPERTY_ID = PropertyHelper.getPropertyId("HostRoles", "host_name");
private static final String HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID = PropertyHelper.getPropertyId("HostRoles", "component_name");
private static final String GANGLIA_SERVER = "GANGLIA_SERVER";
+ private static final String PROPERTIES_CATEGORY = "properties";
+ private static final Map<Service.Type, String> serviceConfigVersions =
+ Collections.synchronizedMap(new HashMap<Service.Type, String>());
+ private static final Map<Service.Type, String> serviceConfigTypes = new HashMap<Service.Type, String>();
+ private static final Map<Service.Type, Map<String, String>> serviceDesiredProperties = new
+ HashMap<Service.Type, Map<String, String>>();
+ private static final Map<String, Service.Type> componentServiceMap = new
+ HashMap<String, Service.Type>();
+
+ static {
+ serviceConfigTypes.put(Service.Type.HDFS, "hdfs-site");
+ serviceConfigTypes.put(Service.Type.MAPREDUCE, "mapred-site");
+ serviceConfigTypes.put(Service.Type.HBASE, "hbase-site");
+
+ componentServiceMap.put("NAMENODE", Service.Type.HDFS);
+ componentServiceMap.put("DATANODE", Service.Type.HDFS);
+ componentServiceMap.put("JOBTRACKER", Service.Type.MAPREDUCE);
+ componentServiceMap.put("TASKTRACKER", Service.Type.MAPREDUCE);
+ componentServiceMap.put("HBASE_MASTER", Service.Type.HBASE);
+
+ Map<String, String> initPropMap = new HashMap<String, String>();
+ initPropMap.put("NAMENODE", "dfs.http.address");
+ initPropMap.put("DATANODE", "dfs.datanode.http.address");
+ serviceDesiredProperties.put(Service.Type.HDFS, initPropMap);
+ initPropMap = new HashMap<String, String>();
+ initPropMap.put("JOBTRACKER", "mapred.job.tracker.http.address");
+ initPropMap.put("TASKTRACKER", "mapred.task.tracker.http.address");
+ serviceDesiredProperties.put(Service.Type.MAPREDUCE, initPropMap);
+ initPropMap = new HashMap<String, String>();
+ initPropMap.put("HBASE_MASTER", "hbase.master.info.port");
+ serviceDesiredProperties.put(Service.Type.HBASE, initPropMap);
+ }
/**
* The map of resource providers.
@@ -75,6 +103,12 @@ public abstract class AbstractProviderMo
*/
private Map<String, String> clusterGangliaCollectorMap;
+ /**
+ * JMX ports read from the configs
+ */
+ private Map<String, Map<String, String>> jmxPortMap = Collections
+ .synchronizedMap(new HashMap<String, Map<String, String>>());
+
private volatile boolean initialized = false;
protected final static Logger LOG =
@@ -135,6 +169,43 @@ public abstract class AbstractProviderMo
return clusterHostComponentMap.get(clusterName).get(componentName);
}
+ @Override
+ public String getPort(String clusterName, String componentName) throws
+ SystemException {
+ Map<String,String> clusterJmxPorts = jmxPortMap.get(clusterName);
+ if (clusterJmxPorts == null) {
+ synchronized (jmxPortMap) {
+ if (clusterJmxPorts == null) {
+ clusterJmxPorts = new HashMap<String, String>();
+ jmxPortMap.put(clusterName, clusterJmxPorts);
+ }
+ }
+ }
+ Service.Type service = componentServiceMap.get(componentName);
+ if (service != null) {
+ try {
+ String currVersion = getDesiredConfigVersion(clusterName, service.name(),
+ serviceConfigTypes.get(service));
+
+ String oldVersion = serviceConfigVersions.get(service);
+ if (!currVersion.equals(oldVersion)) {
+ serviceConfigVersions.put(service, currVersion);
+ Map<String, String> portMap = getDesiredConfigMap(clusterName,
+ currVersion, serviceConfigTypes.get(service),
+ serviceDesiredProperties.get(service));
+ for (String compName : portMap.keySet()) {
+ clusterJmxPorts.put(compName, getPortString(portMap.get
+ (compName)));
+ }
+ }
+ } catch (Exception e) {
+ LOG.error("Exception initializing jmx port maps. " + e);
+ }
+ }
+
+ LOG.debug("jmxPortMap -> " + jmxPortMap);
+ return clusterJmxPorts.get(componentName);
+ }
// ----- GangliaHostProvider -----------------------------------------------
@@ -260,6 +331,7 @@ public abstract class AbstractProviderMo
Request request = PropertyHelper.getReadRequest(CLUSTER_NAME_PROPERTY_ID);
try {
+ jmxPortMap = new HashMap<String, Map<String, String>>();
Set<Resource> clusters = provider.getResources(request, null);
clusterHostComponentMap = new HashMap<String, Map<String, String>>();
@@ -276,7 +348,7 @@ public abstract class AbstractProviderMo
HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID);
Predicate predicate = new PredicateBuilder().property(HOST_COMPONENT_CLUSTER_NAME_PROPERTY_ID).
- equals(clusterName).toPredicate();
+ equals(clusterName).toPredicate();
Set<Resource> hostComponents = provider.getResources(request, predicate);
Map<String, String> hostComponentMap = clusterHostComponentMap.get(clusterName);
@@ -315,4 +387,79 @@ public abstract class AbstractProviderMo
throw new SystemException("An exception occurred while initializing the host mappings: " + e, e);
}
}
+
+ private String getPortString(String value) {
+ return value != null && value.contains(":") ? value.substring
+ (value.lastIndexOf(":") + 1, value.length()) : value;
+ }
+
+ private String getDesiredConfigVersion(String clusterName,
+ String serviceName, String configType) throws
+ NoSuchParentResourceException, UnsupportedPropertyException,
+ SystemException {
+
+ // Get config version tag
+ ResourceProvider serviceResourceProvider = getResourceProvider(Resource.Type.Service);
+ Predicate basePredicate = new PredicateBuilder().property
+ (ServiceResourceProvider.SERVICE_CLUSTER_NAME_PROPERTY_ID).equals(clusterName).and()
+ .property(ServiceResourceProvider.SERVICE_SERVICE_NAME_PROPERTY_ID).equals(serviceName).toPredicate();
+
+ Set<Resource> serviceResource = null;
+ try {
+ serviceResource = serviceResourceProvider.getResources(
+ PropertyHelper.getReadRequest(ServiceResourceProvider.SERVICE_CLUSTER_NAME_PROPERTY_ID,
+ ServiceResourceProvider.SERVICE_SERVICE_NAME_PROPERTY_ID,
+ ServiceResourceProvider.SERVICE_DESIRED_CONFIGS_PROPERTY_ID), basePredicate);
+ } catch (NoSuchResourceException e) {
+ LOG.error("Resource for the desired config not found. " + e);
+ }
+
+ String versionTag = "version1";
+ if (serviceResource != null) {
+ for (Resource res : serviceResource) {
+ Map<String, String> configs = (Map<String,
+ String>) res.getPropertyValue(ServiceResourceProvider.SERVICE_DESIRED_CONFIGS_PROPERTY_ID);
+ if (configs != null) {
+ versionTag = configs.get(configType);
+ }
+ }
+ }
+ return versionTag;
+ }
+
+ private Map<String, String> getDesiredConfigMap(String clusterName,
+ String versionTag, String configType, Map<String, String> keys) throws
+ NoSuchParentResourceException, UnsupportedPropertyException,
+ SystemException {
+ // Get desired configs based on the tag
+ ResourceProvider configResourceProvider = getResourceProvider(Resource.Type.Configuration);
+ Predicate configPredicate = new PredicateBuilder().property
+ (ConfigurationResourceProvider.CONFIGURATION_CLUSTER_NAME_PROPERTY_ID).equals(clusterName).and()
+ .property(ConfigurationResourceProvider.CONFIGURATION_CONFIG_TYPE_PROPERTY_ID).equals(configType).and()
+ .property(ConfigurationResourceProvider.CONFIGURATION_CONFIG_TAG_PROPERTY_ID).equals(versionTag).toPredicate();
+ Set<Resource> configResources = null;
+ try {
+ configResources = configResourceProvider.getResources
+ (PropertyHelper.getReadRequest(ConfigurationResourceProvider.CONFIGURATION_CLUSTER_NAME_PROPERTY_ID,
+ ConfigurationResourceProvider.CONFIGURATION_CONFIG_TYPE_PROPERTY_ID,
+ ConfigurationResourceProvider.CONFIGURATION_CONFIG_TAG_PROPERTY_ID), configPredicate);
+ } catch (NoSuchResourceException e) {
+ LOG.info("Resource for the desired config not found. " + e);
+ return Collections.EMPTY_MAP;
+ }
+ Map<String, String> mConfigs = new HashMap<String, String>();
+ if (configResources != null) {
+ for (Resource res : configResources) {
+ for (String key : keys.keySet()) {
+ String value = (String) res.getPropertyValue
+ (PropertyHelper.getPropertyId(PROPERTIES_CATEGORY, keys.get(key)));
+ LOG.debug("PROPERTY -> key: " + keys.get(key) + ", " +
+ "value: " + value);
+
+ mConfigs.put(key, value);
+ }
+ }
+ }
+ return mConfigs;
+ }
}
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXHostProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXHostProvider.java?rev=1443344&r1=1443343&r2=1443344&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXHostProvider.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXHostProvider.java Thu Feb 7 07:59:32 2013
@@ -37,4 +37,15 @@ public interface JMXHostProvider {
* @throws SystemException of unable to ge the JMX host name
*/
public String getHostName(String clusterName, String componentName) throws SystemException;
+
+ /**
+ * Get the port for specified cluster name and component
+ *
+ * @param clusterName
+ * @param componentName
+ * @return
+ * @throws SystemException
+ */
+ public String getPort(String clusterName, String componentName) throws
+ SystemException;
}
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXPropertyProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXPropertyProvider.java?rev=1443344&r1=1443343&r2=1443344&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXPropertyProvider.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXPropertyProvider.java Thu Feb 7 07:59:32 2013
@@ -49,8 +49,6 @@ public class JMXPropertyProvider extends
private final JMXHostProvider jmxHostProvider;
- private static final Map<String, String> JMX_PORTS = new HashMap<String, String>();
-
private final String clusterNamePropertyId;
private final String hostNamePropertyId;
@@ -61,12 +59,6 @@ public class JMXPropertyProvider extends
static {
- JMX_PORTS.put("NAMENODE", "50070");
- JMX_PORTS.put("DATANODE", "50075");
- JMX_PORTS.put("JOBTRACKER", "50030");
- JMX_PORTS.put("TASKTRACKER", "50060");
- JMX_PORTS.put("HBASE_MASTER", "60010");
-
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationConfig.Feature.USE_ANNOTATIONS, false);
objectReader = objectMapper.reader(JMXMetricHolder.class);
@@ -143,7 +135,7 @@ public class JMXPropertyProvider extends
String clusterName = (String) resource.getPropertyValue(clusterNamePropertyId);
String componentName = (String) resource.getPropertyValue(componentNamePropertyId);
- String port = JMX_PORTS.get(componentName);
+ String port = jmxHostProvider.getPort(clusterName, componentName);
String hostName;
if (hostNamePropertyId == null) {
@@ -269,4 +261,5 @@ public class JMXPropertyProvider extends
protected String getSpec(String jmxSource) {
return "http://" + jmxSource + "/jmx";
}
+
}
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java?rev=1443344&r1=1443343&r2=1443344&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java Thu Feb 7 07:59:32 2013
@@ -84,4 +84,17 @@ public interface Service {
public boolean isClientOnlyService();
public void delete() throws AmbariException;
+
+ public enum Type {
+ HDFS,
+ MAPREDUCE,
+ HBASE,
+ HIVE,
+ OOZIE,
+ WEBHCAT,
+ SQOOP,
+ NAGIOS,
+ GANGLIA,
+ ZOOKEEPER
+ }
}
Added: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JMXHostProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JMXHostProviderTest.java?rev=1443344&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JMXHostProviderTest.java (added)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JMXHostProviderTest.java Thu Feb 7 07:59:32 2013
@@ -0,0 +1,210 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.server.controller.internal;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.api.services.AmbariMetaInfo;
+import org.apache.ambari.server.controller.*;
+import org.apache.ambari.server.controller.spi.*;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.apache.ambari.server.orm.GuiceJpaInitializer;
+import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
+import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.StackId;
+import org.apache.ambari.server.state.State;
+import org.apache.ambari.server.state.cluster.ClusterImpl;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+public class JMXHostProviderTest {
+ private Injector injector;
+ private Clusters clusters;
+ static AmbariManagementController controller;
+ private AmbariMetaInfo ambariMetaInfo;
+ private static final String NAMENODE_PORT = "dfs.http.address";
+ private static final String DATANODE_PORT = "dfs.datanode.http.address";
+
+ @Before
+ public void setup() throws Exception {
+ injector = Guice.createInjector(new InMemoryDefaultTestModule());
+ injector.getInstance(GuiceJpaInitializer.class);
+ clusters = injector.getInstance(Clusters.class);
+ controller = injector.getInstance(AmbariManagementController.class);
+ ambariMetaInfo = injector.getInstance(AmbariMetaInfo.class);
+ ambariMetaInfo.init();
+ }
+
+ private void createService(String clusterName,
+ String serviceName, State desiredState) throws AmbariException {
+ String dStateStr = null;
+ if (desiredState != null) {
+ dStateStr = desiredState.toString();
+ }
+ ServiceRequest r1 = new ServiceRequest(clusterName, serviceName, null,
+ dStateStr);
+ Set<ServiceRequest> requests = new HashSet<ServiceRequest>();
+ requests.add(r1);
+ controller.createServices(requests);
+ }
+
+ private void createServiceComponent(String clusterName,
+ String serviceName, String componentName, State desiredState)
+ throws AmbariException {
+ String dStateStr = null;
+ if (desiredState != null) {
+ dStateStr = desiredState.toString();
+ }
+ ServiceComponentRequest r = new ServiceComponentRequest(clusterName,
+ serviceName, componentName, null, dStateStr);
+ Set<ServiceComponentRequest> requests =
+ new HashSet<ServiceComponentRequest>();
+ requests.add(r);
+ controller.createComponents(requests);
+ }
+
+ private void createServiceComponentHost(String clusterName,
+ String serviceName, String componentName, String hostname,
+ State desiredState) throws AmbariException {
+ String dStateStr = null;
+ if (desiredState != null) {
+ dStateStr = desiredState.toString();
+ }
+ ServiceComponentHostRequest r = new ServiceComponentHostRequest(clusterName,
+ serviceName, componentName, hostname, null, dStateStr);
+ Set<ServiceComponentHostRequest> requests =
+ new HashSet<ServiceComponentHostRequest>();
+ requests.add(r);
+ controller.createHostComponents(requests);
+ }
+
+ private void createHDFSServiceConfigs() throws AmbariException {
+ String clusterName = "c1";
+ ClusterRequest r = new ClusterRequest(null, clusterName, "HDP-0.1", null);
+ controller.createCluster(r);
+ clusters.getCluster(clusterName).setDesiredStackVersion(new StackId("HDP-0.1"));
+ String serviceName = "HDFS";
+ createService(clusterName, serviceName, null);
+ String componentName1 = "NAMENODE";
+ String componentName2 = "DATANODE";
+ String componentName3 = "HDFS_CLIENT";
+
+ createServiceComponent(clusterName, serviceName, componentName1,
+ State.INIT);
+ createServiceComponent(clusterName, serviceName, componentName2,
+ State.INIT);
+ createServiceComponent(clusterName, serviceName, componentName3,
+ State.INIT);
+
+ String host1 = "h1";
+ clusters.addHost(host1);
+ clusters.getHost("h1").setOsType("centos5");
+ clusters.getHost("h1").persist();
+ String host2 = "h2";
+ clusters.addHost(host2);
+ clusters.getHost("h2").setOsType("centos6");
+ clusters.getHost("h2").persist();
+ clusters.mapHostToCluster(host1, clusterName);
+ clusters.mapHostToCluster(host2, clusterName);
+
+ createServiceComponentHost(clusterName, null, componentName1,
+ host1, null);
+ createServiceComponentHost(clusterName, serviceName, componentName2,
+ host1, null);
+ createServiceComponentHost(clusterName, serviceName, componentName2,
+ host2, null);
+ createServiceComponentHost(clusterName, serviceName, componentName3,
+ host1, null);
+ createServiceComponentHost(clusterName, serviceName, componentName3,
+ host2, null);
+
+ // Create configs
+ Map<String, String> configs = new HashMap<String, String>();
+ configs.put(NAMENODE_PORT, "localhost:70070");
+ configs.put(DATANODE_PORT, "localhost:70075");
+ ConfigurationRequest cr = new ConfigurationRequest(clusterName,
+ "hdfs-site", "version1", configs);
+ controller.createConfiguration(cr);
+
+ Map<String, String> configVersions = new HashMap<String, String>();
+ Set<ServiceRequest> sReqs = new HashSet<ServiceRequest>();
+ configVersions.put("hdfs-site", "version1");
+ sReqs.add(new ServiceRequest(clusterName, serviceName, configVersions,
+ null));
+ controller.updateServices(sReqs);
+ }
+
+
+ @Test
+ public void testJMXPortMapInit() throws NoSuchParentResourceException, ResourceAlreadyExistsException, UnsupportedPropertyException, SystemException, AmbariException, NoSuchResourceException {
+ createHDFSServiceConfigs();
+
+ JMXHostProviderModule providerModule = new JMXHostProviderModule();
+ providerModule.registerResourceProvider(Resource.Type.Service);
+ providerModule.registerResourceProvider(Resource.Type.Configuration);
+ // Non default port addresses
+ Assert.assertEquals("70070", providerModule.getPort("c1", "NAMENODE"));
+ Assert.assertEquals("70075", providerModule.getPort("c1", "DATANODE"));
+ // Default port addresses
+ Assert.assertEquals(null, providerModule.getPort("c1", "JOBTRACKER"));
+ Assert.assertEquals(null, providerModule.getPort("c1", "TASKTRACKER"));
+ Assert.assertEquals(null, providerModule.getPort("c1", "HBASE_MASTER"));
+ }
+
+ private static class JMXHostProviderModule extends
+ AbstractProviderModule {
+
+ ResourceProvider clusterResourceProvider = new
+ ClusterResourceProvider(PropertyHelper.getPropertyIds(Resource.Type
+ .Cluster), PropertyHelper.getKeyPropertyIds(Resource.Type.Cluster),
+ controller);
+
+ ResourceProvider serviceResourceProvider = new ServiceResourceProvider(PropertyHelper
+ .getPropertyIds(Resource.Type.Service),
+ PropertyHelper.getKeyPropertyIds(Resource.Type.Service), controller);
+
+ ResourceProvider hostCompResourceProvider = new
+ HostComponentResourceProvider(PropertyHelper.getPropertyIds(Resource
+ .Type.HostComponent), PropertyHelper.getKeyPropertyIds(Resource.Type
+ .HostComponent), controller);
+
+ ResourceProvider configResourceProvider = new
+ ConfigurationResourceProvider(PropertyHelper.getPropertyIds(Resource
+ .Type.Configuration), PropertyHelper.getKeyPropertyIds(Resource.Type
+ .Configuration), controller);
+
+ @Override
+ protected ResourceProvider createResourceProvider(Resource.Type type) {
+ if (type == Resource.Type.Cluster)
+ return clusterResourceProvider;
+ if (type == Resource.Type.Service)
+ return serviceResourceProvider;
+ else if (type == Resource.Type.HostComponent)
+ return hostCompResourceProvider;
+ else if (type == Resource.Type.Configuration)
+ return configResourceProvider;
+ return null;
+ }
+ }
+}
Modified: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/JMXPropertyProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/JMXPropertyProviderTest.java?rev=1443344&r1=1443343&r2=1443344&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/JMXPropertyProviderTest.java (original)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/JMXPropertyProviderTest.java Thu Feb 7 07:59:32 2013
@@ -18,16 +18,25 @@
package org.apache.ambari.server.controller.jmx;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.api.services.AmbariMetaInfo;
+import org.apache.ambari.server.controller.*;
+import org.apache.ambari.server.controller.internal.AbstractProviderModule;
+import org.apache.ambari.server.controller.internal.DefaultProviderModule;
import org.apache.ambari.server.controller.internal.ResourceImpl;
-import org.apache.ambari.server.controller.spi.Request;
-import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.spi.*;
+import org.apache.ambari.server.controller.utilities.PredicateBuilder;
import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.apache.ambari.server.orm.GuiceJpaInitializer;
+import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
+import org.apache.ambari.server.state.*;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
+import java.util.*;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
/**
* JMX property provider tests.
@@ -36,12 +45,10 @@ public class JMXPropertyProviderTest {
protected static final String HOST_COMPONENT_HOST_NAME_PROPERTY_ID = PropertyHelper.getPropertyId("HostRoles", "host_name");
protected static final String HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID = PropertyHelper.getPropertyId("HostRoles", "component_name");
-
@Test
public void testGetResources() throws Exception {
-
TestStreamProvider streamProvider = new TestStreamProvider();
- TestJMXHostProvider hostProvider = new TestJMXHostProvider();
+ TestJMXHostProvider hostProvider = new TestJMXHostProvider();
JMXPropertyProvider propertyProvider = new JMXPropertyProvider(
PropertyHelper.getJMXPropertyIds(Resource.Type.HostComponent),
@@ -180,5 +187,23 @@ public class JMXPropertyProviderTest {
public String getHostName(String clusterName, String componentName) {
return null;
}
+
+ @Override
+ public String getPort(String clusterName, String componentName) throws
+ SystemException {
+ if (componentName.equals("NAMENODE"))
+ return "50070";
+ else if (componentName.equals("DATANODE"))
+ return "50075";
+ else if (componentName.equals("JOBTRACKER"))
+ return "50030";
+ else if (componentName.equals("TASKTRACKER"))
+ return "50060";
+ else if (componentName.equals("HBASE_MASTER"))
+ return "60010";
+ else
+ return null;
+ }
+
}
}