Преглед изворни кода

AMBARI-13521 Allow Monitors/Agents to be configured to communicate with a collector that is behind a VIP (dsen)

Dmytro Sen пре 9 година
родитељ
комит
0c1d4b928e
24 измењених фајлова са 232 додато и 102 уклоњено
  1. 81 33
      ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java
  2. 2 2
      ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/MetricHostProvider.java
  3. 1 2
      ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/AMSPropertyProvider.java
  4. 1 1
      ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/AMSReportPropertyProvider.java
  5. 14 5
      ambari-server/src/main/resources/common-services/ACCUMULO/1.6.1.2.2.0/package/scripts/params.py
  6. 14 5
      ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/params.py
  7. 4 4
      ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/service_check.py
  8. 4 4
      ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/templates/hadoop-metrics2-hbase.properties.j2
  9. 1 1
      ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/templates/metric_monitor.ini.j2
  10. 14 4
      ambari-server/src/main/resources/common-services/FLUME/1.4.0.2.0/package/scripts/params.py
  11. 14 4
      ambari-server/src/main/resources/common-services/HBASE/0.96.0.2.0/package/scripts/params_linux.py
  12. 15 5
      ambari-server/src/main/resources/common-services/KAFKA/0.8.1.2.2/package/scripts/params.py
  13. 15 1
      ambari-server/src/main/resources/common-services/STORM/0.9.1.2.1/package/scripts/params_linux.py
  14. 1 1
      ambari-server/src/main/resources/common-services/STORM/0.9.1.2.1/package/templates/config.yaml.j2
  15. 1 1
      ambari-server/src/main/resources/common-services/STORM/0.9.1.2.1/package/templates/storm-metrics2.properties.j2
  16. 17 7
      ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-START/scripts/params.py
  17. 16 7
      ambari-server/src/main/resources/stacks/HDPWIN/2.1/hooks/before-START/scripts/params.py
  18. 1 1
      ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/JMXPropertyProviderTest.java
  19. 1 1
      ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/RestMetricsPropertyProviderTest.java
  20. 1 1
      ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/ganglia/GangliaPropertyProviderTest.java
  21. 1 1
      ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/ganglia/GangliaReportPropertyProviderTest.java
  22. 1 1
      ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/timeline/AMSPropertyProviderTest.java
  23. 1 1
      ambari-server/src/test/python/stacks/2.0.6/FLUME/test_flume.py
  24. 11 9
      ambari-server/src/test/python/stacks/2.0.6/configs/default.json

+ 81 - 33
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java

@@ -87,7 +87,7 @@ public abstract class AbstractProviderModule implements ProviderModule,
   private static final String GANGLIA_SERVER                            = "GANGLIA_SERVER";
   private static final String METRIC_SERVER                             = "METRICS_COLLECTOR";
   private static final String PROPERTIES_CATEGORY = "properties";
-  private static final Map<Service.Type, String> serviceConfigVersions = new ConcurrentHashMap<Service.Type, String>();
+  private static final Map<String, String> serviceConfigVersions = new ConcurrentHashMap<String, String>();
   private static final Map<Service.Type, String> serviceConfigTypes = new EnumMap<Service.Type, String>(Service.Type.class);
   private static final Map<Service.Type, Map<String, String[]>> serviceDesiredProperties = new EnumMap<Service.Type, Map<String, String[]>>(Service.Type.class);
   private static final Map<String, Service.Type> componentServiceMap = new HashMap<String, Service.Type>();
@@ -99,7 +99,10 @@ public abstract class AbstractProviderModule implements ProviderModule,
   private static final Map<String, Map<String, String[]>> jmxDesiredProperties = new HashMap<String, Map<String, String[]>>();
   private volatile Map<String, String> clusterHdfsSiteConfigVersionMap = new HashMap<String, String>();
   private volatile Map<String, String> clusterJmxProtocolMap = new HashMap<String, String>();
+  private volatile Set<String> metricServerHosts = new HashSet<String>();
   private volatile String clusterMetricServerPort = null;
+  private volatile String clusterMetricServerVipPort = null;
+  private volatile String clusterMetricserverVipHost = null;
 
   static {
     serviceConfigTypes.put(Service.Type.HDFS, "hdfs-site");
@@ -267,57 +270,96 @@ public abstract class AbstractProviderModule implements ProviderModule,
   // ----- MetricsHostProvider ------------------------------------------------
 
   @Override
-  public String getCollectorHostName(String clusterName, MetricsService service) throws SystemException {
+  public String getCollectorHostName(String clusterName, MetricsService service)
+    throws SystemException {
+
     checkInit();
     if (service.equals(GANGLIA)) {
       return clusterGangliaCollectorMap.get(clusterName);
     } else if (service.equals(TIMELINE_METRICS)) {
-      return clusterMetricCollectorMap.get(clusterName);
+      return getMetricsCollectorHostName(clusterName);
     }
     return null;
   }
 
+  private String getMetricsCollectorHostName(String clusterName)
+    throws SystemException {
+    try {
+      // try to get vip properties from cluster-env
+      String configType = "cluster-env";
+      String currentConfigVersion = getDesiredConfigVersion(clusterName, configType);
+      String oldConfigVersion = serviceConfigVersions.get(configType);
+      if (!currentConfigVersion.equals(oldConfigVersion)) {
+        serviceConfigVersions.put(configType, currentConfigVersion);
+        Map<String, String> configProperties = getDesiredConfigMap
+          (clusterName, currentConfigVersion, configType,
+            Collections.singletonMap("METRICS_COLLECTOR",
+              new String[]{"metrics_collector_vip_host"}));
+
+        if (!configProperties.isEmpty()) {
+          clusterMetricserverVipHost = configProperties.get("METRICS_COLLECTOR");
+          if (clusterMetricserverVipHost != null) {
+            clusterMetricCollectorMap.put(clusterName, clusterMetricserverVipHost);
+          }
+        }
+        // updating the port value, because both vip properties are stored in
+        // cluster-env
+        configProperties = getDesiredConfigMap
+          (clusterName, currentConfigVersion, configType,
+            Collections.singletonMap("METRICS_COLLECTOR",
+              new String[]{"metrics_collector_vip_port"}));
+
+        if (!configProperties.isEmpty()) {
+          clusterMetricServerVipPort = configProperties.get("METRICS_COLLECTOR");
+        }
+      }
+    } catch (NoSuchParentResourceException | UnsupportedPropertyException e) {
+      LOG.warn("Failed to retrieve collector hostname.", e);
+    }
+    return clusterMetricCollectorMap.get(clusterName);
+  }
+
   @Override
-  public String getCollectorPortName(String clusterName, MetricsService service) throws SystemException {
+  public String getCollectorPort(String clusterName, MetricsService service) throws SystemException {
     checkInit();
     if (service.equals(GANGLIA)) {
       return "80"; // Not called by the provider
     } else if (service.equals(TIMELINE_METRICS)) {
       try {
-        String configType = serviceConfigTypes.get(Service.Type.AMBARI_METRICS);
-        String currentConfigVersion = getDesiredConfigVersion(clusterName, configType);
-        String oldConfigVersion = serviceConfigVersions.get(Service.Type.AMBARI_METRICS);
-
-        if (!currentConfigVersion.equals(oldConfigVersion)) {
-          serviceConfigVersions.put(Service.Type.AMBARI_METRICS, currentConfigVersion);
-
-          Map<String, String> configProperties = getDesiredConfigMap
-            (clusterName, currentConfigVersion, configType,
+        if (clusterMetricServerVipPort == null) {
+          String configType = serviceConfigTypes.get(Service.Type.AMBARI_METRICS);
+          String currentConfigVersion = getDesiredConfigVersion(clusterName, configType);
+          String oldConfigVersion = serviceConfigVersions.get(configType);
+          if (!currentConfigVersion.equals(oldConfigVersion)) {
+            serviceConfigVersions.put(configType, currentConfigVersion);
+
+            Map<String, String> configProperties = getDesiredConfigMap(clusterName,
+              currentConfigVersion, configType,
               Collections.singletonMap("METRICS_COLLECTOR",
-                new String[] { "timeline.metrics.service.webapp.address" }));
+                new String[]{"timeline.metrics.service.webapp.address"}));
 
-          if (!configProperties.isEmpty()) {
-            clusterMetricServerPort = getPortString(configProperties.get("METRICS_COLLECTOR"));
-          } else {
-            clusterMetricServerPort = COLLECTOR_DEFAULT_PORT;
+            if (!configProperties.isEmpty()) {
+              clusterMetricServerPort = getPortString(configProperties.get("METRICS_COLLECTOR"));
+            } else {
+              clusterMetricServerPort = COLLECTOR_DEFAULT_PORT;
+            }
           }
         }
-
-      } catch (NoSuchParentResourceException e) {
-        LOG.warn("Failed to retrieve collector port.", e);
-      } catch (UnsupportedPropertyException e) {
+      } catch (NoSuchParentResourceException | UnsupportedPropertyException e) {
         LOG.warn("Failed to retrieve collector port.", e);
       }
     }
-    return clusterMetricServerPort;
+    return clusterMetricServerVipPort != null ? clusterMetricServerVipPort : clusterMetricServerPort;
   }
 
   @Override
   public boolean isCollectorHostLive(String clusterName, MetricsService service) throws SystemException {
-
-    final String collectorHostName = getCollectorHostName(clusterName, service);
-
-    return isHostLive(clusterName, collectorHostName);
+    for (String hostname: metricServerHosts) {
+      if (isHostLive(clusterName, hostname)) {
+        return true;
+      }
+    }
+    return false;
   }
 
   @Override
@@ -348,8 +390,12 @@ public abstract class AbstractProviderModule implements ProviderModule,
       return isHostComponentLive(clusterName, collectorHostName, "GANGLIA",
         Role.GANGLIA_SERVER.name());
     } else if (service.equals(TIMELINE_METRICS)) {
-      return isHostComponentLive(clusterName, collectorHostName, "AMBARI_METRICS",
-        Role.METRICS_COLLECTOR.name());
+      for (String hostname: metricServerHosts) {
+        if (isHostComponentLive(clusterName, hostname, "AMBARI_METRICS",
+          Role.METRICS_COLLECTOR.name())) {
+          return true;
+        }
+      }
     }
     return false;
   }
@@ -426,8 +472,9 @@ public abstract class AbstractProviderModule implements ProviderModule,
 
     if (service != null) {
       try {
-        String currVersion = getDesiredConfigVersion(clusterName, serviceConfigTypes.get(service));
-        String oldVersion = serviceConfigVersions.get(service);
+        String configType = serviceConfigTypes.get(service);
+        String currVersion = getDesiredConfigVersion(clusterName, configType);
+        String oldVersion = serviceConfigVersions.get(configType);
 
         // We only update port map when a config version updates,
         // Since concurrent thread access is expected we err on the side of
@@ -436,7 +483,7 @@ public abstract class AbstractProviderModule implements ProviderModule,
         if (!currVersion.equals(oldVersion) ||
             !clusterJmxPorts.containsKey(componentName)) {
 
-          serviceConfigVersions.put(service, currVersion);
+          serviceConfigVersions.put(configType, currVersion);
 
           Map<String, String[]> componentPorts = new HashMap<String, String[]>();
           String[] componentsHttpsPorts;
@@ -721,6 +768,7 @@ public abstract class AbstractProviderModule implements ProviderModule,
           }
           if (componentName.equals(METRIC_SERVER)) {
             clusterMetricCollectorMap.put(clusterName, hostName);
+            metricServerHosts.add(hostName);
           }
         }
       }
@@ -791,7 +839,7 @@ public abstract class AbstractProviderModule implements ProviderModule,
     }
     return versionTag;
   }
-
+  // TODO get configs using ConfigHelper
   private Map<String, String> getDesiredConfigMap(String clusterName, String versionTag,
       String configType, Map<String, String[]> keys) throws NoSuchParentResourceException,
       UnsupportedPropertyException, SystemException {

+ 2 - 2
ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/MetricHostProvider.java

@@ -51,9 +51,9 @@ public interface MetricHostProvider {
    *
    * @return the metrics server
    *
-   * @throws org.apache.ambari.server.controller.spi.SystemException if unable to get the metrics server host name
+   * @throws org.apache.ambari.server.controller.spi.SystemException if unable to get the metrics server port
    */
-  public String getCollectorPortName(String clusterName, MetricsService service) throws SystemException;
+  public String getCollectorPort(String clusterName, MetricsService service) throws SystemException;
 
   /**
    * Get the status of metrics server host for the given cluster name.

+ 1 - 2
ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/AMSPropertyProvider.java

@@ -50,7 +50,6 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.TreeMap;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -564,7 +563,7 @@ public abstract class AMSPropertyProvider extends MetricsPropertyProvider {
       }
 
       if (collectorPort == null) {
-        collectorPort = hostProvider.getCollectorPortName(clusterName, TIMELINE_METRICS);
+        collectorPort = hostProvider.getCollectorPort(clusterName, TIMELINE_METRICS);
       }
 
       for (String id : ids) {

+ 1 - 1
ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/AMSReportPropertyProvider.java

@@ -172,7 +172,7 @@ public class AMSReportPropertyProvider extends MetricsReportPropertyProvider {
 
     Map<String, MetricReportRequest> reportRequestMap = getPropertyIdMaps(request, ids);
     String host = hostProvider.getCollectorHostName(clusterName, TIMELINE_METRICS);
-    String port = hostProvider.getCollectorPortName(clusterName, TIMELINE_METRICS);
+    String port = hostProvider.getCollectorPort(clusterName, TIMELINE_METRICS);
     URIBuilder uriBuilder = AMSPropertyProvider.getAMSUriBuilder(host,
       port != null ? Integer.parseInt(port) : 8188);
 

+ 14 - 5
ambari-server/src/main/resources/common-services/ACCUMULO/1.6.1.2.2.0/package/scripts/params.py

@@ -117,12 +117,21 @@ ganglia_server_host = '' if len(ganglia_server_hosts) == 0 else ganglia_server_h
 ams_collector_hosts = default("/clusterHostInfo/metrics_collector_hosts", [])
 has_metric_collector = not len(ams_collector_hosts) == 0
 if has_metric_collector:
-  metric_collector_host = ams_collector_hosts[0]
-  metric_collector_port = default("/configurations/ams-site/timeline.metrics.service.webapp.address", "0.0.0.0:6188")
-  if metric_collector_port and metric_collector_port.find(':') != -1:
-    metric_collector_port = metric_collector_port.split(':')[1]
+  if 'cluster-env' in config['configurations'] and \
+      'metrics_collector_vip_host' in config['configurations']['cluster-env']:
+    metric_collector_host = config['configurations']['cluster-env']['metrics_collector_vip_host']
+  else:
+    metric_collector_host = ams_collector_hosts[0]
+  if 'cluster-env' in config['configurations'] and \
+      'metrics_collector_vip_port' in config['configurations']['cluster-env']:
+    metric_collector_port = config['configurations']['cluster-env']['metrics_collector_vip_port']
+  else:
+    metric_collector_web_address = default("/configurations/ams-site/timeline.metrics.service.webapp.address", "0.0.0.0:6188")
+    if metric_collector_web_address.find(':') != -1:
+      metric_collector_port = metric_collector_web_address.split(':')[1]
+    else:
+      metric_collector_port = '6188'
   pass
-
 metrics_report_interval = default("/configurations/ams-site/timeline.metrics.sink.report.interval", 60)
 metrics_collection_period = default("/configurations/ams-site/timeline.metrics.sink.collection.period", 60)
 

+ 14 - 5
ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/params.py

@@ -38,11 +38,20 @@ ams_pid_dir = status_params.ams_collector_pid_dir
 ams_collector_script = "/usr/sbin/ambari-metrics-collector"
 ams_collector_pid_dir = status_params.ams_collector_pid_dir
 ams_collector_hosts = default("/clusterHostInfo/metrics_collector_hosts", [])
-ams_collector_host_single = ams_collector_hosts[0] #TODO cardinality is 1+ so we can have more than one host
-metric_collector_port = default("/configurations/ams-site/timeline.metrics.service.webapp.address", "0.0.0.0:6188")
-if metric_collector_port and metric_collector_port.find(':') != -1:
-  metric_collector_port = metric_collector_port.split(':')[1]
-pass
+if 'cluster-env' in config['configurations'] and \
+    'metrics_collector_vip_host' in config['configurations']['cluster-env']:
+  metric_collector_host = config['configurations']['cluster-env']['metrics_collector_vip_host']
+else:
+  metric_collector_host = ams_collector_hosts[0]
+if 'cluster-env' in config['configurations'] and \
+    'metrics_collector_vip_port' in config['configurations']['cluster-env']:
+  metric_collector_port = config['configurations']['cluster-env']['metrics_collector_vip_port']
+else:
+  metric_collector_web_address = default("/configurations/ams-site/timeline.metrics.service.webapp.address", "0.0.0.0:6188")
+  if metric_collector_web_address.find(':') != -1:
+    metric_collector_port = metric_collector_web_address.split(':')[1]
+  else:
+    metric_collector_port = '6188'
 
 ams_collector_log_dir = config['configurations']['ams-env']['metrics_collector_log_dir']
 ams_monitor_log_dir = config['configurations']['ams-env']['metrics_monitor_log_dir']

+ 4 - 4
ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/service_check.py

@@ -76,10 +76,10 @@ class AMSServiceCheck(Script):
 
     for i in xrange(0, self.AMS_CONNECT_TRIES):
       try:
-        Logger.info("Connecting (POST) to %s:%s%s" % (params.ams_collector_host_single,
+        Logger.info("Connecting (POST) to %s:%s%s" % (params.metric_collector_host,
                                                       params.metric_collector_port,
                                                       self.AMS_METRICS_POST_URL))
-        conn = httplib.HTTPConnection(params.ams_collector_host_single,
+        conn = httplib.HTTPConnection(params.metric_collector_host,
                                         int(params.metric_collector_port))
         conn.request("POST", self.AMS_METRICS_POST_URL, metric_json, headers)
       except (httplib.HTTPException, socket.error) as ex:
@@ -123,11 +123,11 @@ class AMSServiceCheck(Script):
     }
     encoded_get_metrics_parameters = urllib.urlencode(get_metrics_parameters)
 
-    Logger.info("Connecting (GET) to %s:%s%s" % (params.ams_collector_host_single,
+    Logger.info("Connecting (GET) to %s:%s%s" % (params.metric_collector_host,
                                                  params.metric_collector_port,
                                               self.AMS_METRICS_GET_URL % encoded_get_metrics_parameters))
 
-    conn = httplib.HTTPConnection(params.ams_collector_host_single,
+    conn = httplib.HTTPConnection(params.metric_collector_host,
                                   int(params.metric_collector_port))
     conn.request("GET", self.AMS_METRICS_GET_URL % encoded_get_metrics_parameters)
     response = conn.getresponse()

+ 4 - 4
ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/templates/hadoop-metrics2-hbase.properties.j2

@@ -40,22 +40,22 @@ hbase.extendedperiod = 3600
 
 hbase.class=org.apache.hadoop.metrics2.sink.timeline.HadoopTimelineMetricsSink
 hbase.period=30
-hbase.collector={{ams_collector_host_single}}:{{metric_collector_port}}
+hbase.collector={{metric_collector_host}}:{{metric_collector_port}}
 
 jvm.class=org.apache.hadoop.metrics2.sink.timeline.HadoopTimelineMetricsSink
 jvm.period=30
-jvm.collector={{ams_collector_host_single}}:{{metric_collector_port}}
+jvm.collector={{metric_collector_host}}:{{metric_collector_port}}
 
 rpc.class=org.apache.hadoop.metrics2.sink.timeline.HadoopTimelineMetricsSink
 rpc.period=30
-rpc.collector={{ams_collector_host_single}}:{{metric_collector_port}}
+rpc.collector={{metric_collector_host}}:{{metric_collector_port}}
 
 *.timeline.plugin.urls=file:///usr/lib/ambari-metrics-hadoop-sink/ambari-metrics-hadoop-sink.jar
 *.sink.timeline.slave.host.name={{hostname}}
 hbase.sink.timeline.class=org.apache.hadoop.metrics2.sink.timeline.HadoopTimelineMetricsSink
 hbase.sink.timeline.period={{metrics_collection_period}}
 hbase.sink.timeline.sendInterval={{metrics_report_interval}}000
-hbase.sink.timeline.collector={{ams_collector_host_single}}:{{metric_collector_port}}
+hbase.sink.timeline.collector={{metric_collector_host}}:{{metric_collector_port}}
 hbase.sink.timeline.serviceName-prefix=ams
 
 # Switch off metrics generation on a per region basis

+ 1 - 1
ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/templates/metric_monitor.ini.j2

@@ -18,7 +18,7 @@
 
 [default]
 debug_level = INFO
-metrics_server = {{ams_collector_host_single}}:{{metric_collector_port}}
+metrics_server = {{metric_collector_host}}:{{metric_collector_port}}
 enable_time_threshold = false
 enable_value_threshold = false
 

+ 14 - 4
ambari-server/src/main/resources/common-services/FLUME/1.4.0.2.0/package/scripts/params.py

@@ -87,10 +87,20 @@ if config.has_key('hostname'):
 ams_collector_hosts = default("/clusterHostInfo/metrics_collector_hosts", [])
 has_metric_collector = not len(ams_collector_hosts) == 0
 if has_metric_collector:
-  metric_collector_host = ams_collector_hosts[0]
-  metric_collector_port = default("/configurations/ams-site/timeline.metrics.service.webapp.address", "0.0.0.0:6188")
-  if metric_collector_port and metric_collector_port.find(':') != -1:
-    metric_collector_port = metric_collector_port.split(':')[1]
+  if 'cluster-env' in config['configurations'] and \
+      'metrics_collector_vip_host' in config['configurations']['cluster-env']:
+    metric_collector_host = config['configurations']['cluster-env']['metrics_collector_vip_host']
+  else:
+    metric_collector_host = ams_collector_hosts[0]
+  if 'cluster-env' in config['configurations'] and \
+      'metrics_collector_vip_port' in config['configurations']['cluster-env']:
+    metric_collector_port = config['configurations']['cluster-env']['metrics_collector_vip_port']
+  else:
+    metric_collector_web_address = default("/configurations/ams-site/timeline.metrics.service.webapp.address", "0.0.0.0:6188")
+    if metric_collector_web_address.find(':') != -1:
+      metric_collector_port = metric_collector_web_address.split(':')[1]
+    else:
+      metric_collector_port = '6188'
   pass
 metrics_report_interval = default("/configurations/ams-site/timeline.metrics.sink.report.interval", 60)
 metrics_collection_period = default("/configurations/ams-site/timeline.metrics.sink.collection.period", 60)

+ 14 - 4
ambari-server/src/main/resources/common-services/HBASE/0.96.0.2.0/package/scripts/params_linux.py

@@ -141,10 +141,20 @@ ganglia_server_host = '' if len(ganglia_server_hosts) == 0 else ganglia_server_h
 ams_collector_hosts = default("/clusterHostInfo/metrics_collector_hosts", [])
 has_metric_collector = not len(ams_collector_hosts) == 0
 if has_metric_collector:
-  metric_collector_host = ams_collector_hosts[0]
-  metric_collector_port = default("/configurations/ams-site/timeline.metrics.service.webapp.address", "0.0.0.0:6188")
-  if metric_collector_port and metric_collector_port.find(':') != -1:
-    metric_collector_port = metric_collector_port.split(':')[1]
+  if 'cluster-env' in config['configurations'] and \
+      'metrics_collector_vip_host' in config['configurations']['cluster-env']:
+    metric_collector_host = config['configurations']['cluster-env']['metrics_collector_vip_host']
+  else:
+    metric_collector_host = ams_collector_hosts[0]
+  if 'cluster-env' in config['configurations'] and \
+      'metrics_collector_vip_port' in config['configurations']['cluster-env']:
+    metric_collector_port = config['configurations']['cluster-env']['metrics_collector_vip_port']
+  else:
+    metric_collector_web_address = default("/configurations/ams-site/timeline.metrics.service.webapp.address", "0.0.0.0:6188")
+    if metric_collector_web_address.find(':') != -1:
+      metric_collector_port = metric_collector_web_address.split(':')[1]
+    else:
+      metric_collector_port = '6188'
   pass
 metrics_report_interval = default("/configurations/ams-site/timeline.metrics.sink.report.interval", 60)
 metrics_collection_period = default("/configurations/ams-site/timeline.metrics.sink.collection.period", 60)

+ 15 - 5
ambari-server/src/main/resources/common-services/KAFKA/0.8.1.2.2/package/scripts/params.py

@@ -93,11 +93,21 @@ ams_collector_hosts = default("/clusterHostInfo/metrics_collector_hosts", [])
 has_metric_collector = not len(ams_collector_hosts) == 0
 
 if has_metric_collector:
-  metric_collector_host = ams_collector_hosts[0]
-  metric_collector_port = default("/configurations/ams-site/timeline.metrics.service.webapp.address", "0.0.0.0:6188")
-  if metric_collector_port and metric_collector_port.find(':') != -1:
-    metric_collector_port = metric_collector_port.split(':')[1]
-
+  if 'cluster-env' in config['configurations'] and \
+      'metrics_collector_vip_host' in config['configurations']['cluster-env']:
+    metric_collector_host = config['configurations']['cluster-env']['metrics_collector_vip_host']
+  else:
+    metric_collector_host = ams_collector_hosts[0]
+  if 'cluster-env' in config['configurations'] and \
+      'metrics_collector_vip_port' in config['configurations']['cluster-env']:
+    metric_collector_port = config['configurations']['cluster-env']['metrics_collector_vip_port']
+  else:
+    metric_collector_web_address = default("/configurations/ams-site/timeline.metrics.service.webapp.address", "0.0.0.0:6188")
+    if metric_collector_web_address.find(':') != -1:
+      metric_collector_port = metric_collector_web_address.split(':')[1]
+    else:
+      metric_collector_port = '6188'
+  pass
 # Security-related params
 security_enabled = config['configurations']['cluster-env']['security_enabled']
 kafka_kerberos_enabled = ('security.inter.broker.protocol' in config['configurations']['kafka-broker'] and

+ 15 - 1
ambari-server/src/main/resources/common-services/STORM/0.9.1.2.1/package/scripts/params_linux.py

@@ -145,7 +145,21 @@ if stack_is_hdp22_or_further:
 ams_collector_hosts = default("/clusterHostInfo/metrics_collector_hosts", [])
 has_metric_collector = not len(ams_collector_hosts) == 0
 if has_metric_collector:
-  metric_collector_host = ams_collector_hosts[0]
+  if 'cluster-env' in config['configurations'] and \
+      'metrics_collector_vip_host' in config['configurations']['cluster-env']:
+    metric_collector_host = config['configurations']['cluster-env']['metrics_collector_vip_host']
+  else:
+    metric_collector_host = ams_collector_hosts[0]
+  if 'cluster-env' in config['configurations'] and \
+      'metrics_collector_vip_port' in config['configurations']['cluster-env']:
+    metric_collector_port = config['configurations']['cluster-env']['metrics_collector_vip_port']
+  else:
+    metric_collector_web_address = default("/configurations/ams-site/timeline.metrics.service.webapp.address", "0.0.0.0:6188")
+    if metric_collector_web_address.find(':') != -1:
+      metric_collector_port = metric_collector_web_address.split(':')[1]
+    else:
+      metric_collector_port = '6188'
+
   metric_collector_report_interval = 60
   metric_collector_app_id = "nimbus"
 

+ 1 - 1
ambari-server/src/main/resources/common-services/STORM/0.9.1.2.1/package/templates/config.yaml.j2

@@ -58,7 +58,7 @@ metrics_collector:
 
   reportInterval: {{metric_collector_report_interval}}
   host: "{{metric_collector_host}}"
-  port: 6188
+  port: {{metric_collector_port}}
   appId: "{{metric_collector_app_id}}"
 
 {% endif %}

+ 1 - 1
ambari-server/src/main/resources/common-services/STORM/0.9.1.2.1/package/templates/storm-metrics2.properties.j2

@@ -17,6 +17,6 @@
 #}
 
 collector={{metric_collector_host}}
-port=6188
+port={{metric_collector_port}}
 maxRowCacheSize=10000
 sendInterval={{metrics_report_interval}}000

+ 17 - 7
ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/before-START/scripts/params.py

@@ -82,9 +82,9 @@ ams_collector_hosts = default("/clusterHostInfo/metrics_collector_hosts", [])
 has_namenode = not len(namenode_host) == 0
 has_resourcemanager = not len(rm_host) == 0
 has_slaves = not len(slave_hosts) == 0
-has_oozie_server = not len(oozie_servers)  == 0
-has_hcat_server_host = not len(hcat_server_hosts)  == 0
-has_hive_server_host = not len(hive_server_host)  == 0
+has_oozie_server = not len(oozie_servers) == 0
+has_hcat_server_host = not len(hcat_server_hosts) == 0
+has_hive_server_host = not len(hive_server_host) == 0
 has_hbase_masters = not len(hbase_master_hosts) == 0
 has_zk_host = not len(zk_hosts) == 0
 has_ganglia_server = not len(ganglia_server_hosts) == 0
@@ -99,10 +99,20 @@ is_slave = hostname in slave_hosts
 if has_ganglia_server:
   ganglia_server_host = ganglia_server_hosts[0]
 if has_metric_collector:
-  metric_collector_host = ams_collector_hosts[0]
-  metric_collector_port = default("/configurations/ams-site/timeline.metrics.service.webapp.address", "0.0.0.0:6188")
-  if metric_collector_port and metric_collector_port.find(':') != -1:
-    metric_collector_port = metric_collector_port.split(':')[1]
+  if 'cluster-env' in config['configurations'] and \
+      'metrics_collector_vip_host' in config['configurations']['cluster-env']:
+    metric_collector_host = config['configurations']['cluster-env']['metrics_collector_vip_host']
+  else:
+    metric_collector_host = ams_collector_hosts[0]
+  if 'cluster-env' in config['configurations'] and \
+      'metrics_collector_vip_port' in config['configurations']['cluster-env']:
+    metric_collector_port = config['configurations']['cluster-env']['metrics_collector_vip_port']
+  else:
+    metric_collector_web_address = default("/configurations/ams-site/timeline.metrics.service.webapp.address", "0.0.0.0:6188")
+    if metric_collector_web_address.find(':') != -1:
+      metric_collector_port = metric_collector_web_address.split(':')[1]
+    else:
+      metric_collector_port = '6188'
   pass
 metrics_report_interval = default("/configurations/ams-site/timeline.metrics.sink.report.interval", 60)
 metrics_collection_period = default("/configurations/ams-site/timeline.metrics.sink.collection.period", 60)

+ 16 - 7
ambari-server/src/main/resources/stacks/HDPWIN/2.1/hooks/before-START/scripts/params.py

@@ -23,15 +23,24 @@ config = Script.get_config()
 ams_collector_hosts = default("/clusterHostInfo/metrics_collector_hosts", [])
 has_metric_collector = not len(ams_collector_hosts) == 0
 if has_metric_collector:
-  metric_collector_host = ams_collector_hosts[0]
-  metric_collector_port = default("/configurations/ams-site/timeline.metrics.service.webapp.address", "0.0.0.0:6188")
-  if metric_collector_port and metric_collector_port.find(':') != -1:
-    metric_collector_port = metric_collector_port.split(':')[1]
-  pass
+  if 'cluster-env' in config['configurations'] and \
+      'metrics_collector_vip_host' in config['configurations']['cluster-env']:
+    metric_collector_host = config['configurations']['cluster-env']['metrics_collector_vip_host']
+  else:
+    metric_collector_host = ams_collector_hosts[0]
+  if 'cluster-env' in config['configurations'] and \
+      'metrics_collector_vip_port' in config['configurations']['cluster-env']:
+    metric_collector_port = config['configurations']['cluster-env']['metrics_collector_vip_port']
+  else:
+    metric_collector_web_address = default("/configurations/ams-site/timeline.metrics.service.webapp.address", "0.0.0.0:6188")
+    if metric_collector_web_address.find(':') != -1:
+      metric_collector_port = metric_collector_web_address.split(':')[1]
+    else:
+      metric_collector_port = '6188'
+
   sink_home = os.environ["SINK_HOME"]
   timeline_plugin_url = "file:"+nturl2path.pathname2url(os.path.join(sink_home, "hadoop-sink", "ambari-metrics-hadoop-sink.jar"))
-
-
+  pass
 
 hadoop_conf_dir = os.environ["HADOOP_CONF_DIR"]
 hbase_conf_dir = os.environ["HBASE_CONF_DIR"]

+ 1 - 1
ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/JMXPropertyProviderTest.java

@@ -438,7 +438,7 @@ public class JMXPropertyProviderTest {
     }
 
     @Override
-    public String getCollectorPortName(String clusterName, MetricsService service) throws SystemException {
+    public String getCollectorPort(String clusterName, MetricsService service) throws SystemException {
       return null;
     }
 

+ 1 - 1
ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/RestMetricsPropertyProviderTest.java

@@ -399,7 +399,7 @@ public class RestMetricsPropertyProviderTest {
     }
 
     @Override
-    public String getCollectorPortName(String clusterName, MetricsService service) throws SystemException {
+    public String getCollectorPort(String clusterName, MetricsService service) throws SystemException {
       return null;
     }
 

+ 1 - 1
ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/ganglia/GangliaPropertyProviderTest.java

@@ -871,7 +871,7 @@ public class GangliaPropertyProviderTest {
     }
 
     @Override
-    public String getCollectorPortName(String clusterName, MetricsService service) throws SystemException {
+    public String getCollectorPort(String clusterName, MetricsService service) throws SystemException {
       return null;
     }
 

+ 1 - 1
ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/ganglia/GangliaReportPropertyProviderTest.java

@@ -115,7 +115,7 @@ public class GangliaReportPropertyProviderTest {
     }
 
     @Override
-    public String getCollectorPortName(String clusterName, MetricsService service) throws SystemException {
+    public String getCollectorPort(String clusterName, MetricsService service) throws SystemException {
       return null;
     }
 

+ 1 - 1
ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/timeline/AMSPropertyProviderTest.java

@@ -695,7 +695,7 @@ public class AMSPropertyProviderTest {
     }
 
     @Override
-    public String getCollectorPortName(String clusterName, MetricsService service) throws SystemException {
+    public String getCollectorPort(String clusterName, MetricsService service) throws SystemException {
       return "8188";
     }
 

+ 1 - 1
ambari-server/src/test/python/stacks/2.0.6/FLUME/test_flume.py

@@ -61,7 +61,7 @@ class TestFlumeHandler(RMFTestCase):
     self.assertTrue(set_desired_mock.call_args[0][0] == 'STARTED')
 
 
-    self.assertResourceCalled('Execute', "ambari-sudo.sh su flume -l -s /bin/bash -c 'export  PATH=/bin JAVA_HOME=/usr/jdk64/jdk1.7.0_45 ; /usr/bin/flume-ng agent --name a1 --conf /etc/flume/conf/a1 --conf-file /etc/flume/conf/a1/flume.conf -Dflume.monitoring.type=org.apache.hadoop.metrics2.sink.flume.FlumeTimelineMetricsSink -Dflume.monitoring.node=c6401.ambari.apache.org:6188 > /var/log/flume/a1.out 2>&1' &",
+    self.assertResourceCalled('Execute', "ambari-sudo.sh su flume -l -s /bin/bash -c 'export  PATH=/bin JAVA_HOME=/usr/jdk64/jdk1.7.0_45 ; /usr/bin/flume-ng agent --name a1 --conf /etc/flume/conf/a1 --conf-file /etc/flume/conf/a1/flume.conf -Dflume.monitoring.type=org.apache.hadoop.metrics2.sink.flume.FlumeTimelineMetricsSink -Dflume.monitoring.node=c6402.ambari.apache.org:6189 > /var/log/flume/a1.out 2>&1' &",
         environment = {'JAVA_HOME': u'/usr/jdk64/jdk1.7.0_45'},
         wait_for_finish = False,
     )

+ 11 - 9
ambari-server/src/test/python/stacks/2.0.6/configs/default.json

@@ -529,15 +529,17 @@
             "xml_configurations_supported" : "false"
         },
       "cluster-env": {
-            "security_enabled": "false",
-            "hdfs_user_principal" : "",
-            "hdfs_user_keytab" : "",
-            "ignore_groupsusers_create": "false",
-            "smokeuser": "ambari-qa",
-            "kerberos_domain": "EXAMPLE.COM",
-            "user_group": "hadoop",
-            "repo_suse_rhel_template": "[{{repo_id}}]\nname={{repo_id}}\n{% if mirror_list %}mirrorlist={{mirror_list}}{% else %}baseurl={{base_url}}{% endif %}\n\npath=/\nenabled=1\ngpgcheck=0",
-            "repo_ubuntu_template": "{{package_type}} {{base_url}} {{components}}",
+          "security_enabled": "false",
+          "hdfs_user_principal" : "",
+          "hdfs_user_keytab" : "",
+          "ignore_groupsusers_create": "false",
+          "smokeuser": "ambari-qa",
+          "kerberos_domain": "EXAMPLE.COM",
+          "user_group": "hadoop",
+          "repo_suse_rhel_template": "[{{repo_id}}]\nname={{repo_id}}\n{% if mirror_list %}mirrorlist={{mirror_list}}{% else %}baseurl={{base_url}}{% endif %}\n\npath=/\nenabled=1\ngpgcheck=0",
+          "repo_ubuntu_template": "{{package_type}} {{base_url}} {{components}}",
+          "metrics_collector_vip_host": "c6402.ambari.apache.org",
+          "metrics_collector_vip_port": "6189",
           "override_uid" : "true"
       },
       "hbase-env": {