Search in sources :

Example 1 with YarnClient

use of com.sequenceiq.cloudbreak.orchestrator.yarn.client.YarnClient in project cloudbreak by hortonworks.

the class YarnContainerOrchestrator method deleteContainer.

@Override
public void deleteContainer(List<ContainerInfo> containerInfo, OrchestrationCredential cred) throws CloudbreakOrchestratorException {
    for (ContainerInfo container : containerInfo) {
        DeleteApplicationRequest deleteApplicationRequest = new DeleteApplicationRequest();
        deleteApplicationRequest.setName(container.getName());
        YarnClient yarnHttpClient = new YarnHttpClient(cred.getApiEndpoint());
        try {
            yarnHttpClient.deleteApplication(deleteApplicationRequest);
        } catch (Exception e) {
            throw new CloudbreakOrchestratorFailedException(e.getMessage(), e);
        }
    }
}
Also used : YarnHttpClient(com.sequenceiq.cloudbreak.orchestrator.yarn.client.YarnHttpClient) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) ContainerInfo(com.sequenceiq.cloudbreak.orchestrator.model.ContainerInfo) DeleteApplicationRequest(com.sequenceiq.cloudbreak.orchestrator.yarn.model.request.DeleteApplicationRequest) YarnClient(com.sequenceiq.cloudbreak.orchestrator.yarn.client.YarnClient) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) ExecutionException(java.util.concurrent.ExecutionException) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)

Example 2 with YarnClient

use of com.sequenceiq.cloudbreak.orchestrator.yarn.client.YarnClient in project cloudbreak by hortonworks.

the class ApplicationSubmissionHandler method submitApplication.

public void submitApplication(ContainerConfig config, OrchestrationCredential cred, ContainerConstraint constraint, int componentNumber) throws CloudbreakOrchestratorFailedException {
    // Set Ambari DB hostname, if available
    if (ComponentType.AMBARIDB.equals(applicationUtils.getComponentType(constraint))) {
        ambariDbHostname = applicationUtils.getComponentHostName(constraint, cred, componentNumber);
    }
    // Set Ambari Server hostname, if available
    if (ComponentType.AMBARISERVER.equals(applicationUtils.getComponentType(constraint))) {
        ambariServerHostname = applicationUtils.getComponentHostName(constraint, cred, componentNumber);
    }
    // Application level attributes
    String applicationName = applicationUtils.getApplicationName(constraint, componentNumber);
    CreateApplicationRequest createApplicationRequest = new CreateApplicationRequest();
    createApplicationRequest.setName(applicationName);
    createApplicationRequest.setQueue(config.getQueue());
    createApplicationRequest.setLifetime(UNLIMITED);
    // Define the artifact (docker image) for the component
    Artifact artifact = new Artifact();
    artifact.setId(getDockerImageName(config));
    artifact.setType("DOCKER");
    // Define the resources for the component
    Resource resource = new Resource();
    resource.setCpus(getCpusForContainerType(constraint));
    resource.setMemory(getMemForContainerType(constraint));
    // Add the component
    List<YarnComponent> components = new ArrayList<>();
    YarnComponent component = new YarnComponent();
    component.setName(applicationUtils.getComponentName(constraint, componentNumber));
    component.setNumberOfContainers(ONE);
    component.setLaunchCommand(getFullEntrypoint(constraint, cred, componentNumber));
    component.setArtifact(artifact);
    component.setDependencies(new ArrayList<>());
    component.setResource(resource);
    component.setRunPrivilegedContainer(true);
    components.add(component);
    createApplicationRequest.setComponents(components);
    // Submit the request
    YarnClient yarnHttpClient = new YarnHttpClient(cred.getApiEndpoint());
    try {
        submitCreateApplicationRequest(createApplicationRequest, yarnHttpClient);
    } catch (RuntimeException e) {
        throw new CloudbreakOrchestratorFailedException(e);
    }
}
Also used : CreateApplicationRequest(com.sequenceiq.cloudbreak.orchestrator.yarn.model.request.CreateApplicationRequest) YarnHttpClient(com.sequenceiq.cloudbreak.orchestrator.yarn.client.YarnHttpClient) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) Resource(com.sequenceiq.cloudbreak.orchestrator.yarn.model.core.Resource) ArrayList(java.util.ArrayList) YarnComponent(com.sequenceiq.cloudbreak.orchestrator.yarn.model.core.YarnComponent) Artifact(com.sequenceiq.cloudbreak.orchestrator.yarn.model.core.Artifact) YarnClient(com.sequenceiq.cloudbreak.orchestrator.yarn.client.YarnClient)

Example 3 with YarnClient

use of com.sequenceiq.cloudbreak.orchestrator.yarn.client.YarnClient 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 4 with YarnClient

use of com.sequenceiq.cloudbreak.orchestrator.yarn.client.YarnClient 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 YarnClient

use of com.sequenceiq.cloudbreak.orchestrator.yarn.client.YarnClient 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)5 YarnClient (com.sequenceiq.cloudbreak.orchestrator.yarn.client.YarnClient)5 YarnHttpClient (com.sequenceiq.cloudbreak.orchestrator.yarn.client.YarnHttpClient)5 ResponseContext (com.sequenceiq.cloudbreak.orchestrator.yarn.model.response.ResponseContext)3 ContainerInfo (com.sequenceiq.cloudbreak.orchestrator.model.ContainerInfo)2 Container (com.sequenceiq.cloudbreak.orchestrator.yarn.model.core.Container)2 ApplicationDetailRequest (com.sequenceiq.cloudbreak.orchestrator.yarn.model.request.ApplicationDetailRequest)2 ApplicationDetailResponse (com.sequenceiq.cloudbreak.orchestrator.yarn.model.response.ApplicationDetailResponse)2 CloudbreakOrchestratorException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException)1 Artifact (com.sequenceiq.cloudbreak.orchestrator.yarn.model.core.Artifact)1 Resource (com.sequenceiq.cloudbreak.orchestrator.yarn.model.core.Resource)1 YarnComponent (com.sequenceiq.cloudbreak.orchestrator.yarn.model.core.YarnComponent)1 CreateApplicationRequest (com.sequenceiq.cloudbreak.orchestrator.yarn.model.request.CreateApplicationRequest)1 DeleteApplicationRequest (com.sequenceiq.cloudbreak.orchestrator.yarn.model.request.DeleteApplicationRequest)1 ApplicationErrorResponse (com.sequenceiq.cloudbreak.orchestrator.yarn.model.response.ApplicationErrorResponse)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1