Example usage for org.apache.hadoop.yarn.api.records ApplicationAttemptReport getYarnApplicationAttemptState

List of usage examples for org.apache.hadoop.yarn.api.records ApplicationAttemptReport getYarnApplicationAttemptState

Introduction

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

Prototype

@Public
@Unstable
public abstract YarnApplicationAttemptState getYarnApplicationAttemptState();

Source Link

Document

Get the YarnApplicationAttemptState of the application attempt.

Usage

From source file:UnmanagedAMLauncher.java

License:Apache License

private ApplicationAttemptReport monitorCurrentAppAttempt(ApplicationId appId,
        YarnApplicationAttemptState attemptState) throws YarnException, IOException {
    long startTime = System.currentTimeMillis();
    ApplicationAttemptId attemptId = null;
    while (true) {
        if (attemptId == null) {
            attemptId = rmClient.getApplicationReport(appId).getCurrentApplicationAttemptId();
        }/*  www  .j  a va 2 s  .  co m*/
        ApplicationAttemptReport attemptReport = null;
        if (attemptId != null) {
            attemptReport = rmClient.getApplicationAttemptReport(attemptId);
            if (attemptState.equals(attemptReport.getYarnApplicationAttemptState())) {
                return attemptReport;
            }
        }
        LOG.info("Current attempt state of " + appId + " is "
                + (attemptReport == null ? " N/A " : attemptReport.getYarnApplicationAttemptState())
                + ", waiting for current attempt to reach " + attemptState);
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            LOG.warn("Interrupted while waiting for current attempt of " + appId + " to reach " + attemptState);
        }
        if (System.currentTimeMillis() - startTime > AM_STATE_WAIT_TIMEOUT_MS) {
            String errmsg = "Timeout for waiting current attempt of " + appId + " to reach " + attemptState;
            LOG.error(errmsg);
            throw new RuntimeException(errmsg);
        }
    }
}

From source file:io.hops.hopsworks.common.admin.llap.LlapClusterFacade.java

License:Open Source License

public List<String> getLlapHosts() {
    ArrayList<String> hosts = new ArrayList<>();

    if (!isClusterUp() || isClusterStarting()) {
        return hosts;
    }//  w  w w  .  j  a  v a 2s  .  c  o m

    // The cluster is app, so the appId exists
    String llapAppID = variablesFacade.getVariableValue(Settings.VARIABLE_LLAP_APP_ID);

    ApplicationId appId = ApplicationId.fromString(llapAppID);
    YarnClient yarnClient = yarnClientService.getYarnClientSuper(settings.getConfiguration()).getYarnClient();
    try {
        List<ApplicationAttemptReport> attempts = yarnClient.getApplicationAttempts(appId);
        ApplicationAttemptReport current = null;
        for (ApplicationAttemptReport attempt : attempts) {
            // Only if the app is running the metrics are available
            if (attempt.getYarnApplicationAttemptState() == YarnApplicationAttemptState.RUNNING) {
                current = attempt;
                break;
            }
        }

        if (current == null) {
            return hosts;
        }

        List<ContainerReport> containerReports = yarnClient.getContainers(current.getApplicationAttemptId());

        // For all the new/running containers, which are not the application master, get the host
        for (ContainerReport containerReport : containerReports) {
            // Only if the container is running the metrics are available
            if (containerReport.getContainerState() == ContainerState.RUNNING
                    && !containerReport.getContainerId().equals(current.getAMContainerId())) {
                hosts.add(containerReport.getAssignedNode().getHost());
            }
        }

    } catch (IOException | YarnException ex) {
        logger.log(Level.SEVERE, "Couldn't retrieve the containers for LLAP cluster", ex);
    } finally {
        try {
            yarnClient.close();
        } catch (IOException ex) {
        }
    }

    return hosts;
}

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

License:Apache License

@Test
public void testValidateRunningAttemptId() throws Exception {
    ApplicationReport appReport = mock(ApplicationReport.class);
    when(client.getApplicationReport(appId)).thenReturn(appReport);
    when(appReport.getCurrentApplicationAttemptId()).thenReturn(attemptId);
    ApplicationAttemptReport attemptReport = mock(ApplicationAttemptReport.class);
    when(attemptReport.getYarnApplicationAttemptState()).thenReturn(YarnApplicationAttemptState.RUNNING);
    when(attemptReport.getApplicationAttemptId()).thenReturn(attemptId);
    when(client.getApplicationAttemptReport(attemptId)).thenReturn(attemptReport);
    assertTrue(tool.validateRunningAttemptId(appId).equals(attemptId));

    when(attemptReport.getYarnApplicationAttemptState()).thenReturn(YarnApplicationAttemptState.FAILED);
    exception.expect(SamzaException.class);
    tool.validateRunningAttemptId(appId);
}

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

License:Apache License

public ApplicationAttemptId validateRunningAttemptId(ApplicationId appId) throws Exception {
    ApplicationAttemptId attemptId = this.client.getApplicationReport(appId).getCurrentApplicationAttemptId();
    ApplicationAttemptReport attemptReport = this.client.getApplicationAttemptReport(attemptId);
    if (attemptReport.getYarnApplicationAttemptState() == YarnApplicationAttemptState.RUNNING) {
        log.info("Job is running. AttempId " + attemptId.toString());
        return attemptId;
    } else {// w  ww  . jav a2 s. c  o m
        throw new SamzaException("Job not running " + this.jobName);
    }
}