Browse Source

AMBARI-9764. Remove duplicated TimelineMetric datastructures from ambari-server. (mpapyrkovskyy)

Myroslav Papirkovskyy 10 năm trước cách đây
mục cha
commit
da8c9879c1

+ 1 - 0
ambari-metrics/ambari-metrics-assembly/pom.xml

@@ -27,6 +27,7 @@
   </parent>
   <modelVersion>4.0.0</modelVersion>
   <artifactId>ambari-metrics-assembly</artifactId>
+  <name>Ambari Metrics Assembly</name>
   <packaging>pom</packaging>
   <version>2.0.0-SNAPSHOT</version>
 

+ 22 - 0
ambari-metrics/ambari-metrics-common/pom.xml

@@ -25,12 +25,34 @@
   </parent>
   <modelVersion>4.0.0</modelVersion>
   <artifactId>ambari-metrics-common</artifactId>
+  <name>Ambari Metrics Common</name>
   <build>
     <plugins>
       <plugin>
         <artifactId>maven-compiler-plugin</artifactId>
         <version>3.0</version>
       </plugin>
+      <plugin>
+        <groupId>org.vafer</groupId>
+        <artifactId>jdeb</artifactId>
+        <version>1.0.1</version>
+        <executions>
+          <execution>
+            <!--Stub execution on direct plugin call - workaround for ambari deb build process-->
+            <id>stub-execution</id>
+            <phase>none</phase>
+            <goals>
+              <goal>jdeb</goal>
+            </goals>
+          </execution>
+        </executions>
+        <configuration>
+          <skip>true</skip>
+          <attach>false</attach>
+          <submodules>false</submodules>
+          <controlDir>${project.basedir}/../src/main/package/deb/control</controlDir>
+        </configuration>
+      </plugin>
     </plugins>
   </build>
 

+ 1 - 0
ambari-metrics/ambari-metrics-flume-sink/pom.xml

@@ -27,6 +27,7 @@ limitations under the License.
   <modelVersion>4.0.0</modelVersion>
   <artifactId>ambari-metrics-flume-sink</artifactId>
   <version>2.0.0-SNAPSHOT</version>
+  <name>Ambari Metrics Flume Sink</name>
   <packaging>jar</packaging>
   <build>
     <plugins>

+ 1 - 0
ambari-metrics/ambari-metrics-hadoop-sink/pom.xml

@@ -27,6 +27,7 @@ limitations under the License.
   <modelVersion>4.0.0</modelVersion>
   <artifactId>ambari-metrics-hadoop-sink</artifactId>
   <version>2.0.0-SNAPSHOT</version>
+  <name>Ambari Metrics Hadoop Sink</name>
   <packaging>jar</packaging>
   <properties>
     <sinkJarName>${project.artifactId}-with-common-${project.version}.jar</sinkJarName>

+ 1 - 0
ambari-metrics/ambari-metrics-host-monitoring/pom.xml

@@ -28,6 +28,7 @@
   <packaging>pom</packaging>
   <version>2.0.0-SNAPSHOT</version>
   <artifactId>ambari-metrics-host-monitoring</artifactId>
+  <name>Ambari Metrics Monitor</name>
   <properties>
     <resmonitor.install.dir>
       /usr/lib/python2.6/site-packages/resource_monitoring

+ 1 - 0
ambari-metrics/ambari-metrics-kafka-sink/pom.xml

@@ -27,6 +27,7 @@ limitations under the License.
   <modelVersion>4.0.0</modelVersion>
   <artifactId>ambari-metrics-kafka-sink</artifactId>
   <version>2.0.0-SNAPSHOT</version>
+  <name>Ambari Metrics Kafka Sink</name>
   <packaging>jar</packaging>
   <build>
     <plugins>

+ 1 - 0
ambari-metrics/ambari-metrics-storm-sink/pom.xml

@@ -27,6 +27,7 @@ limitations under the License.
   <modelVersion>4.0.0</modelVersion>
   <artifactId>ambari-metrics-storm-sink</artifactId>
   <version>2.0.0-SNAPSHOT</version>
+  <name>Ambari Metrics Storm Sink</name>
   <packaging>jar</packaging>
 
   <properties>

+ 1 - 1
ambari-metrics/ambari-metrics-timelineservice/pom.xml

@@ -27,7 +27,7 @@
   <modelVersion>4.0.0</modelVersion>
   <artifactId>ambari-metrics-timelineservice</artifactId>
   <version>2.0.0-SNAPSHOT</version>
-  <name>ambari-metrics-timelineservice</name>
+  <name>Ambari Metrics Collector</name>
   <packaging>jar</packaging>
 
   <properties>

+ 45 - 0
ambari-metrics/pom.xml

@@ -164,6 +164,51 @@
           </execution>
         </executions>
       </plugin>
+      <plugin>
+        <!--Stub execution on direct plugin call - workaround for ambari rpm build process-->
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>rpm-maven-plugin</artifactId>
+        <version>2.0.1</version>
+        <executions>
+          <execution>
+            <id>stub-execution</id>
+            <!-- unbinds rpm creation from maven lifecycle -->
+            <phase>none</phase>
+            <goals>
+              <goal>attached-rpm</goal>
+            </goals>
+          </execution>
+        </executions>
+        <configuration>
+          <copyright>2012, Apache Software Foundation</copyright>
+          <group>Development</group>
+          <description>Maven Recipe: RPM Package.</description>
+          <release>${package-release}</release>
+          <version>${package-version}</version>
+          <mappings/>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.vafer</groupId>
+        <artifactId>jdeb</artifactId>
+        <version>1.0.1</version>
+        <executions>
+          <execution>
+            <!--Stub execution on direct plugin call - workaround for ambari deb build process-->
+            <id>stub-execution</id>
+            <phase>none</phase>
+            <goals>
+              <goal>jdeb</goal>
+            </goals>
+          </execution>
+        </executions>
+        <configuration>
+          <skip>true</skip>
+          <attach>false</attach>
+          <submodules>true</submodules>
+          <controlDir>${project.basedir}/src/main/package/deb/control</controlDir>
+        </configuration>
+      </plugin>
     </plugins>
   </build>
 

+ 21 - 0
ambari-metrics/src/main/package/deb/control/control

@@ -0,0 +1,21 @@
+# 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: [[artifactId]]
+Version: [[package-version]]-[[package-release]]
+Section: [[deb.section]]
+Priority: [[deb.priority]]
+Architecture: [[deb.architecture]]
+Description: [[description]]
+Maintainer: [[deb.publisher]]

+ 15 - 0
ambari-metrics/src/main/package/deb/control/postinst

@@ -0,0 +1,15 @@
+#!/bin/bash
+# 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

+ 15 - 0
ambari-metrics/src/main/package/deb/control/postrm

@@ -0,0 +1,15 @@
+#!/bin/bash
+# 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

+ 15 - 0
ambari-metrics/src/main/package/deb/control/posttrm

@@ -0,0 +1,15 @@
+#!/bin/bash
+# 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

+ 15 - 0
ambari-metrics/src/main/package/deb/control/preinst

@@ -0,0 +1,15 @@
+#!/bin/bash
+# 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

+ 15 - 0
ambari-metrics/src/main/package/deb/control/prerm

@@ -0,0 +1,15 @@
+#!/bin/bash
+# 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

+ 5 - 0
ambari-server/pom.xml

@@ -1761,6 +1761,11 @@
       <artifactId>snmp4j</artifactId>
       <version>1.10.1</version>
     </dependency>
+    <dependency>
+      <groupId>org.apache.ambari</groupId>
+      <artifactId>ambari-metrics-common</artifactId>
+      <version>${project.version}</version>
+    </dependency>
   </dependencies>
 
   <pluginRepositories>

+ 0 - 184
ambari-server/src/main/java/org/apache/hadoop/metrics2/sink/timeline/TimelineMetric.java

@@ -1,184 +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 javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-import java.text.DecimalFormat;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-
-@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 Map<Long, Double> metricValues = new TreeMap<Long, Double>();
-
-  @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 Map<Long, Double> getMetricValues() {
-    return metricValues;
-  }
-
-  public void setMetricValues(Map<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.equals(metric.appId)) 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.equals(metric.appId)) 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.hashCode();
-    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);
-    }
-  }
-
-  @Override
-  public String toString() {
-    return "TimelineMetric{" +
-      "metricName='" + metricName + '\'' +
-      ", appId='" + appId + '\'' +
-      ", instanceId='" + instanceId + '\'' +
-      ", hostName='" + hostName + '\'' +
-      ", timestamp=" + timestamp +
-      ", startTime=" + startTime +
-      ", type='" + type + '\'' +
-      ", metricValues=" + metricValues +
-      '}';
-  }
-}

+ 0 - 103
ambari-server/src/main/java/org/apache/hadoop/metrics2/sink/timeline/TimelineMetrics.java

@@ -1,103 +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 javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * 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;
-  }
-
-  @Override
-  public String toString() {
-    return "TimelineMetrics{" +
-      "allMetrics=" + allMetrics +
-      '}';
-  }
-
-  /**
-   * 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);
-    }
-  }
-}

+ 5 - 0
pom.xml

@@ -345,6 +345,7 @@
 
             <!-- Metrics module -->
             <!-- psutil : external lib, Apache 2.0 license included as a source file -->
+            <exclude>ambari-metrics/target/**</exclude>
             <exclude>ambari-metrics/ambari-metrics-host-monitoring/src/main/python/psutil/**</exclude>
             <exclude>ambari-metrics/target/rpm/ambari-metrics/SPECS/ambari-metrics.spec</exclude>
             <exclude>ambari-metrics/ambari-metrics-timelineservice/src/test/resources/lib/org/apache/phoenix/phoenix-core-tests/4.2.0/phoenix-core-tests-4.2.0.pom</exclude>
@@ -417,6 +418,7 @@
         <module>ambari-agent</module>
         <module>ambari-client</module>
         <module>ambari-shell</module>
+        <module>ambari-metrics/ambari-metrics-common</module>
       </modules>
     </profile>
     <profile>
@@ -429,6 +431,7 @@
         <module>ambari-agent</module>
         <module>ambari-client</module>
         <module>ambari-shell</module>
+        <module>ambari-metrics/ambari-metrics-common</module>
       </modules>
     </profile>
     <profile>
@@ -447,6 +450,7 @@
         <module>ambari-agent</module>
         <module>ambari-client</module>
         <module>ambari-shell</module>
+        <module>ambari-metrics/ambari-metrics-common</module>
       </modules>
     </profile>
     <profile>
@@ -472,6 +476,7 @@
         <module>ambari-agent</module>
         <module>ambari-client</module>
         <module>ambari-shell</module>
+        <module>ambari-metrics/ambari-metrics-common</module>
       </modules>
     </profile>
     <profile>