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 2013/03/20 21:44:50 UTC
svn commit: r1459041 [5/18] - in /incubator/ambari/branches/branch-1.2: ./
ambari-agent/ ambari-agent/conf/unix/
ambari-agent/src/main/puppet/modules/hdp-ganglia/files/
ambari-agent/src/main/puppet/modules/hdp-ganglia/manifests/
ambari-agent/src/main/p...
Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerComponentProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerComponentProvider.java?rev=1459041&r1=1459040&r2=1459041&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerComponentProvider.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerComponentProvider.java Wed Mar 20 20:44:43 2013
@@ -24,7 +24,6 @@ import org.apache.ambari.server.controll
import org.apache.ambari.server.controller.spi.Resource;
import org.apache.ambari.server.controller.utilities.PropertyHelper;
-import java.util.Map;
import java.util.Set;
/**
@@ -47,31 +46,18 @@ public class GSInstallerComponentProvide
* @param clusterDefinition the cluster definition
*/
public GSInstallerComponentProvider(ClusterDefinition clusterDefinition) {
- super(clusterDefinition);
+ super(Resource.Type.Component, clusterDefinition);
initComponentResources();
}
- // ----- ResourceProvider --------------------------------------------------
-
- @Override
- public Set<String> getPropertyIdsForSchema() {
- return PropertyHelper.getPropertyIds(Resource.Type.Component);
- }
-
- @Override
- public Map<Resource.Type, String> getKeyPropertyIds() {
- return PropertyHelper.getKeyPropertyIds(Resource.Type.Component);
- }
-
-
// ----- GSInstallerResourceProvider ---------------------------------------
@Override
public void updateProperties(Resource resource, Request request, Predicate predicate) {
Set<String> propertyIds = getRequestPropertyIds(request, predicate);
- if (propertyIds.contains(COMPONENT_STATE_PROPERTY_ID)) {
+ if (contains(propertyIds, COMPONENT_STATE_PROPERTY_ID)) {
String serviceName = (String) resource.getPropertyValue(COMPONENT_SERVICE_NAME_PROPERTY_ID);
String componentName = (String) resource.getPropertyValue(COMPONENT_COMPONENT_NAME_PROPERTY_ID);
resource.setProperty(COMPONENT_STATE_PROPERTY_ID, getClusterDefinition().getComponentState(serviceName, componentName));
Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostComponentProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostComponentProvider.java?rev=1459041&r1=1459040&r2=1459041&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostComponentProvider.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostComponentProvider.java Wed Mar 20 20:44:43 2013
@@ -24,7 +24,6 @@ import org.apache.ambari.server.controll
import org.apache.ambari.server.controller.spi.Resource;
import org.apache.ambari.server.controller.utilities.PropertyHelper;
-import java.util.Map;
import java.util.Set;
/**
@@ -49,31 +48,18 @@ public class GSInstallerHostComponentPro
* @param clusterDefinition the cluster definition
*/
public GSInstallerHostComponentProvider(ClusterDefinition clusterDefinition) {
- super(clusterDefinition);
+ super(Resource.Type.HostComponent, clusterDefinition);
initHostComponentResources();
}
- // ----- ResourceProvider --------------------------------------------------
-
- @Override
- public Set<String> getPropertyIdsForSchema() {
- return PropertyHelper.getPropertyIds(Resource.Type.HostComponent);
- }
-
- @Override
- public Map<Resource.Type, String> getKeyPropertyIds() {
- return PropertyHelper.getKeyPropertyIds(Resource.Type.HostComponent);
- }
-
-
// ----- GSInstallerResourceProvider ---------------------------------------
@Override
public void updateProperties(Resource resource, Request request, Predicate predicate) {
Set<String> propertyIds = getRequestPropertyIds(request, predicate);
- if (propertyIds.contains(HOST_COMPONENT_STATE_PROPERTY_ID) ||
- propertyIds.contains(HOST_COMPONENT_DESIRED_STATE_PROPERTY_ID)) {
+ if (contains(propertyIds, HOST_COMPONENT_STATE_PROPERTY_ID) ||
+ contains(propertyIds, HOST_COMPONENT_DESIRED_STATE_PROPERTY_ID)) {
String serviceName = (String) resource.getPropertyValue(HOST_COMPONENT_SERVICE_NAME_PROPERTY_ID);
String componentName = (String) resource.getPropertyValue(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID);
String hostName = (String) resource.getPropertyValue(HOST_COMPONENT_HOST_NAME_PROPERTY_ID);
Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostProvider.java?rev=1459041&r1=1459040&r2=1459041&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostProvider.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostProvider.java Wed Mar 20 20:44:43 2013
@@ -24,7 +24,6 @@ import org.apache.ambari.server.controll
import org.apache.ambari.server.controller.spi.Resource;
import org.apache.ambari.server.controller.utilities.PropertyHelper;
-import java.util.Map;
import java.util.Set;
/**
@@ -49,30 +48,17 @@ public class GSInstallerHostProvider ext
* @param clusterDefinition the cluster definition
*/
public GSInstallerHostProvider(ClusterDefinition clusterDefinition) {
- super(clusterDefinition);
+ super(Resource.Type.Host, clusterDefinition);
initHostResources();
}
- // ----- ResourceProvider --------------------------------------------------
-
- @Override
- public Set<String> getPropertyIdsForSchema() {
- return PropertyHelper.getPropertyIds(Resource.Type.Host);
- }
-
- @Override
- public Map<Resource.Type, String> getKeyPropertyIds() {
- return PropertyHelper.getKeyPropertyIds(Resource.Type.Host);
- }
-
-
// ----- GSInstallerResourceProvider ---------------------------------------
@Override
public void updateProperties(Resource resource, Request request, Predicate predicate) {
Set<String> propertyIds = getRequestPropertyIds(request, predicate);
- if (propertyIds.contains(HOST_STATE_PROPERTY_ID)) {
+ if (contains(propertyIds, HOST_STATE_PROPERTY_ID)) {
String hostName = (String) resource.getPropertyValue(HOST_NAME_PROPERTY_ID);
resource.setProperty(HOST_STATE_PROPERTY_ID, getClusterDefinition().getHostState(hostName));
}
Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerNoOpProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerNoOpProvider.java?rev=1459041&r1=1459040&r2=1459041&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerNoOpProvider.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerNoOpProvider.java Wed Mar 20 20:44:43 2013
@@ -20,18 +20,12 @@ package org.apache.ambari.server.control
import org.apache.ambari.server.controller.spi.Predicate;
import org.apache.ambari.server.controller.spi.Request;
import org.apache.ambari.server.controller.spi.Resource;
-import org.apache.ambari.server.controller.utilities.PropertyHelper;
-
-import java.util.Map;
-import java.util.Set;
/**
* A NO-OP resource provider for a gsInstaller defined cluster.
*/
public class GSInstallerNoOpProvider extends GSInstallerResourceProvider{
- private final Resource.Type type;
-
// ----- GSInstallerResourceProvider ---------------------------------------
@Override
@@ -42,20 +36,6 @@ public class GSInstallerNoOpProvider ext
// ----- Constructors ------------------------------------------------------
public GSInstallerNoOpProvider(Resource.Type type, ClusterDefinition clusterDefinition) {
- super(clusterDefinition);
- this.type = type;
- }
-
-
- // ----- ResourceProvider --------------------------------------------------
-
- @Override
- public Set<String> getPropertyIdsForSchema() {
- return PropertyHelper.getPropertyIds(type);
- }
-
- @Override
- public Map<Resource.Type, String> getKeyPropertyIds() {
- return PropertyHelper.getKeyPropertyIds(type);
+ super(type, clusterDefinition);
}
}
Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerProviderModule.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerProviderModule.java?rev=1459041&r1=1459040&r2=1459041&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerProviderModule.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerProviderModule.java Wed Mar 20 20:44:43 2013
@@ -38,11 +38,12 @@ public class GSInstallerProviderModule e
private static final Map<String, String> PORTS = new HashMap<String, String>();
static {
- PORTS.put("NAMENODE", "50070");
- PORTS.put("DATANODE", "50075");
- PORTS.put("JOBTRACKER", "50030");
- PORTS.put("TASKTRACKER", "50060");
- PORTS.put("HBASE_MASTER", "60010");
+ PORTS.put("NAMENODE", "50070");
+ PORTS.put("DATANODE", "50075");
+ PORTS.put("JOBTRACKER", "50030");
+ PORTS.put("TASKTRACKER", "50060");
+ PORTS.put("HBASE_MASTER", "60010");
+ PORTS.put("HBASE_REGIONSERVER", "60030");
}
private static final int TIMEOUT = 5000;
Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerResourceProvider.java?rev=1459041&r1=1459040&r2=1459041&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerResourceProvider.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerResourceProvider.java Wed Mar 20 20:44:43 2013
@@ -30,8 +30,10 @@ import org.apache.ambari.server.controll
import org.apache.ambari.server.controller.spi.SystemException;
import org.apache.ambari.server.controller.spi.UnsupportedPropertyException;
import org.apache.ambari.server.controller.utilities.PredicateHelper;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
@@ -44,6 +46,10 @@ public abstract class GSInstallerResourc
private final Set<Resource> resources = new HashSet<Resource>();
+ private final Resource.Type type;
+
+ private final Set<String> propertyIds;
+
// ----- Constructors ------------------------------------------------------
@@ -52,8 +58,13 @@ public abstract class GSInstallerResourc
*
* @param clusterDefinition the cluster definition
*/
- public GSInstallerResourceProvider(ClusterDefinition clusterDefinition) {
+ public GSInstallerResourceProvider(Resource.Type type, ClusterDefinition clusterDefinition) {
+ this.type = type;
this.clusterDefinition = clusterDefinition;
+
+ Set<String> propertyIds = PropertyHelper.getPropertyIds(type);
+ this.propertyIds = new HashSet<String>(propertyIds);
+ this.propertyIds.addAll(PropertyHelper.getCategories(propertyIds));
}
@@ -94,47 +105,43 @@ public abstract class GSInstallerResourc
}
@Override
+ public Map<Resource.Type, String> getKeyPropertyIds() {
+ return PropertyHelper.getKeyPropertyIds(type);
+ }
+
+ @Override
public Set<String> checkPropertyIds(Set<String> propertyIds) {
propertyIds = new HashSet<String>(propertyIds);
- propertyIds.removeAll(getPropertyIdsForSchema());
+ propertyIds.removeAll(this.propertyIds);
return propertyIds;
}
- // ----- accessors ---------------------------------------------------------
+ // ----- GSInstallerResourceProvider ---------------------------------------
/**
- * Get the configuration provider.
+ * Update the resource with any properties handled by the resource provider.
*
- * @return the configuration provider
+ * @param resource the resource to update
+ * @param request the request
+ * @param predicate the predicate
*/
- protected ClusterDefinition getClusterDefinition() {
- return clusterDefinition;
- }
+ public abstract void updateProperties(Resource resource, Request request, Predicate predicate);
- // ----- helper methods ----------------------------------------------------
+ // ----- accessors ---------------------------------------------------------
/**
- * Add a resource to the set of resources provided by this provider.
+ * Get the configuration provider.
*
- * @param resource the resource to add
+ * @return the configuration provider
*/
- protected void addResource(Resource resource) {
- resources.add(resource);
+ protected ClusterDefinition getClusterDefinition() {
+ return clusterDefinition;
}
- // ----- GSInstallerResourceProvider ---------------------------------------
-
- /**
- * Update the resource with any properties handled by the resource provider.
- *
- * @param resource the resource to update
- * @param request the request
- * @param predicate the predicate
- */
- public abstract void updateProperties(Resource resource, Request request, Predicate predicate);
+ // ----- helper methods ----------------------------------------------------
/**
* Get the set of property ids required to satisfy the given request.
@@ -149,7 +156,7 @@ public abstract class GSInstallerResourc
// if no properties are specified, then return them all
if (propertyIds == null || propertyIds.isEmpty()) {
- return new HashSet<String>(getPropertyIdsForSchema());
+ return new HashSet<String>(this.propertyIds);
}
propertyIds = new HashSet<String>(propertyIds);
@@ -161,6 +168,36 @@ public abstract class GSInstallerResourc
}
/**
+ * Check to see if the given set contains a property or category id that matches the given property id.
+ *
+ * @param ids the set of property/category ids
+ * @param propertyId the property id
+ *
+ * @return true if the given set contains a property id or category that matches the given property id
+ */
+ protected static boolean contains(Set<String> ids, String propertyId) {
+ boolean contains = ids.contains(propertyId);
+
+ if (!contains) {
+ String category = PropertyHelper.getPropertyCategory(propertyId);
+ while (category != null && !contains) {
+ contains = ids.contains(category);
+ category = PropertyHelper.getPropertyCategory(category);
+ }
+ }
+ return contains;
+ }
+
+ /**
+ * Add a resource to the set of resources provided by this provider.
+ *
+ * @param resource the resource to add
+ */
+ protected void addResource(Resource resource) {
+ resources.add(resource);
+ }
+
+ /**
* Factory method for obtaining a resource provider based on a given type.
*
* @param type the resource type
Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerServiceProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerServiceProvider.java?rev=1459041&r1=1459040&r2=1459041&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerServiceProvider.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerServiceProvider.java Wed Mar 20 20:44:43 2013
@@ -24,7 +24,6 @@ import org.apache.ambari.server.controll
import org.apache.ambari.server.controller.spi.Resource;
import org.apache.ambari.server.controller.utilities.PropertyHelper;
-import java.util.Map;
import java.util.Set;
/**
@@ -46,30 +45,17 @@ public class GSInstallerServiceProvider
* @param clusterDefinition the cluster definition
*/
public GSInstallerServiceProvider(ClusterDefinition clusterDefinition) {
- super(clusterDefinition);
+ super(Resource.Type.Service, clusterDefinition);
initServiceResources();
}
- // ----- ResourceProvider --------------------------------------------------
-
- @Override
- public Set<String> getPropertyIdsForSchema() {
- return PropertyHelper.getPropertyIds(Resource.Type.Service);
- }
-
- @Override
- public Map<Resource.Type, String> getKeyPropertyIds() {
- return PropertyHelper.getKeyPropertyIds(Resource.Type.Service);
- }
-
-
// ----- GSInstallerResourceProvider ---------------------------------------
@Override
public void updateProperties(Resource resource, Request request, Predicate predicate) {
Set<String> propertyIds = getRequestPropertyIds(request, predicate);
- if (propertyIds.contains(SERVICE_SERVICE_STATE_PROPERTY_ID)) {
+ if (contains(propertyIds, SERVICE_SERVICE_STATE_PROPERTY_ID)) {
String serviceName = (String) resource.getPropertyValue(SERVICE_SERVICE_NAME_PROPERTY_ID);
resource.setProperty(SERVICE_SERVICE_STATE_PROPERTY_ID, getClusterDefinition().getServiceState(serviceName));
}
Added: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractPropertyProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractPropertyProvider.java?rev=1459041&view=auto
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractPropertyProvider.java (added)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractPropertyProvider.java Wed Mar 20 20:44:43 2013
@@ -0,0 +1,97 @@
+/**
+ * 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 org.apache.ambari.server.controller.spi.PropertyProvider;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Abstract property provider implementation.
+ */
+public abstract class AbstractPropertyProvider extends BaseProvider implements PropertyProvider {
+
+ /**
+ * The property/metric information for this provider keyed by component name / property id.
+ */
+ private final Map<String, Map<String, PropertyInfo>> componentMetrics;
+
+
+ // ----- Constructors ------------------------------------------------------
+
+ /**
+ * Construct a provider.
+ *
+ * @param componentMetrics map of metrics for this provider
+ */
+ public AbstractPropertyProvider(Map<String, Map<String, PropertyInfo>> componentMetrics) {
+ super(PropertyHelper.getPropertyIds(componentMetrics));
+ this.componentMetrics = componentMetrics;
+ }
+
+
+ // ----- accessors ---------------------------------------------------------
+
+ /**
+ * Get the map of metrics for this provider.
+ *
+ * @return the map of metric / property info.
+ */
+ public Map<String, Map<String, PropertyInfo>> getComponentMetrics() {
+ return componentMetrics;
+ }
+
+
+ // ----- helper methods ----------------------------------------------------
+
+ /**
+ * Get a map of metric / property info based on the given component name and property id.
+ * Note that the property id may map to multiple metrics if the property id is a category.
+ *
+ * @param componentName the component name
+ * @param propertyId the property id; may be a category
+ *
+ * @return a map of metrics
+ */
+ protected Map<String, PropertyInfo> getPropertyInfoMap(String componentName, String propertyId) {
+ Map<String, PropertyInfo> componentMetricMap = componentMetrics.get(componentName);
+ if (componentMetricMap == null) {
+ return Collections.emptyMap();
+ }
+
+ PropertyInfo propertyInfo = componentMetricMap.get(propertyId);
+ if (propertyInfo != null) {
+ return Collections.singletonMap(propertyId, propertyInfo);
+ }
+
+ if (!propertyId.endsWith("/")){
+ propertyId += "/";
+ }
+ Map<String, PropertyInfo> propertyInfoMap = new HashMap<String, PropertyInfo>();
+ for (Map.Entry<String, PropertyInfo> entry : componentMetricMap.entrySet()) {
+ if (entry.getKey().startsWith(propertyId)) {
+ propertyInfoMap.put(entry.getKey(), entry.getValue());
+ }
+ }
+ return propertyInfoMap;
+ }
+}
Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java?rev=1459041&r1=1459040&r2=1459041&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java Wed Mar 20 20:44:43 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 -----------------------------------------------
@@ -176,7 +247,7 @@ public abstract class AbstractProviderMo
switch (type){
case Cluster :
providers.add(new GangliaReportPropertyProvider(
- PropertyHelper.getGangliaPropertyIds(type).get("*"),
+ PropertyHelper.getGangliaPropertyIds(type),
streamProvider,
this,
PropertyHelper.getPropertyId("Clusters", "cluster_name")));
@@ -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;
+ }
}
Added: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractResourceProvider.java?rev=1459041&view=auto
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractResourceProvider.java (added)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractResourceProvider.java Wed Mar 20 20:44:43 2013
@@ -0,0 +1,378 @@
+/**
+ * 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.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.DuplicateResourceException;
+import org.apache.ambari.server.ObjectNotFoundException;
+import org.apache.ambari.server.ParentObjectNotFoundException;
+import org.apache.ambari.server.controller.AmbariManagementController;
+import org.apache.ambari.server.controller.RequestStatusResponse;
+import org.apache.ambari.server.controller.predicate.BasePredicate;
+import org.apache.ambari.server.controller.spi.*;
+import org.apache.ambari.server.controller.utilities.PredicateHelper;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Abstract resource provider implementation that maps to an Ambari management controller.
+ */
+public abstract class AbstractResourceProvider extends BaseProvider implements ResourceProvider, ObservableResourceProvider {
+
+ /**
+ * The management controller to delegate to.
+ */
+ private final AmbariManagementController managementController;
+
+ /**
+ * Key property mapping by resource type.
+ */
+ private final Map<Resource.Type, String> keyPropertyIds;
+
+ /**
+ * Observers of this observable resource provider.
+ */
+ private final Set<ResourceProviderObserver> observers = new HashSet<ResourceProviderObserver>();
+
+
+ protected final static Logger LOG =
+ LoggerFactory.getLogger(AbstractResourceProvider.class);
+
+ // ----- Constructors ------------------------------------------------------
+ /**
+ * Create a new resource provider for the given management controller.
+ *
+ * @param propertyIds the property ids
+ * @param keyPropertyIds the key property ids
+ * @param managementController the management controller
+ */
+ protected AbstractResourceProvider(Set<String> propertyIds,
+ Map<Resource.Type, String> keyPropertyIds,
+ AmbariManagementController managementController) {
+ super(propertyIds);
+ this.keyPropertyIds = keyPropertyIds;
+ this.managementController = managementController;
+ }
+
+
+ // ----- ResourceProvider --------------------------------------------------
+
+ @Override
+ public Map<Resource.Type, String> getKeyPropertyIds() {
+ return keyPropertyIds;
+ }
+
+
+ // ----- ObservableResourceProvider ----------------------------------------
+
+ @Override
+ public void updateObservers(ResourceProviderEvent event) {
+ for (ResourceProviderObserver observer : observers) {
+ observer.update(event);
+ }
+ }
+
+ @Override
+ public void addObserver(ResourceProviderObserver observer) {
+ observers.add(observer);
+ }
+
+
+ // ----- accessors ---------------------------------------------------------
+
+ /**
+ * Get the associated management controller.
+ *
+ * @return the associated management controller
+ */
+ protected AmbariManagementController getManagementController() {
+ return managementController;
+ }
+
+
+ // ----- utility methods ---------------------------------------------------
+
+ /**
+ * Get the set of property ids that uniquely identify the resources
+ * of this provider.
+ *
+ * @return the set of primary key properties
+ */
+ protected abstract Set<String> getPKPropertyIds();
+
+ /**
+ * Notify all listeners of a creation event.
+ *
+ * @param type the type of the resources being created
+ * @param request the request used to create the resources
+ */
+ protected void notifyCreate(Resource.Type type, Request request) {
+ updateObservers(new ResourceProviderEvent(type, ResourceProviderEvent.Type.Create, request, null));
+ }
+
+ /**
+ * Notify all listeners of a update event.
+ *
+ * @param type the type of the resources being updated
+ * @param request the request used to update the resources
+ * @param predicate the predicate used to update the resources
+ */
+ protected void notifyUpdate(Resource.Type type, Request request, Predicate predicate) {
+ updateObservers(new ResourceProviderEvent(type, ResourceProviderEvent.Type.Update, request, predicate));
+ }
+
+ /**
+ * Notify all listeners of a delete event.
+ *
+ * @param type the type of the resources being deleted
+ * @param predicate the predicate used to delete the resources
+ */
+ protected void notifyDelete(Resource.Type type, Predicate predicate) {
+ updateObservers(new ResourceProviderEvent(type, ResourceProviderEvent.Type.Delete, null, predicate));
+ }
+
+ /**
+ * Get a set of properties from the given predicate. The returned set of
+ * property/value mappings is required to generate delete or get requests
+ * to the back end which does not deal with predicates. Note that the
+ * single predicate can result in multiple backend requests.
+ *
+ * @param givenPredicate the predicate
+ *
+ * @return the set of properties used to build request objects
+ */
+ protected Set<Map<String, Object>> getPropertyMaps(Predicate givenPredicate)
+ throws UnsupportedPropertyException, SystemException, NoSuchResourceException, NoSuchParentResourceException {
+
+ SimplifyingPredicateVisitor visitor = new SimplifyingPredicateVisitor(getPropertyIds());
+ PredicateHelper.visit(givenPredicate, visitor);
+ List<BasePredicate> predicates = visitor.getSimplifiedPredicates();
+
+ Set<Map<String, Object>> propertyMaps = new HashSet<Map<String, Object>>();
+
+ for (BasePredicate predicate : predicates) {
+ propertyMaps.add(PredicateHelper.getProperties(predicate));
+ }
+ return propertyMaps;
+ }
+
+ /**
+ * Get a set of properties from the given property map and predicate. The
+ * returned set of property/value mappings is required to generate update or create
+ * requests to the back end which does not deal with predicates. Note that
+ * the single property map & predicate can result in multiple backend requests.
+ *
+ * @param requestPropertyMap the request properties (for update)
+ * @param givenPredicate the predicate
+ *
+ * @return the set of properties used to build request objects
+ */
+ protected Set<Map<String, Object>> getPropertyMaps(Map<String, Object> requestPropertyMap,
+ Predicate givenPredicate)
+ throws UnsupportedPropertyException, SystemException, NoSuchResourceException, NoSuchParentResourceException {
+
+ Set<Map<String, Object>> propertyMaps = new HashSet<Map<String, Object>>();
+
+ Set<String> pkPropertyIds = getPKPropertyIds();
+ if (requestPropertyMap != null && !pkPropertyIds.equals(PredicateHelper.getPropertyIds(givenPredicate))) {
+
+ for (Resource resource : getResources(PropertyHelper.getReadRequest(pkPropertyIds), givenPredicate)) {
+ Map<String, Object> propertyMap = new HashMap<String, Object>(PropertyHelper.getProperties(resource));
+ propertyMap.putAll(requestPropertyMap);
+ propertyMaps.add(propertyMap);
+ }
+ }
+ else {
+ Map<String, Object> propertyMap = new HashMap<String, Object>(PredicateHelper.getProperties(givenPredicate));
+ propertyMap.putAll(requestPropertyMap);
+ propertyMaps.add(propertyMap);
+ }
+
+ return propertyMaps;
+ }
+
+ /**
+ * Get a request status
+ *
+ * @return the request status
+ */
+ protected RequestStatus getRequestStatus(RequestStatusResponse response) {
+ if (response != null){
+ Resource requestResource = new ResourceImpl(Resource.Type.Request);
+ requestResource.setProperty(PropertyHelper.getPropertyId("Requests", "id"), response.getRequestId());
+ requestResource.setProperty(PropertyHelper.getPropertyId("Requests", "status"), "InProgress");
+ return new RequestStatusImpl(requestResource);
+ }
+ return new RequestStatusImpl(null);
+ }
+
+ /**
+ * Invoke a command against the Ambari backend to create resources and map
+ * any {@link AmbariException} to the types appropriate for the
+ * {@link ResourceProvider} interface.
+ *
+ * @param command the command to invoke
+ * @param <T> the type of the response
+ *
+ * @return the response
+ *
+ * @throws SystemException thrown if a system exception occurred
+ * @throws ResourceAlreadyExistsException thrown if a resource already exists
+ * @throws NoSuchParentResourceException thrown if a parent of a resource doesn't exist
+ */
+ protected <T> T createResources(Command<T> command)
+ throws SystemException, ResourceAlreadyExistsException, NoSuchParentResourceException {
+ try {
+ return command.invoke();
+ } catch (ParentObjectNotFoundException e) {
+ throw new NoSuchParentResourceException(e.getMessage(), e);
+ } catch (DuplicateResourceException e) {
+ throw new ResourceAlreadyExistsException(e.getMessage());
+ } catch (AmbariException e) {
+ if (LOG.isErrorEnabled()) {
+ LOG.error("Caught AmbariException when creating a resource", e);
+ }
+ throw new SystemException("An internal system exception occurred: " + e.getMessage(), e);
+ }
+ }
+
+ /**
+ * Invoke a command against the Ambari backend to get resources and map
+ * any {@link AmbariException} to the types appropriate for the
+ * {@link ResourceProvider} interface.
+ *
+ * @param command the command to invoke
+ * @param <T> the type of the response
+ *
+ * @return the response
+ *
+ * @throws SystemException thrown if a system exception occurred
+ * @throws NoSuchParentResourceException thrown if a parent of a resource doesn't exist
+ */
+ protected <T> T getResources (Command<T> command)
+ throws SystemException, NoSuchResourceException, NoSuchParentResourceException {
+ try {
+ return command.invoke();
+ } catch (ObjectNotFoundException e) {
+ throw new NoSuchResourceException("The requested resource doesn't exist: " + e.getMessage(), e);
+ } catch (ParentObjectNotFoundException e) {
+ throw new NoSuchParentResourceException(e.getMessage(), e);
+ } catch (AmbariException e) {
+ if (LOG.isErrorEnabled()) {
+ LOG.error("Caught AmbariException when getting a resource", e);
+ }
+ throw new SystemException("An internal system exception occurred: " + e.getMessage(), e);
+ }
+ }
+
+ /**
+ * Invoke a command against the Ambari backend to modify resources and map
+ * any {@link AmbariException} to the types appropriate for the
+ * {@link ResourceProvider} interface.
+ *
+ * @param command the command to invoke
+ * @param <T> the type of the response
+ *
+ * @return the response
+ *
+ * @throws SystemException thrown if a system exception occurred
+ * @throws NoSuchParentResourceException thrown if a parent of a resource doesn't exist
+ */
+ protected <T> T modifyResources (Command<T> command)
+ throws SystemException, NoSuchResourceException, NoSuchParentResourceException {
+ try {
+ return command.invoke();
+ } catch (ObjectNotFoundException e) {
+ throw new NoSuchResourceException("The specified resource doesn't exist: " + e.getMessage(), e);
+ } catch (ParentObjectNotFoundException e) {
+ throw new NoSuchParentResourceException(e.getMessage(), e);
+ } catch (AmbariException e) {
+ if (LOG.isErrorEnabled()) {
+ LOG.error("Caught AmbariException when modifying a resource", e);
+ }
+ throw new SystemException("An internal system exception occurred: " + e.getMessage(), e);
+ }
+ }
+
+ /**
+ * Factory method for obtaining a resource provider based on a given type and management controller.
+ *
+ *
+ * @param type the resource type
+ * @param propertyIds the property ids
+ * @param managementController the management controller
+ *
+ * @return a new resource provider
+ */
+ public static ResourceProvider getResourceProvider(Resource.Type type,
+ Set<String> propertyIds,
+ Map<Resource.Type, String> keyPropertyIds,
+ AmbariManagementController managementController) {
+ switch (type) {
+ case Cluster:
+ return new ClusterResourceProvider(propertyIds, keyPropertyIds, managementController);
+ case Service:
+ return new ServiceResourceProvider(propertyIds, keyPropertyIds, managementController);
+ case Component:
+ return new ComponentResourceProvider(propertyIds, keyPropertyIds, managementController);
+ case Host:
+ return new HostResourceProvider(propertyIds, keyPropertyIds, managementController);
+ case HostComponent:
+ return new HostComponentResourceProvider(propertyIds, keyPropertyIds, managementController);
+ case Configuration:
+ return new ConfigurationResourceProvider(propertyIds, keyPropertyIds, managementController);
+ case Action:
+ return new ActionResourceProvider(propertyIds, keyPropertyIds, managementController);
+ case Request:
+ return new RequestResourceProvider(propertyIds, keyPropertyIds, managementController);
+ case Task:
+ return new TaskResourceProvider(propertyIds, keyPropertyIds, managementController);
+ case User:
+ return new UserResourceProvider(propertyIds, keyPropertyIds, managementController);
+ default:
+ throw new IllegalArgumentException("Unknown type " + type);
+ }
+ }
+
+
+ // ----- Inner interface ---------------------------------------------------
+
+ /**
+ * Command to invoke against the Ambari backend.
+ *
+ * @param <T> the response type
+ */
+ protected interface Command<T> {
+ /**
+ * Invoke this command.
+ *
+ * @return the response
+ *
+ * @throws AmbariException thrown if a problem occurred during invocation
+ */
+ public T invoke() throws AmbariException;
+ }
+}
Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ActionResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ActionResourceProvider.java?rev=1459041&r1=1459040&r2=1459041&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ActionResourceProvider.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ActionResourceProvider.java Wed Mar 20 20:44:43 2013
@@ -34,7 +34,7 @@ import java.util.Set;
/**
* Resource provider for action resources.
*/
-class ActionResourceProvider extends ResourceProviderImpl {
+class ActionResourceProvider extends AbstractResourceProvider {
// ----- Property ID constants ---------------------------------------------
@@ -120,8 +120,11 @@ class ActionResourceProvider extends Res
Map<String, String> params = new HashMap<String, String>();
for (Entry<String, Object> entry : properties.entrySet()) {
String propertyid = entry.getKey();
- if (PropertyHelper.getPropertyCategory(propertyid).equals("parameters")
- && null != entry.getValue()) {
+
+ String propertyCategory = PropertyHelper.getPropertyCategory(propertyid);
+ if (propertyCategory != null &&
+ propertyCategory.equals("parameters") &&
+ null != entry.getValue()) {
params.put(PropertyHelper.getPropertyName(propertyid), entry.getValue().toString());
}
}
Added: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BaseProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BaseProvider.java?rev=1459041&view=auto
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BaseProvider.java (added)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BaseProvider.java Wed Mar 20 20:44:43 2013
@@ -0,0 +1,245 @@
+/**
+ * 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 org.apache.ambari.server.controller.spi.Predicate;
+import org.apache.ambari.server.controller.spi.Request;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.utilities.PredicateHelper;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Base provider implementation for both property and resource providers.
+ */
+public abstract class BaseProvider {
+
+ /**
+ * Set of property ids supported by this provider.
+ */
+ private final Set<String> propertyIds;
+
+ /**
+ * Set of category ids supported by this provider.
+ */
+ private final Set<String> categoryIds;
+
+ /**
+ * Combined property and category ids.
+ */
+ private final Set<String> combinedIds;
+
+ /**
+ * The logger.
+ */
+ protected final static Logger LOG =
+ LoggerFactory.getLogger(BaseProvider.class);
+
+
+ // ----- Constructors ------------------------------------------------------
+
+ /**
+ * Construct a provider.
+ *
+ * @param propertyIds the properties associated with this provider
+ */
+ public BaseProvider(Set<String> propertyIds) {
+ this.propertyIds = new HashSet<String>(propertyIds);
+ this.categoryIds = PropertyHelper.getCategories(propertyIds);
+ this.combinedIds = new HashSet<String>(propertyIds);
+ this.combinedIds.addAll(this.categoryIds);
+ }
+
+
+ // ----- BaseProvider --------------------------------------------------
+
+ public Set<String> checkPropertyIds(Set<String> propertyIds) {
+ if (!this.propertyIds.containsAll(propertyIds)) {
+ Set<String> unsupportedPropertyIds = new HashSet<String>(propertyIds);
+ 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
+ // we want to treat property as a category and the entries as individual properties.
+ Set<String> categoryProperties = new HashSet<String>();
+ for (String unsupportedPropertyId : unsupportedPropertyIds) {
+ String category = PropertyHelper.getPropertyCategory(unsupportedPropertyId);
+ while (category != null) {
+ if (this.propertyIds.contains(category)) {
+ categoryProperties.add(unsupportedPropertyId);
+ }
+ category = PropertyHelper.getPropertyCategory(category);
+ }
+ }
+ unsupportedPropertyIds.removeAll(categoryProperties);
+
+ return unsupportedPropertyIds;
+ }
+ return Collections.emptySet();
+ }
+
+ /**
+ * Get the set of property ids required to satisfy the given request.
+ *
+ * @param request the request
+ * @param predicate the predicate
+ *
+ * @return the set of property ids needed to satisfy the request
+ */
+ protected Set<String> getRequestPropertyIds(Request request, Predicate predicate) {
+ Set<String> propertyIds = request.getPropertyIds();
+
+ // if no properties are specified, then return them all
+ if (propertyIds == null || propertyIds.isEmpty()) {
+ return new HashSet<String>(this.propertyIds);
+ }
+
+ propertyIds = new HashSet<String>(propertyIds);
+
+ if (predicate != null) {
+ propertyIds.addAll(PredicateHelper.getPropertyIds(predicate));
+ }
+
+ if (!this.combinedIds.containsAll(propertyIds)) {
+ Set<String> keepers = new HashSet<String>();
+ Set<String> unsupportedPropertyIds = new HashSet<String>(propertyIds);
+ unsupportedPropertyIds.removeAll(this.combinedIds);
+
+ // Add the categories to account for map properties where the entries will not be
+ // in the provider property list ids but the map (category) might be.
+ for (String unsupportedPropertyId : unsupportedPropertyIds) {
+ String category = PropertyHelper.getPropertyCategory(unsupportedPropertyId);
+ while (category != null) {
+ if (this.propertyIds.contains(category)) {
+ keepers.add(unsupportedPropertyId);
+ break;
+ }
+ category = PropertyHelper.getPropertyCategory(category);
+ }
+ }
+ propertyIds.retainAll(this.combinedIds);
+ propertyIds.addAll(keepers);
+ }
+ return propertyIds;
+ }
+
+ /**
+ * Set a property value on the given resource for the given id and value.
+ * Make sure that the id is in the given set of requested ids.
+ *
+ * @param resource the resource
+ * @param propertyId the property id
+ * @param value the value to set
+ * @param requestedIds the requested set of property ids
+ */
+ protected static boolean setResourceProperty(Resource resource, String propertyId, Object value, Set<String> requestedIds) {
+ boolean contains = requestedIds.contains(propertyId);
+
+ if (!contains) {
+ String category = PropertyHelper.getPropertyCategory(propertyId);
+ while (category != null && !contains) {
+ contains = requestedIds.contains(category);
+ category = PropertyHelper.getPropertyCategory(category);
+ }
+ }
+
+ if (contains) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Setting property for resource"
+ + ", resourceType=" + resource.getType()
+ + ", propertyId=" + propertyId
+ + ", value=" + value);
+ }
+
+ // If the value is a Map then set all of its entries as properties
+ if (!setResourceMapProperty(resource, propertyId, value)){
+ resource.setProperty(propertyId, value);
+ }
+ }
+ else {
+
+ if (value instanceof Map<?, ?>) {
+ // This map wasn't requested, but maybe some of its entries were...
+ Map<?, ?> mapValue = (Map) value;
+
+ for (Map.Entry entry : mapValue.entrySet()) {
+ String entryPropertyId = PropertyHelper.getPropertyId(propertyId, entry.getKey().toString());
+ Object entryValue = entry.getValue();
+
+ contains = setResourceProperty(resource, entryPropertyId, entryValue, requestedIds) || contains;
+ }
+ }
+
+ if (!contains && LOG.isDebugEnabled()) {
+ LOG.debug("Skipping property for resource as not in requestedIds"
+ + ", resourceType=" + resource.getType()
+ + ", propertyId=" + propertyId
+ + ", value=" + value);
+ }
+ }
+ return contains;
+ }
+
+ /**
+ * If the given value is a Map then add its entries to the resource as properties.
+ *
+ * @param resource the resource
+ * @param propertyId the property id of the given value
+ * @param value the property value
+ */
+ private static boolean setResourceMapProperty(Resource resource, String propertyId, Object value) {
+ if (value instanceof Map<?, ?>) {
+ Map<?, ?> mapValue = (Map) value;
+
+ if (mapValue.isEmpty()) {
+ resource.addCategory(propertyId);
+ } else {
+ for (Map.Entry entry : mapValue.entrySet()) {
+ String entryPropertyId = PropertyHelper.getPropertyId(propertyId, entry.getKey().toString());
+ Object entryValue = entry.getValue();
+
+ // If the value is a Map then set all of its entries as properties
+ if (!setResourceMapProperty(resource, entryPropertyId, entryValue)){
+ resource.setProperty(entryPropertyId, entryValue);
+ }
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+
+
+ // ----- accessors ---------------------------------------------------------
+
+ /**
+ * Get the property ids supported by this property adapter.
+ *
+ * @return the property ids supported by this provider
+ */
+ public Set<String> getPropertyIds() {
+ return propertyIds;
+ }
+}
Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterControllerImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterControllerImpl.java?rev=1459041&r1=1459040&r2=1459041&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterControllerImpl.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterControllerImpl.java Wed Mar 20 20:44:43 2013
@@ -109,7 +109,7 @@ public class ClusterControllerImpl imple
synchronized (schemas) {
schema = schemas.get(type);
if (schema == null) {
- schema = new SchemaImpl(ensureResourceProvider(type), ensurePropertyProviders(type));
+ schema = new SchemaImpl(ensureResourceProvider(type));
schemas.put(type, schema);
}
}
Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java?rev=1459041&r1=1459040&r2=1459041&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java Wed Mar 20 20:44:43 2013
@@ -43,7 +43,7 @@ import java.util.Set;
/**
* Resource provider for cluster resources.
*/
-class ClusterResourceProvider extends ResourceProviderImpl{
+class ClusterResourceProvider extends AbstractResourceProvider {
// ----- Property ID constants ---------------------------------------------
@@ -100,7 +100,7 @@ class ClusterResourceProvider extends Re
throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
final ClusterRequest clusterRequest = getRequest(PredicateHelper.getProperties(predicate));
- Set<String> requestedIds = PropertyHelper.getRequestPropertyIds(getPropertyIds(), request, predicate);
+ Set<String> requestedIds = getRequestPropertyIds(request, predicate);
// TODO : handle multiple requests
Set<ClusterResponse> responses = getResources(new Command<Set<ClusterResponse>>() {
Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ComponentResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ComponentResourceProvider.java?rev=1459041&r1=1459040&r2=1459041&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ComponentResourceProvider.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ComponentResourceProvider.java Wed Mar 20 20:44:43 2013
@@ -34,7 +34,7 @@ import java.util.Set;
/**
* Resource provider for component resources.
*/
-class ComponentResourceProvider extends ResourceProviderImpl{
+class ComponentResourceProvider extends AbstractResourceProvider {
// ----- Property ID constants ---------------------------------------------
@@ -112,7 +112,7 @@ class ComponentResourceProvider extends
}
});
- Set<String> requestedIds = PropertyHelper.getRequestPropertyIds(getPropertyIds(), request, predicate);
+ Set<String> requestedIds = getRequestPropertyIds(request, predicate);
Set<Resource> resources = new HashSet<Resource>();
for (ServiceComponentResponse response : responses) {
@@ -139,7 +139,8 @@ class ComponentResourceProvider extends
Map<String, String> configMap = new HashMap<String,String>();
for (Map.Entry<String,Object> entry : propertyMap.entrySet()) {
- if (PropertyHelper.getPropertyCategory(entry.getKey()).equals("config")) {
+ String propertyCategory = PropertyHelper.getPropertyCategory(entry.getKey());
+ if (propertyCategory != null && propertyCategory.equals("config")) {
configMap.put(PropertyHelper.getPropertyName(entry.getKey()), (String) entry.getValue());
}
}
Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ConfigurationResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ConfigurationResourceProvider.java?rev=1459041&r1=1459040&r2=1459041&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ConfigurationResourceProvider.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ConfigurationResourceProvider.java Wed Mar 20 20:44:43 2013
@@ -1,5 +1,3 @@
-package org.apache.ambari.server.controller.internal;
-
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,8 @@ package org.apache.ambari.server.control
* limitations under the License.
*/
+package org.apache.ambari.server.controller.internal;
+
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.controller.AmbariManagementController;
import org.apache.ambari.server.controller.ConfigurationRequest;
@@ -46,7 +46,7 @@ import java.util.Map.Entry;
/**
* Resource provider for configuration resources.
*/
-class ConfigurationResourceProvider extends ResourceProviderImpl {
+class ConfigurationResourceProvider extends AbstractResourceProvider {
// ----- Property ID constants ---------------------------------------------
@@ -56,23 +56,37 @@ class ConfigurationResourceProvider exte
protected static final String CONFIGURATION_CONFIG_TYPE_PROPERTY_ID = PropertyHelper.getPropertyId(null, "type");
protected static final String CONFIGURATION_CONFIG_TAG_PROPERTY_ID = PropertyHelper.getPropertyId(null, "tag");
- private static final String CONFIG_HOST_NAME = PropertyHelper.getPropertyId("Config", "host_name");
+ private static final String CONFIG_HOST_NAME = PropertyHelper.getPropertyId("Config", "host_name");
private static final String CONFIG_COMPONENT_NAME = PropertyHelper.getPropertyId("Config", "component_name");
-
+ /**
+ * The primary key property ids for the configuration resource type.
+ */
private static Set<String> pkPropertyIds =
new HashSet<String>(Arrays.asList(new String[]{
CONFIGURATION_CLUSTER_NAME_PROPERTY_ID,
CONFIGURATION_CONFIG_TYPE_PROPERTY_ID}));
+
+ // ----- Constructors ------------------------------------------------------
+
+ /**
+ * Constructor
+ *
+ * @param propertyIds the property ids supported by this provider
+ * @param keyPropertyIds the key properties for this provider
+ * @param managementController the associated management controller
+ */
ConfigurationResourceProvider(Set<String> propertyIds,
Map<Resource.Type, String> keyPropertyIds,
AmbariManagementController managementController) {
super(propertyIds, keyPropertyIds, managementController);
-
}
+
+ // ----- ResourceProvider --------------------------------------------------
+
@Override
public RequestStatus createResources(Request request)
throws SystemException,
@@ -83,15 +97,14 @@ class ConfigurationResourceProvider exte
for (Map<String, Object> map : request.getProperties()) {
String cluster = (String) map.get(CONFIGURATION_CLUSTER_NAME_PROPERTY_ID);
- // TODO : why not CONFIGURATION_CONFIG_TYPE_PROPERTY_ID?
- String type = (String) map.get(PropertyHelper.getPropertyId("", "type"));
- // TODO : why not CONFIGURATION_CONFIG_TAG_PROPERTY_ID?
- String tag = (String) map.get(PropertyHelper.getPropertyId("", "tag"));
+ String type = (String) map.get(CONFIGURATION_CONFIG_TYPE_PROPERTY_ID);
+ String tag = (String) map.get(CONFIGURATION_CONFIG_TAG_PROPERTY_ID);
Map<String, String> configMap = new HashMap<String, String>();
for (Entry<String, Object> entry : map.entrySet()) {
- if (PropertyHelper.getPropertyCategory(entry.getKey()).equals("properties") && null != entry.getValue()) {
+ String propertyCategory = PropertyHelper.getPropertyCategory(entry.getKey());
+ if (propertyCategory != null && propertyCategory.equals("properties") && null != entry.getValue()) {
configMap.put(PropertyHelper.getPropertyName(entry.getKey()), entry.getValue().toString());
}
}
@@ -145,8 +158,6 @@ class ConfigurationResourceProvider exte
resources.add(resource);
}
-
-
return resources;
} else {
@@ -175,10 +186,8 @@ class ConfigurationResourceProvider exte
resource.setProperty(id, entry.getValue());
}
}
-
resources.add(resource);
}
-
return resources;
}
}
@@ -196,7 +205,8 @@ class ConfigurationResourceProvider exte
* Throws an exception, as Configurations cannot be deleted.
*/
@Override
- public RequestStatus deleteResources(Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
+ public RequestStatus deleteResources(Predicate predicate) throws SystemException,
+ UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
throw new UnsupportedOperationException("Cannot delete a Configuration resource.");
}
@@ -214,7 +224,8 @@ class ConfigurationResourceProvider exte
// TODO : hack to allow for inconsistent property names
// for example, the tag property can come here as Config/tag, /tag or tag
if (!propertyId.equals("tag") && !propertyId.equals("type") &&
- !propertyId.equals("/tag") && !propertyId.equals("/type")) {
+ !propertyId.equals("/tag") && !propertyId.equals("/type") &&
+ !propertyId.equals("properties")) {
String propertyCategory = PropertyHelper.getPropertyCategory(propertyId);
@@ -226,15 +237,28 @@ class ConfigurationResourceProvider exte
return unsupportedProperties;
}
+ // ----- AbstractResourceProvider ------------------------------------------
+
@Override
protected Set<String> getPKPropertyIds() {
return pkPropertyIds;
}
- public static Map<String, String> getConfigPropertyValues(Map<String, Object> propertyMap) {
+
+ // ----- utility methods ---------------------------------------------------
+
+ /**
+ * Get the config related property ids from the given map of property ids.
+ *
+ * @param propertyIdMap the map of property ids
+ *
+ * @return a subset of the given map containing olny the property ids that have a
+ * category of "config"
+ */
+ public static Map<String, String> getConfigPropertyValues(Map<String, Object> propertyIdMap) {
Map<String, String> configMap = new HashMap<String, String>();
- for (Map.Entry<String,Object> entry : propertyMap.entrySet()) {
+ for (Map.Entry<String,Object> entry : propertyIdMap.entrySet()) {
String propertyId = entry.getKey();
if (PropertyHelper.getPropertyCategory(propertyId).equals("config")) {
configMap.put(PropertyHelper.getPropertyName(propertyId), (String) entry.getValue());
@@ -243,10 +267,16 @@ class ConfigurationResourceProvider exte
return configMap;
}
+ /**
+ * Get a configuration request object from the given map of properties.
+ *
+ * @param properties the map of properties
+ *
+ * @return a configuration request
+ */
private ConfigurationRequest getRequest(Map<String, Object> properties) {
String type = (String) properties.get(CONFIGURATION_CONFIG_TYPE_PROPERTY_ID);
-
- String tag = (String) properties.get(CONFIGURATION_CONFIG_TAG_PROPERTY_ID);
+ String tag = (String) properties.get(CONFIGURATION_CONFIG_TAG_PROPERTY_ID);
return new ConfigurationRequest(
(String) properties.get(CONFIGURATION_CLUSTER_NAME_PROPERTY_ID),
Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java?rev=1459041&r1=1459040&r2=1459041&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java Wed Mar 20 20:44:43 2013
@@ -48,7 +48,7 @@ public class DefaultProviderModule exten
@Override
protected ResourceProvider createResourceProvider(Resource.Type type) {
- return ResourceProviderImpl.getResourceProvider(type, PropertyHelper.getPropertyIds(type),
- PropertyHelper.getKeyPropertyIds(type), managementController);
+ return AbstractResourceProvider.getResourceProvider(type, PropertyHelper.getPropertyIds(type),
+ PropertyHelper.getKeyPropertyIds(type), managementController);
}
}
Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java?rev=1459041&r1=1459040&r2=1459041&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java Wed Mar 20 20:44:43 2013
@@ -34,7 +34,7 @@ import java.util.Set;
/**
* Resource provider for host component resources.
*/
-class HostComponentResourceProvider extends ResourceProviderImpl {
+class HostComponentResourceProvider extends AbstractResourceProvider {
// ----- Property ID constants ---------------------------------------------
@@ -108,7 +108,7 @@ class HostComponentResourceProvider exte
}
Set<Resource> resources = new HashSet<Resource>();
- Set<String> requestedIds = PropertyHelper.getRequestPropertyIds(getPropertyIds(), request, predicate);
+ Set<String> requestedIds = getRequestPropertyIds(request, predicate);
Set<ServiceComponentHostResponse> responses = getResources(new Command<Set<ServiceComponentHostResponse>>() {
@Override
@@ -186,9 +186,11 @@ class HostComponentResourceProvider exte
Set<String> unsupportedProperties = new HashSet<String>();
for (String propertyId : propertyIds) {
- String propertyCategory = PropertyHelper.getPropertyCategory(propertyId);
- if (propertyCategory == null || !propertyCategory.equals("config")) {
- unsupportedProperties.add(propertyId);
+ if (!propertyId.equals("config")) {
+ String propertyCategory = PropertyHelper.getPropertyCategory(propertyId);
+ if (propertyCategory == null || !propertyCategory.equals("config")) {
+ unsupportedProperties.add(propertyId);
+ }
}
}
return unsupportedProperties;
Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java?rev=1459041&r1=1459040&r2=1459041&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java Wed Mar 20 20:44:43 2013
@@ -33,7 +33,7 @@ import org.apache.ambari.server.controll
/**
* Resource provider for host resources.
*/
-class HostResourceProvider extends ResourceProviderImpl{
+class HostResourceProvider extends AbstractResourceProvider {
// ----- Property ID constants ---------------------------------------------
@@ -138,7 +138,7 @@ class HostResourceProvider extends Resou
}
});
- Set<String> requestedIds = PropertyHelper.getRequestPropertyIds(getPropertyIds(), request, predicate);
+ Set<String> requestedIds = getRequestPropertyIds(request, predicate);
Set<Resource> resources = new HashSet<Resource>();
for (HostResponse response : responses) {
Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HttpProxyPropertyProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HttpProxyPropertyProvider.java?rev=1459041&r1=1459040&r2=1459041&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HttpProxyPropertyProvider.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HttpProxyPropertyProvider.java Wed Mar 20 20:44:43 2013
@@ -19,7 +19,6 @@ package org.apache.ambari.server.control
import java.io.IOException;
import java.io.InputStream;
-import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -39,7 +38,7 @@ import org.slf4j.LoggerFactory;
/**
* Property provider that is used to read HTTP data from another server.
*/
-public class HttpProxyPropertyProvider implements PropertyProvider {
+public class HttpProxyPropertyProvider extends BaseProvider implements PropertyProvider {
protected final static Logger LOG =
LoggerFactory.getLogger(HttpProxyPropertyProvider.class);
@@ -59,19 +58,17 @@ public class HttpProxyPropertyProvider i
private String hostNamePropertyId = null;
private String componentNamePropertyId = null;
- private Set<String> propertyIds = new HashSet<String>();
-
public HttpProxyPropertyProvider(
StreamProvider stream,
String clusterNamePropertyId,
String hostNamePropertyId,
String componentNamePropertyId) {
+
+ super(new HashSet<String>(MAPPINGS.values()));
this.streamProvider = stream;
this.clusterNamePropertyId = clusterNamePropertyId;
this.hostNamePropertyId = hostNamePropertyId;
this.componentNamePropertyId = componentNamePropertyId;
-
- propertyIds.addAll(MAPPINGS.values());
}
/**
@@ -82,7 +79,7 @@ public class HttpProxyPropertyProvider i
public Set<Resource> populateResources(Set<Resource> resources,
Request request, Predicate predicate) throws SystemException {
- Set<String> ids = PropertyHelper.getRequestPropertyIds(propertyIds, request, predicate);
+ Set<String> ids = getRequestPropertyIds(request, predicate);
if (0 == ids.size())
return resources;
@@ -107,21 +104,6 @@ public class HttpProxyPropertyProvider i
return resources;
}
- @Override
- public Set<String> getPropertyIds() {
- return propertyIds;
- }
-
- @Override
- public Set<String> checkPropertyIds(Set<String> propertyIds) {
- if (!this.propertyIds.containsAll(propertyIds)) {
- Set<String> unsupportedPropertyIds = new HashSet<String>(propertyIds);
- unsupportedPropertyIds.removeAll(this.propertyIds);
- return unsupportedPropertyIds;
- }
- return Collections.emptySet();
- }
-
private void getHttpResponse(Resource r, String url, String propertyIdToSet) {
InputStream in = null;
Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/PropertyPredicateVisitor.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/PropertyPredicateVisitor.java?rev=1459041&r1=1459040&r2=1459041&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/PropertyPredicateVisitor.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/PropertyPredicateVisitor.java Wed Mar 20 20:44:43 2013
@@ -21,6 +21,7 @@ package org.apache.ambari.server.control
import org.apache.ambari.server.controller.predicate.AlwaysPredicate;
import org.apache.ambari.server.controller.predicate.ArrayPredicate;
import org.apache.ambari.server.controller.predicate.BasePredicate;
+import org.apache.ambari.server.controller.predicate.CategoryPredicate;
import org.apache.ambari.server.controller.predicate.ComparisonPredicate;
import org.apache.ambari.server.controller.predicate.PropertyPredicate;
import org.apache.ambari.server.controller.predicate.PredicateVisitor;
@@ -58,6 +59,11 @@ public class PropertyPredicateVisitor im
//Do nothing
}
+ @Override
+ public void acceptCategoryPredicate(CategoryPredicate predicate) {
+ // Do nothing
+ }
+
// ----- accessors ---------------------------------------------------------
Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RequestResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RequestResourceProvider.java?rev=1459041&r1=1459040&r2=1459041&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RequestResourceProvider.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RequestResourceProvider.java Wed Mar 20 20:44:43 2013
@@ -40,7 +40,7 @@ import java.util.Set;
/**
* Resource provider for request resources.
*/
-class RequestResourceProvider extends ResourceProviderImpl{
+class RequestResourceProvider extends AbstractResourceProvider {
// ----- Property ID constants ---------------------------------------------
// Requests
@@ -78,7 +78,7 @@ class RequestResourceProvider extends Re
public Set<Resource> getResources(Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
- Set<String> requestedIds = PropertyHelper.getRequestPropertyIds(getPropertyIds(), request, predicate);
+ Set<String> requestedIds = getRequestPropertyIds(request, predicate);
Map<String, Object> predicateProperties = PredicateHelper.getProperties(predicate);
final RequestStatusRequest requestStatusRequest = getRequest(predicateProperties);
Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ResourceImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ResourceImpl.java?rev=1459041&r1=1459040&r2=1459041&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ResourceImpl.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ResourceImpl.java Wed Mar 20 20:44:43 2013
@@ -121,6 +121,25 @@ public class ResourceImpl implements Res
}
@Override
+ public void addCategory(String id) {
+ TreeNode<Map<String, Object>> node;
+ if (id != null) {
+ node = m_treeProperties.getChild(id);
+ if (node == null) {
+ String[] tokens = id.split("/");
+ node = m_treeProperties;
+ for (String t : tokens) {
+ TreeNode<Map<String, Object>> child = node.getChild(t);
+ if (child == null) {
+ child = node.addChild(new HashMap<String, Object>(), t);
+ }
+ node = child;
+ }
+ }
+ }
+ }
+
+ @Override
public Object getPropertyValue(String id) {
String category = PropertyHelper.getPropertyCategory(id);
TreeNode<Map<String, Object>> node = (category == null) ? m_treeProperties :