Search in sources :

Example 41 with ApplicationNotFoundException

use of org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException in project hadoop by apache.

the class TestYarnCLI method testMoveApplicationAcrossQueuesWithNewCommand.

@Test
public void testMoveApplicationAcrossQueuesWithNewCommand() throws Exception {
    ApplicationCLI cli = createAndGetAppCLI();
    ApplicationId applicationId = ApplicationId.newInstance(1234, 5);
    ApplicationReport newApplicationReport2 = ApplicationReport.newInstance(applicationId, ApplicationAttemptId.newInstance(applicationId, 1), "user", "queue", "appname", "host", 124, null, YarnApplicationState.FINISHED, "diagnostics", "url", 0, 0, FinalApplicationStatus.SUCCEEDED, null, "N/A", 0.53789f, "YARN", null);
    when(client.getApplicationReport(any(ApplicationId.class))).thenReturn(newApplicationReport2);
    int result = cli.run(new String[] { "application", "-appId", applicationId.toString(), "-changeQueue", "targetqueue" });
    assertEquals(0, result);
    verify(client, times(0)).moveApplicationAcrossQueues(any(ApplicationId.class), any(String.class));
    verify(sysOut).println("Application " + applicationId + " has already finished ");
    ApplicationReport newApplicationReport = ApplicationReport.newInstance(applicationId, ApplicationAttemptId.newInstance(applicationId, 1), "user", "queue", "appname", "host", 124, null, YarnApplicationState.RUNNING, "diagnostics", "url", 0, 0, FinalApplicationStatus.SUCCEEDED, null, "N/A", 0.53789f, "YARN", null);
    when(client.getApplicationReport(any(ApplicationId.class))).thenReturn(newApplicationReport);
    result = cli.run(new String[] { "application", "-appId", applicationId.toString(), "-changeQueue", "targetqueue" });
    assertEquals(0, result);
    verify(client).moveApplicationAcrossQueues(any(ApplicationId.class), any(String.class));
    verify(sysOut).println("Moving application application_1234_0005 to queue targetqueue");
    verify(sysOut).println("Successfully completed move.");
    doThrow(new ApplicationNotFoundException("Application with id '" + applicationId + "' doesn't exist in RM.")).when(client).moveApplicationAcrossQueues(applicationId, "targetqueue");
    cli = createAndGetAppCLI();
    try {
        result = cli.run(new String[] { "application", "-appId", applicationId.toString(), "-changeQueue", "targetqueue" });
        Assert.fail();
    } catch (Exception ex) {
        Assert.assertTrue(ex instanceof ApplicationNotFoundException);
        Assert.assertEquals("Application with id '" + applicationId + "' doesn't exist in RM.", ex.getMessage());
    }
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) ContainerNotFoundException(org.apache.hadoop.yarn.exceptions.ContainerNotFoundException) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) ApplicationAttemptNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException) Test(org.junit.Test)

Example 42 with ApplicationNotFoundException

use of org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException in project hadoop by apache.

the class TestYarnCLI method testGetApplicationReportException.

@Test
public void testGetApplicationReportException() throws Exception {
    ApplicationCLI cli = createAndGetAppCLI();
    ApplicationId applicationId = ApplicationId.newInstance(1234, 5);
    when(client.getApplicationReport(any(ApplicationId.class))).thenThrow(new ApplicationNotFoundException("History file for application" + applicationId + " is not found"));
    int exitCode = cli.run(new String[] { "application", "-status", applicationId.toString() });
    verify(sysOut).println("Application with id '" + applicationId + "' doesn't exist in RM or Timeline Server.");
    Assert.assertNotSame("should return non-zero exit code.", 0, exitCode);
}
Also used : ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) Test(org.junit.Test)

Example 43 with ApplicationNotFoundException

use of org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException 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)

Example 44 with ApplicationNotFoundException

use of org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException in project tez by apache.

the class TezClient method getAppMasterStatus.

/**
 * Get the status of the App Master executing the DAG
 * In non-session mode it returns the status of the last submitted DAG App Master
 * In session mode, it returns the status of the App Master hosting the session
 *
 * @return State of the session
 * @throws TezException
 * @throws IOException
 */
public synchronized TezAppMasterStatus getAppMasterStatus() throws TezException, IOException {
    // Supporting per-DAG app master case since user may choose to run the same
    // code in that mode and the code should continue to work. Its easy to provide
    // the correct view for per-DAG app master too.
    ApplicationId appId = null;
    if (isSession) {
        appId = sessionAppId;
    } else {
        appId = lastSubmittedAppId;
    }
    Preconditions.checkState(appId != null, "Cannot get status without starting an application");
    try {
        ApplicationReport appReport = frameworkClient.getApplicationReport(appId);
        switch(appReport.getYarnApplicationState()) {
            case NEW:
            case NEW_SAVING:
            case ACCEPTED:
            case SUBMITTED:
                return TezAppMasterStatus.INITIALIZING;
            case FAILED:
            case KILLED:
                diagnostics = appReport.getDiagnostics();
                LOG.info("App did not succeed. Diagnostics: " + (appReport.getDiagnostics() != null ? appReport.getDiagnostics() : NO_CLUSTER_DIAGNOSTICS_MSG));
                return TezAppMasterStatus.SHUTDOWN;
            case FINISHED:
                return TezAppMasterStatus.SHUTDOWN;
            case RUNNING:
                try {
                    DAGClientAMProtocolBlockingPB proxy = getAMProxy(appId);
                    if (proxy == null) {
                        return TezAppMasterStatus.INITIALIZING;
                    }
                    GetAMStatusResponseProto response = proxy.getAMStatus(null, GetAMStatusRequestProto.newBuilder().build());
                    return DagTypeConverters.convertTezAppMasterStatusFromProto(response.getStatus());
                } catch (TezException e) {
                    LOG.info("Failed to retrieve AM Status via proxy", e);
                } catch (ServiceException e) {
                    LOG.info("Failed to retrieve AM Status via proxy", e);
                }
        }
    } catch (ApplicationNotFoundException e) {
        return TezAppMasterStatus.SHUTDOWN;
    } catch (YarnException e) {
        throw new TezException(e);
    }
    return TezAppMasterStatus.INITIALIZING;
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) TezException(org.apache.tez.dag.api.TezException) DAGClientAMProtocolBlockingPB(org.apache.tez.dag.api.client.rpc.DAGClientAMProtocolBlockingPB) ServiceException(com.google.protobuf.ServiceException) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) GetAMStatusResponseProto(org.apache.tez.dag.api.client.rpc.DAGClientAMProtocolRPC.GetAMStatusResponseProto) YarnException(org.apache.hadoop.yarn.exceptions.YarnException)

Example 45 with ApplicationNotFoundException

use of org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException in project tez by apache.

the class TezClient method stop.

/**
 * Stop the client. This terminates the connection to the YARN cluster.
 * In session mode, this shuts down the session DAG App Master
 * @throws TezException
 * @throws IOException
 */
public synchronized void stop() throws TezException, IOException {
    try {
        if (amKeepAliveService != null) {
            amKeepAliveService.shutdownNow();
        }
        if (sessionStarted.get()) {
            LOG.info("Shutting down Tez Session" + ", sessionName=" + clientName + ", applicationId=" + sessionAppId);
            sessionStopped.set(true);
            boolean sessionShutdownSuccessful = false;
            try {
                DAGClientAMProtocolBlockingPB proxy = getAMProxy(sessionAppId);
                if (proxy != null) {
                    ShutdownSessionRequestProto request = ShutdownSessionRequestProto.newBuilder().build();
                    proxy.shutdownSession(null, request);
                    sessionShutdownSuccessful = true;
                    boolean asynchronousStop = amConfig.getTezConfiguration().getBoolean(TezConfiguration.TEZ_CLIENT_ASYNCHRONOUS_STOP, TezConfiguration.TEZ_CLIENT_ASYNCHRONOUS_STOP_DEFAULT);
                    if (!asynchronousStop) {
                        LOG.info("Waiting until application is in a final state");
                        long currentTimeMillis = System.currentTimeMillis();
                        long timeKillIssued = currentTimeMillis;
                        long killTimeOut = amConfig.getTezConfiguration().getLong(TezConfiguration.TEZ_CLIENT_HARD_KILL_TIMEOUT_MS, TezConfiguration.TEZ_CLIENT_HARD_KILL_TIMEOUT_MS_DEFAULT);
                        ApplicationReport appReport = frameworkClient.getApplicationReport(sessionAppId);
                        while ((currentTimeMillis < timeKillIssued + killTimeOut) && !isJobInTerminalState(appReport.getYarnApplicationState())) {
                            try {
                                Thread.sleep(1000L);
                            } catch (InterruptedException ie) {
                                /**
                                 * interrupted, just break
                                 */
                                break;
                            }
                            currentTimeMillis = System.currentTimeMillis();
                            appReport = frameworkClient.getApplicationReport(sessionAppId);
                        }
                        if (!isJobInTerminalState(appReport.getYarnApplicationState())) {
                            frameworkClient.killApplication(sessionAppId);
                        }
                    }
                }
            } catch (TezException e) {
                LOG.info("Failed to shutdown Tez Session via proxy", e);
            } catch (ServiceException e) {
                LOG.info("Failed to shutdown Tez Session via proxy", e);
            } catch (ApplicationNotFoundException e) {
                LOG.info("Failed to kill nonexistent application " + sessionAppId, e);
            } catch (YarnException e) {
                throw new TezException(e);
            }
            if (!sessionShutdownSuccessful) {
                LOG.info("Could not connect to AM, killing session via YARN" + ", sessionName=" + clientName + ", applicationId=" + sessionAppId);
                try {
                    frameworkClient.killApplication(sessionAppId);
                } catch (ApplicationNotFoundException e) {
                    LOG.info("Failed to kill nonexistent application " + sessionAppId, e);
                } catch (YarnException e) {
                    throw new TezException(e);
                }
            }
        }
    } finally {
        if (frameworkClient != null) {
            frameworkClient.close();
        }
    }
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) TezException(org.apache.tez.dag.api.TezException) DAGClientAMProtocolBlockingPB(org.apache.tez.dag.api.client.rpc.DAGClientAMProtocolBlockingPB) ServiceException(com.google.protobuf.ServiceException) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) ShutdownSessionRequestProto(org.apache.tez.dag.api.client.rpc.DAGClientAMProtocolRPC.ShutdownSessionRequestProto)

Aggregations

ApplicationNotFoundException (org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException)50 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)28 ApplicationReport (org.apache.hadoop.yarn.api.records.ApplicationReport)21 Test (org.junit.Test)21 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)20 IOException (java.io.IOException)19 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)13 ApplicationAttemptNotFoundException (org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException)12 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)11 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)9 ContainerNotFoundException (org.apache.hadoop.yarn.exceptions.ContainerNotFoundException)7 GetApplicationReportRequest (org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportRequest)6 RecordFactory (org.apache.hadoop.yarn.factories.RecordFactory)6 RMAppAttempt (org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt)5 TezException (org.apache.tez.dag.api.TezException)5 GetApplicationReportResponse (org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportResponse)4 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)4 YarnClient (org.apache.hadoop.yarn.client.api.YarnClient)4 ServiceException (com.google.protobuf.ServiceException)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3