Example usage for org.apache.hadoop.yarn.api ApplicationClientProtocol getApplications

List of usage examples for org.apache.hadoop.yarn.api ApplicationClientProtocol getApplications

Introduction

In this page you can find the example usage for org.apache.hadoop.yarn.api ApplicationClientProtocol getApplications.

Prototype

@Public
@Stable
@Idempotent
public GetApplicationsResponse getApplications(GetApplicationsRequest request)
        throws YarnException, IOException;

Source Link

Document

The interface used by clients to get a report of Applications matching the filters defined by GetApplicationsRequest in the cluster from the ResourceManager or ApplicationHistoryServer.

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  .ja  va2 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 ww  .  j  a  v  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;
}

From source file:org.springframework.yarn.client.ClientRmTemplate.java

License:Apache License

@Override
public List<ApplicationReport> listApplications() {
    return execute(new YarnRpcCallback<List<ApplicationReport>, ApplicationClientProtocol>() {
        @Override// w  w w  .jav  a 2s.c  o m
        public List<ApplicationReport> doInYarn(ApplicationClientProtocol proxy)
                throws YarnException, IOException {
            GetApplicationsRequest request = Records.newRecord(GetApplicationsRequest.class);
            GetApplicationsResponse response = proxy.getApplications(request);
            return response.getApplicationList();
        }
    });
}

From source file:org.springframework.yarn.client.ClientRmTemplateTests.java

License:Apache License

@Test
public void testExecuteCallback() {
    List<ApplicationReport> applications = template
            .execute(new YarnRpcCallback<List<ApplicationReport>, ApplicationClientProtocol>() {
                @Override/*  ww  w  .  ja  va2  s . com*/
                public List<ApplicationReport> doInYarn(ApplicationClientProtocol proxy)
                        throws YarnException, IOException {
                    GetApplicationsRequest request = Records.newRecord(GetApplicationsRequest.class);
                    GetApplicationsResponse response = proxy.getApplications(request);
                    return response.getApplicationList();
                }
            });
    assertNotNull(applications);
}