Java Code Examples for org.apache.hadoop.yarn.api.records.ApplicationReport#getApplicationTags()

The following examples show how to use org.apache.hadoop.yarn.api.records.ApplicationReport#getApplicationTags() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AppInfo.java    From hadoop with Apache License 2.0 6 votes vote down vote up
public AppInfo(ApplicationReport app) {
  appId = app.getApplicationId().toString();
  if (app.getCurrentApplicationAttemptId() != null) {
    currentAppAttemptId = app.getCurrentApplicationAttemptId().toString();
  }
  user = app.getUser();
  queue = app.getQueue();
  name = app.getName();
  type = app.getApplicationType();
  host = app.getHost();
  rpcPort = app.getRpcPort();
  appState = app.getYarnApplicationState();
  diagnosticsInfo = app.getDiagnostics();
  trackingUrl = app.getTrackingUrl();
  originalTrackingUrl = app.getOriginalTrackingUrl();
  submittedTime = app.getStartTime();
  startedTime = app.getStartTime();
  finishedTime = app.getFinishTime();
  elapsedTime = Times.elapsed(startedTime, finishedTime);
  finalAppStatus = app.getFinalApplicationStatus();
  progress = app.getProgress() * 100; // in percent
  if (app.getApplicationTags() != null && !app.getApplicationTags().isEmpty()) {
    this.applicationTags = CSV_JOINER.join(app.getApplicationTags());
  }
}
 
Example 2
Source File: AppInfo.java    From big-c with Apache License 2.0 6 votes vote down vote up
public AppInfo(ApplicationReport app) {
  appId = app.getApplicationId().toString();
  if (app.getCurrentApplicationAttemptId() != null) {
    currentAppAttemptId = app.getCurrentApplicationAttemptId().toString();
  }
  user = app.getUser();
  queue = app.getQueue();
  name = app.getName();
  type = app.getApplicationType();
  host = app.getHost();
  rpcPort = app.getRpcPort();
  appState = app.getYarnApplicationState();
  diagnosticsInfo = app.getDiagnostics();
  trackingUrl = app.getTrackingUrl();
  originalTrackingUrl = app.getOriginalTrackingUrl();
  submittedTime = app.getStartTime();
  startedTime = app.getStartTime();
  finishedTime = app.getFinishTime();
  elapsedTime = Times.elapsed(startedTime, finishedTime);
  finalAppStatus = app.getFinalApplicationStatus();
  progress = app.getProgress() * 100; // in percent
  if (app.getApplicationTags() != null && !app.getApplicationTags().isEmpty()) {
    this.applicationTags = CSV_JOINER.join(app.getApplicationTags());
  }
}
 
Example 3
Source File: ApexCli.java    From Bats with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(String[] args, ConsoleReader reader) throws Exception
{
  try {
    JSONArray jsonArray = new JSONArray();
    List<ApplicationReport> appList = getApplicationList();
    Collections.sort(appList, new Comparator<ApplicationReport>()
    {
      @Override
      public int compare(ApplicationReport o1, ApplicationReport o2)
      {
        return o1.getApplicationId().getId() - o2.getApplicationId().getId();
      }

    });
    int totalCnt = 0;
    int runningCnt = 0;

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");

    for (ApplicationReport ar : appList) {
      /*
       * This is inefficient, but what the heck, if this can be passed through the command line, can anyone notice slowness.
       */
      JSONObject jsonObj = new JSONObject();
      jsonObj.put("startTime", sdf.format(new java.util.Date(ar.getStartTime())));
      jsonObj.put("id", ar.getApplicationId().getId());
      jsonObj.put("name", ar.getName());
      jsonObj.put("state", ar.getYarnApplicationState().name());
      jsonObj.put("trackingUrl", ar.getTrackingUrl());
      jsonObj.put("finalStatus", ar.getFinalApplicationStatus());
      JSONArray tags = new JSONArray();
      for (String tag : ar.getApplicationTags()) {
        tags.put(tag);
      }
      jsonObj.put("tags", tags);

      totalCnt++;
      if (ar.getYarnApplicationState() == YarnApplicationState.RUNNING) {
        runningCnt++;
      }

      if (args.length > 1) {
        if (StringUtils.isNumeric(args[1])) {
          if (jsonObj.getString("id").equals(args[1])) {
            jsonArray.put(jsonObj);
            break;
          }
        } else {
          @SuppressWarnings("unchecked")
          Iterator<String> keys = jsonObj.keys();
          while (keys.hasNext()) {
            if (jsonObj.get(keys.next()).toString().toLowerCase().contains(args[1].toLowerCase())) {
              jsonArray.put(jsonObj);
              break;
            }
          }
        }
      } else {
        jsonArray.put(jsonObj);
      }
    }
    printJson(jsonArray, "apps");
    if (consolePresent) {
      System.out.println(runningCnt + " active, total " + totalCnt + " applications.");
    }
  } catch (Exception ex) {
    throw new CliException("Failed to retrieve application list", ex);
  }
}
 
Example 4
Source File: ApexCli.java    From attic-apex-core with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(String[] args, ConsoleReader reader) throws Exception
{
  try {
    JSONArray jsonArray = new JSONArray();
    List<ApplicationReport> appList = getApplicationList();
    Collections.sort(appList, new Comparator<ApplicationReport>()
    {
      @Override
      public int compare(ApplicationReport o1, ApplicationReport o2)
      {
        return o1.getApplicationId().getId() - o2.getApplicationId().getId();
      }

    });
    int totalCnt = 0;
    int runningCnt = 0;

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");

    for (ApplicationReport ar : appList) {
      /*
       * This is inefficient, but what the heck, if this can be passed through the command line, can anyone notice slowness.
       */
      JSONObject jsonObj = new JSONObject();
      jsonObj.put("startTime", sdf.format(new java.util.Date(ar.getStartTime())));
      jsonObj.put("id", ar.getApplicationId().getId());
      jsonObj.put("name", ar.getName());
      jsonObj.put("state", ar.getYarnApplicationState().name());
      jsonObj.put("trackingUrl", ar.getTrackingUrl());
      jsonObj.put("finalStatus", ar.getFinalApplicationStatus());
      JSONArray tags = new JSONArray();
      for (String tag : ar.getApplicationTags()) {
        tags.put(tag);
      }
      jsonObj.put("tags", tags);

      totalCnt++;
      if (ar.getYarnApplicationState() == YarnApplicationState.RUNNING) {
        runningCnt++;
      }

      if (args.length > 1) {
        if (StringUtils.isNumeric(args[1])) {
          if (jsonObj.getString("id").equals(args[1])) {
            jsonArray.put(jsonObj);
            break;
          }
        } else {
          @SuppressWarnings("unchecked")
          Iterator<String> keys = jsonObj.keys();
          while (keys.hasNext()) {
            if (jsonObj.get(keys.next()).toString().toLowerCase().contains(args[1].toLowerCase())) {
              jsonArray.put(jsonObj);
              break;
            }
          }
        }
      } else {
        jsonArray.put(jsonObj);
      }
    }
    printJson(jsonArray, "apps");
    if (consolePresent) {
      System.out.println(runningCnt + " active, total " + totalCnt + " applications.");
    }
  } catch (Exception ex) {
    throw new CliException("Failed to retrieve application list", ex);
  }
}