This is an automated email from the ASF dual-hosted git repository.
adoroszlai pushed a commit to branch branch-feature-AMBARI-14714
in repository https://gitbox.apache.org/repos/asf/ambari.git
The following commit(s) were added to refs/heads/branch-feature-AMBARI-14714 by
this push:
new 2d50429 AMBARI-22875. Replay of topology requests with mpacks (#1591)
2d50429 is described below
commit 2d504294363f78685d763e4e1ef82555d7b1598b
Author: Doroszlai, Attila <[email protected]>
AuthorDate: Wed Jun 27 12:43:25 2018 +0200
AMBARI-22875. Replay of topology requests with mpacks (#1591)
---
.../ambari/server/actionmanager/Request.java | 5 +-
.../api/query/render/ClusterBlueprintRenderer.java | 4 +-
.../internal/ExportBlueprintRequest.java | 48 +++++-----
.../internal/ProvisionClusterRequest.java | 1 -
.../internal/ServiceGroupResourceProvider.java | 9 +-
.../ambari/server/orm/entities/SettingEntity.java | 14 +++
.../ambari/server/topology/AmbariContext.java | 51 ++++++++---
.../BlueprintBasedClusterProvisionRequest.java | 26 +++---
.../topology/ClusterConfigurationRequest.java | 42 +++++----
.../ambari/server/topology/ClusterTopology.java | 7 +-
.../server/topology/ClusterTopologyImpl.java | 36 ++++----
.../ambari/server/topology/DownloadMpacksTask.java | 5 +-
.../ambari/server/topology/LogicalRequest.java | 25 ++---
.../ambari/server/topology/PersistedState.java | 7 --
.../ambari/server/topology/PersistedStateImpl.java | 80 ++++++++--------
.../ambari/server/topology/ProvisionRequest.java | 1 -
.../ambari/server/topology/TopologyManager.java | 65 ++++++-------
.../query/render/ClusterBlueprintRendererTest.java | 2 +-
.../BlueprintConfigurationProcessorTest.java | 5 +-
.../internal/ExportBlueprintRequestTest.java | 87 +++++++++++++-----
.../KerberosDescriptorUpdateHelperTest.java | 14 ++-
.../ambari/server/topology/AmbariContextTest.java | 44 ++++++++-
.../topology/ClusterConfigurationRequestTest.java | 35 +++----
.../topology/ClusterDeployWithStartOnlyTest.java | 6 +-
...terInstallWithoutStartOnComponentLevelTest.java | 6 +-
.../topology/ClusterInstallWithoutStartTest.java | 6 +-
.../server/topology/ClusterTopologyImplTest.java | 71 +++++++++------
.../server/topology/TopologyManagerTest.java | 101 ++++++++-------------
28 files changed, 449 insertions(+), 354 deletions(-)
diff --git
a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/Request.java
b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/Request.java
index 9c215aa..2581d4f 100644
---
a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/Request.java
+++
b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/Request.java
@@ -91,7 +91,7 @@ public class Request {
@AssistedInject
public Request(@Assisted long requestId, @Assisted("clusterId") Long
clusterId, Clusters clusters) {
this.requestId = requestId;
- this.clusterId = clusterId.longValue();
+ this.clusterId = clusterId;
this.createTime = System.currentTimeMillis();
this.startTime = -1;
this.endTime = -1;
@@ -102,8 +102,7 @@ public class Request {
try {
this.clusterName =
clusters.getClusterById(this.clusterId).getClusterName();
} catch (AmbariException e) {
- LOG.debug("Could not load cluster with id {}, the cluster may have
been removed for request {}",
- clusterId, Long.valueOf(requestId));
+ LOG.debug("Could not load cluster with id {}, the cluster may have
been removed for request {}", clusterId, requestId);
}
}
}
diff --git
a/ambari-server/src/main/java/org/apache/ambari/server/api/query/render/ClusterBlueprintRenderer.java
b/ambari-server/src/main/java/org/apache/ambari/server/api/query/render/ClusterBlueprintRenderer.java
index f6a2625..ae31086 100644
---
a/ambari-server/src/main/java/org/apache/ambari/server/api/query/render/ClusterBlueprintRenderer.java
+++
b/ambari-server/src/main/java/org/apache/ambari/server/api/query/render/ClusterBlueprintRenderer.java
@@ -66,7 +66,6 @@ import
org.apache.ambari.server.controller.utilities.PredicateBuilder;
import org.apache.ambari.server.state.SecurityType;
import org.apache.ambari.server.topology.AmbariContext;
import org.apache.ambari.server.topology.ClusterTopology;
-import org.apache.ambari.server.topology.ClusterTopologyImpl;
import org.apache.ambari.server.topology.Configuration;
import org.apache.ambari.server.topology.HostGroup;
import org.apache.ambari.server.topology.HostGroupInfo;
@@ -491,7 +490,8 @@ public class ClusterBlueprintRenderer extends BaseRenderer
implements Renderer {
protected ClusterTopology createClusterTopology(TreeNode<Resource>
clusterNode)
throws InvalidTopologyTemplateException, InvalidTopologyException {
- return new ClusterTopologyImpl(controller.getAmbariContext(), new
ExportBlueprintRequest(clusterNode));
+ AmbariContext ambariContext = controller.getAmbariContext();
+ return ambariContext.createClusterTopology(new
ExportBlueprintRequest(clusterNode));
}
/**
diff --git
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ExportBlueprintRequest.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ExportBlueprintRequest.java
index 6e6fd69..48e4767 100644
---
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ExportBlueprintRequest.java
+++
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ExportBlueprintRequest.java
@@ -19,7 +19,7 @@
package org.apache.ambari.server.controller.internal;
-import static java.util.stream.Collectors.toMap;
+import static java.util.stream.Collectors.toSet;
import java.net.InetAddress;
import java.net.UnknownHostException;
@@ -31,10 +31,7 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-import org.apache.ambari.server.StackAccessException;
import org.apache.ambari.server.api.util.TreeNode;
-import org.apache.ambari.server.controller.AmbariManagementController;
-import org.apache.ambari.server.controller.AmbariServer;
import org.apache.ambari.server.controller.RootComponent;
import org.apache.ambari.server.controller.spi.Resource;
import org.apache.ambari.server.controller.utilities.PropertyHelper;
@@ -48,10 +45,7 @@ import org.apache.ambari.server.topology.Configuration;
import org.apache.ambari.server.topology.HostGroup;
import org.apache.ambari.server.topology.HostGroupImpl;
import org.apache.ambari.server.topology.HostGroupInfo;
-import org.apache.ambari.server.topology.InvalidTopologyTemplateException;
import org.apache.ambari.server.topology.TopologyRequest;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import com.google.common.collect.ImmutableSet;
@@ -60,8 +54,7 @@ import com.google.common.collect.ImmutableSet;
*/
public class ExportBlueprintRequest implements TopologyRequest {
- private final static Logger LOG =
LoggerFactory.getLogger(ExportBlueprintRequest.class);
- private static AmbariManagementController controller =
AmbariServer.getController();
+ private final Set<StackId> stackIds;
private String clusterName;
private Long clusterId;
@@ -69,20 +62,25 @@ public class ExportBlueprintRequest implements
TopologyRequest {
private Configuration configuration;
//todo: Should this map be represented by a new class?
private Map<String, HostGroupInfo> hostGroupInfo = new HashMap<>();
- private Map<String, StackId> serviceGroupToMpack = new HashMap<>();
-
- public ExportBlueprintRequest(TreeNode<Resource> clusterNode) throws
InvalidTopologyTemplateException {
+ public ExportBlueprintRequest(TreeNode<Resource> clusterNode) {
Resource clusterResource = clusterNode.getObject();
clusterName = String.valueOf(clusterResource.getPropertyValue(
ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID));
clusterId = Long.valueOf(String.valueOf(clusterResource.getPropertyValue(
ClusterResourceProvider.CLUSTER_ID_PROPERTY_ID)));
- // create service group to mpack map
- serviceGroupToMpack =
clusterNode.getChild("servicegroups").getChildren().stream().
- map(tn ->
tn.getObject().getPropertiesMap().get(ServiceGroupResourceProvider.RESPONSE_KEY)).
- collect(toMap(m -> m.get("service_group_name").toString(), m -> new
StackId(m.get("stack").toString())));
+ TreeNode<Resource> serviceGroups = clusterNode.getChild("servicegroups");
+ if (serviceGroups != null) {
+ stackIds = serviceGroups.getChildren().stream()
+ .map(TreeNode::getObject)
+ .map(Resource::getPropertiesMap)
+ .map(each -> each.get(ServiceGroupResourceProvider.RESPONSE_KEY))
+ .map(m -> new
StackId(m.get(ServiceGroupResourceProvider.MPACK_NAME).toString(),
m.get(ServiceGroupResourceProvider.MPACK_VERSION).toString()))
+ .collect(toSet());
+ } else {
+ stackIds = ImmutableSet.of(parseStack(clusterResource));
+ }
createConfiguration(clusterNode);
//todo: should be parsing Configuration from the beginning
@@ -90,7 +88,7 @@ public class ExportBlueprintRequest implements
TopologyRequest {
Collection<ExportedHostGroup> exportedHostGroups =
processHostGroups(clusterNode.getChild("hosts"));
createHostGroupInfo(exportedHostGroups);
- createBlueprint(exportedHostGroups,
createStack(parseStack(clusterResource)));
+ createBlueprint(exportedHostGroups);
}
public String getClusterName() {
@@ -127,10 +125,15 @@ public class ExportBlueprintRequest implements
TopologyRequest {
return String.format("Export Command For Cluster '%s'", clusterName);
}
+ @Override
+ public Set<StackId> getStackIds() {
+ return stackIds;
+ }
+
// ----- private instance methods ------------------------------------------
- private void createBlueprint(Collection<ExportedHostGroup>
exportedHostGroups, Stack stack) {
+ private void createBlueprint(Collection<ExportedHostGroup>
exportedHostGroups) {
String bpName = "exported-blueprint";
Collection<HostGroup> hostGroups = new ArrayList<>();
@@ -139,7 +142,6 @@ public class ExportBlueprintRequest implements
TopologyRequest {
exportedHostGroup.getComponents(),
exportedHostGroup.getConfiguration(),
String.valueOf(exportedHostGroup.getCardinality())));
}
- ImmutableSet<StackId> stackIds = ImmutableSet.of(stack.getStackId());
blueprint = new BlueprintImpl(bpName, hostGroups, stackIds,
Collections.emptySet(), configuration, null, null);
}
@@ -158,14 +160,6 @@ public class ExportBlueprintRequest implements
TopologyRequest {
return new
StackId(String.valueOf(clusterResource.getPropertyValue(ClusterResourceProvider.CLUSTER_VERSION_PROPERTY_ID)));
}
- private Stack createStack(StackId stackId) throws
InvalidTopologyTemplateException {
- try {
- return new Stack(stackId, controller.getAmbariMetaInfo());
- } catch (StackAccessException e) {
- throw new InvalidTopologyTemplateException(String.format("The specified
stack doesn't exist: %s", stackId));
- }
- }
-
/**
* Process cluster scoped configurations.
*
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 b1e603b..123cdf4 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
@@ -268,7 +268,6 @@ public class ProvisionClusterRequest extends
BaseClusterRequest implements Provi
return credentialsMap;
}
- @Override
public String getClusterName() {
return clusterName;
}
diff --git
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceGroupResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceGroupResourceProvider.java
index 496a998..04449f8 100644
---
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceGroupResourceProvider.java
+++
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceGroupResourceProvider.java
@@ -75,10 +75,13 @@ public class ServiceGroupResourceProvider extends
AbstractControllerResourceProv
public static final String SERVICE_GROUP_CLUSTER_ID_PROPERTY_ID =
RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "cluster_id";
public static final String SERVICE_GROUP_CLUSTER_NAME_PROPERTY_ID =
RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "cluster_name";
public static final String SERVICE_GROUP_SERVICE_GROUP_ID_PROPERTY_ID =
RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "service_group_id";
- public static final String SERVICE_GROUP_SERVICE_GROUP_NAME_PROPERTY_ID =
RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "service_group_name";
+ public static final String SERVICE_GROUP_NAME = "service_group_name";
+ public static final String SERVICE_GROUP_SERVICE_GROUP_NAME_PROPERTY_ID =
RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + SERVICE_GROUP_NAME;
public static final String SERVICE_GROUP_MPACK_ID = RESPONSE_KEY +
PropertyHelper.EXTERNAL_PATH_SEP + "mpack_id";
- public static final String SERVICE_GROUP_MPACK_NAME = RESPONSE_KEY +
PropertyHelper.EXTERNAL_PATH_SEP + "mpack_name";
- public static final String SERVICE_GROUP_MPACK_VERSION = RESPONSE_KEY +
PropertyHelper.EXTERNAL_PATH_SEP + "mpack_version";
+ public static final String MPACK_NAME = "mpack_name";
+ public static final String SERVICE_GROUP_MPACK_NAME = RESPONSE_KEY +
PropertyHelper.EXTERNAL_PATH_SEP + MPACK_NAME;
+ public static final String MPACK_VERSION = "mpack_version";
+ public static final String SERVICE_GROUP_MPACK_VERSION = RESPONSE_KEY +
PropertyHelper.EXTERNAL_PATH_SEP + MPACK_VERSION;
/**
* The pieces of the Mpack (ID, name, version) should be broken out - there's
diff --git
a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/SettingEntity.java
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/SettingEntity.java
index b9e047b..28488bf 100644
---
a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/SettingEntity.java
+++
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/SettingEntity.java
@@ -30,6 +30,8 @@ import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
+import com.google.common.base.MoreObjects;
+
/**
* Entity representing Setting.
*/
@@ -144,6 +146,18 @@ public class SettingEntity {
}
@Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("id", id)
+ .add("name", name)
+ .add("settingType", settingType)
+ .add("content", content)
+ .add("updatedBy", updatedBy)
+ .add("updateTimestamp", updateTimestamp)
+ .toString();
+ }
+
+ @Override
public int hashCode() {
return Objects.hash(id, name, settingType, content, updatedBy,
updateTimestamp);
}
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 9a0595a..9071920 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
@@ -46,8 +46,8 @@ import org.apache.ambari.server.StackAccessException;
import org.apache.ambari.server.actionmanager.HostRoleCommand;
import org.apache.ambari.server.actionmanager.HostRoleCommandFactory;
import org.apache.ambari.server.actionmanager.HostRoleStatus;
+import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.controller.AmbariManagementController;
-import org.apache.ambari.server.controller.AmbariServer;
import org.apache.ambari.server.controller.ClusterRequest;
import org.apache.ambari.server.controller.ConfigGroupRequest;
import org.apache.ambari.server.controller.ConfigurationRequest;
@@ -62,6 +62,7 @@ import org.apache.ambari.server.controller.ServiceResponse;
import org.apache.ambari.server.controller.internal.AbstractResourceProvider;
import org.apache.ambari.server.controller.internal.ComponentResourceProvider;
import
org.apache.ambari.server.controller.internal.ConfigGroupResourceProvider;
+import org.apache.ambari.server.controller.internal.ExportBlueprintRequest;
import
org.apache.ambari.server.controller.internal.HostComponentResourceProvider;
import org.apache.ambari.server.controller.internal.HostResourceProvider;
import org.apache.ambari.server.controller.internal.RequestImpl;
@@ -75,6 +76,7 @@ import
org.apache.ambari.server.controller.predicate.EqualsPredicate;
import org.apache.ambari.server.controller.spi.ClusterController;
import org.apache.ambari.server.controller.spi.Predicate;
import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.spi.ResourceProvider;
import org.apache.ambari.server.controller.utilities.ClusterControllerHelper;
import org.apache.ambari.server.security.authorization.AuthorizationException;
import org.apache.ambari.server.stack.NoSuchStackException;
@@ -127,12 +129,23 @@ public class AmbariContext {
@Inject
private Provider<ConfigHelper> configHelper;
- private static AmbariManagementController controller;
- private static ClusterController clusterController;
+ @Inject
+ private ComponentResolver resolver;
+
+ @Inject
+ private SecurityConfigurationFactory securityConfigurationFactory;
+
+ @Inject
+ private Provider<AmbariMetaInfo> ambariMetaInfo;
+
+ @Inject
+ private Provider<AmbariManagementController> controller;
+
//todo: task id's. Use existing mechanism for getting next task id sequence
private final static AtomicLong nextTaskId = new AtomicLong(10000);
static final String DEFAULT_SERVICE_GROUP_NAME = "default_service_group"; //
exposed for test
+ private static ClusterController clusterController;
private static HostRoleCommandFactory hostRoleCommandFactory;
private static HostResourceProvider hostResourceProvider;
private static ServiceGroupResourceProvider serviceGroupResourceProvider;
@@ -358,14 +371,11 @@ public class AmbariContext {
return getController().getActionManager().getNextRequestId();
}
- public synchronized static AmbariManagementController getController() {
- if (controller == null) {
- controller = AmbariServer.getController();
- }
- return controller;
+ public AmbariManagementController getController() {
+ return controller.get();
}
- public synchronized static ClusterController getClusterController() {
+ public static ClusterController getClusterController() {
if (clusterController == null) {
clusterController = ClusterControllerHelper.getClusterController();
}
@@ -376,6 +386,23 @@ public class AmbariContext {
hostRoleCommandFactory = factory;
}
+ public ClusterTopology createClusterTopology(ExportBlueprintRequest request)
throws InvalidTopologyException {
+ StackDefinition stack = composeStacks(request.getStackIds());
+ Blueprint bp = request.getBlueprint();
+ return new ClusterTopologyImpl(this, request, stack);
+ }
+
+ public ClusterTopology createClusterTopology(ProvisionRequest request)
throws InvalidTopologyException {
+ BlueprintBasedClusterProvisionRequest provisionRequest = new
BlueprintBasedClusterProvisionRequest(this, securityConfigurationFactory,
request.getBlueprint(), request);
+ Map<String, Set<ResolvedComponent>> resolved =
resolver.resolveComponents(provisionRequest);
+ return new ClusterTopologyImpl(this, provisionRequest, resolved);
+ }
+
+ public void downloadMissingMpacks(Set<MpackInstance> mpacks) {
+ ResourceProvider resourceProvider =
getClusterController().ensureResourceProvider(Resource.Type.Mpack);
+ new DownloadMpacksTask(resourceProvider,
ambariMetaInfo.get()).downloadMissingMpacks(mpacks);
+ }
+
public void registerHostWithConfigGroup(final String hostName, final
ClusterTopology topology, final String groupName) {
String qualifiedGroupName =
getConfigurationGroupName(topology.getBlueprintName(), groupName);
@@ -469,13 +496,13 @@ public class AmbariContext {
* Verifies that all desired configurations have reached the resolved state
* before proceeding with the install
*
- * @param clusterName name of the cluster
+ * @param clusterId ID of the cluster
* @param updatedConfigTypes set of config types that are required to be in
the TOPOLOGY_RESOLVED state
*
* @throws AmbariException upon any system-level error that occurs
*/
- public void waitForConfigurationResolution(String clusterName, Set<String>
updatedConfigTypes) throws AmbariException {
- Cluster cluster = getController().getClusters().getCluster(clusterName);
+ public void waitForConfigurationResolution(Long clusterId, Set<String>
updatedConfigTypes) throws AmbariException {
+ Cluster cluster = getController().getClusters().getCluster(clusterId);
boolean shouldWaitForResolution = true;
while (shouldWaitForResolution) {
int numOfRequestsStillRequiringResolution = 0;
diff --git
a/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintBasedClusterProvisionRequest.java
b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintBasedClusterProvisionRequest.java
index e78b093..ed2ab4b 100644
---
a/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintBasedClusterProvisionRequest.java
+++
b/ambari-server/src/main/java/org/apache/ambari/server/topology/BlueprintBasedClusterProvisionRequest.java
@@ -51,13 +51,13 @@ public class BlueprintBasedClusterProvisionRequest
implements Blueprint, Provisi
public BlueprintBasedClusterProvisionRequest(AmbariContext ambariContext,
SecurityConfigurationFactory securityConfigurationFactory, Blueprint blueprint,
ProvisionRequest request) {
this.blueprint = blueprint;
this.request = request;
-
stackIds = ImmutableSet.copyOf(Sets.union(blueprint.getStackIds(),
request.getStackIds()));
- stack = ambariContext.composeStacks(stackIds);
mpacks = ImmutableSet.<MpackInstance>builder().
addAll(blueprint.getMpacks()).
addAll(request.getMpacks()).build();
+ stack = ambariContext.composeStacks(stackIds);
+
securityConfiguration =
processSecurityConfiguration(securityConfigurationFactory);
if (securityConfiguration.getType() == SecurityType.KERBEROS) {
@@ -101,11 +101,6 @@ public class BlueprintBasedClusterProvisionRequest
implements Blueprint, Provisi
}
@Override
- public SecurityConfiguration getSecurityConfiguration() {
- return securityConfiguration;
- }
-
- @Override
public Collection<HostGroup> getHostGroupsForComponent(String component) {
return blueprint.getHostGroupsForComponent(component);
}
@@ -117,18 +112,18 @@ public class BlueprintBasedClusterProvisionRequest
implements Blueprint, Provisi
}
@Override
- public BlueprintEntity toEntity() {
- throw new UnsupportedOperationException();
+ public SecurityConfiguration getSecurityConfiguration() {
+ return securityConfiguration;
}
@Override
- public Long getClusterId() {
- return null;
+ public BlueprintEntity toEntity() {
+ throw new UnsupportedOperationException();
}
@Override
- public String getClusterName() {
- return request.getClusterName();
+ public Long getClusterId() {
+ return request.getClusterId();
}
@Override
@@ -194,4 +189,9 @@ public class BlueprintBasedClusterProvisionRequest
implements Blueprint, Provisi
public boolean ensureKerberosClientIsPresent() {
return blueprint.ensureKerberosClientIsPresent();
}
+
+ public Set<MpackInstance> getAllMpacks() {
+ return mpacks;
+ }
+
}
diff --git
a/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterConfigurationRequest.java
b/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterConfigurationRequest.java
index 49eb890..e8fbb5b 100644
---
a/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterConfigurationRequest.java
+++
b/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterConfigurationRequest.java
@@ -75,14 +75,16 @@ public class ClusterConfigurationRequest {
private StackDefinition stack;
private boolean configureSecurity = false;
- public ClusterConfigurationRequest(AmbariContext ambariContext,
ClusterTopology topology, boolean setInitial,
- StackAdvisorBlueprintProcessor
stackAdvisorBlueprintProcessor, boolean configureSecurity) {
- this(ambariContext, topology, setInitial, stackAdvisorBlueprintProcessor);
+ public ClusterConfigurationRequest(AmbariContext ambariContext,
ClusterTopology topology,
+ StackAdvisorBlueprintProcessor stackAdvisorBlueprintProcessor, boolean
configureSecurity
+ ) {
+ this(ambariContext, topology, stackAdvisorBlueprintProcessor);
this.configureSecurity = configureSecurity;
}
- public ClusterConfigurationRequest(AmbariContext ambariContext,
ClusterTopology clusterTopology, boolean setInitial,
- StackAdvisorBlueprintProcessor
stackAdvisorBlueprintProcessor) {
+ public ClusterConfigurationRequest(AmbariContext ambariContext,
ClusterTopology clusterTopology,
+ StackAdvisorBlueprintProcessor stackAdvisorBlueprintProcessor
+ ) {
this.ambariContext = ambariContext;
this.clusterTopology = clusterTopology;
this.stack = clusterTopology.getStack();
@@ -90,9 +92,10 @@ public class ClusterConfigurationRequest {
this.configurationProcessor = new
BlueprintConfigurationProcessor(clusterTopology);
this.stackAdvisorBlueprintProcessor = stackAdvisorBlueprintProcessor;
removeOrphanConfigTypes();
- if (setInitial) {
- setConfigurationsOnCluster(clusterTopology,
TopologyManager.INITIAL_CONFIG_TAG, Collections.emptySet());
- }
+ }
+
+ public void setInitialConfigurations() throws AmbariException {
+ setConfigurationsOnCluster(clusterTopology,
TopologyManager.INITIAL_CONFIG_TAG, Collections.emptySet());
}
/**
@@ -181,12 +184,12 @@ public class ClusterConfigurationRequest {
try {
// generate principals & keytabs for headless identities
- AmbariContext.getController().getKerberosHelper()
+ ambariContext.getController().getKerberosHelper()
.ensureHeadlessIdentities(cluster, existingConfigurations,
new HashSet<>(clusterTopology.getServices()));
// apply Kerberos specific configurations
- Map<String, Map<String, String>> updatedConfigs =
AmbariContext.getController().getKerberosHelper()
+ Map<String, Map<String, String>> updatedConfigs =
ambariContext.getController().getKerberosHelper()
.getServiceConfigurationUpdates(cluster, existingConfigurations,
createServiceComponentMap(), null, null, true, false);
@@ -299,7 +302,7 @@ public class ClusterConfigurationRequest {
existingConfigurations.put(CLUSTER_HOST_INFO, new HashMap<>());
// apply Kerberos specific configurations
- Map<String, Map<String, String>> updatedConfigs =
AmbariContext.getController().getKerberosHelper()
+ Map<String, Map<String, String>> updatedConfigs =
ambariContext.getController().getKerberosHelper()
.getServiceConfigurationUpdates(cluster, existingConfigurations,
createServiceComponentMap(), null, null, true, false);
@@ -332,7 +335,7 @@ public class ClusterConfigurationRequest {
private Cluster getCluster() throws AmbariException {
String clusterName =
ambariContext.getClusterName(clusterTopology.getClusterId());
- return AmbariContext.getController().getClusters().getCluster(clusterName);
+ return ambariContext.getController().getClusters().getCluster(clusterName);
}
/**
@@ -340,7 +343,7 @@ public class ClusterConfigurationRequest {
* @param clusterTopology cluster topology
* @param tag config tag
*/
- public void setConfigurationsOnCluster(ClusterTopology clusterTopology,
String tag, Set<String> updatedConfigTypes) {
+ private void setConfigurationsOnCluster(ClusterTopology clusterTopology,
String tag, Set<String> updatedConfigTypes) throws AmbariException {
// TODO: This version works with Ambari 3.0 where it is assumed that any
service with a configuration can be identified
// by its name. Even though the cluster is multi-stack (multi-mpack),
service names should not conflict across mpacks,
// except client services which have no configuration. In 3.1, mpack may
have conflicting service names
@@ -356,9 +359,10 @@ public class ClusterConfigurationRequest {
// TODO: do we need to handle security type? In the previous version it
was handled but in a broken way
- for (ServiceResponse service :
ambariContext.getServices(clusterTopology.getClusterName())) {
+ String clusterName =
ambariContext.getClusterName(clusterTopology.getClusterId());
+ for (ServiceResponse service : ambariContext.getServices(clusterName)) {
ClusterRequest clusterRequest =
- new ClusterRequest(clusterTopology.getClusterId(),
clusterTopology.getClusterName(), null, null, null, null);
+ new ClusterRequest(clusterTopology.getClusterId(), clusterName, null,
null, null, null);
clusterRequest.setDesiredConfig(new ArrayList<>());
Set<String> configTypes =
@@ -373,7 +377,7 @@ public class ClusterConfigurationRequest {
removeNullValues(properties, attributes);
- ConfigurationRequest configurationRequest = new
ConfigurationRequest(clusterTopology.getClusterName(),
+ ConfigurationRequest configurationRequest = new
ConfigurationRequest(clusterName,
serviceConfigType,
tag,
properties,
@@ -388,14 +392,14 @@ public class ClusterConfigurationRequest {
// since the stack returns "cluster-env" with each service's config ensure
that only one
// ClusterRequest occurs for the global cluster-env configuration
ClusterRequest globalConfigClusterRequest =
- new ClusterRequest(clusterTopology.getClusterId(),
clusterTopology.getClusterName(), null, null, null, null);
+ new ClusterRequest(clusterTopology.getClusterId(), clusterName, null,
null, null, null);
Map<String, String> clusterEnvProps = clusterProperties.get("cluster-env");
Map<String, Map<String, String>> clusterEnvAttributes =
clusterAttributes.get("cluster-env");
removeNullValues(clusterEnvProps, clusterEnvAttributes);
- ConfigurationRequest globalConfigurationRequest = new
ConfigurationRequest(clusterTopology.getClusterName(),
+ ConfigurationRequest globalConfigurationRequest = new
ConfigurationRequest(clusterName,
"cluster-env",
tag,
clusterEnvProps,
@@ -443,7 +447,7 @@ public class ClusterConfigurationRequest {
// if this is a request to resolve config, then wait until resolution is
completed
try {
// wait until the cluster topology configuration is set/resolved
-
ambariContext.waitForConfigurationResolution(clusterTopology.getClusterName(),
updatedConfigTypes);
+
ambariContext.waitForConfigurationResolution(clusterTopology.getClusterId(),
updatedConfigTypes);
} catch (AmbariException e) {
LOG.error("Error while attempting to wait for the cluster
configuration to reach TOPOLOGY_RESOLVED state.", e);
}
diff --git
a/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopology.java
b/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopology.java
index 8ef0dba..5791f40 100644
---
a/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopology.java
+++
b/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopology.java
@@ -49,11 +49,6 @@ public interface ClusterTopology {
void setClusterId(Long clusterId);
/**
- * @return the cluster name
- */
- String getClusterName();
-
- /**
* Get the blueprint associated with the cluster.
*
* @return associated blueprint
@@ -257,4 +252,6 @@ public interface ClusterTopology {
ClusterTopology withAdditionalComponents(Map<String, Set<ResolvedComponent>>
additionalComponents) throws InvalidTopologyException;
Set<String> getHostNames();
+
+ SecurityConfiguration getSecurity();
}
diff --git
a/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopologyImpl.java
b/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopologyImpl.java
index d03dd99..428571b 100644
---
a/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopologyImpl.java
+++
b/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopologyImpl.java
@@ -38,8 +38,8 @@ import javax.annotation.Nonnull;
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.controller.RequestStatusResponse;
-import org.apache.ambari.server.controller.internal.BaseClusterRequest;
import
org.apache.ambari.server.controller.internal.BlueprintConfigurationProcessor;
+import org.apache.ambari.server.controller.internal.ExportBlueprintRequest;
import org.apache.ambari.server.controller.internal.ProvisionAction;
import org.apache.ambari.server.controller.internal.StackDefinition;
import org.apache.ambari.server.state.ConfigHelper;
@@ -61,8 +61,8 @@ public class ClusterTopologyImpl implements ClusterTopology {
private final Set<StackId> stackIds;
private final StackDefinition stack;
+ private final SecurityConfiguration securityConfig;
private Long clusterId;
- private String clusterName;
private final Blueprint blueprint;
private final Configuration configuration;
private final ConfigRecommendationStrategy configRecommendationStrategy;
@@ -75,44 +75,48 @@ public class ClusterTopologyImpl implements ClusterTopology
{
private final Map<String, Set<ResolvedComponent>> resolvedComponents;
private final Setting setting;
- public ClusterTopologyImpl(AmbariContext ambariContext, TopologyRequest
topologyRequest) throws InvalidTopologyException {
+ public ClusterTopologyImpl(
+ AmbariContext ambariContext,
+ ExportBlueprintRequest topologyRequest,
+ StackDefinition stack
+ ) throws InvalidTopologyException {
this.ambariContext = ambariContext;
this.clusterId = topologyRequest.getClusterId();
this.blueprint = topologyRequest.getBlueprint();
this.setting = blueprint.getSetting();
this.configuration = topologyRequest.getConfiguration();
configRecommendationStrategy = ConfigRecommendationStrategy.getDefault();
- provisionAction = topologyRequest instanceof BaseClusterRequest ?
((BaseClusterRequest) topologyRequest).getProvisionAction() :
INSTALL_AND_START; // FIXME
+ securityConfig = blueprint.getSecurity();
+ provisionAction = null;
provisionRequest = null;
defaultPassword = null;
- stackIds = ImmutableSet.copyOf(
- Sets.union(topologyRequest.getStackIds(),
topologyRequest.getBlueprint().getStackIds()));
- stack = ambariContext.composeStacks(stackIds);
+
+ stackIds = topologyRequest.getStackIds();
+ this.stack = stack;
resolvedComponents = ImmutableMap.of();
checkForDuplicateHosts(topologyRequest.getHostGroupInfo());
registerHostGroupInfo(topologyRequest.getHostGroupInfo());
}
- // FIXME 2. replayed request should simply be a provision or scale request
- // FIXME 3. do not create a ClusterTopologyImpl for scale request -- create
for original provision request only
public ClusterTopologyImpl(
AmbariContext ambariContext,
BlueprintBasedClusterProvisionRequest request,
Map<String, Set<ResolvedComponent>> resolvedComponents
) throws InvalidTopologyException {
this.ambariContext = ambariContext;
+ this.clusterId = request.getClusterId();
this.blueprint = request.getBlueprint();
this.configuration = request.getConfiguration();
this.provisionRequest = request;
this.resolvedComponents = resolvedComponents;
- clusterName = request.getClusterName();
configRecommendationStrategy =
Optional.ofNullable(request.getConfigRecommendationStrategy()).orElse(ConfigRecommendationStrategy.getDefault());
provisionAction = request.getProvisionAction();
+ securityConfig = request.getSecurity();
- defaultPassword = provisionRequest.getDefaultPassword();
+ defaultPassword = request.getDefaultPassword();
stackIds = request.getStackIds();
stack = request.getStack();
setting = request.getSetting();
@@ -152,11 +156,6 @@ public class ClusterTopologyImpl implements
ClusterTopology {
}
@Override
- public String getClusterName() {
- return clusterName;
- }
-
- @Override
public void setClusterId(Long clusterId) {
if (this.clusterId != null) {
throw new IllegalStateException(String.format("ClusterID %s already set
in topology, cannot set %s ", this.clusterId, clusterId));
@@ -340,6 +339,11 @@ public class ClusterTopologyImpl implements
ClusterTopology {
}
@Override
+ public SecurityConfiguration getSecurity() {
+ return securityConfig;
+ }
+
+ @Override
public RequestStatusResponse installHost(String hostName, boolean
skipInstallTaskCreate, boolean skipFailure) {
try {
String hostGroupName = getHostGroupForHost(hostName);
diff --git
a/ambari-server/src/main/java/org/apache/ambari/server/topology/DownloadMpacksTask.java
b/ambari-server/src/main/java/org/apache/ambari/server/topology/DownloadMpacksTask.java
index e267174..f869905 100644
---
a/ambari-server/src/main/java/org/apache/ambari/server/topology/DownloadMpacksTask.java
+++
b/ambari-server/src/main/java/org/apache/ambari/server/topology/DownloadMpacksTask.java
@@ -28,6 +28,7 @@ import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.controller.internal.MpackResourceProvider;
import org.apache.ambari.server.controller.spi.Request;
import org.apache.ambari.server.controller.spi.RequestStatus;
+import org.apache.ambari.server.controller.spi.ResourceProvider;
import org.apache.ambari.server.controller.utilities.PropertyHelper;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
@@ -44,10 +45,10 @@ import com.google.common.collect.ImmutableSet;
public class DownloadMpacksTask {
private static final Logger LOG =
LoggerFactory.getLogger(DownloadMpacksTask.class);
- private MpackResourceProvider mpackResourceProvider;
+ private ResourceProvider mpackResourceProvider;
private AmbariMetaInfo ambariMetaInfo;
- public DownloadMpacksTask(MpackResourceProvider mpackResourceProvider,
AmbariMetaInfo ambariMetaInfo) {
+ public DownloadMpacksTask(ResourceProvider mpackResourceProvider,
AmbariMetaInfo ambariMetaInfo) {
this.mpackResourceProvider = mpackResourceProvider;
this.ambariMetaInfo = ambariMetaInfo;
}
diff --git
a/ambari-server/src/main/java/org/apache/ambari/server/topology/LogicalRequest.java
b/ambari-server/src/main/java/org/apache/ambari/server/topology/LogicalRequest.java
index 39c711a..b932353 100644
---
a/ambari-server/src/main/java/org/apache/ambari/server/topology/LogicalRequest.java
+++
b/ambari-server/src/main/java/org/apache/ambari/server/topology/LogicalRequest.java
@@ -30,7 +30,6 @@ import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicLong;
-import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.actionmanager.HostRoleCommand;
import org.apache.ambari.server.actionmanager.HostRoleStatus;
import org.apache.ambari.server.actionmanager.Request;
@@ -71,29 +70,27 @@ public class LogicalRequest extends Request {
private static final AtomicLong hostIdCounter = new AtomicLong(1);
private final static Logger LOG =
LoggerFactory.getLogger(LogicalRequest.class);
+ private final TopologyRequest request;
- public LogicalRequest(Long id, TopologyRequest request, ClusterTopology
topology)
- throws AmbariException {
-
- //todo: abstract usage of controller, etc ...
+ public LogicalRequest(Long id, TopologyRequest request, ClusterTopology
topology) {
super(id, topology.getClusterId(), getController().getClusters());
- setRequestContext(String.format("Logical Request: %s",
request.getDescription()));
-
+ this.request = request;
this.topology = topology;
+
+ setRequestContext(String.format("Logical Request: %s",
request.getDescription()));
createHostRequests(request, topology);
}
public LogicalRequest(Long id, TopologyRequest request, ClusterTopology
topology,
- TopologyLogicalRequestEntity requestEntity) throws
AmbariException {
-
- //todo: abstract usage of controller, etc ...
+ TopologyLogicalRequestEntity requestEntity) {
super(id, topology.getClusterId(), getController().getClusters());
- setRequestContext(String.format("Logical Request: %s",
request.getDescription()));
-
+ this.request = request;
this.topology = topology;
+
+ setRequestContext(String.format("Logical Request: %s",
request.getDescription()));
createHostRequests(topology, requestEntity);
}
@@ -162,6 +159,10 @@ public class LogicalRequest extends Request {
return commands;
}
+ public TopologyRequest.Type getType() {
+ return request.getType();
+ }
+
public Collection<String> getReservedHosts() {
return requestsWithReservedHosts.keySet();
}
diff --git
a/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedState.java
b/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedState.java
index a0b96e6..0d80a9b 100644
---
a/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedState.java
+++
b/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedState.java
@@ -75,13 +75,6 @@ public interface PersistedState {
void registerInTopologyHostInfo(Host host);
/**
- * Returns provision request for a cluster
- * @param clusterId
- * @return
- */
- LogicalRequest getProvisionRequest(long clusterId);
-
- /**
* Remove the given host requests (must belong to the same topology request),
* and also the topology request if it does not have any host requests left.
*/
diff --git
a/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedStateImpl.java
b/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedStateImpl.java
index 5c8c63d..3cc7ae1 100644
---
a/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedStateImpl.java
+++
b/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedStateImpl.java
@@ -183,53 +183,29 @@ public class PersistedStateImpl implements PersistedState
{
}
@Override
- public LogicalRequest getProvisionRequest(long clusterId) {
- Collection<TopologyRequestEntity> entities =
topologyRequestDAO.findByClusterId(clusterId);
- for (TopologyRequestEntity entity : entities) {
- if(TopologyRequest.Type.PROVISION ==
TopologyRequest.Type.valueOf(entity.getAction())) {
- TopologyLogicalRequestEntity logicalRequestEntity =
entity.getTopologyLogicalRequestEntity();
- TopologyRequest replayedRequest = new ReplayedTopologyRequest(entity,
blueprintFactory);
- try {
- ClusterTopology clusterTopology = new
ClusterTopologyImpl(ambariContext, replayedRequest);
- Long logicalId = logicalRequestEntity.getId();
- return logicalRequestFactory.createRequest(logicalId,
replayedRequest, clusterTopology, logicalRequestEntity);
- } catch (InvalidTopologyException e) {
- throw new RuntimeException("Failed to construct cluster topology
while replaying request: " + e, e);
- } catch (AmbariException e) {
- throw new RuntimeException("Failed to construct logical request
during replay: " + e, e);
- }
- }
- }
-
- return null;
- }
-
- @Override
public Map<ClusterTopology, List<LogicalRequest>> getAllRequests() {
- //todo: we only currently support a single request per ambari instance so
there should only
- //todo: be a single cluster topology
- Map<ClusterTopology, List<LogicalRequest>> allRequests = new HashMap<>();
+ Map<ClusterTopology, List<LogicalRequest>> allRequests = new HashMap<>(1);
Collection<TopologyRequestEntity> entities = topologyRequestDAO.findAll();
Map<Long, ClusterTopology> topologyRequests = new HashMap<>();
for (TopologyRequestEntity entity : entities) {
- TopologyRequest replayedRequest = new ReplayedTopologyRequest(entity,
blueprintFactory);
- ClusterTopology clusterTopology =
topologyRequests.get(replayedRequest.getClusterId());
+ TopologyRequest replayedRequest;
+ ClusterTopology clusterTopology =
topologyRequests.get(entity.getClusterId());
if (clusterTopology == null) {
+ ReplayedProvisionRequest provisionRequest = new
ReplayedProvisionRequest(entity, blueprintFactory);
+ replayedRequest = provisionRequest;
try {
- clusterTopology = new ClusterTopologyImpl(ambariContext,
replayedRequest);
+ clusterTopology =
ambariContext.createClusterTopology(provisionRequest);
topologyRequests.put(replayedRequest.getClusterId(),
clusterTopology);
allRequests.put(clusterTopology, new ArrayList<>());
} catch (InvalidTopologyException e) {
throw new RuntimeException("Failed to construct cluster topology
while replaying request: " + e, e);
}
} else {
+ replayedRequest = new ReplayedTopologyRequest(entity,
blueprintFactory);
// ensure all host groups are provided in the combined cluster topology
for (Map.Entry<String, HostGroupInfo> groupInfoEntry :
replayedRequest.getHostGroupInfo().entrySet()) {
- String name = groupInfoEntry.getKey();
- if (! clusterTopology.getHostGroupInfo().containsKey(name)) {
- clusterTopology.getHostGroupInfo().put(name,
groupInfoEntry.getValue());
- }
+
clusterTopology.getHostGroupInfo().putIfAbsent(groupInfoEntry.getKey(),
groupInfoEntry.getValue());
}
}
@@ -242,8 +218,7 @@ public class PersistedStateImpl implements PersistedState {
//todo: until this is fixed, increment the counter for every
recovered logical request
//todo: this will cause gaps in the request id's after recovery
ambariContext.getNextRequestId();
-
allRequests.get(clusterTopology).add(logicalRequestFactory.createRequest(
- logicalId, replayedRequest, clusterTopology,
logicalRequestEntity));
+
allRequests.get(clusterTopology).add(logicalRequestFactory.createRequest(logicalId,
replayedRequest, clusterTopology, logicalRequestEntity));
} catch (AmbariException e) {
throw new RuntimeException("Failed to construct logical request
during replay: " + e, e);
}
@@ -311,7 +286,30 @@ public class PersistedStateImpl implements PersistedState {
return entity;
}
- static final class ReplayedTopologyRequest implements TopologyRequest {
+ // FIXME hard-code
+ static final class ReplayedProvisionRequest extends ReplayedTopologyRequest
implements ProvisionRequest {
+
+ ReplayedProvisionRequest(TopologyRequestEntity entity, BlueprintFactory
blueprintFactory) {
+ super(entity, blueprintFactory);
+ }
+
+ @Override
+ public ConfigRecommendationStrategy getConfigRecommendationStrategy() {
+ return null;
+ }
+
+ @Override
+ public String getDefaultPassword() {
+ return null;
+ }
+
+ @Override
+ public SecurityConfiguration getSecurityConfiguration() {
+ return null;
+ }
+ }
+
+ static class ReplayedTopologyRequest implements TopologyRequest {
private final Long clusterId;
private final Type type;
private final String description;
@@ -320,15 +318,17 @@ public class PersistedStateImpl implements PersistedState
{
private final Map<String, HostGroupInfo> hostGroupInfoMap = new
HashMap<>();
private final ProvisionAction provisionAction;
private final Set<StackId> stackIds;
+ private final Collection<MpackInstance> mpackInstances;
- public ReplayedTopologyRequest(TopologyRequestEntity entity,
BlueprintFactory blueprintFactory) {
+ ReplayedTopologyRequest(TopologyRequestEntity entity, BlueprintFactory
blueprintFactory) {
clusterId = entity.getClusterId();
type = Type.valueOf(entity.getAction());
description = entity.getDescription();
provisionAction = entity.getProvisionAction();
- Collection<MpackInstance> mpackInstances =
entity.getMpackInstances().stream().
- map(e -> MpackInstance.fromEntity(e)).collect(toList());
+ mpackInstances = entity.getMpackInstances().stream()
+ .map(MpackInstance::fromEntity)
+ .collect(toList());
stackIds =
mpackInstances.stream().map(MpackInstance::getStackId).collect(toSet());
try {
@@ -389,6 +389,10 @@ public class PersistedStateImpl implements PersistedState {
return new Configuration(properties, attributes);
}
+ public Collection<MpackInstance> getMpacks() {
+ return mpackInstances;
+ }
+
public ProvisionAction getProvisionAction() {
return provisionAction;
}
diff --git
a/ambari-server/src/main/java/org/apache/ambari/server/topology/ProvisionRequest.java
b/ambari-server/src/main/java/org/apache/ambari/server/topology/ProvisionRequest.java
index 0c53c50..0e82f1d 100644
---
a/ambari-server/src/main/java/org/apache/ambari/server/topology/ProvisionRequest.java
+++
b/ambari-server/src/main/java/org/apache/ambari/server/topology/ProvisionRequest.java
@@ -30,7 +30,6 @@ import org.apache.ambari.server.state.StackId;
*/
public interface ProvisionRequest extends TopologyRequest {
- String getClusterName();
ConfigRecommendationStrategy getConfigRecommendationStrategy();
ProvisionAction getProvisionAction();
String getDefaultPassword();
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 b6830b7..6c19895 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
@@ -48,7 +48,6 @@ import
org.apache.ambari.server.controller.internal.ArtifactResourceProvider;
import org.apache.ambari.server.controller.internal.BaseClusterRequest;
import org.apache.ambari.server.controller.internal.CalculatedStatus;
import org.apache.ambari.server.controller.internal.CredentialResourceProvider;
-import org.apache.ambari.server.controller.internal.MpackResourceProvider;
import org.apache.ambari.server.controller.internal.ProvisionClusterRequest;
import org.apache.ambari.server.controller.internal.RequestImpl;
import org.apache.ambari.server.controller.internal.ScaleClusterRequest;
@@ -145,9 +144,6 @@ public class TopologyManager {
private final Object initializationLock = new Object();
@Inject
- private SecurityConfigurationFactory securityConfigurationFactory;
-
- @Inject
private ConfigureClusterTaskFactory configureClusterTaskFactory;
@Inject
@@ -159,9 +155,6 @@ public class TopologyManager {
@Inject
private TopologyValidatorService topologyValidatorService;
- @Inject
- private ComponentResolver resolver;
-
/**
* A boolean not cached thread-local (volatile) to prevent double-checked
* locking on the synchronized keyword.
@@ -282,22 +275,16 @@ public class TopologyManager {
String rawRequestBody) throws
InvalidTopologyException, AmbariException {
ensureInitialized();
- MpackResourceProvider mpackResourceProvider = (MpackResourceProvider)
-
AmbariContext.getClusterController().ensureResourceProvider(Resource.Type.Mpack);
- new DownloadMpacksTask(mpackResourceProvider,
AmbariServer.getController().getAmbariMetaInfo()).
- downloadMissingMpacks(request.getAllMpacks());
-
- BlueprintBasedClusterProvisionRequest provisionRequest = new
BlueprintBasedClusterProvisionRequest(ambariContext,
securityConfigurationFactory, request.getBlueprint(), request);
- Map<String, Set<ResolvedComponent>> resolved =
resolver.resolveComponents(provisionRequest);
-
- ClusterTopology initialTopology = new ClusterTopologyImpl(ambariContext,
provisionRequest, resolved);
- final String clusterName = request.getClusterName();
- final SecurityConfiguration securityConfiguration =
provisionRequest.getSecurity();
+ ambariContext.downloadMissingMpacks(request.getAllMpacks());
+ ClusterTopology initialTopology =
ambariContext.createClusterTopology(request);
final ClusterTopology topology = request.shouldValidateTopology()
? topologyValidatorService.validate(initialTopology) // FIXME known
stacks validation is too late here
: initialTopology;
+ final String clusterName = request.getClusterName();
+ final SecurityConfiguration securityConfiguration = topology.getSecurity();
+
// get the id prior to creating ambari resources which increments the
counter
final Long provisionId = ambariContext.getNextRequestId();
@@ -335,8 +322,11 @@ public class TopologyManager {
clusterTopologyMap.put(clusterId, topology);
- addClusterConfigRequest(logicalRequest, topology, new
ClusterConfigurationRequest(ambariContext, topology, true,
- stackAdvisorBlueprintProcessor, securityConfiguration.getType() ==
SecurityType.KERBEROS));
+ ClusterConfigurationRequest configurationRequest = new
ClusterConfigurationRequest(ambariContext, topology,
+ stackAdvisorBlueprintProcessor, securityConfiguration.getType() ==
SecurityType.KERBEROS
+ );
+ configurationRequest.setInitialConfigurations();
+ addClusterConfigRequest(logicalRequest, topology, configurationRequest);
// Process the logical request
processRequest(request, topology, logicalRequest);
@@ -367,7 +357,7 @@ public class TopologyManager {
* one.
* @param quickLinksProfileJson the quicklinks profile in Json format
*/
- void saveOrUpdateQuickLinksProfile(String quickLinksProfileJson) {
+ private void saveOrUpdateQuickLinksProfile(String quickLinksProfileJson) {
SettingEntity settingEntity =
settingDAO.findByName(QuickLinksProfile.SETTING_NAME_QUICKLINKS_PROFILE);
// create new
if (null == settingEntity) {
@@ -391,7 +381,7 @@ public class TopologyManager {
private void submitCredential(String clusterName, Credential credential) {
ResourceProvider provider =
-
ambariContext.getClusterController().ensureResourceProvider(Resource.Type.Credential);
+
AmbariContext.getClusterController().ensureResourceProvider(Resource.Type.Credential);
Map<String, Object> properties = new HashMap<>();
properties.put(CredentialResourceProvider.CREDENTIAL_CLUSTER_NAME_PROPERTY_ID,
clusterName);
@@ -586,14 +576,13 @@ public class TopologyManager {
throws InvalidTopologyException, AmbariException {
// persist quick links profile if present
- if (null != request.getQuickLinksProfileJson()) {
- saveOrUpdateQuickLinksProfile(request.getQuickLinksProfileJson());
+ String quickLinksProfileJson = request.getQuickLinksProfileJson();
+ if (null != quickLinksProfileJson) {
+ saveOrUpdateQuickLinksProfile(quickLinksProfileJson);
}
// create and persist topology request
- LogicalRequest logicalRequest = processAndPersistTopologyRequest(request,
topology, logicalRequestId);
-
- return logicalRequest;
+ return processAndPersistTopologyRequest(request, topology,
logicalRequestId);
}
@@ -1005,16 +994,18 @@ public class TopologyManager {
boolean configChecked = false;
for (Map.Entry<ClusterTopology, List<LogicalRequest>> requestEntry :
persistedRequests.entrySet()) {
ClusterTopology topology = requestEntry.getKey();
- clusterTopologyMap.put(topology.getClusterId(), topology);
+ Long clusterId = topology.getClusterId();
+ clusterTopologyMap.put(clusterId, topology);
// update provision request cache
- LogicalRequest provisionRequest =
persistedState.getProvisionRequest(topology.getClusterId());
- if(provisionRequest != null) {
-
clusterProvisionWithBlueprintCreateRequests.put(topology.getClusterId(),
provisionRequest);
-
clusterProvisionWithBlueprintCreationFinished.put(topology.getClusterId(),
-
isLogicalRequestFinished(clusterProvisionWithBlueprintCreateRequests.get(topology.getClusterId())));
- }
+ LogicalRequest provisionRequest = null;
for (LogicalRequest logicalRequest : requestEntry.getValue()) {
+ if (logicalRequest.getType() == TopologyRequest.Type.PROVISION) {
+ provisionRequest = logicalRequest;
+ boolean finished =
isLogicalRequestFinished(clusterProvisionWithBlueprintCreateRequests.get(clusterId));
+ clusterProvisionWithBlueprintCreateRequests.put(clusterId,
logicalRequest);
+ clusterProvisionWithBlueprintCreationFinished.put(clusterId,
finished);
+ }
allRequests.put(logicalRequest.getRequestId(), logicalRequest);
if (logicalRequest.hasPendingHostRequests()) {
outstandingRequests.add(logicalRequest);
@@ -1040,18 +1031,18 @@ public class TopologyManager {
if (!configChecked) {
configChecked = true;
- if (!ambariContext.isTopologyResolved(topology.getClusterId())) {
+ if (!ambariContext.isTopologyResolved(clusterId)) {
if (provisionRequest == null) {
LOG.info("TopologyManager.replayRequests: no config with
TOPOLOGY_RESOLVED found, but provision request missing, skipping cluster config
request");
} else if (provisionRequest.isFinished()) {
LOG.info("TopologyManager.replayRequests: no config with
TOPOLOGY_RESOLVED found, but provision request is finished, skipping cluster
config request");
} else {
LOG.info("TopologyManager.replayRequests: no config with
TOPOLOGY_RESOLVED found, adding cluster config request");
- ClusterConfigurationRequest configRequest = new
ClusterConfigurationRequest(ambariContext, topology, false,
stackAdvisorBlueprintProcessor);
+ ClusterConfigurationRequest configRequest = new
ClusterConfigurationRequest(ambariContext, topology,
stackAdvisorBlueprintProcessor);
addClusterConfigRequest(provisionRequest, topology, configRequest);
}
} else {
- getOrCreateTopologyTaskExecutor(topology.getClusterId()).start();
+ getOrCreateTopologyTaskExecutor(clusterId).start();
}
}
}
diff --git
a/ambari-server/src/test/java/org/apache/ambari/server/api/query/render/ClusterBlueprintRendererTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/api/query/render/ClusterBlueprintRendererTest.java
index 1675a5f..c17c90d 100644
---
a/ambari-server/src/test/java/org/apache/ambari/server/api/query/render/ClusterBlueprintRendererTest.java
+++
b/ambari-server/src/test/java/org/apache/ambari/server/api/query/render/ClusterBlueprintRendererTest.java
@@ -138,7 +138,7 @@ public class ClusterBlueprintRendererTest {
PowerMock.mockStatic(AmbariContext.class);
PowerMock.mockStatic(AmbariServer.class);
expect(AmbariContext.getClusterController()).andReturn(clusterController).anyTimes();
- expect(AmbariContext.getController()).andReturn(controller).anyTimes();
+ expect(ambariContext.getController()).andReturn(controller).anyTimes();
expect(AmbariServer.getController()).andReturn(controller).anyTimes();
Map<String, String> clusterTypeProps = new HashMap<>();
diff --git
a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java
index 1c9e28a..8e4f80c 100644
---
a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java
+++
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java
@@ -188,6 +188,7 @@ public class BlueprintConfigurationProcessorTest extends
EasyMockSupport {
expect(ambariContext.isClusterKerberosEnabled(1)).andReturn(true).once();
expect(ambariContext.getClusterName(1L)).andReturn("clusterName").anyTimes();
+ expect(ambariContext.getController()).andReturn(controller).anyTimes();
PowerMock.mockStatic(AmbariServer.class);
expect(AmbariServer.getController()).andReturn(controller).anyTimes();
PowerMock.replay(AmbariServer.class);
@@ -8263,9 +8264,7 @@ public class BlueprintConfigurationProcessorTest extends
EasyMockSupport {
BlueprintBasedClusterProvisionRequest request = new
BlueprintBasedClusterProvisionRequest(ambariContext, securityFactory, bp,
topologyRequestMock);
- ClusterTopologyImpl clusterTopology = new
ClusterTopologyImpl(ambariContext, request, resolvedComponents);
- clusterTopology.setClusterId(1L);
- return clusterTopology;
+ return new ClusterTopologyImpl(ambariContext, request, resolvedComponents);
}
private class TestHostGroup {
diff --git
a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ExportBlueprintRequestTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ExportBlueprintRequestTest.java
index 52dc338..aa6a7c2 100644
---
a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ExportBlueprintRequestTest.java
+++
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ExportBlueprintRequestTest.java
@@ -23,14 +23,12 @@ import static org.easymock.EasyMock.anyString;
import static org.easymock.EasyMock.createNiceMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.reset;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.powermock.api.easymock.PowerMock.mockStatic;
-import java.lang.reflect.Field;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
@@ -49,7 +47,6 @@ import org.apache.ambari.server.state.StackInfo;
import org.apache.ambari.server.topology.Blueprint;
import org.apache.ambari.server.topology.HostGroup;
import org.apache.ambari.server.topology.HostGroupInfo;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -57,32 +54,29 @@ import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+
/**
* ExportBlueprintRequest unit tests.
*/
-@SuppressWarnings("unchecked")
@RunWith(PowerMockRunner.class)
@PrepareForTest({ExportBlueprintRequest.ExportedHostGroup.class})
public class ExportBlueprintRequestTest {
private static final String CLUSTER_NAME = "c1";
private static final String CLUSTER_ID = "2";
- private AmbariManagementController controller =
createNiceMock(AmbariManagementController.class);
-
@Before
public void setupTest() throws Exception {
- Field f = ExportBlueprintRequest.class.getDeclaredField("controller");
- f.setAccessible(true);
- f.set(null, controller);
-
- AmbariMetaInfo metainfo = createNiceMock(AmbariMetaInfo.class);
- expect(controller.getAmbariMetaInfo()).andReturn(metainfo).anyTimes();
+ AmbariManagementController controller =
createNiceMock(AmbariManagementController.class);
+ AmbariMetaInfo metaInfo = createNiceMock(AmbariMetaInfo.class);
+ expect(controller.getAmbariMetaInfo()).andReturn(metaInfo).anyTimes();
StackInfo stackInfo = createNiceMock(StackInfo.class);
- expect(metainfo.getStack(new StackId("TEST", "1.0"))).andReturn(stackInfo);
+ expect(metaInfo.getStack(new StackId("TEST", "1.0"))).andReturn(stackInfo);
expect(stackInfo.getServices()).andReturn(Collections.emptySet()).anyTimes();
expect(stackInfo.getProperties()).andReturn(Collections.emptyList()).anyTimes();
- replay(controller, metainfo, stackInfo);
+ replay(controller, metaInfo, stackInfo);
// This can save precious time
mockStatic(InetAddress.class);
@@ -90,28 +84,76 @@ public class ExportBlueprintRequestTest {
PowerMock.replay(InetAddress.class);
}
- @After
- public void tearDown() {
- reset(controller);
- }
-
//todo: test configuration processing
@Test
-
- public void testExport_noConfigs() throws Exception {
+ public void clusterWithStack() {
+ // GIVEN
Resource clusterResource = new ResourceImpl(Resource.Type.Cluster);
clusterResource.setProperty(ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID,
CLUSTER_NAME);
clusterResource.setProperty(ClusterResourceProvider.CLUSTER_ID_PROPERTY_ID,
CLUSTER_ID);
clusterResource.setProperty(ClusterResourceProvider.CLUSTER_VERSION_PROPERTY_ID,
"TEST-1.0");
+ TreeNode<Resource> clusterNode = new TreeNodeImpl<>(null, clusterResource,
"cluster");
+ // add empty config child resource
+ Resource configResource = new ResourceImpl(Resource.Type.Configuration);
+ clusterNode.addChild(configResource, "configurations");
+ clusterNode.addChild(new ResourceImpl(Resource.Type.Host), "hosts");
+
+ // WHEN
+ ExportBlueprintRequest exportBlueprintRequest = new
ExportBlueprintRequest(clusterNode);
+
+ // THEN
+ assertEquals(CLUSTER_NAME, exportBlueprintRequest.getClusterName());
+ assertEquals(ImmutableSet.of(new StackId("TEST", "1.0")),
exportBlueprintRequest.getStackIds());
+ }
+
+ @Test
+ public void clusterWithMpacks() {
+ Resource clusterResource = new ResourceImpl(Resource.Type.Cluster);
+
clusterResource.setProperty(ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID,
CLUSTER_NAME);
+
+ TreeNode<Resource> clusterNode = new TreeNodeImpl<>(null, clusterResource,
"cluster");
+ // add empty config child resource
+ Resource configResource = new ResourceImpl(Resource.Type.Configuration);
+ clusterNode.addChild(configResource, "configurations");
+
+ ResourceImpl serviceGroups = new ResourceImpl(Resource.Type.ServiceGroup);
+ TreeNode<Resource> serviceGroupsNode = clusterNode.addChild(serviceGroups,
"servicegroups");
+ String mpackName = "HDPCORE";
+ String mpackVersion = "2.0";
+ ResourceImpl serviceGroupResource = new
ResourceImpl(Resource.Type.ServiceGroup);
+ serviceGroupsNode.addChild(serviceGroupResource, mpackName);
+
serviceGroupResource.getPropertiesMap().putAll(ImmutableMap.of(ServiceGroupResourceProvider.RESPONSE_KEY,
ImmutableMap.of(
+ ServiceGroupResourceProvider.SERVICE_GROUP_NAME, mpackName,
+ ServiceGroupResourceProvider.MPACK_NAME, mpackName,
+ ServiceGroupResourceProvider.MPACK_VERSION, mpackVersion
+ )));
+ }
+
+ @Test
+ public void testExport_noConfigs() {
+ Resource clusterResource = new ResourceImpl(Resource.Type.Cluster);
+
clusterResource.setProperty(ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID,
CLUSTER_NAME);
+
clusterResource.setProperty(ClusterResourceProvider.CLUSTER_ID_PROPERTY_ID,
CLUSTER_ID);
+
clusterResource.setProperty(ClusterResourceProvider.CLUSTER_VERSION_PROPERTY_ID,
"TEST-1.0");
TreeNode<Resource> clusterNode = new TreeNodeImpl<>(null, clusterResource,
"cluster");
// add empty config child resource
Resource configResource = new ResourceImpl(Resource.Type.Configuration);
clusterNode.addChild(configResource, "configurations");
- clusterNode.addChild(new ResourceImpl(Resource.Type.ServiceGroup),
"servicegroups");
+ ResourceImpl serviceGroups = new ResourceImpl(Resource.Type.ServiceGroup);
+ TreeNode<Resource> serviceGroupsNode = clusterNode.addChild(serviceGroups,
"servicegroups");
+ String mpackName = "HDPCORE";
+ String mpackVersion = "2.0";
+ ResourceImpl serviceGroupResource = new
ResourceImpl(Resource.Type.ServiceGroup);
+ serviceGroupsNode.addChild(serviceGroupResource, mpackName);
+
serviceGroupResource.getPropertiesMap().putAll(ImmutableMap.of(ServiceGroupResourceProvider.RESPONSE_KEY,
ImmutableMap.of(
+ ServiceGroupResourceProvider.SERVICE_GROUP_NAME, mpackName,
+ ServiceGroupResourceProvider.MPACK_NAME, mpackName,
+ ServiceGroupResourceProvider.MPACK_VERSION, mpackVersion
+ )));
Resource hostsResource = new ResourceImpl(Resource.Type.Host);
Resource host1Resource = new ResourceImpl(Resource.Type.Host);
@@ -140,6 +182,7 @@ public class ExportBlueprintRequestTest {
// assertions
assertEquals(CLUSTER_NAME, exportBlueprintRequest.getClusterName());
+ assertEquals(ImmutableSet.of(new StackId(mpackName, mpackVersion)),
exportBlueprintRequest.getStackIds());
Blueprint bp = exportBlueprintRequest.getBlueprint();
assertEquals("exported-blueprint", bp.getName());
Map<String, HostGroup> hostGroups = bp.getHostGroups();
diff --git
a/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosDescriptorUpdateHelperTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosDescriptorUpdateHelperTest.java
index f267413..b298aae 100644
---
a/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosDescriptorUpdateHelperTest.java
+++
b/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosDescriptorUpdateHelperTest.java
@@ -50,6 +50,7 @@ import org.apache.ambari.server.orm.DBAccessor;
import org.apache.ambari.server.orm.dao.ExtensionLinkDAO;
import org.apache.ambari.server.orm.entities.MetainfoEntity;
import org.apache.ambari.server.orm.entities.StackEntity;
+import org.apache.ambari.server.registry.RegistryManager;
import org.apache.ambari.server.resources.RootLevelSettingsManagerFactory;
import org.apache.ambari.server.scheduler.ExecutionScheduler;
import org.apache.ambari.server.scheduler.ExecutionSchedulerImpl;
@@ -57,11 +58,17 @@ import
org.apache.ambari.server.security.encryption.CredentialStoreService;
import org.apache.ambari.server.stack.StackManager;
import org.apache.ambari.server.stack.StackManagerFactory;
import org.apache.ambari.server.stack.StackManagerMock;
+import org.apache.ambari.server.state.ClusterSettingFactory;
import org.apache.ambari.server.state.Clusters;
import org.apache.ambari.server.state.ServiceComponentHostFactory;
+import org.apache.ambari.server.state.ServiceGroupFactory;
import org.apache.ambari.server.state.stack.OsFamily;
import org.apache.ambari.server.testutils.PartialNiceMockBinder;
+import org.apache.ambari.server.topology.ComponentResolver;
+import org.apache.ambari.server.topology.DefaultStackFactory;
import org.apache.ambari.server.topology.PersistedState;
+import org.apache.ambari.server.topology.StackComponentResolver;
+import org.apache.ambari.server.topology.StackFactory;
import org.easymock.EasyMock;
import org.easymock.EasyMockSupport;
import org.junit.Test;
@@ -103,8 +110,6 @@ public class KerberosDescriptorUpdateHelperTest extends
EasyMockSupport {
PartialNiceMockBinder.newBuilder(KerberosDescriptorUpdateHelperTest.this).addConfigsBindings()
.addFactoriesInstallBinding().build().configure(binder());
- install(new FactoryModuleBuilder().build(StackManagerFactory.class));
-
bind(Clusters.class).toInstance(createNiceMock(Clusters.class));
bind(DBAccessor.class).toInstance(createNiceMock(DBAccessor.class));
bind(EntityManager.class).toInstance(createNiceMock(EntityManager.class));
@@ -112,7 +117,10 @@ public class KerberosDescriptorUpdateHelperTest extends
EasyMockSupport {
bind(Configuration.class).toInstance(configuration);
bind(ExtensionLinkDAO.class).toInstance(createNiceMock(ExtensionLinkDAO.class));
bind(MpackManagerFactory.class).toInstance(createNiceMock(MpackManagerFactory.class));
+
bind(ServiceGroupFactory.class).toInstance(createNiceMock(ServiceGroupFactory.class));
bind(RootLevelSettingsManagerFactory.class).toInstance(createNiceMock(RootLevelSettingsManagerFactory.class));
+
bind(RegistryManager.class).toInstance(createNiceMock(RegistryManager.class));
+
bind(ClusterSettingFactory.class).toInstance(createNiceMock(ClusterSettingFactory.class));
bind(PersistedState.class).toInstance(createNiceMock(PersistedState.class));
bind(HostRoleCommandFactory.class).to(HostRoleCommandFactoryImpl.class);
bind(ActionDBAccessor.class).to(ActionDBAccessorImpl.class);
@@ -127,6 +135,8 @@ public class KerberosDescriptorUpdateHelperTest extends
EasyMockSupport {
bind(CredentialStoreService.class).toInstance(createNiceMock(CredentialStoreService.class));
bind(AmbariManagementController.class).toInstance(createNiceMock(AmbariManagementController.class));
bind(ExecutionScheduler.class).to(ExecutionSchedulerImpl.class);
+ bind(ComponentResolver.class).to(StackComponentResolver.class);
+ bind(StackFactory.class).to(DefaultStackFactory.class);
}
});
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 7e42c5e..97da23b 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
@@ -46,6 +46,7 @@ import java.util.stream.Stream;
import org.apache.ambari.annotations.Experimental;
import org.apache.ambari.annotations.ExperimentalFeature;
+import org.apache.ambari.server.StackAccessException;
import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.controller.AmbariManagementController;
import org.apache.ambari.server.controller.ClusterRequest;
@@ -58,6 +59,8 @@ 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.MpackResourceProvider;
+import org.apache.ambari.server.controller.internal.RequestStatusImpl;
import
org.apache.ambari.server.controller.internal.ServiceGroupResourceProvider;
import org.apache.ambari.server.controller.internal.ServiceResourceProvider;
import org.apache.ambari.server.controller.internal.Stack;
@@ -82,9 +85,11 @@ import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.powermock.api.easymock.PowerMock;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
+import com.google.inject.util.Providers;
/**
* AmbariContext unit tests
@@ -149,7 +154,7 @@ public class AmbariContextTest {
Class<AmbariContext> clazz = AmbariContext.class;
Field f = clazz.getDeclaredField("controller");
f.setAccessible(true);
- f.set(null, controller);
+ f.set(context, Providers.of(controller));
f = clazz.getDeclaredField("clusterController");
f.setAccessible(true);
@@ -262,6 +267,7 @@ public class AmbariContextTest {
expect(controller.getAmbariMetaInfo()).andReturn(metaInfo).anyTimes();
expect(metaInfo.getClusterProperties()).andReturn(emptySet()).anyTimes();
+ expect(clusters.getCluster(CLUSTER_ID)).andReturn(cluster).anyTimes();
expect(clusters.getCluster(CLUSTER_NAME)).andReturn(cluster).anyTimes();
expect(clusters.getClusterById(CLUSTER_ID)).andReturn(cluster).anyTimes();
expect(clusters.getHost(HOST1)).andReturn(host1).anyTimes();
@@ -537,7 +543,7 @@ public class AmbariContextTest {
replayAll();
// verify that wait returns successfully with empty updated list passed in
- context.waitForConfigurationResolution(CLUSTER_NAME,
Collections.emptySet());
+ context.waitForConfigurationResolution(CLUSTER_ID, Collections.emptySet());
}
@Test
@@ -571,7 +577,7 @@ public class AmbariContextTest {
// verify that wait returns successfully with non-empty list
// with all configuration types tagged as "TOPOLOGY_RESOLVED"
- context.waitForConfigurationResolution(CLUSTER_NAME,
testUpdatedConfigTypes);
+ context.waitForConfigurationResolution(CLUSTER_ID, testUpdatedConfigTypes);
}
@Test
@@ -677,4 +683,36 @@ public class AmbariContextTest {
// Then
assertFalse(topologyResolved);
}
+
+ @Test
+ public void testProvisionCluster_downloadMissingMpack() throws Exception {
+ PowerMock.mockStatic(AmbariContext.class);
+
expect(AmbariContext.getClusterController()).andReturn(clusterController).anyTimes();
+
+ // given
+ MpackInstance mpack1 = new MpackInstance("HDPCORE", "HDPCORE", "1.0.0.0",
"http://mpacks.org/hdpcore", Configuration.createEmpty());
+ MpackInstance mpack2 = new MpackInstance("HDF", "HDF", "3.3.0",
"http://mpacks.org/hdf", Configuration.createEmpty());
+ expect(metaInfo.getStack(mpack1.getStackId())).andReturn(null);
+ expect(metaInfo.getStack(mpack2.getStackId())).andThrow(new
StackAccessException("Testing missing stack"));
+
+ MpackResourceProvider mpackResourceProvider =
createNiceMock(MpackResourceProvider.class);
+
expect(clusterController.ensureResourceProvider(Resource.Type.Mpack)).andReturn(mpackResourceProvider).anyTimes();
+
+ Capture<Request> mpackRequestCapture = Capture.newInstance();
+ expect(mpackResourceProvider.createResources(capture(mpackRequestCapture)))
+ .andReturn(new RequestStatusImpl(null, null, null))
+ .once();
+
+ PowerMock.replay(AmbariContext.class);
+ replay(clusterController, metaInfo, mpackResourceProvider);
+
+ // when
+ context.downloadMissingMpacks(ImmutableSet.of(mpack1, mpack2));
+
+ // then
+ Set<Map<String, Object>> requests =
mpackRequestCapture.getValue().getProperties();
+ assertEquals(1, requests.size());
+ assertEquals(mpack2.getUrl(),
requests.iterator().next().get(MpackResourceProvider.MPACK_URI));
+ }
+
}
diff --git
a/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterConfigurationRequestTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterConfigurationRequestTest.java
index 354bf47..d32bc92 100644
---
a/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterConfigurationRequestTest.java
+++
b/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterConfigurationRequestTest.java
@@ -84,7 +84,7 @@ import com.google.common.collect.Maps;
@PrepareForTest({AmbariContext.class})
public class ClusterConfigurationRequestTest {
- public static final Long CLUSTER_ID = Long.valueOf(1);
+ public static final Long CLUSTER_ID = 1L;
public static final String CLUSTER_NAME = "testCluster";
public static final List<String> SERVICE_NAMES = ImmutableList.of("HDFS",
"KERBEROS", "ZOOKEEPER");
@@ -136,7 +136,6 @@ public class ClusterConfigurationRequestTest {
/**
* testConfigType config type should be in updatedConfigTypes, as no custom
property in Blueprint
* ==> Kerberos config property should be updated
- * @throws Exception
*/
@Test
public void
testProcessWithKerberos_UpdateKererosConfigProperty_WithNoCustomValue() throws
Exception {
@@ -150,7 +149,6 @@ public class ClusterConfigurationRequestTest {
/**
* testConfigType config type should be in updatedConfigTypes, as
testProperty in Blueprint is equal to stack
* default ==> Kerberos config property should be updated
- * @throws Exception
*/
@Test
public void
testProcessWithKerberos_UpdateKererosConfigProperty_WithCustomValueEqualToStackDefault()
throws
@@ -167,7 +165,6 @@ public class ClusterConfigurationRequestTest {
/**
* testConfigType config type shouldn't be in updatedConfigTypes, as
testProperty in Blueprint is different that
* stack default (custom value) ==> Kerberos config property shouldn't be
updated
- * @throws Exception
*/
@Test
public void
testProcessWithKerberos_DontUpdateKererosConfigProperty_WithCustomValueDifferentThanStackDefault()
throws
@@ -184,7 +181,6 @@ public class ClusterConfigurationRequestTest {
* testConfigType config type shouldn't be in updatedConfigTypes, as
testProperty in Blueprint is a custom value
* (no default value in stack for testProperty)
* ==> Kerberos config property shouldn't be updated
- * @throws Exception
*/
@Test
public void
testProcessWithKerberos_DontUpdateKererosConfigProperty_WithCustomValueNoStackDefault()
throws Exception {
@@ -242,8 +238,7 @@ public class ClusterConfigurationRequestTest {
}
PowerMock.mockStatic(AmbariContext.class);
- AmbariContext.getController();
- expectLastCall().andReturn(controller).anyTimes();
+ expect(ambariContext.getController()).andReturn(controller).anyTimes();
expect(controller.getClusters()).andReturn(clusters).anyTimes();
expect(controller.getKerberosHelper()).andReturn(kerberosHelper).times(2);
@@ -277,12 +272,11 @@ public class ClusterConfigurationRequestTest {
expect(topology.getConfiguration()).andReturn(blueprintConfig).anyTimes();
expect(topology.getHostGroupInfo()).andReturn(Collections.emptyMap()).anyTimes();
expect(topology.getClusterId()).andReturn(CLUSTER_ID).anyTimes();
- expect(topology.getClusterName()).andReturn(CLUSTER_NAME).anyTimes();
expect(topology.getHostGroupsForComponent(anyString())).andReturn(Collections.emptyList())
.anyTimes();
expect(ambariContext.getConfigHelper()).andReturn(configHelper).anyTimes();
-
expect(ambariContext.getClusterName(Long.valueOf(1))).andReturn(CLUSTER_NAME).anyTimes();
+
expect(ambariContext.getClusterName(CLUSTER_ID)).andReturn(CLUSTER_NAME).anyTimes();
expect(ambariContext.createConfigurationRequests(EasyMock.anyObject())).andReturn(Collections
.emptyList()).anyTimes();
Set<ServiceResponse> services = IntStream.range(0,
SERVICE_NAMES.size()).boxed().map(
@@ -305,9 +299,9 @@ public class ClusterConfigurationRequestTest {
expect(kerberosHelper.getServiceConfigurationUpdates(anyObject(Cluster.class),
EasyMock.anyObject(),
EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject(),
anyBoolean(), eq(false))).andReturn(kerberosConfig).once();
- Capture<? extends String> captureClusterName = newCapture(CaptureType.ALL);
+ Capture<Long> captureClusterId = newCapture(CaptureType.ALL);
Capture<? extends Set<String>> captureUpdatedConfigTypes =
newCapture(CaptureType.ALL);
- ambariContext.waitForConfigurationResolution(capture(captureClusterName),
capture
+ ambariContext.waitForConfigurationResolution(capture(captureClusterId),
capture
(captureUpdatedConfigTypes));
expectLastCall();
@@ -315,14 +309,13 @@ public class ClusterConfigurationRequestTest {
ambariContext, AmbariContext.class, configHelper);
ClusterConfigurationRequest clusterConfigurationRequest = new
ClusterConfigurationRequest(
- ambariContext, topology, false, stackAdvisorBlueprintProcessor, true);
+ ambariContext, topology, stackAdvisorBlueprintProcessor, true);
clusterConfigurationRequest.process();
verify(blueprint, topology, ambariContext, controller, kerberosHelper,
configHelper);
- String clusterName = captureClusterName.getValue();
- assertEquals(CLUSTER_NAME, clusterName);
+ assertEquals(CLUSTER_ID, captureClusterId.getValue());
return captureUpdatedConfigTypes;
}
@@ -334,7 +327,7 @@ public class ClusterConfigurationRequestTest {
new HashMap<>());
PowerMock.mockStatic(AmbariContext.class);
- AmbariContext.getController();
+ ambariContext.getController();
expectLastCall().andReturn(controller).anyTimes();
expect(controller.getClusters()).andReturn(clusters).anyTimes();
@@ -378,7 +371,7 @@ public class ClusterConfigurationRequestTest {
AmbariContext.class, configHelper);
ClusterConfigurationRequest clusterConfigurationRequest = new
ClusterConfigurationRequest(
- ambariContext, topology, false, stackAdvisorBlueprintProcessor);
+ ambariContext, topology, stackAdvisorBlueprintProcessor);
clusterConfigurationRequest.process();
verify(blueprint, topology, ambariContext, controller, configHelper);
@@ -417,7 +410,7 @@ public class ClusterConfigurationRequestTest {
EasyMock.replay(stack, blueprint, topology, ambariContext, configHelper);
// WHEN
- new ClusterConfigurationRequest(ambariContext, topology, false,
stackAdvisorBlueprintProcessor);
+ new ClusterConfigurationRequest(ambariContext, topology,
stackAdvisorBlueprintProcessor);
// THEN
assertFalse("YARN service not present in topology config thus 'yarn-site'
config type should be removed from config.",
configuration.getFullProperties().containsKey("yarn-site"));
assertTrue("HDFS service is present in topology host group config thus
'hdfs-site' config type should be left in the config.",
configuration.getFullAttributes().containsKey("hdfs-site"));
@@ -467,7 +460,7 @@ public class ClusterConfigurationRequestTest {
// When
- new ClusterConfigurationRequest(ambariContext, topology, false,
stackAdvisorBlueprintProcessor);
+ new ClusterConfigurationRequest(ambariContext, topology,
stackAdvisorBlueprintProcessor);
// Then
assertTrue("'cluster-env' config type should not be removed from
configuration.", configuration.getFullProperties().containsKey("cluster-env"));
@@ -545,6 +538,7 @@ public class ClusterConfigurationRequestTest {
hostGroupInfoMap.put("hg1", hg1);
expect(topology.getAmbariContext()).andReturn(ambariContext).anyTimes();
+ expect(topology.getClusterId()).andReturn(CLUSTER_ID).anyTimes();
expect(topology.getConfiguration()).andReturn(configuration).anyTimes();
expect(topology.getBlueprint()).andReturn(blueprint).anyTimes();
expect(topology.getHostGroupInfo()).andReturn(hostGroupInfoMap).anyTimes();
@@ -563,6 +557,7 @@ public class ClusterConfigurationRequestTest {
expect(stack.getAllConfigurationTypes("ZOOKEEPER")).andReturn(ImmutableSet.of("zoo.cfg",
"zookeeper-env"));
expect(stack.getAllConfigurationTypes("HDFS")).andReturn(ImmutableSet.of("hdfs-site",
"hadoop-env"));
+
expect(ambariContext.getClusterName(CLUSTER_ID)).andReturn(CLUSTER_NAME).anyTimes();
expect(ambariContext.getConfigHelper()).andReturn(configHelper).anyTimes();
expect(ambariContext.getServices(anyString())).andReturn(serviceResponses).anyTimes();
Capture<ClusterRequest> clusterRequestCapture =
Capture.newInstance(CaptureType.ALL);
@@ -575,7 +570,7 @@ public class ClusterConfigurationRequestTest {
// WHEN
ClusterConfigurationRequest request =
- new ClusterConfigurationRequest(ambariContext, topology, false,
stackAdvisorBlueprintProcessor);
+ new ClusterConfigurationRequest(ambariContext, topology,
stackAdvisorBlueprintProcessor);
request.process();
// THEN
@@ -584,7 +579,7 @@ public class ClusterConfigurationRequestTest {
"zookeeper-env", Optional.of(0L),
"hadoop-env", Optional.of(1L),
"hdfs-site", Optional.of(1L),
- "cluster-env", Optional.<Long>empty()
+ "cluster-env", Optional.empty()
);
Set<String> clusterConfigTypes = new HashSet<>();
clusterRequestCapture.getValues().forEach(
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 b8dc695..5f0e4e3 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
@@ -90,7 +90,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
@RunWith(PowerMockRunner.class)
-@PrepareForTest({ AmbariContext.class, AmbariServer.class })
+@PrepareForTest({ AmbariServer.class })
public class ClusterDeployWithStartOnlyTest extends EasyMockSupport {
private static final String CLUSTER_NAME = "test-cluster";
private static final long CLUSTER_ID = 1;
@@ -361,9 +361,7 @@ public class ClusterDeployWithStartOnlyTest extends
EasyMockSupport {
PowerMock.mockStatic(AmbariServer.class);
expect(AmbariServer.getController()).andReturn(managementController).anyTimes();
PowerMock.replay(AmbariServer.class);
- PowerMock.mockStatic(AmbariContext.class);
-
expect(AmbariContext.getClusterController()).andReturn(clusterController).anyTimes();
- PowerMock.replay(AmbariContext.class);
+
expect(ambariContext.getClusterController()).andReturn(clusterController).anyTimes();
expect(clusterController.ensureResourceProvider(Resource.Type.Mpack)).andReturn(mpackResourceProvider).anyTimes();
expect(clusterController.ensureResourceProvider(Resource.Type.Artifact)).andReturn(artifactResourceProvider).anyTimes();
RequestStatus completedStatus = createNiceMock(RequestStatus.class);
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 50d888d..9ea744f 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
@@ -91,7 +91,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
@RunWith(PowerMockRunner.class)
-@PrepareForTest({ AmbariContext.class, AmbariServer.class })
+@PrepareForTest({ AmbariServer.class })
public class ClusterInstallWithoutStartOnComponentLevelTest extends
EasyMockSupport {
private static final String CLUSTER_NAME = "test-cluster";
private static final long CLUSTER_ID = 1;
@@ -365,9 +365,7 @@ public class ClusterInstallWithoutStartOnComponentLevelTest
extends EasyMockSupp
PowerMock.mockStatic(AmbariServer.class);
expect(AmbariServer.getController()).andReturn(managementController).anyTimes();
PowerMock.replay(AmbariServer.class);
- PowerMock.mockStatic(AmbariContext.class);
-
expect(AmbariContext.getClusterController()).andReturn(clusterController).anyTimes();
- PowerMock.replay(AmbariContext.class);
+
expect(ambariContext.getClusterController()).andReturn(clusterController).anyTimes();
expect(clusterController.ensureResourceProvider(Resource.Type.Mpack)).andReturn(mpackResourceProvider).anyTimes();
expect(clusterController.ensureResourceProvider(Resource.Type.Artifact)).andReturn(artifactResourceProvider).anyTimes();
RequestStatus completedStatus = createNiceMock(RequestStatus.class);
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 e980189..295817b 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
@@ -92,7 +92,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
@RunWith(PowerMockRunner.class)
-@PrepareForTest({ AmbariContext.class, AmbariServer.class })
+@PrepareForTest({ AmbariServer.class })
public class ClusterInstallWithoutStartTest extends EasyMockSupport {
private static final String CLUSTER_NAME = "test-cluster";
@@ -368,9 +368,7 @@ public class ClusterInstallWithoutStartTest extends
EasyMockSupport {
PowerMock.mockStatic(AmbariServer.class);
expect(AmbariServer.getController()).andReturn(managementController).anyTimes();
PowerMock.replay(AmbariServer.class);
- PowerMock.mockStatic(AmbariContext.class);
-
expect(AmbariContext.getClusterController()).andReturn(clusterController).anyTimes();
- PowerMock.replay(AmbariContext.class);
+
expect(ambariContext.getClusterController()).andReturn(clusterController).anyTimes();
expect(clusterController.ensureResourceProvider(Resource.Type.Mpack)).andReturn(mpackResourceProvider).anyTimes();
expect(clusterController.ensureResourceProvider(Resource.Type.Artifact)).andReturn(artifactResourceProvider).anyTimes();
RequestStatus completedStatus = createNiceMock(RequestStatus.class);
diff --git
a/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterTopologyImplTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterTopologyImplTest.java
index ff9acbb..bab1b0c 100644
---
a/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterTopologyImplTest.java
+++
b/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterTopologyImplTest.java
@@ -24,9 +24,6 @@ import static org.easymock.EasyMock.expect;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-import static org.powermock.api.easymock.PowerMock.createNiceMock;
-import static org.powermock.api.easymock.PowerMock.replay;
-import static org.powermock.api.easymock.PowerMock.reset;
import java.util.Collection;
import java.util.HashMap;
@@ -41,10 +38,17 @@ import org.apache.ambari.server.state.ComponentInfo;
import org.apache.ambari.server.state.ServiceInfo;
import org.apache.ambari.server.state.StackId;
import org.apache.commons.lang3.tuple.Pair;
+import org.easymock.EasyMockRule;
+import org.easymock.EasyMockRunner;
+import org.easymock.EasyMockSupport;
+import org.easymock.Mock;
+import org.easymock.MockType;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.runner.RunWith;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
@@ -52,21 +56,43 @@ import com.google.common.collect.ImmutableSet;
/**
* Unit tests for ClusterTopologyImpl.
*/
-@SuppressWarnings("unchecked")
-public class ClusterTopologyImplTest {
+@RunWith(EasyMockRunner.class)
+public class ClusterTopologyImplTest extends EasyMockSupport {
private static final String CLUSTER_NAME = "cluster_name";
private static final long CLUSTER_ID = 1L;
private static final String predicate = "Hosts/host_name=foo";
- private static final Blueprint blueprint = createNiceMock(Blueprint.class);
- private static final HostGroup group1 = createNiceMock(HostGroup.class);
- private static final HostGroup group2 = createNiceMock(HostGroup.class);
- private static final HostGroup group3 = createNiceMock(HostGroup.class);
- private static final HostGroup group4 = createNiceMock(HostGroup.class);
private static final StackId STACK_ID = new StackId("HDP", "2.6");
private static final ImmutableSet<StackId> STACK_IDS =
ImmutableSet.of(STACK_ID);
- private final AmbariContext ambariContext =
createNiceMock(AmbariContext.class);
- private final StackDefinition stack = createNiceMock(StackDefinition.class);
+ private static final Configuration configuration =
Configuration.createEmpty();
+
+ @Mock(type = MockType.NICE)
+ private Blueprint blueprint;
+
+ @Mock(type = MockType.NICE)
+ private HostGroup group1;
+
+ @Mock(type = MockType.NICE)
+ private HostGroup group2;
+
+ @Mock(type = MockType.NICE)
+ private HostGroup group3;
+
+ @Mock(type = MockType.NICE)
+ private HostGroup group4;
+
+ @Mock(type = MockType.NICE)
+ private AmbariContext ambariContext;
+
+ @Mock(type = MockType.NICE)
+ private StackDefinition stack;
+
+ @Rule
+ public final EasyMockRule mocks = new EasyMockRule(this);
+
+ @Mock(type = MockType.NICE)
+ private BlueprintBasedClusterProvisionRequest request;
+
private final Map<String, HostGroupInfo> hostGroupInfoMap = new HashMap<>();
private final Map<String, HostGroup> hostGroupMap = new HashMap<>();
private final Map<String, Set<ResolvedComponent>> resolvedComponents =
ImmutableMap.of(
@@ -82,15 +108,11 @@ public class ClusterTopologyImplTest {
);
private BlueprintBasedClusterProvisionRequest provisionRequest;
- private Configuration configuration;
private Configuration bpconfiguration;
@Before
public void setUp() throws Exception {
- configuration = new Configuration(new HashMap<>(),
- new HashMap<>());
- bpconfiguration = new Configuration(new HashMap<>(),
- new HashMap<>());
+ bpconfiguration = Configuration.createEmpty();
HostGroupInfo group1Info = new HostGroupInfo("group1");
HostGroupInfo group2Info = new HostGroupInfo("group2");
@@ -158,18 +180,13 @@ public class ClusterTopologyImplTest {
@After
public void tearDown() {
- reset(ambariContext, stack, blueprint, group1, group2, group3, group4);
+ verifyAll();
+ resetAll();
hostGroupInfoMap.clear();
hostGroupMap.clear();
}
- private void replayAll() {
- replay(ambariContext, stack, blueprint, group1, group2, group3, group4);
- }
-
-
-
@Test(expected = InvalidTopologyException.class)
public void testCreate_duplicateHosts() throws Exception {
// add a duplicate host
@@ -193,6 +210,7 @@ public class ClusterTopologyImplTest {
ClusterTopologyImpl topology = new ClusterTopologyImpl(ambariContext,
provisionRequest, resolvedComponents);
Collection<String> assignments =
topology.getHostAssignmentsForComponent("component1");
+
assertEquals(ImmutableSet.of("host1", "host2"),
ImmutableSet.copyOf(assignments));
}
@@ -265,11 +283,6 @@ public class ClusterTopologyImplTest {
private class TestTopologyRequest implements ProvisionRequest {
@Override
- public String getClusterName() {
- return CLUSTER_NAME;
- }
-
- @Override
public Long getClusterId() {
return CLUSTER_ID;
}
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 db10408..e549ce4 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
@@ -64,13 +64,11 @@ import
org.apache.ambari.server.controller.RequestStatusResponse;
import org.apache.ambari.server.controller.ServiceResponse;
import org.apache.ambari.server.controller.ShortTaskStatus;
import org.apache.ambari.server.controller.internal.HostResourceProvider;
-import org.apache.ambari.server.controller.internal.MpackResourceProvider;
import org.apache.ambari.server.controller.internal.ProvisionClusterRequest;
import org.apache.ambari.server.controller.internal.RequestStatusImpl;
import org.apache.ambari.server.controller.internal.ScaleClusterRequest;
import org.apache.ambari.server.controller.internal.Stack;
import org.apache.ambari.server.controller.spi.ClusterController;
-import org.apache.ambari.server.controller.spi.Request;
import org.apache.ambari.server.controller.spi.Resource;
import org.apache.ambari.server.controller.spi.ResourceProvider;
import org.apache.ambari.server.events.RequestFinishedEvent;
@@ -111,7 +109,7 @@ import com.google.common.collect.ImmutableSet;
* TopologyManager unit tests
*/
@RunWith(PowerMockRunner.class)
-@PrepareForTest({TopologyManager.class, AmbariServer.class,
AmbariContext.class})
+@PrepareForTest({ AmbariContext.class, AmbariServer.class })
public class TopologyManagerTest {
private static final String CLUSTER_NAME = "test-cluster";
@@ -158,6 +156,8 @@ public class TopologyManagerTest {
private LogicalRequestFactory logicalRequestFactory;
@Mock(type = MockType.DEFAULT)
private LogicalRequest logicalRequest;
+ @Mock(type = MockType.DEFAULT)
+ private ProvisionRequest provisionRequest;
@Mock(type = MockType.NICE)
private AmbariContext ambariContext;
@Mock(type = MockType.NICE)
@@ -184,9 +184,7 @@ public class TopologyManagerTest {
private ClusterController clusterController;
@Mock(type = MockType.STRICT)
private ResourceProvider resourceProvider;
- @Mock(type = MockType.STRICT)
- private MpackResourceProvider mpackResourceProvider;
- @Mock(type = MockType.STRICT)
+ @Mock(type = MockType.NICE)
private SettingDAO settingDAO;
@Mock(type = MockType.NICE)
private ClusterTopology clusterTopologyMock;
@@ -314,6 +312,10 @@ public class TopologyManagerTest {
expect(blueprint.getName()).andReturn(BLUEPRINT_NAME).anyTimes();
expect(clusterTopologyMock.getServices()).andReturn(SERVICE_NAMES).anyTimes();
expect(clusterTopologyMock.getStack()).andReturn(stack).anyTimes();
+
expect(clusterTopologyMock.getSecurity()).andReturn(SecurityConfiguration.NONE).anyTimes();
+
expect(clusterTopologyMock.getStackIds()).andReturn(ImmutableSet.of(STACK_ID)).anyTimes();
+
expect(clusterTopologyMock.getHostGroupForHost("host1")).andReturn("group1").anyTimes();
+
expect(clusterTopologyMock.getHostGroupForHost(anyString())).andReturn(null).anyTimes();
expect(blueprint.getStackIds()).andReturn(ImmutableSet.of(STACK_ID)).anyTimes();
expect(blueprint.getSecurity()).andReturn(SecurityConfiguration.NONE).anyTimes();
expect(blueprint.getMpacks()).andReturn(ImmutableSet.of()).anyTimes();
@@ -346,9 +348,10 @@ public class TopologyManagerTest {
expect(stack.getServiceForComponent("component4")).andReturn("service2").anyTimes();
expect(request.getBlueprint()).andReturn(blueprint).anyTimes();
- expect(request.getClusterId()).andReturn(CLUSTER_ID).anyTimes();
expect(request.getClusterName()).andReturn(CLUSTER_NAME).anyTimes();
expect(request.getDescription()).andReturn("Provision Cluster
Test").anyTimes();
+
expect(clusterTopologyMock.getConfiguration()).andReturn(topoConfiguration).anyTimes();
+
expect(clusterTopologyMock.getClusterId()).andReturn(CLUSTER_ID).anyTimes();
expect(request.getConfiguration()).andReturn(topoConfiguration).anyTimes();
expect(request.getHostGroupInfo()).andReturn(groupInfoMap).anyTimes();
expect(request.getConfigRecommendationStrategy()).andReturn(ConfigRecommendationStrategy.NEVER_APPLY).anyTimes();
@@ -383,6 +386,7 @@ public class TopologyManagerTest {
expect(logicalRequest.getRequestStatus()).andReturn(requestStatusResponse).anyTimes();
expect(ambariContext.composeStacks(anyObject())).andReturn(stack).anyTimes();
+
expect(ambariContext.createClusterTopology(request)).andReturn(clusterTopologyMock).anyTimes();
expect(ambariContext.getPersistedTopologyState()).andReturn(persistedState).anyTimes();
//todo: don't ignore param
ambariContext.createAmbariResources(isA(ClusterTopology.class),
eq(CLUSTER_NAME), eq(SecurityType.NONE));
@@ -406,7 +410,6 @@ public class TopologyManagerTest {
expectLastCall().anyTimes();
expect(ambariContext.getServices(anyString())).andReturn(services).anyTimes();
-
expect(clusterController.ensureResourceProvider(Resource.Type.Mpack)).andReturn(mpackResourceProvider).anyTimes();
expect(resourceProvider.createResources((anyObject()))).andReturn(new
RequestStatusImpl(null, null, null)).anyTimes(); // persist raw request
expect(clusterController.ensureResourceProvider(anyObject(Resource.Type.class))).andReturn(resourceProvider);
@@ -449,17 +452,16 @@ public class TopologyManagerTest {
@After
public void tearDown() {
- PowerMock.verify(System.class);
verify(blueprint, stack, request, group1, group2, ambariContext,
logicalRequestFactory, componentResolver,
logicalRequest, configurationRequest, configurationRequest2,
configurationRequest3,
requestStatusResponse, executor, persistedState, clusterTopologyMock,
mockFuture, settingDAO,
- resourceProvider, mpackResourceProvider);
+ resourceProvider);
- PowerMock.reset(System.class, AmbariServer.class, AmbariContext.class);
+ PowerMock.reset(AmbariServer.class, AmbariContext.class);
reset(blueprint, stack, request, group1, group2, ambariContext,
logicalRequestFactory, componentResolver,
logicalRequest, configurationRequest, configurationRequest2,
configurationRequest3,
requestStatusResponse, executor, persistedState, clusterTopologyMock,
mockFuture, settingDAO,
- resourceProvider, mpackResourceProvider, metaInfo, controller);
+ resourceProvider, metaInfo, controller);
}
@Test
@@ -472,41 +474,15 @@ public class TopologyManagerTest {
}
@Test
- public void testProvisionCluster_downloadMissingMpack() throws Exception {
- // given
-
expect(persistedState.getAllRequests()).andReturn(Collections.emptyMap()).anyTimes();
-
- installedMpacks.remove("HDF");
-
- reset(mpackResourceProvider);
- Capture<Request> mpackRequestCapture = Capture.newInstance();
-
expect(mpackResourceProvider.createResources(capture(mpackRequestCapture))).
- andReturn(new RequestStatusImpl(null, null, null)).once();
- replayAll();
-
- // when
- topologyManager.provisionCluster(request, "{}");
-
- // then
- assertEquals("http://mpacks.org/hdf",
-
mpackRequestCapture.getValue().getProperties().iterator().next().get(MpackResourceProvider.MPACK_URI));
- }
-
-
- @Test
public void testAddKerberosClientAtTopologyInit() throws Exception {
- Map<ClusterTopology, List<LogicalRequest>> allRequests = new HashMap<>();
- List<LogicalRequest> requestList = new ArrayList<>();
- requestList.add(logicalRequest);
expect(logicalRequest.hasPendingHostRequests()).andReturn(false).anyTimes();
expect(logicalRequest.isFinished()).andReturn(false).anyTimes();
- allRequests.put(clusterTopologyMock, requestList);
+
expect(logicalRequest.getType()).andReturn(TopologyRequest.Type.PROVISION).anyTimes();
expect(requestStatusResponse.getTasks()).andReturn(Collections.emptyList()).anyTimes();
+
expect(persistedState.getAllRequests()).andReturn(ImmutableMap.of(clusterTopologyMock,
ImmutableList.of(logicalRequest))).anyTimes();
expect(clusterTopologyMock.isClusterKerberosEnabled()).andReturn(true);
-
expect(clusterTopologyMock.getClusterId()).andReturn(CLUSTER_ID).anyTimes();
- expect(clusterTopologyMock.getBlueprint()).andReturn(blueprint).anyTimes();
- expect(persistedState.getAllRequests()).andReturn(allRequests).anyTimes();
-
expect(persistedState.getProvisionRequest(CLUSTER_ID)).andReturn(logicalRequest).anyTimes();
+ expect(clusterTopologyMock.getBlueprint()).andReturn(blueprint);
+ expect(blueprint.ensureKerberosClientIsPresent()).andReturn(true);
expect(ambariContext.isTopologyResolved(CLUSTER_ID)).andReturn(true).anyTimes();
expect(group1.addComponent(new
Component("KERBEROS_CLIENT"))).andReturn(true).anyTimes();
expect(group2.addComponent(new
Component("KERBEROS_CLIENT"))).andReturn(true).anyTimes();
@@ -532,7 +508,6 @@ public class TopologyManagerTest {
expect(requestStatusResponse.getTasks()).andReturn(tasks).anyTimes();
expect(persistedState.getAllRequests()).andReturn(Collections.emptyMap()).anyTimes();
-
expect(persistedState.getProvisionRequest(CLUSTER_ID)).andReturn(logicalRequest).anyTimes();
expect(logicalRequest.isFinished()).andReturn(true).anyTimes();
expect(logicalRequest.isSuccessful()).andReturn(true).anyTimes();
replayAll();
@@ -556,7 +531,6 @@ public class TopologyManagerTest {
expect(requestStatusResponse.getTasks()).andReturn(tasks).anyTimes();
expect(persistedState.getAllRequests()).andReturn(Collections.emptyMap()).anyTimes();
-
expect(persistedState.getProvisionRequest(CLUSTER_ID)).andReturn(logicalRequest).anyTimes();
expect(logicalRequest.isFinished()).andReturn(true).anyTimes();
expect(logicalRequest.isSuccessful()).andReturn(false).anyTimes();
replayAll();
@@ -580,7 +554,6 @@ public class TopologyManagerTest {
expect(requestStatusResponse.getTasks()).andReturn(tasks).anyTimes();
expect(persistedState.getAllRequests()).andReturn(Collections.emptyMap()).anyTimes();
-
expect(persistedState.getProvisionRequest(CLUSTER_ID)).andReturn(logicalRequest).anyTimes();
expect(logicalRequest.isFinished()).andReturn(false).anyTimes();
replayAll();
topologyManager.provisionCluster(request, "{}");
@@ -619,10 +592,10 @@ public class TopologyManagerTest {
allRequests.put(clusterTopologyMock, logicalRequests);
expect(persistedState.getAllRequests()).andReturn(allRequests).anyTimes();
-
expect(persistedState.getProvisionRequest(CLUSTER_ID)).andReturn(logicalRequest).anyTimes();
expect(logicalRequest.hasPendingHostRequests()).andReturn(true).anyTimes();
-
expect(logicalRequest.getCompletedHostRequests()).andReturn(Collections.EMPTY_LIST).anyTimes();
+
expect(logicalRequest.getCompletedHostRequests()).andReturn(Collections.emptyList()).anyTimes();
expect(logicalRequest.isFinished()).andReturn(true).anyTimes();
+
expect(logicalRequest.getType()).andReturn(TopologyRequest.Type.PROVISION).anyTimes();
expect(requestStatusResponse.getTasks()).andReturn(tasks).anyTimes();
replayAll();
EasyMock.replay(clusterTopologyMock);
@@ -638,7 +611,7 @@ public class TopologyManagerTest {
replay(blueprint, stack, request, group1, group2, ambariContext,
logicalRequestFactory, componentResolver,
configurationRequest, configurationRequest2,
configurationRequest3, executor,
persistedState, clusterTopologyMock, securityConfigurationFactory,
credentialStoreService,
- clusterController, resourceProvider, mpackResourceProvider,
mockFuture, requestStatusResponse,
+ clusterController, resourceProvider, mockFuture,
requestStatusResponse,
logicalRequest, settingDAO, configureClusterTaskFactory,
configureClusterTask, metaInfo, controller);
}
@@ -659,7 +632,6 @@ public class TopologyManagerTest {
replayAll();
topologyManager.provisionCluster(request, "{}");
topologyManager.scaleHosts(new ScaleClusterRequest(propertySet));
- Assert.fail("InvalidTopologyException should have been thrown");
}
@Test
@@ -673,18 +645,19 @@ public class TopologyManagerTest {
expect(settingDAO.findByName(QuickLinksProfile.SETTING_NAME_QUICKLINKS_PROFILE)).andReturn(null);
// expect that settingsDao saves the quick links profile with the right
content
- final long timeStamp = System.currentTimeMillis();
- mockStatic(System.class);
- expect(System.currentTimeMillis()).andReturn(timeStamp);
- PowerMock.replay(System.class);
- final SettingEntity quickLinksProfile =
createQuickLinksSettingEntity(SAMPLE_QUICKLINKS_PROFILE_1, timeStamp);
- settingDAO.create(eq(quickLinksProfile));
+ final SettingEntity expectedProfile =
createQuickLinksSettingEntity(SAMPLE_QUICKLINKS_PROFILE_1,
System.currentTimeMillis());
+ Capture<SettingEntity> profileCapture = Capture.newInstance();
+ settingDAO.create(capture(profileCapture));
expectLastCall();
replayAll();
PowerMock.replayAll();
topologyManager.provisionCluster(request, "{}");
+
+ SettingEntity capturedProfile = profileCapture.getValue();
+ capturedProfile.setUpdateTimestamp(expectedProfile.getUpdateTimestamp());
+ assertEquals(expectedProfile, capturedProfile);
}
@Test
@@ -695,22 +668,22 @@ public class TopologyManagerTest {
expect(request.getQuickLinksProfileJson()).andReturn(SAMPLE_QUICKLINKS_PROFILE_2).anyTimes();
// existing quick links profile returned by dao
- final long timeStamp1 = System.currentTimeMillis();
- SettingEntity originalProfile =
createQuickLinksSettingEntity(SAMPLE_QUICKLINKS_PROFILE_1, timeStamp1);
+ SettingEntity originalProfile =
createQuickLinksSettingEntity(SAMPLE_QUICKLINKS_PROFILE_1,
System.currentTimeMillis());
expect(settingDAO.findByName(QuickLinksProfile.SETTING_NAME_QUICKLINKS_PROFILE)).andReturn(originalProfile);
// expect that settingsDao overwrites the quick links profile with the new
content
- mockStatic(System.class);
- final long timeStamp2 = timeStamp1 + 100;
- expect(System.currentTimeMillis()).andReturn(timeStamp2);
- PowerMock.replay(System.class);
- final SettingEntity newProfile =
createQuickLinksSettingEntity(SAMPLE_QUICKLINKS_PROFILE_2, timeStamp2);
- expect(settingDAO.merge(newProfile)).andReturn(newProfile);
+ final SettingEntity newProfile =
createQuickLinksSettingEntity(SAMPLE_QUICKLINKS_PROFILE_2,
System.currentTimeMillis());
+ Capture<SettingEntity> profileCapture = Capture.newInstance();
+ expect(settingDAO.merge(capture(profileCapture))).andReturn(newProfile);
replayAll();
PowerMock.replayAll();
topologyManager.provisionCluster(request, "{}");
+
+ SettingEntity capturedProfile = profileCapture.getValue();
+ capturedProfile.setUpdateTimestamp(newProfile.getUpdateTimestamp());
+ assertEquals(newProfile, capturedProfile);
}
@Test
@@ -734,7 +707,7 @@ public class TopologyManagerTest {
settingEntity.setSettingType(QuickLinksProfile.SETTING_TYPE_AMBARI_SERVER);
settingEntity.setContent(content);
settingEntity.setUpdatedBy(AuthorizationHelper.getAuthenticatedName());
- settingEntity.setUpdateTimestamp(timeStamp);
+ settingEntity.setUpdateTimestamp(System.currentTimeMillis());
return settingEntity;
}
}