AMBARI-21777 Remove Ambiguous Repository Version When Creating Clusters via 
Blueprints (dgrinenko)


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: 698293d2d70d19f833e064dcb9c2c1775ce36d50
Parents: eb9cce7
Author: Dmytro Grinenko <hapyles...@apache.org>
Authored: Fri Aug 25 19:31:02 2017 +0300
Committer: Dmytro Grinenko <hapyles...@apache.org>
Committed: Fri Aug 25 19:31:02 2017 +0300

----------------------------------------------------------------------
 .../internal/ClusterResourceProvider.java       |  2 +-
 .../internal/ProvisionClusterRequest.java       | 18 +++++++++++++++
 .../ambari/server/topology/AmbariContext.java   | 24 ++++++++++++++------
 .../ambari/server/topology/TopologyManager.java |  5 ++--
 .../server/topology/AmbariContextTest.java      |  8 +++----
 .../ClusterDeployWithStartOnlyTest.java         |  2 +-
 ...InstallWithoutStartOnComponentLevelTest.java |  2 +-
 .../ClusterInstallWithoutStartTest.java         |  2 +-
 .../server/topology/TopologyManagerTest.java    |  3 ++-
 9 files changed, 48 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/698293d2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java
index abb017b..54c8360 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java
@@ -207,7 +207,7 @@ public class ClusterResourceProvider extends 
AbstractControllerResourceProvider
     baseUnsupported.remove("config_recommendation_strategy");
     baseUnsupported.remove("provision_action");
     baseUnsupported.remove(ProvisionClusterRequest.REPO_VERSION_PROPERTY);
-
+    baseUnsupported.remove(ProvisionClusterRequest.REPO_VERSION_ID_PROPERTY);
     return checkConfigPropertyIds(baseUnsupported, "Clusters");
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/698293d2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ProvisionClusterRequest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ProvisionClusterRequest.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ProvisionClusterRequest.java
index b053366..1fd6091 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ProvisionClusterRequest.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ProvisionClusterRequest.java
@@ -105,6 +105,11 @@ public class ProvisionClusterRequest extends 
BaseClusterRequest {
   public static final String REPO_VERSION_PROPERTY = "repository_version";
 
   /**
+   * The repo version id to use
+   */
+  public static final String REPO_VERSION_ID_PROPERTY = 
"repository_version_id";
+
+  /**
    * The global quick link filters property
    */
   public static final String QUICKLINKS_PROFILE_FILTERS_PROPERTY = 
"quicklinks_profile/filters";
@@ -139,6 +144,8 @@ public class ProvisionClusterRequest extends 
BaseClusterRequest {
 
   private String repoVersion;
 
+  private Long repoVersionId;
+
   private final String quickLinksProfileJson;
 
   private final static Logger LOG = 
LoggerFactory.getLogger(ProvisionClusterRequest.class);
@@ -158,6 +165,10 @@ public class ProvisionClusterRequest extends 
BaseClusterRequest {
       repoVersion = properties.get(REPO_VERSION_PROPERTY).toString();
     }
 
+    if (properties.containsKey(REPO_VERSION_ID_PROPERTY)) {
+      repoVersionId = 
Long.parseLong(properties.get(REPO_VERSION_ID_PROPERTY).toString());
+    }
+
     if (properties.containsKey(DEFAULT_PASSWORD_PROPERTY)) {
       defaultPassword = 
String.valueOf(properties.get(DEFAULT_PASSWORD_PROPERTY));
     }
@@ -462,6 +473,13 @@ public class ProvisionClusterRequest extends 
BaseClusterRequest {
   }
 
   /**
+   * @return the repository version id or {@code null}
+   */
+  public Long getRepositoryVersionId(){
+    return repoVersionId;
+  }
+
+  /**
    * @return the quick links profile in Json string format
    */
   public String getQuickLinksProfileJson() {

http://git-wip-us.apache.org/repos/asf/ambari/blob/698293d2/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java
index 75435a3..f81ff99 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java
@@ -200,12 +200,13 @@ public class AmbariContext {
     return getController().getActionManager().getTasks(ids);
   }
 
-  public void createAmbariResources(ClusterTopology topology, String 
clusterName, SecurityType securityType, String repoVersionString) {
+  public void createAmbariResources(ClusterTopology topology, String 
clusterName, SecurityType securityType,
+                                    String repoVersionString, Long 
repoVersionId) {
     Stack stack = topology.getBlueprint().getStack();
     StackId stackId = new StackId(stack.getName(), stack.getVersion());
 
     RepositoryVersionEntity repoVersion = null;
-    if (null == repoVersionString) {
+    if (null == repoVersionString && null == repoVersionId) {
       List<RepositoryVersionEntity> stackRepoVersions = 
repositoryVersionDAO.findByStack(stackId);
 
       if (stackRepoVersions.isEmpty()) {
@@ -218,13 +219,13 @@ public class AmbariContext {
         Request request = new RequestImpl(Collections.<String>emptySet(),
             Collections.singleton(properties), Collections.<String, 
String>emptyMap(), null);
 
-        Long repoVersionId = null;
+        Long defaultRepoVersionId = null;
 
         try {
           RequestStatus requestStatus = vdfProvider.createResources(request);
           if (!requestStatus.getAssociatedResources().isEmpty()) {
             Resource resource = 
requestStatus.getAssociatedResources().iterator().next();
-            repoVersionId = (Long) 
resource.getPropertyValue(VersionDefinitionResourceProvider.VERSION_DEF_ID);
+            defaultRepoVersionId = (Long) 
resource.getPropertyValue(VersionDefinitionResourceProvider.VERSION_DEF_ID);
           }
         } catch (Exception e) {
           throw new IllegalArgumentException(String.format(
@@ -234,7 +235,7 @@ public class AmbariContext {
               + " and try again.", stackId), e);
         }
 
-        repoVersion = repositoryVersionDAO.findByPK(repoVersionId);
+        repoVersion = repositoryVersionDAO.findByPK(defaultRepoVersionId);
         // !!! better not!
         if (null == repoVersion) {
           throw new IllegalArgumentException(String.format(
@@ -259,14 +260,23 @@ public class AmbariContext {
         repoVersion = stackRepoVersions.get(0);
         LOG.warn("Cluster is being provisioned using the single matching 
repository version {}", repoVersion.getVersion());
       }
+    } else if (null != repoVersionId){
+      repoVersion = repositoryVersionDAO.findByPK(repoVersionId);
+
+      if (null == repoVersion) {
+        throw new IllegalArgumentException(String.format(
+          "Could not identify repository version with repository version id %s 
for installing services. "
+            + "Specify a valid repository version id with '%s'",
+          repoVersionId, ProvisionClusterRequest.REPO_VERSION_ID_PROPERTY));
+      }
     } else {
       repoVersion = repositoryVersionDAO.findByStackAndVersion(stackId, 
repoVersionString);
 
       if (null == repoVersion) {
         throw new IllegalArgumentException(String.format(
-            "Could not identify repository version with stack %s and version 
%s for installing services. "
+          "Could not identify repository version with stack %s and version %s 
for installing services. "
             + "Specify a valid version with '%s'",
-            stackId, repoVersionString, 
ProvisionClusterRequest.REPO_VERSION_PROPERTY));
+          stackId, repoVersionString, 
ProvisionClusterRequest.REPO_VERSION_PROPERTY));
       }
     }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/698293d2/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyManager.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyManager.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyManager.java
index 5b58e1d..0863e37 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyManager.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyManager.java
@@ -269,6 +269,7 @@ public class TopologyManager {
     final String clusterName = request.getClusterName();
     final Stack stack = topology.getBlueprint().getStack();
     final String repoVersion = request.getRepositoryVersion();
+    final Long repoVersionID = request.getRepositoryVersionId();
 
     // get the id prior to creating ambari resources which increments the 
counter
     final Long provisionId = ambariContext.getNextRequestId();
@@ -276,7 +277,7 @@ public class TopologyManager {
     SecurityType securityType = null;
     Credential credential = null;
 
-    if (null == repoVersion) {
+    if (null == repoVersion && null == repoVersionID) {
       throw new AmbariException("Repository should be created and the version 
passed in the request.");
     }
 
@@ -299,7 +300,7 @@ public class TopologyManager {
 
 
     // create resources
-    ambariContext.createAmbariResources(topology, clusterName, securityType, 
repoVersion);
+    ambariContext.createAmbariResources(topology, clusterName, securityType, 
repoVersion, repoVersionID);
 
     if (securityConfiguration != null && securityConfiguration.getDescriptor() 
!= null) {
       submitKerberosDescriptorAsArtifact(clusterName, 
securityConfiguration.getDescriptor());

http://git-wip-us.apache.org/repos/asf/ambari/blob/698293d2/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java
index f8ed815..0deeae9 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java
@@ -315,7 +315,7 @@ public class AmbariContextTest {
     replayAll();
 
     // test
-    context.createAmbariResources(topology, CLUSTER_NAME, null, null);
+    context.createAmbariResources(topology, CLUSTER_NAME, null, null, null);
 
     // assertions
     ClusterRequest clusterRequest = clusterRequestCapture.getValue();
@@ -744,7 +744,7 @@ public class AmbariContextTest {
     replayAll();
 
     // test
-    context.createAmbariResources(topology, CLUSTER_NAME, null, null);
+    context.createAmbariResources(topology, CLUSTER_NAME, null, null, null);
   }
 
   @Test
@@ -769,7 +769,7 @@ public class AmbariContextTest {
 
     // test
     try {
-      context.createAmbariResources(topology, CLUSTER_NAME, null, null);
+      context.createAmbariResources(topology, CLUSTER_NAME, null, null, null);
       fail("Expected failure when several versions are found");
     } catch (IllegalArgumentException e) {
       assertEquals(
@@ -792,7 +792,7 @@ public class AmbariContextTest {
 
     // test
     try {
-      context.createAmbariResources(topology, CLUSTER_NAME, null, "xyz");
+      context.createAmbariResources(topology, CLUSTER_NAME, null, "xyz", null);
       fail("Expected failure when a bad version is provided");
     } catch (IllegalArgumentException e) {
       assertEquals(

http://git-wip-us.apache.org/repos/asf/ambari/blob/698293d2/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterDeployWithStartOnlyTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterDeployWithStartOnlyTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterDeployWithStartOnlyTest.java
index 6c3f097..c3248a3 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterDeployWithStartOnlyTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterDeployWithStartOnlyTest.java
@@ -338,7 +338,7 @@ public class ClusterDeployWithStartOnlyTest extends 
EasyMockSupport {
 
     
expect(ambariContext.getPersistedTopologyState()).andReturn(persistedState).anyTimes();
     //todo: don't ignore param
-    ambariContext.createAmbariResources(isA(ClusterTopology.class), 
eq(CLUSTER_NAME), (SecurityType) isNull(), eq("1"));
+    ambariContext.createAmbariResources(isA(ClusterTopology.class), 
eq(CLUSTER_NAME), (SecurityType) isNull(), eq("1"), anyLong());
     expectLastCall().once();
     expect(ambariContext.getNextRequestId()).andReturn(1L).once();
     
expect(ambariContext.isClusterKerberosEnabled(CLUSTER_ID)).andReturn(false).anyTimes();

http://git-wip-us.apache.org/repos/asf/ambari/blob/698293d2/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterInstallWithoutStartOnComponentLevelTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterInstallWithoutStartOnComponentLevelTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterInstallWithoutStartOnComponentLevelTest.java
index 929f5af..372d0a1 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterInstallWithoutStartOnComponentLevelTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterInstallWithoutStartOnComponentLevelTest.java
@@ -340,7 +340,7 @@ public class ClusterInstallWithoutStartOnComponentLevelTest 
extends EasyMockSupp
 
     
expect(ambariContext.getPersistedTopologyState()).andReturn(persistedState).anyTimes();
     //todo: don't ignore param
-    ambariContext.createAmbariResources(isA(ClusterTopology.class), 
eq(CLUSTER_NAME), (SecurityType) isNull(), (String) eq("1"));
+    ambariContext.createAmbariResources(isA(ClusterTopology.class), 
eq(CLUSTER_NAME), (SecurityType) isNull(), (String) eq("1"), anyLong());
     expectLastCall().once();
     expect(ambariContext.getNextRequestId()).andReturn(1L).once();
     
expect(ambariContext.isClusterKerberosEnabled(CLUSTER_ID)).andReturn(false).anyTimes();

http://git-wip-us.apache.org/repos/asf/ambari/blob/698293d2/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterInstallWithoutStartTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterInstallWithoutStartTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterInstallWithoutStartTest.java
index 389ce06..9620507 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterInstallWithoutStartTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterInstallWithoutStartTest.java
@@ -337,7 +337,7 @@ public class ClusterInstallWithoutStartTest extends 
EasyMockSupport {
 
     
expect(ambariContext.getPersistedTopologyState()).andReturn(persistedState).anyTimes();
     //todo: don't ignore param
-    ambariContext.createAmbariResources(isA(ClusterTopology.class), 
eq(CLUSTER_NAME), (SecurityType) isNull(), eq("1"));
+    ambariContext.createAmbariResources(isA(ClusterTopology.class), 
eq(CLUSTER_NAME), (SecurityType) isNull(), eq("1"), anyLong());
     expectLastCall().once();
     expect(ambariContext.getNextRequestId()).andReturn(1L).once();
     
expect(ambariContext.isClusterKerberosEnabled(CLUSTER_ID)).andReturn(false).anyTimes();

http://git-wip-us.apache.org/repos/asf/ambari/blob/698293d2/ambari-server/src/test/java/org/apache/ambari/server/topology/TopologyManagerTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/topology/TopologyManagerTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/topology/TopologyManagerTest.java
index 9a58b88..45c8b1a 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/topology/TopologyManagerTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/topology/TopologyManagerTest.java
@@ -18,6 +18,7 @@
 
 package org.apache.ambari.server.topology;
 
+import static org.easymock.EasyMock.anyLong;
 import static org.easymock.EasyMock.anyObject;
 import static org.easymock.EasyMock.capture;
 import static org.easymock.EasyMock.eq;
@@ -320,7 +321,7 @@ public class TopologyManagerTest {
 
     
expect(ambariContext.getPersistedTopologyState()).andReturn(persistedState).anyTimes();
     //todo: don't ignore param
-    ambariContext.createAmbariResources(isA(ClusterTopology.class), 
eq(CLUSTER_NAME), (SecurityType) isNull(), (String) isNull());
+    ambariContext.createAmbariResources(isA(ClusterTopology.class), 
eq(CLUSTER_NAME), (SecurityType) isNull(), (String) isNull(), anyLong());
     expectLastCall().anyTimes();
     expect(ambariContext.getNextRequestId()).andReturn(1L).anyTimes();
     
expect(ambariContext.isClusterKerberosEnabled(CLUSTER_ID)).andReturn(false).anyTimes();

Reply via email to