Search in sources :

Example 1 with SessionNotRunning

use of org.apache.tez.dag.api.SessionNotRunning in project hive by apache.

the class TezTask method submit.

DAGClient submit(JobConf conf, DAG dag, Path scratchDir, LocalResource appJarLr, TezSessionState sessionState, List<LocalResource> additionalLr, String[] inputOutputJars, Map<String, LocalResource> inputOutputLocalResources) throws Exception {
    perfLogger.PerfLogBegin(CLASS_NAME, PerfLogger.TEZ_SUBMIT_DAG);
    DAGClient dagClient = null;
    Map<String, LocalResource> resourceMap = new HashMap<String, LocalResource>();
    if (additionalLr != null) {
        for (LocalResource lr : additionalLr) {
            if (lr.getType() == LocalResourceType.FILE) {
                // TEZ AM will only localize FILE (no script operators in the AM)
                resourceMap.put(utils.getBaseName(lr), lr);
            }
        }
    }
    try {
        try {
            // ready to start execution on the cluster
            sessionState.getSession().addAppMasterLocalFiles(resourceMap);
            dagClient = sessionState.getSession().submitDAG(dag);
        } catch (SessionNotRunning nr) {
            console.printInfo("Tez session was closed. Reopening...");
            // close the old one, but keep the tmp files around
            // TODO Why is the session being create using a conf instance belonging to TezTask
            //      - instead of the session conf instance.
            TezSessionPoolManager.getInstance().reopenSession(sessionState, this.conf, inputOutputJars, true);
            console.printInfo("Session re-established.");
            dagClient = sessionState.getSession().submitDAG(dag);
        }
    } catch (Exception e) {
        // In case of any other exception, retry. If this also fails, report original error and exit.
        try {
            console.printInfo("Dag submit failed due to " + e.getMessage() + " stack trace: " + Arrays.toString(e.getStackTrace()) + " retrying...");
            TezSessionPoolManager.getInstance().reopenSession(sessionState, this.conf, inputOutputJars, true);
            dagClient = sessionState.getSession().submitDAG(dag);
        } catch (Exception retryException) {
            // we failed to submit after retrying. Destroy session and bail.
            TezSessionPoolManager.getInstance().destroySession(sessionState);
            throw retryException;
        }
    }
    perfLogger.PerfLogEnd(CLASS_NAME, PerfLogger.TEZ_SUBMIT_DAG);
    return new SyncDagClient(dagClient);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SessionNotRunning(org.apache.tez.dag.api.SessionNotRunning) DAGClient(org.apache.tez.dag.api.client.DAGClient) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) IOException(java.io.IOException) TezException(org.apache.tez.dag.api.TezException) LocalResource(org.apache.hadoop.yarn.api.records.LocalResource)

Example 2 with SessionNotRunning

use of org.apache.tez.dag.api.SessionNotRunning in project hive by apache.

the class TezTask method submit.

DAGClient submit(JobConf conf, DAG dag, Ref<TezSessionState> sessionStateRef) throws Exception {
    perfLogger.PerfLogBegin(CLASS_NAME, PerfLogger.TEZ_SUBMIT_DAG);
    DAGClient dagClient = null;
    TezSessionState sessionState = sessionStateRef.value;
    try {
        try {
            // ready to start execution on the cluster
            dagClient = sessionState.getSession().submitDAG(dag);
        } catch (SessionNotRunning nr) {
            console.printInfo("Tez session was closed. Reopening...");
            sessionStateRef.value = null;
            sessionStateRef.value = sessionState = getNewTezSessionOnError(sessionState);
            console.printInfo("Session re-established.");
            dagClient = sessionState.getSession().submitDAG(dag);
        }
    } catch (Exception e) {
        // In case of any other exception, retry. If this also fails, report original error and exit.
        try {
            console.printInfo("Dag submit failed due to " + e.getMessage() + " stack trace: " + Arrays.toString(e.getStackTrace()) + " retrying...");
            sessionStateRef.value = null;
            sessionStateRef.value = sessionState = getNewTezSessionOnError(sessionState);
            dagClient = sessionState.getSession().submitDAG(dag);
        } catch (Exception retryException) {
            // we failed to submit after retrying. Destroy session and bail.
            sessionStateRef.value = null;
            sessionState.destroy();
            throw retryException;
        }
    }
    perfLogger.PerfLogEnd(CLASS_NAME, PerfLogger.TEZ_SUBMIT_DAG);
    return new SyncDagClient(dagClient);
}
Also used : SessionNotRunning(org.apache.tez.dag.api.SessionNotRunning) DAGClient(org.apache.tez.dag.api.client.DAGClient) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) IOException(java.io.IOException) TezException(org.apache.tez.dag.api.TezException)

Example 3 with SessionNotRunning

use of org.apache.tez.dag.api.SessionNotRunning in project tez by apache.

the class TestTezJobs method testInvalidQueueSubmissionToSession.

@Test(timeout = 60000)
public void testInvalidQueueSubmissionToSession() throws Exception {
    TezConfiguration tezConf = new TezConfiguration(mrrTezCluster.getConfig());
    YarnClient yarnClient = YarnClient.createYarnClient();
    try {
        yarnClient.init(mrrTezCluster.getConfig());
        yarnClient.start();
        SimpleSessionExample job = new SimpleSessionExample();
        tezConf.setBoolean(TezConfiguration.TEZ_AM_SESSION_MODE, true);
        tezConf.set(TezConfiguration.TEZ_QUEUE_NAME, "nonexistent");
        String[] inputPaths = new String[1];
        String[] outputPaths = new String[1];
        String inputDirStr = "/tmp/owc-input";
        inputPaths[0] = inputDirStr;
        Path inputDir = new Path(inputDirStr);
        remoteFs.mkdirs(inputDir);
        String outputDirStr = "/tmp/owc-output";
        outputPaths[0] = outputDirStr;
        job.run(tezConf, new String[] { StringUtils.join(",", inputPaths), StringUtils.join(",", outputPaths), "2" }, null);
        fail("Job submission should have failed");
    } catch (SessionNotRunning e) {
        // Expected
        LOG.info("Session not running", e);
    } catch (TezException e) {
        Assert.assertTrue(e.getMessage().contains("Failed to submit application"));
    } finally {
        if (yarnClient != null) {
            yarnClient.stop();
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) TezException(org.apache.tez.dag.api.TezException) SessionNotRunning(org.apache.tez.dag.api.SessionNotRunning) SimpleSessionExample(org.apache.tez.examples.SimpleSessionExample) YarnClient(org.apache.hadoop.yarn.client.api.YarnClient) TezConfiguration(org.apache.tez.dag.api.TezConfiguration) Test(org.junit.Test)

Example 4 with SessionNotRunning

use of org.apache.tez.dag.api.SessionNotRunning in project hive by apache.

the class TestTezTask method setUp.

@Before
public void setUp() throws Exception {
    utils = mock(DagUtils.class);
    fs = mock(FileSystem.class);
    path = mock(Path.class);
    when(path.getFileSystem(any())).thenReturn(fs);
    when(utils.getTezDir(any())).thenReturn(path);
    when(utils.createVertex(any(), any(BaseWork.class), any(Path.class), any(TezWork.class), anyMap())).thenAnswer(new Answer<Vertex>() {

        @Override
        public Vertex answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            return Vertex.create(((BaseWork) args[1]).getName(), mock(ProcessorDescriptor.class), 0, mock(Resource.class));
        }
    });
    when(utils.createEdge(any(), any(Vertex.class), any(Vertex.class), any(TezEdgeProperty.class), any(BaseWork.class), any(TezWork.class))).thenAnswer(new Answer<Edge>() {

        @Override
        public Edge answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            return Edge.create((Vertex) args[1], (Vertex) args[2], mock(EdgeProperty.class));
        }
    });
    work = new TezWork("", null);
    mws = new MapWork[] { new MapWork(), new MapWork() };
    rws = new ReduceWork[] { new ReduceWork(), new ReduceWork() };
    work.addAll(mws);
    work.addAll(rws);
    int i = 0;
    for (BaseWork w : work.getAllWork()) {
        w.setName("Work " + (++i));
    }
    op = mock(Operator.class);
    Map<String, Operator<? extends OperatorDesc>> map = new LinkedHashMap<String, Operator<? extends OperatorDesc>>();
    map.put("foo", op);
    mws[0].setAliasToWork(map);
    mws[1].setAliasToWork(map);
    Map<Path, List<String>> pathMap = new LinkedHashMap<>();
    List<String> aliasList = new ArrayList<String>();
    aliasList.add("foo");
    pathMap.put(new Path("foo"), aliasList);
    mws[0].setPathToAliases(pathMap);
    mws[1].setPathToAliases(pathMap);
    rws[0].setReducer(op);
    rws[1].setReducer(op);
    TezEdgeProperty edgeProp = new TezEdgeProperty(EdgeType.SIMPLE_EDGE);
    work.connect(mws[0], rws[0], edgeProp);
    work.connect(mws[1], rws[0], edgeProp);
    work.connect(rws[0], rws[1], edgeProp);
    task = new TezTask(utils);
    task.setWork(work);
    task.setConsole(mock(LogHelper.class));
    QueryPlan mockQueryPlan = mock(QueryPlan.class);
    doReturn(UUID.randomUUID().toString()).when(mockQueryPlan).getQueryId();
    task.setQueryPlan(mockQueryPlan);
    conf = new JobConf();
    appLr = createResource("foo.jar");
    HiveConf hiveConf = new HiveConf();
    hiveConf.setVar(HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER, "org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdHiveAuthorizerFactory");
    SessionState.start(hiveConf);
    session = mock(TezClient.class);
    sessionState = mock(TezSessionState.class);
    when(sessionState.getSession()).thenReturn(session);
    when(sessionState.reopen()).thenReturn(sessionState);
    when(session.submitDAG(any(DAG.class))).thenThrow(new SessionNotRunning("")).thenReturn(mock(DAGClient.class));
}
Also used : Operator(org.apache.hadoop.hive.ql.exec.Operator) Vertex(org.apache.tez.dag.api.Vertex) LogHelper(org.apache.hadoop.hive.ql.session.SessionState.LogHelper) TezEdgeProperty(org.apache.hadoop.hive.ql.plan.TezEdgeProperty) ArrayList(java.util.ArrayList) Mockito.anyString(org.mockito.Mockito.anyString) QueryPlan(org.apache.hadoop.hive.ql.QueryPlan) LinkedHashMap(java.util.LinkedHashMap) TezClient(org.apache.tez.client.TezClient) SessionNotRunning(org.apache.tez.dag.api.SessionNotRunning) FileSystem(org.apache.hadoop.fs.FileSystem) List(java.util.List) ArrayList(java.util.ArrayList) HiveConf(org.apache.hadoop.hive.conf.HiveConf) BaseWork(org.apache.hadoop.hive.ql.plan.BaseWork) JobConf(org.apache.hadoop.mapred.JobConf) Path(org.apache.hadoop.fs.Path) ReduceWork(org.apache.hadoop.hive.ql.plan.ReduceWork) MapWork(org.apache.hadoop.hive.ql.plan.MapWork) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DAGClient(org.apache.tez.dag.api.client.DAGClient) Edge(org.apache.tez.dag.api.Edge) OperatorDesc(org.apache.hadoop.hive.ql.plan.OperatorDesc) TezWork(org.apache.hadoop.hive.ql.plan.TezWork) Before(org.junit.Before)

Example 5 with SessionNotRunning

use of org.apache.tez.dag.api.SessionNotRunning in project tez by apache.

the class TezClientUtils method getAMProxy.

static DAGClientAMProtocolBlockingPB getAMProxy(FrameworkClient yarnClient, Configuration conf, ApplicationId applicationId) throws TezException, IOException {
    ApplicationReport appReport;
    try {
        appReport = yarnClient.getApplicationReport(applicationId);
        if (appReport == null) {
            throw new TezUncheckedException("Could not retrieve application report" + " from YARN, applicationId=" + applicationId);
        }
        YarnApplicationState appState = appReport.getYarnApplicationState();
        if (appState != YarnApplicationState.RUNNING) {
            if (appState == YarnApplicationState.FINISHED || appState == YarnApplicationState.KILLED || appState == YarnApplicationState.FAILED) {
                String msg = "Application not running" + ", applicationId=" + applicationId + ", yarnApplicationState=" + appReport.getYarnApplicationState() + ", finalApplicationStatus=" + appReport.getFinalApplicationStatus() + ", trackingUrl=" + appReport.getTrackingUrl() + ", diagnostics=" + (appReport.getDiagnostics() != null ? appReport.getDiagnostics() : TezClient.NO_CLUSTER_DIAGNOSTICS_MSG);
                LOG.info(msg);
                throw new SessionNotRunning(msg);
            }
            return null;
        }
    } catch (ApplicationNotFoundException e) {
        throw new SessionNotRunning(e);
    } catch (YarnException e) {
        throw new TezException(e);
    }
    return getAMProxy(conf, appReport.getHost(), appReport.getRpcPort(), appReport.getClientToAMToken());
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) TezException(org.apache.tez.dag.api.TezException) TezUncheckedException(org.apache.tez.dag.api.TezUncheckedException) SessionNotRunning(org.apache.tez.dag.api.SessionNotRunning) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) YarnApplicationState(org.apache.hadoop.yarn.api.records.YarnApplicationState) YarnException(org.apache.hadoop.yarn.exceptions.YarnException)

Aggregations

SessionNotRunning (org.apache.tez.dag.api.SessionNotRunning)10 TezException (org.apache.tez.dag.api.TezException)6 IOException (java.io.IOException)5 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)5 DAGClient (org.apache.tez.dag.api.client.DAGClient)4 Test (org.junit.Test)4 TezClient (org.apache.tez.client.TezClient)3 DAG (org.apache.tez.dag.api.DAG)3 LinkedHashMap (java.util.LinkedHashMap)2 Path (org.apache.hadoop.fs.Path)2 Vertex (org.apache.tez.dag.api.Vertex)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 HiveConf (org.apache.hadoop.hive.conf.HiveConf)1 QueryPlan (org.apache.hadoop.hive.ql.QueryPlan)1 Operator (org.apache.hadoop.hive.ql.exec.Operator)1 BaseWork (org.apache.hadoop.hive.ql.plan.BaseWork)1 MapWork (org.apache.hadoop.hive.ql.plan.MapWork)1