001/*
002 * Copyright (c) 2007-2017 Xplenty, Inc. All Rights Reserved.
003 *
004 * Project and contact information: http://www.cascading.org/
005 *
006 * This file is part of the Cascading project.
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 *     http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 */
020
021package cascading.stats.tez.util;
022
023import java.io.IOException;
024import java.util.HashMap;
025import java.util.Iterator;
026import java.util.Map;
027import java.util.Set;
028import javax.annotation.Nullable;
029
030import cascading.CascadingException;
031import org.apache.hadoop.yarn.api.records.ApplicationId;
032import org.apache.hadoop.yarn.api.records.ApplicationReport;
033import org.apache.tez.client.FrameworkClient;
034import org.apache.tez.common.ATSConstants;
035import org.apache.tez.dag.api.TezConfiguration;
036import org.apache.tez.dag.api.TezException;
037import org.apache.tez.dag.api.client.DAGClient;
038import org.apache.tez.dag.api.client.DAGClientTimelineImpl;
039import org.apache.tez.dag.api.client.DAGStatus;
040import org.apache.tez.dag.api.client.StatusGetOpts;
041import org.apache.tez.dag.api.client.VertexStatus;
042import org.codehaus.jettison.json.JSONArray;
043import org.codehaus.jettison.json.JSONException;
044import org.codehaus.jettison.json.JSONObject;
045import org.slf4j.Logger;
046import org.slf4j.LoggerFactory;
047
048import static org.apache.tez.common.ATSConstants.*;
049import static org.apache.tez.dag.history.logging.EntityTypes.TEZ_TASK_ID;
050
051/**
052 * TezTimelineClient is currently just a proxy around DAGClient that pretends to
053 * implement TimelineClient (throws errors on all methods).
054 *
055 * When TEZ-3369 is implemented, TezTimelineClient can be replaced by a pure DAGClient usage. Until then,
056 * FlowStats is non-functional.
057 */
058public class TezTimelineClient extends DAGClient implements TimelineClient {
059
060    private final String dagId;
061    private final FrameworkClient frameworkClient;
062    private final DAGClient dagClient;
063
064    public TezTimelineClient(ApplicationId appId, String dagId, TezConfiguration conf, FrameworkClient frameworkClient, DAGClient dagClient) throws TezException {
065        this.dagId = dagId;
066        this.frameworkClient = frameworkClient;
067        this.dagClient = dagClient;
068    }
069
070    public DAGClient getDAGClient() {
071        return dagClient;
072    }
073
074    public FrameworkClient getFrameworkClient() {
075        return frameworkClient;
076    }
077
078
079    @Override
080    public DAGStatus getDAGStatus(@Nullable Set<StatusGetOpts> statusOptions) throws IOException, TezException {
081        return dagClient.getDAGStatus(statusOptions);
082    }
083
084    @Override
085    public DAGStatus getDAGStatus(@Nullable Set<StatusGetOpts> statusOptions, long timeout) throws IOException, TezException {
086        return dagClient.getDAGStatus(statusOptions, timeout);
087    }
088
089    @Override
090    public VertexStatus getVertexStatus(String vertexName, Set<StatusGetOpts> statusOptions) throws IOException, TezException {
091        return dagClient.getVertexStatus(vertexName, statusOptions);
092    }
093
094    @Override
095    public void tryKillDAG() throws IOException, TezException {
096        dagClient.tryKillDAG();
097    }
098
099    @Override
100    public DAGStatus waitForCompletion() throws IOException, TezException, InterruptedException {
101        return dagClient.waitForCompletion();
102    }
103
104    @Override
105    public void close() throws IOException {
106        dagClient.close();
107    }
108
109    @Override
110    public DAGStatus waitForCompletionWithStatusUpdates(@Nullable Set<StatusGetOpts> statusOpts) throws IOException, TezException, InterruptedException {
111        return dagClient.waitForCompletionWithStatusUpdates(statusOpts);
112    }
113
114    @Override
115    public String getSessionIdentifierString() {
116        return dagClient.getSessionIdentifierString();
117    }
118
119    @Override
120    public String getDagIdentifierString() {
121        return dagClient.getDagIdentifierString();
122    }
123
124    @Override
125    public String getExecutionContext() {
126        return dagClient.getExecutionContext();
127    }
128
129    @Override
130    public String getVertexID(String vertexName) throws IOException, TezException {
131        throw new TezException("reporting API is temporarily disabled on TEZ-3369 implementation");
132    }
133
134    @Override
135    public Iterator<TaskStatus> getVertexChildren(String vertexID, int limit, String startTaskID) throws IOException, TezException {
136        throw new TezException("reporting API is temporarily disabled on TEZ-3369 implementation");
137    }
138
139    @Override
140    public TaskStatus getVertexChild(String taskID) throws TezException {
141        throw new TezException("reporting API is temporarily disabled on TEZ-3369 implementation");
142    }
143
144    @Override
145    protected ApplicationReport getApplicationReportInternal() {
146        return null; // not implemented
147    }
148
149}