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

mpapirkovskyy 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 2caa282  AMBARI-23263. hdfs-site.xml is not getting updated after 
config change and restart via Ambari. (mpapirkovskyy)
2caa282 is described below

commit 2caa282fdd0ed47167a459b86d1358ef0d26c39f
Author: Myroslav Papirkovskyi <[email protected]>
AuthorDate: Wed Mar 21 20:34:11 2018 +0200

    AMBARI-23263. hdfs-site.xml is not getting updated after config change and 
restart via Ambari. (mpapirkovskyy)
---
 .../org/apache/ambari/server/orm/dao/ClusterDAO.java | 18 ++++++++++++++++++
 .../server/orm/entities/ClusterConfigEntity.java     |  5 ++++-
 .../java/org/apache/ambari/server/state/Cluster.java |  7 +++++++
 .../org/apache/ambari/server/state/ConfigHelper.java |  2 +-
 .../ambari/server/state/cluster/ClusterImpl.java     | 20 +++++++++++++++-----
 5 files changed, 45 insertions(+), 7 deletions(-)

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 a1b6fbe..b6786fc 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
@@ -255,6 +255,24 @@ public class ClusterDAO {
   }
 
   /**
+   * Gets the latest configurations for the specified cluster.
+   *
+   * @param clusterId
+   *          the cluster that the service is a part of.
+   * @return the latest configurations for the specified cluster.
+   */
+  @RequiresSession
+  public List<ClusterConfigEntity> getEnabledConfigs(long clusterId) {
+
+    TypedQuery<ClusterConfigEntity> query = 
entityManagerProvider.get().createNamedQuery(
+        "ClusterConfigEntity.findEnabledConfigs", ClusterConfigEntity.class);
+
+    query.setParameter("clusterId", clusterId);
+
+    return daoUtils.selectList(query);
+  }
+
+  /**
    * Gets the latest config in the given cluster by type name. Only a config
    * which is enabled can be returned.
    *
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterConfigEntity.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterConfigEntity.java
index 0c5276c..287ee89 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterConfigEntity.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterConfigEntity.java
@@ -75,7 +75,10 @@ import org.apache.commons.lang.builder.EqualsBuilder;
         query = "SELECT config FROM ClusterConfigEntity config WHERE 
config.clusterId = :clusterId AND config.selected = 1 and config.type = :type"),
     @NamedQuery(
         name = "ClusterConfigEntity.findEnabledConfigsByTypes",
-        query = "SELECT config FROM ClusterConfigEntity config WHERE 
config.clusterId = :clusterId AND config.selected = 1 and config.type in 
:types") })
+        query = "SELECT config FROM ClusterConfigEntity config WHERE 
config.clusterId = :clusterId AND config.selected = 1 and config.type in 
:types"),
+    @NamedQuery(
+        name = "ClusterConfigEntity.findEnabledConfigs",
+        query = "SELECT config FROM ClusterConfigEntity config WHERE 
config.clusterId = :clusterId AND config.selected = 1") })
 
 public class ClusterConfigEntity {
 
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 9a68428..686af5c 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
@@ -387,6 +387,13 @@ public interface Cluster {
    */
   Map<String, DesiredConfig> getDesiredConfigs();
 
+  /**
+   * Gets the active desired configurations for the cluster.
+   * @param cachedConfigEntities retrieves cluster config entities from the 
cache if true, otherwise from the DB directly.
+   * @return a map of type-to-configuration information.
+   */
+  Map<String, DesiredConfig> getDesiredConfigs(boolean cachedConfigEntities);
+
   ClusterEntity getClusterEntity();
 
   /**
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java 
b/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java
index 339aeb9..73afef7 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java
@@ -1943,7 +1943,7 @@ public class ConfigHelper {
       if (LOG.isInfoEnabled()) {
         LOG.info("For configs update on host {} will be used cluster entity 
{}", hostId, cl.getClusterEntity().toString());
       }
-      Map<String, DesiredConfig> clusterDesiredConfigs = 
cl.getDesiredConfigs();
+      Map<String, DesiredConfig> clusterDesiredConfigs = 
cl.getDesiredConfigs(false);
       LOG.info("For configs update on host {} will be used following cluster 
desired configs {}", hostId,
           clusterDesiredConfigs.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 0335879..3df9943 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
@@ -1439,13 +1439,18 @@ public class ClusterImpl implements Cluster {
    */
   @Override
   public Map<String, Set<DesiredConfig>> getAllDesiredConfigVersions() {
-    return getDesiredConfigs(true);
+    return getDesiredConfigs(true, true);
   }
 
 
   @Override
   public Map<String, DesiredConfig> getDesiredConfigs() {
-    Map<String, Set<DesiredConfig>> activeConfigsByType = 
getDesiredConfigs(false);
+    return getDesiredConfigs(true);
+  }
+
+  @Override
+  public Map<String, DesiredConfig> getDesiredConfigs(boolean 
cachedConfigEntities) {
+    Map<String, Set<DesiredConfig>> activeConfigsByType = 
getDesiredConfigs(false, cachedConfigEntities);
     return Maps.transformEntries(
         activeConfigsByType,
         new Maps.EntryTransformer<String, Set<DesiredConfig>, DesiredConfig>() 
{
@@ -1461,15 +1466,20 @@ public class ClusterImpl implements Cluster {
    * @param allVersions specifies if all versions of the desired 
configurations to be returned
    *                    or only the active ones. It is expected that there is 
one and only one active
    *                    desired configuration per config type.
+   * @param cachedConfigEntities retrieves cluster config entities from the 
cache if true, otherwise from the DB directly.
    * @return a map of type-to-configuration information.
    */
-  private Map<String, Set<DesiredConfig>> getDesiredConfigs(boolean 
allVersions) {
+  private Map<String, Set<DesiredConfig>> getDesiredConfigs(boolean 
allVersions, boolean cachedConfigEntities) {
     clusterGlobalLock.readLock().lock();
     try {
       Map<String, Set<DesiredConfig>> map = new HashMap<>();
       Collection<String> types = new HashSet<>();
-      Collection<ClusterConfigEntity> entities = 
getClusterEntity().getClusterConfigEntities();
-
+      Collection<ClusterConfigEntity> entities;
+      if (cachedConfigEntities) {
+        entities = getClusterEntity().getClusterConfigEntities();
+      } else {
+        entities = clusterDAO.getEnabledConfigs(clusterId);
+      }
       for (ClusterConfigEntity configEntity : entities) {
         if (allVersions || configEntity.isSelected()) {
           DesiredConfig desiredConfig = new DesiredConfig();

-- 
To stop receiving notification emails like this one, please contact
[email protected].

Reply via email to