Example usage for org.apache.hadoop.yarn.api.protocolrecords GetApplicationsRequest setScope

List of usage examples for org.apache.hadoop.yarn.api.protocolrecords GetApplicationsRequest setScope

Introduction

In this page you can find the example usage for org.apache.hadoop.yarn.api.protocolrecords GetApplicationsRequest setScope.

Prototype

@Private
@Unstable
public abstract void setScope(ApplicationsRequestScope scope);

Source Link

Document

Set the ApplicationsRequestScope of applications to filter.

Usage

From source file:org.apache.hive.service.server.KillQueryImpl.java

License:Apache License

public static Set<ApplicationId> getChildYarnJobs(Configuration conf, String tag)
        throws IOException, YarnException {
    Set<ApplicationId> childYarnJobs = new HashSet<ApplicationId>();
    GetApplicationsRequest gar = GetApplicationsRequest.newInstance();
    gar.setScope(ApplicationsRequestScope.OWN);
    gar.setApplicationTags(Collections.singleton(tag));

    ApplicationClientProtocol proxy = ClientRMProxy.createRMProxy(conf, ApplicationClientProtocol.class);
    GetApplicationsResponse apps = proxy.getApplications(gar);
    List<ApplicationReport> appsList = apps.getApplicationList();
    for (ApplicationReport appReport : appsList) {
        if (isAdmin() || appReport.getApplicationTags()
                .contains(QueryState.USERID_TAG + "=" + SessionState.get().getUserName())) {
            childYarnJobs.add(appReport.getApplicationId());
        }/*from w w w . j a v  a 2  s . c  o m*/
    }

    if (childYarnJobs.isEmpty()) {
        LOG.info("No child applications found");
    } else {
        LOG.info("Found child YARN applications: " + StringUtils.join(childYarnJobs, ","));
    }

    return childYarnJobs;
}

From source file:org.apache.oozie.action.hadoop.LauncherMainHadoopUtils.java

License:Apache License

private static Set<ApplicationId> getChildYarnJobs(Configuration actionConf) {
    System.out.println("Fetching child yarn jobs");
    Set<ApplicationId> childYarnJobs = new HashSet<ApplicationId>();
    String tag = actionConf.get(CHILD_MAPREDUCE_JOB_TAGS);
    if (tag == null) {
        System.out.print("Could not find Yarn tags property " + CHILD_MAPREDUCE_JOB_TAGS);
        return childYarnJobs;
    }//w w w .  j  av  a  2 s .c  o m
    System.out.println("tag id : " + tag);
    long startTime = 0L;
    try {
        startTime = Long.parseLong((System.getProperty(OOZIE_JOB_LAUNCH_TIME)));
    } catch (NumberFormatException nfe) {
        throw new RuntimeException("Could not find Oozie job launch time", nfe);
    }

    GetApplicationsRequest gar = GetApplicationsRequest.newInstance();
    gar.setScope(ApplicationsRequestScope.OWN);
    gar.setApplicationTags(Collections.singleton(tag));
    long endTime = System.currentTimeMillis();
    if (startTime > endTime) {
        System.out.println(
                "WARNING: Clock skew between the Oozie server host and this host detected.  Please fix this.  "
                        + "Attempting to work around...");
        // We don't know which one is wrong (relative to the RM), so to be safe, let's assume they're both wrong and add an
        // offset in both directions
        long diff = 2 * (startTime - endTime);
        startTime = startTime - diff;
        endTime = endTime + diff;
    }
    gar.setStartRange(startTime, endTime);
    try {
        ApplicationClientProtocol proxy = ClientRMProxy.createRMProxy(actionConf,
                ApplicationClientProtocol.class);
        GetApplicationsResponse apps = proxy.getApplications(gar);
        List<ApplicationReport> appsList = apps.getApplicationList();
        for (ApplicationReport appReport : appsList) {
            childYarnJobs.add(appReport.getApplicationId());
        }
    } catch (IOException ioe) {
        throw new RuntimeException("Exception occurred while finding child jobs", ioe);
    } catch (YarnException ye) {
        throw new RuntimeException("Exception occurred while finding child jobs", ye);
    }

    System.out.println("Child yarn jobs are found - " + StringUtils.join(childYarnJobs, ","));
    return childYarnJobs;
}