Example usage for org.apache.hadoop.yarn.api.records ApplicationReport getApplicationId

List of usage examples for org.apache.hadoop.yarn.api.records ApplicationReport getApplicationId

Introduction

In this page you can find the example usage for org.apache.hadoop.yarn.api.records ApplicationReport getApplicationId.

Prototype

@Public
@Stable
public abstract ApplicationId getApplicationId();

Source Link

Document

Get the ApplicationId of the application.

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 ww  .  j a  v  a  2 s.  co 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.hoya.core.launch.LaunchedApplication.java

License:Apache License

public LaunchedApplication(HoyaYarnClientImpl yarnClient, ApplicationReport report) {
    this.yarnClient = yarnClient;
    this.applicationId = report.getApplicationId();
}

From source file:org.apache.hoya.tools.HoyaUtils.java

License:Apache License

/**
 * convert an AM report to a string for diagnostics
 * @param report the report/*from  w w  w. j a va  2 s . c o m*/
 * @return the string value
 */
public static String reportToString(ApplicationReport report) {
    if (report == null) {
        return "Null application report";
    }

    return "App " + report.getName() + "/" + report.getApplicationType() + "# " + report.getApplicationId()
            + " user " + report.getUser() + " is in state " + report.getYarnApplicationState() + "RPC: "
            + report.getHost() + ":" + report.getRpcPort();
}

From source file:org.apache.hoya.yarn.appmaster.rpc.RpcBinder.java

License:Apache License

/**
 * This loops for a limited period trying to get the Proxy -
 * by doing so it handles AM failover/*from w w  w .ja  va  2s.  com*/
 * @param conf configuration to patch and use
 * @param rmClient client of the resource manager
 * @param application application to work with
 * @param connectTimeout timeout for the whole proxy operation to timeout
 * (milliseconds). Use 0 to indicate "do not attempt to wait" -fail fast.
 * @param rpcTimeout timeout for RPCs to block during communications
 * @return the proxy
 * @throws IOException IO problems
 * @throws YarnException Hoya-generated exceptions related to the binding
 * failing. This can include the application finishing or timeouts
 * @throws InterruptedException if a sleep operation waiting for
 * the cluster to respond is interrupted.
 */
@SuppressWarnings("NestedAssignment")
public static HoyaClusterProtocol getProxy(final Configuration conf, final ApplicationClientProtocol rmClient,
        ApplicationReport application, final int connectTimeout,

        final int rpcTimeout) throws IOException, YarnException, InterruptedException {
    ApplicationId appId;
    appId = application.getApplicationId();
    Duration timeout = new Duration(connectTimeout);
    timeout.start();
    Exception exception = null;
    YarnApplicationState state = null;
    while (application != null
            && (state = application.getYarnApplicationState()).equals(YarnApplicationState.RUNNING)) {

        try {
            return getProxy(conf, application, rpcTimeout);
        } catch (IOException e) {
            if (connectTimeout <= 0 || timeout.getLimitExceeded()) {
                throw e;
            }
            exception = e;
        } catch (YarnException e) {
            if (connectTimeout <= 0 || timeout.getLimitExceeded()) {
                throw e;
            }
            exception = e;

        }
        //at this point: app failed to work
        log.debug("Could not connect to {}. Waiting for getting the latest AM address...", appId);
        Thread.sleep(1000);
        //or get the app report
        application = rmClient.getApplicationReport(GetApplicationReportRequest.newInstance(appId))
                .getApplicationReport();
    }
    //get here if the app is no longer running. Raise a specific
    //exception but init it with the previous failure
    throw new BadClusterStateException(exception, ErrorStrings.E_FINISHED_APPLICATION, appId, state);
}

From source file:org.apache.hoya.yarn.client.HoyaYarnClientImpl.java

License:Apache License

/**
 * Force kill a yarn application by ID. No niceities here
 */// w ww.  j a va  2  s  .  c om
public void emergencyForceKill(String applicationId) throws YarnException, IOException {

    if (ActionForceKillArgs.ALL.equals(applicationId)) {
        // user wants all hoya applications killed
        String user = getUsername();
        log.info("Killing all applications belonging to {}", user);
        Collection<ApplicationReport> instances = listInstances(user);
        for (ApplicationReport instance : instances) {
            if (isApplicationLive(instance)) {
                ApplicationId appId = instance.getApplicationId();
                log.info("Killing Application {}", appId);

                killRunningApplication(appId, "forced kill");
            }
        }
    } else {
        ApplicationId appId = ConverterUtils.toApplicationId(applicationId);

        log.info("Killing Application {}", applicationId);

        killRunningApplication(appId, "forced kill");
    }
}

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;
    }/* ww w.  j a va  2s  .  com*/
    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.apache.oozie.action.hadoop.TestYarnApplicationIdFinder.java

License:Apache License

@Test
public void whenOldLauncherAndMRobApplicationsAreFinishedAndNewLauncherPresentNewLauncherIsUsed()
        throws Exception {
    final ApplicationReport oldLauncher = mock(ApplicationReport.class);
    when(oldLauncher.getApplicationType()).thenReturn("Oozie Launcher");
    final ApplicationReport oldMRJob = mock(ApplicationReport.class);
    when(oldMRJob.getApplicationType()).thenReturn("MAPREDUCE");
    final ApplicationId oldMRJobId = mock(ApplicationId.class);
    when(oldMRJobId.toString()).thenReturn("application_1534164756526_0002");
    when(oldMRJob.getApplicationId()).thenReturn(oldMRJobId);
    final ApplicationReport newLauncher = mock(ApplicationReport.class);
    when(newLauncher.getApplicationType()).thenReturn("Oozie Launcher");
    final ApplicationReport newMRJob = mock(ApplicationReport.class);
    when(newMRJob.getApplicationType()).thenReturn("MAPREDUCE");
    final ApplicationId newMRJobId = mock(ApplicationId.class);
    when(newMRJobId.toString()).thenReturn("application_1534164756526_0004");
    when(newMRJob.getApplicationId()).thenReturn(newMRJobId);
    when(reader.read())/*from w ww  . j ava 2 s. c o  m*/
            .thenReturn(new ArrayList<>(Arrays.asList(oldLauncher, oldMRJob, newLauncher, newMRJob)));

    when(workflowActionBean.getExternalId()).thenReturn("application_1534164756526_0003");
    assertEquals("newLauncher should be found", "application_1534164756526_0004",
            yarnApplicationIdFinder.find());

    when(workflowActionBean.getExternalId()).thenReturn("application_1534164756526_0004");
    assertEquals("newLauncher should be found", "application_1534164756526_0004",
            yarnApplicationIdFinder.find());

    when(workflowActionBean.getExternalId()).thenReturn("application_1534164756526_0005");
    assertEquals("workflowActionBean.externalId should be found", "application_1534164756526_0005",
            yarnApplicationIdFinder.find());
}

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

License:Apache License

@Test
public void testGetLastYarnIdFromUnorderedListSuccess() {
    final ApplicationReport newLauncher = mock(ApplicationReport.class);
    final ApplicationId newLauncherId = mock(ApplicationId.class);
    when(newLauncherId.toString()).thenReturn("application_1534164756526_0003");
    when(newLauncher.getApplicationId()).thenReturn(newLauncherId);
    final ApplicationReport newMRJob = mock(ApplicationReport.class);
    final ApplicationId newMRJobId = mock(ApplicationId.class);
    when(newMRJobId.toString()).thenReturn("application_1534164756526_0004");
    when(newMRJob.getApplicationId()).thenReturn(newMRJobId);

    final String lastYarnId = yarnApplicationIdFinder.getLastYarnId(Arrays.asList(newMRJob, newLauncher));
    assertEquals("last YARN id should be the maximal element in the list", "application_1534164756526_0004",
            lastYarnId);// w w  w  .ja  v a2s . c om
}

From source file:org.apache.samza.validation.TestYarnJobValidationTool.java

License:Apache License

@Test
public void testValidateAppId() throws Exception {
    ApplicationReport appReport = mock(ApplicationReport.class);
    when(appReport.getName()).thenReturn(jobName + "_" + jobId);
    when(appReport.getApplicationId()).thenReturn(appId);
    when(client.getApplications()).thenReturn(Collections.singletonList(appReport));
    assertTrue(tool.validateAppId().equals(appId));

    when(appReport.getName()).thenReturn("dummy");
    exception.expect(SamzaException.class);
    tool.validateAppId();/* w  w  w .j  a v  a 2 s .  c o  m*/
}

From source file:org.apache.samza.validation.YarnJobValidationTool.java

License:Apache License

public ApplicationId validateAppId() throws Exception {
    // fetch only the last created application with the job name and id
    // i.e. get the application with max appId
    ApplicationId appId = null;//w w w . ja  v a2 s  .co m
    for (ApplicationReport applicationReport : this.client.getApplications()) {
        if (applicationReport.getName().equals(this.jobName)) {
            ApplicationId id = applicationReport.getApplicationId();
            if (appId == null || appId.compareTo(id) < 0) {
                appId = id;
            }
        }
    }
    if (appId != null) {
        log.info("Job lookup success. ApplicationId " + appId.toString());
        return appId;
    } else {
        throw new SamzaException("Job lookup failure " + this.jobName);
    }
}