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/09/25 13:48:59 UTC
[ambari] branch branch-2.7 updated: AMBARI-25385. Reduce cluster
creation request processing time. (mpapirkovskyy) (#3085)
This is an automated email from the ASF dual-hosted git repository.
mpapirkovskyy pushed a commit to branch branch-2.7
in repository https://gitbox.apache.org/repos/asf/ambari.git
The following commit(s) were added to refs/heads/branch-2.7 by this push:
new 913ab58 AMBARI-25385. Reduce cluster creation request processing time. (mpapirkovskyy) (#3085)
913ab58 is described below
commit 913ab5862e00669808e6776a23123b2d2f03ce24
Author: Myroslav Papirkovskyi <mp...@apache.org>
AuthorDate: Wed Sep 25 16:48:52 2019 +0300
AMBARI-25385. Reduce cluster creation request processing time. (mpapirkovskyy) (#3085)
---
.../controller/AmbariManagementController.java | 24 +++++++++++++--
.../controller/AmbariManagementControllerImpl.java | 36 +++++++++++++++-------
.../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 | 19 ++++++++++--
.../server/state/configgroup/ConfigGroupImpl.java | 4 +--
.../ambari/server/topology/AmbariContext.java | 3 +-
.../topology/ClusterConfigurationRequest.java | 3 ++
.../topology/ClusterDeployWithStartOnlyTest.java | 1 +
...terInstallWithoutStartOnComponentLevelTest.java | 1 +
.../topology/ClusterInstallWithoutStartTest.java | 1 +
.../server/topology/TopologyManagerTest.java | 29 ++++++++++++++---
.../server/upgrade/UpgradeCatalog260Test.java | 11 ++++---
.../server/upgrade/UpgradeCatalog270Test.java | 30 +++++++++++-------
.../server/upgrade/UpgradeCatalog271Test.java | 16 ++++++----
18 files changed, 203 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 57e80f5..19213e3 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
@@ -121,6 +121,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.
*/
@@ -133,6 +144,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);
/**
@@ -262,13 +280,15 @@ public interface AmbariManagementController {
*
* @param fireAgentUpdates should agent updates (configurations, metadata etc.) be fired inside
*
+ * @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 fireAgentUpdates)
+ RequestStatusResponse updateClusters(Set<ClusterRequest> requests, Map<String, String> requestProperties,
+ boolean fireAgentUpdates, boolean refreshCluster)
throws AmbariException, AuthorizationException;
/**
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 38a8436..31cc39a 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
@@ -922,7 +922,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()) {
@@ -1059,7 +1059,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(),
@@ -1070,17 +1070,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 createGroups(Set<GroupRequest> requests) throws AmbariException {
for (GroupRequest request : requests) {
if (StringUtils.isBlank(request.getGroupName())) {
@@ -1566,14 +1579,14 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
public synchronized RequestStatusResponse updateClusters(Set<ClusterRequest> requests,
Map<String, String> requestProperties)
throws AmbariException, AuthorizationException {
- return updateClusters(requests, requestProperties, true);
+ return updateClusters(requests, requestProperties, true, true);
}
@Override
@Transactional
public synchronized RequestStatusResponse updateClusters(Set<ClusterRequest> requests,
Map<String, String> requestProperties,
- boolean fireAgentUpdates)
+ boolean fireAgentUpdates, boolean refreshCluster)
throws AmbariException, AuthorizationException {
RequestStatusResponse response = null;
@@ -1581,7 +1594,7 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
// We have to allow for multiple requests to account for multiple
// configuration updates (create multiple configuration resources)...
for (ClusterRequest request : requests) {
- response = updateCluster(request, requestProperties, fireAgentUpdates);
+ response = updateCluster(request, requestProperties, fireAgentUpdates, refreshCluster);
}
return response;
}
@@ -1682,7 +1695,7 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
private synchronized RequestStatusResponse updateCluster(ClusterRequest request,
Map<String, String> requestProperties,
- boolean fireAgentUpdates
+ boolean fireAgentUpdates, boolean refreshCluster
)
throws AmbariException, AuthorizationException {
@@ -1841,7 +1854,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(),
@@ -5795,7 +5809,7 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
PropertyType.NOT_MANAGED_HDFS_PATH, cluster, desiredConfigs);
String notManagedHdfsPathList = gson.toJson(notManagedHdfsPathSet);
clusterLevelParams.put(NOT_MANAGED_HDFS_PATH_LIST, notManagedHdfsPathList);
-
+
for (Service service : cluster.getServices().values()) {
ServiceInfo serviceInfoInstance = ambariMetaInfo.getService(service);
String serviceType = serviceInfoInstance.getServiceType();
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 b6786fc..1bdfea3 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
@@ -380,6 +380,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
@@ -399,6 +408,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 c22449c..b92082e 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 c201310..0955200 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
@@ -431,6 +431,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 2879345..6872acb 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
@@ -47,7 +47,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 b3ff843..fb3bb75 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
@@ -105,18 +105,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 @Nullable StackId stackId, @Assisted Cluster cluster, @Assisted("type") String type,
+ ConfigImpl(@Assisted @Nullable 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);
@@ -158,12 +158,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) {
@@ -343,14 +354,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 29a0700..6dbabc4 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
@@ -1312,6 +1312,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, DeleteHostComponentStatusMetaData deleteMetaData)
throws AmbariException {
clusterGlobalLock.writeLock().lock();
@@ -1389,6 +1403,7 @@ public class ClusterImpl implements Cluster {
try {
refresh();
deleteAllServices();
+ deleteAllClusterConfigs();
resetHostVersions();
refresh(); // update one-to-many clusterServiceEntities
@@ -2003,7 +2018,7 @@ public class ClusterImpl implements Cluster {
}
}
- clusterEntity = clusterDAO.merge(clusterEntity);
+ clusterDAO.merge(clusterConfigs);
if (serviceName == null) {
ArrayList<String> configTypes = new ArrayList<>();
@@ -2519,7 +2534,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 9760915..ebbfe9b 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
@@ -419,8 +419,8 @@ public class ConfigGroupImpl implements ConfigGroup {
String serviceName = getServiceName();
Service service = cluster.getService(serviceName);
- config = configFactory.createNew(service.getDesiredStackId(), cluster, config.getType(),
- config.getTag(), config.getProperties(), config.getPropertiesAttributes());
+ config = configFactory.createNew(service.getDesiredStackId(), 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 6e95c4d..3b0d169 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
@@ -533,7 +533,8 @@ public class AmbariContext {
RetryHelper.executeWithRetry(new Callable<Object>() {
@Override
public Object call() throws Exception {
- getController().updateClusters(Collections.singleton(clusterRequest), null, false);
+ getController().updateClusters(Collections.singleton(clusterRequest), null,
+ false, 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 985c290..44a520b 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
@@ -399,8 +399,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);
@@ -468,6 +470,7 @@ public class ClusterConfigurationRequest {
LOG.error("ClusterRequest should not be null for service = " + blueprintConfigRequest.getServiceName());
}
}
+ cluster.refresh();
ambariContext.notifyAgentsAboutConfigsChanges(clusterName);
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 3a98ab0..9d3cbc5 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
@@ -340,6 +340,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 46e3ff9..6bc3963 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
@@ -342,6 +342,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 61face9..773683c 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
@@ -339,6 +339,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 c045686..d514cdf 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.KerberosHelper;
@@ -71,6 +73,8 @@ import org.apache.ambari.server.security.authorization.AuthorizationHelper;
import org.apache.ambari.server.security.encryption.CredentialStoreService;
import org.apache.ambari.server.security.encryption.CredentialStoreType;
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;
@@ -97,7 +101,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";
@@ -172,6 +176,12 @@ public class TopologyManagerTest {
private ConfigureClusterTask configureClusterTask;
@Mock(type = MockType.NICE)
private AmbariEventPublisher eventPublisher;
+ @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;
@@ -346,6 +356,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))).
@@ -393,6 +405,14 @@ public class TopologyManagerTest {
f.set(ambariContext, clusterController);
EasyMockSupport.injectMocks(ambariContext);
+
+ 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
@@ -401,13 +421,13 @@ public class TopologyManagerTest {
verify(blueprint, stack, request, group1, group2, ambariContext, logicalRequestFactory,
logicalRequest, configurationRequest, configurationRequest2, configurationRequest3,
requestStatusResponse, executor, persistedState, clusterTopologyMock, mockFuture, settingDAO, eventPublisher,
- securityConfiguration, credential);
+ securityConfiguration, credential, 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, eventPublisher,
- securityConfiguration, credential);
+ securityConfiguration, credential, ambariManagementController, clusters, cluster);
}
@Test
@@ -629,7 +649,8 @@ public class TopologyManagerTest {
configurationRequest, configurationRequest2, configurationRequest3, executor,
persistedState, clusterTopologyMock, securityConfigurationFactory, credentialStoreService,
clusterController, resourceProvider, mockFuture, requestStatusResponse, logicalRequest, settingDAO,
- configureClusterTaskFactory, configureClusterTask, eventPublisher, securityConfiguration, credential);
+ configureClusterTaskFactory, configureClusterTask, eventPublisher, securityConfiguration, credential,
+ ambariManagementController, clusters, cluster);
}
@Test(expected = InvalidTopologyException.class)
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 dc0e93c..e51bdd8 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
@@ -70,6 +70,7 @@ import org.apache.ambari.server.configuration.Configuration;
import org.apache.ambari.server.controller.AbstractRootServiceResponseFactory;
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.KerberosHelperImpl;
import org.apache.ambari.server.controller.MaintenanceStateHelper;
@@ -900,9 +901,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();
@@ -959,9 +961,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();
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog270Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog270Test.java
index 329aea0..ce0bdd2 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog270Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog270Test.java
@@ -185,6 +185,7 @@ import org.apache.ambari.server.controller.AbstractRootServiceResponseFactory;
import org.apache.ambari.server.controller.AmbariManagementController;
import org.apache.ambari.server.controller.AmbariManagementControllerImpl;
import org.apache.ambari.server.controller.AmbariServer;
+import org.apache.ambari.server.controller.ConfigurationRequest;
import org.apache.ambari.server.controller.KerberosHelper;
import org.apache.ambari.server.controller.KerberosHelperImpl;
import org.apache.ambari.server.controller.MaintenanceStateHelper;
@@ -988,9 +989,10 @@ public class UpgradeCatalog270Test {
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)
.createNiceMock();
ConfigHelper configHelper = createMockBuilder(ConfigHelper.class)
.addMockedMethod("createConfigType", Cluster.class, StackId.class, AmbariManagementController.class,
@@ -1202,9 +1204,10 @@ public class UpgradeCatalog270Test {
Capture<Map<String, String>> capturedProperties = newCapture();
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)
.addMockedMethod("getClusterMetadataOnConfigsUpdate", Cluster.class)
.createMock();
expect(controller.getClusters()).andReturn(clusters).anyTimes();
@@ -1455,9 +1458,10 @@ public class UpgradeCatalog270Test {
replay(injector, clusters, mockAmsSite, mockAmsHbaseSite, 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();
@@ -1517,9 +1521,10 @@ public class UpgradeCatalog270Test {
replay(injector, clusters, 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(createNiceMock(ActionManager.class), clusters, injector)
.createNiceMock();
@@ -1576,7 +1581,8 @@ public class UpgradeCatalog270Test {
AmbariManagementControllerImpl controller = createMockBuilder(AmbariManagementControllerImpl.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();
@@ -1634,7 +1640,8 @@ public class UpgradeCatalog270Test {
AmbariManagementControllerImpl controller = createMockBuilder(AmbariManagementControllerImpl.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();
@@ -1687,7 +1694,8 @@ public class UpgradeCatalog270Test {
AmbariManagementControllerImpl controller = createMockBuilder(AmbariManagementControllerImpl.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();
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog271Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog271Test.java
index 22c0a7c..78a045e 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog271Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog271Test.java
@@ -41,6 +41,7 @@ import java.util.Map;
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.orm.DBAccessor;
import org.apache.ambari.server.orm.dao.DaoUtils;
import org.apache.ambari.server.state.BlueprintProvisioningState;
@@ -183,9 +184,10 @@ public class UpgradeCatalog271Test {
Injector injector = 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)
.createNiceMock();
expect(injector.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes();
@@ -265,9 +267,10 @@ public class UpgradeCatalog271Test {
Injector injector = 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)
.createNiceMock();
expect(injector.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes();
@@ -327,9 +330,10 @@ public class UpgradeCatalog271Test {
Injector injector = 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)
.createNiceMock();
DaoUtils daoUtilsMock = easyMockSupport.createNiceMock(DaoUtils.class);