You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sw...@apache.org on 2017/12/12 04:08:53 UTC

ambari git commit: AMBARI-22602. Add 'clusterSettings' and 'stackSettings' parameters in Execution Commannd.

Repository: ambari
Updated Branches:
  refs/heads/branch-feature-AMBARI-14714 bcbacf0c7 -> 982ac4bae


AMBARI-22602. Add 'clusterSettings' and 'stackSettings' parameters in Execution Commannd.


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/982ac4ba
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/982ac4ba
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/982ac4ba

Branch: refs/heads/branch-feature-AMBARI-14714
Commit: 982ac4bae9bf199e8415326780522917c61e76b0
Parents: bcbacf0
Author: Swapan Shridhar <ss...@hortonworks.com>
Authored: Mon Dec 11 16:37:54 2017 -0800
Committer: Swapan Shridhar <ss...@hortonworks.com>
Committed: Mon Dec 11 20:08:43 2017 -0800

----------------------------------------------------------------------
 .../ambari/server/agent/ExecutionCommand.java   | 23 ++++++++++++++++++++
 .../server/api/services/AmbariMetaInfo.java     | 16 ++++++++++++++
 .../AmbariCustomCommandExecutionHelper.java     | 10 +++++++++
 .../AmbariManagementControllerImpl.java         |  9 ++++++++
 .../internal/ClientConfigResourceProvider.java  | 15 +++++++++++++
 .../resources/RootLevelSettingsManager.java     |  2 --
 .../org/apache/ambari/server/state/Cluster.java |  8 +++++++
 .../server/state/cluster/ClusterImpl.java       | 10 +++++++++
 8 files changed, 91 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/982ac4ba/ambari-server/src/main/java/org/apache/ambari/server/agent/ExecutionCommand.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/agent/ExecutionCommand.java b/ambari-server/src/main/java/org/apache/ambari/server/agent/ExecutionCommand.java
index 5ee4bf6..977ff93 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/agent/ExecutionCommand.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/agent/ExecutionCommand.java
@@ -54,6 +54,12 @@ public class ExecutionCommand extends AgentCommand {
   @SerializedName("clusterName")
   private String clusterName;
 
+  @SerializedName("clusterSettings")
+  private Map<String, String> clusterSettings;
+
+  @SerializedName("stackSettings")
+  private Map<String, String> stackSettings;
+
   @SerializedName("requestId")
   private long requestId;
 
@@ -278,6 +284,23 @@ public class ExecutionCommand extends AgentCommand {
     hostLevelParams = params;
   }
 
+  public Map<String, String> getClusterSettings() {
+    return clusterSettings;
+  }
+
+  public void setClusterSettings(Map<String, String> clusterSettings) {
+    this.clusterSettings = clusterSettings;
+  }
+
+
+  public Map<String, String> getStackSettings() {
+    return stackSettings;
+  }
+
+  public void setStackSettings(Map<String, String> stackSettings) {
+    this.stackSettings = stackSettings;
+  }
+
   public Map<String, Set<String>> getClusterHostInfo() {
     return clusterHostInfo;
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/982ac4ba/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
index fd43edf..af291f6 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
@@ -22,6 +22,7 @@ import static org.apache.ambari.server.controller.spi.Resource.InternalType.Comp
 import static org.apache.ambari.server.controller.spi.Resource.InternalType.HostComponent;
 import static org.apache.ambari.server.controller.utilities.PropertyHelper.AGGREGATE_FUNCTION_IDENTIFIERS;
 
+import com.google.common.collect.Maps;
 import java.io.File;
 import java.io.FileReader;
 import java.io.IOException;
@@ -37,6 +38,7 @@ import java.util.Map;
 import java.util.Scanner;
 import java.util.Set;
 
+import java.util.stream.Collectors;
 import javax.xml.bind.JAXBException;
 
 import org.apache.ambari.server.AmbariException;
@@ -848,6 +850,20 @@ public class AmbariMetaInfo {
   }
 
   /*
+  Returns read only 'Stack Settings' name and value as map.
+  If stack settings are not fond, returns an Empty Map.
+  */
+  public Map<String, String> getStackSettingsNameValueMap(StackId stackId)
+          throws AmbariException {
+    Set<PropertyInfo> stackSettings = getStackSettings(stackId.getStackName(), stackId.getStackVersion());
+    if (stackSettings != null) {
+      return stackSettings.stream().collect(
+              Collectors.toMap(PropertyInfo::getName, PropertyInfo::getValue));
+    }
+    return Maps.newHashMap();
+  }
+
+  /*
   Returns specific read only 'Stack Setting'.
   */
   public Set<PropertyInfo> getStackSettingsByName(String stackName, String version, String settingName)

http://git-wip-us.apache.org/repos/asf/ambari/blob/982ac4ba/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
index e7dea06..94589c3 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
@@ -53,6 +53,7 @@ import java.util.Map;
 import java.util.Random;
 import java.util.Set;
 import java.util.TreeMap;
+import java.util.stream.Collectors;
 
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.Role;
@@ -72,6 +73,7 @@ import org.apache.ambari.server.controller.spi.SystemException;
 import org.apache.ambari.server.metadata.ActionMetadata;
 import org.apache.ambari.server.orm.dao.HostRoleCommandDAO;
 import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.ClusterSetting;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.CommandScriptDefinition;
 import org.apache.ambari.server.state.ComponentInfo;
@@ -102,6 +104,8 @@ import org.apache.commons.lang.math.NumberUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.collect.Maps;
+
 import com.google.gson.Gson;
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
@@ -428,6 +432,12 @@ public class AmbariCustomCommandExecutionHelper {
       String userGroups = gson.toJson(userGroupsMap);
       hostLevelParams.put(USER_GROUPS, userGroups);
 
+      // Set exec command with 'ClusterSettings' map
+      execCmd.setClusterSettings(cluster.getClusterSettingsNameValueMap());
+
+      // Set exec command with 'StackSettings' map
+      execCmd.setStackSettings(ambariMetaInfo.getStackSettingsNameValueMap(stackId));
+
       Set<String> groupSet = configHelper.getPropertyValuesWithPropertyType(stackId, PropertyType.GROUP, cluster, desiredConfigs);
       String groupList = gson.toJson(groupSet);
       hostLevelParams.put(GROUP_LIST, groupList);

http://git-wip-us.apache.org/repos/asf/ambari/blob/982ac4ba/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
----------------------------------------------------------------------
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 59e6622..36c6fc6 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
@@ -65,6 +65,7 @@ import java.util.Set;
 import java.util.TreeMap;
 import java.util.UUID;
 import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
 
 import javax.persistence.RollbackException;
 
@@ -162,6 +163,7 @@ import org.apache.ambari.server.stack.RepoUtil;
 import org.apache.ambari.server.stageplanner.RoleGraph;
 import org.apache.ambari.server.stageplanner.RoleGraphFactory;
 import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.ClusterSetting;
 import org.apache.ambari.server.state.ClusterSettingFactory;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.CommandScriptDefinition;
@@ -230,6 +232,7 @@ import com.google.common.cache.Cache;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.collect.ArrayListMultimap;
 import com.google.common.collect.ListMultimap;
+import com.google.common.collect.Maps;
 import com.google.common.collect.Multimap;
 import com.google.gson.Gson;
 import com.google.gson.reflect.TypeToken;
@@ -2670,6 +2673,12 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
     String userGroups = gson.toJson(userGroupsMap);
     hostParams.put(USER_GROUPS, userGroups);
 
+    // Set exec command with 'ClusterSettings' map
+    execCmd.setClusterSettings(cluster.getClusterSettingsNameValueMap());
+
+    // Set exec command with 'StackSettings' map
+    execCmd.setStackSettings(ambariMetaInfo.getStackSettingsNameValueMap(stackId));
+
     Set<String> groupSet = configHelper.getPropertyValuesWithPropertyType(PropertyType.GROUP, cluster, clusterDesiredConfigs, servicesMap, stackProperties);
     String groupList = gson.toJson(groupSet);
     hostParams.put(GROUP_LIST, groupList);

http://git-wip-us.apache.org/repos/asf/ambari/blob/982ac4ba/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProvider.java
index 9043297..64d5eca 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProvider.java
@@ -61,6 +61,8 @@ import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 
+import java.util.stream.Collectors;
+
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.configuration.Configuration;
@@ -80,11 +82,13 @@ import org.apache.ambari.server.controller.spi.UnsupportedPropertyException;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
 import org.apache.ambari.server.state.ClientConfigFileDefinition;
 import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.ClusterSetting;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.ComponentInfo;
 import org.apache.ambari.server.state.Config;
 import org.apache.ambari.server.state.ConfigHelper;
 import org.apache.ambari.server.state.DesiredConfig;
+import org.apache.ambari.server.state.PropertyInfo;
 import org.apache.ambari.server.state.PropertyInfo.PropertyType;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponent;
@@ -103,6 +107,7 @@ import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.collect.Maps;
 import com.google.gson.Gson;
 import com.google.inject.assistedinject.Assisted;
 import com.google.inject.assistedinject.AssistedInject;
@@ -277,6 +282,14 @@ public class ClientConfigResourceProvider extends AbstractControllerResourceProv
 
         Map<String, DesiredConfig> desiredClusterConfigs = cluster.getDesiredConfigs();
 
+
+        // Create 'clusterSettings' map
+        Map<String, String> clusterSettingsMap = cluster.getClusterSettingsNameValueMap();
+
+        // Create 'stackSettings' map
+        Map<String, String> stackSettingsMap = managementController.getAmbariMetaInfo().getStackSettingsNameValueMap(stackId);
+
+
         //Get configurations and configuration attributes
         for (Map.Entry<String, DesiredConfig> desiredConfigEntry : desiredClusterConfigs.entrySet()) {
 
@@ -437,6 +450,8 @@ public class ClientConfigResourceProvider extends AbstractControllerResourceProv
 
         Map<String, Object> jsonContent = new TreeMap<>();
         jsonContent.put("configurations", configurations);
+        jsonContent.put("clusterSettings", clusterSettingsMap);
+        jsonContent.put("stackSettings", stackSettingsMap);
         jsonContent.put("configuration_attributes", configurationAttributes);
         jsonContent.put("commandParams", commandParams);
         jsonContent.put("clusterHostInfo", clusterHostInfo);

http://git-wip-us.apache.org/repos/asf/ambari/blob/982ac4ba/ambari-server/src/main/java/org/apache/ambari/server/resources/RootLevelSettingsManager.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/resources/RootLevelSettingsManager.java b/ambari-server/src/main/java/org/apache/ambari/server/resources/RootLevelSettingsManager.java
index 8bd24f2..cc48bde 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/resources/RootLevelSettingsManager.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/resources/RootLevelSettingsManager.java
@@ -25,7 +25,6 @@ import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
 
 import javax.xml.namespace.QName;
 
@@ -54,7 +53,6 @@ public class RootLevelSettingsManager {
   private String clusterSettingsConfigType;
   private static File clusterSettingsFile;
   private final static Logger LOG = LoggerFactory.getLogger(RootLevelSettingsManager.class);
-  private Map<String, Map<String, PropertyInfo>> clusterSettingsMap = new ConcurrentHashMap<>();
   private Map<String, ConfigurationModule> configurationModules = new HashMap<>();
 
   @AssistedInject

http://git-wip-us.apache.org/repos/asf/ambari/blob/982ac4ba/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
----------------------------------------------------------------------
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 c8768dd..d12e8cd 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
@@ -215,6 +215,14 @@ public interface Cluster {
   Map<String, ClusterSetting> getClusterSettings() throws AmbariException;
 
   /**
+   * Get all cluster settings name and value as Map.
+   * If cluster settings are not fonud, returns an Empty Map.
+   *
+   * @return
+   */
+  Map<String, String> getClusterSettingsNameValueMap() throws AmbariException;
+
+  /**
    * Get all ServiceComponentHosts on a given host
    *
    * @param hostname

http://git-wip-us.apache.org/repos/asf/ambari/blob/982ac4ba/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
----------------------------------------------------------------------
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 3b0ebae..7ca13e8 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
@@ -1233,6 +1233,16 @@ public class ClusterImpl implements Cluster {
   }
 
   @Override
+  public Map<String, String> getClusterSettingsNameValueMap() throws AmbariException {
+    Map<String, ClusterSetting> clusterSettings = getClusterSettings();
+    if (clusterSettings != null) {
+      return clusterSettings.values().stream().collect(
+              Collectors.toMap(ClusterSetting::getClusterSettingName, ClusterSetting::getClusterSettingValue));
+    }
+    return Maps.newHashMap();
+  }
+
+  @Override
   public StackId getDesiredStackVersion() {
     return desiredStackVersion;
   }