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

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

Introduction

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

Prototype

@Public
@Stable
public abstract ApplicationId getApplicationId();

Source Link

Document

Get the ApplicationId of the application.

Usage

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()));
    }//  w  w w. j a  va  2 s. 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.elasticsearch.hadoop.yarn.client.ClientRpc.java

License:Apache License

public List<ApplicationReport> killEsApps() {
    try {/*from  w w  w .j  a v a 2 s.c om*/
        List<ApplicationReport> esApps = client.getApplications(ES_TYPE, ALIVE);

        for (ApplicationReport appReport : esApps) {
            client.killApplication(appReport.getApplicationId());
        }

        return esApps;
    } catch (Exception ex) {
        throw new EsYarnException(ex);
    }
}

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.huahinframework.manager.rest.service.ApplicationService.java

License:Apache License

@Path("/kill/{" + APPLICATION_ID + "}")
@DELETE//from w w  w  . ja va2  s  . com
@Produces(MediaType.APPLICATION_JSON)
public JSONObject kill(@PathParam(APPLICATION_ID) String applicationId) {
    Map<String, String> status = new HashMap<String, String>();
    try {
        GetAllApplicationsRequest getRequest = recordFactory.newRecordInstance(GetAllApplicationsRequest.class);
        GetAllApplicationsResponse getResponse = applicationsManager.getAllApplications(getRequest);
        for (ApplicationReport ar : getResponse.getApplicationList()) {
            if (ar.getApplicationId().toString().equals(applicationId)) {
                KillApplicationRequest killRequest = recordFactory
                        .newRecordInstance(KillApplicationRequest.class);
                killRequest.setApplicationId(ar.getApplicationId());
                applicationsManager.forceKillApplication(killRequest);

                status.put(Response.STATUS, "Killed application " + applicationId);
                break;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        log.error(e);
        status.put(Response.STATUS, e.getMessage());
    }

    if (status.isEmpty()) {
        status.put(Response.STATUS, "Could not find application " + applicationId);
    }

    return new JSONObject(status);
}

From source file:org.springframework.cloud.dataflow.module.deployer.yarn.YarnCloudAppServiceApplication.java

License:Apache License

public Collection<CloudAppInstanceInfo> getSubmittedApplications() {
    List<CloudAppInstanceInfo> appIds = new ArrayList<CloudAppInstanceInfo>();
    for (ApplicationReport report : yarnClient.listApplications("DATAFLOW")) {
        appIds.add(new CloudAppInstanceInfo(report.getApplicationId().toString(), report.getName(),
                report.getYarnApplicationState().toString(), report.getOriginalTrackingUrl()));
    }//from  ww  w .j  a va2  s .com
    return appIds;
}

From source file:org.springframework.cloud.dataflow.yarn.buildtests.AbstractCliBootYarnClusterTests.java

License:Apache License

private ApplicationReport findApplicationReport(YarnClient client, ApplicationId applicationId) {
    Assert.notNull(getYarnClient(), "Yarn client must be set");
    for (ApplicationReport report : client.listApplications()) {
        if (report.getApplicationId().equals(applicationId)) {
            return report;
        }/*  w ww .j  a va  2  s  . c  o  m*/
    }
    return null;
}

From source file:org.springframework.cloud.deployer.spi.yarn.YarnCloudAppServiceApplication.java

License:Apache License

public Collection<CloudAppInstanceInfo> getSubmittedApplications(String yarnApplicationId) {
    List<CloudAppInstanceInfo> appIds = new ArrayList<CloudAppInstanceInfo>();
    for (ApplicationReport report : yarnClient.listApplications("DATAFLOW")) {
        if (report.getApplicationId().toString().equals(yarnApplicationId)) {
            appIds.add(new CloudAppInstanceInfo(report.getApplicationId().toString(), report.getName(),
                    report.getYarnApplicationState().toString(), report.getOriginalTrackingUrl()));
        }/*  w  w w  . j  a  v  a 2 s .  com*/
    }
    return appIds;
}

From source file:org.springframework.yarn.boot.app.AbstractApplicationTests.java

License:Apache License

protected YarnApplicationState findState(YarnClient client, ApplicationId applicationId) {
    YarnApplicationState state = null;//from  w  w w  .  j  a v  a 2  s  .  c  o  m
    for (ApplicationReport report : client.listApplications()) {
        if (report.getApplicationId().equals(applicationId)) {
            state = report.getYarnApplicationState();
            break;
        }
    }
    return state;
}

From source file:org.springframework.yarn.boot.app.AbstractApplicationTests.java

License:Apache License

protected ApplicationReport findApplicationReport(ApplicationId applicationId) throws Exception {
    YarnClient client = getYarnClient();
    for (ApplicationReport report : client.listApplications()) {
        if (report.getApplicationId().equals(applicationId)) {
            client = null;//w  ww . java  2 s .c  o m
            return report;
        }
    }
    client = null;
    return null;
}

From source file:org.springframework.yarn.client.CommandLineClientRunner.java

License:Apache License

/**
 * Query application id.//w ww .j a v a2  s.c  o  m
 *
 * @param client the yarn client
 * @param applicationId the application id
 * @return the application id if exists, NULL otherwise
 */
protected ApplicationId queryApplicationId(YarnClient client, String applicationId) {
    if (!StringUtils.hasText(applicationId)) {
        return null;
    }
    ApplicationId appId = null;
    for (ApplicationReport a : client.listApplications()) {
        if (a.getApplicationId().toString().equals(applicationId)) {
            appId = a.getApplicationId();
            break;
        }
    }
    return appId;
}