ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yus...@apache.org
Subject git commit: AMBARI-3987 - Resource providers are set with wrong stack version.
Date Thu, 05 Dec 2013 22:12:53 GMT
Updated Branches:
  refs/heads/branch-1.4.1 6696a62e7 -> ba83fbf7f


AMBARI-3987 - Resource providers are set with wrong stack version.


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

Branch: refs/heads/branch-1.4.1
Commit: ba83fbf7f7a5219fd287128799bbed1b8b75bc96
Parents: 6696a62
Author: tbeerbower <tbeerbower@hortonworks.com>
Authored: Thu Dec 5 10:41:24 2013 -0500
Committer: Yusaku Sako <yusaku@hortonworks.com>
Committed: Thu Dec 5 14:12:33 2013 -0800

----------------------------------------------------------------------
 .../internal/AbstractProviderModule.java        |  27 ++++-
 .../internal/AbstractProviderModuleTest.java    | 121 +++++++++++++++++++
 2 files changed, 144 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/ba83fbf7/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 0f392d0..4011f4d 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
@@ -43,11 +43,12 @@ import org.apache.ambari.server.state.DesiredConfig;
 import org.apache.ambari.server.state.HostState;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.State;
-import org.apache.commons.collections.CollectionUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
  * An abstract provider module implementation.
@@ -315,6 +316,18 @@ public abstract class AbstractProviderModule implements ProviderModule,
Resource
 
   // ----- utility methods ---------------------------------------------------
 
+  /**
+   * Get the metrics version for the given cluster name.
+   *
+   * @param clusterName  the cluster name
+   *
+   * @return the metrics version for the given cluster name
+   */
+  protected PropertyHelper.MetricsVersion getMetricsVersion(String clusterName) {
+    updateClusterVersion();
+    return clusterVersionsMap.get(clusterName);
+  }
+
   protected abstract ResourceProvider createResourceProvider(Resource.Type type);
 
   protected void registerResourceProvider(Resource.Type type) {
@@ -444,9 +457,15 @@ public abstract class AbstractProviderModule implements ProviderModule,
Resource
 
         for (Resource cluster : clusters) {
           String clusterVersion = (String) cluster.getPropertyValue(CLUSTER_VERSION_PROPERTY_ID);
-
-          PropertyHelper.MetricsVersion version =  clusterVersion.startsWith("HDP-1") ?
-              PropertyHelper.MetricsVersion.HDP1 : PropertyHelper.MetricsVersion.HDP2;
+          PropertyHelper.MetricsVersion version = PropertyHelper.MetricsVersion.HDP2;
+
+          Matcher m = Pattern.compile("[0-9]+(\\.[0-9]+)+").matcher(clusterVersion);
+          if (m.find()) {
+            clusterVersion = m.group(0);
+            if (clusterVersion.equals("1") || clusterVersion.startsWith("1.")) {
+              version = PropertyHelper.MetricsVersion.HDP1;
+            }
+          }
 
           clusterVersionsMap.put(
               (String) cluster.getPropertyValue(CLUSTER_NAME_PROPERTY_ID),

http://git-wip-us.apache.org/repos/asf/ambari/blob/ba83fbf7/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AbstractProviderModuleTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AbstractProviderModuleTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AbstractProviderModuleTest.java
new file mode 100644
index 0000000..36410c9
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AbstractProviderModuleTest.java
@@ -0,0 +1,121 @@
+package org.apache.ambari.server.controller.internal;
+
+import org.apache.ambari.server.controller.spi.NoSuchParentResourceException;
+import org.apache.ambari.server.controller.spi.NoSuchResourceException;
+import org.apache.ambari.server.controller.spi.Predicate;
+import org.apache.ambari.server.controller.spi.Request;
+import org.apache.ambari.server.controller.spi.RequestStatus;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.spi.ResourceAlreadyExistsException;
+import org.apache.ambari.server.controller.spi.ResourceProvider;
+import org.apache.ambari.server.controller.spi.SystemException;
+import org.apache.ambari.server.controller.spi.UnsupportedPropertyException;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * AbstractProviderModule tests.
+ */
+public class AbstractProviderModuleTest {
+  @Test
+  public void testGetMetricsVersion() throws Exception {
+
+    TestAbstractProviderModule module = new TestAbstractProviderModule("HDP-1.0");
+    PropertyHelper.MetricsVersion version = module.getMetricsVersion("c1");
+    Assert.assertEquals(PropertyHelper.MetricsVersion.HDP1, version);
+    version = module.getMetricsVersion("c2");
+    Assert.assertNull(version);
+
+    module = new TestAbstractProviderModule("HDPLocal-1.3.2");
+    version = module.getMetricsVersion("c1");
+    Assert.assertEquals(PropertyHelper.MetricsVersion.HDP1, version);
+
+    module = new TestAbstractProviderModule("HDP-2.0.1");
+    version = module.getMetricsVersion("c1");
+    Assert.assertEquals(PropertyHelper.MetricsVersion.HDP2, version);
+
+    module = new TestAbstractProviderModule("HDP-2.0.1.x");
+    version = module.getMetricsVersion("c1");
+    Assert.assertEquals(PropertyHelper.MetricsVersion.HDP2, version);
+
+    module = new TestAbstractProviderModule("HDP-9.9.9");
+    version = module.getMetricsVersion("c1");
+    Assert.assertEquals(PropertyHelper.MetricsVersion.HDP2, version);
+
+    module = new TestAbstractProviderModule("HDPLocal-2.0.0");
+    version = module.getMetricsVersion("c1");
+    Assert.assertEquals(PropertyHelper.MetricsVersion.HDP2, version);
+  }
+
+  private static class TestAbstractProviderModule extends AbstractProviderModule {
+    private final String clusterVersion;
+
+    private TestAbstractProviderModule(String clusterVersion) {
+      this.clusterVersion = clusterVersion;
+    }
+
+    @Override
+    protected ResourceProvider createResourceProvider(Resource.Type type) {
+      return new TestResourceProvider(type, clusterVersion);
+    }
+  }
+
+  private static class TestResourceProvider implements ResourceProvider {
+    private final Resource.Type type;
+    private final String clusterVersion;
+
+    private TestResourceProvider(Resource.Type type, String clusterVersion) {
+      this.type = type;
+      this.clusterVersion = clusterVersion;
+    }
+
+    @Override
+    public RequestStatus createResources(Request request)
+        throws SystemException, UnsupportedPropertyException,
+        ResourceAlreadyExistsException, NoSuchParentResourceException {
+      return null;
+    }
+
+    @Override
+    public Set<Resource> getResources(Request request, Predicate predicate)
+        throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException
{
+
+      if (type == Resource.Type.Cluster) {
+        Resource cluster = new ResourceImpl(Resource.Type.Cluster);
+        cluster.setProperty(ClusterResourceProvider.CLUSTER_ID_PROPERTY_ID, 1);
+        cluster.setProperty(ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID, "c1");
+        cluster.setProperty(ClusterResourceProvider.CLUSTER_VERSION_PROPERTY_ID, clusterVersion);
+
+        return Collections.singleton(cluster);
+      }
+      return Collections.emptySet();
+    }
+
+    @Override
+    public RequestStatus updateResources(Request request, Predicate predicate)
+        throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException
{
+      return null;
+    }
+
+    @Override
+    public RequestStatus deleteResources(Predicate predicate)
+        throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException
{
+      return null;
+    }
+
+    @Override
+    public Map<Resource.Type, String> getKeyPropertyIds() {
+      return null;
+    }
+
+    @Override
+    public Set<String> checkPropertyIds(Set<String> propertyIds) {
+      return null;
+    }
+  }
+}


Mime
View raw message