You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by wu...@apache.org on 2022/11/14 16:36:16 UTC

[ambari] branch trunk updated: AMBARI-25385: Reduce cluster creation request processing time (#3489)

This is an automated email from the ASF dual-hosted git repository.

wuzhiguo pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 364437479e AMBARI-25385: Reduce cluster creation request processing time (#3489)
364437479e is described below

commit 364437479ef189f5ec6ceacd2dbd15ee25ef1e59
Author: Zhiguo Wu <wu...@apache.org>
AuthorDate: Tue Nov 15 00:36:11 2022 +0800

    AMBARI-25385: Reduce cluster creation request processing time (#3489)
---
 .../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 | 28 ++++++++++++-----
 .../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(+), 52 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 fe4af8386d..0e65f51c09 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
@@ -120,6 +120,17 @@ public interface AmbariManagementController {
   void createHostComponents(
       Set<ServiceComponentHostRequest> requests, boolean isBlueprintProvisioned) throws AmbariException, AuthorizationException;
 
+  /**
+   * 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.
    *
@@ -135,6 +146,13 @@ public interface AmbariManagementController {
    * TODO move this method to Cluster? doesn't seem to be on its place
    * @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);
 
@@ -274,13 +292,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 bb59855484..16f0275791 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
@@ -1029,7 +1029,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()) {
@@ -1166,7 +1166,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(),
@@ -1176,17 +1176,30 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
     return new ConfigurationResponse(cluster.getClusterName(), config);
   }
 
+  @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) {
@@ -1673,14 +1686,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;
@@ -1688,7 +1701,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;
   }
@@ -1789,7 +1802,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 {
 
@@ -1949,7 +1962,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(),
@@ -5929,7 +5943,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 41d032f603..29cc548f1f 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
@@ -383,6 +383,15 @@ public class ClusterDAO {
     return merge(clusterConfigEntity, false);
   }
 
+  /**
+   * 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.
    *
@@ -403,6 +412,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 c22449c1af..b92082ea39 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 c4b418c991..30fd197ab6 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
@@ -438,6 +438,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
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 287934534b..6872acb141 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 9da9771d36..8689715a6d 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
@@ -109,18 +109,30 @@ public class ConfigImpl implements Config {
              ClusterDAO clusterDAO, StackDAO stackDAO,
              Gson gson, AmbariEventPublisher eventPublisher, LockFactory lockFactory,
              @Named("ConfigPropertiesEncryptor") Encryptor<Config> configPropertiesEncryptor) {
-    this(cluster.getDesiredStackVersion(), cluster, type, tag, properties, propertiesAttributes,
-        clusterDAO, stackDAO, gson, eventPublisher, lockFactory, configPropertiesEncryptor);
+    this(cluster.getDesiredStackVersion(), type, cluster, tag, properties, propertiesAttributes,
+            clusterDAO, stackDAO, gson, eventPublisher, lockFactory, true, configPropertiesEncryptor);
   }
 
+  @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,
+             @Named("ConfigPropertiesEncryptor") Encryptor<Config> configPropertiesEncryptor) {
+    this(stackId, type, cluster, tag, properties, propertiesAttributes, clusterDAO, stackDAO, gson, eventPublisher,
+            lockFactory, true, configPropertiesEncryptor);
+  }
 
   @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,
+             @Assisted boolean refreshCluster,
              @Named("ConfigPropertiesEncryptor") Encryptor<Config> configPropertiesEncryptor) {
 
     propertyLock = lockFactory.newReadWriteLock(PROPERTY_LOCK_LABEL);
@@ -164,7 +176,7 @@ 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();
     configPropertiesEncryptor.decryptSensitiveData(this);
@@ -356,14 +368,16 @@ 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(),
@@ -384,7 +398,7 @@ public class ConfigImpl implements Config {
 
     // save the entity, forcing a flush to ensure the refresh picks up the
     // newest data
-    clusterEntity = clusterDAO.merge(clusterEntity, true);
+    clusterDAO.merge(entity, true);
     LOG.info("Persisted config entity with id {} and cluster entity {}", entity.getConfigId(),
         clusterEntity.toString());
   }
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 8959e6f770..11420ed071 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
@@ -1338,6 +1338,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 {
@@ -1416,6 +1430,7 @@ public class ClusterImpl implements Cluster {
     try {
       refresh();
       deleteAllServices();
+      deleteAllClusterConfigs();
       resetHostVersions();
 
       refresh(); // update one-to-many clusterServiceEntities
@@ -2030,7 +2045,7 @@ public class ClusterImpl implements Cluster {
       }
     }
 
-    clusterEntity = clusterDAO.merge(clusterEntity);
+    clusterDAO.merge(clusterConfigs);
 
     if (serviceName == null) {
       ArrayList<String> configTypes = new ArrayList<>();
@@ -2546,7 +2561,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 9760915298..ebbfe9bb71 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 34268ca91c..e6b778c67a 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
@@ -546,7 +546,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 cdaeae45be..65f31360f3 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
@@ -334,8 +334,10 @@ public class ClusterConfigurationRequest {
   private void setConfigurationsOnCluster(List<BlueprintServiceConfigRequest> configurationRequests,
                                          String tag, Set<String> updatedConfigTypes)  {
     String clusterName;
+    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);
@@ -403,6 +405,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 d91a30d9db..c88f5302ed 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
@@ -339,6 +339,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 2067620a97..01261398f9 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
@@ -341,6 +341,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 59acbe9bc3..c8f10dbdcb 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
@@ -338,6 +338,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 15c38efcd1..1acfbb126d 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;
@@ -345,6 +355,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))).
@@ -392,6 +404,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
@@ -400,13 +420,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
@@ -628,7 +648,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 dea6bef573..be9ee4f5da 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 50e01154a2..8478c958af 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;
@@ -990,9 +991,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,
@@ -1204,9 +1206,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();
@@ -1460,9 +1463,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();
 
@@ -1522,9 +1526,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();
 
@@ -1581,7 +1586,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();
 
@@ -1639,7 +1645,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();
 
@@ -1692,7 +1699,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 22c0a7c832..78a045ec8e 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);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@ambari.apache.org
For additional commands, e-mail: commits-help@ambari.apache.org