You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by mp...@apache.org on 2019/07/12 11:16:40 UTC
[ambari] branch branch-2.6 updated: AMBARI-25335. Reduce cluster
creation request processing time. (#3047)
This is an automated email from the ASF dual-hosted git repository.
mpapirkovskyy pushed a commit to branch branch-2.6
in repository https://gitbox.apache.org/repos/asf/ambari.git
The following commit(s) were added to refs/heads/branch-2.6 by this push:
new bc63702 AMBARI-25335. Reduce cluster creation request processing time. (#3047)
bc63702 is described below
commit bc637022a47cd21e7f018a13cfea4b90088d661e
Author: Myroslav Papirkovskyi <mp...@apache.org>
AuthorDate: Fri Jul 12 14:16:34 2019 +0300
AMBARI-25335. Reduce cluster creation request processing time. (#3047)
* AMBARI-25335. Reduce cluster creation request processing time. (mpapirkovskyy)
Change-Id: I2bd1e245587882b8e21a2f8a954b93603ee7795c
* AMBARI-25335. Reduce cluster creation request processing time. (mpapirkovskyy)
Change-Id: Ic23abea3819d873d5506c5012a5ce1566ea29db8
* AMBARI-25335. Reduce cluster creation request processing time. (mpapirkovskyy)
Change-Id: I649a95660da09d61878e9c248131cd849e0f7020
---
.../controller/AmbariManagementController.java | 38 ++++++++++++++++
.../controller/AmbariManagementControllerImpl.java | 40 +++++++++++++----
.../apache/ambari/server/orm/dao/ClusterDAO.java | 26 +++++++++++
.../ambari/server/orm/entities/ClusterEntity.java | 2 +-
.../org/apache/ambari/server/state/Cluster.java | 5 +++
.../apache/ambari/server/state/ConfigFactory.java | 16 ++++++-
.../org/apache/ambari/server/state/ConfigImpl.java | 30 +++++++++----
.../ambari/server/state/cluster/ClusterImpl.java | 21 +++++++--
.../server/state/configgroup/ConfigGroupImpl.java | 4 +-
.../ambari/server/topology/AmbariContext.java | 2 +-
.../topology/ClusterConfigurationRequest.java | 3 ++
.../ambari/server/upgrade/UpgradeCatalog252.java | 2 +-
.../topology/ClusterDeployWithStartOnlyTest.java | 1 +
...terInstallWithoutStartOnComponentLevelTest.java | 1 +
.../topology/ClusterInstallWithoutStartTest.java | 1 +
.../server/topology/TopologyManagerTest.java | 29 ++++++++++--
.../server/upgrade/UpgradeCatalog250Test.java | 51 +++++++++++++---------
.../server/upgrade/UpgradeCatalog260Test.java | 11 +++--
18 files changed, 229 insertions(+), 54 deletions(-)
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java
index 9ac48a4..c29ffbf 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java
@@ -104,6 +104,17 @@ public interface AmbariManagementController {
* Creates a configuration.
*
* @param request the request object which defines the configuration.
+ * @param refreshCluster should the cluster entity be refreshed from DB
+ * @throws AmbariException when the configuration cannot be created.
+ * @throws AuthorizationException when user is not authorized to perform operation.
+ */
+ ConfigurationResponse createConfiguration(ConfigurationRequest request, boolean refreshCluster)
+ throws AmbariException, AuthorizationException;
+
+ /**
+ * Creates a configuration.
+ *
+ * @param request the request object which defines the configuration.
*
* @throws AmbariException when the configuration cannot be created.
*/
@@ -116,6 +127,13 @@ public interface AmbariManagementController {
* @return config created
*/
Config createConfig(Cluster cluster, StackId stackId, String type, Map<String, String> properties,
+ String versionTag, Map<String, Map<String, String>> propertiesAttributes, boolean refreshCluster);
+
+ /**
+ * Create cluster config
+ * @return config created
+ */
+ Config createConfig(Cluster cluster, StackId stackId, String type, Map<String, String> properties,
String versionTag, Map<String, Map<String, String>> propertiesAttributes);
/**
@@ -253,6 +271,26 @@ public interface AmbariManagementController {
throws AmbariException, AuthorizationException;
/**
+ * Update the cluster identified by the given request object with the
+ * values carried by the given request object.
+ *
+ *
+ * @param requests request objects which define which cluster to
+ * update and the values to set
+ * @param requestProperties request specific properties independent of resource
+ *
+ * @param refreshCluster refreshes cluster entity after cluster configs update
+ *
+ * @return a track action response
+ *
+ * @throws AmbariException thrown if the resource cannot be updated
+ * @throws AuthorizationException thrown if the authenticated user is not authorized to perform this operation
+ */
+ RequestStatusResponse updateClusters(Set<ClusterRequest> requests,
+ Map<String, String> requestProperties, boolean refreshCluster)
+ throws AmbariException, AuthorizationException;
+
+ /**
* Updates the users specified.
*
* @param requests the users to modify
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
index 2508da4..85dd86c 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
@@ -796,7 +796,7 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
*/
@Override
public synchronized ConfigurationResponse createConfiguration(
- ConfigurationRequest request) throws AmbariException, AuthorizationException {
+ ConfigurationRequest request, boolean refreshCluster) throws AmbariException, AuthorizationException {
if (null == request.getClusterName() || request.getClusterName().isEmpty()
|| null == request.getType() || request.getType().isEmpty()
|| null == request.getProperties()) {
@@ -928,7 +928,7 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
}
Config config = createConfig(cluster, stackId, request.getType(), requestProperties,
- request.getVersionTag(), propertiesAttributes);
+ request.getVersionTag(), propertiesAttributes, refreshCluster);
LOG.info(MessageFormat.format("Creating configuration with tag ''{0}'' to cluster ''{1}'' for configuration type {2}",
request.getVersionTag(),
@@ -939,17 +939,30 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
}
@Override
+ public synchronized ConfigurationResponse createConfiguration(
+ ConfigurationRequest request) throws AmbariException, AuthorizationException {
+ return createConfiguration(request, true);
+ }
+
+ @Override
public Config createConfig(Cluster cluster, StackId stackId, String type, Map<String, String> properties,
- String versionTag, Map<String, Map<String, String>> propertiesAttributes) {
+ String versionTag, Map<String, Map<String, String>> propertiesAttributes, boolean refreshCluster) {
- Config config = configFactory.createNew(stackId, cluster, type, versionTag, properties,
- propertiesAttributes);
+ Config config = configFactory.createNew(stackId, type, cluster, versionTag, properties,
+ propertiesAttributes, refreshCluster);
cluster.addConfig(config);
return config;
}
@Override
+ public Config createConfig(Cluster cluster, StackId stackId, String type, Map<String, String> properties,
+ String versionTag, Map<String, Map<String, String>> propertiesAttributes) {
+
+ return createConfig(cluster, stackId, type, properties, versionTag, propertiesAttributes, true);
+ }
+
+ @Override
public void createUsers(Set<UserRequest> requests) throws AmbariException {
for (UserRequest request : requests) {
@@ -1448,6 +1461,15 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
Map<String, String> requestProperties)
throws AmbariException, AuthorizationException {
+ return updateClusters(requests, requestProperties, true);
+ }
+
+ @Override
+ @Transactional
+ public synchronized RequestStatusResponse updateClusters(Set<ClusterRequest> requests,
+ Map<String, String> requestProperties, boolean refreshCluster)
+ throws AmbariException, AuthorizationException {
+
RequestStatusResponse response = null;
// We have to allow for multiple requests to account for multiple
@@ -1517,7 +1539,7 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
//
// ***************************************************
- response = updateCluster(request, requestProperties);
+ response = updateCluster(request, requestProperties, refreshCluster);
}
return response;
}
@@ -1616,7 +1638,8 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
return output;
}
- private synchronized RequestStatusResponse updateCluster(ClusterRequest request, Map<String, String> requestProperties)
+ private synchronized RequestStatusResponse updateCluster(ClusterRequest request,
+ Map<String, String> requestProperties, boolean refreshCluster)
throws AmbariException, AuthorizationException {
RequestStageContainer requestStageContainer = null;
@@ -1765,7 +1788,8 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
cr.getProperties().size() > 0) { // properties to set
cr.setClusterName(cluster.getClusterName());
- configurationResponses.add(createConfiguration(cr));
+ configurationResponses.add(createConfiguration(cr, refreshCluster));
+
LOG.info(MessageFormat.format("Applying configuration with tag ''{0}'' to cluster ''{1}'' for configuration type {2}",
cr.getVersionTag(),
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java
index 7dec445..2f8f65c 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java
@@ -347,6 +347,15 @@ public class ClusterDAO {
}
/**
+ * Merge the specified entities into the current persistence context.
+ * @param clusterConfigEntities list of cluster configs to merge (not {@code null}).
+ */
+ @Transactional
+ public void merge(Collection<ClusterConfigEntity> clusterConfigEntities) {
+ merge(clusterConfigEntities, false);
+ }
+
+ /**
* Merge the specified entity into the current persistence context.
*
* @param clusterConfigEntity
@@ -366,6 +375,23 @@ public class ClusterDAO {
return clusterConfigEntityRes;
}
+ /**
+ * Merge the specified list of cluster config entities into the current persistence context.
+ * @param clusterConfigEntities the entity to merge (not {@code null}).
+ * @param flush if {@code true} then {@link EntityManager#flush()} will be invoked
+ * immediately after the merge.
+ */
+ @Transactional
+ public void merge(Collection<ClusterConfigEntity> clusterConfigEntities, boolean flush) {
+ EntityManager entityManager = entityManagerProvider.get();
+ for (ClusterConfigEntity clusterConfigEntity : clusterConfigEntities) {
+ entityManager.merge(clusterConfigEntity);
+ }
+ if(flush) {
+ entityManager.flush();
+ }
+ }
+
@Transactional
public void remove(ClusterEntity clusterEntity) {
entityManagerProvider.get().remove(clusterEntity);
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterEntity.java
index 0f8f336..4bc2f14 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterEntity.java
@@ -111,7 +111,7 @@ public class ClusterEntity {
@ManyToMany(mappedBy = "clusterEntities")
private Collection<HostEntity> hostEntities;
- @OneToMany(mappedBy = "clusterEntity", cascade = CascadeType.ALL)
+ @OneToMany(mappedBy = "clusterEntity")
private Collection<ClusterConfigEntity> configEntities;
@OneToMany(mappedBy = "clusterEntity", cascade = CascadeType.ALL)
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java b/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
index 7962148..213dc1f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
@@ -402,6 +402,11 @@ public interface Cluster {
void deleteAllServices() throws AmbariException;
/**
+ * Deletes all cluster configs associated with this cluster.
+ */
+ void deleteAllClusterConfigs();
+
+ /**
* Delete the named service associated with this cluster
* @param serviceName
* @throws AmbariException
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigFactory.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigFactory.java
index 6307f18..a242f97 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigFactory.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigFactory.java
@@ -46,7 +46,21 @@ public interface ConfigFactory {
* @param tag
* @param map
* @param mapAttributes
- * @return
+ * @param refreshCluster refreshes cluster entity after configs creating
+ * @return created config
+ */
+ Config createNew(StackId stackId, @Assisted("type") String type, Cluster cluster, @Assisted("tag") String tag,
+ Map<String, String> map, Map<String, Map<String, String>> mapAttributes, boolean refreshCluster);
+
+ /**
+ * Creates a new {@link Config} object using provided values.
+ *
+ * @param cluster
+ * @param type
+ * @param tag
+ * @param map
+ * @param mapAttributes
+ * @return created config
*/
Config createNew(StackId stackId, Cluster cluster, @Assisted("type") String type, @Assisted("tag") String tag,
Map<String, String> map, Map<String, Map<String, String>> mapAttributes);
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java
index abe2e8b..d12d81b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java
@@ -107,18 +107,18 @@ public class ConfigImpl implements Config {
@Assisted @Nullable Map<String, Map<String, String>> propertiesAttributes,
ClusterDAO clusterDAO, StackDAO stackDAO,
Gson gson, AmbariEventPublisher eventPublisher, LockFactory lockFactory) {
- this(cluster.getDesiredStackVersion(), cluster, type, tag, properties, propertiesAttributes,
- clusterDAO, stackDAO, gson, eventPublisher, lockFactory);
+ this(cluster.getDesiredStackVersion(), type, cluster, tag, properties, propertiesAttributes,
+ clusterDAO, stackDAO, gson, eventPublisher, lockFactory, true);
}
@AssistedInject
- ConfigImpl(@Assisted StackId stackId, @Assisted Cluster cluster, @Assisted("type") String type,
+ ConfigImpl(@Assisted StackId stackId, @Assisted("type") String type, @Assisted Cluster cluster,
@Assisted("tag") @Nullable String tag,
@Assisted Map<String, String> properties,
@Assisted @Nullable Map<String, Map<String, String>> propertiesAttributes,
ClusterDAO clusterDAO, StackDAO stackDAO,
- Gson gson, AmbariEventPublisher eventPublisher, LockFactory lockFactory) {
+ Gson gson, AmbariEventPublisher eventPublisher, LockFactory lockFactory, @Assisted boolean refreshCluster) {
propertyLock = lockFactory.newReadWriteLock(PROPERTY_LOCK_LABEL);
@@ -160,12 +160,23 @@ public class ConfigImpl implements Config {
// cluster's desired stack as the config's stack
this.stackId = stackId;
propertiesTypes = cluster.getConfigPropertiesTypes(type);
- persist(entity);
+ persist(entity, refreshCluster);
configId = entity.getConfigId();
}
@AssistedInject
+ ConfigImpl(@Assisted StackId stackId, @Assisted Cluster cluster, @Assisted("type") String type,
+ @Assisted("tag") @Nullable String tag,
+ @Assisted Map<String, String> properties,
+ @Assisted @Nullable Map<String, Map<String, String>> propertiesAttributes,
+ ClusterDAO clusterDAO, StackDAO stackDAO,
+ Gson gson, AmbariEventPublisher eventPublisher, LockFactory lockFactory) {
+ this(stackId, type, cluster, tag, properties, propertiesAttributes, clusterDAO, stackDAO, gson, eventPublisher,
+ lockFactory, true);
+ }
+
+ @AssistedInject
ConfigImpl(@Assisted Cluster cluster, @Assisted ClusterConfigEntity entity,
ClusterDAO clusterDAO, Gson gson, AmbariEventPublisher eventPublisher,
LockFactory lockFactory) {
@@ -345,14 +356,15 @@ public class ConfigImpl implements Config {
* Persist the entity and update the internal state relationships once the
* transaction has been committed.
*/
- private void persist(ClusterConfigEntity entity) {
+ private void persist(ClusterConfigEntity entity, boolean refreshCluster) {
persistEntitiesInTransaction(entity);
// ensure that the in-memory state of the cluster is kept consistent
cluster.addConfig(this);
- // re-load the entity associations for the cluster
- cluster.refresh();
+ if (refreshCluster) {
+ cluster.refresh();
+ }
// broadcast the change event for the configuration
ClusterConfigChangedEvent event = new ClusterConfigChangedEvent(cluster.getClusterName(),
@@ -394,7 +406,7 @@ public class ConfigImpl implements Config {
// save the entity, forcing a flush to ensure the refresh picks up the
// newest data
- clusterDAO.merge(clusterEntity, true);
+ clusterDAO.merge(entity, true);
// re-load the entity associations for the cluster
cluster.refresh();
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
index 888ea57..b18c641 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
@@ -1261,6 +1261,20 @@ public class ClusterImpl implements Cluster {
}
@Override
+ @Transactional
+ public void deleteAllClusterConfigs() {
+ clusterGlobalLock.writeLock().lock();
+ try {
+ Collection<ClusterConfigEntity> clusterConfigs = getClusterEntity().getClusterConfigEntities();
+ for (ClusterConfigEntity clusterConfigEntity : clusterConfigs) {
+ clusterDAO.removeConfig(clusterConfigEntity);
+ }
+ } finally {
+ clusterGlobalLock.writeLock().unlock();
+ }
+ }
+
+ @Override
public void deleteService(String serviceName)
throws AmbariException {
clusterGlobalLock.writeLock().lock();
@@ -1346,6 +1360,7 @@ public class ClusterImpl implements Cluster {
try {
refresh();
deleteAllServices();
+ deleteAllClusterConfigs();
refresh(); // update one-to-many clusterServiceEntities
removeEntities();
@@ -1934,7 +1949,7 @@ public class ClusterImpl implements Cluster {
}
}
- clusterEntity = clusterDAO.merge(clusterEntity);
+ clusterDAO.merge(clusterConfigs);
if (serviceName == null) {
ArrayList<String> configTypes = new ArrayList<>();
@@ -2418,7 +2433,7 @@ public class ClusterImpl implements Cluster {
// !!! without providing the flush here, when this transaction completes it
// looks like the database has all unselected configs for some types
- clusterEntity = clusterDAO.merge(clusterEntity, true);
+ clusterDAO.merge(configEntities, true);
cacheConfigurations();
@@ -2499,7 +2514,7 @@ public class ClusterImpl implements Cluster {
// since the entities which were modified came from the cluster entity's
// list to begin with, we can just save them right back - no need for a
// new collection since the entity instances were modified directly
- clusterEntity = clusterDAO.merge(clusterEntity, true);
+ clusterDAO.merge(configEntities, true);
cacheConfigurations();
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java
index 3cc1856..be1d677 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java
@@ -429,8 +429,8 @@ public class ConfigGroupImpl implements ConfigGroup {
Service service = cluster.getServices().get(serviceName);
StackId stackId = (null == service) ? cluster.getDesiredStackVersion() : service.getDesiredStackId();
- config = configFactory.createNew(stackId, cluster, config.getType(),
- config.getTag(), config.getProperties(), config.getPropertiesAttributes());
+ config = configFactory.createNew(stackId, config.getType(), cluster,
+ config.getTag(), config.getProperties(), config.getPropertiesAttributes(), true);
entry.setValue(config);
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 134fffc..e6eda6e 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
@@ -527,7 +527,7 @@ public class AmbariContext {
RetryHelper.executeWithRetry(new Callable<Object>() {
@Override
public Object call() throws Exception {
- getController().updateClusters(Collections.singleton(clusterRequest), null);
+ getController().updateClusters(Collections.singleton(clusterRequest), null, false);
return null;
}
});
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 de1d587..439eea1 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
@@ -404,8 +404,10 @@ public class ClusterConfigurationRequest {
private void setConfigurationsOnCluster(List<BlueprintServiceConfigRequest> configurationRequests,
String tag, Set<String> updatedConfigTypes) {
String clusterName = null;
+ Cluster cluster;
try {
clusterName = ambariContext.getClusterName(clusterTopology.getClusterId());
+ cluster = AmbariContext.getController().getClusters().getCluster(clusterName);
} catch (AmbariException e) {
LOG.error("Cannot get cluster name for clusterId = " + clusterTopology.getClusterId(), e);
throw new RuntimeException(e);
@@ -473,6 +475,7 @@ public class ClusterConfigurationRequest {
LOG.error("ClusterRequest should not be null for service = " + blueprintConfigRequest.getServiceName());
}
}
+ cluster.refresh();
if (tag.equals(TopologyManager.TOPOLOGY_RESOLVED_TAG)) {
// if this is a request to resolve config, then wait until resolution is completed
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog252.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog252.java
index b8a87ec..5396467 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog252.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog252.java
@@ -316,7 +316,7 @@ public class UpgradeCatalog252 extends AbstractUpgradeCatalog {
}
if (atLeastOneChanged) {
- clusterDAO.merge(clusterEntity);
+ clusterDAO.merge(configEntities);
}
}
}
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 b1233f4..0bdd9a2 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
@@ -338,6 +338,7 @@ public class ClusterDeployWithStartOnlyTest extends EasyMockSupport {
PowerMock.replay(AmbariServer.class);
expect(managementController.getClusters()).andReturn(clusters).anyTimes();
expect(clusters.getClusterById(anyLong())).andReturn(cluster).anyTimes();
+ expect(clusters.getCluster(CLUSTER_NAME)).andReturn(cluster).anyTimes();
expect(cluster.getClusterName()).andReturn(CLUSTER_NAME).anyTimes();
expect(ambariContext.getPersistedTopologyState()).andReturn(persistedState).anyTimes();
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 63c9077..454b82c 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
@@ -340,6 +340,7 @@ public class ClusterInstallWithoutStartOnComponentLevelTest extends EasyMockSupp
PowerMock.replay(AmbariServer.class);
expect(managementController.getClusters()).andReturn(clusters).anyTimes();
expect(clusters.getClusterById(anyLong())).andReturn(cluster).anyTimes();
+ expect(clusters.getCluster(CLUSTER_NAME)).andReturn(cluster).anyTimes();
expect(cluster.getClusterName()).andReturn(CLUSTER_NAME).anyTimes();
expect(ambariContext.getPersistedTopologyState()).andReturn(persistedState).anyTimes();
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 8e8e3d5..0fd5c35 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
@@ -337,6 +337,7 @@ public class ClusterInstallWithoutStartTest extends EasyMockSupport {
PowerMock.replay(AmbariServer.class);
expect(managementController.getClusters()).andReturn(clusters).anyTimes();
expect(clusters.getClusterById(anyLong())).andReturn(cluster).anyTimes();
+ expect(clusters.getCluster(CLUSTER_NAME)).andReturn(cluster).anyTimes();
expect(cluster.getClusterName()).andReturn(CLUSTER_NAME).anyTimes();
expect(ambariContext.getPersistedTopologyState()).andReturn(persistedState).anyTimes();
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 0c556f5..c667b28 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
@@ -33,6 +33,7 @@ import static org.easymock.EasyMock.verify;
import static org.powermock.api.easymock.PowerMock.mockStatic;
import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -47,6 +48,7 @@ import java.util.concurrent.Future;
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.actionmanager.HostRoleStatus;
+import org.apache.ambari.server.controller.AmbariManagementController;
import org.apache.ambari.server.controller.ClusterRequest;
import org.apache.ambari.server.controller.ConfigurationRequest;
import org.apache.ambari.server.controller.RequestStatusResponse;
@@ -65,6 +67,8 @@ import org.apache.ambari.server.orm.entities.SettingEntity;
import org.apache.ambari.server.security.authorization.AuthorizationHelper;
import org.apache.ambari.server.security.encryption.CredentialStoreService;
import org.apache.ambari.server.stack.NoSuchStackException;
+import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.Clusters;
import org.apache.ambari.server.state.SecurityType;
import org.apache.ambari.server.state.quicklinksprofile.QuickLinksProfile;
import org.apache.ambari.server.topology.tasks.ConfigureClusterTask;
@@ -91,7 +95,7 @@ import org.powermock.modules.junit4.PowerMockRunner;
* TopologyManager unit tests
*/
@RunWith(PowerMockRunner.class)
-@PrepareForTest( { TopologyManager.class })
+@PrepareForTest( { TopologyManager.class, AmbariContext.class })
public class TopologyManagerTest {
private static final String CLUSTER_NAME = "test-cluster";
@@ -160,6 +164,12 @@ public class TopologyManagerTest {
private ConfigureClusterTaskFactory configureClusterTaskFactory;
@Mock(type = MockType.NICE)
private ConfigureClusterTask configureClusterTask;
+ @Mock(type = MockType.NICE)
+ private AmbariManagementController ambariManagementController;
+ @Mock(type = MockType.NICE)
+ private Clusters clusters;
+ @Mock(type = MockType.NICE)
+ private Cluster cluster;
@Mock(type = MockType.STRICT)
private Future mockFuture;
@@ -329,6 +339,8 @@ public class TopologyManagerTest {
expect(ambariContext.isClusterKerberosEnabled(CLUSTER_ID)).andReturn(false).anyTimes();
expect(ambariContext.getClusterId(CLUSTER_NAME)).andReturn(CLUSTER_ID).anyTimes();
expect(ambariContext.getClusterName(CLUSTER_ID)).andReturn(CLUSTER_NAME).anyTimes();
+ expect(clusters.getCluster(CLUSTER_NAME)).andReturn(cluster).anyTimes();
+ expect(ambariManagementController.getClusters()).andReturn(clusters).anyTimes();
// cluster configuration task run() isn't executed by mock executor
// so only INITIAL config
expect(ambariContext.createConfigurationRequests(capture(configRequestPropertiesCapture))).
@@ -372,6 +384,13 @@ public class TopologyManagerTest {
EasyMockSupport.injectMocks(topologyManagerReplay);
+ Field controllerField = AmbariContext.class.getDeclaredField("controller");
+ controllerField.setAccessible(true);
+ Field modifiersField = Field.class.getDeclaredField("modifiers");
+ modifiersField.setAccessible(true);
+ modifiersField.setInt(controllerField, controllerField.getModifiers() & ~Modifier.FINAL);
+ controllerField.set(null, ambariManagementController);
+
}
@After
@@ -379,12 +398,14 @@ public class TopologyManagerTest {
PowerMock.verify(System.class);
verify(blueprint, stack, request, group1, group2, ambariContext, logicalRequestFactory,
logicalRequest, configurationRequest, configurationRequest2, configurationRequest3,
- requestStatusResponse, executor, persistedState, clusterTopologyMock, mockFuture, settingDAO);
+ requestStatusResponse, executor, persistedState, clusterTopologyMock, mockFuture, settingDAO,
+ ambariManagementController, clusters, cluster);
PowerMock.reset(System.class);
reset(blueprint, stack, request, group1, group2, ambariContext, logicalRequestFactory,
logicalRequest, configurationRequest, configurationRequest2, configurationRequest3,
- requestStatusResponse, executor, persistedState, clusterTopologyMock, mockFuture, settingDAO);
+ requestStatusResponse, executor, persistedState, clusterTopologyMock, mockFuture, settingDAO,
+ ambariManagementController, clusters, cluster);
}
@Test
@@ -546,7 +567,7 @@ public class TopologyManagerTest {
configurationRequest, configurationRequest2, configurationRequest3, executor,
persistedState, clusterTopologyMock, securityConfigurationFactory, credentialStoreService,
clusterController, resourceProvider, mockFuture, requestStatusResponse, logicalRequest, settingDAO,
- configureClusterTaskFactory, configureClusterTask);
+ configureClusterTaskFactory, configureClusterTask, ambariManagementController, clusters, cluster);
}
@Test(expected = InvalidTopologyException.class)
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog250Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog250Test.java
index 1a3a0d1..1bef310 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog250Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog250Test.java
@@ -53,6 +53,7 @@ import org.apache.ambari.server.actionmanager.ActionManager;
import org.apache.ambari.server.configuration.Configuration;
import org.apache.ambari.server.controller.AmbariManagementController;
import org.apache.ambari.server.controller.AmbariManagementControllerImpl;
+import org.apache.ambari.server.controller.ConfigurationRequest;
import org.apache.ambari.server.controller.KerberosHelper;
import org.apache.ambari.server.controller.MaintenanceStateHelper;
import org.apache.ambari.server.orm.DBAccessor;
@@ -726,9 +727,10 @@ public class UpgradeCatalog250Test {
replay(clusters, mockAmsEnv, cluster);
AmbariManagementControllerImpl controller = createMockBuilder(AmbariManagementControllerImpl.class)
- .addMockedMethod("createConfiguration")
+ .addMockedMethod("createConfiguration", ConfigurationRequest.class)
.addMockedMethod("getClusters", new Class[]{})
- .addMockedMethod("createConfig")
+ .addMockedMethod("createConfig", Cluster.class, StackId.class, String.class, Map.class,
+ String.class, Map.class)
.withConstructor(actionManager, clusters, injector)
.createNiceMock();
@@ -813,9 +815,10 @@ public class UpgradeCatalog250Test {
replay(clusters, mockAmsGrafanaIni, cluster);
AmbariManagementControllerImpl controller = createMockBuilder(AmbariManagementControllerImpl.class)
- .addMockedMethod("createConfiguration")
+ .addMockedMethod("createConfiguration", ConfigurationRequest.class)
.addMockedMethod("getClusters", new Class[]{})
- .addMockedMethod("createConfig")
+ .addMockedMethod("createConfig", Cluster.class, StackId.class, String.class, Map.class,
+ String.class, Map.class)
.withConstructor(actionManager, clusters, injector)
.createNiceMock();
@@ -894,9 +897,10 @@ public class UpgradeCatalog250Test {
replay(clusters, mockAmsHbaseSite, mockAmsSite, cluster);
AmbariManagementControllerImpl controller = createMockBuilder(AmbariManagementControllerImpl.class)
- .addMockedMethod("createConfiguration")
+ .addMockedMethod("createConfiguration", ConfigurationRequest.class)
.addMockedMethod("getClusters", new Class[]{})
- .addMockedMethod("createConfig")
+ .addMockedMethod("createConfig", Cluster.class, StackId.class, String.class, Map.class,
+ String.class, Map.class)
.withConstructor(actionManager, clusters, injector)
.createNiceMock();
@@ -948,9 +952,10 @@ public class UpgradeCatalog250Test {
replay(clusters, mockKafkaBroker, cluster);
AmbariManagementControllerImpl controller = createMockBuilder(AmbariManagementControllerImpl.class)
- .addMockedMethod("createConfiguration")
+ .addMockedMethod("createConfiguration", ConfigurationRequest.class)
.addMockedMethod("getClusters", new Class[]{})
- .addMockedMethod("createConfig")
+ .addMockedMethod("createConfig", Cluster.class, StackId.class, String.class, Map.class,
+ String.class, Map.class)
.withConstructor(actionManager, clusters, injector)
.createNiceMock();
@@ -979,9 +984,10 @@ public class UpgradeCatalog250Test {
Injector injector2 = easyMockSupport.createNiceMock(Injector.class);
AmbariManagementControllerImpl controller = createMockBuilder(AmbariManagementControllerImpl.class)
- .addMockedMethod("createConfiguration")
+ .addMockedMethod("createConfiguration", ConfigurationRequest.class)
.addMockedMethod("getClusters", new Class[]{})
- .addMockedMethod("createConfig")
+ .addMockedMethod("createConfig", Cluster.class, StackId.class, String.class, Map.class,
+ String.class, Map.class)
.withConstructor(actionManager, clusters, injector)
.createNiceMock();
@@ -1325,9 +1331,10 @@ public class UpgradeCatalog250Test {
Injector injector2 = easyMockSupport.createNiceMock(Injector.class);
AmbariManagementControllerImpl controller = createMockBuilder(AmbariManagementControllerImpl.class)
- .addMockedMethod("createConfiguration")
+ .addMockedMethod("createConfiguration", ConfigurationRequest.class)
.addMockedMethod("getClusters", new Class[]{})
- .addMockedMethod("createConfig")
+ .addMockedMethod("createConfig", Cluster.class, StackId.class, String.class, Map.class,
+ String.class, Map.class)
.withConstructor(actionManager, clusters, injector)
.createNiceMock();
@@ -1588,9 +1595,10 @@ public class UpgradeCatalog250Test {
Injector injector2 = easyMockSupport.createNiceMock(Injector.class);
AmbariManagementControllerImpl controller = createMockBuilder(AmbariManagementControllerImpl.class)
- .addMockedMethod("createConfiguration")
+ .addMockedMethod("createConfiguration", ConfigurationRequest.class)
.addMockedMethod("getClusters", new Class[]{})
- .addMockedMethod("createConfig")
+ .addMockedMethod("createConfig", Cluster.class, StackId.class, String.class, Map.class,
+ String.class, Map.class)
.withConstructor(actionManager, clusters, injector)
.createNiceMock();
@@ -1677,9 +1685,10 @@ public class UpgradeCatalog250Test {
Injector injector2 = easyMockSupport.createNiceMock(Injector.class);
AmbariManagementControllerImpl controller = createMockBuilder(AmbariManagementControllerImpl.class)
- .addMockedMethod("createConfiguration")
+ .addMockedMethod("createConfiguration", ConfigurationRequest.class)
.addMockedMethod("getClusters", new Class[]{})
- .addMockedMethod("createConfig")
+ .addMockedMethod("createConfig", Cluster.class, StackId.class, String.class, Map.class,
+ String.class, Map.class)
.withConstructor(actionManager, clusters, injector)
.createNiceMock();
@@ -1778,9 +1787,10 @@ public class UpgradeCatalog250Test {
replay(clusters, mockAtlasConfig, cluster);
AmbariManagementControllerImpl controller = createMockBuilder(AmbariManagementControllerImpl.class)
- .addMockedMethod("createConfiguration")
+ .addMockedMethod("createConfiguration", ConfigurationRequest.class)
.addMockedMethod("getClusters", new Class[]{})
- .addMockedMethod("createConfig")
+ .addMockedMethod("createConfig", Cluster.class, StackId.class, String.class, Map.class,
+ String.class, Map.class)
.withConstructor(actionManager, clusters, injector)
.createNiceMock();
@@ -2067,9 +2077,10 @@ public class UpgradeCatalog250Test {
replay(clusters, mockRangerPluginConfig, mockRangerAdminProperties, cluster);
AmbariManagementControllerImpl controller = createMockBuilder(AmbariManagementControllerImpl.class)
- .addMockedMethod("createConfiguration")
+ .addMockedMethod("createConfiguration", ConfigurationRequest.class)
.addMockedMethod("getClusters", new Class[]{})
- .addMockedMethod("createConfig")
+ .addMockedMethod("createConfig", Cluster.class, StackId.class, String.class, Map.class,
+ String.class, Map.class)
.withConstructor(actionManager, clusters, injector)
.createNiceMock();
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog260Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog260Test.java
index 0e2ecb2..e34d4a5 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog260Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog260Test.java
@@ -55,6 +55,7 @@ import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.configuration.Configuration;
import org.apache.ambari.server.controller.AmbariManagementController;
import org.apache.ambari.server.controller.AmbariManagementControllerImpl;
+import org.apache.ambari.server.controller.ConfigurationRequest;
import org.apache.ambari.server.controller.MaintenanceStateHelper;
import org.apache.ambari.server.controller.ServiceConfigVersionResponse;
import org.apache.ambari.server.orm.DBAccessor;
@@ -819,9 +820,10 @@ public class UpgradeCatalog260Test {
replay(injector, clusters, mockAmsSslClient, cluster);
AmbariManagementControllerImpl controller = createMockBuilder(AmbariManagementControllerImpl.class)
- .addMockedMethod("createConfiguration")
+ .addMockedMethod("createConfiguration", ConfigurationRequest.class)
.addMockedMethod("getClusters", new Class[] { })
- .addMockedMethod("createConfig")
+ .addMockedMethod("createConfig", Cluster.class, StackId.class, String.class, Map.class,
+ String.class, Map.class)
.withConstructor(createNiceMock(ActionManager.class), clusters, injector)
.createNiceMock();
@@ -878,9 +880,10 @@ public class UpgradeCatalog260Test {
replay(injector, clusters, mockHsiConfigs, cluster);
AmbariManagementControllerImpl controller = createMockBuilder(AmbariManagementControllerImpl.class)
- .addMockedMethod("createConfiguration")
+ .addMockedMethod("createConfiguration", ConfigurationRequest.class)
.addMockedMethod("getClusters", new Class[] { })
- .addMockedMethod("createConfig")
+ .addMockedMethod("createConfig", Cluster.class, StackId.class, String.class, Map.class,
+ String.class, Map.class)
.withConstructor(createNiceMock(ActionManager.class), clusters, injector)
.createNiceMock();