Search in sources :

Example 1 with ApplicationDetailResponse

use of com.sequenceiq.cloudbreak.orchestrator.yarn.model.response.ApplicationDetailResponse in project cloudbreak by hortonworks.

the class YarnApplicationPoller method waitForApplicationStart.

public void waitForApplicationStart(String appName, String apiEndpoint) throws CloudbreakOrchestratorException, MalformedURLException {
    YarnClient dashHttpClient = new YarnHttpClient(apiEndpoint);
    for (int i = 1; i <= RETRIES; i++) {
        // Make the request
        ResponseContext responseContext = dashHttpClient.getApplicationDetail(getApplicationDetailRequest(appName));
        // If 404, application isn't ready, sleep
        if (responseContext.getStatusCode() == YarnResourceConstants.HTTP_NOT_FOUND) {
            handle404(appName, responseContext);
        }
        // If 200, check application state to ensure RUNNING
        if (responseContext.getStatusCode() == YarnResourceConstants.HTTP_SUCCESS) {
            if (null != responseContext.getResponseObject()) {
                ApplicationDetailResponse applicationDetailResponse = (ApplicationDetailResponse) responseContext.getResponseObject();
                // Validate the application is "RUNNING"
                if (!applicationDetailResponse.getState().equals(ApplicationState.READY.name())) {
                    LOGGER.debug(String.format("Application %s not ready, in %s state, sleeping 1000 ms", appName, applicationDetailResponse.getState()));
                    sleep();
                } else {
                    // Validate the container is running
                    if (!applicationDetailResponse.getContainers().isEmpty()) {
                        Container appContainer = applicationDetailResponse.getContainers().get(0);
                        if (!appContainer.getState().equals(ContainerState.READY.name())) {
                            String msg = String.format("Application %s not ready, in %s state, sleeping 1000 ms", appName, applicationDetailResponse.getState());
                            LOGGER.debug(msg);
                            sleep();
                        } else {
                            String msg = String.format("Application %s has now successfully started, in %s state", appName, applicationDetailResponse.getState());
                            LOGGER.debug(msg);
                            break;
                        }
                    }
                }
            }
        }
        if (i == RETRIES) {
            String msg = String.format("ERROR: %s did not start in %d retries", appName, RETRIES);
            throw new CloudbreakOrchestratorFailedException(msg);
        }
    }
}
Also used : YarnHttpClient(com.sequenceiq.cloudbreak.orchestrator.yarn.client.YarnHttpClient) ApplicationDetailResponse(com.sequenceiq.cloudbreak.orchestrator.yarn.model.response.ApplicationDetailResponse) Container(com.sequenceiq.cloudbreak.orchestrator.yarn.model.core.Container) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) ResponseContext(com.sequenceiq.cloudbreak.orchestrator.yarn.model.response.ResponseContext) YarnClient(com.sequenceiq.cloudbreak.orchestrator.yarn.client.YarnClient)

Example 2 with ApplicationDetailResponse

use of com.sequenceiq.cloudbreak.orchestrator.yarn.model.response.ApplicationDetailResponse in project cloudbreak by hortonworks.

the class YarnAppBootstrap method call.

@Override
public Boolean call() throws Exception {
    YarnClient dashHttpClient = new YarnHttpClient(apiEndpoint);
    // Make the request
    ApplicationDetailRequest applicationDetailRequest = new ApplicationDetailRequest();
    applicationDetailRequest.setName(appName);
    ResponseContext responseContext = dashHttpClient.getApplicationDetail(applicationDetailRequest);
    // If 404, application isn't ready, sleep
    if (responseContext.getStatusCode() == YarnResourceConstants.HTTP_NOT_FOUND) {
        String msg = String.format("Application %s not ready, received %d response, sleeping 1000 ms", appName, responseContext.getStatusCode());
        LOGGER.debug(msg);
        throw new CloudbreakOrchestratorFailedException(msg);
    }
    // If 200, check application state to ensure RUNNING
    if (responseContext.getStatusCode() == YarnResourceConstants.HTTP_SUCCESS) {
        if (null != responseContext.getResponseObject()) {
            ApplicationDetailResponse applicationDetailResponse = (ApplicationDetailResponse) responseContext.getResponseObject();
            // Validate the application is "RUNNING"
            if (!applicationDetailResponse.getState().equals(ApplicationState.READY.name())) {
                LOGGER.debug(String.format("Application %s not ready, in %s state, sleeping 1000 ms", appName, applicationDetailResponse.getState()));
                throw new CloudbreakOrchestratorFailedException(String.format("Application %s not ready, in %s state, sleeping 1000 ms", appName, applicationDetailResponse.getState()));
            } else {
                // Validate the container is running
                if (!applicationDetailResponse.getContainers().isEmpty()) {
                    Container appContainer = applicationDetailResponse.getContainers().get(0);
                    if (!appContainer.getState().equals(ContainerState.READY.name())) {
                        String msg = String.format("Application %s not ready, in %s state, sleeping 1000 ms", appName, applicationDetailResponse.getState());
                        LOGGER.debug(msg);
                        throw new CloudbreakOrchestratorFailedException(msg);
                    } else {
                        String msg = String.format("Application %s has now successfully started, in %s state", appName, applicationDetailResponse.getState());
                        LOGGER.debug(msg);
                        return true;
                    }
                }
            }
        }
    }
    return true;
}
Also used : YarnHttpClient(com.sequenceiq.cloudbreak.orchestrator.yarn.client.YarnHttpClient) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) ApplicationDetailResponse(com.sequenceiq.cloudbreak.orchestrator.yarn.model.response.ApplicationDetailResponse) Container(com.sequenceiq.cloudbreak.orchestrator.yarn.model.core.Container) ApplicationDetailRequest(com.sequenceiq.cloudbreak.orchestrator.yarn.model.request.ApplicationDetailRequest) ResponseContext(com.sequenceiq.cloudbreak.orchestrator.yarn.model.response.ResponseContext) YarnClient(com.sequenceiq.cloudbreak.orchestrator.yarn.client.YarnClient)

Aggregations

CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)2 YarnClient (com.sequenceiq.cloudbreak.orchestrator.yarn.client.YarnClient)2 YarnHttpClient (com.sequenceiq.cloudbreak.orchestrator.yarn.client.YarnHttpClient)2 Container (com.sequenceiq.cloudbreak.orchestrator.yarn.model.core.Container)2 ApplicationDetailResponse (com.sequenceiq.cloudbreak.orchestrator.yarn.model.response.ApplicationDetailResponse)2 ResponseContext (com.sequenceiq.cloudbreak.orchestrator.yarn.model.response.ResponseContext)2 ApplicationDetailRequest (com.sequenceiq.cloudbreak.orchestrator.yarn.model.request.ApplicationDetailRequest)1