TEZ-2936. Create ATS implementation that enables support for YARN-4265 (ATSv1.5)...
authorHitesh Shah <hitesh@apache.org>
Mon, 14 Mar 2016 23:36:43 +0000 (16:36 -0700)
committerHitesh Shah <hitesh@apache.org>
Mon, 14 Mar 2016 23:36:43 +0000 (16:36 -0700)
26 files changed:
BUILDING.txt
CHANGES.txt
pom.xml
tez-api/src/main/java/org/apache/tez/client/TezClient.java
tez-api/src/main/java/org/apache/tez/dag/api/TezConfiguration.java
tez-common/src/main/java/org/apache/tez/dag/history/logging/EntityTypes.java [moved from tez-dag/src/main/java/org/apache/tez/dag/history/logging/EntityTypes.java with 100% similarity]
tez-dist/pom.xml
tez-plugins/pom.xml
tez-plugins/tez-yarn-timeline-cache-plugin/findbugs-exclude.xml [new file with mode: 0644]
tez-plugins/tez-yarn-timeline-cache-plugin/pom.xml [new file with mode: 0644]
tez-plugins/tez-yarn-timeline-cache-plugin/src/main/java/org/apache/tez/dag/history/logging/ats/TimelineCachePluginImpl.java [new file with mode: 0644]
tez-plugins/tez-yarn-timeline-cache-plugin/src/main/javadoc/resources/META-INF/LICENSE.txt [new file with mode: 0644]
tez-plugins/tez-yarn-timeline-cache-plugin/src/main/javadoc/resources/META-INF/NOTICE.txt [new file with mode: 0644]
tez-plugins/tez-yarn-timeline-cache-plugin/src/main/resources/META-INF/LICENSE.txt [new file with mode: 0644]
tez-plugins/tez-yarn-timeline-cache-plugin/src/main/resources/META-INF/NOTICE.txt [new file with mode: 0644]
tez-plugins/tez-yarn-timeline-cache-plugin/src/test/java/org/apache/tez/dag/history/logging/ats/TestTimelineCachePluginImpl.java [new file with mode: 0644]
tez-plugins/tez-yarn-timeline-history-with-fs/findbugs-exclude.xml [new file with mode: 0644]
tez-plugins/tez-yarn-timeline-history-with-fs/pom.xml [new file with mode: 0644]
tez-plugins/tez-yarn-timeline-history-with-fs/src/main/java/org/apache/tez/dag/history/ats/acls/ATSV15HistoryACLPolicyManager.java [new file with mode: 0644]
tez-plugins/tez-yarn-timeline-history-with-fs/src/main/java/org/apache/tez/dag/history/logging/ats/ATSV15HistoryLoggingService.java [new file with mode: 0644]
tez-plugins/tez-yarn-timeline-history-with-fs/src/main/javadoc/resources/META-INF/LICENSE.txt [new file with mode: 0644]
tez-plugins/tez-yarn-timeline-history-with-fs/src/main/javadoc/resources/META-INF/NOTICE.txt [new file with mode: 0644]
tez-plugins/tez-yarn-timeline-history-with-fs/src/main/resources/META-INF/LICENSE.txt [new file with mode: 0644]
tez-plugins/tez-yarn-timeline-history-with-fs/src/main/resources/META-INF/NOTICE.txt [new file with mode: 0644]
tez-plugins/tez-yarn-timeline-history-with-fs/src/test/java/org/apache/tez/dag/history/ats/acls/TestATSHistoryV15.java [new file with mode: 0644]
tez-tools/analyzers/pom.xml

index 241b7a8..c251b4a 100644 (file)
@@ -74,9 +74,13 @@ To skip Tests and java docs
 
  $ mvn package -Dhadoop.version=3.0.0-SNAPSHOT -DskipTests -Dmaven.javadoc.skip=true
 
-However, to build against hadoop versions lower than 2.6.0, you will need to do the
+However, to build against hadoop versions lower or higher than 2.6.0, you will need to do the
 following:
 
+For Hadoop version X where X >= 2.8.0
+
+ $ mvn package  -Dhadoop.version=${X} -Phadoop28 -P\!hadoop26
+
 For Hadoop version X where 2.4.0 <= X < 2.6.0
 
  $ mvn package  -Dhadoop.version=${X} -Phadoop24 -P\!hadoop26
index 2c87be5..c45ce37 100644 (file)
@@ -7,6 +7,7 @@ INCOMPATIBLE CHANGES
   TEZ-3029. Add an onError method to service plugin contexts.
 
 ALL CHANGES:
+  TEZ-2936. Create ATS implementation that enables support for YARN-4265 (ATS v1.5)
   TEZ-3148. Invalid event TA_TEZ_EVENT_UPDATE on TaskAttempt.
   TEZ-3105. TezMxBeanResourceCalculator does not work on IBM JDK 7 or 8 causing Tez failures.
   TEZ-3155. Support a way to submit DAGs to a session where the DAG plan exceeds hadoop ipc limits.
diff --git a/pom.xml b/pom.xml
index 26abc24..2b6e1d4 100644 (file)
--- a/pom.xml
+++ b/pom.xml
       </dependency>
       <dependency>
         <groupId>org.apache.hadoop</groupId>
+        <artifactId>hadoop-yarn-server-timeline-pluginstorage</artifactId>
+        <version>${hadoop.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.hadoop</groupId>
         <artifactId>hadoop-yarn-server-tests</artifactId>
         <version>${hadoop.version}</version>
         <type>test-jar</type>
index a6a256c..bded5a2 100644 (file)
@@ -144,6 +144,10 @@ public class TezClient {
       "org.apache.tez.dag.history.logging.ats.ATSHistoryLoggingService";
   private static final String atsHistoryACLManagerClassName =
       "org.apache.tez.dag.history.ats.acls.ATSHistoryACLPolicyManager";
+  private static final String atsv15HistoryLoggingServiceClassName =
+      "org.apache.tez.dag.history.logging.ats.ATSV15HistoryLoggingService";
+  private static final String atsV15HistoryACLManagerClassName =
+      "org.apache.tez.dag.history.ats.acls.ATSV15HistoryACLPolicyManager";
 
   private TezClient(String name, TezConfiguration tezConf) {
     this(name, tezConf, tezConf.getBoolean(
@@ -364,23 +368,35 @@ public class TezClient {
 
     ///need additional check for historyACLPolicyManager because tests could stub historyACLPolicyManager
     ///before tezclient start. If there is already a stubbed historyACLPolicyManager, we don't overwrite it
-    if (this.amConfig.getTezConfiguration().get(
-        TezConfiguration.TEZ_HISTORY_LOGGING_SERVICE_CLASS, "")
-        .equals(atsHistoryLoggingServiceClassName) && (historyACLPolicyManager == null)) {
-      LOG.info("Using " + atsHistoryACLManagerClassName + " to manage Timeline ACLs");
-      try {
-        historyACLPolicyManager = ReflectionUtils.createClazzInstance(
-            atsHistoryACLManagerClassName);
-        historyACLPolicyManager.setConf(this.amConfig.getYarnConfiguration());
-      } catch (TezReflectionException e) {
-        if (!amConfig.getTezConfiguration().getBoolean(
-            TezConfiguration.TEZ_AM_ALLOW_DISABLED_TIMELINE_DOMAINS,
-            TezConfiguration.TEZ_AM_ALLOW_DISABLED_TIMELINE_DOMAINS_DEFAULT)) {
-          LOG.warn("Could not instantiate object for " + atsHistoryACLManagerClassName
-                    + ". ACLs cannot be enforced correctly for history data in Timeline", e);
-          throw e;
+    if (historyACLPolicyManager == null) {
+      //TODO: FIXME: The ACL manager should be retrieved either from the
+      //logging service directly or via a pluggable factory that can
+      //instantiate ACL managers and logging services
+      String logSvcClassName = amConfig.getTezConfiguration().get(
+          TezConfiguration.TEZ_HISTORY_LOGGING_SERVICE_CLASS, "");
+      String aclMgrClassName = null;
+      if (logSvcClassName.equals(atsHistoryLoggingServiceClassName)) {
+        aclMgrClassName = atsHistoryACLManagerClassName;
+      } else if (logSvcClassName.equals(
+        atsv15HistoryLoggingServiceClassName)) {
+        aclMgrClassName = atsV15HistoryACLManagerClassName;
+      }
+      if (aclMgrClassName != null) {
+        LOG.info("Using " + aclMgrClassName + " to manage Timeline ACLs");
+        try {
+          historyACLPolicyManager = ReflectionUtils.createClazzInstance(
+              aclMgrClassName);
+          historyACLPolicyManager.setConf(this.amConfig.getYarnConfiguration());
+        } catch (TezReflectionException e) {
+          if (!amConfig.getTezConfiguration().getBoolean(
+              TezConfiguration.TEZ_AM_ALLOW_DISABLED_TIMELINE_DOMAINS,
+              TezConfiguration.TEZ_AM_ALLOW_DISABLED_TIMELINE_DOMAINS_DEFAULT)) {
+            LOG.warn("Could not instantiate object for " + aclMgrClassName
+                + ". ACLs cannot be enforced correctly for history data in Timeline", e);
+            throw e;
+          }
+          historyACLPolicyManager = null;
         }
-        historyACLPolicyManager = null;
       }
     }
 
@@ -500,7 +516,8 @@ public class TezClient {
 
     TezConfiguration dagClientConf = new TezConfiguration(amConfig.getTezConfiguration());
     Map<String, String> aclConfigs = null;
-    // TEZ_AM_HISTORY_LOGGING_ENABLED is a config setting enable/disable logging of all dags within a session
+    // TEZ_AM_HISTORY_LOGGING_ENABLED is a config setting enable/disable logging of all
+    // dags within a session
     boolean sessionHistoryLoggingEnabled = amConfig.getTezConfiguration().getBoolean(
         TezConfiguration.TEZ_AM_HISTORY_LOGGING_ENABLED,
         TezConfiguration.TEZ_AM_HISTORY_LOGGING_ENABLED_DEFAULT);
index 0221e6b..4fc8322 100644 (file)
@@ -1545,4 +1545,15 @@ public class TezConfiguration extends Configuration {
       TEZ_PREFIX + "test.recovery-service-class";
   @Private
   public static final String TEZ_AM_RECOVERY_SERVICE_CLASS_DEFAULT = "org.apache.tez.dag.history.recovery.RecoveryService";
+
+  /**
+   * Boolean value. Default false.
+   * By default, configured values for the Summary Entity Types for Timeline will
+   * not be respected and be overridden by the Timeline History Service.
+   */
+  @Private
+  @ConfigurationScope(Scope.AM)
+  public static final String TEZ_AM_ATS_V15_OVERRIDE_SUMMARY_TYPES =
+      TEZ_PREFIX + "am.ats.v15.override.summary-types";
+  public static final boolean TEZ_AM_ATS_V15_OVERRIDE_SUMMARY_TYPES_DEFAULT = true;
 }
index 9ff4416..3201d4f 100644 (file)
           <artifactId>tez-yarn-timeline-history-with-acls</artifactId>
           <version>${project.version}</version>
         </dependency>
-        <!--
         <dependency>
           <groupId>org.apache.tez</groupId>
           <artifactId>tez-yarn-timeline-history-with-fs</artifactId>
           <groupId>org.apache.tez</groupId>
           <artifactId>tez-yarn-timeline-cache-plugin</artifactId>
           <version>${project.version}</version>
-        </dependency> -->
+        </dependency>
         <dependency>
           <groupId>org.apache.tez</groupId>
           <artifactId>hadoop-shim-2.8</artifactId>
index 6d1c88a..06a7f61 100644 (file)
         <module>tez-history-parser</module>
       </modules>
     </profile>
+    <profile>
+      <id>hadoop28</id>
+      <activation>
+        <activeByDefault>false</activeByDefault>
+      </activation>
+      <modules>
+        <module>tez-yarn-timeline-history</module>
+        <module>tez-yarn-timeline-history-with-acls</module>
+        <module>tez-yarn-timeline-cache-plugin</module>
+        <module>tez-yarn-timeline-history-with-fs</module>
+        <module>tez-history-parser</module>
+      </modules>
+    </profile>
+
   </profiles>
 
   <build>
diff --git a/tez-plugins/tez-yarn-timeline-cache-plugin/findbugs-exclude.xml b/tez-plugins/tez-yarn-timeline-cache-plugin/findbugs-exclude.xml
new file mode 100644 (file)
index 0000000..5b11308
--- /dev/null
@@ -0,0 +1,16 @@
+<!--
+  Licensed 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. See accompanying LICENSE file.
+-->
+<FindBugsFilter>
+
+</FindBugsFilter>
diff --git a/tez-plugins/tez-yarn-timeline-cache-plugin/pom.xml b/tez-plugins/tez-yarn-timeline-cache-plugin/pom.xml
new file mode 100644 (file)
index 0000000..2948e96
--- /dev/null
@@ -0,0 +1,74 @@
+<!--
+  Licensed 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. See accompanying LICENSE file.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.tez</groupId>
+    <artifactId>tez-plugins</artifactId>
+    <version>0.8.3-SNAPSHOT</version>
+  </parent>
+  <artifactId>tez-yarn-timeline-cache-plugin</artifactId>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.tez</groupId>
+      <artifactId>tez-common</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.hadoop</groupId>
+      <artifactId>hadoop-yarn-server-timeline-pluginstorage</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.rat</groupId>
+        <artifactId>apache-rat-plugin</artifactId>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-assembly-plugin</artifactId>
+        <configuration>
+          <descriptorRefs>
+            <descriptorRef>jar-with-dependencies</descriptorRef>
+          </descriptorRefs>
+          <archive>
+            <manifest>
+              <addClasspath>true</addClasspath>
+            </manifest>
+          </archive>
+        </configuration>
+        <executions>
+          <execution>
+            <id>assemble-all</id>
+            <phase>package</phase>
+            <goals>
+              <goal>single</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/tez-plugins/tez-yarn-timeline-cache-plugin/src/main/java/org/apache/tez/dag/history/logging/ats/TimelineCachePluginImpl.java b/tez-plugins/tez-yarn-timeline-cache-plugin/src/main/java/org/apache/tez/dag/history/logging/ats/TimelineCachePluginImpl.java
new file mode 100644 (file)
index 0000000..d81f56a
--- /dev/null
@@ -0,0 +1,166 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.tez.dag.history.logging.ats;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.SortedSet;
+
+import org.apache.hadoop.yarn.api.records.ApplicationId;
+import org.apache.hadoop.yarn.api.records.ContainerId;
+import org.apache.hadoop.yarn.api.records.timeline.TimelineEntityGroupId;
+import org.apache.hadoop.yarn.server.timeline.NameValuePair;
+import org.apache.hadoop.yarn.server.timeline.TimelineEntityGroupPlugin;
+import org.apache.tez.dag.history.logging.EntityTypes;
+import org.apache.tez.dag.records.TezDAGID;
+import org.apache.tez.dag.records.TezTaskAttemptID;
+import org.apache.tez.dag.records.TezTaskID;
+import org.apache.tez.dag.records.TezVertexID;
+
+import com.google.common.collect.Sets;
+
+public class TimelineCachePluginImpl extends TimelineEntityGroupPlugin {
+
+  private static Set<String> summaryEntityTypes;
+  private static Set<String> knownEntityTypes;
+
+  static {
+    knownEntityTypes = Sets.newHashSet(
+        EntityTypes.TEZ_DAG_ID.name(),
+        EntityTypes.TEZ_VERTEX_ID.name(),
+        EntityTypes.TEZ_TASK_ID.name(),
+        EntityTypes.TEZ_TASK_ATTEMPT_ID.name(),
+        EntityTypes.TEZ_CONTAINER_ID.name());
+    summaryEntityTypes = Sets.newHashSet(
+        EntityTypes.TEZ_DAG_ID.name(),
+        EntityTypes.TEZ_APPLICATION_ATTEMPT.name(),
+        EntityTypes.TEZ_APPLICATION.name());
+  }
+
+  // Empty public constructor
+  public TimelineCachePluginImpl() {
+  }
+
+  private TimelineEntityGroupId convertToTimelineEntityGroupId(String entityType, String entityId) {
+    if (entityType == null || entityType.isEmpty()
+        || entityId == null || entityId.isEmpty()) {
+      return null;
+    }
+    if (entityType.equals(EntityTypes.TEZ_DAG_ID.name())) {
+      TezDAGID dagId = TezDAGID.fromString(entityId);
+      if (dagId != null) {
+        return TimelineEntityGroupId.newInstance(dagId.getApplicationId(), dagId.toString());
+      }
+    } else if (entityType.equals(EntityTypes.TEZ_VERTEX_ID.name())) {
+      TezVertexID vertexID = TezVertexID.fromString(entityId);
+      if (vertexID != null) {
+        return TimelineEntityGroupId.newInstance(vertexID.getDAGId().getApplicationId(),
+            vertexID.getDAGId().toString());
+      }
+
+    } else if (entityType.equals(EntityTypes.TEZ_TASK_ID.name())) {
+      TezTaskID taskID = TezTaskID.fromString(entityId);
+      if (taskID != null) {
+        return TimelineEntityGroupId.newInstance(taskID.getVertexID().getDAGId().getApplicationId(),
+            taskID.getVertexID().getDAGId().toString());
+      }
+    } else if (entityType.equals(EntityTypes.TEZ_TASK_ATTEMPT_ID.name())) {
+      TezTaskAttemptID taskAttemptID = TezTaskAttemptID.fromString(entityId);
+      if (taskAttemptID != null) {
+        return TimelineEntityGroupId.newInstance(
+            taskAttemptID.getTaskID().getVertexID().getDAGId().getApplicationId(),
+            taskAttemptID.getTaskID().getVertexID().getDAGId().toString());
+      }
+    } else if (entityType.equals(EntityTypes.TEZ_CONTAINER_ID.name())) {
+      String cId = entityId;
+      if (cId.startsWith("tez_")) {
+        cId = cId.substring(4);
+      }
+      ContainerId containerId = ContainerId.fromString(cId);
+      if (containerId != null) {
+        return TimelineEntityGroupId.newInstance(
+            containerId.getApplicationAttemptId().getApplicationId(),
+            containerId.getApplicationAttemptId().getApplicationId().toString());
+      }
+    }
+    return null;
+  }
+
+  @Override
+  public Set<TimelineEntityGroupId> getTimelineEntityGroupId(String entityType,
+      NameValuePair primaryFilter,
+      Collection<NameValuePair> secondaryFilters) {
+    if (!knownEntityTypes.contains(entityType)
+        || primaryFilter == null
+        || !knownEntityTypes.contains(primaryFilter.getName())
+        || summaryEntityTypes.contains(entityType)) {
+      return null;
+    }
+    TimelineEntityGroupId groupId = convertToTimelineEntityGroupId(primaryFilter.getName(),
+        primaryFilter.getValue().toString());
+    if (groupId != null) {
+      TimelineEntityGroupId appGroupId =
+          TimelineEntityGroupId.newInstance(groupId.getApplicationId(),
+              groupId.getApplicationId().toString());
+      return Sets.newHashSet(groupId, appGroupId);
+    }
+    return null;
+  }
+
+  @Override
+  public Set<TimelineEntityGroupId> getTimelineEntityGroupId(String entityId, String entityType) {
+    if (!knownEntityTypes.contains(entityType) || summaryEntityTypes.contains(entityType)) {
+      return null;
+    }
+    TimelineEntityGroupId groupId = convertToTimelineEntityGroupId(entityType, entityId);
+    if (groupId != null) {
+      TimelineEntityGroupId appGroupId =
+          TimelineEntityGroupId.newInstance(groupId.getApplicationId(),
+              groupId.getApplicationId().toString());
+      return Sets.newHashSet(groupId, appGroupId);
+    }
+    return null;
+  }
+
+  @Override
+  public Set<TimelineEntityGroupId> getTimelineEntityGroupId(String entityType,
+      SortedSet<String> entityIds, Set<String> eventTypes) {
+    if (!knownEntityTypes.contains(entityType)
+        || summaryEntityTypes.contains(entityType)
+        || entityIds == null || entityIds.isEmpty()) {
+      return null;
+    }
+    Set<TimelineEntityGroupId> groupIds = new HashSet<TimelineEntityGroupId>();
+    Set<ApplicationId> appIdSet = new HashSet<ApplicationId>();
+
+    for (String entityId : entityIds) {
+      TimelineEntityGroupId groupId = convertToTimelineEntityGroupId(entityType, entityId);
+      if (groupId != null) {
+        groupIds.add(groupId);
+        appIdSet.add(groupId.getApplicationId());
+      }
+    }
+    for (ApplicationId appId : appIdSet) {
+      groupIds.add(TimelineEntityGroupId.newInstance(appId, appId.toString()));
+    }
+    return groupIds;
+  }
+
+}
diff --git a/tez-plugins/tez-yarn-timeline-cache-plugin/src/main/javadoc/resources/META-INF/LICENSE.txt b/tez-plugins/tez-yarn-timeline-cache-plugin/src/main/javadoc/resources/META-INF/LICENSE.txt
new file mode 100644 (file)
index 0000000..d645695
--- /dev/null
@@ -0,0 +1,202 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed 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.
diff --git a/tez-plugins/tez-yarn-timeline-cache-plugin/src/main/javadoc/resources/META-INF/NOTICE.txt b/tez-plugins/tez-yarn-timeline-cache-plugin/src/main/javadoc/resources/META-INF/NOTICE.txt
new file mode 100644 (file)
index 0000000..88ff448
--- /dev/null
@@ -0,0 +1,6 @@
+Apache Tez
+Copyright (c) 2015 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/tez-plugins/tez-yarn-timeline-cache-plugin/src/main/resources/META-INF/LICENSE.txt b/tez-plugins/tez-yarn-timeline-cache-plugin/src/main/resources/META-INF/LICENSE.txt
new file mode 100644 (file)
index 0000000..d645695
--- /dev/null
@@ -0,0 +1,202 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed 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.
diff --git a/tez-plugins/tez-yarn-timeline-cache-plugin/src/main/resources/META-INF/NOTICE.txt b/tez-plugins/tez-yarn-timeline-cache-plugin/src/main/resources/META-INF/NOTICE.txt
new file mode 100644 (file)
index 0000000..88ff448
--- /dev/null
@@ -0,0 +1,6 @@
+Apache Tez
+Copyright (c) 2015 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/tez-plugins/tez-yarn-timeline-cache-plugin/src/test/java/org/apache/tez/dag/history/logging/ats/TestTimelineCachePluginImpl.java b/tez-plugins/tez-yarn-timeline-cache-plugin/src/test/java/org/apache/tez/dag/history/logging/ats/TestTimelineCachePluginImpl.java
new file mode 100644 (file)
index 0000000..562a66e
--- /dev/null
@@ -0,0 +1,260 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.tez.dag.history.logging.ats;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
+import org.apache.hadoop.yarn.api.records.ApplicationId;
+import org.apache.hadoop.yarn.api.records.ContainerId;
+import org.apache.hadoop.yarn.api.records.timeline.TimelineEntityGroupId;
+import org.apache.hadoop.yarn.server.timeline.NameValuePair;
+import org.apache.tez.dag.history.logging.EntityTypes;
+import org.apache.tez.dag.records.TezDAGID;
+import org.apache.tez.dag.records.TezTaskAttemptID;
+import org.apache.tez.dag.records.TezTaskID;
+import org.apache.tez.dag.records.TezVertexID;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.google.common.collect.Sets;
+
+public class TestTimelineCachePluginImpl {
+
+  static ApplicationId appId1;
+  static ApplicationAttemptId appAttemptId1;
+  static ApplicationId appId2;
+  static TezDAGID dagID1;
+  static TezVertexID vertexID1;
+  static TezTaskID taskID1;
+  static TezTaskAttemptID attemptID1;
+  static TezDAGID dagID2;
+  static TezVertexID vertexID2;
+  static TezTaskID taskID2;
+  static TezTaskAttemptID attemptID2;
+  static ContainerId cId1;
+  static ContainerId cId2;
+  static Map<String, String> typeIdMap1;
+  static Map<String, String> typeIdMap2;
+
+  TimelineCachePluginImpl plugin =
+      new TimelineCachePluginImpl();
+
+  @BeforeClass
+  public static void beforeClass() {
+    appId1 = ApplicationId.newInstance(1000l, 111);
+    appId2 = ApplicationId.newInstance(1001l, 121);
+    appAttemptId1 = ApplicationAttemptId.newInstance(appId1, 11);
+
+    dagID1 = TezDAGID.getInstance(appId1, 1);
+    vertexID1 = TezVertexID.getInstance(dagID1, 12);
+    taskID1 = TezTaskID.getInstance(vertexID1, 11144);
+    attemptID1 = TezTaskAttemptID.getInstance(taskID1, 4);
+
+    dagID2 = TezDAGID.getInstance(appId2, 111);
+    vertexID2 = TezVertexID.getInstance(dagID2, 121);
+    taskID2 = TezTaskID.getInstance(vertexID2, 113344);
+    attemptID2 = TezTaskAttemptID.getInstance(taskID2, 14);
+
+    cId1 = ContainerId.newContainerId(appAttemptId1, 1);
+    cId2 = ContainerId.newContainerId(ApplicationAttemptId.newInstance(appId2, 1), 22);
+
+    typeIdMap1 = new HashMap<String, String>();
+    typeIdMap1.put(EntityTypes.TEZ_DAG_ID.name(), dagID1.toString());
+    typeIdMap1.put(EntityTypes.TEZ_VERTEX_ID.name(), vertexID1.toString());
+    typeIdMap1.put(EntityTypes.TEZ_TASK_ID.name(), taskID1.toString());
+    typeIdMap1.put(EntityTypes.TEZ_TASK_ATTEMPT_ID.name(), attemptID1.toString());
+
+    typeIdMap2 = new HashMap<String, String>();
+    typeIdMap2.put(EntityTypes.TEZ_DAG_ID.name(), dagID2.toString());
+    typeIdMap2.put(EntityTypes.TEZ_VERTEX_ID.name(), vertexID2.toString());
+    typeIdMap2.put(EntityTypes.TEZ_TASK_ID.name(), taskID2.toString());
+    typeIdMap2.put(EntityTypes.TEZ_TASK_ATTEMPT_ID.name(), attemptID2.toString());
+
+  }
+
+  @Test
+  public void testGetTimelineEntityGroupIdByPrimaryFilter() {
+    for (Entry<String, String> entry : typeIdMap1.entrySet()) {
+      NameValuePair primaryFilter = new NameValuePair(entry.getKey(), entry.getValue());
+      Assert.assertNull(plugin.getTimelineEntityGroupId(EntityTypes.TEZ_APPLICATION.name(),
+          primaryFilter, null));
+      Set<TimelineEntityGroupId> groupIds = plugin.getTimelineEntityGroupId(entry.getKey(), primaryFilter, null);
+      if (entry.getKey().equals(EntityTypes.TEZ_DAG_ID.name())) {
+        Assert.assertNull(groupIds);
+        continue;
+      }
+      Assert.assertEquals(2, groupIds.size());
+      Iterator<TimelineEntityGroupId> iter = groupIds.iterator();
+      while (iter.hasNext()) {
+        TimelineEntityGroupId groupId = iter.next();
+        Assert.assertEquals(appId1, groupId.getApplicationId());
+        Assert.assertTrue((dagID1.toString().equals(groupId.getTimelineEntityGroupId()))
+            || (appId1.toString().equals(groupId.getTimelineEntityGroupId())));
+      }
+    }
+  }
+
+  @Test
+  public void testGetTimelineEntityGroupIdById() {
+    for (Entry<String, String> entry : typeIdMap1.entrySet()) {
+      Set<TimelineEntityGroupId> groupIds = plugin.getTimelineEntityGroupId(entry.getValue(), entry.getKey());
+      if (entry.getKey().equals(EntityTypes.TEZ_DAG_ID.name())) {
+        Assert.assertNull(groupIds);
+        continue;
+      }
+      Assert.assertEquals(2, groupIds.size());
+      Iterator<TimelineEntityGroupId> iter = groupIds.iterator();
+      while (iter.hasNext()) {
+        TimelineEntityGroupId groupId = iter.next();
+        Assert.assertEquals(appId1, groupId.getApplicationId());
+        Assert.assertTrue((dagID1.toString().equals(groupId.getTimelineEntityGroupId()))
+            || (appId1.toString().equals(groupId.getTimelineEntityGroupId())));
+      }
+    }
+  }
+
+  @Test
+  public void testGetTimelineEntityGroupIdByIds() {
+    for (Entry<String, String> entry : typeIdMap1.entrySet()) {
+      SortedSet<String> entityIds = new TreeSet<String>();
+      entityIds.add(entry.getValue());
+      entityIds.add(typeIdMap2.get(entry.getKey()));
+      Set<TimelineEntityGroupId> groupIds = plugin.getTimelineEntityGroupId(entry.getKey(),
+          entityIds, null);
+      if (entry.getKey().equals(EntityTypes.TEZ_DAG_ID.name())) {
+        Assert.assertNull(groupIds);
+        continue;
+      }
+      Assert.assertEquals(4, groupIds.size());
+      int found = 0;
+      Iterator<TimelineEntityGroupId> iter = groupIds.iterator();
+      while (iter.hasNext()) {
+        TimelineEntityGroupId groupId = iter.next();
+        if (groupId.getApplicationId().equals(appId1)
+            && groupId.getTimelineEntityGroupId().equals(dagID1.toString())) {
+          ++found;
+        } else if (groupId.getApplicationId().equals(appId2)
+            && groupId.getTimelineEntityGroupId().equals(dagID2.toString())) {
+          ++found;
+        } else if (groupId.getApplicationId().equals(appId1)
+            && groupId.getTimelineEntityGroupId().equals(appId1.toString())) {
+          ++found;
+        } else if (groupId.getApplicationId().equals(appId2)
+            && groupId.getTimelineEntityGroupId().equals(appId2.toString())) {
+          ++found;
+        }
+      }
+      Assert.assertEquals("All groupIds not returned", 4, found);
+    }
+  }
+
+  @Test
+  public void testInvalidIds() {
+    Assert.assertNull(plugin.getTimelineEntityGroupId(EntityTypes.TEZ_DAG_ID.name(),
+        vertexID1.toString()));
+    Assert.assertNull(plugin.getTimelineEntityGroupId(EntityTypes.TEZ_VERTEX_ID.name(),
+        taskID1.toString()));
+    Assert.assertNull(plugin.getTimelineEntityGroupId(EntityTypes.TEZ_TASK_ID.name(),
+        attemptID1.toString()));
+    Assert.assertNull(plugin.getTimelineEntityGroupId(EntityTypes.TEZ_TASK_ATTEMPT_ID.name(),
+        dagID1.toString()));
+    Assert.assertNull(plugin.getTimelineEntityGroupId("", ""));
+    Assert.assertNull(plugin.getTimelineEntityGroupId(null, null));
+    Assert.assertNull(plugin.getTimelineEntityGroupId("adadasd", EntityTypes.TEZ_DAG_ID.name()));
+  }
+
+  @Test
+  public void testInvalidTypeRequests() {
+    Assert.assertNull(plugin.getTimelineEntityGroupId(EntityTypes.TEZ_APPLICATION.name(),
+        appId1.toString()));
+    Assert.assertNull(plugin.getTimelineEntityGroupId(EntityTypes.TEZ_APPLICATION_ATTEMPT.name(),
+        appAttemptId1.toString()));
+    Assert.assertNull(plugin.getTimelineEntityGroupId(EntityTypes.TEZ_CONTAINER_ID.name(),
+        appId1.toString()));
+
+    Assert.assertNull(plugin.getTimelineEntityGroupId(EntityTypes.TEZ_TASK_ID.name(), null,
+        new HashSet<String>()));
+    Assert.assertNull(plugin.getTimelineEntityGroupId(EntityTypes.TEZ_TASK_ID.name(), null,
+        new HashSet<NameValuePair>()));
+
+  }
+
+  @Test
+  public void testContainerIdConversion() {
+
+    String entityType = EntityTypes.TEZ_CONTAINER_ID.name();
+    SortedSet<String> entityIds = new TreeSet<String>();
+    entityIds.add("tez_" + cId1.toString());
+    entityIds.add("tez_" + cId2.toString());
+    Set<TimelineEntityGroupId> groupIds = plugin.getTimelineEntityGroupId(entityType,
+        entityIds, null);
+    Assert.assertEquals(2, groupIds.size());
+    int found = 0;
+    Iterator<TimelineEntityGroupId> iter = groupIds.iterator();
+    while (iter.hasNext()) {
+      TimelineEntityGroupId groupId = iter.next();
+      if (groupId.getApplicationId().equals(appId1)
+          && groupId.getTimelineEntityGroupId().equals(appId1.toString())) {
+        ++found;
+      } else if (groupId.getApplicationId().equals(appId2)
+          && groupId.getTimelineEntityGroupId().equals(appId2.toString())) {
+        ++found;
+      }
+    }
+    Assert.assertEquals("All groupIds not returned", 2, found);
+
+    groupIds.clear();
+    groupIds = plugin.getTimelineEntityGroupId(cId1.toString(), entityType);
+    Assert.assertEquals(1, groupIds.size());
+    found = 0;
+    iter = groupIds.iterator();
+    while (iter.hasNext()) {
+      TimelineEntityGroupId groupId = iter.next();
+      if (groupId.getApplicationId().equals(appId1)
+          && groupId.getTimelineEntityGroupId().equals(appId1.toString())) {
+        ++found;
+      }
+    }
+    Assert.assertEquals("All groupIds not returned", 1, found);
+
+    groupIds.clear();
+    groupIds = plugin.getTimelineEntityGroupId("tez_" + cId2.toString(), entityType);
+    Assert.assertEquals(1, groupIds.size());
+    found = 0;
+    iter = groupIds.iterator();
+    while (iter.hasNext()) {
+      TimelineEntityGroupId groupId = iter.next();
+      if (groupId.getApplicationId().equals(appId2)
+          && groupId.getTimelineEntityGroupId().equals(appId2.toString())) {
+        ++found;
+      }
+    }
+    Assert.assertEquals("All groupIds not returned", 1, found);
+
+  }
+}
diff --git a/tez-plugins/tez-yarn-timeline-history-with-fs/findbugs-exclude.xml b/tez-plugins/tez-yarn-timeline-history-with-fs/findbugs-exclude.xml
new file mode 100644 (file)
index 0000000..5b11308
--- /dev/null
@@ -0,0 +1,16 @@
+<!--
+  Licensed 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. See accompanying LICENSE file.
+-->
+<FindBugsFilter>
+
+</FindBugsFilter>
diff --git a/tez-plugins/tez-yarn-timeline-history-with-fs/pom.xml b/tez-plugins/tez-yarn-timeline-history-with-fs/pom.xml
new file mode 100644 (file)
index 0000000..23a7f5d
--- /dev/null
@@ -0,0 +1,149 @@
+<!--
+  Licensed 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. See accompanying LICENSE file.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.tez</groupId>
+    <artifactId>tez-plugins</artifactId>
+    <version>0.8.3-SNAPSHOT</version>
+  </parent>
+  <artifactId>tez-yarn-timeline-history-with-fs</artifactId>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.tez</groupId>
+      <artifactId>tez-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.tez</groupId>
+      <artifactId>tez-common</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.tez</groupId>
+      <artifactId>tez-dag</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.tez</groupId>
+      <artifactId>tez-yarn-timeline-history</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.tez</groupId>
+      <artifactId>tez-yarn-timeline-history</artifactId>
+      <type>test-jar</type>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.tez</groupId>
+      <artifactId>tez-tests</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.tez</groupId>
+      <artifactId>tez-tests</artifactId>
+      <type>test-jar</type>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.hadoop</groupId>
+      <artifactId>hadoop-common</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.hadoop</groupId>
+      <artifactId>hadoop-yarn-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.hadoop</groupId>
+      <artifactId>hadoop-yarn-common</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.hadoop</groupId>
+      <artifactId>hadoop-yarn-client</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.hadoop</groupId>
+      <artifactId>hadoop-yarn-server-tests</artifactId>
+      <scope>test</scope>
+      <type>test-jar</type>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.hadoop</groupId>
+      <artifactId>hadoop-hdfs</artifactId>
+      <scope>test</scope>
+      <type>test-jar</type>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.hadoop</groupId>
+      <artifactId>hadoop-common</artifactId>
+      <scope>test</scope>
+      <type>test-jar</type>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.hadoop</groupId>
+      <artifactId>hadoop-mapreduce-client-core</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.hadoop</groupId>
+      <artifactId>hadoop-mapreduce-client-common</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.hadoop</groupId>
+      <artifactId>hadoop-mapreduce-client-jobclient</artifactId>
+      <scope>test</scope>
+      <type>test-jar</type>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.jettison</groupId>
+      <artifactId>jettison</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>com.google.guava</groupId>
+      <artifactId>guava</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-all</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>com.sun.jersey</groupId>
+      <artifactId>jersey-json</artifactId>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.rat</groupId>
+        <artifactId>apache-rat-plugin</artifactId>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
+
diff --git a/tez-plugins/tez-yarn-timeline-history-with-fs/src/main/java/org/apache/tez/dag/history/ats/acls/ATSV15HistoryACLPolicyManager.java b/tez-plugins/tez-yarn-timeline-history-with-fs/src/main/java/org/apache/tez/dag/history/ats/acls/ATSV15HistoryACLPolicyManager.java
new file mode 100644 (file)
index 0000000..f0ec1eb
--- /dev/null
@@ -0,0 +1,263 @@
+/**
+ * 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.tez.dag.history.ats.acls;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.hadoop.service.Service;
+import org.apache.hadoop.yarn.api.records.ApplicationId;
+import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
+import org.apache.hadoop.yarn.api.records.timeline.TimelineEntityGroupId;
+import org.apache.hadoop.yarn.api.records.timeline.TimelineDomain;
+import org.apache.hadoop.yarn.api.records.timeline.TimelineEntity;
+import org.apache.hadoop.yarn.client.api.TimelineClient;
+import org.apache.tez.common.security.ACLConfigurationParser;
+import org.apache.tez.common.security.ACLManager;
+import org.apache.tez.common.security.ACLType;
+import org.apache.tez.common.security.DAGAccessControls;
+import org.apache.tez.common.security.HistoryACLPolicyManager;
+import org.apache.tez.common.security.HistoryACLPolicyException;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.tez.dag.api.TezConfiguration;
+import org.apache.tez.dag.api.TezUncheckedException;
+
+public class ATSV15HistoryACLPolicyManager implements HistoryACLPolicyManager {
+
+  private final static Logger LOG = LoggerFactory.getLogger(ATSV15HistoryACLPolicyManager.class);
+
+  TimelineClient timelineClient;
+  Configuration conf;
+  String user;
+  final static String DOMAIN_ID_PREFIX = "Tez_ATS_";
+  private static final String atsHistoryLoggingServiceClassName =
+      "org.apache.tez.dag.history.logging.ats.ATSV15HistoryLoggingService";
+
+  private void initializeTimelineClient() {
+    if (this.conf == null) {
+      throw new TezUncheckedException("ATSACLManager not configured");
+    }
+    if (timelineClient != null) {
+      this.timelineClient.stop();
+      this.timelineClient = null;
+    }
+    if (conf.getBoolean(YarnConfiguration.TIMELINE_SERVICE_ENABLED,
+      YarnConfiguration.DEFAULT_TIMELINE_SERVICE_ENABLED)) {
+      this.timelineClient = TimelineClient.createTimelineClient();
+      this.timelineClient.init(this.conf);
+      this.timelineClient.start();
+    } else {
+      this.timelineClient = null;
+      if (conf.get(TezConfiguration.TEZ_HISTORY_LOGGING_SERVICE_CLASS, "")
+         .equals(atsHistoryLoggingServiceClassName)) {
+        LOG.warn(atsHistoryLoggingServiceClassName
+            + " is disabled due to Timeline Service being disabled, "
+            + YarnConfiguration.TIMELINE_SERVICE_ENABLED + " set to false");
+      }
+    }
+    try {
+      this.user = UserGroupInformation.getCurrentUser().getShortUserName();
+    } catch (IOException e) {
+      throw new TezUncheckedException("Unable to get Current User UGI", e);
+    }
+  }
+
+  private String getMergedViewACLs(ACLConfigurationParser parser,
+      DAGAccessControls dagAccessControls) {
+    Map<ACLType, Set<String>> allowedUsers = parser.getAllowedUsers();
+    Map<ACLType, Set<String>> allowedGroups = parser.getAllowedGroups();
+
+    Set<String> viewUsers = new HashSet<String>();
+    viewUsers.add(user);
+    if (allowedUsers.containsKey(ACLType.AM_VIEW_ACL)) {
+      viewUsers.addAll(allowedUsers.get(ACLType.AM_VIEW_ACL));
+    }
+    if (dagAccessControls != null && dagAccessControls.getUsersWithViewACLs() != null) {
+      viewUsers.addAll(dagAccessControls.getUsersWithViewACLs());
+    }
+
+    if (viewUsers.contains(ACLManager.WILDCARD_ACL_VALUE)) {
+      return ACLManager.WILDCARD_ACL_VALUE;
+    }
+
+    Set<String> viewGroups = new HashSet<String>();
+    if (allowedGroups.containsKey(ACLType.AM_VIEW_ACL)) {
+      viewGroups.addAll(allowedGroups.get(ACLType.AM_VIEW_ACL));
+    }
+    if (dagAccessControls != null && dagAccessControls.getGroupsWithViewACLs() != null) {
+      viewGroups.addAll(dagAccessControls.getGroupsWithViewACLs());
+    }
+
+    return ACLManager.toCommaSeparatedString(viewUsers) + " " +
+        ACLManager.toCommaSeparatedString(viewGroups);
+  }
+
+  private void createTimelineDomain(ApplicationId applicationId,
+      String domainId, Configuration tezConf, DAGAccessControls dagAccessControls)
+      throws IOException, HistoryACLPolicyException {
+    TimelineDomain timelineDomain = new TimelineDomain();
+    timelineDomain.setId(domainId);
+
+    ACLConfigurationParser parser = new ACLConfigurationParser(tezConf, false);
+    timelineDomain.setReaders(getMergedViewACLs(parser, dagAccessControls));
+    timelineDomain.setWriters(user);
+
+    // Use dummy app attempt id
+    ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(applicationId, 1);
+    try {
+      if (timelineClient != null) {
+        timelineClient.putDomain(appAttemptId, timelineDomain);
+      }
+    } catch (Exception e) {
+      LOG.warn("Could not post timeline domain", e);
+      throw new
+        HistoryACLPolicyException("Fail to create ACL-related domain in Timeline", e);
+    }
+  }
+
+
+  private Map<String, String> createSessionDomain(Configuration tezConf,
+      ApplicationId applicationId, DAGAccessControls dagAccessControls)
+      throws IOException, HistoryACLPolicyException {
+    String domainId =
+        tezConf.get(TezConfiguration.YARN_ATS_ACL_SESSION_DOMAIN_ID);
+    if (!tezConf.getBoolean(TezConfiguration.TEZ_AM_ACLS_ENABLED,
+        TezConfiguration.TEZ_AM_ACLS_ENABLED_DEFAULT)) {
+      if (domainId != null) {
+        throw new TezUncheckedException("ACLs disabled but DomainId is specified"
+            + ", aclsEnabled=true, domainId=" + domainId);
+      }
+      return null;
+    }
+
+    boolean autoCreateDomain = tezConf.getBoolean(TezConfiguration.YARN_ATS_ACL_DOMAINS_AUTO_CREATE,
+        TezConfiguration.YARN_ATS_ACL_DOMAINS_AUTO_CREATE_DEFAULT);
+
+    if (domainId != null) {
+      // do nothing
+      LOG.info("Using specified domainId with Timeline, domainId=" + domainId);
+      return null;
+    } else {
+      if (!autoCreateDomain) {
+        // Error - Cannot fallback to default as that leaves ACLs open
+        throw new TezUncheckedException("Timeline DomainId is not specified and auto-create"
+            + " Domains is disabled");
+      }
+      domainId = DOMAIN_ID_PREFIX + applicationId.toString();
+      createTimelineDomain(applicationId, domainId, tezConf, dagAccessControls);
+      LOG.info("Created Timeline Domain for History ACLs, domainId=" + domainId);
+      return Collections.singletonMap(TezConfiguration.YARN_ATS_ACL_SESSION_DOMAIN_ID, domainId);
+    }
+  }
+
+  private Map<String, String> createDAGDomain(Configuration tezConf,
+      ApplicationId applicationId, String dagName, DAGAccessControls dagAccessControls)
+      throws IOException, HistoryACLPolicyException {
+    if (dagAccessControls == null) {
+      // No DAG specific ACLs
+      return null;
+    }
+
+    String domainId =
+        tezConf.get(TezConfiguration.YARN_ATS_ACL_DAG_DOMAIN_ID);
+    if (!tezConf.getBoolean(TezConfiguration.TEZ_AM_ACLS_ENABLED,
+        TezConfiguration.TEZ_AM_ACLS_ENABLED_DEFAULT)) {
+      if (domainId != null) {
+        throw new TezUncheckedException("ACLs disabled but domainId for DAG is specified"
+            + ", aclsEnabled=true, domainId=" + domainId);
+      }
+      return null;
+    }
+
+    boolean autoCreateDomain = tezConf.getBoolean(TezConfiguration.YARN_ATS_ACL_DOMAINS_AUTO_CREATE,
+        TezConfiguration.YARN_ATS_ACL_DOMAINS_AUTO_CREATE_DEFAULT);
+
+    if (domainId != null) {
+      // do nothing
+      LOG.info("Using specified domainId with Timeline, domainId=" + domainId);
+      return null;
+    } else {
+      if (!autoCreateDomain) {
+        // Error - Cannot fallback to default as that leaves ACLs open
+        throw new TezUncheckedException("Timeline DomainId is not specified and auto-create"
+            + " Domains is disabled");
+      }
+
+      domainId = DOMAIN_ID_PREFIX + applicationId.toString() + "_" + dagName;
+      createTimelineDomain(applicationId, domainId, tezConf, dagAccessControls);
+      LOG.info("Created Timeline Domain for DAG-specific History ACLs, domainId=" + domainId);
+      return Collections.singletonMap(TezConfiguration.YARN_ATS_ACL_DAG_DOMAIN_ID, domainId);
+    }
+  }
+
+
+  @Override
+  public void setConf(Configuration conf) {
+    this.conf = conf;
+    initializeTimelineClient();
+  }
+
+  @Override
+  public Configuration getConf() {
+    return this.conf;
+  }
+
+  @Override
+  public Map<String, String> setupSessionACLs(Configuration conf, ApplicationId applicationId)
+      throws IOException, HistoryACLPolicyException {
+    return createSessionDomain(conf, applicationId, null);
+  }
+
+  @Override
+  public Map<String, String> setupNonSessionACLs(Configuration conf, ApplicationId applicationId,
+      DAGAccessControls dagAccessControls) throws IOException, HistoryACLPolicyException {
+    return createSessionDomain(conf, applicationId, dagAccessControls);
+  }
+
+  @Override
+  public Map<String, String> setupSessionDAGACLs(Configuration conf, ApplicationId applicationId,
+      String dagName, DAGAccessControls dagAccessControls) throws IOException, HistoryACLPolicyException {
+    return createDAGDomain(conf, applicationId, dagName, dagAccessControls);
+  }
+
+  @Override
+  public void updateTimelineEntityDomain(Object timelineEntity, String domainId) {
+    if (!(timelineEntity instanceof TimelineEntity)) {
+      throw new UnsupportedOperationException("Invalid object provided of type"
+          + timelineEntity.getClass().getName());
+    }
+    TimelineEntity entity = (TimelineEntity) timelineEntity;
+    entity.setDomainId(domainId);
+  }
+
+  @Override
+  public void close() {
+    if (timelineClient != null && timelineClient.isInState(Service.STATE.STARTED)) {
+      timelineClient.stop();
+    }
+  }
+
+}
diff --git a/tez-plugins/tez-yarn-timeline-history-with-fs/src/main/java/org/apache/tez/dag/history/logging/ats/ATSV15HistoryLoggingService.java b/tez-plugins/tez-yarn-timeline-history-with-fs/src/main/java/org/apache/tez/dag/history/logging/ats/ATSV15HistoryLoggingService.java
new file mode 100644 (file)
index 0000000..0c5b8d6
--- /dev/null
@@ -0,0 +1,400 @@
+/**
+ * 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.tez.dag.history.logging.ats;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.hadoop.yarn.api.records.timeline.TimelineEntityGroupId;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.yarn.api.records.timeline.TimelineEntity;
+import org.apache.hadoop.yarn.api.records.timeline.TimelinePutResponse;
+import org.apache.hadoop.yarn.api.records.timeline.TimelinePutResponse.TimelinePutError;
+import org.apache.hadoop.yarn.client.api.TimelineClient;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.tez.common.ReflectionUtils;
+import org.apache.tez.common.TezUtilsInternal;
+import org.apache.tez.common.security.HistoryACLPolicyManager;
+import org.apache.tez.dag.api.TezConfiguration;
+import org.apache.tez.dag.api.TezConstants;
+import org.apache.tez.dag.api.TezReflectionException;
+import org.apache.tez.dag.history.DAGHistoryEvent;
+import org.apache.tez.dag.history.HistoryEventType;
+import org.apache.tez.dag.history.events.DAGSubmittedEvent;
+import org.apache.tez.dag.history.logging.HistoryLoggingService;
+import org.apache.tez.dag.history.events.DAGRecoveredEvent;
+import org.apache.tez.dag.history.logging.EntityTypes;
+import org.apache.tez.dag.records.TezDAGID;
+
+import com.google.common.annotations.VisibleForTesting;
+
+public class ATSV15HistoryLoggingService extends HistoryLoggingService {
+
+  private static final Logger LOG = LoggerFactory.getLogger(ATSV15HistoryLoggingService.class);
+
+  private LinkedBlockingQueue<DAGHistoryEvent> eventQueue =
+      new LinkedBlockingQueue<DAGHistoryEvent>();
+
+  private Thread eventHandlingThread;
+  private AtomicBoolean stopped = new AtomicBoolean(false);
+  private int eventCounter = 0;
+  private int eventsProcessed = 0;
+  private final Object lock = new Object();
+  private boolean historyLoggingEnabled = true;
+
+  @VisibleForTesting
+  TimelineClient timelineClient;
+
+  private HashSet<TezDAGID> skippedDAGs = new HashSet<TezDAGID>();
+  private Map<TezDAGID, String> dagDomainIdMap = new HashMap<TezDAGID, String>();
+  private long maxTimeToWaitOnShutdown;
+  private boolean waitForeverOnShutdown = false;
+
+  private long maxPollingTimeMillis;
+
+  private String sessionDomainId;
+  private static final String atsHistoryLoggingServiceClassName =
+      ATSV15HistoryLoggingService.class.getName();
+  private static final String atsHistoryACLManagerClassName =
+      "org.apache.tez.dag.history.ats.acls.ATSV15HistoryACLPolicyManager";
+  private HistoryACLPolicyManager historyACLPolicyManager;
+
+  public ATSV15HistoryLoggingService() {
+    super(ATSV15HistoryLoggingService.class.getName());
+  }
+
+  @Override
+  public void serviceInit(Configuration serviceConf) throws Exception {
+    Configuration conf = new Configuration(serviceConf);
+
+    String summaryEntityTypesStr = EntityTypes.TEZ_APPLICATION
+        + "," + EntityTypes.TEZ_APPLICATION_ATTEMPT
+        + "," + EntityTypes.TEZ_DAG_ID;
+
+    // Ensure that summary entity types are defined properly for Tez.
+    if (conf.getBoolean(TezConfiguration.TEZ_AM_ATS_V15_OVERRIDE_SUMMARY_TYPES,
+        TezConfiguration.TEZ_AM_ATS_V15_OVERRIDE_SUMMARY_TYPES_DEFAULT)) {
+      conf.set(YarnConfiguration.TIMELINE_SERVICE_ENTITYGROUP_FS_STORE_SUMMARY_ENTITY_TYPES,
+          summaryEntityTypesStr);
+    }
+
+    historyLoggingEnabled = conf.getBoolean(TezConfiguration.TEZ_AM_HISTORY_LOGGING_ENABLED,
+        TezConfiguration.TEZ_AM_HISTORY_LOGGING_ENABLED_DEFAULT);
+    if (!historyLoggingEnabled) {
+      LOG.info("ATSService: History Logging disabled. "
+          + TezConfiguration.TEZ_AM_HISTORY_LOGGING_ENABLED + " set to false");
+      return;
+    }
+
+    if (conf.getBoolean(YarnConfiguration.TIMELINE_SERVICE_ENABLED,
+      YarnConfiguration.DEFAULT_TIMELINE_SERVICE_ENABLED)) {
+      timelineClient = TimelineClient.createTimelineClient();
+      timelineClient.init(conf);
+    } else {
+      this.timelineClient = null;
+      if (conf.get(TezConfiguration.TEZ_HISTORY_LOGGING_SERVICE_CLASS, "")
+        .equals(atsHistoryLoggingServiceClassName)) {
+        LOG.warn(atsHistoryLoggingServiceClassName
+            + " is disabled due to Timeline Service being disabled, "
+            + YarnConfiguration.TIMELINE_SERVICE_ENABLED + " set to false");
+      }
+    }
+    maxTimeToWaitOnShutdown = conf.getLong(
+        TezConfiguration.YARN_ATS_EVENT_FLUSH_TIMEOUT_MILLIS,
+        TezConfiguration.YARN_ATS_EVENT_FLUSH_TIMEOUT_MILLIS_DEFAULT);
+    maxPollingTimeMillis = conf.getInt(
+        TezConfiguration.YARN_ATS_MAX_POLLING_TIME_PER_EVENT,
+        TezConfiguration.YARN_ATS_MAX_POLLING_TIME_PER_EVENT_DEFAULT);
+    if (maxTimeToWaitOnShutdown < 0) {
+      waitForeverOnShutdown = true;
+    }
+    sessionDomainId = conf.get(TezConfiguration.YARN_ATS_ACL_SESSION_DOMAIN_ID);
+
+    LOG.info("Initializing " + ATSV15HistoryLoggingService.class.getSimpleName() + " with "
+        + ", maxPollingTime(ms)=" + maxPollingTimeMillis
+        + ", waitTimeForShutdown(ms)=" + maxTimeToWaitOnShutdown
+        + ", TimelineACLManagerClass=" + atsHistoryACLManagerClassName);
+
+    try {
+      historyACLPolicyManager = ReflectionUtils.createClazzInstance(
+          atsHistoryACLManagerClassName);
+      historyACLPolicyManager.setConf(conf);
+    } catch (TezReflectionException e) {
+      LOG.warn("Could not instantiate object for " + atsHistoryACLManagerClassName
+          + ". ACLs cannot be enforced correctly for history data in Timeline", e);
+      if (!conf.getBoolean(TezConfiguration.TEZ_AM_ALLOW_DISABLED_TIMELINE_DOMAINS,
+          TezConfiguration.TEZ_AM_ALLOW_DISABLED_TIMELINE_DOMAINS_DEFAULT)) {
+        throw e;
+      }
+      historyACLPolicyManager = null;
+    }
+
+  }
+
+  @Override
+  public void serviceStart() {
+    if (!historyLoggingEnabled || timelineClient == null) {
+      return;
+    }
+    timelineClient.start();
+
+    eventHandlingThread = new Thread(new Runnable() {
+      @Override
+      public void run() {
+        boolean interrupted = false;
+        TezUtilsInternal.setHadoopCallerContext(appContext.getHadoopShim(),
+            appContext.getApplicationID());
+        while (!stopped.get() && !Thread.currentThread().isInterrupted()
+              && !interrupted) {
+
+          // Log the size of the event-queue every so often.
+          if (eventCounter != 0 && eventCounter % 1000 == 0) {
+            if (eventsProcessed != 0 && !eventQueue.isEmpty()) {
+              LOG.info("Event queue stats"
+                  + ", eventsProcessedSinceLastUpdate=" + eventsProcessed
+                  + ", eventQueueSize=" + eventQueue.size());
+            }
+            eventCounter = 0;
+            eventsProcessed = 0;
+          } else {
+            ++eventCounter;
+          }
+
+          synchronized (lock) {
+            try {
+              DAGHistoryEvent event = eventQueue.poll(maxPollingTimeMillis, TimeUnit.MILLISECONDS);
+              if (event == null) {
+                continue;
+              }
+              if (!isValidEvent(event)) {
+                continue;
+              }
+
+              try {
+                handleEvents(event);
+                eventsProcessed += 1;
+              } catch (Exception e) {
+                LOG.warn("Error handling events", e);
+              }
+            } catch (InterruptedException e) {
+              // Finish processing events and then return
+              interrupted = true;
+            }
+          }
+        }
+      }
+    }, "HistoryEventHandlingThread");
+    eventHandlingThread.start();
+  }
+
+  @Override
+  public void serviceStop() {
+    if (!historyLoggingEnabled || timelineClient == null) {
+      return;
+    }
+    LOG.info("Stopping ATSService"
+        + ", eventQueueBacklog=" + eventQueue.size());
+    stopped.set(true);
+    if (eventHandlingThread != null) {
+      eventHandlingThread.interrupt();
+    }
+    try {
+      TezUtilsInternal.setHadoopCallerContext(appContext.getHadoopShim(),
+          appContext.getApplicationID());
+      synchronized (lock) {
+        if (!eventQueue.isEmpty()) {
+          LOG.warn("ATSService being stopped"
+              + ", eventQueueBacklog=" + eventQueue.size()
+              + ", maxTimeLeftToFlush=" + maxTimeToWaitOnShutdown
+              + ", waitForever=" + waitForeverOnShutdown);
+          long startTime = appContext.getClock().getTime();
+          long endTime = startTime + maxTimeToWaitOnShutdown;
+          while (waitForeverOnShutdown || (endTime >= appContext.getClock().getTime())) {
+            try {
+              DAGHistoryEvent event = eventQueue.poll(maxPollingTimeMillis, TimeUnit.MILLISECONDS);
+              if (event == null) {
+                LOG.info("Event queue empty, stopping ATS Service");
+                break;
+              }
+              if (!isValidEvent(event)) {
+                continue;
+              }
+              try {
+                handleEvents(event);
+              } catch (Exception e) {
+                LOG.warn("Error handling event", e);
+              }
+            } catch (InterruptedException e) {
+              LOG.info("ATSService interrupted while shutting down. Exiting."
+                  + " EventQueueBacklog=" + eventQueue.size());
+            }
+          }
+        }
+      }
+    } finally {
+      appContext.getHadoopShim().clearHadoopCallerContext();
+    }
+    if (!eventQueue.isEmpty()) {
+      LOG.warn("Did not finish flushing eventQueue before stopping ATSService"
+          + ", eventQueueBacklog=" + eventQueue.size());
+    }
+    timelineClient.stop();
+    if (historyACLPolicyManager != null) {
+      historyACLPolicyManager.close();
+    }
+
+  }
+
+  @VisibleForTesting
+  public TimelineEntityGroupId getGroupId(DAGHistoryEvent event) {
+    // Changing this function will impact TimelineCachePluginImpl and should be done very
+    // carefully to account for handling different versions of Tez
+    switch (event.getHistoryEvent().getEventType()) {
+      case DAG_SUBMITTED:
+      case DAG_INITIALIZED:
+      case DAG_STARTED:
+      case DAG_FINISHED:
+      case DAG_KILL_REQUEST:
+      case VERTEX_INITIALIZED:
+      case VERTEX_STARTED:
+      case VERTEX_CONFIGURE_DONE:
+      case VERTEX_FINISHED:
+      case TASK_STARTED:
+      case TASK_FINISHED:
+      case TASK_ATTEMPT_STARTED:
+      case TASK_ATTEMPT_FINISHED:
+      case DAG_COMMIT_STARTED:
+      case VERTEX_COMMIT_STARTED:
+      case VERTEX_GROUP_COMMIT_STARTED:
+      case VERTEX_GROUP_COMMIT_FINISHED:
+      case DAG_RECOVERED:
+        return TimelineEntityGroupId.newInstance(event.getDagID().getApplicationId(),
+            event.getDagID().toString());
+      case APP_LAUNCHED:
+      case AM_LAUNCHED:
+      case AM_STARTED:
+      case CONTAINER_LAUNCHED:
+      case CONTAINER_STOPPED:
+        return TimelineEntityGroupId.newInstance(appContext.getApplicationID(),
+            appContext.getApplicationID().toString());
+    }
+    return null;
+  }
+
+  public void handle(DAGHistoryEvent event) {
+    if (historyLoggingEnabled && timelineClient != null) {
+      eventQueue.add(event);
+    }
+  }
+
+  private boolean isValidEvent(DAGHistoryEvent event) {
+    HistoryEventType eventType = event.getHistoryEvent().getEventType();
+    TezDAGID dagId = event.getDagID();
+
+    if (eventType.equals(HistoryEventType.DAG_SUBMITTED)) {
+      DAGSubmittedEvent dagSubmittedEvent =
+          (DAGSubmittedEvent) event.getHistoryEvent();
+      String dagName = dagSubmittedEvent.getDAGName();
+      if ((dagName != null
+          && dagName.startsWith(TezConstants.TEZ_PREWARM_DAG_NAME_PREFIX))
+          || (!dagSubmittedEvent.isHistoryLoggingEnabled())) {
+        // Skip recording pre-warm DAG events
+        skippedDAGs.add(dagId);
+        return false;
+      }
+      if (historyACLPolicyManager != null) {
+        String dagDomainId = dagSubmittedEvent.getConf().get(
+            TezConfiguration.YARN_ATS_ACL_DAG_DOMAIN_ID);
+        if (dagDomainId != null) {
+          dagDomainIdMap.put(dagId, dagDomainId);
+        }
+      }
+    }
+    if (eventType.equals(HistoryEventType.DAG_RECOVERED)) {
+      DAGRecoveredEvent dagRecoveredEvent = (DAGRecoveredEvent) event.getHistoryEvent();
+      if (!dagRecoveredEvent.isHistoryLoggingEnabled()) {
+        skippedDAGs.add(dagRecoveredEvent.getDagID());
+        return false;
+      }
+    }
+    if (eventType.equals(HistoryEventType.DAG_FINISHED)) {
+      // Remove from set to keep size small
+      // No more events should be seen after this point.
+      if (skippedDAGs.remove(dagId)) {
+        return false;
+      }
+    }
+
+    if (dagId != null && skippedDAGs.contains(dagId)) {
+      // Skip pre-warm DAGs
+      return false;
+    }
+
+    return true;
+  }
+
+  private void handleEvents(DAGHistoryEvent event) {
+    String domainId = sessionDomainId;
+    TezDAGID dagId = event.getDagID();
+
+    if (historyACLPolicyManager != null && dagId != null) {
+      if (dagDomainIdMap.containsKey(dagId)) {
+        domainId = dagDomainIdMap.get(dagId);
+      }
+    }
+
+    TimelineEntity entity =
+        HistoryEventTimelineConversion.convertToTimelineEntity(event.getHistoryEvent());
+    if (historyACLPolicyManager != null) {
+      if (domainId != null && !domainId.isEmpty()) {
+        historyACLPolicyManager.updateTimelineEntityDomain(entity, domainId);
+      }
+    }
+
+    try {
+      TimelineEntityGroupId groupId = getGroupId(event);
+      TimelinePutResponse response = timelineClient.putEntities(
+          appContext.getApplicationAttemptId(), groupId, entity);
+      if (response != null
+          && !response.getErrors().isEmpty()) {
+        int count = response.getErrors().size();
+        for (int i = 0; i < count; ++i) {
+          TimelinePutError err = response.getErrors().get(i);
+          if (err.getErrorCode() != 0) {
+            LOG.warn("Could not post history event to ATS"
+                + ", atsPutError=" + err.getErrorCode()
+                + ", entityId=" + err.getEntityId());
+          }
+        }
+      }
+      // Do nothing additional, ATS client library should handle throttling
+      // or auto-disable as needed
+    } catch (Exception e) {
+      LOG.warn("Could not handle history events", e);
+    }
+
+  }
+
+}
diff --git a/tez-plugins/tez-yarn-timeline-history-with-fs/src/main/javadoc/resources/META-INF/LICENSE.txt b/tez-plugins/tez-yarn-timeline-history-with-fs/src/main/javadoc/resources/META-INF/LICENSE.txt
new file mode 100644 (file)
index 0000000..d645695
--- /dev/null
@@ -0,0 +1,202 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed 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.
diff --git a/tez-plugins/tez-yarn-timeline-history-with-fs/src/main/javadoc/resources/META-INF/NOTICE.txt b/tez-plugins/tez-yarn-timeline-history-with-fs/src/main/javadoc/resources/META-INF/NOTICE.txt
new file mode 100644 (file)
index 0000000..88ff448
--- /dev/null
@@ -0,0 +1,6 @@
+Apache Tez
+Copyright (c) 2015 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/tez-plugins/tez-yarn-timeline-history-with-fs/src/main/resources/META-INF/LICENSE.txt b/tez-plugins/tez-yarn-timeline-history-with-fs/src/main/resources/META-INF/LICENSE.txt
new file mode 100644 (file)
index 0000000..d645695
--- /dev/null
@@ -0,0 +1,202 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed 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.
diff --git a/tez-plugins/tez-yarn-timeline-history-with-fs/src/main/resources/META-INF/NOTICE.txt b/tez-plugins/tez-yarn-timeline-history-with-fs/src/main/resources/META-INF/NOTICE.txt
new file mode 100644 (file)
index 0000000..88ff448
--- /dev/null
@@ -0,0 +1,6 @@
+Apache Tez
+Copyright (c) 2015 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/tez-plugins/tez-yarn-timeline-history-with-fs/src/test/java/org/apache/tez/dag/history/ats/acls/TestATSHistoryV15.java b/tez-plugins/tez-yarn-timeline-history-with-fs/src/test/java/org/apache/tez/dag/history/ats/acls/TestATSHistoryV15.java
new file mode 100644 (file)
index 0000000..6f70bf5
--- /dev/null
@@ -0,0 +1,297 @@
+/**
+ * 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.tez.dag.history.ats.acls;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Random;
+
+import javax.ws.rs.core.MediaType;
+
+import org.apache.hadoop.fs.LocatedFileStatus;
+import org.apache.hadoop.fs.RemoteIterator;
+import org.apache.hadoop.hdfs.DFSConfigKeys;
+import org.apache.hadoop.yarn.api.records.timeline.TimelineEntityGroupId;
+import org.apache.tez.dag.app.AppContext;
+import org.apache.tez.dag.history.HistoryEvent;
+import org.apache.tez.dag.history.logging.ats.ATSV15HistoryLoggingService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hdfs.MiniDFSCluster;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.hadoop.yarn.api.records.ApplicationId;
+import org.apache.hadoop.yarn.api.records.Resource;
+import org.apache.hadoop.yarn.api.records.timeline.TimelineDomain;
+import org.apache.hadoop.yarn.api.records.timeline.TimelineEntity;
+import org.apache.hadoop.yarn.client.api.TimelineClient;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.tez.client.TezClient;
+import org.apache.tez.common.ReflectionUtils;
+import org.apache.tez.common.security.DAGAccessControls;
+import org.apache.tez.dag.api.DAG;
+import org.apache.tez.dag.api.ProcessorDescriptor;
+import org.apache.tez.dag.api.TezConfiguration;
+import org.apache.tez.dag.api.Vertex;
+import org.apache.tez.dag.api.client.DAGClient;
+import org.apache.tez.dag.api.client.DAGStatus;
+import org.apache.tez.dag.api.records.DAGProtos.DAGPlan;
+import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
+import org.apache.tez.dag.records.TezDAGID;
+import org.apache.tez.dag.history.events.DAGSubmittedEvent;
+import org.apache.tez.dag.history.DAGHistoryEvent;
+import org.apache.tez.dag.history.HistoryEventType;
+import org.apache.tez.runtime.library.processor.SleepProcessor;
+import org.apache.tez.runtime.library.processor.SleepProcessor.SleepProcessorConfig;
+import org.apache.tez.tests.MiniTezClusterWithTimeline;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.google.common.collect.Sets;
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.WebResource;
+
+import org.mockito.Matchers;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.when;
+
+public class TestATSHistoryV15 {
+
+  private static final Logger LOG = LoggerFactory.getLogger(TestATSHistoryV15.class);
+
+  protected static MiniTezClusterWithTimeline mrrTezCluster = null;
+  protected static MiniDFSCluster dfsCluster = null;
+  private static String timelineAddress;
+  private static Random random = new Random();
+
+  private static Configuration conf = new Configuration();
+  private static FileSystem remoteFs;
+
+  private static String TEST_ROOT_DIR = "target" + Path.SEPARATOR
+      + TestATSHistoryV15.class.getName() + "-tmpDir";
+  private static Path atsActivePath;
+
+  private static String user;
+
+  @BeforeClass
+  public static void setup() throws IOException {
+    try {
+      conf.set(MiniDFSCluster.HDFS_MINIDFS_BASEDIR, TEST_ROOT_DIR);
+      dfsCluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).format(true).racks(null)
+          .build();
+      remoteFs = dfsCluster.getFileSystem();
+    } catch (IOException io) {
+      throw new RuntimeException("problem starting mini dfs cluster", io);
+    }
+
+    if (mrrTezCluster == null) {
+      try {
+        mrrTezCluster = new MiniTezClusterWithTimeline(TestATSHistoryV15.class.getName(),
+            1, 1, 1, true);
+        Configuration conf = new Configuration();
+        conf.setBoolean(YarnConfiguration.TIMELINE_SERVICE_ENABLED, true);
+        conf.set("fs.defaultFS", remoteFs.getUri().toString()); // use HDFS
+        conf.setInt("yarn.nodemanager.delete.debug-delay-sec", 20000);
+        atsActivePath = new Path("/tmp/ats/active/" + random.nextInt(100000));
+        Path atsDonePath = new Path("/tmp/ats/done/" + random.nextInt(100000));
+        conf.setDouble(YarnConfiguration.TIMELINE_SERVICE_VERSION, 1.5);
+
+        remoteFs.mkdirs(atsActivePath);
+        remoteFs.mkdirs(atsDonePath);
+
+        conf.setInt(DFSConfigKeys.DFS_REPLICATION_KEY, 1);
+        conf.set(YarnConfiguration.TIMELINE_SERVICE_ENTITYGROUP_FS_STORE_ACTIVE_DIR,
+            remoteFs.resolvePath(atsActivePath).toString());
+        conf.set(YarnConfiguration.TIMELINE_SERVICE_ENTITYGROUP_FS_STORE_DONE_DIR,
+            remoteFs.resolvePath(atsDonePath).toString());
+
+
+        mrrTezCluster.init(conf);
+        mrrTezCluster.start();
+      } catch (Throwable e) {
+        LOG.info("Failed to start Mini Tez Cluster", e);
+      }
+    }
+    user = UserGroupInformation.getCurrentUser().getShortUserName();
+    timelineAddress = mrrTezCluster.getConfig().get(
+        YarnConfiguration.TIMELINE_SERVICE_WEBAPP_ADDRESS);
+    if (timelineAddress != null) {
+      // Hack to handle bug in MiniYARNCluster handling of webapp address
+      timelineAddress = timelineAddress.replace("0.0.0.0", "localhost");
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws InterruptedException {
+    LOG.info("Shutdown invoked");
+    Thread.sleep(10000);
+    if (mrrTezCluster != null) {
+      mrrTezCluster.stop();
+      mrrTezCluster = null;
+    }
+    if (dfsCluster != null) {
+      dfsCluster.shutdown();
+      dfsCluster = null;
+    }
+  }
+
+  @Test (timeout=50000)
+  public void testSimpleDAG() throws Exception {
+    TezClient tezSession = null;
+    ApplicationId applicationId;
+    String viewAcls = "nobody nobody_group";
+    try {
+      SleepProcessorConfig spConf = new SleepProcessorConfig(1);
+
+      DAG dag = DAG.create("TezSleepProcessor");
+      Vertex vertex = Vertex.create("SleepVertex", ProcessorDescriptor.create(
+              SleepProcessor.class.getName()).setUserPayload(spConf.toUserPayload()), 1,
+          Resource.newInstance(256, 1));
+      dag.addVertex(vertex);
+
+      TezConfiguration tezConf = new TezConfiguration(mrrTezCluster.getConfig());
+
+      tezConf.set(YarnConfiguration.TIMELINE_SERVICE_ENTITYGROUP_FS_STORE_SUMMARY_ENTITY_TYPES,
+          "TEZ_DAG_ID");
+
+      tezConf.set(TezConfiguration.TEZ_AM_VIEW_ACLS, viewAcls);
+      tezConf.set(TezConfiguration.TEZ_HISTORY_LOGGING_SERVICE_CLASS,
+          ATSV15HistoryLoggingService.class.getName());
+      Path remoteStagingDir = remoteFs.makeQualified(new Path("/tmp", String.valueOf(random
+          .nextInt(100000))));
+      remoteFs.mkdirs(remoteStagingDir);
+      tezConf.set(TezConfiguration.TEZ_AM_STAGING_DIR, remoteStagingDir.toString());
+
+      tezSession = TezClient.create("TezSleepProcessor", tezConf, true);
+      tezSession.start();
+
+      applicationId = tezSession.getAppMasterApplicationId();
+
+      DAGClient dagClient = tezSession.submitDAG(dag);
+
+      DAGStatus dagStatus = dagClient.getDAGStatus(null);
+      while (!dagStatus.isCompleted()) {
+        LOG.info("Waiting for job to complete. Sleeping for 500ms." + " Current state: "
+            + dagStatus.getState());
+        Thread.sleep(500l);
+        dagStatus = dagClient.getDAGStatus(null);
+      }
+      assertEquals(DAGStatus.State.SUCCEEDED, dagStatus.getState());
+
+      // Verify HDFS data
+      int count = verifyATSDataOnHDFS(atsActivePath, 0, applicationId);
+      Assert.assertTrue("Count is: " + count, count > 0);
+
+    } finally {
+      if (tezSession != null) {
+        tezSession.stop();
+      }
+    }
+
+  }
+
+  private int verifyATSDataOnHDFS(Path p, int count, ApplicationId applicationId) throws IOException {
+    RemoteIterator<LocatedFileStatus> iter = remoteFs.listFiles(p, true);
+    while (iter.hasNext()) {
+      LocatedFileStatus f = iter.next();
+      LOG.info("Found file " + f.toString());
+      if (f.isDirectory()) {
+        verifyATSDataOnHDFS(f.getPath(), count, applicationId);
+      } else {
+        if (f.getPath().getName().contains(
+            "" + applicationId.getClusterTimestamp() + "_" + applicationId.getId())) {
+          ++count;
+        }
+      }
+    }
+    return count;
+  }
+
+  @Test
+  public void testGetGroupId() {
+    ApplicationId appId = ApplicationId.newInstance(1000l, 1);
+    TezDAGID dagid = TezDAGID.getInstance(appId, 1);
+    for (final HistoryEventType eventType : HistoryEventType.values()) {
+      HistoryEvent historyEvent = new HistoryEvent() {
+        @Override
+        public HistoryEventType getEventType() {
+          return eventType;
+        }
+
+        @Override
+        public boolean isRecoveryEvent() {
+          return false;
+        }
+
+        @Override
+        public boolean isHistoryEvent() {
+          return false;
+        }
+
+        @Override
+        public void toProtoStream(OutputStream outputStream) throws IOException {
+
+        }
+
+        @Override
+        public void fromProtoStream(InputStream inputStream) throws IOException {
+
+        }
+      };
+      DAGHistoryEvent event = new DAGHistoryEvent(dagid, historyEvent);
+      ATSV15HistoryLoggingService service = new ATSV15HistoryLoggingService();
+      AppContext appContext = mock(AppContext.class);
+      when(appContext.getApplicationID()).thenReturn(appId);
+      service.setAppContext(appContext);
+
+      TimelineEntityGroupId grpId = service.getGroupId(event);
+      Assert.assertNotNull(grpId);
+      Assert.assertEquals(appId, grpId.getApplicationId());
+      switch (eventType) {
+        case AM_LAUNCHED:
+        case APP_LAUNCHED:
+        case AM_STARTED:
+        case CONTAINER_LAUNCHED:
+        case CONTAINER_STOPPED:
+          Assert.assertEquals(appId.toString(), grpId.getTimelineEntityGroupId());
+          break;
+        default:
+          Assert.assertEquals(dagid.toString(), grpId.getTimelineEntityGroupId());
+      }
+    }
+  }
+
+
+}
index dce6978..99eaa4b 100644 (file)
         <module>job-analyzer</module>
       </modules>
     </profile>
+    <profile>
+      <id>hadoop28</id>
+      <activation>
+        <activeByDefault>false</activeByDefault>
+      </activation>
+      <modules>
+        <module>job-analyzer</module>
+      </modules>
+    </profile>
   </profiles>
 
 </project>