Search in sources :

Example 1 with StatisticsItemInfo

use of org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.StatisticsItemInfo in project hadoop by apache.

the class RMWebServices method getAppStatistics.

@GET
@Path("/appstatistics")
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
public ApplicationStatisticsInfo getAppStatistics(@Context HttpServletRequest hsr, @QueryParam("states") Set<String> stateQueries, @QueryParam("applicationTypes") Set<String> typeQueries) {
    init();
    // parse the params and build the scoreboard
    // converting state/type name to lowercase
    Set<String> states = parseQueries(stateQueries, true);
    Set<String> types = parseQueries(typeQueries, false);
    // if no types, counts the applications of any types
    if (types.size() == 0) {
        types.add(ANY);
    } else if (types.size() != 1) {
        throw new BadRequestException("# of applicationTypes = " + types.size() + ", we temporarily support at most one applicationType");
    }
    // if no states, returns the counts of all RMAppStates
    if (states.size() == 0) {
        for (YarnApplicationState state : YarnApplicationState.values()) {
            states.add(StringUtils.toLowerCase(state.toString()));
        }
    }
    // in case we extend to multiple applicationTypes in the future
    Map<YarnApplicationState, Map<String, Long>> scoreboard = buildScoreboard(states, types);
    // go through the apps in RM to count the numbers, ignoring the case of
    // the state/type name
    ConcurrentMap<ApplicationId, RMApp> apps = rm.getRMContext().getRMApps();
    for (RMApp rmapp : apps.values()) {
        YarnApplicationState state = rmapp.createApplicationState();
        String type = StringUtils.toLowerCase(rmapp.getApplicationType().trim());
        if (states.contains(StringUtils.toLowerCase(state.toString()))) {
            if (types.contains(ANY)) {
                countApp(scoreboard, state, ANY);
            } else if (types.contains(type)) {
                countApp(scoreboard, state, type);
            }
        }
    }
    // fill the response object
    ApplicationStatisticsInfo appStatInfo = new ApplicationStatisticsInfo();
    for (Map.Entry<YarnApplicationState, Map<String, Long>> partScoreboard : scoreboard.entrySet()) {
        for (Map.Entry<String, Long> statEntry : partScoreboard.getValue().entrySet()) {
            StatisticsItemInfo statItem = new StatisticsItemInfo(partScoreboard.getKey(), statEntry.getKey(), statEntry.getValue());
            appStatInfo.add(statItem);
        }
    }
    return appStatInfo;
}
Also used : RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) YarnApplicationState(org.apache.hadoop.yarn.api.records.YarnApplicationState) ApplicationStatisticsInfo(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ApplicationStatisticsInfo) BadRequestException(org.apache.hadoop.yarn.webapp.BadRequestException) StatisticsItemInfo(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.StatisticsItemInfo) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) Map(java.util.Map) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)1 YarnApplicationState (org.apache.hadoop.yarn.api.records.YarnApplicationState)1 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)1 ApplicationStatisticsInfo (org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ApplicationStatisticsInfo)1 StatisticsItemInfo (org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.StatisticsItemInfo)1 BadRequestException (org.apache.hadoop.yarn.webapp.BadRequestException)1