Java Code Examples for org.apache.hadoop.yarn.api.records.YarnApplicationState#values()

The following examples show how to use org.apache.hadoop.yarn.api.records.YarnApplicationState#values() . 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: NavBlock.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override public void render(Block html) {
  UL<DIV<Hamlet>> mainList = html.
    div("#nav").
      h3("Cluster").
      ul().
        li().a(url("cluster"), "About")._().
        li().a(url("nodes"), "Nodes")._().
        li().a(url("nodelabels"), "Node Labels")._();
  UL<LI<UL<DIV<Hamlet>>>> subAppsList = mainList.
        li().a(url("apps"), "Applications").
          ul();
  subAppsList.li()._();
  for (YarnApplicationState state : YarnApplicationState.values()) {
    subAppsList.
            li().a(url("apps", state.toString()), state.toString())._();
  }
  subAppsList._()._();
  mainList.
        li().a(url("scheduler"), "Scheduler")._()._().
      h3("Tools").
      ul().
        li().a("/conf", "Configuration")._().
        li().a("/logs", "Local logs")._().
        li().a("/stacks", "Server stacks")._().
        li().a("/jmx?qry=Hadoop:*", "Server metrics")._()._()._();
}
 
Example 2
Source File: TestTypeConverter.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testEnums() throws Exception {
  for (YarnApplicationState applicationState : YarnApplicationState.values()) {
    TypeConverter.fromYarn(applicationState, FinalApplicationStatus.FAILED);
  }
  // ad hoc test of NEW_SAVING, which is newly added
  Assert.assertEquals(State.PREP, TypeConverter.fromYarn(
      YarnApplicationState.NEW_SAVING, FinalApplicationStatus.FAILED));
  
  for (TaskType taskType : TaskType.values()) {
    TypeConverter.fromYarn(taskType);
  }
  
  for (JobState jobState : JobState.values()) {
    TypeConverter.fromYarn(jobState);
  }
  
  for (QueueState queueState : QueueState.values()) {
    TypeConverter.fromYarn(queueState);
  }
  
  for (TaskState taskState : TaskState.values()) {
    TypeConverter.fromYarn(taskState);
  }
}
 
Example 3
Source File: NavBlock.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Override public void render(Block html) {
  UL<DIV<Hamlet>> mainList = html.
    div("#nav").
      h3("Cluster").
      ul().
        li().a(url("cluster"), "About")._().
        li().a(url("nodes"), "Nodes")._().
        li().a(url("nodelabels"), "Node Labels")._();
  UL<LI<UL<DIV<Hamlet>>>> subAppsList = mainList.
        li().a(url("apps"), "Applications").
          ul();
  subAppsList.li()._();
  for (YarnApplicationState state : YarnApplicationState.values()) {
    subAppsList.
            li().a(url("apps", state.toString()), state.toString())._();
  }
  subAppsList._()._();
  mainList.
        li().a(url("scheduler"), "Scheduler")._()._().
      h3("Tools").
      ul().
        li().a("/conf", "Configuration")._().
        li().a("/logs", "Local logs")._().
        li().a("/stacks", "Server stacks")._().
        li().a("/jmx?qry=Hadoop:*", "Server metrics")._()._()._();
}
 
Example 4
Source File: TestTypeConverter.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testEnums() throws Exception {
  for (YarnApplicationState applicationState : YarnApplicationState.values()) {
    TypeConverter.fromYarn(applicationState, FinalApplicationStatus.FAILED);
  }
  // ad hoc test of NEW_SAVING, which is newly added
  Assert.assertEquals(State.PREP, TypeConverter.fromYarn(
      YarnApplicationState.NEW_SAVING, FinalApplicationStatus.FAILED));
  
  for (TaskType taskType : TaskType.values()) {
    TypeConverter.fromYarn(taskType);
  }
  
  for (JobState jobState : JobState.values()) {
    TypeConverter.fromYarn(jobState);
  }
  
  for (QueueState queueState : QueueState.values()) {
    TypeConverter.fromYarn(queueState);
  }
  
  for (TaskState taskState : TaskState.values()) {
    TypeConverter.fromYarn(taskState);
  }
}
 
Example 5
Source File: GetApplicationsRequestPBImpl.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public void setApplicationStates(Set<String> applicationStates) {
  EnumSet<YarnApplicationState> appStates = null;
  for (YarnApplicationState state : YarnApplicationState.values()) {
    if (applicationStates.contains(
        StringUtils.toLowerCase(state.name()))) {
      if (appStates == null) {
        appStates = EnumSet.of(state);
      } else {
        appStates.add(state);
      }
    }
  }
  setApplicationStates(appStates);
}
 
Example 6
Source File: WebServices.java    From hadoop with Apache License 2.0 5 votes vote down vote up
protected static Set<String>
    parseQueries(Set<String> queries, boolean isState) {
  Set<String> params = new HashSet<String>();
  if (!queries.isEmpty()) {
    for (String query : queries) {
      if (query != null && !query.trim().isEmpty()) {
        String[] paramStrs = query.split(",");
        for (String paramStr : paramStrs) {
          if (paramStr != null && !paramStr.trim().isEmpty()) {
            if (isState) {
              try {
                // enum string is in the uppercase
                YarnApplicationState.valueOf(
                    StringUtils.toUpperCase(paramStr.trim()));
              } catch (RuntimeException e) {
                YarnApplicationState[] stateArray =
                    YarnApplicationState.values();
                String allAppStates = Arrays.toString(stateArray);
                throw new BadRequestException("Invalid application-state "
                    + paramStr.trim() + " specified. It should be one of "
                    + allAppStates);
              }
            }
            params.add(StringUtils.toLowerCase(paramStr.trim()));
          }
        }
      }
    }
  }
  return params;
}
 
Example 7
Source File: RMWebServices.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private static Set<String> parseQueries(
    Set<String> queries, boolean isState) {
  Set<String> params = new HashSet<String>();
  if (!queries.isEmpty()) {
    for (String query : queries) {
      if (query != null && !query.trim().isEmpty()) {
        String[] paramStrs = query.split(",");
        for (String paramStr : paramStrs) {
          if (paramStr != null && !paramStr.trim().isEmpty()) {
            if (isState) {
              try {
                // enum string is in the uppercase
                YarnApplicationState.valueOf(
                    StringUtils.toUpperCase(paramStr.trim()));
              } catch (RuntimeException e) {
                YarnApplicationState[] stateArray =
                    YarnApplicationState.values();
                String allAppStates = Arrays.toString(stateArray);
                throw new BadRequestException(
                    "Invalid application-state " + paramStr.trim()
                    + " specified. It should be one of " + allAppStates);
              }
            }
            params.add(
                StringUtils.toLowerCase(paramStr.trim()));
          }
        }
      }
    }
  }
  return params;
}
 
Example 8
Source File: ApplicationCLI.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Lists the applications matching the given application Types And application
 * States present in the Resource Manager
 * 
 * @param appTypes
 * @param appStates
 * @throws YarnException
 * @throws IOException
 */
private void listApplications(Set<String> appTypes,
    EnumSet<YarnApplicationState> appStates) throws YarnException,
    IOException {
  PrintWriter writer = new PrintWriter(
      new OutputStreamWriter(sysout, Charset.forName("UTF-8")));
  if (allAppStates) {
    for (YarnApplicationState appState : YarnApplicationState.values()) {
      appStates.add(appState);
    }
  } else {
    if (appStates.isEmpty()) {
      appStates.add(YarnApplicationState.RUNNING);
      appStates.add(YarnApplicationState.ACCEPTED);
      appStates.add(YarnApplicationState.SUBMITTED);
    }
  }

  List<ApplicationReport> appsReport = client.getApplications(appTypes,
      appStates);

  writer.println("Total number of applications (application-types: "
      + appTypes + " and states: " + appStates + ")" + ":"
      + appsReport.size());
  writer.printf(APPLICATIONS_PATTERN, "Application-Id", "Application-Name",
      "Application-Type", "User", "Queue", "State", "Final-State",
      "Progress", "Tracking-URL");
  for (ApplicationReport appReport : appsReport) {
    DecimalFormat formatter = new DecimalFormat("###.##%");
    String progress = formatter.format(appReport.getProgress());
    writer.printf(APPLICATIONS_PATTERN, appReport.getApplicationId(),
        appReport.getName(), appReport.getApplicationType(), appReport
            .getUser(), appReport.getQueue(), appReport
            .getYarnApplicationState(),
        appReport.getFinalApplicationStatus(), progress, appReport
            .getOriginalTrackingUrl());
  }
  writer.flush();
}
 
Example 9
Source File: ApplicationCLI.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private String getAllValidApplicationStates() {
  StringBuilder sb = new StringBuilder();
  sb.append("The valid application state can be" + " one of the following: ");
  sb.append(ALLSTATES_OPTION + ",");
  for (YarnApplicationState appState : YarnApplicationState.values()) {
    sb.append(appState + ",");
  }
  String output = sb.toString();
  return output.substring(0, output.length() - 1);
}
 
Example 10
Source File: TestYarnCLI.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private List<ApplicationReport> getApplicationReports(
    List<ApplicationReport> applicationReports,
    Set<String> appTypes, EnumSet<YarnApplicationState> appStates,
    boolean allStates) {

  List<ApplicationReport> appReports = new ArrayList<ApplicationReport>();

  if (allStates) {
    for(YarnApplicationState state : YarnApplicationState.values()) {
      appStates.add(state);
    }
  }
  for (ApplicationReport appReport : applicationReports) {
    if (appTypes != null && !appTypes.isEmpty()) {
      if (!appTypes.contains(appReport.getApplicationType())) {
        continue;
      }
    }

    if (appStates != null && !appStates.isEmpty()) {
      if (!appStates.contains(appReport.getYarnApplicationState())) {
        continue;
      }
    }

    appReports.add(appReport);
  }
  return appReports;
}
 
Example 11
Source File: GetApplicationsRequestPBImpl.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public void setApplicationStates(Set<String> applicationStates) {
  EnumSet<YarnApplicationState> appStates = null;
  for (YarnApplicationState state : YarnApplicationState.values()) {
    if (applicationStates.contains(
        StringUtils.toLowerCase(state.name()))) {
      if (appStates == null) {
        appStates = EnumSet.of(state);
      } else {
        appStates.add(state);
      }
    }
  }
  setApplicationStates(appStates);
}
 
Example 12
Source File: WebServices.java    From big-c with Apache License 2.0 5 votes vote down vote up
protected static Set<String>
    parseQueries(Set<String> queries, boolean isState) {
  Set<String> params = new HashSet<String>();
  if (!queries.isEmpty()) {
    for (String query : queries) {
      if (query != null && !query.trim().isEmpty()) {
        String[] paramStrs = query.split(",");
        for (String paramStr : paramStrs) {
          if (paramStr != null && !paramStr.trim().isEmpty()) {
            if (isState) {
              try {
                // enum string is in the uppercase
                YarnApplicationState.valueOf(
                    StringUtils.toUpperCase(paramStr.trim()));
              } catch (RuntimeException e) {
                YarnApplicationState[] stateArray =
                    YarnApplicationState.values();
                String allAppStates = Arrays.toString(stateArray);
                throw new BadRequestException("Invalid application-state "
                    + paramStr.trim() + " specified. It should be one of "
                    + allAppStates);
              }
            }
            params.add(StringUtils.toLowerCase(paramStr.trim()));
          }
        }
      }
    }
  }
  return params;
}
 
Example 13
Source File: RMWebServices.java    From big-c with Apache License 2.0 5 votes vote down vote up
private static Set<String> parseQueries(
    Set<String> queries, boolean isState) {
  Set<String> params = new HashSet<String>();
  if (!queries.isEmpty()) {
    for (String query : queries) {
      if (query != null && !query.trim().isEmpty()) {
        String[] paramStrs = query.split(",");
        for (String paramStr : paramStrs) {
          if (paramStr != null && !paramStr.trim().isEmpty()) {
            if (isState) {
              try {
                // enum string is in the uppercase
                YarnApplicationState.valueOf(
                    StringUtils.toUpperCase(paramStr.trim()));
              } catch (RuntimeException e) {
                YarnApplicationState[] stateArray =
                    YarnApplicationState.values();
                String allAppStates = Arrays.toString(stateArray);
                throw new BadRequestException(
                    "Invalid application-state " + paramStr.trim()
                    + " specified. It should be one of " + allAppStates);
              }
            }
            params.add(
                StringUtils.toLowerCase(paramStr.trim()));
          }
        }
      }
    }
  }
  return params;
}
 
Example 14
Source File: ApplicationCLI.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Lists the applications matching the given application Types And application
 * States present in the Resource Manager
 * 
 * @param appTypes
 * @param appStates
 * @throws YarnException
 * @throws IOException
 */
private void listApplications(Set<String> appTypes,
    EnumSet<YarnApplicationState> appStates) throws YarnException,
    IOException {
  PrintWriter writer = new PrintWriter(
      new OutputStreamWriter(sysout, Charset.forName("UTF-8")));
  if (allAppStates) {
    for (YarnApplicationState appState : YarnApplicationState.values()) {
      appStates.add(appState);
    }
  } else {
    if (appStates.isEmpty()) {
      appStates.add(YarnApplicationState.RUNNING);
      appStates.add(YarnApplicationState.ACCEPTED);
      appStates.add(YarnApplicationState.SUBMITTED);
    }
  }

  List<ApplicationReport> appsReport = client.getApplications(appTypes,
      appStates);

  writer.println("Total number of applications (application-types: "
      + appTypes + " and states: " + appStates + ")" + ":"
      + appsReport.size());
  writer.printf(APPLICATIONS_PATTERN, "Application-Id", "Application-Name",
      "Application-Type", "User", "Queue", "State", "Final-State",
      "Progress", "Tracking-URL");
  for (ApplicationReport appReport : appsReport) {
    DecimalFormat formatter = new DecimalFormat("###.##%");
    String progress = formatter.format(appReport.getProgress());
    writer.printf(APPLICATIONS_PATTERN, appReport.getApplicationId(),
        appReport.getName(), appReport.getApplicationType(), appReport
            .getUser(), appReport.getQueue(), appReport
            .getYarnApplicationState(),
        appReport.getFinalApplicationStatus(), progress, appReport
            .getOriginalTrackingUrl());
  }
  writer.flush();
}
 
Example 15
Source File: ApplicationCLI.java    From big-c with Apache License 2.0 5 votes vote down vote up
private String getAllValidApplicationStates() {
  StringBuilder sb = new StringBuilder();
  sb.append("The valid application state can be" + " one of the following: ");
  sb.append(ALLSTATES_OPTION + ",");
  for (YarnApplicationState appState : YarnApplicationState.values()) {
    sb.append(appState + ",");
  }
  String output = sb.toString();
  return output.substring(0, output.length() - 1);
}
 
Example 16
Source File: TestYarnCLI.java    From big-c with Apache License 2.0 5 votes vote down vote up
private List<ApplicationReport> getApplicationReports(
    List<ApplicationReport> applicationReports,
    Set<String> appTypes, EnumSet<YarnApplicationState> appStates,
    boolean allStates) {

  List<ApplicationReport> appReports = new ArrayList<ApplicationReport>();

  if (allStates) {
    for(YarnApplicationState state : YarnApplicationState.values()) {
      appStates.add(state);
    }
  }
  for (ApplicationReport appReport : applicationReports) {
    if (appTypes != null && !appTypes.isEmpty()) {
      if (!appTypes.contains(appReport.getApplicationType())) {
        continue;
      }
    }

    if (appStates != null && !appStates.isEmpty()) {
      if (!appStates.contains(appReport.getYarnApplicationState())) {
        continue;
      }
    }

    appReports.add(appReport);
  }
  return appReports;
}