ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tbeerbo...@apache.org
Subject git commit: AMBARI-4375 : Ambari-SCOM : Remove Resource.Type switch statements.
Date Tue, 21 Jan 2014 21:22:37 GMT
Updated Branches:
  refs/heads/trunk 6ddd861cd -> c41796157


AMBARI-4375 : Ambari-SCOM : Remove Resource.Type switch statements.


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/c4179615
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/c4179615
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/c4179615

Branch: refs/heads/trunk
Commit: c417961570d98f05709fce07526a4b74cfaf8d64
Parents: 6ddd861
Author: tbeerbower <tbeerbower@hortonworks.com>
Authored: Tue Jan 21 13:17:21 2014 -0500
Committer: tbeerbower <tbeerbower@hortonworks.com>
Committed: Tue Jan 21 16:22:11 2014 -0500

----------------------------------------------------------------------
 .../ambari/msi/AbstractResourceProvider.java    | 33 ++++----
 .../apache/ambari/scom/SQLProviderModule.java   | 79 +++++++++-----------
 .../msi/AbstractResourceProviderTest.java       | 62 +++++++++++++++
 3 files changed, 114 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/c4179615/contrib/ambari-scom/ambari-scom-server/src/main/java/org/apache/ambari/msi/AbstractResourceProvider.java
----------------------------------------------------------------------
diff --git a/contrib/ambari-scom/ambari-scom-server/src/main/java/org/apache/ambari/msi/AbstractResourceProvider.java
b/contrib/ambari-scom/ambari-scom-server/src/main/java/org/apache/ambari/msi/AbstractResourceProvider.java
index 489063f..5d7e3db 100644
--- a/contrib/ambari-scom/ambari-scom-server/src/main/java/org/apache/ambari/msi/AbstractResourceProvider.java
+++ b/contrib/ambari-scom/ambari-scom-server/src/main/java/org/apache/ambari/msi/AbstractResourceProvider.java
@@ -252,23 +252,22 @@ public abstract class AbstractResourceProvider implements ResourceProvider
{
    */
   public static ResourceProvider getResourceProvider(Resource.Type type,
                                                      ClusterDefinition clusterDefinition)
{
-    switch (type) {
-      case Cluster:
-        return new ClusterProvider(clusterDefinition);
-      case Service:
-        return new ServiceProvider(clusterDefinition);
-      case Component:
-        return new ComponentProvider(clusterDefinition);
-      case Host:
-        return new HostProvider(clusterDefinition);
-      case HostComponent:
-        return new HostComponentProvider(clusterDefinition);
-      case Request:
-        return new RequestProvider(clusterDefinition);
-      case Task:
-        return new TaskProvider(clusterDefinition);
-      default:
-        return new NoOpProvider(type, clusterDefinition);
+    if (type.equals(Resource.Type.Cluster)) {
+      return new ClusterProvider(clusterDefinition);
+    } else if (type.equals(Resource.Type.Service)) {
+      return new ServiceProvider(clusterDefinition);
+    } else if (type.equals(Resource.Type.Component)) {
+      return new ComponentProvider(clusterDefinition);
+    } else if (type.equals(Resource.Type.Host)) {
+      return new HostProvider(clusterDefinition);
+    } else if (type.equals(Resource.Type.HostComponent)) {
+      return new HostComponentProvider(clusterDefinition);
+    } else if (type.equals(Resource.Type.Request)) {
+      return new RequestProvider(clusterDefinition);
+    } else if (type.equals(Resource.Type.Task)) {
+      return new TaskProvider(clusterDefinition);
+    } else {
+      return new NoOpProvider(type, clusterDefinition);
     }
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c4179615/contrib/ambari-scom/ambari-scom-server/src/main/java/org/apache/ambari/scom/SQLProviderModule.java
----------------------------------------------------------------------
diff --git a/contrib/ambari-scom/ambari-scom-server/src/main/java/org/apache/ambari/scom/SQLProviderModule.java
b/contrib/ambari-scom/ambari-scom-server/src/main/java/org/apache/ambari/scom/SQLProviderModule.java
index 82217c8..439ac00 100644
--- a/contrib/ambari-scom/ambari-scom-server/src/main/java/org/apache/ambari/scom/SQLProviderModule.java
+++ b/contrib/ambari-scom/ambari-scom-server/src/main/java/org/apache/ambari/scom/SQLProviderModule.java
@@ -100,49 +100,42 @@ public class SQLProviderModule extends DefaultProviderModule implements
HostInfo
 
     List<PropertyProvider> providers = new LinkedList<PropertyProvider>();
 
-    switch (type) {
-      case Component:
-
-        providers.add(new JMXPropertyProvider(
-            PropertyHelper.getJMXPropertyIds(type),
-            urlStreamProvider,
-            this,
-            PropertyHelper.getPropertyId("ServiceComponentInfo", "cluster_name"),
-            null,
-            PropertyHelper.getPropertyId("ServiceComponentInfo", "component_name"),
-            PropertyHelper.getPropertyId("ServiceComponentInfo", "state"),
-            Collections.singleton("STARTED")));
-
-        providers.add(new SQLPropertyProvider(
-            PropertyHelper.getGangliaPropertyIds(type),
-            this,
-            PropertyHelper.getPropertyId("ServiceComponentInfo", "cluster_name"),
-            null,
-            PropertyHelper.getPropertyId("ServiceComponentInfo", "component_name"),
-            connectionFactory));
-        break;
-      case HostComponent:
-
-        providers.add(new JMXPropertyProvider(
-            PropertyHelper.getJMXPropertyIds(type),
-            urlStreamProvider,
-            this,
-            PropertyHelper.getPropertyId("HostRoles", "cluster_name"),
-            PropertyHelper.getPropertyId("HostRoles", "host_name"),
-            PropertyHelper.getPropertyId("HostRoles", "component_name"),
-            PropertyHelper.getPropertyId("HostRoles", "state"),
-            Collections.singleton("STARTED")));
-
-        providers.add(new SQLPropertyProvider(
-            PropertyHelper.getGangliaPropertyIds(type),
-            this,
-            PropertyHelper.getPropertyId("HostRoles", "cluster_name"),
-            PropertyHelper.getPropertyId("HostRoles", "host_name"),
-            PropertyHelper.getPropertyId("HostRoles", "component_name"),
-            connectionFactory));
-        break;
-      default:
-        break;
+    if (type.equals(Resource.Type.Component)) {
+      providers.add(new JMXPropertyProvider(
+          PropertyHelper.getJMXPropertyIds(type),
+          urlStreamProvider,
+          this,
+          PropertyHelper.getPropertyId("ServiceComponentInfo", "cluster_name"),
+          null,
+          PropertyHelper.getPropertyId("ServiceComponentInfo", "component_name"),
+          PropertyHelper.getPropertyId("ServiceComponentInfo", "state"),
+          Collections.singleton("STARTED")));
+
+      providers.add(new SQLPropertyProvider(
+          PropertyHelper.getGangliaPropertyIds(type),
+          this,
+          PropertyHelper.getPropertyId("ServiceComponentInfo", "cluster_name"),
+          null,
+          PropertyHelper.getPropertyId("ServiceComponentInfo", "component_name"),
+          connectionFactory));
+    } else if (type.equals(Resource.Type.HostComponent)) {
+      providers.add(new JMXPropertyProvider(
+          PropertyHelper.getJMXPropertyIds(type),
+          urlStreamProvider,
+          this,
+          PropertyHelper.getPropertyId("HostRoles", "cluster_name"),
+          PropertyHelper.getPropertyId("HostRoles", "host_name"),
+          PropertyHelper.getPropertyId("HostRoles", "component_name"),
+          PropertyHelper.getPropertyId("HostRoles", "state"),
+          Collections.singleton("STARTED")));
+
+      providers.add(new SQLPropertyProvider(
+          PropertyHelper.getGangliaPropertyIds(type),
+          this,
+          PropertyHelper.getPropertyId("HostRoles", "cluster_name"),
+          PropertyHelper.getPropertyId("HostRoles", "host_name"),
+          PropertyHelper.getPropertyId("HostRoles", "component_name"),
+          connectionFactory));
     }
     putPropertyProviders(type, providers);
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c4179615/contrib/ambari-scom/ambari-scom-server/src/test/java/org/apache/ambari/msi/AbstractResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/contrib/ambari-scom/ambari-scom-server/src/test/java/org/apache/ambari/msi/AbstractResourceProviderTest.java
b/contrib/ambari-scom/ambari-scom-server/src/test/java/org/apache/ambari/msi/AbstractResourceProviderTest.java
new file mode 100644
index 0000000..f4e2446
--- /dev/null
+++ b/contrib/ambari-scom/ambari-scom-server/src/test/java/org/apache/ambari/msi/AbstractResourceProviderTest.java
@@ -0,0 +1,62 @@
+/**
+ * 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.msi;
+
+import org.apache.ambari.scom.TestClusterDefinitionProvider;
+import org.apache.ambari.scom.TestHostInfoProvider;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.spi.ResourceProvider;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * AbstractResourceProvider tests.
+ */
+public class AbstractResourceProviderTest {
+
+  private static Set<Resource.Type> types = new HashSet<Resource.Type>();
+  static {
+    types.add(Resource.Type.Cluster);
+    types.add(Resource.Type.Service);
+    types.add(Resource.Type.Component);
+    types.add(Resource.Type.Host);
+    types.add(Resource.Type.HostComponent);
+    types.add(Resource.Type.Request);
+    types.add(Resource.Type.Task);
+  }
+
+  @Test
+  public void testGetResourceProvider() throws Exception {
+    ClusterDefinition clusterDefinition = new ClusterDefinition(new TestStateProvider(),
new TestClusterDefinitionProvider(), new TestHostInfoProvider());
+    clusterDefinition.setServiceState("HDFS", "INSTALLED");
+
+    for (Resource.Type type : types) {
+      ResourceProvider provider = AbstractResourceProvider.getResourceProvider(type, clusterDefinition);
+      Set<Resource> resources = provider.getResources(PropertyHelper.getReadRequest(),
null);
+
+      for (Resource resource : resources) {
+        Assert.assertEquals(type, resource.getType());
+      }
+    }
+  }
+}


Mime
View raw message