You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by tb...@apache.org on 2014/01/22 05:52:35 UTC
git commit: AMBARI-4376 - Convert Resource.Type enum to class
Updated Branches:
refs/heads/trunk 937bcbbbb -> a2d7c9e57
AMBARI-4376 - Convert Resource.Type enum to class
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/a2d7c9e5
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/a2d7c9e5
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/a2d7c9e5
Branch: refs/heads/trunk
Commit: a2d7c9e57cc8a652e408b1731236c00d8f8275bb
Parents: 937bcbb
Author: tbeerbower <tb...@hortonworks.com>
Authored: Tue Jan 21 22:22:00 2014 -0500
Committer: tbeerbower <tb...@hortonworks.com>
Committed: Tue Jan 21 23:50:55 2014 -0500
----------------------------------------------------------------------
.../resources/ResourceInstanceFactoryImpl.java | 2 +-
.../GSInstallerResourceProvider.java | 2 +-
.../AbstractControllerResourceProvider.java | 2 +-
.../internal/AbstractDRResourceProvider.java | 2 +-
.../internal/AbstractProviderModule.java | 198 ++++++++--------
.../internal/DefaultProviderModule.java | 2 +-
.../nagios/NagiosPropertyProvider.java | 2 +-
.../ambari/server/controller/spi/Resource.java | 235 ++++++++++++++++++-
.../controller/utilities/PropertyHelper.java | 55 +++--
.../internal/TestIvoryProviderModule.java | 2 +-
.../server/controller/spi/ResourceTest.java | 75 ++++++
11 files changed, 449 insertions(+), 128 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/a2d7c9e5/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ResourceInstanceFactoryImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ResourceInstanceFactoryImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ResourceInstanceFactoryImpl.java
index 1ab6682..de6307c 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ResourceInstanceFactoryImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ResourceInstanceFactoryImpl.java
@@ -53,7 +53,7 @@ public class ResourceInstanceFactoryImpl implements ResourceInstanceFactory {
ResourceDefinition resourceDefinition;
//todo: consider ResourceDependencyManager : Map<Resource.Type, ResourceDefinition>
- switch (type) {
+ switch (type.getInternalType()) {
case Cluster:
resourceDefinition = new ClusterResourceDefinition();
break;
http://git-wip-us.apache.org/repos/asf/ambari/blob/a2d7c9e5/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerResourceProvider.java
index 539978e..d403114 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerResourceProvider.java
@@ -216,7 +216,7 @@ public abstract class GSInstallerResourceProvider implements ResourceProvider {
*/
public static ResourceProvider getResourceProvider(Resource.Type type,
ClusterDefinition clusterDefinition) {
- switch (type) {
+ switch (type.getInternalType()) {
case Cluster:
return new GSInstallerClusterProvider(clusterDefinition);
case Service:
http://git-wip-us.apache.org/repos/asf/ambari/blob/a2d7c9e5/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractControllerResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractControllerResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractControllerResourceProvider.java
index c8699cc..c66ae65 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractControllerResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractControllerResourceProvider.java
@@ -90,7 +90,7 @@ public abstract class AbstractControllerResourceProvider extends AbstractResourc
Map<Resource.Type, String> keyPropertyIds,
AmbariManagementController managementController) {
- switch (type) {
+ switch (type.getInternalType()) {
case Cluster:
return new ClusterResourceProvider(propertyIds, keyPropertyIds, managementController);
case Service:
http://git-wip-us.apache.org/repos/asf/ambari/blob/a2d7c9e5/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractDRResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractDRResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractDRResourceProvider.java
index 9ac967e..95c64a8 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractDRResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractDRResourceProvider.java
@@ -77,7 +77,7 @@ public abstract class AbstractDRResourceProvider extends AbstractResourceProvide
Set<String> propertyIds,
Map<Resource.Type, String> keyPropertyIds,
IvoryService service) {
- switch (type) {
+ switch (type.getInternalType()) {
case DRFeed:
return new FeedResourceProvider(service, propertyIds, keyPropertyIds);
case DRTargetCluster:
http://git-wip-us.apache.org/repos/asf/ambari/blob/a2d7c9e5/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 77b7213..f39893c 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
@@ -330,104 +330,106 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource
PROPERTY_REQUEST_CONNECT_TIMEOUT, PROPERTY_REQUEST_READ_TIMEOUT,
configuration.getTruststorePath(), configuration.getTruststorePassword(), configuration.getTruststoreType());
- switch (type){
- case Cluster :
- providers.add(createGangliaReportPropertyProvider(
- type,
- streamProvider,
- ComponentSSLConfiguration.instance(),
- this,
- PropertyHelper.getPropertyId("Clusters", "cluster_name")));
- break;
- case Service:
- providers.add(new NagiosPropertyProvider(type,
- streamProvider,
- "ServiceInfo/cluster_name",
- "ServiceInfo/service_name"));
- break;
- case Host :
- providers.add(createGangliaHostPropertyProvider(
- type,
- streamProvider,
- ComponentSSLConfiguration.instance(),
- this,
- PropertyHelper.getPropertyId("Hosts", "cluster_name"),
- PropertyHelper.getPropertyId("Hosts", "host_name")
- ));
- providers.add(new NagiosPropertyProvider(type,
- streamProvider,
- "Hosts/cluster_name",
- "Hosts/host_name"));
- break;
- case Component : {
- // TODO as we fill out stack metric definitions, these can be phased out
- PropertyProvider jpp = createJMXPropertyProvider(
- type,
- streamProvider,
- this,
- PropertyHelper.getPropertyId("ServiceComponentInfo", "cluster_name"),
- null,
- PropertyHelper.getPropertyId("ServiceComponentInfo", "component_name"),
- PropertyHelper.getPropertyId("ServiceComponentInfo", "state"),
- Collections.singleton("STARTED"));
-
- PropertyProvider gpp = createGangliaComponentPropertyProvider(
- type,
- streamProvider,
- ComponentSSLConfiguration.instance(),
- this,
- PropertyHelper.getPropertyId("ServiceComponentInfo", "cluster_name"),
- PropertyHelper.getPropertyId("ServiceComponentInfo", "component_name"));
-
- providers.add(new StackDefinedPropertyProvider(
- type,
- this,
- this,
- streamProvider,
- PropertyHelper.getPropertyId("ServiceComponentInfo", "cluster_name"),
- null,
- PropertyHelper.getPropertyId("ServiceComponentInfo", "component_name"),
- PropertyHelper.getPropertyId("ServiceComponentInfo", "state"),
- jpp,
- gpp));
- }
- break;
- case HostComponent: {
- // TODO as we fill out stack metric definitions, these can be phased out
- PropertyProvider jpp = createJMXPropertyProvider(
- type,
- streamProvider,
- 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 = 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,
- streamProvider,
- PropertyHelper.getPropertyId("HostRoles", "cluster_name"),
- PropertyHelper.getPropertyId("HostRoles", "host_name"),
- PropertyHelper.getPropertyId("HostRoles", "component_name"),
- PropertyHelper.getPropertyId("HostRoles", "state"),
- jpp,
- gpp));
- }
- break;
- default :
- break;
+ if (type.isInternalType()) {
+ switch (type.getInternalType()) {
+ case Cluster:
+ providers.add(createGangliaReportPropertyProvider(
+ type,
+ streamProvider,
+ ComponentSSLConfiguration.instance(),
+ this,
+ PropertyHelper.getPropertyId("Clusters", "cluster_name")));
+ break;
+ case Service:
+ providers.add(new NagiosPropertyProvider(type,
+ streamProvider,
+ "ServiceInfo/cluster_name",
+ "ServiceInfo/service_name"));
+ break;
+ case Host:
+ providers.add(createGangliaHostPropertyProvider(
+ type,
+ streamProvider,
+ ComponentSSLConfiguration.instance(),
+ this,
+ PropertyHelper.getPropertyId("Hosts", "cluster_name"),
+ PropertyHelper.getPropertyId("Hosts", "host_name")
+ ));
+ providers.add(new NagiosPropertyProvider(type,
+ streamProvider,
+ "Hosts/cluster_name",
+ "Hosts/host_name"));
+ break;
+ case Component: {
+ // TODO as we fill out stack metric definitions, these can be phased out
+ PropertyProvider jpp = createJMXPropertyProvider(
+ type,
+ streamProvider,
+ this,
+ PropertyHelper.getPropertyId("ServiceComponentInfo", "cluster_name"),
+ null,
+ PropertyHelper.getPropertyId("ServiceComponentInfo", "component_name"),
+ PropertyHelper.getPropertyId("ServiceComponentInfo", "state"),
+ Collections.singleton("STARTED"));
+
+ PropertyProvider gpp = createGangliaComponentPropertyProvider(
+ type,
+ streamProvider,
+ ComponentSSLConfiguration.instance(),
+ this,
+ PropertyHelper.getPropertyId("ServiceComponentInfo", "cluster_name"),
+ PropertyHelper.getPropertyId("ServiceComponentInfo", "component_name"));
+
+ providers.add(new StackDefinedPropertyProvider(
+ type,
+ this,
+ this,
+ streamProvider,
+ PropertyHelper.getPropertyId("ServiceComponentInfo", "cluster_name"),
+ null,
+ PropertyHelper.getPropertyId("ServiceComponentInfo", "component_name"),
+ PropertyHelper.getPropertyId("ServiceComponentInfo", "state"),
+ jpp,
+ gpp));
+ }
+ break;
+ case HostComponent: {
+ // TODO as we fill out stack metric definitions, these can be phased out
+ PropertyProvider jpp = createJMXPropertyProvider(
+ type,
+ streamProvider,
+ 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 = 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,
+ streamProvider,
+ PropertyHelper.getPropertyId("HostRoles", "cluster_name"),
+ PropertyHelper.getPropertyId("HostRoles", "host_name"),
+ PropertyHelper.getPropertyId("HostRoles", "component_name"),
+ PropertyHelper.getPropertyId("HostRoles", "state"),
+ jpp,
+ gpp));
+ }
+ break;
+ default:
+ break;
+ }
}
putPropertyProviders(type, providers);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/a2d7c9e5/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java
index 5d07eb5..a10835e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java
@@ -54,7 +54,7 @@ public class DefaultProviderModule extends AbstractProviderModule {
Set<String> propertyIds = PropertyHelper.getPropertyIds(type);
Map<Resource.Type,String> keyPropertyIds = PropertyHelper.getKeyPropertyIds(type);
- switch (type) {
+ switch (type.getInternalType()) {
case Workflow:
return new WorkflowResourceProvider(propertyIds, keyPropertyIds);
case Job:
http://git-wip-us.apache.org/repos/asf/ambari/blob/a2d7c9e5/ambari-server/src/main/java/org/apache/ambari/server/controller/nagios/NagiosPropertyProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/nagios/NagiosPropertyProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/nagios/NagiosPropertyProvider.java
index 0fcb549..79222af 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/nagios/NagiosPropertyProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/nagios/NagiosPropertyProvider.java
@@ -179,7 +179,7 @@ public class NagiosPropertyProvider extends BaseProvider implements PropertyProv
for (NagiosAlert alert : allAlerts) {
boolean match = false;
- switch (resourceType) {
+ switch (resourceType.getInternalType()) {
case Service:
match = alert.getService().equals(matchValue);
break;
http://git-wip-us.apache.org/repos/asf/ambari/blob/a2d7c9e5/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/Resource.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/Resource.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/Resource.java
index 2081766..6a82e59 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/Resource.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/Resource.java
@@ -19,6 +19,7 @@
package org.apache.ambari.server.controller.spi;
+import java.util.LinkedHashMap;
import java.util.Map;
/**
@@ -66,10 +67,13 @@ public interface Resource {
*/
public Object getPropertyValue(String id);
+
+ // ----- Enum : InternalType -----------------------------------------------
+
/**
- * Resource types.
+ * Enum of internal types.
*/
- public enum Type {
+ public enum InternalType {
Cluster,
Service,
Host,
@@ -97,6 +101,231 @@ public interface Resource {
TaskAttempt,
RootService,
RootServiceComponent,
- RootServiceHostComponent
+ RootServiceHostComponent;
+
+ /**
+ * Get the {@link Type} that corresponds to this InternalType.
+ *
+ * @return the corresponding type.
+ */
+ private Type getType() {
+ String name = name();
+ Type type = Type.getType(name);
+ return type == null ? new Type(name(), ordinal()) : type;
+ }
+ }
+
+
+ // ----- Inner class : Type ------------------------------------------------
+
+ /**
+ * Resource types. Allows for the addition of external types.
+ */
+ public final class Type implements Comparable<Type>{
+
+ /**
+ * Map of all registered types.
+ */
+ private static Map<String, Type> types = new LinkedHashMap<String, Type>();
+
+ /**
+ * Ordinal number counter for registering external types.
+ */
+ private static int nextOrdinal = 10000;
+
+ /**
+ * Internal types. See {@link InternalType}.
+ */
+ public static final Type Cluster = InternalType.Cluster.getType();
+ public static final Type Service = InternalType.Service.getType();
+ public static final Type Host = InternalType.Host.getType();
+ public static final Type Component = InternalType.Component.getType();
+ public static final Type HostComponent = InternalType.HostComponent.getType();
+ public static final Type Configuration = InternalType.Configuration.getType();
+ public static final Type ConfigGroup = InternalType.ConfigGroup.getType();
+ public static final Type Action = InternalType.Action.getType();
+ public static final Type Request = InternalType.Request.getType();
+ public static final Type RequestSchedule = InternalType.RequestSchedule.getType();
+ public static final Type Task = InternalType.Task.getType();
+ public static final Type User = InternalType.User.getType();
+ public static final Type Stack = InternalType.Stack.getType();
+ public static final Type StackVersion = InternalType.StackVersion.getType();
+ public static final Type OperatingSystem = InternalType.OperatingSystem.getType();
+ public static final Type Repository = InternalType.Repository.getType();
+ public static final Type StackService = InternalType.StackService.getType();
+ public static final Type StackConfiguration = InternalType.StackConfiguration.getType();
+ public static final Type StackServiceComponent = InternalType.StackServiceComponent.getType();
+ public static final Type DRFeed = InternalType.DRFeed.getType();
+ public static final Type DRTargetCluster = InternalType.DRTargetCluster.getType();
+ public static final Type DRInstance = InternalType.DRInstance.getType();
+ public static final Type Workflow = InternalType.Workflow.getType();
+ public static final Type Job = InternalType.Job.getType();
+ public static final Type TaskAttempt = InternalType.TaskAttempt.getType();
+ public static final Type RootService = InternalType.RootService.getType();
+ public static final Type RootServiceComponent = InternalType.RootServiceComponent.getType();
+ public static final Type RootServiceHostComponent = InternalType.RootServiceHostComponent.getType();
+
+ /**
+ * The type name.
+ */
+ private final String name;
+
+ /**
+ * The type ordinal value.
+ */
+ private final int ordinal;
+
+
+ // ----- Constructors ----------------------------------------------------
+
+ /**
+ * Construct an internal type.
+ *
+ * @param name the type name
+ * @param ordinal the ordinal number
+ */
+ private Type(String name, int ordinal) {
+ assert(name != null);
+
+ this.name = name;
+ this.ordinal = ordinal;
+
+ setType(name, this);
+ }
+
+ /**
+ * Construct an extended type.
+ *
+ * @param name the type name
+ */
+ public Type(String name) {
+ this(name, getNextOrdinal());
+ }
+
+
+ // ----- Resource.Type ---------------------------------------------------
+
+ /**
+ * Get the ordinal number for this type.
+ *
+ * @return the ordinal number
+ */
+ public final int ordinal() {
+ return ordinal;
+ }
+
+ /**
+ * Get the name for this type.
+ *
+ * @return the name
+ */
+ public String name() {
+ return name;
+ }
+
+ /**
+ * Indicate whether this is an internal type.
+ *
+ * @return true if this is an internal type; false otherwise
+ */
+ public boolean isInternalType() {
+ return ordinal < InternalType.values().length;
+ }
+
+ /**
+ * Get the internal type enum associated with this type.
+ *
+ * @return the internal type enum
+ *
+ * @throws UnsupportedOperationException if this type is not an internal type
+ */
+ public InternalType getInternalType() {
+ if (isInternalType()) {
+ return InternalType.values()[ordinal];
+ }
+ throw new UnsupportedOperationException(name + " is not an internal type.");
+ }
+
+ /**
+ * Get the type associated with the given type name.
+ *
+ * @param name the type name
+ *
+ * @return the associated type
+ *
+ * @throws IllegalArgumentException if the given type name is not associated with any known type
+ */
+ public static Type valueOf(String name) {
+ Type type = types.get(name);
+ if (type == null) {
+ throw new IllegalArgumentException(name + " is not a type.");
+ }
+ return type;
+ }
+
+ /**
+ * Get all of the known types.
+ *
+ * @return all of the types
+ */
+ public static Type[] values() {
+ return types.values().toArray(new Type[types.size()]);
+ }
+
+
+ // ----- Object overrides ------------------------------------------------
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ Type type = (Type) o;
+
+ return ordinal == type.ordinal && name.equals(type.name);
+ }
+
+ @Override
+ public int hashCode() {
+ int result = name.hashCode();
+ result = 31 * result + ordinal;
+ return result;
+ }
+
+ @Override
+ protected Object clone() throws CloneNotSupportedException {
+ throw new CloneNotSupportedException();
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+
+
+ // ----- Comparable<Type> ------------------------------------------------
+
+ @Override
+ public int compareTo(Type type) {
+ return ordinal - type.ordinal();
+ }
+
+
+ // ----- helper methods --------------------------------------------------
+
+ // get the next ordinal number
+ private static synchronized int getNextOrdinal() {
+ return nextOrdinal++;
+ }
+
+ // register the type by name
+ private static synchronized void setType(String name, Type type) {
+ types.put(name, type);
+ }
+
+ // get the type for the given name; null if not present
+ private static Type getType(String name) {
+ return types.get(name);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/a2d7c9e5/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/PropertyHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/PropertyHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/PropertyHelper.java
index 7ba1522..efc7ee4 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/PropertyHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/PropertyHelper.java
@@ -46,10 +46,10 @@ public class PropertyHelper {
private static final String KEY_PROPERTIES_FILE = "key_properties.json";
private static final char EXTERNAL_PATH_SEP = '/';
- private static final Map<Resource.Type, Set<String>> PROPERTY_IDS = readPropertyIds(PROPERTIES_FILE);
- private static final Map<Resource.Type, Map<String, Map<String, PropertyInfo>>> JMX_PROPERTY_IDS = readPropertyProviderIds(JMX_PROPERTIES_FILE);
- private static final Map<Resource.Type, Map<String, Map<String, PropertyInfo>>> GANGLIA_PROPERTY_IDS = readPropertyProviderIds(GANGLIA_PROPERTIES_FILE);
- private static final Map<Resource.Type, Map<Resource.Type, String>> KEY_PROPERTY_IDS = readKeyPropertyIds(KEY_PROPERTIES_FILE);
+ private static final Map<Resource.InternalType, Set<String>> PROPERTY_IDS = readPropertyIds(PROPERTIES_FILE);
+ private static final Map<Resource.InternalType, Map<String, Map<String, PropertyInfo>>> JMX_PROPERTY_IDS = readPropertyProviderIds(JMX_PROPERTIES_FILE);
+ private static final Map<Resource.InternalType, Map<String, Map<String, PropertyInfo>>> GANGLIA_PROPERTY_IDS = readPropertyProviderIds(GANGLIA_PROPERTIES_FILE);
+ private static final Map<Resource.InternalType, Map<Resource.Type, String>> KEY_PROPERTY_IDS = readKeyPropertyIds(KEY_PROPERTIES_FILE);
/**
* Regular expression to check for replacement arguments (e.g. $1) in a property id.
@@ -58,7 +58,7 @@ public class PropertyHelper {
public static String getPropertyId(String category, String name) {
String propertyId = (category == null || category.isEmpty())? name :
- (name == null || name.isEmpty()) ? category : category + EXTERNAL_PATH_SEP + name;
+ (name == null || name.isEmpty()) ? category : category + EXTERNAL_PATH_SEP + name;
if (propertyId.endsWith("/")) {
propertyId = propertyId.substring(0, propertyId.length() - 1);
@@ -68,7 +68,7 @@ public class PropertyHelper {
public static Set<String> getPropertyIds(Resource.Type resourceType) {
- Set<String> propertyIds = PROPERTY_IDS.get(resourceType);
+ Set<String> propertyIds = PROPERTY_IDS.get(resourceType.getInternalType());
return propertyIds == null ? Collections.<String>emptySet() : propertyIds;
}
@@ -89,15 +89,15 @@ public class PropertyHelper {
}
public static Map<String, Map<String, PropertyInfo>> getGangliaPropertyIds(Resource.Type resourceType) {
- return GANGLIA_PROPERTY_IDS.get(resourceType);
+ return GANGLIA_PROPERTY_IDS.get(resourceType.getInternalType());
}
public static Map<String, Map<String, PropertyInfo>> getJMXPropertyIds(Resource.Type resourceType) {
- return JMX_PROPERTY_IDS.get(resourceType);
+ return JMX_PROPERTY_IDS.get(resourceType.getInternalType());
}
public static Map<Resource.Type, String> getKeyPropertyIds(Resource.Type resourceType) {
- return KEY_PROPERTY_IDS.get(resourceType);
+ return KEY_PROPERTY_IDS.get(resourceType.getInternalType());
}
/**
@@ -302,18 +302,18 @@ public class PropertyHelper {
return new RequestImpl(null, Collections.singleton(properties), requestInfoProperties, null);
}
- private static Map<Resource.Type, Map<String, Map<String, PropertyInfo>>> readPropertyProviderIds(String filename) {
+ private static Map<Resource.InternalType, Map<String, Map<String, PropertyInfo>>> readPropertyProviderIds(String filename) {
ObjectMapper mapper = new ObjectMapper();
try {
- Map<Resource.Type, Map<String, Map<String, Metric>>> resourceMetricMap =
+ Map<Resource.InternalType, Map<String, Map<String, Metric>>> resourceMetricMap =
mapper.readValue(ClassLoader.getSystemResourceAsStream(filename),
- new TypeReference<Map<Resource.Type, Map<String, Map<String, Metric>>>>() {});
+ new TypeReference<Map<Resource.InternalType, Map<String, Map<String, Metric>>>>() {});
- Map<Resource.Type, Map<String, Map<String, PropertyInfo>>> resourceMetrics =
- new HashMap<Resource.Type, Map<String, Map<String, PropertyInfo>>>();
+ Map<Resource.InternalType, Map<String, Map<String, PropertyInfo>>> resourceMetrics =
+ new HashMap<Resource.InternalType, Map<String, Map<String, PropertyInfo>>>();
- for (Map.Entry<Resource.Type, Map<String, Map<String, Metric>>> resourceEntry : resourceMetricMap.entrySet()) {
+ for (Map.Entry<Resource.InternalType, Map<String, Map<String, Metric>>> resourceEntry : resourceMetricMap.entrySet()) {
Map<String, Map<String, PropertyInfo>> componentMetrics = new HashMap<String, Map<String, PropertyInfo>>();
for (Map.Entry<String, Map<String, Metric>> componentEntry : resourceEntry.getValue().entrySet()) {
@@ -335,23 +335,38 @@ public class PropertyHelper {
}
}
- private static Map<Resource.Type, Set<String>> readPropertyIds(String filename) {
+ private static Map<Resource.InternalType, Set<String>> readPropertyIds(String filename) {
ObjectMapper mapper = new ObjectMapper();
try {
- return mapper.readValue(ClassLoader.getSystemResourceAsStream(filename), new TypeReference<Map<Resource.Type, Set<String>>>() {
+ return mapper.readValue(ClassLoader.getSystemResourceAsStream(filename), new TypeReference<Map<Resource.InternalType, Set<String>>>() {
});
} catch (IOException e) {
throw new IllegalStateException("Can't read properties file " + filename, e);
}
}
- private static Map<Resource.Type, Map<Resource.Type, String>> readKeyPropertyIds(String filename) {
+ private static Map<Resource.InternalType, Map<Resource.Type, String>> readKeyPropertyIds(String filename) {
ObjectMapper mapper = new ObjectMapper();
try {
- return mapper.readValue(ClassLoader.getSystemResourceAsStream(filename), new TypeReference<Map<Resource.Type, Map<Resource.Type, String>>>() {
- });
+ Map<Resource.InternalType, Map<Resource.InternalType, String>> map =
+ mapper.readValue(ClassLoader.getSystemResourceAsStream(filename),
+ new TypeReference<Map<Resource.InternalType, Map<Resource.InternalType, String>>>() {});
+
+ Map<Resource.InternalType, Map<Resource.Type, String>> returnMap =
+ new HashMap<Resource.InternalType, Map<Resource.Type, String>>();
+
+ // convert inner maps from InternalType to Type
+ for (Map.Entry<Resource.InternalType, Map<Resource.InternalType, String>> entry : map.entrySet()) {
+ Map<Resource.Type, String> innerMap = new HashMap<Resource.Type, String>();
+
+ for (Map.Entry<Resource.InternalType, String> entry1 : entry.getValue().entrySet()) {
+ innerMap.put(Resource.Type.values()[entry1.getKey().ordinal()], entry1.getValue());
+ }
+ returnMap.put(entry.getKey(), innerMap);
+ }
+ return returnMap;
} catch (IOException e) {
throw new IllegalStateException("Can't read properties file " + filename, e);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/a2d7c9e5/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/TestIvoryProviderModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/TestIvoryProviderModule.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/TestIvoryProviderModule.java
index 6f77528..801ed24 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/TestIvoryProviderModule.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/TestIvoryProviderModule.java
@@ -38,7 +38,7 @@ public class TestIvoryProviderModule extends DefaultProviderModule{
Set<String> propertyIds = PropertyHelper.getPropertyIds(type);
Map<Resource.Type,String> keyPropertyIds = PropertyHelper.getKeyPropertyIds(type);
- switch (type) {
+ switch (type.getInternalType()) {
case DRFeed:
return new FeedResourceProvider(service, propertyIds, keyPropertyIds);
case DRTargetCluster:
http://git-wip-us.apache.org/repos/asf/ambari/blob/a2d7c9e5/ambari-server/src/test/java/org/apache/ambari/server/controller/spi/ResourceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/spi/ResourceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/spi/ResourceTest.java
new file mode 100644
index 0000000..2ab5be1
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/spi/ResourceTest.java
@@ -0,0 +1,75 @@
+/**
+ * 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.spi;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Resource tests.
+ */
+public class ResourceTest {
+ @Test
+ public void testResource() {
+
+ for (Resource.InternalType internalType : Resource.InternalType.values()) {
+ Resource.Type type= null;
+ try {
+ type = Resource.Type.valueOf(internalType.name());
+ } catch (IllegalArgumentException e) {
+ Assert.fail("Resource.Type should be defined for internal type " + internalType.name() + ".");
+ }
+ Assert.assertEquals(type.name(), internalType.name());
+ Assert.assertEquals(type.ordinal(), internalType.ordinal());
+ }
+
+ Resource.Type newType = new Resource.Type("newType");
+ Resource.Type newType2 = new Resource.Type("newType2");
+
+ Assert.assertFalse(newType.equals(newType2));
+ Assert.assertFalse(newType2.equals(newType));
+
+ Assert.assertEquals("newType", newType.name());
+
+ Assert.assertFalse(newType.isInternalType());
+
+ try {
+ newType.getInternalType();
+ Assert.fail("Can't get internal type for a extended resource.");
+ } catch (UnsupportedOperationException e) {
+ //Expected
+ }
+
+ Resource.Type t1 = Resource.Type.valueOf("newType");
+ Resource.Type t2 = Resource.Type.valueOf("newType2");
+ Assert.assertTrue(newType.equals(t1));
+ Assert.assertTrue(t1.equals(newType));
+ Assert.assertTrue(newType2.equals(t2));
+ Assert.assertTrue(t2.equals(newType2));
+ Assert.assertFalse(t1.equals(newType2));
+ Assert.assertFalse(t2.equals(newType));
+
+ try {
+ Resource.Type.valueOf("badType");
+ Assert.fail("Expected IllegalArgumentException.");
+ } catch (IllegalArgumentException e) {
+ //Expected
+ }
+ }
+}