http://git-wip-us.apache.org/repos/asf/ambari/blob/a52f8a55/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaComponentPropertyProvider.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaComponentPropertyProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaComponentPropertyProvider.java deleted file mode 100644 index 1e01aa0..0000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaComponentPropertyProvider.java +++ /dev/null @@ -1,71 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ambari.server.controller.ganglia; - -import java.util.Collections; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.apache.ambari.server.configuration.ComponentSSLConfiguration; -import org.apache.ambari.server.controller.internal.PropertyInfo; -import org.apache.ambari.server.controller.spi.Resource; -import org.apache.ambari.server.controller.utilities.StreamProvider; - -/** - * Ganglia property provider implementation for component resources. - */ -public class GangliaComponentPropertyProvider extends GangliaPropertyProvider { - - - // ----- Constructors ------------------------------------------------------ - - public GangliaComponentPropertyProvider(Map<String, Map<String, PropertyInfo>> componentMetrics, - StreamProvider streamProvider, - ComponentSSLConfiguration configuration, - GangliaHostProvider hostProvider, - String clusterNamePropertyId, - String componentNamePropertyId) { - - super(componentMetrics, streamProvider, configuration, hostProvider, - clusterNamePropertyId, null, componentNamePropertyId); - } - - - // ----- GangliaPropertyProvider ------------------------------------------- - - @Override - protected String getHostName(Resource resource) { - return "__SummaryInfo__"; - } - - @Override - protected String getComponentName(Resource resource) { - return (String) resource.getPropertyValue(getComponentNamePropertyId()); - } - - @Override - protected Set<String> getGangliaClusterNames(Resource resource, String clusterName) { - String component = getComponentName(resource); - - return new HashSet<String>(GANGLIA_CLUSTER_NAME_MAP.containsKey(component) ? - GANGLIA_CLUSTER_NAME_MAP.get(component) : - Collections.<String>emptyList()); - } -}
http://git-wip-us.apache.org/repos/asf/ambari/blob/a52f8a55/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaHostComponentPropertyProvider.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaHostComponentPropertyProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaHostComponentPropertyProvider.java deleted file mode 100644 index 9411cab..0000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaHostComponentPropertyProvider.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ambari.server.controller.ganglia; - -import java.util.Collections; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.apache.ambari.server.configuration.ComponentSSLConfiguration; -import org.apache.ambari.server.controller.internal.PropertyInfo; -import org.apache.ambari.server.controller.spi.Resource; -import org.apache.ambari.server.controller.utilities.StreamProvider; - -/** - * Ganglia property provider implementation for host component resources. - */ -public class GangliaHostComponentPropertyProvider extends GangliaPropertyProvider { - - - // ----- Constructors ------------------------------------------------------ - - public GangliaHostComponentPropertyProvider(Map<String, Map<String, PropertyInfo>> componentPropertyInfoMap, - StreamProvider streamProvider, - ComponentSSLConfiguration configuration, - GangliaHostProvider hostProvider, - String clusterNamePropertyId, - String hostNamePropertyId, - String componentNamePropertyId) { - - super(componentPropertyInfoMap, streamProvider, configuration, hostProvider, - clusterNamePropertyId, hostNamePropertyId, componentNamePropertyId); - } - - - // ----- GangliaPropertyProvider ------------------------------------------- - - @Override - protected String getHostName(Resource resource) { - return (String) resource.getPropertyValue(getHostNamePropertyId()); - } - - @Override - protected String getComponentName(Resource resource) { - return (String) resource.getPropertyValue(getComponentNamePropertyId()); - } - - @Override - protected Set<String> getGangliaClusterNames(Resource resource, String clusterName) { - String component = getComponentName(resource); - - return new HashSet<String>(GANGLIA_CLUSTER_NAME_MAP.containsKey(component) ? - GANGLIA_CLUSTER_NAME_MAP.get(component) : - Collections.<String>emptyList()); - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/a52f8a55/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaHostPropertyProvider.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaHostPropertyProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaHostPropertyProvider.java deleted file mode 100644 index e1769a9..0000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaHostPropertyProvider.java +++ /dev/null @@ -1,85 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ambari.server.controller.ganglia; - -import org.apache.ambari.server.configuration.ComponentSSLConfiguration; -import org.apache.ambari.server.controller.internal.PropertyInfo; -import org.apache.ambari.server.controller.spi.Resource; -import org.apache.ambari.server.controller.utilities.StreamProvider; - -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -/** - * Ganglia property provider implementation for host resources. - */ -public class GangliaHostPropertyProvider extends GangliaPropertyProvider{ - - /** - * Set of Ganglia cluster names. - */ - private static final Set<String> GANGLIA_CLUSTER_NAMES = new HashSet<String>(); - - static { - GANGLIA_CLUSTER_NAMES.add("HDPNameNode"); - GANGLIA_CLUSTER_NAMES.add("HDPSlaves"); - GANGLIA_CLUSTER_NAMES.add("HDPJobTracker"); - GANGLIA_CLUSTER_NAMES.add("HDPResourceManager"); - GANGLIA_CLUSTER_NAMES.add("HDPHBaseMaster"); - GANGLIA_CLUSTER_NAMES.add("HDPHistoryServer"); - GANGLIA_CLUSTER_NAMES.add("HDPNameNode"); - GANGLIA_CLUSTER_NAMES.add("HDPTaskTracker"); - GANGLIA_CLUSTER_NAMES.add("HDPHBaseRegionServer"); - GANGLIA_CLUSTER_NAMES.add("HDPFlumeServer"); - GANGLIA_CLUSTER_NAMES.add("HDPJournalNode"); - GANGLIA_CLUSTER_NAMES.add("HDPKafka"); - } - - // ----- Constructors ------------------------------------------------------ - - public GangliaHostPropertyProvider(Map<String, Map<String, PropertyInfo>> componentPropertyInfoMap, - StreamProvider streamProvider, - ComponentSSLConfiguration configuration, - GangliaHostProvider hostProvider, - String clusterNamePropertyId, - String hostNamePropertyId) { - - super(componentPropertyInfoMap, streamProvider, configuration, hostProvider, - clusterNamePropertyId, hostNamePropertyId, null); - } - - - // ----- GangliaPropertyProvider ------------------------------------------- - - @Override - protected String getHostName(Resource resource) { - return (String) resource.getPropertyValue(getHostNamePropertyId()); - } - - @Override - protected String getComponentName(Resource resource) { - return "*"; - } - - @Override - protected Set<String> getGangliaClusterNames(Resource resource, String clusterName) { - return GANGLIA_CLUSTER_NAMES; - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/a52f8a55/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaHostProvider.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaHostProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaHostProvider.java deleted file mode 100644 index 51721a4..0000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaHostProvider.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ambari.server.controller.ganglia; - -import org.apache.ambari.server.controller.spi.SystemException; - -/** - * Provider of Ganglia host information. - */ -public interface GangliaHostProvider { - - /** - * Get the Ganglia server host name for the given cluster name. - * - * @param clusterName the cluster name - * - * @return the Ganglia server - * - * @throws SystemException if unable to get the Ganglia server host name - */ - public String getGangliaCollectorHostName(String clusterName) throws SystemException; - - /** - * Get the status of Ganglia server host for the given cluster name. - * - * @param clusterName the cluster name - * - * @return true if heartbeat with Ganglia server host wasn't lost - * - * @throws SystemException if unable to get the status of Ganglia server host - */ - public boolean isGangliaCollectorHostLive(String clusterName) throws SystemException; - - /** - * Get the status of Ganglia server component for the given cluster name. - * - * @param clusterName the cluster name - * - * @return true if Ganglia server component is started - * - * @throws SystemException if unable to get the status of Ganglia server component - */ - public boolean isGangliaCollectorComponentLive(String clusterName) throws SystemException; -} http://git-wip-us.apache.org/repos/asf/ambari/blob/a52f8a55/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaMetric.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaMetric.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaMetric.java deleted file mode 100644 index c5ff540..0000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaMetric.java +++ /dev/null @@ -1,257 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ambari.server.controller.ganglia; - -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -@JsonIgnoreProperties(ignoreUnknown = true) - - -/** - * Data structure for temporal data returned from Ganglia Web. - */ -public class GangliaMetric { - - // Note that the member names correspond to the names in the JSON returned from Ganglia Web. - - /** - * The name. - */ - private String ds_name; - - /** - * The ganglia cluster name. - */ - private String cluster_name; - - /** - * The graph type. - */ - private String graph_type; - - /** - * The host name. - */ - private String host_name; - - /** - * The metric name. - */ - private String metric_name; - - /** - * The temporal data points. - */ - private Number[][] datapoints; - - - private static final Set<String> PERCENTAGE_METRIC; - - //BUG-3386 Cluster CPU Chart is off the charts - // Here can be added other percentage metrics - static { - Set<String> temp = new HashSet<String>(); - temp.add("cpu_wio"); - temp.add("cpu_idle"); - temp.add("cpu_nice"); - temp.add("cpu_aidle"); - temp.add("cpu_system"); - temp.add("cpu_user"); - PERCENTAGE_METRIC = Collections.unmodifiableSet(temp); - } - - - // ----- GangliaMetric ----------------------------------------------------- - - public String getDs_name() { - return ds_name; - } - - public void setDs_name(String ds_name) { - this.ds_name = ds_name; - } - - public String getCluster_name() { - return cluster_name; - } - - public void setCluster_name(String cluster_name) { - this.cluster_name = cluster_name; - } - - public String getGraph_type() { - return graph_type; - } - - public void setGraph_type(String graph_type) { - this.graph_type = graph_type; - } - - public String getHost_name() { - return host_name; - } - - public void setHost_name(String host_name) { - this.host_name = host_name; - } - - public String getMetric_name() { - return metric_name; - } - - public void setMetric_name(String metric_name) { - this.metric_name = metric_name; - } - - public Number[][] getDatapoints() { - return datapoints; - } - - - public void setDatapoints(Number[][] datapoints) { - this.datapoints = datapoints; - } - - public void setDatapointsFromList(List<GangliaMetric.TemporalMetric> listTemporalMetrics) { - //this.datapoints = datapoints; - Number[][] datapointsArray = new Number[listTemporalMetrics.size()][2]; - int cnt = 0; - if (PERCENTAGE_METRIC.contains(metric_name)) { - int firstIndex = 0; - int lastIndex = listTemporalMetrics.size() - 1; - for (int i = firstIndex; i <= lastIndex; ++i) { - GangliaMetric.TemporalMetric m = listTemporalMetrics.get(i); - Number val = m.getValue(); - if (100.0 >= val.doubleValue()) { - datapointsArray[cnt][0] = val; - datapointsArray[cnt][1] = m.getTime(); - cnt++; - } - } - } else { - int firstIndex = 0; - int lastIndex = listTemporalMetrics.size() - 1; - for (int i = firstIndex; i <= lastIndex; ++i) { - GangliaMetric.TemporalMetric m = listTemporalMetrics.get(i); - datapointsArray[i][0] = m.getValue(); - datapointsArray[i][1] = m.getTime(); - cnt++; - } - } - - this.datapoints = new Number[cnt][2]; - for (int i = 0; i < this.datapoints.length; i++) { - this.datapoints[i][0] = datapointsArray[i][0]; - this.datapoints[i][1] = datapointsArray[i][1]; - } - - } - - // ----- Object overrides -------------------------------------------------- - - @Override - public String toString() { - StringBuilder stringBuilder = new StringBuilder(); - - stringBuilder.append("\n"); - stringBuilder.append("name="); - stringBuilder.append(ds_name); - stringBuilder.append("\n"); - stringBuilder.append("cluster name="); - stringBuilder.append(cluster_name); - stringBuilder.append("\n"); - stringBuilder.append("graph type="); - stringBuilder.append(graph_type); - stringBuilder.append("\n"); - stringBuilder.append("host name="); - stringBuilder.append(host_name); - stringBuilder.append("\n"); - stringBuilder.append("api name="); - stringBuilder.append(metric_name); - stringBuilder.append("\n"); - - stringBuilder.append("datapoints (value/timestamp):"); - stringBuilder.append("\n"); - - - boolean first = true; - stringBuilder.append("["); - for (Number[] m : datapoints) { - if (!first) { - stringBuilder.append(","); - } - stringBuilder.append("["); - stringBuilder.append(m[0]); - stringBuilder.append(","); - stringBuilder.append(m[1].longValue()); - stringBuilder.append("]"); - first = false; - } - stringBuilder.append("]"); - - return stringBuilder.toString(); - } - - public static class TemporalMetric { - private Number m_value; - private Number m_time; - private boolean valid; - - public boolean isValid() { - return valid; - } - - public TemporalMetric(String value, Number time) { - valid = true; - try{ - m_value = convertToNumber(value); - } catch (NumberFormatException e) { - valid = false; - } - m_time = time; - } - - public Number getValue() { - return m_value; - } - - public Number getTime() { - return m_time; - } - - private Number convertToNumber(String s) throws NumberFormatException { - Number res; - if(s.contains(".")){ - Double d = Double.parseDouble(s); - if(d.isNaN() || d.isInfinite()){ - throw new NumberFormatException(s); - } else { - res = d; - } - } else { - res = Long.parseLong(s); - } - return res; - } - - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/a52f8a55/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProvider.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProvider.java deleted file mode 100644 index e786681..0000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProvider.java +++ /dev/null @@ -1,676 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ambari.server.controller.ganglia; - -import org.apache.ambari.server.controller.internal.AbstractPropertyProvider; -import org.apache.ambari.server.configuration.ComponentSSLConfiguration; -import org.apache.ambari.server.controller.internal.PropertyInfo; -import org.apache.ambari.server.controller.spi.*; -import org.apache.ambari.server.controller.utilities.StreamProvider; -import org.apache.http.client.utils.URIBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.*; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Abstract property provider implementation for a Ganglia source. - */ -public abstract class GangliaPropertyProvider extends AbstractPropertyProvider { - - private static final Pattern questionMarkPattern = Pattern.compile("\\?"); - - private final StreamProvider streamProvider; - - private final GangliaHostProvider hostProvider; - - private final String clusterNamePropertyId; - - private final String hostNamePropertyId; - - private final String componentNamePropertyId; - - private final ComponentSSLConfiguration configuration; - - /** - * Map of Ganglia cluster names keyed by component type. - */ - static final Map<String, List<String>> GANGLIA_CLUSTER_NAME_MAP = new HashMap<String, List<String>>(); - - - static { - GANGLIA_CLUSTER_NAME_MAP.put("NAMENODE", Collections.singletonList("HDPNameNode")); - GANGLIA_CLUSTER_NAME_MAP.put("DATANODE", Arrays.asList("HDPDataNode", "HDPSlaves")); - GANGLIA_CLUSTER_NAME_MAP.put("JOBTRACKER", Collections.singletonList("HDPJobTracker")); - GANGLIA_CLUSTER_NAME_MAP.put("TASKTRACKER", Arrays.asList("HDPTaskTracker", "HDPSlaves")); - GANGLIA_CLUSTER_NAME_MAP.put("RESOURCEMANAGER", Collections.singletonList("HDPResourceManager")); - GANGLIA_CLUSTER_NAME_MAP.put("NODEMANAGER", Arrays.asList("HDPNodeManager", "HDPSlaves")); - GANGLIA_CLUSTER_NAME_MAP.put("HISTORYSERVER", Collections.singletonList("HDPHistoryServer")); - GANGLIA_CLUSTER_NAME_MAP.put("HBASE_MASTER", Collections.singletonList("HDPHBaseMaster")); - GANGLIA_CLUSTER_NAME_MAP.put("HBASE_REGIONSERVER", Arrays.asList("HDPHBaseRegionServer", "HDPSlaves")); - GANGLIA_CLUSTER_NAME_MAP.put("FLUME_HANDLER", Arrays.asList("HDPFlumeServer", "HDPSlaves")); - GANGLIA_CLUSTER_NAME_MAP.put("JOURNALNODE", Arrays.asList("HDPJournalNode", "HDPSlaves")); - GANGLIA_CLUSTER_NAME_MAP.put("NIMBUS", Collections.singletonList("HDPNimbus")); - GANGLIA_CLUSTER_NAME_MAP.put("SUPERVISOR", Collections.singletonList("HDPSupervisor")); - GANGLIA_CLUSTER_NAME_MAP.put("KAFKA_BROKER", Collections.singletonList("HDPKafka")); - } - - protected final static Logger LOG = - LoggerFactory.getLogger(GangliaPropertyProvider.class); - - // ----- Constructors ------------------------------------------------------ - - public GangliaPropertyProvider(Map<String, Map<String, PropertyInfo>> componentPropertyInfoMap, - StreamProvider streamProvider, - ComponentSSLConfiguration configuration, - GangliaHostProvider hostProvider, - String clusterNamePropertyId, - String hostNamePropertyId, - String componentNamePropertyId) { - - super(componentPropertyInfoMap); - - this.streamProvider = streamProvider; - this.configuration = configuration; - this.hostProvider = hostProvider; - this.clusterNamePropertyId = clusterNamePropertyId; - this.hostNamePropertyId = hostNamePropertyId; - this.componentNamePropertyId = componentNamePropertyId; - } - - - // ----- PropertyProvider -------------------------------------------------- - - @Override - public Set<Resource> populateResources(Set<Resource> resources, Request request, Predicate predicate) - throws SystemException { - - Set<String> ids = getRequestPropertyIds(request, predicate); - if (ids.isEmpty()) { - return resources; - } - - Map<String, Map<TemporalInfo, RRDRequest>> requestMap = getRRDRequests(resources, request, ids); - - // For each cluster... - for (Map.Entry<String, Map<TemporalInfo, RRDRequest>> clusterEntry : requestMap.entrySet()) { - // For each request ... - for (RRDRequest rrdRequest : clusterEntry.getValue().values() ) { - //todo: property provider can reduce set of resources - rrdRequest.populateResources(); - } - } - return resources; - } - - - // ----- GangliaPropertyProvider ------------------------------------------- - - /** - * Get the host name for the given resource. - * - * @param resource the resource - * - * @return the host name - */ - protected abstract String getHostName(Resource resource); - - /** - * Get the component name for the given resource. - * - * @param resource the resource - * - * @return the component name - */ - protected abstract String getComponentName(Resource resource); - - /** - * Get the ganglia cluster name for the given resource. - * - * - * @param resource the resource - * - * @return the ganglia cluster name - */ - protected abstract Set<String> getGangliaClusterNames(Resource resource, String clusterName); - - - /** - * Get the component name property id. - * - * @return the component name property id - */ - protected String getComponentNamePropertyId() { - return componentNamePropertyId; - } - - /** - * Get the host name property id. - * - * @return the host name property id - */ - protected String getHostNamePropertyId() { - return hostNamePropertyId; - } - - /** - * Get the stream provider. - * - * @return the stream provider - */ - public StreamProvider getStreamProvider() { - return streamProvider; - } - - - // ----- helper methods ---------------------------------------------------- - - /** - * Get the request objects containing all the information required to - * make single requests to the Ganglia rrd script. - * Requests are created per cluster name / temporal information but - * can span multiple resources and metrics. - * - * @param resources the resources being populated - * @param request the request - * @param ids the relevant property ids - * - * @return a map of maps of rrd requests keyed by cluster name / temporal info - */ - private Map<String, Map<TemporalInfo, RRDRequest>> getRRDRequests(Set<Resource> resources, - Request request, - Set<String> ids) { - - Map<String, Map<TemporalInfo, RRDRequest>> requestMap = - new HashMap<String, Map<TemporalInfo, RRDRequest>>(); - - for (Resource resource : resources) { - String clusterName = (String) resource.getPropertyValue(clusterNamePropertyId); - Map<TemporalInfo, RRDRequest> requests = requestMap.get(clusterName); - if (requests == null) { - requests = new HashMap<TemporalInfo, RRDRequest>(); - requestMap.put(clusterName, requests); - } - - Set<String> gangliaClusterNames = getGangliaClusterNames(resource, clusterName); - - for (String gangliaClusterName : gangliaClusterNames) { - ResourceKey key = - new ResourceKey(getHostName(resource), gangliaClusterName); - - for (String id : ids) { - Map<String, PropertyInfo> propertyInfoMap = new HashMap<String, PropertyInfo>(); - - Map<String, PropertyInfo> componentMetricMap = - getComponentMetrics().get(getComponentName(resource)); - - // Not all components have metrics - if (componentMetricMap != null && - !componentMetricMap.containsKey(id)) { - updateComponentMetricMap(componentMetricMap, id); - } - - getPropertyInfoMap(getComponentName(resource), id, propertyInfoMap); - - for (Map.Entry<String, PropertyInfo> entry : propertyInfoMap.entrySet()) { - String propertyId = entry.getKey(); - PropertyInfo propertyInfo = entry.getValue(); - - TemporalInfo temporalInfo = request.getTemporalInfo(id); - - if ((temporalInfo == null && propertyInfo.isPointInTime()) || (temporalInfo != null && propertyInfo.isTemporal())) { - RRDRequest rrdRequest = requests.get(temporalInfo); - if (rrdRequest == null) { - rrdRequest = new RRDRequest(clusterName, temporalInfo); - requests.put(temporalInfo, rrdRequest); - } - rrdRequest.putResource(key, resource); - rrdRequest.putPropertyId(propertyInfo.getPropertyId(), propertyId); - } - } - } - } - } - return requestMap; - } - - /** - * Get the spec to locate the Ganglia stream from the given - * request info. - * - * @param clusterName the cluster name - * @param clusterSet the set of ganglia cluster names - * @param hostSet the set of host names - * @param metricSet the set of metric names - * @param temporalInfo the temporal information - * - * @return the spec, like http://example.com/path?param1=val1¶mn=valn - * - * @throws org.apache.ambari.server.controller.spi.SystemException if unable to get the Ganglia Collector host name - */ - private String getSpec(String clusterName, - Set<String> clusterSet, - Set<String> hostSet, - Set<String> metricSet, - TemporalInfo temporalInfo) throws SystemException { - - String clusters = getSetString(clusterSet, -1); - String hosts = getSetString(hostSet, -1); - String metrics = getSetString(metricSet, -1); - - URIBuilder uriBuilder = new URIBuilder(); - - if (configuration.isGangliaSSL()) { - uriBuilder.setScheme("https"); - } else { - uriBuilder.setScheme("http"); - } - - uriBuilder.setHost(hostProvider.getGangliaCollectorHostName(clusterName)); - - uriBuilder.setPath("/cgi-bin/rrd.py"); - - uriBuilder.setParameter("c", clusters); - - if (hosts.length() > 0) { - uriBuilder.setParameter("h", hosts); - } - - if (metrics.length() > 0) { - uriBuilder.setParameter("m", metrics); - } else { - // get all metrics - uriBuilder.setParameter("m", ".*"); - } - - if (temporalInfo != null) { - long startTime = temporalInfo.getStartTime(); - if (startTime != -1) { - uriBuilder.setParameter("s", String.valueOf(startTime)); - } - - long endTime = temporalInfo.getEndTime(); - if (endTime != -1) { - uriBuilder.setParameter("e", String.valueOf(endTime)); - } - - long step = temporalInfo.getStep(); - if (step != -1) { - uriBuilder.setParameter("r", String.valueOf(step)); - } - } else { - uriBuilder.setParameter("e", "now"); - uriBuilder.setParameter("pt", "true"); - } - - return uriBuilder.toString(); - } - - - /** - * Get value from the given metric. - * - * @param metric the metric - * @param isTemporal indicates whether or not this a temporal metric - * - * @return a range of temporal data or a point in time value if not temporal - */ - private static Object getValue(GangliaMetric metric, boolean isTemporal) { - Number[][] dataPoints = metric.getDatapoints(); - - int length = dataPoints.length; - if (isTemporal) { - return length > 0 ? dataPoints : null; - } else { - // return the value of the last data point - return length > 0 ? dataPoints[length - 1][0] : 0; - } - } - - /** - * Get a comma delimited string from the given set of strings or - * an empty string if the size of the given set is greater than - * the given limit. - * - * @param set the set of strings - * @param limit the upper size limit for the list - * - * @return a comma delimited string of strings - */ - private static String getSetString(Set<String> set, int limit) { - StringBuilder sb = new StringBuilder(); - - if (limit == -1 || set.size() <= limit) { - for (String cluster : set) { - if (sb.length() > 0) { - sb.append(','); - } - sb.append(cluster); - } - } - return sb.toString(); - } - - - // ----- inner classes ----------------------------------------------------- - - - // ----- RRDRequest ---------------------------------------------------- - - /** - * The information required to make a single RRD request. - */ - private class RRDRequest { - private static final int POPULATION_TIME_UPPER_LIMIT = 5; - private final String clusterName; - private final TemporalInfo temporalInfo; - private final Map<ResourceKey, Set<Resource>> resources = new HashMap<ResourceKey, Set<Resource>>(); - private final Map<String, Set<String>> metrics = new HashMap<String, Set<String>>(); - private final Set<String> clusterSet = new HashSet<String>(); - private final Set<String> hostSet = new HashSet<String>(); - - - private RRDRequest(String clusterName, TemporalInfo temporalInfo) { - this.clusterName = clusterName; - this.temporalInfo = temporalInfo; - } - - public void putResource(ResourceKey key, Resource resource) { - clusterSet.add(key.getClusterName()); - hostSet.add(key.getHostName()); - Set<Resource> resourceSet = resources.get(key); - if (resourceSet == null) { - resourceSet = new HashSet<Resource>(); - resources.put(key, resourceSet); - } - resourceSet.add(resource); - } - - public void putPropertyId(String metric, String id) { - Set<String> propertyIds = metrics.get(metric); - - if (propertyIds == null) { - propertyIds = new HashSet<String>(); - metrics.put(metric, propertyIds); - } - propertyIds.add(id); - } - - /** - * Populate the associated resources by making the rrd request. - * - * @return a collection of populated resources - * - * @throws org.apache.ambari.server.controller.spi.SystemException if unable to populate the resources - */ - public Collection<Resource> populateResources() throws SystemException { - - //Get full url with parameters - String specWithParams = getSpec(clusterName, clusterSet, hostSet, metrics.keySet(), temporalInfo); - - //URL - String spec = null; - //Parameters - String params = null; - - String[] tokens = questionMarkPattern.split(specWithParams, 2); - - try { - spec = tokens[0]; - params = tokens[1]; - } catch (ArrayIndexOutOfBoundsException e) { - LOG.info(e.toString()); - } - - - BufferedReader reader = null; - try { - - //Check if host is live - if (!hostProvider.isGangliaCollectorHostLive(clusterName)) { - LOG.info("Ganglia host is not live"); - return Collections.emptySet(); - } - - //Check if Ganglia server component is live - if (!hostProvider.isGangliaCollectorComponentLive(clusterName)) { - LOG.debug("Ganglia server component is not live"); - return Collections.emptySet(); - } - - reader = new BufferedReader(new InputStreamReader( - getStreamProvider().readFrom(spec, "POST", params))); - - String feedStart = reader.readLine(); - if (feedStart == null || feedStart.isEmpty()) { - LOG.info("Empty feed while getting ganglia metrics for spec => "+ - spec); - return Collections.emptySet(); - } - int startTime = convertToNumber(feedStart).intValue(); - - String dsName = reader.readLine(); - if (dsName == null || dsName.isEmpty()) { - LOG.info("Feed without body while reading ganglia metrics for spec " + - "=> " + spec); - return Collections.emptySet(); - } - - while(!"[~EOF]".equals(dsName)) { - GangliaMetric metric = new GangliaMetric(); - List<GangliaMetric.TemporalMetric> listTemporalMetrics = - new ArrayList<GangliaMetric.TemporalMetric>(); - - metric.setDs_name(dsName); - metric.setCluster_name(reader.readLine()); - metric.setHost_name(reader.readLine()); - metric.setMetric_name(reader.readLine()); - - String timeStr = reader.readLine(); - String stepStr = reader.readLine(); - if (timeStr == null || timeStr.isEmpty() || stepStr == null - || stepStr.isEmpty()) { - LOG.info("Unexpected end of stream reached while getting ganglia " + - "metrics for spec => " + spec); - return Collections.emptySet(); - } - int time = convertToNumber(timeStr).intValue(); - int step = convertToNumber(stepStr).intValue(); - - String val = reader.readLine(); - String lastVal = null; - - while(val!=null && !"[~EOM]".equals(val)) { - if (val.startsWith("[~r]")) { - Integer repeat = Integer.valueOf(val.substring(4)) - 1; - for (int i = 0; i < repeat; ++i) { - if (! "[~n]".equals(lastVal)) { - GangliaMetric.TemporalMetric tm = new GangliaMetric.TemporalMetric(lastVal, time); - if (tm.isValid()) listTemporalMetrics.add(tm); - } - time += step; - } - } else { - if (! "[~n]".equals(val)) { - GangliaMetric.TemporalMetric tm = new GangliaMetric.TemporalMetric(val, time); - if (tm.isValid()) listTemporalMetrics.add(tm); - } - time += step; - } - lastVal = val; - val = reader.readLine(); - } - - metric.setDatapointsFromList(listTemporalMetrics); - - ResourceKey key = new ResourceKey(metric.getHost_name(), metric.getCluster_name()); - Set<Resource> resourceSet = resources.get(key); - if (resourceSet != null) { - for (Resource resource : resourceSet) { - populateResource(resource, metric); - } - } - - dsName = reader.readLine(); - if (dsName == null || dsName.isEmpty()) { - LOG.info("Unexpected end of stream reached while getting ganglia " + - "metrics for spec => " + spec); - return Collections.emptySet(); - } - } - String feedEnd = reader.readLine(); - if (feedEnd == null || feedEnd.isEmpty()) { - LOG.info("Error reading end of feed while getting ganglia metrics " + - "for spec => " + spec); - } else { - - int endTime = convertToNumber(feedEnd).intValue(); - int totalTime = endTime - startTime; - if (LOG.isInfoEnabled() && totalTime > POPULATION_TIME_UPPER_LIMIT) { - LOG.info("Ganglia resource population time: " + totalTime); - } - } - } catch (IOException e) { - if (LOG.isErrorEnabled()) { - LOG.error("Caught exception getting Ganglia metrics : spec=" + spec); - } - } finally { - if (reader != null) { - try { - reader.close(); - } catch (IOException e) { - if (LOG.isWarnEnabled()) { - LOG.warn("Unable to close http input steam : spec=" + spec, e); - } - } - } - } - //todo: filter out resources and return keepers - return Collections.emptySet(); - } - - - /** - * Populate the given resource with the given Ganglia metric. - * - * @param resource the resource - * @param gangliaMetric the Ganglia metrics - */ - private void populateResource(Resource resource, GangliaMetric gangliaMetric) { - String metric_name = gangliaMetric.getMetric_name(); - - Set<String> propertyIdSet = metrics.get(metric_name); - List<String> parameterList = new LinkedList<String>(); - - if (propertyIdSet == null) { - for (Map.Entry<String, Set<String>> entry : metrics.entrySet()) { - - String key = entry.getKey(); - - Pattern pattern = Pattern.compile(key); - Matcher matcher = pattern.matcher(metric_name); - - if (matcher.matches()) { - propertyIdSet = entry.getValue(); - // get parameters - for (int i = 0; i < matcher.groupCount(); ++i) { - parameterList.add(matcher.group(i + 1)); - } - break; - } - } - } - if (propertyIdSet != null) { - Map<String, PropertyInfo> metricsMap = getComponentMetrics().get(getComponentName(resource)); - if (metricsMap != null) { - for (String propertyId : propertyIdSet) { - if (propertyId != null) { - if (metricsMap.containsKey(propertyId)){ - if (containsArguments(propertyId)) { - int i = 1; - for (String param : parameterList) { - propertyId = substituteArgument(propertyId, "$" + i, param); - ++i; - } - } - Object value = getValue(gangliaMetric, temporalInfo != null); - if (value != null) { - resource.setProperty(propertyId, value); - } - } - } - } - } - } - } - - private Number convertToNumber(String s) { - return s.contains(".") ? Double.parseDouble(s) : Long.parseLong(s); - } - } - - - // ----- ResourceKey --------------------------------------------------- - - /** - * Key used to associate information from a Ganglia metric to a resource. - */ - private static class ResourceKey { - private final String hostName; - private final String gangliaClusterName; - - private ResourceKey(String hostName, String gangliaClusterName) { - this.hostName = hostName; - this.gangliaClusterName = gangliaClusterName; - } - - public String getHostName() { - return hostName; - } - - public String getClusterName() { - return gangliaClusterName; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - ResourceKey that = (ResourceKey) o; - - return - !(gangliaClusterName != null ? !gangliaClusterName.equals(that.gangliaClusterName) : that.gangliaClusterName != null) && - !(hostName != null ? !hostName.equals(that.hostName) : that.hostName != null); - - } - - @Override - public int hashCode() { - int result = hostName != null ? hostName.hashCode() : 0; - result = 31 * result + (gangliaClusterName != null ? gangliaClusterName.hashCode() : 0); - return result; - } - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/a52f8a55/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaReportPropertyProvider.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaReportPropertyProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaReportPropertyProvider.java deleted file mode 100644 index 35b156c..0000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ganglia/GangliaReportPropertyProvider.java +++ /dev/null @@ -1,234 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ambari.server.controller.ganglia; - -import org.apache.ambari.server.controller.internal.AbstractPropertyProvider; -import org.apache.ambari.server.configuration.ComponentSSLConfiguration; -import org.apache.ambari.server.controller.internal.PropertyInfo; -import org.apache.ambari.server.controller.spi.*; -import org.apache.ambari.server.controller.utilities.StreamProvider; -import org.codehaus.jackson.map.ObjectMapper; -import org.codehaus.jackson.type.TypeReference; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * Property provider implementation for a Ganglia source. This provider is specialized - * to pull metrics from existing Ganglia reports. - */ -public class GangliaReportPropertyProvider extends AbstractPropertyProvider { - - private final StreamProvider streamProvider; - - private final GangliaHostProvider hostProvider; - - private final String clusterNamePropertyId; - - private final ComponentSSLConfiguration configuration; - - - // ----- Constants -------------------------------------------------------- - - protected final static Logger LOG = - LoggerFactory.getLogger(GangliaReportPropertyProvider.class); - - - // ----- Constructors ------------------------------------------------------ - - public GangliaReportPropertyProvider(Map<String, Map<String, PropertyInfo>> componentPropertyInfoMap, - StreamProvider streamProvider, - ComponentSSLConfiguration configuration, - GangliaHostProvider hostProvider, - String clusterNamePropertyId) { - super(componentPropertyInfoMap); - - this.streamProvider = streamProvider; - this.hostProvider = hostProvider; - this.clusterNamePropertyId = clusterNamePropertyId; - this.configuration = configuration; - } - - - // ----- PropertyProvider -------------------------------------------------- - - @Override - public Set<Resource> populateResources(Set<Resource> resources, Request request, Predicate predicate) - throws SystemException { - - Set<Resource> keepers = new HashSet<Resource>(); - for (Resource resource : resources) { - if (populateResource(resource, request, predicate)) { - keepers.add(resource); - } - } - return keepers; - } - - - // ----- helper methods ---------------------------------------------------- - - /** - * Populate a resource by obtaining the requested Ganglia RESOURCE_METRICS. - * - * @param resource the resource to be populated - * @param request the request - * @param predicate the predicate - * - * @return true if the resource was successfully populated with the requested properties - * - * @throws SystemException if unable to populate the resource - */ - private boolean populateResource(Resource resource, Request request, Predicate predicate) - throws SystemException { - - Set<String> propertyIds = getPropertyIds(); - - if (propertyIds.isEmpty()) { - return true; - } - String clusterName = (String) resource.getPropertyValue(clusterNamePropertyId); - - if (hostProvider.getGangliaCollectorHostName(clusterName) == null) { - if (LOG.isWarnEnabled()) { - LOG.warn("Attempting to get metrics but the Ganglia server is unknown. Resource=" + resource + - " : Cluster=" + clusterName); - } - return true; - } - - setProperties(resource, clusterName, request, getRequestPropertyIds(request, predicate)); - - return true; - } - - private boolean setProperties(Resource resource, String clusterName, Request request, Set<String> ids) - throws SystemException { - - Map<String, Map<String, String>> propertyIdMaps = getPropertyIdMaps(request, ids); - - for (Map.Entry<String, Map<String, String>> entry : propertyIdMaps.entrySet()) { - Map<String, String> map = entry.getValue(); - String report = entry.getKey(); - - String spec = getSpec(clusterName, report); - - try { - List<GangliaMetric> gangliaMetrics = new ObjectMapper().readValue(streamProvider.readFrom(spec), - new TypeReference<List<GangliaMetric>>() {}); - - if (gangliaMetrics != null) { - for (GangliaMetric gangliaMetric : gangliaMetrics) { - - String propertyId = map.get(gangliaMetric.getMetric_name()); - if (propertyId != null) { - resource.setProperty(propertyId, getValue(gangliaMetric)); - } - } - } - } catch (IOException e) { - if (LOG.isErrorEnabled()) { - LOG.error("Caught exception getting Ganglia metrics : " + e + " : spec=" + spec); - } - return false; - } - } - return true; - } - - private Map<String, Map<String, String>> getPropertyIdMaps(Request request, Set<String> ids) { - Map<String, Map<String, String>> propertyMap = new HashMap<String, Map<String, String>>(); - - for (String id : ids) { - Map<String, PropertyInfo> propertyInfoMap = getPropertyInfoMap("*", id); - - for (Map.Entry<String, PropertyInfo> entry : propertyInfoMap.entrySet()) { - String propertyId = entry.getKey(); - PropertyInfo propertyInfo = entry.getValue(); - - TemporalInfo temporalInfo = request.getTemporalInfo(id); - - if (temporalInfo != null && propertyInfo.isTemporal()) { - String propertyName = propertyInfo.getPropertyId(); - String report = null; - // format : report_name.metric_name - int dotIndex = propertyName.lastIndexOf('.'); - if (dotIndex != -1){ - report = propertyName.substring(0, dotIndex); - propertyName = propertyName.substring(dotIndex + 1); - } - if (report != null) { - Map<String, String> map = propertyMap.get(report); - if (map == null) { - map = new HashMap<String, String>(); - propertyMap.put(report, map); - } - map.put(propertyName, propertyId); - } - } - } - } - return propertyMap; - } - - /** - * Get value from the given metric. - * - * @param metric the metric - */ - private Object getValue(GangliaMetric metric) { - return metric.getDatapoints(); - } - - /** - * Get the spec to locate the Ganglia stream from the given - * request info. - * - * - * @param clusterName the cluster name - * @param report the report - * - * @return the spec - * - * @throws SystemException if unable to ge the Ganglia Collector host name - */ - protected String getSpec(String clusterName, String report) throws SystemException { - - StringBuilder sb = new StringBuilder(); - - if (configuration.isGangliaSSL()) { - sb.append("https://"); - } else { - sb.append("http://"); - } - - sb.append(hostProvider.getGangliaCollectorHostName(clusterName)). - append("/ganglia/graph.php?g="). - append(report). - append("&json=1"); - - return sb.toString(); - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/a52f8a55/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java index 2381f11..d1a2330 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java @@ -18,18 +18,7 @@ package org.apache.ambari.server.controller.internal; -import java.net.InetAddress; -import java.util.Collections; -import java.util.EnumMap; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - +import com.google.inject.Inject; import org.apache.ambari.server.AmbariException; import org.apache.ambari.server.Role; import org.apache.ambari.server.configuration.ComponentSSLConfiguration; @@ -39,14 +28,11 @@ import org.apache.ambari.server.controller.HostRequest; import org.apache.ambari.server.controller.HostResponse; import org.apache.ambari.server.controller.ServiceComponentHostRequest; import org.apache.ambari.server.controller.ServiceComponentHostResponse; -import org.apache.ambari.server.controller.ganglia.GangliaComponentPropertyProvider; -import org.apache.ambari.server.controller.ganglia.GangliaHostComponentPropertyProvider; -import org.apache.ambari.server.controller.ganglia.GangliaHostPropertyProvider; -import org.apache.ambari.server.controller.ganglia.GangliaHostProvider; -import org.apache.ambari.server.controller.ganglia.GangliaReportPropertyProvider; import org.apache.ambari.server.controller.jmx.JMXHostProvider; import org.apache.ambari.server.controller.jmx.JMXPropertyProvider; -import org.apache.ambari.server.controller.metrics.MetricsHostProvider; +import org.apache.ambari.server.controller.metrics.MetricHostProvider; +import org.apache.ambari.server.controller.metrics.MetricsPropertyProvider; +import org.apache.ambari.server.controller.metrics.MetricsReportPropertyProvider; import org.apache.ambari.server.controller.spi.NoSuchParentResourceException; import org.apache.ambari.server.controller.spi.NoSuchResourceException; import org.apache.ambari.server.controller.spi.Predicate; @@ -70,13 +56,26 @@ import org.apache.ambari.server.state.Service; import org.apache.ambari.server.state.State; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.net.InetAddress; +import java.util.Collections; +import java.util.EnumMap; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import static org.apache.ambari.server.controller.metrics.MetricsPropertyProvider.MetricsService; +import static org.apache.ambari.server.controller.metrics.MetricsPropertyProvider.MetricsService.GANGLIA; +import static org.apache.ambari.server.controller.metrics.MetricsPropertyProvider.MetricsService.TIMELINE_METRICS; -import com.google.inject.Inject; /** * An abstract provider module implementation. */ -public abstract class AbstractProviderModule implements ProviderModule, ResourceProviderObserver, JMXHostProvider, GangliaHostProvider, HostInfoProvider, MetricsHostProvider { +public abstract class AbstractProviderModule implements ProviderModule, ResourceProviderObserver, JMXHostProvider, MetricHostProvider, HostInfoProvider { private static final int PROPERTY_REQUEST_CONNECT_TIMEOUT = 5000; private static final int PROPERTY_REQUEST_READ_TIMEOUT = 10000; @@ -86,6 +85,7 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource private static final String HOST_COMPONENT_HOST_NAME_PROPERTY_ID = PropertyHelper.getPropertyId("HostRoles", "host_name"); private static final String HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID = PropertyHelper.getPropertyId("HostRoles", "component_name"); private static final String GANGLIA_SERVER = "GANGLIA_SERVER"; + private static final String METRIC_SERVER = "METRIC_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<Service.Type, String> serviceConfigTypes = new EnumMap<Service.Type, String>(Service.Type.class); @@ -102,6 +102,7 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource serviceConfigTypes.put(Service.Type.HBASE, "hbase-site"); serviceConfigTypes.put(Service.Type.YARN, "yarn-site"); serviceConfigTypes.put(Service.Type.MAPREDUCE2, "mapred-site"); + serviceConfigTypes.put(Service.Type.AMS, "ams-site"); componentServiceMap.put("NAMENODE", Service.Type.HDFS); componentServiceMap.put("DATANODE", Service.Type.HDFS); @@ -164,6 +165,11 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource private Map<String, String> clusterGangliaCollectorMap; /** + * The host name of Metrics collector. + */ + private Map<String, String> clusterMetricCollectorMap; + + /** * JMX ports read from the configs */ private final Map<String, Map<String, String>> jmxPortMap = @@ -198,7 +204,7 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource } @Override - public List<PropertyProvider> getPropertyProviders(Resource.Type type) { + public List<PropertyProvider> getPropertyProviders(Resource.Type type) { if (!propertyProviders.containsKey(type)) { createPropertyProviders(type); @@ -224,6 +230,59 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource // ----- MetricsHostProvider --------------------------------------------------- @Override + 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 null; + } + + @Override + public String getCollectorPortName(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.AMS); + String currentConfigVersion = getDesiredConfigVersion(clusterName, configType); + String oldConfigVersion = serviceConfigVersions.get(Service.Type.AMS); + + if (!currentConfigVersion.equals(oldConfigVersion)) { + serviceConfigVersions.put(Service.Type.AMS, currentConfigVersion); + + Map<String, String> configProperties = getDesiredConfigMap + (clusterName, currentConfigVersion, configType, + Collections.singletonMap("METRIC_COLLECTOR", + new String[]{"timeline.metrics.service.webapp.address"})); + + if (!configProperties.isEmpty()) { + return getPortString(configProperties.get("METRIC_COLLECTOR")); + } + } + + } catch (NoSuchParentResourceException e) { + LOG.warn("Failed to retrieve collector port.", e); + } catch (UnsupportedPropertyException e) { + LOG.warn("Failed to retrieve collector port.", e); + } + return "8188"; + } + return null; + } + + @Override + public boolean isCollectorHostLive(String clusterName, MetricsService service) throws SystemException { + + final String collectorHostName = getCollectorHostName(clusterName, service); + + return isHostLive(clusterName, collectorHostName); + } + + @Override public String getHostName(String clusterName, String componentName) throws SystemException { checkInit(); return clusterHostComponentMap.get(clusterName).get(componentName); @@ -242,6 +301,83 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource return hosts; } + @Override + public boolean isCollectorComponentLive(String clusterName, MetricsService service) throws SystemException { + + final String collectorHostName = getCollectorHostName(clusterName, service); + + if (service.equals(GANGLIA)) { + return isHostComponentLive(clusterName, collectorHostName, "GANGLIA", + Role.GANGLIA_SERVER.name()); + } else if (service.equals(TIMELINE_METRICS)) { + return isHostComponentLive(clusterName, collectorHostName, "AMS", + Role.METRIC_COLLECTOR.name()); + } + return false; + } + + private boolean isHostComponentLive(String clusterName, String hostName, + String serviceName, String componentName) { + if (clusterName == null) { + return false; + } + + ServiceComponentHostResponse componentHostResponse; + + try { + ServiceComponentHostRequest componentRequest = + new ServiceComponentHostRequest(clusterName, serviceName, + componentName, hostName, null); + + Set<ServiceComponentHostResponse> hostComponents = + managementController.getHostComponents(Collections.singleton(componentRequest)); + + componentHostResponse = hostComponents.size() == 1 ? hostComponents.iterator().next() : null; + } catch (AmbariException e) { + LOG.debug("Error checking " + componentName + " server host component state: ", e); + return false; + } + + //Cluster without SCH + return componentHostResponse != null && + componentHostResponse.getLiveState().equals(State.STARTED.name()); + } + + protected MetricsService getMetricsServiceType() { + try { + checkInit(); + } catch (SystemException e) { + LOG.error("Exception during checkInit.", e); + return GANGLIA; + } + if (!clusterMetricCollectorMap.isEmpty()) { + return TIMELINE_METRICS; + } else { + return GANGLIA; + } + } + + protected boolean isHostLive(String clusterName, String hostName) { + if (clusterName == null) { + return false; + } + HostResponse hostResponse; + + try { + HostRequest hostRequest = new HostRequest(hostName, clusterName, + Collections.<String, String>emptyMap()); + Set<HostResponse> hosts = HostResourceProvider.getHosts(managementController, hostRequest); + + hostResponse = hosts.size() == 1 ? hosts.iterator().next() : null; + } catch (AmbariException e) { + LOG.debug("Error checking of Ganglia server host live status: ", e); + return false; + } + //Cluster without host + return hostResponse != null && + !hostResponse.getHostState().equals(HostState.HEARTBEAT_LOST.name()); + } + // ----- JMXHostProvider --------------------------------------------------- @Override @@ -371,72 +507,6 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource } } - // ----- GangliaHostProvider ----------------------------------------------- - - @Override - public String getGangliaCollectorHostName(String clusterName) throws SystemException { - checkInit(); - return clusterGangliaCollectorMap.get(clusterName); - } - - @Override - public boolean isGangliaCollectorHostLive(String clusterName) throws SystemException { - - if (clusterName == null) { - return false; - } - - HostResponse gangliaCollectorHost; - - try { - - final String gangliaCollectorHostName = getGangliaCollectorHostName(clusterName); - - HostRequest hostRequest = new HostRequest(gangliaCollectorHostName, clusterName, Collections.<String, String>emptyMap()); - Set<HostResponse> hosts = HostResourceProvider.getHosts(managementController, hostRequest); - - gangliaCollectorHost = hosts.size() == 1 ? hosts.iterator().next() : null; - } catch (AmbariException e) { - LOG.debug("Error checking of Ganglia server host live status: ", e); - return false; - } - - //Cluster without Ganglia - return gangliaCollectorHost != null && - !gangliaCollectorHost.getHostState().equals(HostState.HEARTBEAT_LOST.name()); - } - - @Override - public boolean isGangliaCollectorComponentLive(String clusterName) throws SystemException { - if (clusterName == null) { - return false; - } - - ServiceComponentHostResponse gangliaCollectorHostComponent; - - try { - final String gangliaCollectorHostName = getGangliaCollectorHostName(clusterName); - - ServiceComponentHostRequest componentRequest = new ServiceComponentHostRequest(clusterName, "GANGLIA", - Role.GANGLIA_SERVER.name(), - gangliaCollectorHostName, - null); - - Set<ServiceComponentHostResponse> hostComponents = - managementController.getHostComponents(Collections.singleton(componentRequest)); - - gangliaCollectorHostComponent = hostComponents.size() == 1 ? hostComponents.iterator().next() : null; - } catch (AmbariException e) { - LOG.debug("Error checking of Ganglia server host component state: ", e); - return false; - } - - //Cluster without Ganglia - return gangliaCollectorHostComponent != null && - gangliaCollectorHostComponent.getLiveState().equals(State.STARTED.name()); - } - - // ----- utility methods --------------------------------------------------- protected abstract ResourceProvider createResourceProvider(Resource.Type type); @@ -471,27 +541,27 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource if (type.isInternalType()) { switch (type.getInternalType()) { case Cluster: - providers.add(createGangliaReportPropertyProvider( - type, - streamProvider, - ComponentSSLConfiguration.instance(), - this, - PropertyHelper.getPropertyId("Clusters", "cluster_name"))); - providers.add(new AlertSummaryPropertyProvider(type, - "Clusters/cluster_name", null)); + providers.add(createMetricsReportPropertyProvider( + type, + streamProvider, + ComponentSSLConfiguration.instance(), + this, + PropertyHelper.getPropertyId("Clusters", "cluster_name"))); + providers.add(new AlertSummaryPropertyProvider(type, + "Clusters/cluster_name", null)); break; case Service: providers.add(new AlertSummaryPropertyProvider(type, "ServiceInfo/cluster_name", "ServiceInfo/service_name")); break; case Host: - providers.add(createGangliaHostPropertyProvider( - type, - streamProvider, - ComponentSSLConfiguration.instance(), - this, - PropertyHelper.getPropertyId("Hosts", "cluster_name"), - PropertyHelper.getPropertyId("Hosts", "host_name") + providers.add(createMetricsHostPropertyProvider( + type, + streamProvider, + ComponentSSLConfiguration.instance(), + this, + PropertyHelper.getPropertyId("Hosts", "cluster_name"), + PropertyHelper.getPropertyId("Hosts", "host_name") )); providers.add(new AlertSummaryPropertyProvider(type, "Hosts/cluster_name", "Hosts/host_name")); @@ -516,19 +586,18 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource PropertyHelper.getPropertyId("ServiceComponentInfo", "component_name"), PropertyHelper.getPropertyId("ServiceComponentInfo", "service_name")); } else { - gpp = createGangliaComponentPropertyProvider( - type, - streamProvider, - ComponentSSLConfiguration.instance(), - this, - PropertyHelper.getPropertyId("ServiceComponentInfo", "cluster_name"), - PropertyHelper.getPropertyId("ServiceComponentInfo", "component_name")); + gpp = createMetricsComponentPropertyProvider( + type, + streamProvider, + ComponentSSLConfiguration.instance(), + this, + PropertyHelper.getPropertyId("ServiceComponentInfo", "cluster_name"), + PropertyHelper.getPropertyId("ServiceComponentInfo", "component_name")); } providers.add(new StackDefinedPropertyProvider( type, this, this, - this, streamProvider, PropertyHelper.getPropertyId("ServiceComponentInfo", "cluster_name"), null, @@ -559,20 +628,19 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource PropertyHelper.getPropertyId("HostRoles", "component_name"), PropertyHelper.getPropertyId("HostRoles", "service_name")); } else { - gpp = createGangliaHostComponentPropertyProvider( - type, - streamProvider, - ComponentSSLConfiguration.instance(), - this, - PropertyHelper.getPropertyId("HostRoles", "cluster_name"), - PropertyHelper.getPropertyId("HostRoles", "host_name"), - PropertyHelper.getPropertyId("HostRoles", "component_name")); + gpp = createMetricsHostComponentPropertyProvider( + type, + streamProvider, + ComponentSSLConfiguration.instance(), + this, + PropertyHelper.getPropertyId("HostRoles", "cluster_name"), + PropertyHelper.getPropertyId("HostRoles", "host_name"), + PropertyHelper.getPropertyId("HostRoles", "component_name")); } providers.add(new StackDefinedPropertyProvider( type, this, this, - this, streamProvider, PropertyHelper.getPropertyId("HostRoles", "cluster_name"), PropertyHelper.getPropertyId("HostRoles", "host_name"), @@ -589,6 +657,8 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource putPropertyProviders(type, providers); } + + private void checkInit() throws SystemException { if (!initialized) { synchronized (this) { @@ -626,6 +696,7 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource clusterHostComponentMap = new HashMap<String, Map<String, String>>(); clusterGangliaCollectorMap = new HashMap<String, String>(); + clusterMetricCollectorMap = new HashMap<String, String>(); for (Resource cluster : clusters) { @@ -658,6 +729,9 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource if (componentName.equals(GANGLIA_SERVER)) { clusterGangliaCollectorMap.put(clusterName, hostName); } + if (componentName.equals(METRIC_SERVER)) { + clusterMetricCollectorMap.put(clusterName, hostName); + } } } } catch (UnsupportedPropertyException e) { @@ -797,9 +871,10 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource /** * Create the JMX property provider for the given type. */ - private PropertyProvider createJMXPropertyProvider(Resource.Type type, StreamProvider streamProvider, + private PropertyProvider createJMXPropertyProvider(Resource.Type type, + StreamProvider streamProvider, JMXHostProvider jmxHostProvider, - MetricsHostProvider metricsHostProvider, + MetricHostProvider metricsHostProvider, String clusterNamePropertyId, String hostNamePropertyId, String componentNamePropertyId, @@ -813,52 +888,59 @@ public abstract class AbstractProviderModule implements ProviderModule, Resource /** * Create the Ganglia report property provider for the given type. */ - private PropertyProvider createGangliaReportPropertyProvider(Resource.Type type, StreamProvider streamProvider, + private PropertyProvider createMetricsReportPropertyProvider(Resource.Type type, StreamProvider streamProvider, ComponentSSLConfiguration configuration, - GangliaHostProvider hostProvider, + MetricHostProvider hostProvider, String clusterNamePropertyId) { - return new GangliaReportPropertyProvider(PropertyHelper.getGangliaPropertyIds(type), streamProvider, - configuration, hostProvider, clusterNamePropertyId); + return MetricsReportPropertyProvider.createInstance( + getMetricsServiceType(), PropertyHelper.getMetricPropertyIds(type), + streamProvider, configuration, hostProvider, clusterNamePropertyId); } /** * Create the Ganglia host property provider for the given type. */ - private PropertyProvider createGangliaHostPropertyProvider(Resource.Type type, StreamProvider streamProvider, + private PropertyProvider createMetricsHostPropertyProvider(Resource.Type type, + StreamProvider streamProvider, ComponentSSLConfiguration configuration, - GangliaHostProvider hostProvider, + MetricHostProvider hostProvider, String clusterNamePropertyId, String hostNamePropertyId) { - return new GangliaHostPropertyProvider(PropertyHelper.getGangliaPropertyIds(type), streamProvider, - configuration, hostProvider, clusterNamePropertyId, hostNamePropertyId); + return MetricsPropertyProvider.createInstance(getMetricsServiceType(), type, + PropertyHelper.getMetricPropertyIds(type), streamProvider, configuration, + hostProvider, clusterNamePropertyId, hostNamePropertyId, null); } /** * Create the Ganglia component property provider for the given type. */ - private PropertyProvider createGangliaComponentPropertyProvider(Resource.Type type, StreamProvider streamProvider, + private PropertyProvider createMetricsComponentPropertyProvider(Resource.Type type, + StreamProvider streamProvider, ComponentSSLConfiguration configuration, - GangliaHostProvider hostProvider, + MetricHostProvider hostProvider, String clusterNamePropertyId, String componentNamePropertyId) { - return new GangliaComponentPropertyProvider(PropertyHelper.getGangliaPropertyIds(type), - streamProvider, configuration, hostProvider, clusterNamePropertyId, componentNamePropertyId); + return MetricsPropertyProvider.createInstance(getMetricsServiceType(), type, + PropertyHelper.getMetricPropertyIds(type), streamProvider, configuration, + hostProvider, clusterNamePropertyId, null, componentNamePropertyId); } /** * Create the Ganglia host component property provider for the given type. */ - private PropertyProvider createGangliaHostComponentPropertyProvider(Resource.Type type, StreamProvider streamProvider, + private PropertyProvider createMetricsHostComponentPropertyProvider(Resource.Type type, + StreamProvider streamProvider, ComponentSSLConfiguration configuration, - GangliaHostProvider hostProvider, + MetricHostProvider hostProvider, String clusterNamePropertyId, String hostNamePropertyId, String componentNamePropertyId) { - return new GangliaHostComponentPropertyProvider(PropertyHelper.getGangliaPropertyIds(type), streamProvider, - configuration, hostProvider, clusterNamePropertyId, hostNamePropertyId, componentNamePropertyId); + return MetricsPropertyProvider.createInstance(getMetricsServiceType(), type, + PropertyHelper.getMetricPropertyIds(type), streamProvider, configuration, + hostProvider, clusterNamePropertyId, hostNamePropertyId, componentNamePropertyId); } /**