ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lpus...@apache.org
Subject [35/51] [abbrv] ambari git commit: AMBARI-21758 - Prevent New Clusters from Being Provisioned With PATCH/MAINT Repos (jonathanhurley)
Date Tue, 22 Aug 2017 11:48:03 GMT
AMBARI-21758 - Prevent New Clusters from Being Provisioned With PATCH/MAINT Repos (jonathanhurley)


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

Branch: refs/heads/feature-branch-AMBARI-21307
Commit: 28a42236a1dfc924fed73edfaf4ea6d896f16f02
Parents: f901e15
Author: Jonathan Hurley <jhurley@hortonworks.com>
Authored: Fri Aug 18 15:38:17 2017 -0400
Committer: Jonathan Hurley <jhurley@hortonworks.com>
Committed: Mon Aug 21 09:31:10 2017 -0400

----------------------------------------------------------------------
 .../controller/AmbariManagementControllerImpl.java   | 15 ++++++---------
 .../controller/internal/ServiceResourceProvider.java | 10 ++++++++++
 .../server/orm/entities/RepositoryVersionEntity.java |  8 +++-----
 .../apache/ambari/server/topology/AmbariContext.java |  8 ++++++++
 .../ambari/server/topology/AmbariContextTest.java    |  2 ++
 5 files changed, 29 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/28a42236/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
index d3b6d7c..96280ea 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
@@ -39,7 +39,6 @@ import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.SERVICE_R
 import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.UNLIMITED_KEY_JCE_REQUIRED;
 import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.USER_GROUPS;
 import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.USER_LIST;
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.VERSION;
 import static org.apache.ambari.server.controller.AmbariCustomCommandExecutionHelper.masterToSlaveMappingForDecom;
 
 import java.io.File;
@@ -434,18 +433,19 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
     if (request.getClusterName() == null
         || request.getClusterName().isEmpty()
         || request.getClusterId() != null) {
-      throw new IllegalArgumentException("Cluster name should be provided" +
-          " and clusterId should be null");
+      throw new IllegalArgumentException(
+          "Cluster name should be provided and clusterId should be null");
     }
 
     if (LOG.isDebugEnabled()) {
-      LOG.debug("Received a createCluster request, clusterName={}, request={}", request.getClusterName(),
request);
+      LOG.debug("Received a createCluster request, clusterName={}, request={}",
+          request.getClusterName(), request);
     }
 
     if (request.getStackVersion() == null
         || request.getStackVersion().isEmpty()) {
-      throw new IllegalArgumentException("Stack information should be"
-          + " provided when creating a cluster");
+      throw new IllegalArgumentException(
+          "Stack information should be provided when creating a cluster");
     }
 
     StackId stackId = new StackId(request.getStackVersion());
@@ -2418,9 +2418,6 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
         commandParams.put(MAX_DURATION_OF_RETRIES, Integer.toString(retryMaxTime));
         commandParams.put(COMMAND_RETRY_ENABLED, Boolean.toString(retryEnabled));
 
-        if (repoVersion != null) {
-         commandParams.put(VERSION, repoVersion.getVersion());
-        }
         if (script.getTimeout() > 0) {
           scriptCommandTimeout = String.valueOf(script.getTimeout());
         }

http://git-wip-us.apache.org/repos/asf/ambari/blob/28a42236/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java
index 818017e..e65693b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java
@@ -68,6 +68,7 @@ import org.apache.ambari.server.serveraction.kerberos.KerberosMissingAdminCreden
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.MaintenanceState;
+import org.apache.ambari.server.state.RepositoryType;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.ServiceComponentHost;
@@ -417,6 +418,7 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider
       LOG.warn("Received an empty requests set");
       return;
     }
+
     Clusters clusters = getManagementController().getClusters();
     // do all validation checks
     validateCreateRequests(requests, clusters);
@@ -430,6 +432,14 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider
         throw new AmbariException("Could not find any repository on the request.");
       }
 
+      if (repositoryVersion.getType() != RepositoryType.STANDARD
+          && cluster.getProvisioningState() == State.INIT) {
+        throw new AmbariException(String.format(
+            "Unable to add %s to %s because the cluster is still being provisioned and the
repository for the service is not %s: $s",
+            request.getServiceName(), cluster.getClusterName(), RepositoryType.STANDARD,
+            repositoryVersion));
+      }
+
       Service s = cluster.addService(request.getServiceName(), repositoryVersion);
 
       /*

http://git-wip-us.apache.org/repos/asf/ambari/blob/28a42236/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RepositoryVersionEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RepositoryVersionEntity.java
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RepositoryVersionEntity.java
index 2f38af3..c746363 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RepositoryVersionEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RepositoryVersionEntity.java
@@ -380,11 +380,9 @@ public class RepositoryVersionEntity {
    * {@inheritDoc}
    */
   @Override
-  public String toString(){
-    return Objects.toStringHelper(this)
-        .add("id", id)
-        .add("stack", stack)
-        .add("version", version).toString();
+  public String toString() {
+    return Objects.toStringHelper(this).add("id", id).add("stack", stack).add("version",
+        version).add("type", type).toString();
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/28a42236/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 0bbd5e6..fa703ed 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
@@ -76,6 +76,7 @@ import org.apache.ambari.server.state.ConfigFactory;
 import org.apache.ambari.server.state.ConfigHelper;
 import org.apache.ambari.server.state.DesiredConfig;
 import org.apache.ambari.server.state.Host;
+import org.apache.ambari.server.state.RepositoryType;
 import org.apache.ambari.server.state.SecurityType;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.configgroup.ConfigGroup;
@@ -233,6 +234,13 @@ public class AmbariContext {
       }
     }
 
+    // only use a STANDARD repo when creating a new cluster
+    if (repoVersion.getType() != RepositoryType.STANDARD) {
+      throw new IllegalArgumentException(String.format(
+          "Unable to create a cluster using the following repository since it is not a STANDARD
type: %s",
+          repoVersion));
+    }
+
     createAmbariClusterResource(clusterName, stack.getName(), stack.getVersion(), securityType);
     createAmbariServiceAndComponentResources(topology, clusterName, stackId, repoVersion.getId());
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/28a42236/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 efafbea..bef0a45 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
@@ -69,6 +69,7 @@ import org.apache.ambari.server.state.ConfigFactory;
 import org.apache.ambari.server.state.ConfigHelper;
 import org.apache.ambari.server.state.DesiredConfig;
 import org.apache.ambari.server.state.Host;
+import org.apache.ambari.server.state.RepositoryType;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.configgroup.ConfigGroup;
@@ -209,6 +210,7 @@ public class AmbariContextTest {
     RepositoryVersionEntity repositoryVersion = createNiceMock(RepositoryVersionEntity.class);
     expect(repositoryVersion.getId()).andReturn(1L).atLeastOnce();
     expect(repositoryVersion.getVersion()).andReturn("1.1.1.1").atLeastOnce();
+    expect(repositoryVersion.getType()).andReturn(RepositoryType.STANDARD).atLeastOnce();
 
     expect(repositoryVersionDAO.findByStack(EasyMock.anyObject(StackId.class))).andReturn(
         Collections.singletonList(repositoryVersion)).atLeastOnce();


Mime
View raw message