You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by yu...@apache.org on 2014/10/08 00:52:35 UTC
[07/51] [partial] AMBARI-7621. Import initial contribution for Ambari
support on Windows to branch-windows-dev. (Jayush Luniya and Florian Barca
via yusaku)
http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java
index b5164fe..3e59c63 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java
@@ -21,6 +21,7 @@ package org.apache.ambari.server.controller.internal;
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.Role;
import org.apache.ambari.server.configuration.ComponentSSLConfiguration;
+import org.apache.ambari.server.configuration.Configuration;
import org.apache.ambari.server.controller.AmbariServer;
import org.apache.ambari.server.controller.HostRequest;
import org.apache.ambari.server.controller.HostResponse;
@@ -33,9 +34,11 @@ import org.apache.ambari.server.controller.ganglia.GangliaReportPropertyProvider
import org.apache.ambari.server.controller.ganglia.GangliaHostProvider;
import org.apache.ambari.server.controller.jmx.JMXHostProvider;
import org.apache.ambari.server.controller.jmx.JMXPropertyProvider;
-import org.apache.ambari.server.controller.metrics.MetricsHostProvider;
import org.apache.ambari.server.controller.nagios.NagiosPropertyProvider;
import org.apache.ambari.server.controller.spi.*;
+import org.apache.ambari.server.controller.sql.HostInfoProvider;
+import org.apache.ambari.server.controller.sql.SQLPropertyProvider;
+import org.apache.ambari.server.controller.sql.SinkConnectionFactory;
import org.apache.ambari.server.controller.utilities.PredicateBuilder;
import org.apache.ambari.server.controller.utilities.PropertyHelper;
import org.apache.ambari.server.controller.AmbariManagementController;
@@ -47,18 +50,19 @@ import org.apache.ambari.server.state.DesiredConfig;
import org.apache.ambari.server.state.HostState;
import org.apache.ambari.server.state.Service;
import org.apache.ambari.server.state.State;
-import org.apache.ambari.server.state.Cluster;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.net.InetAddress;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
+import java.lang.System;
/**
* An abstract provider module implementation.
*/
-public abstract class AbstractProviderModule implements ProviderModule, ResourceProviderObserver, JMXHostProvider, GangliaHostProvider, MetricsHostProvider {
+public abstract class AbstractProviderModule implements ProviderModule, ResourceProviderObserver, JMXHostProvider, GangliaHostProvider, HostInfoProvider {
private static final int PROPERTY_REQUEST_CONNECT_TIMEOUT = 5000;
private static final int PROPERTY_REQUEST_READ_TIMEOUT = 10000;
@@ -135,7 +139,7 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
private final Map<Resource.Type,List<PropertyProvider>> propertyProviders = new HashMap<Resource.Type, List<PropertyProvider>>();
@Inject
- AmbariManagementController managementController;
+ private AmbariManagementController managementController;
/**
* The map of host components.
@@ -205,7 +209,7 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
}
- // ----- MetricsHostProvider ---------------------------------------------------
+ // ----- JMXHostProvider ---------------------------------------------------
@Override
public String getHostName(String clusterName, String componentName) throws SystemException {
@@ -214,21 +218,6 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
}
@Override
- public Set<String> getHostNames(String clusterName, String componentName) {
- Set<String> hosts = null;
- try {
- Cluster cluster = managementController.getClusters().getCluster(clusterName);
- String serviceName = managementController.findServiceName(cluster, componentName);
- hosts = cluster.getService(serviceName).getServiceComponent(componentName).getServiceComponentHosts().keySet();
- } catch (Exception e) {
- LOG.warn("Exception in getting host names for jmx metrics: ", e);
- }
- return hosts;
- }
-
- // ----- JMXHostProvider ---------------------------------------------------
-
- @Override
public String getPort(String clusterName, String componentName) throws SystemException {
// Parent map need not be synchronized
Map<String, String> clusterJmxPorts = jmxPortMap.get(clusterName);
@@ -311,8 +300,47 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
properties.put(key, value);
}
return value;
- }
-
+ }
+
+
+ // ----- HostInfoProvider -----------------------------------------------
+
+ @Override
+ public String getHostName(String id) throws SystemException {
+ return getClusterNodeName(id);
+ }
+
+ @Override
+ public String getHostAddress(String id) throws SystemException {
+ return getClusterHostAddress(id);
+ }
+
+
+ // get the hostname
+ private String getClusterNodeName(String hostname) throws SystemException {
+ try {
+ if (hostname.equalsIgnoreCase("localhost")) {
+ return InetAddress.getLocalHost().getCanonicalHostName();
+ }
+ return InetAddress.getByName(hostname).getCanonicalHostName();
+ } catch (Exception e) {
+ throw new SystemException("Error getting hostname.", e);
+ }
+ }
+
+ // get the hostname
+ private String getClusterHostAddress(String hostname) throws SystemException {
+ try {
+ if (hostname.equalsIgnoreCase("localhost")) {
+ return InetAddress.getLocalHost().getHostAddress();
+ }
+ return InetAddress.getByName(hostname).getHostAddress();
+ } catch (Exception e) {
+ throw new SystemException("Error getting ip address.", e);
+ }
+ }
+
+
// ----- GangliaHostProvider -----------------------------------------------
@Override
@@ -456,25 +484,33 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
type,
streamProvider,
this,
- this,
PropertyHelper.getPropertyId("ServiceComponentInfo", "cluster_name"),
null,
PropertyHelper.getPropertyId("ServiceComponentInfo", "component_name"),
- PropertyHelper.getPropertyId("ServiceComponentInfo", "state"));
-
- PropertyProvider gpp = createGangliaComponentPropertyProvider(
- type,
- streamProvider,
- ComponentSSLConfiguration.instance(),
- this,
- PropertyHelper.getPropertyId("ServiceComponentInfo", "cluster_name"),
- PropertyHelper.getPropertyId("ServiceComponentInfo", "component_name"));
-
+ PropertyHelper.getPropertyId("ServiceComponentInfo", "state"),
+ Collections.singleton("STARTED"));
+ PropertyProvider gpp = null;
+ if (System.getProperty("os.name").contains("Windows")) {
+ gpp = createSQLComponentPropertyProvider(
+ type,
+ this,
+ PropertyHelper.getPropertyId("ServiceComponentInfo", "cluster_name"),
+ PropertyHelper.getPropertyId("ServiceComponentInfo", "component_name"),
+ PropertyHelper.getPropertyId("ServiceComponentInfo", "service_name"));
+ }
+ else {
+ gpp = createGangliaComponentPropertyProvider(
+ type,
+ streamProvider,
+ ComponentSSLConfiguration.instance(),
+ this,
+ PropertyHelper.getPropertyId("ServiceComponentInfo", "cluster_name"),
+ PropertyHelper.getPropertyId("ServiceComponentInfo", "component_name"));
+ }
providers.add(new StackDefinedPropertyProvider(
type,
this,
this,
- this,
streamProvider,
PropertyHelper.getPropertyId("ServiceComponentInfo", "cluster_name"),
null,
@@ -490,26 +526,35 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
type,
streamProvider,
this,
- this,
PropertyHelper.getPropertyId("HostRoles", "cluster_name"),
PropertyHelper.getPropertyId("HostRoles", "host_name"),
PropertyHelper.getPropertyId("HostRoles", "component_name"),
- PropertyHelper.getPropertyId("HostRoles", "state"));
-
- PropertyProvider gpp = createGangliaHostComponentPropertyProvider(
- type,
- streamProvider,
- ComponentSSLConfiguration.instance(),
- this,
- PropertyHelper.getPropertyId("HostRoles", "cluster_name"),
- PropertyHelper.getPropertyId("HostRoles", "host_name"),
- PropertyHelper.getPropertyId("HostRoles", "component_name"));
-
+ PropertyHelper.getPropertyId("HostRoles", "state"),
+ Collections.singleton("STARTED"));
+ PropertyProvider gpp = null;
+ if (System.getProperty("os.name").contains("Windows")) {
+ gpp = createSQLHostComponentPropertyProvider(
+ type,
+ this,
+ PropertyHelper.getPropertyId("HostRoles", "cluster_name"),
+ PropertyHelper.getPropertyId("HostRoles", "host_name"),
+ PropertyHelper.getPropertyId("HostRoles", "component_name"),
+ PropertyHelper.getPropertyId("HostRoles", "service_name"));
+ }
+ else {
+ gpp = createGangliaHostComponentPropertyProvider(
+ type,
+ streamProvider,
+ ComponentSSLConfiguration.instance(),
+ this,
+ PropertyHelper.getPropertyId("HostRoles", "cluster_name"),
+ PropertyHelper.getPropertyId("HostRoles", "host_name"),
+ PropertyHelper.getPropertyId("HostRoles", "component_name"));
+ }
providers.add(new StackDefinedPropertyProvider(
type,
this,
this,
- this,
streamProvider,
PropertyHelper.getPropertyId("HostRoles", "cluster_name"),
PropertyHelper.getPropertyId("HostRoles", "host_name"),
@@ -547,14 +592,7 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
private void initProviderMaps() throws SystemException {
ResourceProvider provider = getResourceProvider(Resource.Type.Cluster);
-
- Set<String> propertyIds = new HashSet<String>();
- propertyIds.add(ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID);
-
- Map<String, String> requestInfoProperties = new HashMap<String, String>();
- requestInfoProperties.put(ClusterResourceProvider.GET_IGNORE_PERMISSIONS_PROPERTY_ID, "true");
-
- Request request = PropertyHelper.getReadRequest(propertyIds, requestInfoProperties, null);
+ Request request = PropertyHelper.getReadRequest(CLUSTER_NAME_PROPERTY_ID);
try {
jmxPortMap.clear();
@@ -633,17 +671,9 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
Set<Resource> clusterResource = null;
try {
-
- Set<String> propertyIds = new HashSet<String>();
- propertyIds.add(ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID);
- propertyIds.add(ClusterResourceProvider.CLUSTER_DESIRED_CONFIGS_PROPERTY_ID);
-
- Map<String, String> requestInfoProperties = new HashMap<String, String>();
- requestInfoProperties.put(ClusterResourceProvider.GET_IGNORE_PERMISSIONS_PROPERTY_ID, "true");
-
- Request readRequest = PropertyHelper.getReadRequest(propertyIds, requestInfoProperties, null);
-
- clusterResource = clusterResourceProvider.getResources(readRequest, basePredicate);
+ clusterResource = clusterResourceProvider.getResources(
+ PropertyHelper.getReadRequest(ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID,
+ ClusterResourceProvider.CLUSTER_DESIRED_CONFIGS_PROPERTY_ID), basePredicate);
} catch (NoSuchResourceException e) {
LOG.error("Resource for the desired config not found. " + e);
}
@@ -657,7 +687,7 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
if (configs != null) {
DesiredConfig config = (DesiredConfig) configs.get(configType);
if (config != null) {
- versionTag = config.getTag();
+ versionTag = config.getVersion();
}
}
}
@@ -733,15 +763,14 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
*/
private PropertyProvider createJMXPropertyProvider(Resource.Type type, StreamProvider streamProvider,
JMXHostProvider jmxHostProvider,
- MetricsHostProvider metricsHostProvider,
String clusterNamePropertyId,
String hostNamePropertyId,
String componentNamePropertyId,
- String statePropertyId) {
+ String statePropertyId,
+ Set<String> healthyStates) {
return new JMXPropertyProvider(PropertyHelper.getJMXPropertyIds(type), streamProvider,
- jmxHostProvider, metricsHostProvider, clusterNamePropertyId, hostNamePropertyId,
- componentNamePropertyId, statePropertyId);
+ jmxHostProvider, clusterNamePropertyId, hostNamePropertyId, componentNamePropertyId, statePropertyId, healthyStates);
}
/**
@@ -794,6 +823,46 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
return new GangliaHostComponentPropertyProvider(PropertyHelper.getGangliaPropertyIds(type), streamProvider,
configuration, hostProvider, clusterNamePropertyId, hostNamePropertyId, componentNamePropertyId);
}
+
+ /**
+ * Create the SQL component property provider for the given type.
+ */
+ private PropertyProvider createSQLComponentPropertyProvider( Resource.Type type,
+ HostInfoProvider hostProvider,
+ String clusterNamePropertyId,
+ String componentNamePropertyId,
+ String serviceNamePropertyId) {
+ return new SQLPropertyProvider(
+ PropertyHelper.getSQLServerPropertyIds(type),
+ hostProvider,
+ clusterNamePropertyId,
+ null,
+ componentNamePropertyId,
+ serviceNamePropertyId,
+ SinkConnectionFactory.instance());
+ }
+
+
+ /**
+ * Create the SQL host component property provider for the given type.
+ */
+ private PropertyProvider createSQLHostComponentPropertyProvider( Resource.Type type,
+ HostInfoProvider hostProvider,
+ String clusterNamePropertyId,
+ String hostNamePropertyId,
+ String componentNamePropertyId,
+ String serviceNamePropertyId) {
+
+ return new SQLPropertyProvider(
+ PropertyHelper.getSQLServerPropertyIds(type),
+ hostProvider,
+ clusterNamePropertyId,
+ hostNamePropertyId,
+ componentNamePropertyId,
+ serviceNamePropertyId,
+ SinkConnectionFactory.instance());
+ }
+
@Override
public String getJMXProtocol(String clusterName, String componentName) {
http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractResourceProvider.java
index 2c25623..8caa01b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractResourceProvider.java
@@ -20,7 +20,6 @@ package org.apache.ambari.server.controller.internal;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -33,8 +32,6 @@ import org.apache.ambari.server.ObjectNotFoundException;
import org.apache.ambari.server.ParentObjectNotFoundException;
import org.apache.ambari.server.controller.ConfigurationRequest;
import org.apache.ambari.server.controller.RequestStatusResponse;
-import org.apache.ambari.server.controller.predicate.ArrayPredicate;
-import org.apache.ambari.server.controller.predicate.EqualsPredicate;
import org.apache.ambari.server.controller.spi.*;
import org.apache.ambari.server.controller.utilities.PredicateHelper;
import org.apache.ambari.server.controller.utilities.PropertyHelper;
@@ -206,9 +203,6 @@ public abstract class AbstractResourceProvider extends BaseProvider implements R
protected RequestStatus getRequestStatus(RequestStatusResponse response, Set<Resource> associatedResources) {
if (response != null){
Resource requestResource = new ResourceImpl(Resource.Type.Request);
- if (response.getMessage() != null){
- requestResource.setProperty(PropertyHelper.getPropertyId("Requests", "message"), response.getMessage());
- }
requestResource.setProperty(PropertyHelper.getPropertyId("Requests", "id"), response.getRequestId());
requestResource.setProperty(PropertyHelper.getPropertyId("Requests", "status"), "InProgress");
return new RequestStatusImpl(requestResource, associatedResources);
@@ -226,34 +220,6 @@ public abstract class AbstractResourceProvider extends BaseProvider implements R
}
/**
- * Extracting given query_parameter value from the predicate
- * @param queryParameterId query parameter id
- * @param predicate predicate
- * @return the query parameter
- */
- protected static Object getQueryParameterValue(String queryParameterId, Predicate predicate) {
-
- Object result = null;
-
- if (predicate instanceof EqualsPredicate) {
- EqualsPredicate equalsPredicate = (EqualsPredicate) predicate;
- if (queryParameterId.equals(equalsPredicate.getPropertyId())) {
- return equalsPredicate.getValue();
- }
- } else if (predicate instanceof ArrayPredicate) {
- ArrayPredicate arrayPredicate = (ArrayPredicate) predicate;
- for (Predicate predicateItem : arrayPredicate.getPredicates()) {
- result = getQueryParameterValue(queryParameterId, predicateItem);
- if (result != null) {
- return result;
- }
- }
-
- }
- return result;
- }
-
- /**
* Invoke a command against the Ambari backend to create resources and map
* any {@link AmbariException} to the types appropriate for the
* {@link ResourceProvider} interface.
@@ -347,79 +313,47 @@ public abstract class AbstractResourceProvider extends BaseProvider implements R
* whose category is the parent and marked as a desired config.
* @param properties the properties on the request.
*/
- protected List<ConfigurationRequest> getConfigurationRequests(String parentCategory, Map<String, Object> properties) {
-
- List<ConfigurationRequest> configs = new LinkedList<ConfigurationRequest>();
-
- String desiredConfigKey = parentCategory + "/desired_config";
- // Multiple configs to be updated
- if (properties.containsKey(desiredConfigKey)
- && properties.get(desiredConfigKey) instanceof Set) {
-
- Set<Map<String, Object>> configProperties =
- (Set<Map<String, Object>>) properties.get(desiredConfigKey);
- for (Map<String, Object> value: configProperties) {
- ConfigurationRequest newConfig = new ConfigurationRequest();
-
- for (Entry<String, Object> e : value.entrySet()) {
- String propName =
- PropertyHelper.getPropertyName(desiredConfigKey + '/' + e.getKey());
- String absCatategory =
- PropertyHelper.getPropertyCategory(desiredConfigKey + '/' + e.getKey());
- parseProperties(newConfig, absCatategory, propName, e.getValue().toString());
- }
- configs.add(newConfig);
- }
- return configs;
- }
+ protected ConfigurationRequest getConfigurationRequest(String parentCategory, Map<String, Object> properties) {
ConfigurationRequest config = null;
+
// as a convenience, allow consumers to specify name/value overrides in this
// call instead of forcing a cluster call to do that work
for (Entry<String, Object> entry : properties.entrySet()) {
String absCategory = PropertyHelper.getPropertyCategory(entry.getKey());
String propName = PropertyHelper.getPropertyName(entry.getKey());
- if (absCategory.startsWith(desiredConfigKey)) {
+ if (absCategory.startsWith(parentCategory + "/desired_config")) {
config = (null == config) ? new ConfigurationRequest() : config;
- parseProperties(config, absCategory, propName, entry.getValue().toString());
+ if (propName.equals("type"))
+ config.setType(entry.getValue().toString());
+ else if (propName.equals("tag"))
+ config.setVersionTag(entry.getValue().toString());
+ else if (propName.equals("selected")) {
+ config.setSelected(Boolean.parseBoolean(entry.getValue().toString()));
+ }
+ else if (absCategory.endsWith("/properties")) {
+ config.getProperties().put(propName, entry.getValue().toString());
+ }
+ else if (propertiesAttributesPattern.matcher(absCategory).matches()) {
+ String attributeName = absCategory.substring(absCategory.lastIndexOf('/') + 1);
+ Map<String, Map<String, String>> configAttributesMap = config.getPropertiesAttributes();
+ if (null == configAttributesMap) {
+ configAttributesMap = new HashMap<String, Map<String,String>>();
+ config.setPropertiesAttributes(configAttributesMap);
+ }
+ Map<String, String> attributesMap = configAttributesMap.get(attributeName);
+ if (null == attributesMap) {
+ attributesMap = new HashMap<String, String>();
+ configAttributesMap.put(attributeName, attributesMap);
+ }
+ attributesMap.put(PropertyHelper.getPropertyName(entry.getKey()), entry.getValue().toString());
+ }
}
}
- if (config != null) {
- configs.add(config);
- }
- return configs;
- }
- private void parseProperties(ConfigurationRequest config, String absCategory, String propName, String propValue) {
- if (propName.equals("type"))
- config.setType(propValue);
- else if (propName.equals("tag"))
- config.setVersionTag(propValue);
- else if (propName.equals("selected")) {
- config.setSelected(Boolean.parseBoolean(propValue));
- }
- else if (propName.equals("service_config_version_note")) {
- config.setServiceConfigVersionNote(propValue);
- }
- else if (absCategory.endsWith("/properties")) {
- config.getProperties().put(propName, propValue);
- }
- else if (propertiesAttributesPattern.matcher(absCategory).matches()) {
- String attributeName = absCategory.substring(absCategory.lastIndexOf('/') + 1);
- Map<String, Map<String, String>> configAttributesMap = config.getPropertiesAttributes();
- if (null == configAttributesMap) {
- configAttributesMap = new HashMap<String, Map<String,String>>();
- config.setPropertiesAttributes(configAttributesMap);
- }
- Map<String, String> attributesMap = configAttributesMap.get(attributeName);
- if (null == attributesMap) {
- attributesMap = new HashMap<String, String>();
- configAttributesMap.put(attributeName, attributesMap);
- }
- attributesMap.put(propName, propValue);
- }
+ return config;
}
// get the resources (id fields only) for the given predicate.
http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertDefinitionResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertDefinitionResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertDefinitionResourceProvider.java
deleted file mode 100644
index 07b033e..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertDefinitionResourceProvider.java
+++ /dev/null
@@ -1,374 +0,0 @@
-/**
- * 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 java.util.ArrayList;
-import java.util.Arrays;
-import java.util.EnumSet;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.UUID;
-
-import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.controller.AmbariManagementController;
-import org.apache.ambari.server.controller.spi.NoSuchParentResourceException;
-import org.apache.ambari.server.controller.spi.NoSuchResourceException;
-import org.apache.ambari.server.controller.spi.Predicate;
-import org.apache.ambari.server.controller.spi.Request;
-import org.apache.ambari.server.controller.spi.RequestStatus;
-import org.apache.ambari.server.controller.spi.Resource;
-import org.apache.ambari.server.controller.spi.ResourceAlreadyExistsException;
-import org.apache.ambari.server.controller.spi.SystemException;
-import org.apache.ambari.server.controller.spi.UnsupportedPropertyException;
-import org.apache.ambari.server.controller.utilities.PropertyHelper;
-import org.apache.ambari.server.orm.dao.AlertDefinitionDAO;
-import org.apache.ambari.server.orm.entities.AlertDefinitionEntity;
-import org.apache.ambari.server.state.Cluster;
-import org.apache.ambari.server.state.alert.Scope;
-import org.apache.ambari.server.state.alert.SourceType;
-
-import com.google.gson.Gson;
-import com.google.gson.JsonObject;
-import com.google.inject.Inject;
-
-/**
- * ResourceProvider for Alert Definitions
- */
-public class AlertDefinitionResourceProvider extends AbstractControllerResourceProvider {
-
- protected static final String ALERT_DEF_CLUSTER_NAME = "AlertDefinition/cluster_name";
- protected static final String ALERT_DEF_ID = "AlertDefinition/id";
- protected static final String ALERT_DEF_NAME = "AlertDefinition/name";
- protected static final String ALERT_DEF_LABEL = "AlertDefinition/label";
- protected static final String ALERT_DEF_INTERVAL = "AlertDefinition/interval";
- protected static final String ALERT_DEF_SOURCE_TYPE = "AlertDefinition/source/type";
- protected static final String ALERT_DEF_SOURCE = "AlertDefinition/source";
- protected static final String ALERT_DEF_SERVICE_NAME = "AlertDefinition/service_name";
- protected static final String ALERT_DEF_COMPONENT_NAME = "AlertDefinition/component_name";
- protected static final String ALERT_DEF_ENABLED = "AlertDefinition/enabled";
- protected static final String ALERT_DEF_SCOPE = "AlertDefinition/scope";
-
- private static Set<String> pkPropertyIds = new HashSet<String>(
- Arrays.asList(ALERT_DEF_ID, ALERT_DEF_NAME));
- private static AlertDefinitionDAO alertDefinitionDAO = null;
-
- private static Gson gson = new Gson();
-
- /**
- * @param instance
- */
- @Inject
- public static void init(AlertDefinitionDAO instance) {
- alertDefinitionDAO = instance;
- }
-
- AlertDefinitionResourceProvider(Set<String> propertyIds,
- Map<Resource.Type, String> keyPropertyIds,
- AmbariManagementController managementController) {
- super(propertyIds, keyPropertyIds, managementController);
- }
-
- @Override
- protected Set<String> getPKPropertyIds() {
- return pkPropertyIds;
- }
-
- @Override
- public RequestStatus createResources(final Request request) throws SystemException,
- UnsupportedPropertyException, ResourceAlreadyExistsException,
- NoSuchParentResourceException {
-
- createResources(new Command<Void>() {
- @Override
- public Void invoke() throws AmbariException {
- createAlertDefinitions(request.getProperties());
- return null;
- }
- });
- notifyCreate(Resource.Type.AlertDefinition, request);
-
- return getRequestStatus(null);
- }
-
- private void createAlertDefinitions(Set<Map<String, Object>> requestMaps)
- throws AmbariException {
- List<AlertDefinitionEntity> entities = new ArrayList<AlertDefinitionEntity>();
-
- for (Map<String, Object> requestMap : requestMaps) {
- entities.add(toCreateEntity(requestMap));
- }
-
- // !!! TODO multi-create in a transaction
- for (AlertDefinitionEntity entity : entities) {
- alertDefinitionDAO.create(entity);
- }
- }
-
- private AlertDefinitionEntity toCreateEntity(Map<String, Object> requestMap)
- throws AmbariException {
-
- String clusterName = (String) requestMap.get(ALERT_DEF_CLUSTER_NAME);
-
- if (null == clusterName || clusterName.isEmpty()) {
- throw new IllegalArgumentException("Invalid argument, cluster name is required");
- }
-
- if (!requestMap.containsKey(ALERT_DEF_INTERVAL)) {
- throw new IllegalArgumentException("Check interval must be specified");
- }
-
- Integer interval = Integer.valueOf((String) requestMap.get(ALERT_DEF_INTERVAL));
-
- if (!requestMap.containsKey(ALERT_DEF_NAME)) {
- throw new IllegalArgumentException("Definition name must be specified");
- }
-
- if (!requestMap.containsKey(ALERT_DEF_SERVICE_NAME)) {
- throw new IllegalArgumentException("Service name must be specified");
- }
-
- if (!requestMap.containsKey(ALERT_DEF_SOURCE_TYPE)) {
- throw new IllegalArgumentException(String.format(
- "Source type must be specified and one of %s", EnumSet.allOf(
- SourceType.class)));
- }
-
- JsonObject jsonObj = new JsonObject();
-
- for (Entry<String, Object> entry : requestMap.entrySet()) {
- String propCat = PropertyHelper.getPropertyCategory(entry.getKey());
- String propName = PropertyHelper.getPropertyName(entry.getKey());
-
- if (propCat.equals(ALERT_DEF_SOURCE)) {
- jsonObj.addProperty(propName, entry.getValue().toString());
- }
- }
-
- if (0 == jsonObj.entrySet().size()) {
- throw new IllegalArgumentException("Source must be specified");
- }
-
- Cluster cluster = getManagementController().getClusters().getCluster(clusterName);
-
- AlertDefinitionEntity entity = new AlertDefinitionEntity();
- entity.setClusterId(Long.valueOf(cluster.getClusterId()));
- entity.setComponentName((String) requestMap.get(ALERT_DEF_COMPONENT_NAME));
- entity.setDefinitionName((String) requestMap.get(ALERT_DEF_NAME));
- entity.setLabel((String) requestMap.get(ALERT_DEF_LABEL));
-
- boolean enabled = requestMap.containsKey(ALERT_DEF_ENABLED) ?
- Boolean.parseBoolean((String)requestMap.get(ALERT_DEF_ENABLED)) : true;
-
- entity.setEnabled(enabled);
- entity.setHash(UUID.randomUUID().toString());
- entity.setScheduleInterval(interval);
- entity.setServiceName((String) requestMap.get(ALERT_DEF_SERVICE_NAME));
- entity.setSourceType((String) requestMap.get(ALERT_DEF_SOURCE_TYPE));
- entity.setSource(jsonObj.toString());
-
- Scope scope = null;
- String desiredScope = (String) requestMap.get(ALERT_DEF_SCOPE);
- if (null != desiredScope && desiredScope.length() > 0) {
- scope = Scope.valueOf(desiredScope);
- }
-
- entity.setScope(scope);
-
- return entity;
- }
-
- @Override
- public Set<Resource> getResources(Request request, Predicate predicate)
- throws SystemException, UnsupportedPropertyException,
- NoSuchResourceException, NoSuchParentResourceException {
-
- Set<String> requestPropertyIds = getRequestPropertyIds(request, predicate);
-
- Set<Resource> results = new HashSet<Resource>();
-
- for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) {
- String clusterName = (String) propertyMap.get(ALERT_DEF_CLUSTER_NAME);
-
- if (null == clusterName || clusterName.isEmpty()) {
- throw new IllegalArgumentException("Invalid argument, cluster name is required");
- }
-
- String id = (String) propertyMap.get(ALERT_DEF_ID);
- if (null != id) {
- AlertDefinitionEntity entity = alertDefinitionDAO.findById(Long.parseLong(id));
- if (null != entity) {
- results.add(toResource(false, clusterName, entity, requestPropertyIds));
- }
- } else {
-
- Cluster cluster = null;
- try {
- cluster = getManagementController().getClusters().getCluster(clusterName);
- } catch (AmbariException e) {
- throw new NoSuchResourceException("Parent Cluster resource doesn't exist", e);
- }
-
- List<AlertDefinitionEntity> entities = alertDefinitionDAO.findAll(
- cluster.getClusterId());
-
- for (AlertDefinitionEntity entity : entities) {
- results.add(toResource(true, clusterName, entity, requestPropertyIds));
- }
- }
- }
-
- return results;
- }
-
- @Override
- public RequestStatus updateResources(Request request, Predicate predicate)
- throws SystemException, UnsupportedPropertyException,
- NoSuchResourceException, NoSuchParentResourceException {
-
- for (Map<String, Object> requestPropMap : request.getProperties()) {
- for (Map<String, Object> propertyMap : getPropertyMaps(requestPropMap, predicate)) {
- Long id = (Long) propertyMap.get(ALERT_DEF_ID);
-
- AlertDefinitionEntity entity = alertDefinitionDAO.findById(id.longValue());
- if (null == entity) {
- continue;
- }
-
- if (propertyMap.containsKey(ALERT_DEF_NAME)) {
- entity.setDefinitionName((String) propertyMap.get(ALERT_DEF_NAME));
- }
-
- if (propertyMap.containsKey(ALERT_DEF_ENABLED)) {
- entity.setEnabled(Boolean.parseBoolean(
- (String) propertyMap.get(ALERT_DEF_ENABLED)));
- }
-
- if (propertyMap.containsKey(ALERT_DEF_INTERVAL)) {
- entity.setScheduleInterval(Integer.valueOf(
- (String) propertyMap.get(ALERT_DEF_INTERVAL)));
- }
-
- if (propertyMap.containsKey(ALERT_DEF_SCOPE)){
- Scope scope = null;
- String desiredScope = (String) propertyMap.get(ALERT_DEF_SCOPE);
-
- if (null != desiredScope && desiredScope.length() > 0) {
- scope = Scope.valueOf((desiredScope));
- }
-
- entity.setScope(scope);
- }
-
-
- if (propertyMap.containsKey(ALERT_DEF_SOURCE_TYPE)) {
- entity.setSourceType((String) propertyMap.get(ALERT_DEF_SOURCE_TYPE));
- }
-
- JsonObject jsonObj = new JsonObject();
-
- for (Entry<String, Object> entry : propertyMap.entrySet()) {
- String propCat = PropertyHelper.getPropertyCategory(entry.getKey());
- String propName = PropertyHelper.getPropertyName(entry.getKey());
-
- if (propCat.equals(ALERT_DEF_SOURCE)) {
- jsonObj.addProperty(propName, entry.getValue().toString());
- }
- }
-
- entity.setHash(UUID.randomUUID().toString());
-
- alertDefinitionDAO.merge(entity);
- }
- }
-
- notifyUpdate(Resource.Type.AlertDefinition, request, predicate);
-
- return getRequestStatus(null);
- }
-
- @Override
- public RequestStatus deleteResources(Predicate predicate)
- throws SystemException, UnsupportedPropertyException,
- NoSuchResourceException, NoSuchParentResourceException {
-
- Set<Resource> resources = getResources(
- new RequestImpl(null, null, null, null), predicate);
-
- Set<Long> definitionIds = new HashSet<Long>();
-
- for (final Resource resource : resources) {
- definitionIds.add((Long) resource.getPropertyValue(ALERT_DEF_ID));
- }
-
- for (Long definitionId : definitionIds) {
-
- LOG.info("Deleting alert definition {}", definitionId);
-
- final AlertDefinitionEntity ad = alertDefinitionDAO.findById(definitionId.longValue());
-
- modifyResources(new Command<Void>() {
- @Override
- public Void invoke() throws AmbariException {
- alertDefinitionDAO.remove(ad);
- return null;
- }
- });
- }
-
- notifyDelete(Resource.Type.AlertDefinition, predicate);
- return getRequestStatus(null);
-
- }
-
- private Resource toResource(boolean isCollection, String clusterName,
- AlertDefinitionEntity entity, Set<String> requestedIds) {
- Resource resource = new ResourceImpl(Resource.Type.AlertDefinition);
-
- setResourceProperty(resource, ALERT_DEF_CLUSTER_NAME, clusterName, requestedIds);
- setResourceProperty(resource, ALERT_DEF_ID, entity.getDefinitionId(), requestedIds);
- setResourceProperty(resource, ALERT_DEF_NAME, entity.getDefinitionName(), requestedIds);
- setResourceProperty(resource, ALERT_DEF_INTERVAL, entity.getScheduleInterval(), requestedIds);
- setResourceProperty(resource, ALERT_DEF_SERVICE_NAME, entity.getServiceName(), requestedIds);
- setResourceProperty(resource, ALERT_DEF_COMPONENT_NAME, entity.getComponentName(), requestedIds);
- setResourceProperty(resource, ALERT_DEF_ENABLED, Boolean.valueOf(entity.getEnabled()), requestedIds);
- setResourceProperty(resource, ALERT_DEF_SCOPE, entity.getScope(), requestedIds);
- setResourceProperty(resource, ALERT_DEF_SOURCE_TYPE, entity.getSourceType(), requestedIds);
- setResourceProperty(resource, ALERT_DEF_LABEL, entity.getLabel(),
- requestedIds);
-
- if (!isCollection && null != resource.getPropertyValue(ALERT_DEF_SOURCE_TYPE)) {
-
- try {
- Map<String, String> map = gson.<Map<String, String>>fromJson(entity.getSource(), Map.class);
-
- for (Entry<String, String> entry : map.entrySet()) {
- String subProp = PropertyHelper.getPropertyId(ALERT_DEF_SOURCE, entry.getKey());
- resource.setProperty(subProp, entry.getValue());
- }
- } catch (Exception e) {
- LOG.error("Could not coerce alert JSON into a type");
- }
- }
-
- return resource;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AmbariPrivilegeResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AmbariPrivilegeResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AmbariPrivilegeResourceProvider.java
deleted file mode 100644
index f4839e9..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AmbariPrivilegeResourceProvider.java
+++ /dev/null
@@ -1,174 +0,0 @@
-/**
- * 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 privileges and
- * limitations under the License.
- */
-package org.apache.ambari.server.controller.internal;
-
-import org.apache.ambari.server.controller.spi.Predicate;
-import org.apache.ambari.server.controller.spi.Resource;
-import org.apache.ambari.server.orm.dao.ClusterDAO;
-import org.apache.ambari.server.orm.entities.ClusterEntity;
-import org.apache.ambari.server.orm.entities.GroupEntity;
-import org.apache.ambari.server.orm.entities.PrivilegeEntity;
-import org.apache.ambari.server.orm.entities.ResourceEntity;
-import org.apache.ambari.server.orm.entities.ResourceTypeEntity;
-import org.apache.ambari.server.orm.entities.UserEntity;
-import org.apache.ambari.server.orm.entities.ViewEntity;
-import org.apache.ambari.server.orm.entities.ViewInstanceEntity;
-import org.apache.ambari.server.view.ViewRegistry;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import static org.apache.ambari.server.controller.internal.ClusterPrivilegeResourceProvider.PRIVILEGE_CLUSTER_NAME_PROPERTY_ID;
-import static org.apache.ambari.server.controller.internal.ViewPrivilegeResourceProvider.PRIVILEGE_INSTANCE_NAME_PROPERTY_ID;
-import static org.apache.ambari.server.controller.internal.ViewPrivilegeResourceProvider.PRIVILEGE_VIEW_NAME_PROPERTY_ID;
-import static org.apache.ambari.server.controller.internal.ViewPrivilegeResourceProvider.PRIVILEGE_VIEW_VERSION_PROPERTY_ID;
-
-/**
- * Resource provider for Ambari privileges.
- */
-public class AmbariPrivilegeResourceProvider extends PrivilegeResourceProvider<Object> {
-
- public static final String PRIVILEGE_TYPE_PROPERTY_ID = "PrivilegeInfo/type";
-
- /**
- * Data access object used to obtain privilege entities.
- */
- protected static ClusterDAO clusterDAO;
-
- /**
- * The property ids for an Ambari privilege resource.
- */
- private static Set<String> propertyIds = new HashSet<String>();
- static {
- propertyIds.add(PRIVILEGE_ID_PROPERTY_ID);
- propertyIds.add(PERMISSION_NAME_PROPERTY_ID);
- propertyIds.add(PRINCIPAL_NAME_PROPERTY_ID);
- propertyIds.add(PRINCIPAL_TYPE_PROPERTY_ID);
- propertyIds.add(PRIVILEGE_VIEW_NAME_PROPERTY_ID);
- propertyIds.add(PRIVILEGE_VIEW_VERSION_PROPERTY_ID);
- propertyIds.add(PRIVILEGE_INSTANCE_NAME_PROPERTY_ID);
- propertyIds.add(PRIVILEGE_CLUSTER_NAME_PROPERTY_ID);
- propertyIds.add(PRIVILEGE_TYPE_PROPERTY_ID);
-
- }
-
- /**
- * The key property ids for a privilege resource.
- */
- private static Map<Resource.Type, String> keyPropertyIds = new HashMap<Resource.Type, String>();
- static {
- keyPropertyIds.put(Resource.Type.AmbariPrivilege, PRIVILEGE_ID_PROPERTY_ID);
- }
-
-
- // ----- Constructors ------------------------------------------------------
-
- /**
- * Construct an AmbariPrivilegeResourceProvider.
- */
- public AmbariPrivilegeResourceProvider() {
- super(propertyIds, keyPropertyIds, Resource.Type.AmbariPrivilege);
- }
-
- // ----- AmbariPrivilegeResourceProvider ---------------------------------
-
- /**
- * Static initialization.
- *
- * @param clusterDao the cluster data access object
- */
- public static void init(ClusterDAO clusterDao) {
- clusterDAO = clusterDao;
- }
-
- // ----- AbstractResourceProvider ------------------------------------------
-
- @Override
- public Map<Resource.Type, String> getKeyPropertyIds() {
- return keyPropertyIds;
- }
-
-
- // ----- PrivilegeResourceProvider -----------------------------------------
-
- @Override
- public Map<Long, Object> getResourceEntities(Map<String, Object> properties) {
- Map<Long, Object> resourceEntities = new HashMap<Long, Object>();
-
- resourceEntities.put(ResourceEntity.AMBARI_RESOURCE_ID, null);
- // add cluster entities
- List<ClusterEntity> clusterEntities = clusterDAO.findAll();
-
- if (clusterEntities != null) {
- for (ClusterEntity clusterEntity : clusterEntities) {
- resourceEntities.put(clusterEntity.getResource().getId(), clusterEntity);
- }
- }
- //add view entities
- ViewRegistry viewRegistry = ViewRegistry.getInstance();
- for (ViewEntity viewEntity : viewRegistry.getDefinitions()) {
- if (viewEntity.isDeployed()) {
- for (ViewInstanceEntity viewInstanceEntity : viewEntity.getInstances()) {
- resourceEntities.put(viewInstanceEntity.getResource().getId(), viewInstanceEntity);
- }
- }
- }
- return resourceEntities;
- }
-
- @Override
- protected Resource toResource(PrivilegeEntity privilegeEntity,
- Map<Long, UserEntity> userEntities,
- Map<Long, GroupEntity> groupEntities,
- Map<Long, Object> resourceEntities, Set<String> requestedIds) {
- Resource resource = super.toResource(privilegeEntity, userEntities, groupEntities, resourceEntities, requestedIds);
- if (resource != null) {
- ResourceEntity resourceEntity = privilegeEntity.getResource();
- ResourceTypeEntity type = resourceEntity.getResourceType();
- String privilegeType;
- switch (type.getId()) {
- case ResourceTypeEntity.CLUSTER_RESOURCE_TYPE:
- ClusterEntity clusterEntity = (ClusterEntity) resourceEntities.get(resourceEntity.getId());
- privilegeType = ResourceTypeEntity.CLUSTER_RESOURCE_TYPE_NAME;
- setResourceProperty(resource, PRIVILEGE_CLUSTER_NAME_PROPERTY_ID, clusterEntity.getClusterName(), requestedIds);
- break;
- case ResourceTypeEntity.AMBARI_RESOURCE_TYPE:
- privilegeType = ResourceTypeEntity.AMBARI_RESOURCE_TYPE_NAME;
- break;
- default:
- privilegeType = ResourceTypeEntity.VIEW_RESOURCE_TYPE_NAME;
- ViewInstanceEntity viewInstanceEntity = (ViewInstanceEntity) resourceEntities.get(resourceEntity.getId());
- ViewEntity viewEntity = viewInstanceEntity.getViewEntity();
-
- setResourceProperty(resource, PRIVILEGE_VIEW_NAME_PROPERTY_ID, viewEntity.getCommonName(), requestedIds);
- setResourceProperty(resource, PRIVILEGE_VIEW_VERSION_PROPERTY_ID, viewEntity.getVersion(), requestedIds);
- setResourceProperty(resource, PRIVILEGE_INSTANCE_NAME_PROPERTY_ID, viewInstanceEntity.getName(), requestedIds);
- break;
- }
- setResourceProperty(resource, PRIVILEGE_TYPE_PROPERTY_ID, privilegeType, requestedIds);
- }
- return resource;
- }
- @Override
- public Long getResourceEntityId(Predicate predicate) {
- return ResourceEntity.AMBARI_RESOURCE_ID;
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BaseBlueprintProcessor.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BaseBlueprintProcessor.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BaseBlueprintProcessor.java
index abd22a4..800ff3b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BaseBlueprintProcessor.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BaseBlueprintProcessor.java
@@ -19,14 +19,12 @@
package org.apache.ambari.server.controller.internal;
import com.google.gson.Gson;
-
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.StackAccessException;
import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.controller.AmbariManagementController;
import org.apache.ambari.server.controller.StackConfigurationRequest;
import org.apache.ambari.server.controller.StackConfigurationResponse;
-import org.apache.ambari.server.controller.StackLevelConfigurationRequest;
import org.apache.ambari.server.controller.StackServiceComponentRequest;
import org.apache.ambari.server.controller.StackServiceComponentResponse;
import org.apache.ambari.server.controller.StackServiceRequest;
@@ -40,9 +38,7 @@ import org.apache.ambari.server.orm.entities.HostGroupComponentEntity;
import org.apache.ambari.server.orm.entities.HostGroupConfigEntity;
import org.apache.ambari.server.orm.entities.HostGroupEntity;
import org.apache.ambari.server.state.AutoDeployInfo;
-import org.apache.ambari.server.state.ConfigHelper;
import org.apache.ambari.server.state.DependencyInfo;
-import org.apache.ambari.server.state.PropertyInfo;
import java.util.Collection;
import java.util.Collections;
@@ -67,8 +63,6 @@ public abstract class BaseBlueprintProcessor extends AbstractControllerResourceP
* Stack related information.
*/
protected static AmbariMetaInfo stackInfo;
-
- protected static ConfigHelper configHelper;
protected BaseBlueprintProcessor(Set<String> propertyIds,
@@ -86,9 +80,9 @@ public abstract class BaseBlueprintProcessor extends AbstractControllerResourceP
*
* @return collection of host groups which contain the specified component
*/
- protected Collection<HostGroupImpl> getHostGroupsForComponent(String component, Collection<HostGroupImpl> hostGroups) {
- Collection<HostGroupImpl> resultGroups = new HashSet<HostGroupImpl>();
- for (HostGroupImpl group : hostGroups ) {
+ protected Collection<HostGroup> getHostGroupsForComponent(String component, Collection<HostGroup> hostGroups) {
+ Collection<HostGroup> resultGroups = new HashSet<HostGroup>();
+ for (HostGroup group : hostGroups ) {
if (group.getComponents().contains(component)) {
resultGroups.add(group);
}
@@ -104,11 +98,11 @@ public abstract class BaseBlueprintProcessor extends AbstractControllerResourceP
*
* @return map of host group name to host group
*/
- protected Map<String, HostGroupImpl> parseBlueprintHostGroups(BlueprintEntity blueprint, Stack stack) {
- Map<String, HostGroupImpl> mapHostGroups = new HashMap<String, HostGroupImpl>();
+ protected Map<String, HostGroup> parseBlueprintHostGroups(BlueprintEntity blueprint, Stack stack) {
+ Map<String, HostGroup> mapHostGroups = new HashMap<String, HostGroup>();
for (HostGroupEntity hostGroup : blueprint.getHostGroups()) {
- mapHostGroups.put(hostGroup.getName(), new HostGroupImpl(hostGroup, stack, this));
+ mapHostGroups.put(hostGroup.getName(), new HostGroup(hostGroup, stack));
}
return mapHostGroups;
}
@@ -125,7 +119,7 @@ public abstract class BaseBlueprintProcessor extends AbstractControllerResourceP
protected Stack parseStack(BlueprintEntity blueprint) throws SystemException {
Stack stack;
try {
- stack = new Stack(blueprint.getStackName(), blueprint.getStackVersion(), getManagementController());
+ stack = new Stack(blueprint.getStackName(), blueprint.getStackVersion());
} catch (StackAccessException e) {
throw new IllegalArgumentException("Invalid stack information provided for cluster. " +
"stack name: " + blueprint.getStackName() +
@@ -150,15 +144,15 @@ public abstract class BaseBlueprintProcessor extends AbstractControllerResourceP
* @throws IllegalArgumentException when validation fails
*/
protected BlueprintEntity validateTopology(BlueprintEntity blueprint) throws AmbariException {
- Stack stack = new Stack(blueprint.getStackName(), blueprint.getStackVersion(), getManagementController());
- Map<String, HostGroupImpl> hostGroupMap = parseBlueprintHostGroups(blueprint, stack);
- Collection<HostGroupImpl> hostGroups = hostGroupMap.values();
+ Stack stack = new Stack(blueprint.getStackName(), blueprint.getStackVersion());
+ Map<String, HostGroup> hostGroupMap = parseBlueprintHostGroups(blueprint, stack);
+ Collection<HostGroup> hostGroups = hostGroupMap.values();
Map<String, Map<String, String>> clusterConfig = processBlueprintConfigurations(blueprint, null);
Map<String, Map<String, Collection<DependencyInfo>>> missingDependencies =
new HashMap<String, Map<String, Collection<DependencyInfo>>>();
Collection<String> services = getTopologyServices(hostGroups);
- for (HostGroupImpl group : hostGroups) {
+ for (HostGroup group : hostGroups) {
Map<String, Collection<DependencyInfo>> missingGroupDependencies =
group.validateTopology(hostGroups, services, clusterConfig);
if (! missingGroupDependencies.isEmpty()) {
@@ -212,33 +206,6 @@ public abstract class BaseBlueprintProcessor extends AbstractControllerResourceP
}
/**
- * Process cluster scoped configuration attributes contained in blueprint.
- *
- * @param blueprint blueprint entity
- *
- * @return cluster scoped property attributes contained within in blueprint
- */
- protected Map<String, Map<String, Map<String, String>>> processBlueprintAttributes(BlueprintEntity blueprint) {
-
- Map<String, Map<String, Map<String, String>>> mapAttributes =
- new HashMap<String, Map<String, Map<String, String>>>();
- Collection<BlueprintConfigEntity> configs = blueprint.getConfigurations();
-
- if (configs != null) {
- Gson gson = new Gson();
- for (BlueprintConfigEntity config : configs) {
- Map<String, Map<String, String>> typeAttrs =
- gson.<Map<String, Map<String, String>>>fromJson(config.getConfigAttributes(), Map.class);
- if (typeAttrs != null && !typeAttrs.isEmpty()) {
- mapAttributes.put(config.getType(), typeAttrs);
- }
- }
- }
-
- return mapAttributes;
- }
-
- /**
* Override existing properties or add new.
*
* @param existingProperties current property values
@@ -313,9 +280,9 @@ public abstract class BaseBlueprintProcessor extends AbstractControllerResourceP
*
* @return collections of all services provided by topology
*/
- protected Collection<String> getTopologyServices(Collection<HostGroupImpl> hostGroups) {
+ protected Collection<String> getTopologyServices(Collection<HostGroup> hostGroups) {
Collection<String> services = new HashSet<String>();
- for (HostGroupImpl group : hostGroups) {
+ for (HostGroup group : hostGroups) {
services.addAll(group.getServices());
}
return services;
@@ -361,7 +328,7 @@ public abstract class BaseBlueprintProcessor extends AbstractControllerResourceP
* @return collection of missing component information
*/
private Collection<String> verifyComponentCardinalityCount(BlueprintEntity blueprint,
- Collection<HostGroupImpl> hostGroups,
+ Collection<HostGroup> hostGroups,
String component,
Cardinality cardinality,
AutoDeployInfo autoDeploy,
@@ -376,11 +343,11 @@ public abstract class BaseBlueprintProcessor extends AbstractControllerResourceP
if (! validated && autoDeploy != null && autoDeploy.isEnabled() && cardinality.supportsAutoDeploy()) {
String coLocateName = autoDeploy.getCoLocate();
if (coLocateName != null && ! coLocateName.isEmpty()) {
- Collection<HostGroupImpl> coLocateHostGroups = getHostGroupsForComponent(
+ Collection<HostGroup> coLocateHostGroups = getHostGroupsForComponent(
coLocateName.split("/")[1], hostGroups);
if (! coLocateHostGroups.isEmpty()) {
validated = true;
- HostGroupImpl group = coLocateHostGroups.iterator().next();
+ HostGroup group = coLocateHostGroups.iterator().next();
if (group.addComponent(component)) {
addComponentToBlueprint(blueprint, group.getEntity().getName(), component);
}
@@ -407,7 +374,7 @@ public abstract class BaseBlueprintProcessor extends AbstractControllerResourceP
* @return collection of missing component information
*/
private Collection<String> verifyComponentInAllHostGroups(BlueprintEntity blueprint,
- Collection<HostGroupImpl> hostGroups,
+ Collection<HostGroup> hostGroups,
String component,
AutoDeployInfo autoDeploy) {
@@ -415,7 +382,7 @@ public abstract class BaseBlueprintProcessor extends AbstractControllerResourceP
int actualCount = getHostGroupsForComponent(component, hostGroups).size();
if (actualCount != hostGroups.size()) {
if (autoDeploy != null && autoDeploy.isEnabled()) {
- for (HostGroupImpl group : hostGroups) {
+ for (HostGroup group : hostGroups) {
if (group.addComponent(component)) {
addComponentToBlueprint(blueprint, group.getEntity().getName(), component);
}
@@ -457,7 +424,7 @@ public abstract class BaseBlueprintProcessor extends AbstractControllerResourceP
/**
* Encapsulates stack information.
*/
- protected static class Stack {
+ protected class Stack {
/**
* Stack name
*/
@@ -513,44 +480,8 @@ public abstract class BaseBlueprintProcessor extends AbstractControllerResourceP
/**
* Map of service to config type properties
*/
- private Map<String, Map<String, Map<String, ConfigProperty>>> serviceConfigurations =
- new HashMap<String, Map<String, Map<String, ConfigProperty>>>();
-
-
- /**
- * Ambari Management Controller, used to obtain Stack definitions
- */
- private final AmbariManagementController ambariManagementController;
-
- /**
- * Contains a configuration property's value and attributes.
- */
- private class ConfigProperty {
-
- private ConfigProperty(String value, Map<String, String> attributes) {
- this.value = value;
- this.attributes = attributes;
- }
-
- private String value;
- private Map<String, String> attributes;
-
- public String getValue() {
- return value;
- }
-
- public void setValue(String value) {
- this.value = value;
- }
-
- public Map<String, String> getAttributes() {
- return attributes;
- }
-
- public void setAttributes(Map<String, String> attributes) {
- this.attributes = attributes;
- }
- }
+ private Map<String, Map<String, Map<String, String>>> serviceConfigurations =
+ new HashMap<String, Map<String, Map<String, String>>>();
/**
* Constructor.
@@ -561,12 +492,11 @@ public abstract class BaseBlueprintProcessor extends AbstractControllerResourceP
* @throws AmbariException an exception occurred getting stack information
* for the specified name and version
*/
- public Stack(String name, String version, AmbariManagementController ambariManagementController) throws AmbariException {
+ public Stack(String name, String version) throws AmbariException {
this.name = name;
this.version = version;
- this.ambariManagementController = ambariManagementController;
- Set<StackServiceResponse> stackServices = ambariManagementController.getStackServices(
+ Set<StackServiceResponse> stackServices = getManagementController().getStackServices(
Collections.singleton(new StackServiceRequest(name, version, null)));
for (StackServiceResponse stackService : stackServices) {
@@ -595,11 +525,6 @@ public abstract class BaseBlueprintProcessor extends AbstractControllerResourceP
return version;
}
-
- Map<DependencyInfo, String> getDependencyConditionalServiceMap() {
- return dependencyConditionalServiceMap;
- }
-
/**
* Get services contained in the stack.
*
@@ -640,47 +565,7 @@ public abstract class BaseBlueprintProcessor extends AbstractControllerResourceP
* @return map of property names to values for the specified service and configuration type
*/
public Map<String, String> getConfigurationProperties(String service, String type) {
- Map<String, String> configMap = new HashMap<String, String>();
- Map<String, ConfigProperty> configProperties = serviceConfigurations.get(service).get(type);
- if (configProperties != null) {
- for (Map.Entry<String, ConfigProperty> configProperty : configProperties.entrySet()) {
- configMap.put(configProperty.getKey(), configProperty.getValue().getValue());
- }
- }
- return configMap;
- }
-
- /**
- * Get config attributes for the specified service and configuration type.
- *
- * @param service service name
- * @param type configuration type
- *
- * @return map of attribute names to map of property names to attribute values
- * for the specified service and configuration type
- */
- public Map<String, Map<String, String>> getConfigurationAttributes(String service, String type) {
- Map<String, Map<String, String>> attributesMap = new HashMap<String, Map<String, String>>();
- Map<String, ConfigProperty> configProperties = serviceConfigurations.get(service).get(type);
- if (configProperties != null) {
- for (Map.Entry<String, ConfigProperty> configProperty : configProperties.entrySet()) {
- String propertyName = configProperty.getKey();
- Map<String, String> propertyAttributes = configProperty.getValue().getAttributes();
- if (propertyAttributes != null) {
- for (Map.Entry<String, String> propertyAttribute : propertyAttributes.entrySet()) {
- String attributeName = propertyAttribute.getKey();
- String attributeValue = propertyAttribute.getValue();
- Map<String, String> attributes = attributesMap.get(attributeName);
- if (attributes == null) {
- attributes = new HashMap<String, String>();
- attributesMap.put(attributeName, attributes);
- }
- attributes.put(propertyName, attributeValue);
- }
- }
- }
- }
- return attributesMap;
+ return serviceConfigurations.get(service).get(type);
}
/**
@@ -718,8 +603,8 @@ public abstract class BaseBlueprintProcessor extends AbstractControllerResourceP
* @return name of service which corresponds to the specified configuration type
*/
public String getServiceForConfigType(String config) {
- for (Map.Entry<String, Map<String, Map<String, ConfigProperty>>> entry : serviceConfigurations.entrySet()) {
- Map<String, Map<String, ConfigProperty>> typeMap = entry.getValue();
+ for (Map.Entry<String, Map<String, Map<String, String>>> entry : serviceConfigurations.entrySet()) {
+ Map<String, Map<String, String>> typeMap = entry.getValue();
if (typeMap.containsKey(config)) {
return entry.getKey();
}
@@ -781,7 +666,7 @@ public abstract class BaseBlueprintProcessor extends AbstractControllerResourceP
private void parseComponents(String service) throws AmbariException{
Collection<String> componentSet = new HashSet<String>();
- Set<StackServiceComponentResponse> components = ambariManagementController.getStackComponents(
+ Set<StackServiceComponentResponse> components = getManagementController().getStackComponents(
Collections.singleton(new StackServiceComponentRequest(name, version, service, null)));
// stack service components
@@ -817,29 +702,25 @@ public abstract class BaseBlueprintProcessor extends AbstractControllerResourceP
* @throws AmbariException an exception occurred getting configurations from the stack definition
*/
private void parseConfigurations(String service) throws AmbariException {
- Map<String, Map<String, ConfigProperty>> mapServiceConfig = new HashMap<String, Map<String, ConfigProperty>>();
+ Map<String, Map<String, String>> mapServiceConfig = new HashMap<String, Map<String, String>>();
serviceConfigurations.put(service, mapServiceConfig);
- Set<StackConfigurationResponse> serviceConfigs = ambariManagementController.getStackConfigurations(
+ Set<StackConfigurationResponse> serviceConfigs = getManagementController().getStackConfigurations(
Collections.singleton(new StackConfigurationRequest(name, version, service, null)));
- Set<StackConfigurationResponse> stackLevelConfigs = ambariManagementController.getStackLevelConfigurations(
- Collections.singleton(new StackLevelConfigurationRequest(name, version, null)));
- serviceConfigs.addAll(stackLevelConfigs);
-
+
for (StackConfigurationResponse config : serviceConfigs) {
String type = config.getType();
//strip .xml from type
if (type.endsWith(".xml")) {
type = type.substring(0, type.length() - 4);
}
- Map<String, ConfigProperty> mapTypeConfig = mapServiceConfig.get(type);
+ Map<String, String> mapTypeConfig = mapServiceConfig.get(type);
if (mapTypeConfig == null) {
- mapTypeConfig = new HashMap<String, ConfigProperty>();
+ mapTypeConfig = new HashMap<String, String>();
mapServiceConfig.put(type, mapTypeConfig);
}
- mapTypeConfig.put(config.getPropertyName(),
- new ConfigProperty(config.getPropertyValue(), config.getPropertyAttributes()));
+ mapTypeConfig.put(config.getPropertyName(), config.getPropertyValue());
}
}
@@ -847,19 +728,13 @@ public abstract class BaseBlueprintProcessor extends AbstractControllerResourceP
* Register conditional dependencies.
*/
//todo: This information should be specified in the stack definition.
- void registerConditionalDependencies() {
+ private void registerConditionalDependencies() {
Collection<DependencyInfo> nagiosDependencies = getDependenciesForComponent("NAGIOS_SERVER");
for (DependencyInfo dependency : nagiosDependencies) {
if (dependency.getComponentName().equals("HCAT")) {
- dependencyConditionalServiceMap.put(dependency, "HIVE");
+ dependencyConditionalServiceMap.put(dependency, "HCATALOG");
} else if (dependency.getComponentName().equals("OOZIE_CLIENT")) {
dependencyConditionalServiceMap.put(dependency, "OOZIE");
- } else if (dependency.getComponentName().equals("YARN_CLIENT")) {
- dependencyConditionalServiceMap.put(dependency, "YARN");
- } else if (dependency.getComponentName().equals("TEZ_CLIENT")) {
- dependencyConditionalServiceMap.put(dependency, "TEZ");
- } else if (dependency.getComponentName().equals("MAPREDUCE2_CLIENT")) {
- dependencyConditionalServiceMap.put(dependency, "MAPREDUCE2");
}
}
dbDependencyInfo.put("MYSQL_SERVER", "global/hive_database");
@@ -869,7 +744,7 @@ public abstract class BaseBlueprintProcessor extends AbstractControllerResourceP
/**
* Host group representation.
*/
- protected static class HostGroupImpl implements HostGroup {
+ protected class HostGroup {
/**
* Host group entity
*/
@@ -903,39 +778,18 @@ public abstract class BaseBlueprintProcessor extends AbstractControllerResourceP
private Stack stack;
/**
- * The Blueprint processor associated with this HostGroupImpl instance
- */
- private final BaseBlueprintProcessor blueprintProcessor;
-
- /**
* Constructor.
*
* @param hostGroup host group
* @param stack stack
*/
- public HostGroupImpl(HostGroupEntity hostGroup, Stack stack, BaseBlueprintProcessor blueprintProcessor) {
+ public HostGroup(HostGroupEntity hostGroup, Stack stack) {
this.hostGroup = hostGroup;
this.stack = stack;
- this.blueprintProcessor = blueprintProcessor;
parseComponents();
parseConfigurations();
}
- @Override
- public String getName() {
- return hostGroup.getName();
- }
-
- @Override
- public Collection<String> getComponents() {
- return this.components;
- }
-
- @Override
- public Collection<String> getHostInfo() {
- return this.hosts;
- }
-
/**
* Associate a host with the host group.
*
@@ -946,6 +800,15 @@ public abstract class BaseBlueprintProcessor extends AbstractControllerResourceP
}
/**
+ * Get associated host information.
+ *
+ * @return collection of hosts associated with the host group
+ */
+ public Collection<String> getHostInfo() {
+ return this.hosts;
+ }
+
+ /**
* Get the services which are deployed to this host group.
*
* @return collection of services which have components in this host group
@@ -955,6 +818,16 @@ public abstract class BaseBlueprintProcessor extends AbstractControllerResourceP
}
/**
+ * Get the components associated with the host group.
+ *
+ * @return collection of component names for the host group
+ */
+ public Collection<String> getComponents() {
+ return this.components;
+ }
+
+
+ /**
* Add a component to the host group.
*
* @param component component to add
@@ -994,7 +867,7 @@ public abstract class BaseBlueprintProcessor extends AbstractControllerResourceP
*
* @return map of configuration type to a map of properties
*/
- public Map<String, Map<String, String>> getConfigurationProperties() {
+ public Map<String, Map<String, String>> getConfigurations() {
return configurations;
}
@@ -1016,7 +889,7 @@ public abstract class BaseBlueprintProcessor extends AbstractControllerResourceP
*
* @return map of component to missing dependencies
*/
- public Map<String, Collection<DependencyInfo>> validateTopology(Collection<HostGroupImpl> hostGroups,
+ public Map<String, Collection<DependencyInfo>> validateTopology(Collection<HostGroup> hostGroups,
Collection<String> services,
Map<String, Map<String, String>> clusterConfig) {
@@ -1038,14 +911,14 @@ public abstract class BaseBlueprintProcessor extends AbstractControllerResourceP
boolean resolved = false;
if (dependencyScope.equals("cluster")) {
- Collection<String> missingDependencyInfo = blueprintProcessor.verifyComponentCardinalityCount(entity, hostGroups,
+ Collection<String> missingDependencyInfo = verifyComponentCardinalityCount(entity, hostGroups,
componentName, new Cardinality("1+"), autoDeployInfo, stack, clusterConfig);
resolved = missingDependencyInfo.isEmpty();
} else if (dependencyScope.equals("host")) {
if (components.contains(component) || (autoDeployInfo != null && autoDeployInfo.isEnabled())) {
resolved = true;
if (addComponent(componentName)) {
- blueprintProcessor.addComponentToBlueprint(hostGroup.getBlueprintEntity(), getEntity().getName(), componentName);
+ addComponentToBlueprint(hostGroup.getBlueprintEntity(), getEntity().getName(), componentName);
}
}
}
@@ -1084,12 +957,8 @@ public abstract class BaseBlueprintProcessor extends AbstractControllerResourceP
typeProperties = new HashMap<String, String>();
configurations.put(type, typeProperties);
}
- Map<String, String> propertyMap = jsonSerializer.<Map<String, String>>fromJson(
- configEntity.getConfigData(), Map.class);
-
- if (propertyMap != null) {
- typeProperties.putAll(propertyMap);
- }
+ configurations.put(type, jsonSerializer.<Map<String, String>>fromJson(
+ configEntity.getConfigData(), Map.class));
}
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/7e28d1e3/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BaseProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BaseProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BaseProvider.java
index b4d582a..f31ed7a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BaseProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BaseProvider.java
@@ -18,16 +18,6 @@
package org.apache.ambari.server.controller.internal;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
import org.apache.ambari.server.controller.spi.Predicate;
import org.apache.ambari.server.controller.spi.Request;
import org.apache.ambari.server.controller.spi.Resource;
@@ -36,6 +26,10 @@ import org.apache.ambari.server.controller.utilities.PropertyHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
/**
* Base provider implementation for both property and resource providers.
*/
@@ -67,19 +61,6 @@ public abstract class BaseProvider {
protected final static Logger LOG =
LoggerFactory.getLogger(BaseProvider.class);
- /**
- * The regex pattern that will match on all $1, $2.method(0), and
- * $3.method(\"/\",\"///\") and properly substitute. For example, it can turn
- * <p/>
- * {@code
- * metrics/yarn/Queue/$1.replaceAll(\"([.])\",\"/\")/AppsCompleted/$2.substring(0)/foo/$3/bar/$4
- * }
- * <p/>
- * into
- * <p/>
- * {@code metrics/yarn/Queue/-/AppsCompleted/-/foo/-/bar/-}
- */
- private static final Pattern METRIC_ARGUMENT_METHOD_REPLACEMENT = Pattern.compile("\\$\\d+(\\.\\w+(\\(\\\\\"\\S+\\\\\"\\)|\\(\\d+\\)))*");
// ----- Constructors ------------------------------------------------------
@@ -90,17 +71,13 @@ public abstract class BaseProvider {
*/
public BaseProvider(Set<String> propertyIds) {
this.propertyIds = new HashSet<String>(propertyIds);
- categoryIds = PropertyHelper.getCategories(propertyIds);
- combinedIds = new HashSet<String>(propertyIds);
- combinedIds.addAll(categoryIds);
- patterns = new HashMap<String, Pattern>();
-
- // convert the argumented metric as it's defined in the JSON file to regex
- for (String id : combinedIds) {
+ this.categoryIds = PropertyHelper.getCategories(propertyIds);
+ this.combinedIds = new HashSet<String>(propertyIds);
+ this.combinedIds.addAll(this.categoryIds);
+ this.patterns = new HashMap<String, Pattern>();
+ for (String id : this.combinedIds) {
if (containsArguments(id)) {
- String pattern = METRIC_ARGUMENT_METHOD_REPLACEMENT.matcher(id).replaceAll(
- "(\\\\S*)");
-
+ String pattern = id.replaceAll("\\$\\d+(\\.\\S+\\(\\S+\\))*", "(\\\\S+)");
patterns.put(id, Pattern.compile(pattern));
}
}
@@ -116,17 +93,15 @@ public abstract class BaseProvider {
*/
protected Set<String> checkConfigPropertyIds(Set<String> base, String configCategory) {
- if (0 == base.size()) {
+ if (0 == base.size())
return base;
- }
Set<String> unsupported = new HashSet<String>();
for (String propertyId : base)
{
- if (!propertyId.startsWith(configCategory + "/desired_config")) {
+ if (!propertyId.startsWith(configCategory + "/desired_config"))
unsupported.add(propertyId);
- }
}
return unsupported;
@@ -135,7 +110,7 @@ public abstract class BaseProvider {
public Set<String> checkPropertyIds(Set<String> propertyIds) {
if (!this.propertyIds.containsAll(propertyIds)) {
Set<String> unsupportedPropertyIds = new HashSet<String>(propertyIds);
- unsupportedPropertyIds.removeAll(combinedIds);
+ unsupportedPropertyIds.removeAll(this.combinedIds);
// If the property id is not in the set of known property ids we may still allow it if
// its parent category is a known property. This allows for Map type properties where
@@ -175,17 +150,17 @@ public abstract class BaseProvider {
propertyIds.addAll(PredicateHelper.getPropertyIds(predicate));
}
- if (!combinedIds.containsAll(propertyIds)) {
+ if (!this.combinedIds.containsAll(propertyIds)) {
Set<String> keepers = new HashSet<String>();
Set<String> unsupportedPropertyIds = new HashSet<String>(propertyIds);
- unsupportedPropertyIds.removeAll(combinedIds);
+ unsupportedPropertyIds.removeAll(this.combinedIds);
for (String unsupportedPropertyId : unsupportedPropertyIds) {
if (checkCategory(unsupportedPropertyId) || checkRegExp(unsupportedPropertyId)) {
keepers.add(unsupportedPropertyId);
}
}
- propertyIds.retainAll(combinedIds);
+ propertyIds.retainAll(this.combinedIds);
propertyIds.addAll(keepers);
}
return propertyIds;
@@ -198,7 +173,7 @@ public abstract class BaseProvider {
protected boolean checkCategory(String unsupportedPropertyId) {
String category = PropertyHelper.getPropertyCategory(unsupportedPropertyId);
while (category != null) {
- if(propertyIds.contains(category)) {
+ if(this.propertyIds.contains(category)) {
return true;
}
category = PropertyHelper.getPropertyCategory(category);
@@ -216,28 +191,20 @@ public abstract class BaseProvider {
return false;
}
- /**
- * Gets the key/value mapping between a metric string in the JSON files and
- * the Java regular expression pattern that matches it.
- *
- * @param id
- * @return the entry, or {@code null} if none match the ID.
- */
- protected Map.Entry<String, Pattern> getRegexEntry(String id) {
- Map.Entry<String, Pattern> regexEntry = null;
-
+ protected String getRegExpKey(String id) {
+ String regExpKey = null;
for (Map.Entry<String, Pattern> entry : patterns.entrySet()) {
Pattern pattern = entry.getValue();
Matcher matcher = pattern.matcher(id);
if (matcher.matches()) {
String key = entry.getKey();
- if (regexEntry == null || key.startsWith(regexEntry.getKey())) {
- regexEntry = entry;
+ if (regExpKey == null || key.startsWith(regExpKey)) {
+ regExpKey = entry.getKey();
}
}
}
- return regexEntry;
+ return regExpKey;
}
/**