You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by jo...@apache.org on 2017/08/21 13:26:14 UTC
ambari git commit: AMBARI-21758 - Prevent New Clusters from Being
Provisioned With PATCH/MAINT Repos (jonathanhurley)
Repository: ambari
Updated Branches:
refs/heads/branch-feature-AMBARI-21450 5d0914c3a -> 1edd300af
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/1edd300a
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/1edd300a
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/1edd300a
Branch: refs/heads/branch-feature-AMBARI-21450
Commit: 1edd300afec2b8342d8768bc6ed5f6ae06fdb260
Parents: 5d0914c
Author: Jonathan Hurley <jh...@hortonworks.com>
Authored: Fri Aug 18 15:38:17 2017 -0400
Committer: Jonathan Hurley <jh...@hortonworks.com>
Committed: Fri Aug 18 15:38:17 2017 -0400
----------------------------------------------------------------------
.../AmbariManagementControllerImpl.java | 18 ++++++------------
.../ambari/server/controller/ClusterRequest.java | 2 --
.../internal/ServiceResourceProvider.java | 10 ++++++++++
.../orm/entities/RepositoryVersionEntity.java | 10 ++++++++++
.../ambari/server/topology/AmbariContext.java | 8 ++++++++
.../ambari/server/topology/AmbariContextTest.java | 2 ++
6 files changed, 36 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/1edd300a/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 60f5cce..1a022af 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;
@@ -429,20 +428,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.getClusterName()
- + ", request=" + 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());
@@ -2400,10 +2398,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/1edd300a/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterRequest.java
index aea2072..927a40a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterRequest.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterRequest.java
@@ -55,8 +55,6 @@ public class ClusterRequest {
*/
private final Map<String, Object> sessionAttributes;
- private String repositoryVersion = null;
-
// ----- Constructors ------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/1edd300a/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 2b4bf3b..a44ba6b 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;
@@ -419,6 +420,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);
@@ -432,6 +434,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/1edd300a/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 27b1654..aed0aaf 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
@@ -55,6 +55,7 @@ import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.base.Objects;
import com.google.inject.Inject;
import com.google.inject.Provider;
@@ -390,6 +391,15 @@ public class RepositoryVersionEntity {
}
/**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return Objects.toStringHelper(this).add("id", id).add("stack", stack).add("version",
+ version).add("type", type).toString();
+ }
+
+ /**
* Determine if the version belongs to the stack.
* @param stackId Stack, such as HDP-2.3
* @param version Version number, such as 2.3.0.0, or 2.3.0.0-1234
http://git-wip-us.apache.org/repos/asf/ambari/blob/1edd300a/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 d77d13c..902d4db 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/1edd300a/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 fc4fa86..16edc1b 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();