Example usage for org.apache.hadoop.yarn.util Times elapsed

List of usage examples for org.apache.hadoop.yarn.util Times elapsed

Introduction

In this page you can find the example usage for org.apache.hadoop.yarn.util Times elapsed.

Prototype

public static long elapsed(long started, long finished) 

Source Link

Usage

From source file:com.datatorrent.stram.webapp.AppInfo.java

License:Apache License

/**
 *
 * @param context//from   ww  w.  java  2  s  . c  o  m
 */
public AppInfo(StramAppContext context) {
    this.appId = context.getApplicationID().toString();
    this.name = context.getApplicationName();
    this.docLink = context.getApplicationDocLink();
    this.user = context.getUser().toString();
    this.startTime = context.getStartTime();
    this.elapsedTime = Times.elapsed(this.startTime, 0);
    this.appPath = context.getApplicationPath();
    this.appMasterTrackingUrl = context.getAppMasterTrackingUrl();
    this.stats = context.getStats();
    this.gatewayAddress = context.getGatewayAddress();
    this.version = VersionInfo.getBuildVersion();
    this.attributes = new TreeMap<String, Object>();
    for (Map.Entry<Attribute<Object>, Object> entry : AttributeMap.AttributeInitializer
            .getAllAttributes(context, DAGContext.class).entrySet()) {
        this.attributes.put(entry.getKey().getSimpleName(), entry.getValue());
    }
    this.gatewayConnected = context.isGatewayConnected();
    this.appDataSources = context.getAppDataSources();
    this.customMetrics = context.getCustomMetrics();
}

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

License:Apache License

@Path("/list")
@GET//  www  . j ava2s. c o m
@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;
}