Search in sources :

Example 16 with CloudbreakOrchestratorFailedException

use of com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException in project cloudbreak by hortonworks.

the class SaltUpload method call.

@Override
public Boolean call() throws Exception {
    LOGGER.info("Uploading files to: {}", targets);
    if (!targets.isEmpty()) {
        LOGGER.info("Current targets for upload: {}", targets);
        GenericResponses responses = sc.upload(targets, path, fileName, content);
        Set<String> failedTargets = new HashSet<>();
        LOGGER.info("Salt file upload responses: {}", responses);
        for (GenericResponse genericResponse : responses.getResponses()) {
            if (genericResponse.getStatusCode() != HttpStatus.CREATED.value()) {
                LOGGER.info("Failed upload attempt to: " + genericResponse.getAddress());
                String address = genericResponse.getAddress().split(":")[0];
                failedTargets.addAll(originalTargets.stream().filter(a -> a.equals(address)).collect(Collectors.toList()));
            }
        }
        targets = failedTargets;
        if (!targets.isEmpty()) {
            LOGGER.info("Missing nodes for file upload: {}", targets);
            throw new CloudbreakOrchestratorFailedException("There are missing nodes for file upload: " + targets);
        }
    }
    LOGGER.info("File upload has been completed on nodes: {}", originalTargets);
    return true;
}
Also used : CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) GenericResponses(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses) HashSet(java.util.HashSet)

Example 17 with CloudbreakOrchestratorFailedException

use of com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException in project cloudbreak by hortonworks.

the class YarnHttpClient method deleteApplication.

@Override
public void deleteApplication(DeleteApplicationRequest deleteApplicationRequest) throws CloudbreakOrchestratorFailedException, MalformedURLException {
    // Add the application name to the URL
    YarnEndpoint dashEndpoint = new YarnEndpoint(apiEndpoint, YarnResourceConstants.APPLICATIONS_PATH + '/' + deleteApplicationRequest.getName());
    ClientConfig clientConfig = new DefaultClientConfig();
    Client client = Client.create(clientConfig);
    // Delete the application
    WebResource webResource = client.resource(dashEndpoint.getFullEndpointUrl().toString());
    ClientResponse response = webResource.accept("application/json").type("application/json").delete(ClientResponse.class);
    // Validate HTTP 204 return
    String msg;
    switch(response.getStatus()) {
        case YarnResourceConstants.HTTP_NO_CONTENT:
            msg = String.format("Successfully deleted application %s", deleteApplicationRequest.getName());
            LOGGER.debug(msg);
            break;
        case YarnResourceConstants.HTTP_NOT_FOUND:
            msg = String.format("Application %s not found, already deleted?", deleteApplicationRequest.getName());
            LOGGER.debug(msg);
            break;
        default:
            msg = String.format("Received %d status code from url %s, reason: %s", response.getStatus(), dashEndpoint.getFullEndpointUrl().toString(), response.getEntity(String.class));
            LOGGER.debug(msg);
            throw new CloudbreakOrchestratorFailedException(msg);
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) WebResource(com.sun.jersey.api.client.WebResource) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) Client(com.sun.jersey.api.client.Client) YarnEndpoint(com.sequenceiq.cloudbreak.orchestrator.yarn.api.YarnEndpoint)

Example 18 with CloudbreakOrchestratorFailedException

use of com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException 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 19 with CloudbreakOrchestratorFailedException

use of com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException 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 20 with CloudbreakOrchestratorFailedException

use of com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException in project cloudbreak by hortonworks.

the class ClusterBootstrapperErrorHandler method terminateFailedNodes.

public void terminateFailedNodes(HostOrchestrator hostOrchestrator, ContainerOrchestrator containerOrchestrator, Stack stack, GatewayConfig gatewayConfig, Set<Node> nodes) throws CloudbreakOrchestratorFailedException {
    List<String> allAvailableNode;
    allAvailableNode = hostOrchestrator != null ? hostOrchestrator.getAvailableNodes(gatewayConfig, nodes) : containerOrchestrator.getAvailableNodes(gatewayConfig, nodes);
    List<Node> missingNodes = selectMissingNodes(nodes, allAvailableNode);
    if (!missingNodes.isEmpty()) {
        String message = cloudbreakMessagesService.getMessage(Msg.BOOTSTRAPPER_ERROR_BOOTSTRAP_FAILED_ON_NODES.code(), Collections.singletonList(missingNodes.size()));
        LOGGER.info(message);
        eventService.fireCloudbreakEvent(stack.getId(), Status.UPDATE_IN_PROGRESS.name(), message);
        for (Node missingNode : missingNodes) {
            InstanceMetaData instanceMetaData = instanceMetaDataRepository.findNotTerminatedByPrivateAddress(stack.getId(), missingNode.getPrivateIp());
            InstanceGroup ig = instanceGroupRepository.findOneByGroupNameInStack(stack.getId(), instanceMetaData.getInstanceGroup().getGroupName());
            ig.setNodeCount(ig.getNodeCount() - 1);
            if (ig.getNodeCount() < 1) {
                throw new CloudbreakOrchestratorFailedException(cloudbreakMessagesService.getMessage(Msg.BOOTSTRAPPER_ERROR_INVALID_NODECOUNT.code(), Collections.singletonList(ig.getGroupName())));
            }
            instanceGroupRepository.save(ig);
            message = cloudbreakMessagesService.getMessage(Msg.BOOTSTRAPPER_ERROR_DELETING_NODE.code(), Arrays.asList(instanceMetaData.getInstanceId(), ig.getGroupName()));
            LOGGER.info(message);
            eventService.fireCloudbreakEvent(stack.getId(), Status.UPDATE_IN_PROGRESS.name(), message);
            deleteResourceAndDependencies(stack, instanceMetaData);
            deleteInstanceResourceFromDatabase(stack, instanceMetaData);
            long timeInMillis = Calendar.getInstance().getTimeInMillis();
            instanceMetaData.setTerminationDate(timeInMillis);
            instanceMetaData.setInstanceStatus(InstanceStatus.TERMINATED);
            instanceMetaDataRepository.save(instanceMetaData);
            LOGGER.info("InstanceMetadata [name: {}, id: {}] status set to {}.", instanceMetaData.getId(), instanceMetaData.getInstanceId(), instanceMetaData.getInstanceStatus());
        }
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup)

Aggregations

CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)39 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)14 SaltConnector (com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector)14 CloudbreakOrchestratorException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException)12 ExecutionException (java.util.concurrent.ExecutionException)12 IOException (java.io.IOException)11 Node (com.sequenceiq.cloudbreak.orchestrator.model.Node)10 OrchestratorBootstrap (com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrap)9 HostOrchestrator (com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator)9 HashSet (java.util.HashSet)9 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)7 SaltPillarProperties (com.sequenceiq.cloudbreak.orchestrator.model.SaltPillarProperties)6 GrainAddRunner (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainAddRunner)6 GrainRemoveRunner (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainRemoveRunner)6 HighStateRunner (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.HighStateRunner)6 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)6 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)5 RecipeModel (com.sequenceiq.cloudbreak.orchestrator.model.RecipeModel)5