Repository: ambari
Updated Branches:
  refs/heads/branch-2.6 6588679df -> 3946ff677
  refs/heads/trunk eb9cce7e0 -> 698293d2d


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/3946ff67
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/3946ff67
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/3946ff67

Branch: refs/heads/branch-2.6
Commit: 3946ff677401e0324f8f632aac412b90ad662d82
Parents: 6588679
Author: Dmytro Grinenko <hapyles...@apache.org>
Authored: Fri Aug 25 19:29:02 2017 +0300
Committer: Dmytro Grinenko <hapyles...@apache.org>
Committed: Fri Aug 25 19:29:02 2017 +0300

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


http://git-wip-us.apache.org/repos/asf/ambari/blob/3946ff67/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 83df6aa..244caf6 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
@@ -196,7 +196,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/3946ff67/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 de7883d..97c3b4c 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
@@ -104,6 +104,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";
@@ -138,6 +143,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);
@@ -157,6 +164,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));
     }
@@ -459,6 +470,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/3946ff67/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 95c0597..da517f3 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/3946ff67/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 494d6a8..092339b 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
@@ -266,6 +266,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();
@@ -273,6 +274,10 @@ public class TopologyManager {
     SecurityType securityType = null;
     Credential credential = null;
 
+    if (null == repoVersion && null == repoVersionID) {
+      throw new AmbariException("Repository should be created and the version 
passed in the request.");
+    }
+
     SecurityConfiguration securityConfiguration = 
processSecurityConfiguration(request);
 
     if (securityConfiguration != null && securityConfiguration.getType() == 
SecurityType.KERBEROS) {
@@ -291,7 +296,7 @@ public class TopologyManager {
     topologyValidatorService.validateTopologyConfiguration(topology);
 
     // 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/3946ff67/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 d129048..84f43b6 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
@@ -314,7 +314,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();
@@ -743,7 +743,7 @@ public class AmbariContextTest {
     replayAll();
 
     // test
-    context.createAmbariResources(topology, CLUSTER_NAME, null, null);
+    context.createAmbariResources(topology, CLUSTER_NAME, null, null, null);
   }
 
   @Test
@@ -770,7 +770,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(
@@ -793,7 +793,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/3946ff67/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 c8d4d55..87ffa0e 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
@@ -337,7 +337,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(), (String) isNull());
+    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/3946ff67/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 4c9815c..b881487 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
@@ -339,7 +339,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) isNull());
+    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/3946ff67/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 1bdeb1b..5e88e74 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
@@ -336,7 +336,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(), (String) isNull());
+    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/3946ff67/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 101c693..8d891b9 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;
@@ -319,7 +320,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