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

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

Introduction

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

Prototype

@Public
@Stable
public abstract String getName();

Source Link

Document

Get the user-defined name of the application.

Usage

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

License:Apache License

@Path("/list")
@GET/*  ww  w  .  ja  v  a2s.com*/
@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.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   w w w  .  j  av  a2  s . c  o  m*/
    return appIds;
}

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()));
        }//from  w  w  w.  j  a va  2 s  .c  om
    }
    return appIds;
}

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

License:Apache License

/**
 * Gets the application report table.// w w  w .j a  va  2 s.c  o m
 *
 * @param applications the applications
 * @return the application report table
 */
private static Table getApplicationReportTable(List<ApplicationReport> applications) {
    Table table = new Table();
    table.addHeader(1, new TableHeader("Id")).addHeader(2, new TableHeader("User"))
            .addHeader(3, new TableHeader("Name")).addHeader(4, new TableHeader("Queue"))
            .addHeader(5, new TableHeader("StartTime")).addHeader(6, new TableHeader("FinishTime"))
            .addHeader(7, new TableHeader("State")).addHeader(8, new TableHeader("FinalStatus"));

    for (ApplicationReport a : applications) {
        final TableRow row = new TableRow();
        row.addValue(1, a.getApplicationId().toString()).addValue(2, a.getUser()).addValue(3, a.getName())
                .addValue(4, a.getQueue())
                .addValue(5,
                        DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT)
                                .format(new Date(a.getStartTime())))
                .addValue(6,
                        DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT)
                                .format(new Date(a.getFinishTime())))
                .addValue(7, a.getYarnApplicationState().toString())
                .addValue(8, a.getFinalApplicationStatus().toString());
        table.getRows().add(row);
    }
    return table;
}

From source file:org.trustedanalytics.servicebroker.h2oprovisioner.cdhclients.DeprovisionerYarnClientTest.java

License:Apache License

@Before
public void setUp() {
    expectedYarnJobId1 = mock(ApplicationId.class);
    ApplicationReport yarnJobMetadata1 = mock(ApplicationReport.class);
    when(yarnJobMetadata1.getName()).thenReturn(expectedH2oJobName);
    when(yarnJobMetadata1.getApplicationId()).thenReturn(expectedYarnJobId1);

    // another YarnJob with the same name
    expectedYarnJobId2 = mock(ApplicationId.class);
    ApplicationReport yarnJobMetadata2 = mock(ApplicationReport.class);
    when(yarnJobMetadata2.getName()).thenReturn(expectedH2oJobName);
    when(yarnJobMetadata2.getApplicationId()).thenReturn(expectedYarnJobId2);

    yarnReportWithOneJob = ImmutableList.of(yarnJobMetadata1);
    yarnReportWithNoJobs = ImmutableList.of();
    yarnReportWithTwoJobs = ImmutableList.of(yarnJobMetadata1, yarnJobMetadata2);
}

From source file:yrun.commands.Yps.java

License:Apache License

public static void main(String[] args) throws YarnException, IOException {
    YarnClient yarnClient = YarnClient.createYarnClient();
    YarnConfiguration yarnConfiguration = new YarnConfiguration();
    yarnClient.init(yarnConfiguration);//from   w w w. j  av  a2  s . c om
    yarnClient.start();
    try {
        List<ApplicationReport> applications = yarnClient.getApplications();
        for (ApplicationReport applicationReport : applications) {
            ApplicationId applicationId = applicationReport.getApplicationId();
            String user = applicationReport.getUser();
            String queue = applicationReport.getQueue();
            String name = applicationReport.getName();
            YarnApplicationState yarnApplicationState = applicationReport.getYarnApplicationState();
            float progress = applicationReport.getProgress();
            System.out.printf("%s\t%s\t%s\t%s\t%s\t%f%n", toString(applicationId), user, queue, name,
                    yarnApplicationState.name(), progress);
        }
    } finally {
        yarnClient.stop();
        yarnClient.close();
    }
}