You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ol...@apache.org on 2016/04/26 14:33:06 UTC

ambari git commit: AMBARI-16111. Add ambari-metrics-common dependency instead of hard-coded metrics code in Logfeeder (Dharmesh Makwana via oleewere)

Repository: ambari
Updated Branches:
  refs/heads/trunk ee4dfb963 -> 071c175a1


AMBARI-16111. Add ambari-metrics-common dependency instead of hard-coded metrics code in Logfeeder (Dharmesh Makwana via oleewere)


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

Branch: refs/heads/trunk
Commit: 071c175a119c54f26cb12a092992d18e69a425ba
Parents: ee4dfb9
Author: oleewere <ol...@gmail.com>
Authored: Tue Apr 26 14:22:10 2016 +0200
Committer: oleewere <ol...@gmail.com>
Committed: Tue Apr 26 14:22:10 2016 +0200

----------------------------------------------------------------------
 .../ambari-logsearch-logfeeder/pom.xml          |   6 +-
 .../timeline/AbstractTimelineMetricsSink.java   |  95 ----------
 .../metrics2/sink/timeline/Precision.java       |  79 --------
 .../PrecisionLimitExceededException.java        |  36 ----
 .../timeline/SingleValuedTimelineMetric.java    | 107 -----------
 .../metrics2/sink/timeline/TimelineMetric.java  | 188 -------------------
 .../metrics2/sink/timeline/TimelineMetrics.java | 123 ------------
 .../sink/timeline/UnableToConnectException.java |  46 -----
 .../timeline/cache/TimelineMetricsCache.java    | 175 -----------------
 .../timeline/configuration/Configuration.java   |  62 ------
 .../hadoop/metrics2/sink/util/Servers.java      | 106 -----------
 11 files changed, 5 insertions(+), 1018 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/071c175a/ambari-logsearch/ambari-logsearch-logfeeder/pom.xml
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-logfeeder/pom.xml b/ambari-logsearch/ambari-logsearch-logfeeder/pom.xml
index dc1b361..12255fe 100644
--- a/ambari-logsearch/ambari-logsearch-logfeeder/pom.xml
+++ b/ambari-logsearch/ambari-logsearch-logfeeder/pom.xml
@@ -115,7 +115,11 @@
       <artifactId>jackson-xc</artifactId>
       <version>1.9.13</version>
     </dependency>
-
+    <dependency>
+      <groupId>org.apache.ambari</groupId>
+      <artifactId>ambari-metrics-common</artifactId>
+      <version>${project.version}</version>
+    </dependency>
   </dependencies>
   <build>
     <finalName>LogFeeder</finalName>

http://git-wip-us.apache.org/repos/asf/ambari/blob/071c175a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/timeline/AbstractTimelineMetricsSink.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/timeline/AbstractTimelineMetricsSink.java b/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/timeline/AbstractTimelineMetricsSink.java
deleted file mode 100644
index 956af16..0000000
--- a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/timeline/AbstractTimelineMetricsSink.java
+++ /dev/null
@@ -1,95 +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.hadoop.metrics2.sink.timeline;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.codehaus.jackson.map.AnnotationIntrospector;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.map.annotate.JsonSerialize;
-import org.codehaus.jackson.xc.JaxbAnnotationIntrospector;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.net.HttpURLConnection;
-import java.net.URL;
-
-public abstract class AbstractTimelineMetricsSink {
-  public static final String TAGS_FOR_PREFIX_PROPERTY_PREFIX = "tagsForPrefix.";
-  public static final String MAX_METRIC_ROW_CACHE_SIZE = "maxRowCacheSize";
-  public static final String METRICS_SEND_INTERVAL = "sendInterval";
-  public static final String METRICS_POST_TIMEOUT_SECONDS = "timeout";
-  public static final String COLLECTOR_HOST_PROPERTY = "collector";
-  public static final String COLLECTOR_PORT_PROPERTY = "port";
-  public static final int DEFAULT_POST_TIMEOUT_SECONDS = 10;
-
-  protected final Log LOG;
-
-  protected static ObjectMapper mapper;
-
-  static {
-    mapper = new ObjectMapper();
-    AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
-    mapper.setAnnotationIntrospector(introspector);
-    mapper.getSerializationConfig()
-        .setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
-  }
-
-  public AbstractTimelineMetricsSink() {
-    LOG = LogFactory.getLog(this.getClass());
-  }
-
-  protected void emitMetrics(TimelineMetrics metrics) {
-    String connectUrl = getCollectorUri();
-    int timeout = getTimeoutSeconds() * 1000;
-    try {
-      String jsonData = mapper.writeValueAsString(metrics);
-      LOG.info("Posting JSON=" + jsonData);
-      
-      HttpURLConnection connection =
-        (HttpURLConnection) new URL(connectUrl).openConnection();
-
-      connection.setRequestMethod("POST");
-      connection.setRequestProperty("Content-Type", "application/json");
-      connection.setConnectTimeout(timeout);
-      connection.setReadTimeout(timeout);
-      connection.setDoOutput(true);
-
-      if (jsonData != null) {
-        try (OutputStream os = connection.getOutputStream()) {
-          os.write(jsonData.getBytes("UTF-8"));
-        }
-      }
-
-      int statusCode = connection.getResponseCode();
-
-      if (statusCode != 200) {
-        LOG.info("Unable to POST metrics to collector, " + connectUrl + ", " +
-          "statusCode = " + statusCode);
-      } else {
-        LOG.debug("Metrics posted to Collector " + connectUrl);
-      }
-    } catch (IOException e) {
-      throw new UnableToConnectException(e).setConnectUrl(connectUrl);
-    }
-  }
-
-  abstract protected String getCollectorUri();
-
-  abstract protected int getTimeoutSeconds();
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/071c175a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/timeline/Precision.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/timeline/Precision.java b/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/timeline/Precision.java
deleted file mode 100644
index 31044cc..0000000
--- a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/timeline/Precision.java
+++ /dev/null
@@ -1,79 +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.hadoop.metrics2.sink.timeline;
-
-/**
- * Is used to determine metrics aggregate table.
- *
- * @see org.apache.hadoop.yarn.server.applicationhistoryservice.webapp.TimelineWebServices#getTimelineMetric
- */
-public enum Precision {
-  SECONDS,
-  MINUTES,
-  HOURS,
-  DAYS;
-
-  public static class PrecisionFormatException extends IllegalArgumentException {
-    public PrecisionFormatException(String message, Throwable cause) {
-      super(message, cause);
-    }
-  }
-
-  public static Precision getPrecision(String precision) throws PrecisionFormatException {
-    if (precision == null ) {
-      return null;
-    }
-    try {
-      return Precision.valueOf(precision.toUpperCase());
-    } catch (IllegalArgumentException e) {
-      throw new PrecisionFormatException("precision should be seconds, " +
-        "minutes, hours or days", e);
-    }
-  }
-
-  public static Precision getPrecision(long startTime, long endTime) {
-    long HOUR = 3600000; // 1 hour
-    long DAY = 86400000; // 1 day
-    long timeRange = endTime - startTime;
-    if (timeRange > 30 * DAY) {
-      return Precision.DAYS;
-    } else if (timeRange > 1 * DAY) {
-      return Precision.HOURS;
-    } else if (timeRange > 2 * HOUR) {
-      return Precision.MINUTES;
-    } else {
-      return Precision.SECONDS;
-    }
-  }
-
-  public static Precision getHigherPrecision(Precision precision) {
-
-    if (precision == null)
-      return null;
-
-    if (precision.equals(Precision.SECONDS)) {
-      return Precision.MINUTES;
-    } else if (precision.equals(Precision.MINUTES)) {
-      return Precision.HOURS;
-    } else if (precision.equals(Precision.HOURS)) {
-      return Precision.DAYS;
-    } else {
-      return null;
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/071c175a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/timeline/PrecisionLimitExceededException.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/timeline/PrecisionLimitExceededException.java b/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/timeline/PrecisionLimitExceededException.java
deleted file mode 100644
index 962a071..0000000
--- a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/timeline/PrecisionLimitExceededException.java
+++ /dev/null
@@ -1,36 +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.hadoop.metrics2.sink.timeline;
-
-public class PrecisionLimitExceededException extends IllegalArgumentException {
-
-  private static final long serialVersionUID = 1L;
-
-  public PrecisionLimitExceededException(String message, Throwable cause) {
-    super(message, cause);
-  }
-
-  public PrecisionLimitExceededException(String message) {
-    super(message);
-  }
-
-  public PrecisionLimitExceededException(Throwable cause) {
-    super(cause);
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/071c175a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/timeline/SingleValuedTimelineMetric.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/timeline/SingleValuedTimelineMetric.java b/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/timeline/SingleValuedTimelineMetric.java
deleted file mode 100644
index 8ecca54..0000000
--- a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/timeline/SingleValuedTimelineMetric.java
+++ /dev/null
@@ -1,107 +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.hadoop.metrics2.sink.timeline;
-
-/**
- * This class prevents creating a TreeMap for every instantiation of a metric
- * read from the store. The methods are meant to provide interoperability
- * with @TimelineMetric
- */
-public class SingleValuedTimelineMetric {
-  private Long timestamp;
-  private Double value;
-  private String metricName;
-  private String appId;
-  private String instanceId;
-  private String hostName;
-  private Long startTime;
-  private String type;
-
-  public void setSingleTimeseriesValue(Long timestamp, Double value) {
-    this.timestamp = timestamp;
-    this.value = value;
-  }
-
-  public SingleValuedTimelineMetric(String metricName, String appId,
-                                    String instanceId, String hostName,
-                                    long timestamp, long startTime, String type) {
-    this.metricName = metricName;
-    this.appId = appId;
-    this.instanceId = instanceId;
-    this.hostName = hostName;
-    this.timestamp = timestamp;
-    this.startTime = startTime;
-    this.type = type;
-  }
-
-  public Long getTimestamp() {
-    return timestamp;
-  }
-
-  public long getStartTime() {
-    return startTime;
-  }
-
-  public String getType() {
-    return type;
-  }
-
-  public Double getValue() {
-    return value;
-  }
-
-  public String getMetricName() {
-    return metricName;
-  }
-
-  public String getAppId() {
-    return appId;
-  }
-
-  public String getInstanceId() {
-    return instanceId;
-  }
-
-  public String getHostName() {
-    return hostName;
-  }
-
-  public boolean equalsExceptTime(TimelineMetric metric) {
-    if (!metricName.equals(metric.getMetricName())) return false;
-    if (hostName != null ? !hostName.equals(metric.getHostName()) : metric.getHostName() != null)
-      return false;
-    if (appId != null ? !appId.equals(metric.getAppId()) : metric.getAppId() != null)
-      return false;
-    if (instanceId != null ? !instanceId.equals(metric.getInstanceId()) : metric.getInstanceId() != null) return false;
-
-    return true;
-  }
-
-  public TimelineMetric getTimelineMetric() {
-    TimelineMetric metric = new TimelineMetric();
-    metric.setMetricName(this.metricName);
-    metric.setAppId(this.appId);
-    metric.setHostName(this.hostName);
-    metric.setType(this.type);
-    metric.setInstanceId(this.instanceId);
-    metric.setStartTime(this.startTime);
-    metric.setTimestamp(this.timestamp);
-    metric.getMetricValues().put(timestamp, value);
-    return metric;
-  }
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/071c175a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/timeline/TimelineMetric.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/timeline/TimelineMetric.java b/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/timeline/TimelineMetric.java
deleted file mode 100644
index 0e74f2d..0000000
--- a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/timeline/TimelineMetric.java
+++ /dev/null
@@ -1,188 +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.hadoop.metrics2.sink.timeline;
-
-import java.util.Map;
-import java.util.TreeMap;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-
-import org.codehaus.jackson.map.annotate.JsonDeserialize;
-
-@XmlRootElement(name = "metric")
-@XmlAccessorType(XmlAccessType.NONE)
-public class TimelineMetric implements Comparable<TimelineMetric> {
-
-  private String metricName;
-  private String appId;
-  private String instanceId;
-  private String hostName;
-  private long timestamp;
-  private long startTime;
-  private String type;
-  private TreeMap<Long, Double> metricValues = new TreeMap<Long, Double>();
-
-  // default
-  public TimelineMetric() {
-
-  }
-
-  // copy constructor
-  public TimelineMetric(TimelineMetric metric) {
-    setMetricName(metric.getMetricName());
-    setType(metric.getType());
-    setTimestamp(metric.getTimestamp());
-    setAppId(metric.getAppId());
-    setInstanceId(metric.getInstanceId());
-    setHostName(metric.getHostName());
-    setStartTime(metric.getStartTime());
-    setMetricValues(new TreeMap<Long, Double>(metric.getMetricValues()));
-  }
-
-  @XmlElement(name = "metricname")
-  public String getMetricName() {
-    return metricName;
-  }
-
-  public void setMetricName(String metricName) {
-    this.metricName = metricName;
-  }
-
-  @XmlElement(name = "appid")
-  public String getAppId() {
-    return appId;
-  }
-
-  public void setAppId(String appId) {
-    this.appId = appId;
-  }
-
-  @XmlElement(name = "instanceid")
-  public String getInstanceId() {
-    return instanceId;
-  }
-
-  public void setInstanceId(String instanceId) {
-    this.instanceId = instanceId;
-  }
-
-  @XmlElement(name = "hostname")
-  public String getHostName() {
-    return hostName;
-  }
-
-  public void setHostName(String hostName) {
-    this.hostName = hostName;
-  }
-
-  @XmlElement(name = "timestamp")
-  public long getTimestamp() {
-    return timestamp;
-  }
-
-  public void setTimestamp(long timestamp) {
-    this.timestamp = timestamp;
-  }
-
-  @XmlElement(name = "starttime")
-  public long getStartTime() {
-    return startTime;
-  }
-
-  public void setStartTime(long startTime) {
-    this.startTime = startTime;
-  }
-
-  @XmlElement(name = "type")
-  public String getType() {
-    return type;
-  }
-
-  public void setType(String type) {
-    this.type = type;
-  }
-
-  @XmlElement(name = "metrics")
-  public TreeMap<Long, Double> getMetricValues() {
-    return metricValues;
-  }
-
-  public void setMetricValues(TreeMap<Long, Double> metricValues) {
-    this.metricValues = metricValues;
-  }
-
-  public void addMetricValues(Map<Long, Double> metricValues) {
-    this.metricValues.putAll(metricValues);
-  }
-
-  @Override
-  public boolean equals(Object o) {
-    if (this == o) return true;
-    if (o == null || getClass() != o.getClass()) return false;
-
-    TimelineMetric metric = (TimelineMetric) o;
-
-    if (!metricName.equals(metric.metricName)) return false;
-    if (hostName != null ? !hostName.equals(metric.hostName) : metric.hostName != null)
-      return false;
-    if (appId != null ? !appId.equals(metric.appId) : metric.appId != null)
-      return false;
-    if (instanceId != null ? !instanceId.equals(metric.instanceId) : metric.instanceId != null)
-      return false;
-    if (timestamp != metric.timestamp) return false;
-    if (startTime != metric.startTime) return false;
-
-    return true;
-  }
-
-  public boolean equalsExceptTime(TimelineMetric metric) {
-    if (!metricName.equals(metric.metricName)) return false;
-    if (hostName != null ? !hostName.equals(metric.hostName) : metric.hostName != null)
-      return false;
-    if (appId != null ? !appId.equals(metric.appId) : metric.appId != null)
-      return false;
-    if (instanceId != null ? !instanceId.equals(metric.instanceId) : metric.instanceId != null)
-      return false;
-
-    return true;
-  }
-
-  @Override
-  public int hashCode() {
-    int result = metricName.hashCode();
-    result = 31 * result + (appId != null ? appId.hashCode() : 0);
-    result = 31 * result + (instanceId != null ? instanceId.hashCode() : 0);
-    result = 31 * result + (hostName != null ? hostName.hashCode() : 0);
-    result = 31 * result + (int) (timestamp ^ (timestamp >>> 32));
-    return result;
-  }
-
-  @Override
-  public int compareTo(TimelineMetric other) {
-    if (timestamp > other.timestamp) {
-      return -1;
-    } else if (timestamp < other.timestamp) {
-      return 1;
-    } else {
-      return metricName.compareTo(other.metricName);
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/071c175a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/timeline/TimelineMetrics.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/timeline/TimelineMetrics.java b/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/timeline/TimelineMetrics.java
deleted file mode 100644
index 11ca665..0000000
--- a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/timeline/TimelineMetrics.java
+++ /dev/null
@@ -1,123 +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.hadoop.metrics2.sink.timeline;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-
-/**
- * The class that hosts a list of timeline entities.
- */
-@XmlRootElement(name = "metrics")
-@XmlAccessorType(XmlAccessType.NONE)
-public class TimelineMetrics {
-
-  private List<TimelineMetric> allMetrics = new ArrayList<TimelineMetric>();
-
-  public TimelineMetrics() {}
-
-  @XmlElement(name = "metrics")
-  public List<TimelineMetric> getMetrics() {
-    return allMetrics;
-  }
-
-  public void setMetrics(List<TimelineMetric> allMetrics) {
-    this.allMetrics = allMetrics;
-  }
-
-  private boolean isEqualTimelineMetrics(TimelineMetric metric1,
-                                         TimelineMetric metric2) {
-
-    boolean isEqual = true;
-
-    if (!metric1.getMetricName().equals(metric2.getMetricName())) {
-      return false;
-    }
-
-    if (metric1.getHostName() != null) {
-      isEqual = metric1.getHostName().equals(metric2.getHostName());
-    }
-
-    if (metric1.getAppId() != null) {
-      isEqual = metric1.getAppId().equals(metric2.getAppId());
-    }
-
-    return isEqual;
-  }
-
-  /**
-   * Merge with existing TimelineMetric if everything except startTime is
-   * the same.
-   * @param metric {@link TimelineMetric}
-   */
-  public void addOrMergeTimelineMetric(TimelineMetric metric) {
-    TimelineMetric metricToMerge = null;
-
-    if (!allMetrics.isEmpty()) {
-      for (TimelineMetric timelineMetric : allMetrics) {
-        if (timelineMetric.equalsExceptTime(metric)) {
-          metricToMerge = timelineMetric;
-          break;
-        }
-      }
-    }
-
-    if (metricToMerge != null) {
-      metricToMerge.addMetricValues(metric.getMetricValues());
-      if (metricToMerge.getTimestamp() > metric.getTimestamp()) {
-        metricToMerge.setTimestamp(metric.getTimestamp());
-      }
-      if (metricToMerge.getStartTime() > metric.getStartTime()) {
-        metricToMerge.setStartTime(metric.getStartTime());
-      }
-    } else {
-      allMetrics.add(metric);
-    }
-  }
-
-  // Optimization that addresses too many TreeMaps from getting created.
-  public void addOrMergeTimelineMetric(SingleValuedTimelineMetric metric) {
-    TimelineMetric metricToMerge = null;
-
-    if (!allMetrics.isEmpty()) {
-      for (TimelineMetric timelineMetric : allMetrics) {
-        if (metric.equalsExceptTime(timelineMetric)) {
-          metricToMerge = timelineMetric;
-          break;
-        }
-      }
-    }
-
-    if (metricToMerge != null) {
-      metricToMerge.getMetricValues().put(metric.getTimestamp(), metric.getValue());
-      if (metricToMerge.getTimestamp() > metric.getTimestamp()) {
-        metricToMerge.setTimestamp(metric.getTimestamp());
-      }
-      if (metricToMerge.getStartTime() > metric.getStartTime()) {
-        metricToMerge.setStartTime(metric.getStartTime());
-      }
-    } else {
-      allMetrics.add(metric.getTimelineMetric());
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/071c175a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/timeline/UnableToConnectException.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/timeline/UnableToConnectException.java b/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/timeline/UnableToConnectException.java
deleted file mode 100644
index 797924f..0000000
--- a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/timeline/UnableToConnectException.java
+++ /dev/null
@@ -1,46 +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.hadoop.metrics2.sink.timeline;
-
-public class UnableToConnectException extends RuntimeException {
-
-  private static final long serialVersionUID = 1L;
-
-  private String connectUrl;
-
-  public UnableToConnectException(String message, Throwable cause) {
-    super(message, cause);
-  }
-
-  public UnableToConnectException(String message) {
-    super(message);
-  }
-
-  public UnableToConnectException(Throwable cause) {
-    super(cause);
-  }
-
-  public UnableToConnectException setConnectUrl(String connectUrl) {
-    this.connectUrl = connectUrl;
-    return this;
-  }
-
-  public String getConnectUrl() {
-    return connectUrl;
-  }
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/071c175a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/timeline/cache/TimelineMetricsCache.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/timeline/cache/TimelineMetricsCache.java b/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/timeline/cache/TimelineMetricsCache.java
deleted file mode 100644
index a331c77..0000000
--- a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/timeline/cache/TimelineMetricsCache.java
+++ /dev/null
@@ -1,175 +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.hadoop.metrics2.sink.timeline.cache;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.metrics2.sink.timeline.TimelineMetric;
-
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.TreeMap;
-
-public class TimelineMetricsCache {
-
-  private final TimelineMetricHolder timelineMetricCache = new TimelineMetricHolder();
-  private static final Log LOG = LogFactory.getLog(TimelineMetric.class);
-  public static final int MAX_RECS_PER_NAME_DEFAULT = 10000;
-  public static final int MAX_EVICTION_TIME_MILLIS = 59000; // ~ 1 min
-  private final int maxRecsPerName;
-  private final int maxEvictionTimeInMillis;
-  private final Map<String, Double> counterMetricLastValue = new HashMap<String, Double>();
-
-  public TimelineMetricsCache(int maxRecsPerName, int maxEvictionTimeInMillis) {
-    this.maxRecsPerName = maxRecsPerName;
-    this.maxEvictionTimeInMillis = maxEvictionTimeInMillis;
-  }
-
-  class TimelineMetricWrapper {
-    private long timeDiff = -1;
-    private long oldestTimestamp = -1;
-    private TimelineMetric timelineMetric;
-
-    TimelineMetricWrapper(TimelineMetric timelineMetric) {
-      this.timelineMetric = timelineMetric;
-      this.oldestTimestamp = timelineMetric.getStartTime();
-    }
-
-    private void updateTimeDiff(long timestamp) {
-      if (oldestTimestamp != -1 && timestamp > oldestTimestamp) {
-        timeDiff = timestamp - oldestTimestamp;
-      } else {
-        oldestTimestamp = timestamp;
-      }
-    }
-
-    public void putMetric(TimelineMetric metric) {
-      this.timelineMetric.addMetricValues(metric.getMetricValues());
-      updateTimeDiff(metric.getStartTime());
-    }
-
-    public long getTimeDiff() {
-      return timeDiff;
-    }
-
-    public TimelineMetric getTimelineMetric() {
-      return timelineMetric;
-    }
-  }
-
-  // TODO: Change to ConcurentHashMap with weighted eviction
-  class TimelineMetricHolder extends LinkedHashMap<String, TimelineMetricWrapper> {//
-    private static final long serialVersionUID = 1L;
-    private boolean gotOverflow = false;
-    // To avoid duplication at the end of the buffer and beginning of the next
-    // segment of values
-    private Map<String, Long> endOfBufferTimestamps = new HashMap<String, Long>();
-
-    @Override
-    protected boolean removeEldestEntry(Map.Entry<String, TimelineMetricWrapper> eldest) {
-      boolean overflow = size() > maxRecsPerName;
-      if (overflow && !gotOverflow) {
-        LOG.warn("Metrics cache overflow at "+ size() +" for "+ eldest);
-        gotOverflow = true;
-      }
-      return overflow;
-    }
-
-    public TimelineMetric evict(String metricName) {
-      TimelineMetricWrapper metricWrapper = this.get(metricName);
-
-      if (metricWrapper == null
-        || metricWrapper.getTimeDiff() < getMaxEvictionTimeInMillis()) {
-        return null;
-      }
-
-      TimelineMetric timelineMetric = metricWrapper.getTimelineMetric();
-      this.remove(metricName);
-
-      return timelineMetric;
-    }
-
-    public void put(String metricName, TimelineMetric timelineMetric) {
-      if (isDuplicate(timelineMetric)) {
-        return;
-      }
-      TimelineMetricWrapper metric = this.get(metricName);
-      if (metric == null) {
-        this.put(metricName, new TimelineMetricWrapper(timelineMetric));
-      } else {
-        metric.putMetric(timelineMetric);
-      }
-      // Buffer last ts value
-      endOfBufferTimestamps.put(metricName, timelineMetric.getStartTime());
-    }
-
-    /**
-     * Test whether last buffered timestamp is same as the newly received.
-     * @param timelineMetric @TimelineMetric
-     * @return true/false
-     */
-    private boolean isDuplicate(TimelineMetric timelineMetric) {
-      return endOfBufferTimestamps.containsKey(timelineMetric.getMetricName())
-        && endOfBufferTimestamps.get(timelineMetric.getMetricName()).equals(timelineMetric.getStartTime());
-    }
-  }
-
-  public TimelineMetric getTimelineMetric(String metricName) {
-    if (timelineMetricCache.containsKey(metricName)) {
-      return timelineMetricCache.evict(metricName);
-    }
-
-    return null;
-  }
-
-  /**
-   * Getter method to help testing eviction
-   * @return @int
-   */
-  public int getMaxEvictionTimeInMillis() {
-    return maxEvictionTimeInMillis;
-  }
-
-  public void putTimelineMetric(TimelineMetric timelineMetric) {
-    timelineMetricCache.put(timelineMetric.getMetricName(), timelineMetric);
-  }
-
-  private void transformMetricValuesToDerivative(TimelineMetric timelineMetric) {
-    String metricName = timelineMetric.getMetricName();
-    double firstValue = timelineMetric.getMetricValues().size() > 0
-        ? timelineMetric.getMetricValues().entrySet().iterator().next().getValue() : 0;
-    Double value = counterMetricLastValue.get(metricName);
-    double previousValue = value != null ? value : firstValue;
-    Map<Long, Double> metricValues = timelineMetric.getMetricValues();
-    TreeMap<Long, Double>   newMetricValues = new TreeMap<Long, Double>();
-    for (Map.Entry<Long, Double> entry : metricValues.entrySet()) {
-      newMetricValues.put(entry.getKey(), entry.getValue() - previousValue);
-      previousValue = entry.getValue();
-    }
-    timelineMetric.setMetricValues(newMetricValues);
-    counterMetricLastValue.put(metricName, previousValue);
-  }
-
-  public void putTimelineMetric(TimelineMetric timelineMetric, boolean isCounter) {
-    if (isCounter) {
-      transformMetricValuesToDerivative(timelineMetric);
-    }
-    putTimelineMetric(timelineMetric);
-  }
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/071c175a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/timeline/configuration/Configuration.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/timeline/configuration/Configuration.java b/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/timeline/configuration/Configuration.java
deleted file mode 100644
index a0380e1..0000000
--- a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/timeline/configuration/Configuration.java
+++ /dev/null
@@ -1,62 +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.hadoop.metrics2.sink.timeline.configuration;
-
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Properties;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-public class Configuration {
-  public final Log LOG = LogFactory.getLog(this.getClass());
-  private final Properties properties;
-
-  public Configuration(String configFile) {
-    properties = new Properties();
-
-    //Get property file stream from classpath
-    InputStream inputStream = Configuration.class.getResourceAsStream(configFile);
-
-    if (inputStream == null) {
-      throw new IllegalArgumentException(configFile + " not found in classpath");
-    }
-
-    // load the properties
-    try {
-      properties.load(inputStream);
-      inputStream.close();
-    } catch (FileNotFoundException fnf) {
-      LOG.info("No configuration file " + configFile + " found in classpath.", fnf);
-    } catch (IOException ie) {
-      throw new IllegalArgumentException("Can't read configuration file " +
-          configFile, ie);
-    }
-  }
-
-  public String getProperty(String key) {
-    return properties.getProperty(key);
-  }
-
-  public String getProperty(String key, String defaultValue) {
-    return properties.getProperty(key, defaultValue);
-  }
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/071c175a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/util/Servers.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/util/Servers.java b/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/util/Servers.java
deleted file mode 100644
index b3dc46f..0000000
--- a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/hadoop/metrics2/sink/util/Servers.java
+++ /dev/null
@@ -1,106 +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.hadoop.metrics2.sink.util;
-
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.URI;
-import java.net.UnknownHostException;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Helpers to handle server addresses
- */
-public class Servers {
-  /**
-   * This class is not intended to be instantiated
-   */
-  private Servers() {}
-
-  /**
-   * Parses a space and/or comma separated sequence of server specifications
-   * of the form <i>hostname</i> or <i>hostname:port</i>.  If
-   * the specs string is null, defaults to localhost:defaultPort.
-   *
-   * @param specs   server specs (see description)
-   * @param defaultPort the default port if not specified
-   * @return a list of InetSocketAddress objects.
-   */
-  public static List<InetSocketAddress> parse(String specs, int defaultPort) {
-    List<InetSocketAddress> result = new ArrayList<InetSocketAddress>();
-    if (specs == null) {
-      result.add(new InetSocketAddress("localhost", defaultPort));
-    } else {
-      String[] specStrings = specs.split("[ ,]+");
-      for (String specString : specStrings) {
-        result.add(createSocketAddr(specString, defaultPort));
-      }
-    }
-    return result;
-  }
-
-  /**
-   * @param host
-   * @param port
-   * @return a InetSocketAddress created with the specified host and port
-   */
-  private static InetSocketAddress createSocketAddr(String target, int defaultPort) {
-    String helpText = "";
-    if (target == null) {
-      throw new IllegalArgumentException("Target address cannot be null." + helpText);
-    }
-    boolean hasScheme = target.contains("://");
-    URI uri = null;
-    try {
-      uri = hasScheme ? URI.create(target) : URI.create("dummyscheme://" + target);
-    } catch (IllegalArgumentException e) {
-      throw new IllegalArgumentException("Does not contain a valid host:port authority: " + target + helpText);
-    }
-
-    String host = uri.getHost();
-    int port = uri.getPort();
-    if (port == -1) {
-      port = defaultPort;
-    }
-    String path = uri.getPath();
-
-    if ((host == null) || (port < 0) || (!hasScheme && path != null && !path.isEmpty())) {
-      throw new IllegalArgumentException("Does not contain a valid host:port authority: " + target + helpText);
-    }
-    return createSocketAddrForHost(host, port);
-  }
-
-  /**
-   * @param host
-   * @param port
-   * @return a InetSocketAddress created with the specified host and port
-   */
-  private static InetSocketAddress createSocketAddrForHost(String host, int port) {
-    InetSocketAddress addr;
-    try {
-      InetAddress iaddr = InetAddress.getByName(host);
-      iaddr = InetAddress.getByAddress(host, iaddr.getAddress());
-      addr = new InetSocketAddress(iaddr, port);
-    } catch (UnknownHostException e) {
-      addr = InetSocketAddress.createUnresolved(host, port);
-    }
-    return addr;
-  }
-
-}