Search in sources :

Example 91 with ApplicationReport

use of org.apache.hadoop.yarn.api.records.ApplicationReport in project kitten by cloudera.

the class KittenClient method handle.

public int handle(YarnClientService service) throws Exception {
    service.startAndWait();
    if (!service.isRunning()) {
        LOG.error("Service failed to startup, exiting...");
        return 1;
    }
    String trackingUrl = null;
    while (service.isRunning()) {
        if (trackingUrl == null) {
            Thread.sleep(1000);
            ApplicationReport report = service.getApplicationReport();
            YarnApplicationState yarnAppState = report.getYarnApplicationState();
            if (yarnAppState == YarnApplicationState.RUNNING) {
                trackingUrl = report.getTrackingUrl();
                if (trackingUrl == null || trackingUrl.isEmpty()) {
                    LOG.info("Application is running, but did not specify a tracking URL");
                    trackingUrl = "";
                } else {
                    LOG.info("Master Tracking URL = " + trackingUrl);
                }
            }
        }
    }
    LOG.info("Checking final app report");
    ApplicationReport report = service.getFinalReport();
    if (report == null || report.getFinalApplicationStatus() != FinalApplicationStatus.SUCCEEDED) {
        return 1;
    }
    LOG.info("Kitten client finishing...");
    return 0;
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) YarnApplicationState(org.apache.hadoop.yarn.api.records.YarnApplicationState)

Example 92 with ApplicationReport

use of org.apache.hadoop.yarn.api.records.ApplicationReport in project kitten by cloudera.

the class YarnClientServiceImpl method runOneIteration.

@Override
protected void runOneIteration() throws Exception {
    if (isApplicationFinished()) {
        LOG.info("Nothing to do, application is finished");
        return;
    }
    ApplicationReport report = getApplicationReport();
    if (report == null) {
        LOG.error("No application report received");
    } else if (DONE.contains(report.getYarnApplicationState()) || report.getFinalApplicationStatus() != FinalApplicationStatus.UNDEFINED) {
        finalReport = report;
        stop();
    }
    // Ensure that we haven't been running for all that long.
    if (parameters.getClientTimeoutMillis() > 0 && stopwatch.elapsedMillis() > parameters.getClientTimeoutMillis()) {
        LOG.warn("Stopping application due to timeout.");
        timeout = true;
        stop();
    }
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport)

Example 93 with ApplicationReport

use of org.apache.hadoop.yarn.api.records.ApplicationReport in project jstorm by alibaba.

the class JstormOnYarn method monitorApplication.

/**
     * Monitor the submitted application for completion.
     * Kill application if time expires.
     *
     * @param appId Application Id of application to be monitored
     * @return true if application completed successfully
     * @throws YarnException
     * @throws IOException
     */
private boolean monitorApplication(ApplicationId appId) throws YarnException, IOException {
    Integer monitorTimes = JOYConstants.MONITOR_TIMES;
    while (true) {
        // Check app status every 1 second.
        try {
            Thread.sleep(JOYConstants.MONITOR_TIME_INTERVAL);
        } catch (InterruptedException e) {
            LOG.debug("Thread sleep in monitoring loop interrupted");
        }
        // Get application report for the appId we are interested in
        ApplicationReport report = jstormClientContext.yarnClient.getApplicationReport(appId);
        try {
            File writename = new File(JOYConstants.RPC_ADDRESS_FILE);
            writename.createNewFile();
            BufferedWriter out = new BufferedWriter(new FileWriter(writename));
            out.write(report.getHost() + JOYConstants.NEW_LINE);
            out.write(report.getRpcPort() + JOYConstants.NEW_LINE);
            out.flush();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        LOG.info("Got application report from ASM for" + ", appId=" + appId.getId() + ", clientToAMToken=" + report.getClientToAMToken() + ", appDiagnostics=" + report.getDiagnostics() + ", appMasterHost=" + report.getHost() + ", appQueue=" + report.getQueue() + ", appMasterRpcPort=" + report.getRpcPort() + ", appStartTime=" + report.getStartTime() + ", yarnAppState=" + report.getYarnApplicationState().toString() + ", distributedFinalState=" + report.getFinalApplicationStatus().toString() + ", appTrackingUrl=" + report.getTrackingUrl() + ", appUser=" + report.getUser());
        YarnApplicationState state = report.getYarnApplicationState();
        FinalApplicationStatus dsStatus = report.getFinalApplicationStatus();
        if (YarnApplicationState.FINISHED == state) {
            if (FinalApplicationStatus.SUCCEEDED == dsStatus) {
                LOG.info("Application has completed successfully. Breaking monitoring loop");
                return true;
            } else {
                LOG.info("Application did finished unsuccessfully." + " YarnState=" + state.toString() + ", DSFinalStatus=" + dsStatus.toString() + ". Breaking monitoring loop");
                return false;
            }
        } else if (YarnApplicationState.KILLED == state || YarnApplicationState.FAILED == state) {
            LOG.info("Application did not finish." + " YarnState=" + state.toString() + ", DSFinalStatus=" + dsStatus.toString() + ". Breaking monitoring loop");
            return false;
        } else if (YarnApplicationState.RUNNING == state) {
            LOG.info("Application is running successfully. Breaking monitoring loop");
            return true;
        } else {
            if (monitorTimes-- <= 0) {
                forceKillApplication(appId);
                return false;
            }
        }
    }
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) FinalApplicationStatus(org.apache.hadoop.yarn.api.records.FinalApplicationStatus) YarnApplicationState(org.apache.hadoop.yarn.api.records.YarnApplicationState) ParseException(org.apache.commons.cli.ParseException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException)

Example 94 with ApplicationReport

use of org.apache.hadoop.yarn.api.records.ApplicationReport in project hadoop by apache.

the class ApplicationHistoryClientService method getApplications.

@Override
public GetApplicationsResponse getApplications(GetApplicationsRequest request) throws YarnException, IOException {
    long startedBegin = request.getStartRange() == null ? 0L : request.getStartRange().getMinimumLong();
    long startedEnd = request.getStartRange() == null ? Long.MAX_VALUE : request.getStartRange().getMaximumLong();
    GetApplicationsResponse response = GetApplicationsResponse.newInstance(new ArrayList<ApplicationReport>(history.getApplications(request.getLimit(), startedBegin, startedEnd).values()));
    return response;
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) GetApplicationsResponse(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsResponse)

Example 95 with ApplicationReport

use of org.apache.hadoop.yarn.api.records.ApplicationReport in project hadoop by apache.

the class ApplicationHistoryManagerOnTimelineStore method getApplications.

@Override
public Map<ApplicationId, ApplicationReport> getApplications(long appsNum, long appStartedTimeBegin, long appStartedTimeEnd) throws YarnException, IOException {
    TimelineEntities entities = timelineDataManager.getEntities(ApplicationMetricsConstants.ENTITY_TYPE, null, null, appStartedTimeBegin, appStartedTimeEnd, null, null, appsNum == Long.MAX_VALUE ? this.maxLoadedApplications : appsNum, EnumSet.allOf(Field.class), UserGroupInformation.getLoginUser());
    Map<ApplicationId, ApplicationReport> apps = new LinkedHashMap<ApplicationId, ApplicationReport>();
    if (entities != null && entities.getEntities() != null) {
        for (TimelineEntity entity : entities.getEntities()) {
            try {
                ApplicationReportExt app = generateApplicationReport(entity, ApplicationReportField.ALL);
                apps.put(app.appReport.getApplicationId(), app.appReport);
            } catch (Exception e) {
                LOG.error("Error on generating application report for " + entity.getEntityId(), e);
            }
        }
    }
    return apps;
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) Field(org.apache.hadoop.yarn.server.timeline.TimelineReader.Field) TimelineEntities(org.apache.hadoop.yarn.api.records.timeline.TimelineEntities) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) TimelineEntity(org.apache.hadoop.yarn.api.records.timeline.TimelineEntity) AuthorizationException(org.apache.hadoop.security.authorize.AuthorizationException) ContainerNotFoundException(org.apache.hadoop.yarn.exceptions.ContainerNotFoundException) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) IOException(java.io.IOException) ApplicationAttemptNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ApplicationReport (org.apache.hadoop.yarn.api.records.ApplicationReport)143 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)65 Test (org.junit.Test)52 IOException (java.io.IOException)41 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)32 YarnApplicationState (org.apache.hadoop.yarn.api.records.YarnApplicationState)29 YarnClient (org.apache.hadoop.yarn.client.api.YarnClient)21 ApplicationNotFoundException (org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException)19 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)18 ApplicationSubmissionContext (org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext)16 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)16 Configuration (org.apache.hadoop.conf.Configuration)14 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)14 ArrayList (java.util.ArrayList)13 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)13 GetApplicationReportRequest (org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportRequest)11 GetApplicationsRequest (org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsRequest)11 GetApplicationReportResponse (org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportResponse)10 ApplicationResourceUsageReport (org.apache.hadoop.yarn.api.records.ApplicationResourceUsageReport)10 ContainerLaunchContext (org.apache.hadoop.yarn.api.records.ContainerLaunchContext)10