Repository: tez Updated Branches: refs/heads/master 65c4dc678 -> 42b61f43f
http://git-wip-us.apache.org/repos/asf/tez/blob/42b61f43/tez-plugins/tez-yarn-timeline-history-with-fs/src/main/java/org/apache/tez/dag/history/logging/ats/ATSV15HistoryLoggingService.java ---------------------------------------------------------------------- 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 index 0000000..0c5b8d6 --- /dev/null +++ b/tez-plugins/tez-yarn-timeline-history-with-fs/src/main/java/org/apache/tez/dag/history/logging/ats/ATSV15HistoryLoggingService.java @@ -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); + } + + } + +} http://git-wip-us.apache.org/repos/asf/tez/blob/42b61f43/tez-plugins/tez-yarn-timeline-history-with-fs/src/main/javadoc/resources/META-INF/LICENSE.txt ---------------------------------------------------------------------- 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 index 0000000..d645695 --- /dev/null +++ b/tez-plugins/tez-yarn-timeline-history-with-fs/src/main/javadoc/resources/META-INF/LICENSE.txt @@ -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. http://git-wip-us.apache.org/repos/asf/tez/blob/42b61f43/tez-plugins/tez-yarn-timeline-history-with-fs/src/main/javadoc/resources/META-INF/NOTICE.txt ---------------------------------------------------------------------- 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 index 0000000..88ff448 --- /dev/null +++ b/tez-plugins/tez-yarn-timeline-history-with-fs/src/main/javadoc/resources/META-INF/NOTICE.txt @@ -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/). + http://git-wip-us.apache.org/repos/asf/tez/blob/42b61f43/tez-plugins/tez-yarn-timeline-history-with-fs/src/main/resources/META-INF/LICENSE.txt ---------------------------------------------------------------------- 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 index 0000000..d645695 --- /dev/null +++ b/tez-plugins/tez-yarn-timeline-history-with-fs/src/main/resources/META-INF/LICENSE.txt @@ -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. http://git-wip-us.apache.org/repos/asf/tez/blob/42b61f43/tez-plugins/tez-yarn-timeline-history-with-fs/src/main/resources/META-INF/NOTICE.txt ---------------------------------------------------------------------- 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 index 0000000..88ff448 --- /dev/null +++ b/tez-plugins/tez-yarn-timeline-history-with-fs/src/main/resources/META-INF/NOTICE.txt @@ -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/). + http://git-wip-us.apache.org/repos/asf/tez/blob/42b61f43/tez-plugins/tez-yarn-timeline-history-with-fs/src/test/java/org/apache/tez/dag/history/ats/acls/TestATSHistoryV15.java ---------------------------------------------------------------------- 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 index 0000000..6f70bf5 --- /dev/null +++ b/tez-plugins/tez-yarn-timeline-history-with-fs/src/test/java/org/apache/tez/dag/history/ats/acls/TestATSHistoryV15.java @@ -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()); + } + } + } + + +} http://git-wip-us.apache.org/repos/asf/tez/blob/42b61f43/tez-tools/analyzers/pom.xml ---------------------------------------------------------------------- diff --git a/tez-tools/analyzers/pom.xml b/tez-tools/analyzers/pom.xml index dce6978..99eaa4b 100644 --- a/tez-tools/analyzers/pom.xml +++ b/tez-tools/analyzers/pom.xml @@ -46,6 +46,15 @@ <module>job-analyzer</module> </modules> </profile> + <profile> + <id>hadoop28</id> + <activation> + <activeByDefault>false</activeByDefault> + </activation> + <modules> + <module>job-analyzer</module> + </modules> + </profile> </profiles> </project>
