|
@@ -30,16 +30,12 @@ import org.apache.ambari.server.controller.spi.*;
|
|
import org.apache.ambari.server.controller.utilities.PredicateBuilder;
|
|
import org.apache.ambari.server.controller.utilities.PredicateBuilder;
|
|
import org.apache.ambari.server.controller.utilities.PropertyHelper;
|
|
import org.apache.ambari.server.controller.utilities.PropertyHelper;
|
|
import org.apache.ambari.server.controller.AmbariManagementController;
|
|
import org.apache.ambari.server.controller.AmbariManagementController;
|
|
-
|
|
|
|
import com.google.inject.Inject;
|
|
import com.google.inject.Inject;
|
|
|
|
+import org.apache.ambari.server.state.Service;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
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.
|
|
* An abstract provider module implementation.
|
|
@@ -51,6 +47,38 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
|
|
private static final String HOST_COMPONENT_HOST_NAME_PROPERTY_ID = PropertyHelper.getPropertyId("HostRoles", "host_name");
|
|
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 HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID = PropertyHelper.getPropertyId("HostRoles", "component_name");
|
|
private static final String GANGLIA_SERVER = "GANGLIA_SERVER";
|
|
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.
|
|
* The map of resource providers.
|
|
@@ -75,6 +103,12 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
|
|
*/
|
|
*/
|
|
private Map<String, String> clusterGangliaCollectorMap;
|
|
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;
|
|
private volatile boolean initialized = false;
|
|
|
|
|
|
protected final static Logger LOG =
|
|
protected final static Logger LOG =
|
|
@@ -135,6 +169,43 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
|
|
return clusterHostComponentMap.get(clusterName).get(componentName);
|
|
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 -----------------------------------------------
|
|
// ----- GangliaHostProvider -----------------------------------------------
|
|
|
|
|
|
@@ -260,6 +331,7 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
|
|
Request request = PropertyHelper.getReadRequest(CLUSTER_NAME_PROPERTY_ID);
|
|
Request request = PropertyHelper.getReadRequest(CLUSTER_NAME_PROPERTY_ID);
|
|
|
|
|
|
try {
|
|
try {
|
|
|
|
+ jmxPortMap = new HashMap<String, Map<String, String>>();
|
|
Set<Resource> clusters = provider.getResources(request, null);
|
|
Set<Resource> clusters = provider.getResources(request, null);
|
|
|
|
|
|
clusterHostComponentMap = new HashMap<String, Map<String, String>>();
|
|
clusterHostComponentMap = new HashMap<String, Map<String, String>>();
|
|
@@ -276,7 +348,7 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
|
|
HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID);
|
|
HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID);
|
|
|
|
|
|
Predicate predicate = new PredicateBuilder().property(HOST_COMPONENT_CLUSTER_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);
|
|
Set<Resource> hostComponents = provider.getResources(request, predicate);
|
|
Map<String, String> hostComponentMap = clusterHostComponentMap.get(clusterName);
|
|
Map<String, String> hostComponentMap = clusterHostComponentMap.get(clusterName);
|
|
@@ -315,4 +387,79 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
|
|
throw new SystemException("An exception occurred while initializing the host mappings: " + e, e);
|
|
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;
|
|
|
|
+ }
|
|
}
|
|
}
|