ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ababiic...@apache.org
Subject [16/19] ambari git commit: AMBARI-21721. Blueprint deployments failing without version string (ncole)
Date Tue, 15 Aug 2017 14:36:15 GMT
AMBARI-21721. Blueprint deployments failing without version string (ncole)


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

Branch: refs/heads/branch-feature-logsearch-ui
Commit: c802a29814e9911b337c1dbb8804839575b0a838
Parents: 12b6caa
Author: Nate Cole <ncole@hortonworks.com>
Authored: Tue Aug 15 08:35:10 2017 -0400
Committer: Nate Cole <ncole@hortonworks.com>
Committed: Tue Aug 15 08:35:17 2017 -0400

----------------------------------------------------------------------
 .../ambari/server/topology/AmbariContext.java   | 39 +++++++-
 .../server/topology/AmbariContextTest.java      | 93 ++++++++++++++++++--
 2 files changed, 122 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/c802a298/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 662f9aa..0bbd5e6 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
@@ -57,6 +57,7 @@ import org.apache.ambari.server.controller.internal.ComponentResourceProvider;
 import org.apache.ambari.server.controller.internal.ConfigGroupResourceProvider;
 import org.apache.ambari.server.controller.internal.HostComponentResourceProvider;
 import org.apache.ambari.server.controller.internal.HostResourceProvider;
+import org.apache.ambari.server.controller.internal.ProvisionClusterRequest;
 import org.apache.ambari.server.controller.internal.RequestImpl;
 import org.apache.ambari.server.controller.internal.ServiceResourceProvider;
 import org.apache.ambari.server.controller.internal.Stack;
@@ -79,9 +80,12 @@ import org.apache.ambari.server.state.SecurityType;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.configgroup.ConfigGroup;
 import org.apache.ambari.server.utils.RetryHelper;
+import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.base.Function;
+import com.google.common.collect.Collections2;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Sets;
 import com.google.common.util.concurrent.Striped;
@@ -195,11 +199,38 @@ public class AmbariContext {
     Stack stack = topology.getBlueprint().getStack();
     StackId stackId = new StackId(stack.getName(), stack.getVersion());
 
-    RepositoryVersionEntity repoVersion = repositoryVersionDAO.findByStackAndVersion(stackId,
repoVersionString);
+    RepositoryVersionEntity repoVersion = null;
+    if (null == repoVersionString) {
+      List<RepositoryVersionEntity> stackRepoVersions = repositoryVersionDAO.findByStack(stackId);
 
-    if (null == repoVersion) {
-      throw new IllegalArgumentException(String.format("Could not identify repository version
with stack %s and version %s for installing services",
-          stackId, repoVersionString));
+      if (stackRepoVersions.isEmpty()) {
+        throw new IllegalArgumentException(String.format("No repositories were found for
%s", stackId));
+      } else if (stackRepoVersions.size() > 1) {
+
+        Function<RepositoryVersionEntity, String> function = new Function<RepositoryVersionEntity,
String>() {
+          @Override
+          public String apply(RepositoryVersionEntity input) {
+            return input.getVersion();
+          }
+        };
+
+        Collection<String> versions = Collections2.transform(stackRepoVersions, function);
+
+        throw new IllegalArgumentException(String.format("Several repositories were found
for %s:  %s.  Specify the version"
+            + " with '%s'", stackId, StringUtils.join(versions, ", "), ProvisionClusterRequest.REPO_VERSION_PROPERTY));
+      } else {
+        repoVersion = stackRepoVersions.get(0);
+        LOG.warn("Cluster is being provisioned using the single matching repository version
{}", repoVersion.getVersion());
+      }
+    } 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. "
+            + "Specify a valid version with '%s'",
+            stackId, repoVersionString, ProvisionClusterRequest.REPO_VERSION_PROPERTY));
+      }
     }
 
     createAmbariClusterResource(clusterName, stack.getName(), stack.getVersion(), securityType);

http://git-wip-us.apache.org/repos/asf/ambari/blob/c802a298/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 13a14ac..01af9fa 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
@@ -31,6 +31,7 @@ import static org.easymock.EasyMock.verify;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.lang.reflect.Field;
 import java.util.ArrayList;
@@ -204,11 +205,13 @@ public class AmbariContextTest {
             type1Service1).anyTimes();
     replay(type1Service1);
 
-    RepositoryVersionDAO repositoryVersionDAO = createStrictMock(RepositoryVersionDAO.class);
-    RepositoryVersionEntity repositoryVersion = createStrictMock(RepositoryVersionEntity.class);
-    expect(repositoryVersion.getId()).andReturn(1L).anyTimes();
-    expect(repositoryVersionDAO.findByStackAndVersion(EasyMock.anyObject(StackId.class),
-        EasyMock.anyString())).andReturn(repositoryVersion).anyTimes();
+    RepositoryVersionDAO repositoryVersionDAO = createNiceMock(RepositoryVersionDAO.class);
+    RepositoryVersionEntity repositoryVersion = createNiceMock(RepositoryVersionEntity.class);
+    expect(repositoryVersion.getId()).andReturn(1L).atLeastOnce();
+    expect(repositoryVersion.getVersion()).andReturn("1.1.1.1").atLeastOnce();
+
+    expect(repositoryVersionDAO.findByStack(EasyMock.anyObject(StackId.class))).andReturn(
+        Collections.singletonList(repositoryVersion)).atLeastOnce();
     replay(repositoryVersionDAO, repositoryVersion);
 
     context.configFactory = configFactory;
@@ -308,7 +311,7 @@ public class AmbariContextTest {
     replayAll();
 
     // test
-    context.createAmbariResources(topology, CLUSTER_NAME, null, "1.2.3");
+    context.createAmbariResources(topology, CLUSTER_NAME, null, null);
 
     // assertions
     ClusterRequest clusterRequest = clusterRequestCapture.getValue();
@@ -691,5 +694,83 @@ public class AmbariContextTest {
     assertFalse(topologyResolved);
   }
 
+  @Test
+  public void testCreateAmbariResourcesNoVersions() throws Exception {
+
+    RepositoryVersionDAO repositoryVersionDAO = createNiceMock(RepositoryVersionDAO.class);
+    RepositoryVersionEntity repositoryVersion = createNiceMock(RepositoryVersionEntity.class);
+    expect(repositoryVersion.getId()).andReturn(1L).atLeastOnce();
+    expect(repositoryVersion.getVersion()).andReturn("1.1.1.1").atLeastOnce();
+
+    expect(repositoryVersionDAO.findByStack(EasyMock.anyObject(StackId.class))).andReturn(
+        Collections.<RepositoryVersionEntity>emptyList()).atLeastOnce();
+    replay(repositoryVersionDAO, repositoryVersion);
+
+    context.repositoryVersionDAO = repositoryVersionDAO;
+
+    replayAll();
+
+    // test
+    try {
+      context.createAmbariResources(topology, CLUSTER_NAME, null, null);
+      fail("Expected failure when no versions are found");
+    } catch (IllegalArgumentException e) {
+      assertEquals("No repositories were found for testStack-testVersion", e.getMessage());
+    }
+  }
+
+  @Test
+  public void testCreateAmbariResourcesManyVersions() throws Exception {
+
+    RepositoryVersionDAO repositoryVersionDAO = createNiceMock(RepositoryVersionDAO.class);
+    RepositoryVersionEntity repositoryVersion1 = createNiceMock(RepositoryVersionEntity.class);
+    expect(repositoryVersion1.getId()).andReturn(1L).atLeastOnce();
+    expect(repositoryVersion1.getVersion()).andReturn("1.1.1.1").atLeastOnce();
+
+    RepositoryVersionEntity repositoryVersion2 = createNiceMock(RepositoryVersionEntity.class);
+    expect(repositoryVersion2.getId()).andReturn(2L).atLeastOnce();
+    expect(repositoryVersion2.getVersion()).andReturn("1.1.2.2").atLeastOnce();
+
+    expect(repositoryVersionDAO.findByStack(EasyMock.anyObject(StackId.class))).andReturn(
+        Arrays.asList(repositoryVersion1, repositoryVersion2)).atLeastOnce();
+    replay(repositoryVersionDAO, repositoryVersion1, repositoryVersion2);
+
+    context.repositoryVersionDAO = repositoryVersionDAO;
+
+    replayAll();
+
+    // test
+    try {
+      context.createAmbariResources(topology, CLUSTER_NAME, null, null);
+      fail("Expected failure when several versions are found");
+    } catch (IllegalArgumentException e) {
+      assertEquals(
+          "Several repositories were found for testStack-testVersion:  1.1.1.1, 1.1.2.2.
 Specify the version with 'repository_version'",
+          e.getMessage());
+    }
+  }
+
+  @Test
+  public void testCreateAmbariResourcesBadVersion() throws Exception {
+
+    RepositoryVersionDAO repositoryVersionDAO = createNiceMock(RepositoryVersionDAO.class);
+    expect(repositoryVersionDAO.findByStackAndVersion(EasyMock.anyObject(StackId.class),
+        EasyMock.anyString())).andReturn(null).atLeastOnce();
+    replay(repositoryVersionDAO);
+
+    context.repositoryVersionDAO = repositoryVersionDAO;
+
+    replayAll();
+
+    // test
+    try {
+      context.createAmbariResources(topology, CLUSTER_NAME, null, "xyz");
+      fail("Expected failure when a bad version is provided");
+    } catch (IllegalArgumentException e) {
+      assertEquals(
+          "Could not identify repository version with stack testStack-testVersion and version
xyz for installing services. Specify a valid version with 'repository_version'",
+          e.getMessage());
+    }
+  }
 
 }


Mime
View raw message