Example usage for org.apache.hadoop.yarn.api.records ApplicationReport getTrackingUrl

List of usage examples for org.apache.hadoop.yarn.api.records ApplicationReport getTrackingUrl

Introduction

In this page you can find the example usage for org.apache.hadoop.yarn.api.records ApplicationReport getTrackingUrl.

Prototype

@Public
@Stable
public abstract String getTrackingUrl();

Source Link

Document

Get the tracking url for the application.

Usage

From source file:org.apache.tez.client.TezClient.java

License:Apache License

@Private // To be used only by YarnRunner
DAGClient submitDAGApplication(ApplicationId appId, DAG dag) throws TezException, IOException {
    LOG.info("Submitting DAG application with id: " + appId);
    try {//from   w w  w .  j av a  2 s .  c  om
        // Use the AMCredentials object in client mode, since this won't be re-used.
        // Ensures we don't fetch credentially unnecessarily if the user has already provided them.
        Credentials credentials = amConfig.getCredentials();
        if (credentials == null) {
            credentials = new Credentials();
        }
        TezClientUtils.processTezLocalCredentialsFile(credentials, amConfig.getTezConfiguration());

        // Add session token for shuffle
        TezClientUtils.createSessionToken(appId.toString(), jobTokenSecretManager, credentials);

        // Add credentials for tez-local resources.
        Map<String, LocalResource> tezJarResources = getTezJarResources(credentials);
        ApplicationSubmissionContext appContext = TezClientUtils.createApplicationSubmissionContext(appId, dag,
                dag.getName(), amConfig, tezJarResources, credentials, usingTezArchiveDeploy, apiVersionInfo,
                historyACLPolicyManager);
        LOG.info("Submitting DAG to YARN" + ", applicationId=" + appId + ", dagName=" + dag.getName());

        frameworkClient.submitApplication(appContext);
        ApplicationReport appReport = frameworkClient.getApplicationReport(appId);
        LOG.info("The url to track the Tez AM: " + appReport.getTrackingUrl());
        lastSubmittedAppId = appId;
    } catch (YarnException e) {
        throw new TezException(e);
    }
    return getDAGClient(appId, amConfig.getTezConfiguration(), frameworkClient);
}

From source file:org.apache.tez.client.TezClientUtils.java

License:Apache License

static DAGClientAMProtocolBlockingPB getSessionAMProxy(FrameworkClient yarnClient, Configuration conf,
        ApplicationId applicationId) throws TezException, IOException {
    ApplicationReport appReport;
    try {/*from   www.j  av  a  2  s.co m*/
        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 (YarnException e) {
        throw new TezException(e);
    }
    return getAMProxy(conf, appReport.getHost(), appReport.getRpcPort(), appReport.getClientToAMToken());
}

From source file:org.dknight.app.UnmanagedAMLauncher.java

License:Apache License

/**
 * Monitor the submitted application for completion. Kill application if time
 * expires./*from   w w  w  .ja  v  a 2  s  .  c om*/
 *
 * @param appId
 *          Application Id of application to be monitored
 * @return true if application completed successfully
 * @throws YarnException
 * @throws IOException
 */
private ApplicationReport monitorApplication(ApplicationId appId, Set<YarnApplicationState> finalState)
        throws YarnException, IOException {

    long foundAMCompletedTime = 0;
    final int timeToWaitMS = 10000;
    StringBuilder expectedFinalState = new StringBuilder();
    boolean first = true;
    for (YarnApplicationState state : finalState) {
        if (first) {
            first = false;
            expectedFinalState.append(state.name());
        } else {
            expectedFinalState.append("," + state.name());
        }
    }

    while (true) {

        // Check app status every 1 second.
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            LOG.debug("Thread sleep in monitoring loop interrupted");
        }

        // Get application report for the appId we are interested in
        ApplicationReport report = rmClient.getApplicationReport(appId);

        LOG.info("Got application report from ASM for" + ", appId=" + appId.getId() + ", appAttemptId="
                + report.getCurrentApplicationAttemptId() + ", 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();
        if (finalState.contains(state)) {
            return report;
        }

        // wait for 10 seconds after process has completed for app report to
        // come back
        if (amCompleted) {
            if (foundAMCompletedTime == 0) {
                foundAMCompletedTime = System.currentTimeMillis();
            } else if ((System.currentTimeMillis() - foundAMCompletedTime) > timeToWaitMS) {
                LOG.warn("Waited " + timeToWaitMS / 1000 + " seconds after process completed for AppReport"
                        + " to reach desired final state. Not waiting anymore." + "CurrentState = " + state
                        + ", ExpectedStates = " + expectedFinalState.toString());
                throw new RuntimeException("Failed to receive final expected state" + " in ApplicationReport"
                        + ", CurrentState=" + state + ", ExpectedStates=" + expectedFinalState.toString());
            }
        }
    }
}

From source file:org.elasticsearch.hadoop.yarn.cli.YarnBootstrap.java

License:Apache License

private void start() {
    ClientRpc client = new ClientRpc(getConf());
    ApplicationId id = null;/*  w  w  w .ja  v a 2s  .  c om*/
    ApplicationReport report = null;

    try {
        YarnLauncher launcher = new YarnLauncher(client, cfg);
        id = launcher.run();
        report = client.getReport(id);
    } finally {
        client.close();
    }

    System.out.println(String.format("Launched a %d %s Elasticsearch-YARN cluster [%s@%s] at %tc",
            cfg.containersToAllocate(), (cfg.containersToAllocate() > 1 ? "nodes" : "node"), id,
            report.getTrackingUrl(), report.getStartTime()));
}

From source file:org.elasticsearch.hadoop.yarn.cli.YarnBootstrap.java

License:Apache License

private String buildStatusReport(List<ApplicationReport> esApps) {
    if (esApps.isEmpty()) {
        return String.format("No Elasticsearch YARN clusters found at %s, webapp at %s",
                getConf().get(YarnConfiguration.RM_ADDRESS),
                WebAppUtils.getRMWebAppURLWithoutScheme(getConf()));
    }/*from www . j a  v  a  2s  .c  o m*/

    String columnSeparator = "  ";
    StringBuilder sb = new StringBuilder();
    // header
    sb.append("Id                            ");
    sb.append(columnSeparator);
    sb.append("State     ");
    sb.append(columnSeparator);
    sb.append("Status   ");
    sb.append(columnSeparator);
    sb.append("Start Time       ");
    sb.append(columnSeparator);
    sb.append("Finish Time      ");
    sb.append(columnSeparator);
    sb.append("Tracking URL");
    sb.append("\n");

    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);

    for (ApplicationReport appReport : esApps) {
        sb.append(appReport.getApplicationId());
        sb.append(columnSeparator);
        sb.append(box(appReport.getYarnApplicationState().toString(), 10));
        sb.append(columnSeparator);
        sb.append(box(appReport.getFinalApplicationStatus().toString(), 9));
        sb.append(columnSeparator);
        long date = appReport.getStartTime();
        sb.append(date == 0 ? "N/A              " : box(dateFormat.format(new Date(date)), 17));
        sb.append(columnSeparator);
        date = appReport.getFinishTime();
        sb.append(date == 0 ? "N/A              " : box(dateFormat.format(new Date(date)), 17));
        sb.append(columnSeparator);
        sb.append(appReport.getTrackingUrl());
        sb.append(columnSeparator);
        sb.append("\n");
    }

    return sb.toString();
}

From source file:org.hdl.caffe.yarn.app.Client.java

License:Apache License

/**
 * Monitor the submitted application for completion.
 *
 * @param appId Application Id of application to be monitored
 * @return true if application completed successfully
 * @throws YarnException/*from   w w  w.java2s .  c o m*/
 * @throws IOException
 */
private boolean monitorApplication(ApplicationId appId) throws YarnException, IOException {

    while (true) {

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            LOG.debug("Thread sleep in monitoring loop interrupted");
        }

        ApplicationReport report = yarnClient.getApplicationReport(appId);

        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() + ", caffeAppFinalState="
                + report.getFinalApplicationStatus().toString() + ", appTrackingUrl=" + report.getTrackingUrl()
                + ", appUser=" + report.getUser());

        YarnApplicationState state = report.getYarnApplicationState();
        FinalApplicationStatus caffeStatus = report.getFinalApplicationStatus();

        if (YarnApplicationState.RUNNING == state) {
            if (appRpc == null) {
                String hostname = report.getHost();
                int port = report.getRpcPort();
                LOG.info("Application master rpc host: " + hostname + "; port: " + port);
                appRpc = new CaffeApplicationRpcClient(hostname, port).getRpc();
            }
        }

        if (YarnApplicationState.FINISHED == state) {
            if (FinalApplicationStatus.SUCCEEDED == caffeStatus) {
                LOG.info("Application has completed successfully. Breaking monitoring loop");
                return true;
            } else {
                LOG.info("Application did finished unsuccessfully." + " YarnState=" + state.toString()
                        + ", appFinalState=" + caffeStatus.toString() + ". Breaking monitoring loop");
                return false;
            }
        } else if (YarnApplicationState.KILLED == state || YarnApplicationState.FAILED == state) {
            LOG.info("Application did not finish." + " YarnState=" + state.toString() + ", appFinalState="
                    + caffeStatus.toString() + ". Breaking monitoring loop");
            return false;
        }
    }

}

From source file:org.hortonworks.dovetail.client.Client.java

License:Apache License

/**
 * Monitor the submitted application for completion. Kill application if
 * time expires./*from   ww  w .j  av  a2  s  .  c o m*/
 * 
 * @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 {

    while (true) {

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            LOG.finest("Thread sleep in monitoring loop interrupted");
        }

        ApplicationReport report = yarnClient.getApplicationReport(appId);

        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 dovetailStatus = report.getFinalApplicationStatus();
        if (YarnApplicationState.FINISHED == state) {
            if (FinalApplicationStatus.SUCCEEDED == dovetailStatus) {
                LOG.info("Application has completed successfully. Breaking monitoring loop");
                return true;
            } else {
                LOG.info("Application did finished unsuccessfully." + " YarnState=" + state.toString()
                        + ", DovetailFinalStatus=" + dovetailStatus.toString() + ". Breaking monitoring loop");
                return false;
            }
        } else if (YarnApplicationState.KILLED == state || YarnApplicationState.FAILED == state) {
            LOG.info("Application did not finish." + " YarnState=" + state.toString() + ", DovetailFinalStatus="
                    + dovetailStatus.toString() + ". Breaking monitoring loop");
            return false;
        }
    }
}

From source file:org.huahinframework.manager.rest.service.ApplicationService.java

License:Apache License

@Path("/list")
@GET// w  w  w  .  j  a v a  2 s . c  om
@Produces(MediaType.APPLICATION_JSON)
public JSONObject list() {
    JSONObject jsonObject = new JSONObject();

    try {
        GetAllApplicationsRequest request = recordFactory.newRecordInstance(GetAllApplicationsRequest.class);
        GetAllApplicationsResponse response = applicationsManager.getAllApplications(request);

        JSONObject appObject = new JSONObject();
        List<JSONObject> apps = new ArrayList<JSONObject>();
        for (ApplicationReport ar : response.getApplicationList()) {
            JSONObject app = new JSONObject();
            app.put(Response.ID, ar.getApplicationId().toString());
            app.put(Response.USER, ar.getUser());
            app.put(Response.NAME, ar.getName());
            app.put(Response.QUEUE, ar.getQueue());
            YarnApplicationState state = ar.getYarnApplicationState();
            app.put(Response.STATE, state);
            app.put(Response.FINAL_STATUS, ar.getFinalApplicationStatus().name());
            String trackingUrl = ar.getTrackingUrl();
            boolean trackingUrlIsNotReady = trackingUrl == null || trackingUrl.isEmpty()
                    || YarnApplicationState.NEW == state || YarnApplicationState.SUBMITTED == state
                    || YarnApplicationState.ACCEPTED == state;
            String trackingUI = trackingUrlIsNotReady ? "UNASSIGNED"
                    : (ar.getFinishTime() == 0 ? "ApplicationMaster" : "History");
            app.put(Response.TRACKING_UI, trackingUI);
            app.put(Response.TRACKING_URL, trackingUrl);
            app.put(Response.DIAGNOSTICS, ar.getDiagnostics());
            app.put(Response.START_TIME, new Date(ar.getStartTime()));
            app.put(Response.FINISHED_TIME, ar.getFinishTime() == 0 ? "" : new Date(ar.getFinishTime()));
            app.put(Response.ELAPSED_TIME,
                    (Times.elapsed(ar.getStartTime(), ar.getFinishTime()) / 1000) + "sec");
            apps.add(app);
        }

        appObject.put(Response.APP, new JSONArray(apps));
        jsonObject.put(Response.APPS, appObject);
    } catch (Exception e) {
        e.printStackTrace();
        log.error(e);
        Map<String, String> status = new HashMap<String, String>();
        status.put(Response.STATUS, e.getMessage());
        jsonObject = new JSONObject(status);
    }

    return jsonObject;
}

From source file:org.starschema.hadoop.yarn.applications.distributedshell.Client.java

License:Apache License

/**
 * Monitor the submitted application for completion. 
 * Kill application if time expires. /*from ww  w.ja  va2 s  . c  om*/
 * @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 {

    while (true) {

        // Check app status every 1 second.
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            LOG.debug("Thread sleep in monitoring loop interrupted");
        }

        // Get application report for the appId we are interested in 
        ApplicationReport report = yarnClient.getApplicationReport(appId);

        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;
        }

        //      if (System.currentTimeMillis() > (clientStartTime + clientTimeout)) {
        //        LOG.info("Reached client specified timeout for application. Killing application");
        //        forceKillApplication(appId);
        //        return false;            
        //      }
    }

}

From source file:proxyyarn.ProxyYarn.java

License:Apache License

private boolean monitorApplication(YarnClient yarnClient, ApplicationId appId)
        throws YarnException, IOException {

    long clientStartTime = System.currentTimeMillis();
    while (true) {

        // Check app status every 1 second.
        try {//from w w w. j a v a 2s  . c o m
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            log.debug("Thread sleep in monitoring loop interrupted");
        }

        // Get application report for the appId we are interested in 
        ApplicationReport report = yarnClient.getApplicationReport(appId);

        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;
        }

        if (System.currentTimeMillis() > (clientStartTime + clientTimeout)) {
            log.info("Reached client specified timeout for application. Killing application");
            forceKillApplication(yarnClient, appId);
            return false;
        }
    }
}