Search in sources :

Example 36 with ApplicationNotFoundException

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

the class ApplicationCLI method killApplication.

/**
   * Kills the application with the application id as appId
   * 
   * @param applicationId
   * @throws YarnException
   * @throws IOException
   */
private void killApplication(String applicationId) throws YarnException, IOException {
    ApplicationId appId = ApplicationId.fromString(applicationId);
    ApplicationReport appReport = null;
    try {
        appReport = client.getApplicationReport(appId);
    } catch (ApplicationNotFoundException e) {
        sysout.println("Application with id '" + applicationId + "' doesn't exist in RM.");
        throw e;
    }
    if (appReport.getYarnApplicationState() == YarnApplicationState.FINISHED || appReport.getYarnApplicationState() == YarnApplicationState.KILLED || appReport.getYarnApplicationState() == YarnApplicationState.FAILED) {
        sysout.println("Application " + applicationId + " has already finished ");
    } else {
        sysout.println("Killing application " + applicationId);
        client.killApplication(appId);
    }
}
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)

Example 37 with ApplicationNotFoundException

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

the class ApplicationCLI method printApplicationReport.

/**
   * Prints the application report for an application id.
   * 
   * @param applicationId
   * @return exitCode
   * @throws YarnException
   */
private int printApplicationReport(String applicationId) throws YarnException, IOException {
    ApplicationReport appReport = null;
    try {
        appReport = client.getApplicationReport(ApplicationId.fromString(applicationId));
    } catch (ApplicationNotFoundException e) {
        sysout.println("Application with id '" + applicationId + "' doesn't exist in RM or Timeline Server.");
        return -1;
    }
    // Use PrintWriter.println, which uses correct platform line ending.
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintWriter appReportStr = new PrintWriter(new OutputStreamWriter(baos, Charset.forName("UTF-8")));
    if (appReport != null) {
        appReportStr.println("Application Report : ");
        appReportStr.print("\tApplication-Id : ");
        appReportStr.println(appReport.getApplicationId());
        appReportStr.print("\tApplication-Name : ");
        appReportStr.println(appReport.getName());
        appReportStr.print("\tApplication-Type : ");
        appReportStr.println(appReport.getApplicationType());
        appReportStr.print("\tUser : ");
        appReportStr.println(appReport.getUser());
        appReportStr.print("\tQueue : ");
        appReportStr.println(appReport.getQueue());
        appReportStr.print("\tApplication Priority : ");
        appReportStr.println(appReport.getPriority());
        appReportStr.print("\tStart-Time : ");
        appReportStr.println(appReport.getStartTime());
        appReportStr.print("\tFinish-Time : ");
        appReportStr.println(appReport.getFinishTime());
        appReportStr.print("\tProgress : ");
        DecimalFormat formatter = new DecimalFormat("###.##%");
        String progress = formatter.format(appReport.getProgress());
        appReportStr.println(progress);
        appReportStr.print("\tState : ");
        appReportStr.println(appReport.getYarnApplicationState());
        appReportStr.print("\tFinal-State : ");
        appReportStr.println(appReport.getFinalApplicationStatus());
        appReportStr.print("\tTracking-URL : ");
        appReportStr.println(appReport.getOriginalTrackingUrl());
        appReportStr.print("\tRPC Port : ");
        appReportStr.println(appReport.getRpcPort());
        appReportStr.print("\tAM Host : ");
        appReportStr.println(appReport.getHost());
        appReportStr.print("\tAggregate Resource Allocation : ");
        ApplicationResourceUsageReport usageReport = appReport.getApplicationResourceUsageReport();
        if (usageReport != null) {
            //completed app report in the timeline server doesn't have usage report
            appReportStr.print(usageReport.getMemorySeconds() + " MB-seconds, ");
            appReportStr.println(usageReport.getVcoreSeconds() + " vcore-seconds");
            appReportStr.print("\tAggregate Resource Preempted : ");
            appReportStr.print(usageReport.getPreemptedMemorySeconds() + " MB-seconds, ");
            appReportStr.println(usageReport.getPreemptedVcoreSeconds() + " vcore-seconds");
        } else {
            appReportStr.println("N/A");
            appReportStr.print("\tAggregate Resource Preempted : ");
            appReportStr.println("N/A");
        }
        appReportStr.print("\tLog Aggregation Status : ");
        appReportStr.println(appReport.getLogAggregationStatus() == null ? "N/A" : appReport.getLogAggregationStatus());
        appReportStr.print("\tDiagnostics : ");
        appReportStr.println(appReport.getDiagnostics());
        appReportStr.print("\tUnmanaged Application : ");
        appReportStr.println(appReport.isUnmanagedApp());
        appReportStr.print("\tApplication Node Label Expression : ");
        appReportStr.println(appReport.getAppNodeLabelExpression());
        appReportStr.print("\tAM container Node Label Expression : ");
        appReportStr.println(appReport.getAmNodeLabelExpression());
        for (ApplicationTimeout timeout : appReport.getApplicationTimeouts().values()) {
            appReportStr.print("\tTimeoutType : " + timeout.getTimeoutType());
            appReportStr.print("\tExpiryTime : " + timeout.getExpiryTime());
            appReportStr.println("\tRemainingTime : " + timeout.getRemainingTime() + "seconds");
        }
    } else {
        appReportStr.print("Application with id '" + applicationId + "' doesn't exist in RM.");
        appReportStr.close();
        sysout.println(baos.toString("UTF-8"));
        return -1;
    }
    appReportStr.close();
    sysout.println(baos.toString("UTF-8"));
    return 0;
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) DecimalFormat(java.text.DecimalFormat) ApplicationResourceUsageReport(org.apache.hadoop.yarn.api.records.ApplicationResourceUsageReport) ApplicationTimeout(org.apache.hadoop.yarn.api.records.ApplicationTimeout) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PrintWriter(java.io.PrintWriter)

Example 38 with ApplicationNotFoundException

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

the class AsterixYARNClient method execute.

public static void execute(AsterixYARNClient client) throws IOException, YarnException {
    YarnClientApplication app;
    List<DFSResourceCoordinate> res;
    System.out.println("JAVA HOME: " + JAVA_HOME);
    switch(client.mode) {
        case START:
            startAction(client);
            break;
        case STOP:
            try {
                client.stopInstance();
            } catch (ApplicationNotFoundException e) {
                LOG.info(e);
                System.out.println("Asterix instance by that name already exited or was never started");
                client.deleteLockFile();
            }
            break;
        case KILL:
            if (client.isRunning() && Utils.confirmAction("Are you sure you want to kill this instance? In-progress tasks will be aborted")) {
                try {
                    AsterixYARNClient.killApplication(client.getLockFile(), client.yarnClient);
                } catch (ApplicationNotFoundException e) {
                    LOG.info(e);
                    System.out.println("Asterix instance by that name already exited or was never started");
                    client.deleteLockFile();
                }
            } else if (!client.isRunning()) {
                System.out.println("Asterix instance by that name already exited or was never started");
                client.deleteLockFile();
            }
            break;
        case DESCRIBE:
            Utils.listInstances(client.conf, CONF_DIR_REL);
            break;
        case INSTALL:
            installAction(client);
            break;
        case LIBINSTALL:
            client.installExtLibs();
            break;
        case ALTER:
            client.writeAsterixConfig(Utils.parseYarnClusterConfig(client.asterixConf));
            client.installAsterixConfig(true);
            System.out.println("Configuration successfully modified");
            break;
        case DESTROY:
            try {
                if (client.force || Utils.confirmAction("Are you really sure you want to obliterate this instance? This action cannot be undone!")) {
                    app = client.makeApplicationContext();
                    res = client.deployConfig();
                    res.addAll(client.distributeBinaries());
                    client.removeInstance(app, res);
                }
            } catch (YarnException | IOException e) {
                LOG.error("Asterix failed to deploy on to cluster");
                throw e;
            }
            break;
        case BACKUP:
            if (client.force || Utils.confirmAction("Performing a backup will stop a running instance.")) {
                app = client.makeApplicationContext();
                res = client.deployConfig();
                res.addAll(client.distributeBinaries());
                client.backupInstance(app, res);
            }
            break;
        case LSBACKUP:
            Utils.listBackups(client.conf, CONF_DIR_REL, client.instanceName);
            break;
        case RMBACKUP:
            Utils.rmBackup(client.conf, CONF_DIR_REL, client.instanceName, Long.parseLong(client.snapName));
            break;
        case RESTORE:
            if (client.force || Utils.confirmAction("Performing a restore will stop a running instance.")) {
                app = client.makeApplicationContext();
                res = client.deployConfig();
                res.addAll(client.distributeBinaries());
                client.restoreInstance(app, res);
            }
            break;
        default:
            LOG.fatal("Unknown mode. Known client modes are: start, stop, install, describe, kill, destroy, describe, backup, restore, lsbackup, rmbackup");
            client.printUsage();
            System.exit(-1);
    }
}
Also used : YarnClientApplication(org.apache.hadoop.yarn.client.api.YarnClientApplication) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) IOException(java.io.IOException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException)

Example 39 with ApplicationNotFoundException

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

the class TestYarnCLI method testKillApplications.

@Test
public void testKillApplications() throws Exception {
    ApplicationCLI cli = createAndGetAppCLI();
    ApplicationId applicationId1 = ApplicationId.newInstance(1234, 5);
    ApplicationId applicationId2 = ApplicationId.newInstance(1234, 6);
    ApplicationId applicationId3 = ApplicationId.newInstance(1234, 7);
    ApplicationId applicationId4 = ApplicationId.newInstance(1234, 8);
    // Test Scenario 1: Both applications are FINISHED.
    ApplicationReport newApplicationReport1 = ApplicationReport.newInstance(applicationId1, ApplicationAttemptId.newInstance(applicationId1, 1), "user", "queue", "appname", "host", 124, null, YarnApplicationState.FINISHED, "diagnostics", "url", 0, 0, FinalApplicationStatus.SUCCEEDED, null, "N/A", 0.53789f, "YARN", null);
    ApplicationReport newApplicationReport2 = ApplicationReport.newInstance(applicationId2, ApplicationAttemptId.newInstance(applicationId2, 1), "user", "queue", "appname", "host", 124, null, YarnApplicationState.FINISHED, "diagnostics", "url", 0, 0, FinalApplicationStatus.SUCCEEDED, null, "N/A", 0.34344f, "YARN", null);
    when(client.getApplicationReport(applicationId1)).thenReturn(newApplicationReport1);
    when(client.getApplicationReport(applicationId2)).thenReturn(newApplicationReport2);
    int result = cli.run(new String[] { "application", "-kill", applicationId1.toString() + " " + applicationId2.toString() });
    assertEquals(0, result);
    verify(client, times(0)).killApplication(applicationId1);
    verify(client, times(0)).killApplication(applicationId2);
    verify(sysOut).println("Application " + applicationId1 + " has already finished ");
    verify(sysOut).println("Application " + applicationId2 + " has already finished ");
    // Test Scenario 2: Both applications are RUNNING.
    ApplicationReport newApplicationReport3 = ApplicationReport.newInstance(applicationId1, ApplicationAttemptId.newInstance(applicationId1, 1), "user", "queue", "appname", "host", 124, null, YarnApplicationState.RUNNING, "diagnostics", "url", 0, 0, FinalApplicationStatus.SUCCEEDED, null, "N/A", 0.53789f, "YARN", null);
    ApplicationReport newApplicationReport4 = ApplicationReport.newInstance(applicationId2, ApplicationAttemptId.newInstance(applicationId2, 1), "user", "queue", "appname", "host", 124, null, YarnApplicationState.RUNNING, "diagnostics", "url", 0, 0, FinalApplicationStatus.SUCCEEDED, null, "N/A", 0.53345f, "YARN", null);
    when(client.getApplicationReport(applicationId1)).thenReturn(newApplicationReport3);
    when(client.getApplicationReport(applicationId2)).thenReturn(newApplicationReport4);
    result = cli.run(new String[] { "application", "-kill", applicationId1.toString() + " " + applicationId2.toString() });
    assertEquals(0, result);
    verify(client).killApplication(applicationId1);
    verify(client).killApplication(applicationId2);
    verify(sysOut).println("Killing application application_1234_0005");
    verify(sysOut).println("Killing application application_1234_0006");
    // Test Scenario 3: Both applications are not present.
    doThrow(new ApplicationNotFoundException("Application with id '" + applicationId3 + "' doesn't exist in RM.")).when(client).getApplicationReport(applicationId3);
    doThrow(new ApplicationNotFoundException("Application with id '" + applicationId4 + "' doesn't exist in RM.")).when(client).getApplicationReport(applicationId4);
    result = cli.run(new String[] { "application", "-kill", applicationId3.toString() + " " + applicationId4.toString() });
    Assert.assertNotEquals(0, result);
    verify(sysOut).println("Application with id 'application_1234_0007' doesn't exist in RM.");
    verify(sysOut).println("Application with id 'application_1234_0008' doesn't exist in RM.");
    // Test Scenario 4: one application is not present and other RUNNING
    doThrow(new ApplicationNotFoundException("Application with id '" + applicationId3 + "' doesn't exist in RM.")).when(client).getApplicationReport(applicationId3);
    ApplicationReport newApplicationReport5 = ApplicationReport.newInstance(applicationId1, ApplicationAttemptId.newInstance(applicationId1, 1), "user", "queue", "appname", "host", 124, null, YarnApplicationState.RUNNING, "diagnostics", "url", 0, 0, FinalApplicationStatus.SUCCEEDED, null, "N/A", 0.53345f, "YARN", null);
    when(client.getApplicationReport(applicationId1)).thenReturn(newApplicationReport5);
    result = cli.run(new String[] { "application", "-kill", applicationId3.toString() + " " + applicationId1.toString() });
    Assert.assertEquals(0, result);
    // Test Scenario 5: kill operation with some other command.
    sysOutStream.reset();
    result = cli.run(new String[] { "application", "--appStates", "RUNNING", "-kill", applicationId3.toString() + " " + applicationId1.toString() });
    Assert.assertEquals(-1, result);
    Assert.assertEquals(createApplicationCLIHelpMessage(), sysOutStream.toString());
}
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) Test(org.junit.Test)

Example 40 with ApplicationNotFoundException

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

the class TestYarnCLI method testGetContainerReportException.

@Test
public void testGetContainerReportException() throws Exception {
    ApplicationCLI cli = createAndGetAppCLI();
    ApplicationId applicationId = ApplicationId.newInstance(1234, 5);
    ApplicationAttemptId attemptId = ApplicationAttemptId.newInstance(applicationId, 1);
    long cntId = 1;
    ContainerId containerId1 = ContainerId.newContainerId(attemptId, cntId++);
    when(client.getContainerReport(containerId1)).thenThrow(new ApplicationNotFoundException("History file for application" + applicationId + " is not found"));
    int exitCode = cli.run(new String[] { "container", "-status", containerId1.toString() });
    verify(sysOut).println("Application for Container with id '" + containerId1 + "' doesn't exist in RM or Timeline Server.");
    Assert.assertNotSame("should return non-zero exit code.", 0, exitCode);
    ContainerId containerId2 = ContainerId.newContainerId(attemptId, cntId++);
    when(client.getContainerReport(containerId2)).thenThrow(new ApplicationAttemptNotFoundException("History file for application attempt" + attemptId + " is not found"));
    exitCode = cli.run(new String[] { "container", "-status", containerId2.toString() });
    verify(sysOut).println("Application Attempt for Container with id '" + containerId2 + "' doesn't exist in RM or Timeline Server.");
    Assert.assertNotSame("should return non-zero exit code.", 0, exitCode);
    ContainerId containerId3 = ContainerId.newContainerId(attemptId, cntId++);
    when(client.getContainerReport(containerId3)).thenThrow(new ContainerNotFoundException("History file for container" + containerId3 + " is not found"));
    exitCode = cli.run(new String[] { "container", "-status", containerId3.toString() });
    verify(sysOut).println("Container with id '" + containerId3 + "' doesn't exist in RM or Timeline Server.");
    Assert.assertNotSame("should return non-zero exit code.", 0, exitCode);
}
Also used : ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) ContainerNotFoundException(org.apache.hadoop.yarn.exceptions.ContainerNotFoundException) ApplicationAttemptNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException) Test(org.junit.Test)

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