Search in sources :

Example 1 with ResponseContext

use of com.sequenceiq.cloudbreak.orchestrator.yarn.model.response.ResponseContext 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 ResponseContext

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

the class YarnHttpClient method createApplication.

@Override
public ResponseContext createApplication(CreateApplicationRequest createApplicationRequest) throws MalformedURLException {
    YarnEndpoint dashEndpoint = new YarnEndpoint(apiEndpoint, YarnResourceConstants.APPLICATIONS_PATH);
    ResponseContext responseContext = new ResponseContext();
    // Construct the webresource and perform the get
    WebResource webResource = getNewWebResource(dashEndpoint.getFullEndpointUrl().toString());
    ClientResponse response = webResource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).post(ClientResponse.class, createApplicationRequest);
    responseContext.setStatusCode(response.getStatus());
    // Validate the results
    if (responseContext.getStatusCode() == YarnResourceConstants.HTTP_ACCEPTED) {
        responseContext.setResponseObject(response.getEntity(ApplicationDetailResponse.class));
    } else {
        responseContext.setResponseError(response.getEntity(ApplicationErrorResponse.class));
    }
    return responseContext;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ApplicationDetailResponse(com.sequenceiq.cloudbreak.orchestrator.yarn.model.response.ApplicationDetailResponse) ResponseContext(com.sequenceiq.cloudbreak.orchestrator.yarn.model.response.ResponseContext) WebResource(com.sun.jersey.api.client.WebResource) ApplicationErrorResponse(com.sequenceiq.cloudbreak.orchestrator.yarn.model.response.ApplicationErrorResponse) YarnEndpoint(com.sequenceiq.cloudbreak.orchestrator.yarn.api.YarnEndpoint)

Example 3 with ResponseContext

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

the class YarnHttpClient method getApplicationDetail.

@Override
public ResponseContext getApplicationDetail(ApplicationDetailRequest applicationDetailRequest) throws MalformedURLException {
    ResponseContext responseContext = new ResponseContext();
    // Add the application name to the URL
    YarnEndpoint dashEndpoint = new YarnEndpoint(apiEndpoint, YarnResourceConstants.APPLICATIONS_PATH + '/' + applicationDetailRequest.getName());
    // Construct the webresource and perform the get
    WebResource webResource = getNewWebResource(dashEndpoint.getFullEndpointUrl().toString());
    ClientResponse response = webResource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    responseContext.setStatusCode(response.getStatus());
    // Validate the results
    if (checkStatusCode(response, YarnResourceConstants.HTTP_SUCCESS)) {
        responseContext.setResponseObject(response.getEntity(ApplicationDetailResponse.class));
    } else {
        responseContext.setResponseError(response.getEntity(ApplicationErrorResponse.class));
    }
    return responseContext;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ApplicationDetailResponse(com.sequenceiq.cloudbreak.orchestrator.yarn.model.response.ApplicationDetailResponse) ResponseContext(com.sequenceiq.cloudbreak.orchestrator.yarn.model.response.ResponseContext) WebResource(com.sun.jersey.api.client.WebResource) ApplicationErrorResponse(com.sequenceiq.cloudbreak.orchestrator.yarn.model.response.ApplicationErrorResponse) YarnEndpoint(com.sequenceiq.cloudbreak.orchestrator.yarn.api.YarnEndpoint)

Example 4 with ResponseContext

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

the class ApplicationDetailHandler method getContainerInfo.

public ContainerInfo getContainerInfo(ContainerConfig config, OrchestrationCredential cred, ContainerConstraint constraint, int componentNumber) throws CloudbreakOrchestratorFailedException {
    String applicationName = applicationUtils.getApplicationName(constraint, componentNumber);
    // Build the ApplicationDetailRequest
    ApplicationDetailRequest applicationDetailRequest = new ApplicationDetailRequest();
    applicationDetailRequest.setName(applicationName);
    try {
        // Validate that the app exists
        YarnClient yarnHttpClient = new YarnHttpClient(cred.getApiEndpoint());
        ResponseContext appDetailResponseContext = yarnHttpClient.getApplicationDetail(applicationDetailRequest);
        if (appDetailResponseContext.getResponseError() != null) {
            ApplicationErrorResponse applicationErrorResponse = appDetailResponseContext.getResponseError();
            throw new CloudbreakOrchestratorFailedException(String.format("ERROR: HTTP Return: %d Error: %s.", appDetailResponseContext.getStatusCode(), applicationErrorResponse.getDiagnostics()));
        }
        // Return the details
        String componentHostName = applicationUtils.getComponentHostName(constraint, cred, componentNumber);
        String image = String.format("%s:%s", config.getName(), config.getVersion());
        return new ContainerInfo(applicationName, applicationName, componentHostName, image);
    } catch (MalformedURLException e) {
        String msg = String.format("ERROR: URL is malformed: %s", cred.getApiEndpoint());
        throw new CloudbreakOrchestratorFailedException(msg, e);
    }
}
Also used : YarnHttpClient(com.sequenceiq.cloudbreak.orchestrator.yarn.client.YarnHttpClient) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) MalformedURLException(java.net.MalformedURLException) ApplicationDetailRequest(com.sequenceiq.cloudbreak.orchestrator.yarn.model.request.ApplicationDetailRequest) ResponseContext(com.sequenceiq.cloudbreak.orchestrator.yarn.model.response.ResponseContext) ContainerInfo(com.sequenceiq.cloudbreak.orchestrator.model.ContainerInfo) ApplicationErrorResponse(com.sequenceiq.cloudbreak.orchestrator.yarn.model.response.ApplicationErrorResponse) YarnClient(com.sequenceiq.cloudbreak.orchestrator.yarn.client.YarnClient)

Example 5 with ResponseContext

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

the class ApplicationSubmissionHandler method submitCreateApplicationRequest.

private void submitCreateApplicationRequest(CreateApplicationRequest createApplicationRequest, YarnClient yarnHttpClient) throws CloudbreakOrchestratorFailedException {
    try {
        ResponseContext createAppResponseContext = yarnHttpClient.createApplication(createApplicationRequest);
        if (createAppResponseContext.getResponseError() != null) {
            ApplicationErrorResponse applicationErrorResponse = createAppResponseContext.getResponseError();
            String msg = String.format("ERROR: HTTP Return: %d Error: %s", createAppResponseContext.getStatusCode(), applicationErrorResponse.getDiagnostics());
            LOGGER.debug(msg);
            throw new CloudbreakOrchestratorFailedException(msg);
        }
    } catch (Exception e) {
        throw new CloudbreakOrchestratorFailedException(e);
    }
}
Also used : CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) ResponseContext(com.sequenceiq.cloudbreak.orchestrator.yarn.model.response.ResponseContext) ApplicationErrorResponse(com.sequenceiq.cloudbreak.orchestrator.yarn.model.response.ApplicationErrorResponse) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)

Aggregations

ResponseContext (com.sequenceiq.cloudbreak.orchestrator.yarn.model.response.ResponseContext)6 CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)4 ApplicationDetailResponse (com.sequenceiq.cloudbreak.orchestrator.yarn.model.response.ApplicationDetailResponse)4 ApplicationErrorResponse (com.sequenceiq.cloudbreak.orchestrator.yarn.model.response.ApplicationErrorResponse)4 YarnClient (com.sequenceiq.cloudbreak.orchestrator.yarn.client.YarnClient)3 YarnHttpClient (com.sequenceiq.cloudbreak.orchestrator.yarn.client.YarnHttpClient)3 YarnEndpoint (com.sequenceiq.cloudbreak.orchestrator.yarn.api.YarnEndpoint)2 Container (com.sequenceiq.cloudbreak.orchestrator.yarn.model.core.Container)2 ApplicationDetailRequest (com.sequenceiq.cloudbreak.orchestrator.yarn.model.request.ApplicationDetailRequest)2 ClientResponse (com.sun.jersey.api.client.ClientResponse)2 WebResource (com.sun.jersey.api.client.WebResource)2 ContainerInfo (com.sequenceiq.cloudbreak.orchestrator.model.ContainerInfo)1 MalformedURLException (java.net.MalformedURLException)1