Search in sources :

Example 41 with CloudbreakException

use of com.sequenceiq.cloudbreak.service.CloudbreakException in project cloudbreak by hortonworks.

the class AmbariDecommissioner method collectDownscaleCandidates.

public Set<String> collectDownscaleCandidates(Stack stack, String hostGroupName, Integer scalingAdjustment) throws CloudbreakException {
    Cluster cluster = stack.getCluster();
    int adjustment = Math.abs(scalingAdjustment);
    Set<String> hostsToRemove = selectHostsToRemove(collectDownscaleCandidates(stack, cluster, hostGroupName, adjustment), adjustment);
    if (hostsToRemove.size() != adjustment) {
        throw new CloudbreakException(String.format("Only %d hosts found to downscale but %d required.", hostsToRemove.size(), adjustment));
    }
    return hostsToRemove;
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.Cluster) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException)

Example 42 with CloudbreakException

use of com.sequenceiq.cloudbreak.service.CloudbreakException in project cloudbreak by hortonworks.

the class AmbariClusterModificationService method startCluster.

@Override
public int startCluster(Stack stack) throws CloudbreakException {
    AmbariClient ambariClient = clientFactory.getAmbariClient(stack, stack.getCluster());
    PollingResult ambariHealthCheckResult = ambariPollingServiceProvider.ambariHealthChecker(stack, ambariClient);
    if (isExited(ambariHealthCheckResult)) {
        throw new CancellationException("Cluster was terminated while waiting for Ambari to start.");
    } else if (isTimeout(ambariHealthCheckResult)) {
        throw new CloudbreakException("Ambari server was not restarted properly.");
    }
    LOGGER.info("Starting Ambari agents on the hosts.");
    Set<HostMetadata> hostsInCluster = hostMetadataRepository.findHostsInCluster(stack.getCluster().getId());
    PollingResult hostsJoinedResult = ambariPollingServiceProvider.ambariHostJoin(stack, ambariClient, hostsInCluster);
    if (isExited(hostsJoinedResult)) {
        throw new CancellationException("Cluster was terminated while starting Ambari agents.");
    }
    LOGGER.info("Start all Hadoop services");
    eventService.fireCloudbreakEvent(stack.getId(), UPDATE_IN_PROGRESS.name(), cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_SERVICES_STARTING.code()));
    int requestId = ambariClient.startAllServices();
    if (requestId == -1) {
        LOGGER.error("Failed to start Hadoop services.");
        throw new CloudbreakException("Failed to start Hadoop services.");
    }
    return requestId;
}
Also used : CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) PollingResult(com.sequenceiq.cloudbreak.service.PollingResult) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata)

Example 43 with CloudbreakException

use of com.sequenceiq.cloudbreak.service.CloudbreakException in project cloudbreak by hortonworks.

the class AmbariClusterModificationService method stopCluster.

@Override
public void stopCluster(Stack stack) throws CloudbreakException {
    AmbariClient ambariClient = clientFactory.getAmbariClient(stack, stack.getCluster());
    try {
        boolean stopped = true;
        Collection<Map<String, String>> values = ambariClient.getHostComponentsStates().values();
        for (Map<String, String> value : values) {
            for (String state : value.values()) {
                if (!"INSTALLED".equals(state)) {
                    stopped = false;
                }
            }
        }
        if (!stopped) {
            LOGGER.info("Stop all Hadoop services");
            eventService.fireCloudbreakEvent(stack.getId(), UPDATE_IN_PROGRESS.name(), cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_SERVICES_STOPPING.code()));
            int requestId = ambariClient.stopAllServices();
            if (requestId != -1) {
                LOGGER.info("Waiting for Hadoop services to stop on stack");
                PollingResult servicesStopResult = ambariOperationService.waitForOperations(stack, ambariClient, singletonMap("stop services", requestId), STOP_AMBARI_PROGRESS_STATE).getLeft();
                if (isExited(servicesStopResult)) {
                    throw new CancellationException("Cluster was terminated while waiting for Hadoop services to start");
                } else if (isTimeout(servicesStopResult)) {
                    throw new CloudbreakException("Timeout while stopping Ambari services.");
                }
            } else {
                LOGGER.warn("Failed to stop Hadoop services.");
                throw new CloudbreakException("Failed to stop Hadoop services.");
            }
            eventService.fireCloudbreakEvent(stack.getId(), UPDATE_IN_PROGRESS.name(), cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_SERVICES_STOPPED.code()));
        }
    } catch (AmbariConnectionException ignored) {
        LOGGER.debug("Ambari not running on the gateway machine, no need to stop it.");
    }
}
Also used : CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) PollingResult(com.sequenceiq.cloudbreak.service.PollingResult) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) AmbariConnectionException(com.sequenceiq.ambari.client.AmbariConnectionException) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) AmbariClient(com.sequenceiq.ambari.client.AmbariClient)

Example 44 with CloudbreakException

use of com.sequenceiq.cloudbreak.service.CloudbreakException in project cloudbreak by hortonworks.

the class ClusterCreationService method handleClusterCreationFailure.

public void handleClusterCreationFailure(StackView stackView, Exception exception) {
    if (stackView.getClusterView() != null) {
        Cluster cluster = clusterService.getById(stackView.getClusterView().getId());
        clusterService.cleanupKerberosCredential(cluster);
        String errorMessage = exception instanceof CloudbreakException && exception.getCause() != null ? exception.getCause().getMessage() : exception.getMessage();
        clusterService.updateClusterStatusByStackId(stackView.getId(), CREATE_FAILED, errorMessage);
        stackUpdater.updateStackStatus(stackView.getId(), DetailedStackStatus.AVAILABLE);
        flowMessageService.fireEventAndLog(stackView.getId(), Msg.AMBARI_CLUSTER_CREATE_FAILED, CREATE_FAILED.name(), errorMessage);
        try {
            OrchestratorType orchestratorType = orchestratorTypeResolver.resolveType(stackView.getOrchestrator().getType());
            if (cluster != null && orchestratorType.containerOrchestrator()) {
                clusterTerminationService.deleteClusterContainers(cluster);
            }
        } catch (CloudbreakException | TerminationFailedException ex) {
            LOGGER.error("Cluster containers could not be deleted, preparation for reinstall failed: ", ex);
        }
        if (cluster != null && cluster.getEmailNeeded()) {
            emailSenderService.sendProvisioningFailureEmail(cluster.getOwner(), stackView.getClusterView().getEmailTo(), cluster.getName());
            flowMessageService.fireEventAndLog(stackView.getId(), Msg.AMBARI_CLUSTER_NOTIFICATION_EMAIL, AVAILABLE.name());
        }
    } else {
        LOGGER.error("Cluster was null. Flow action was not required.");
    }
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.Cluster) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) TerminationFailedException(com.sequenceiq.cloudbreak.service.stack.flow.TerminationFailedException) OrchestratorType(com.sequenceiq.cloudbreak.common.model.OrchestratorType)

Example 45 with CloudbreakException

use of com.sequenceiq.cloudbreak.service.CloudbreakException in project cloudbreak by hortonworks.

the class ClusterResetService method handleResetClusterFailure.

public void handleResetClusterFailure(StackView stackView, Exception exception) {
    Cluster cluster = clusterService.retrieveClusterByStackId(stackView.getId());
    clusterService.cleanupKerberosCredential(cluster.getId());
    String errorMessage = exception instanceof CloudbreakException && exception.getCause() != null ? exception.getCause().getMessage() : exception.getMessage();
    clusterService.updateClusterStatusByStackId(stackView.getId(), Status.CREATE_FAILED, errorMessage);
    stackUpdater.updateStackStatus(stackView.getId(), DetailedStackStatus.AVAILABLE);
    flowMessageService.fireEventAndLog(stackView.getId(), Msg.AMBARI_CLUSTER_CREATE_FAILED, Status.CREATE_FAILED.name(), errorMessage);
    if (cluster.getEmailNeeded()) {
        emailSenderService.sendProvisioningFailureEmail(cluster.getOwner(), stackView.getClusterView().getEmailTo(), cluster.getName());
        flowMessageService.fireEventAndLog(stackView.getId(), Msg.AMBARI_CLUSTER_NOTIFICATION_EMAIL, Status.AVAILABLE.name());
    }
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.Cluster) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException)

Aggregations

CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)45 Stack (com.sequenceiq.cloudbreak.domain.Stack)23 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)22 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)18 PollingResult (com.sequenceiq.cloudbreak.service.PollingResult)14 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)13 HostOrchestrator (com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator)13 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)13 OrchestratorType (com.sequenceiq.cloudbreak.common.model.OrchestratorType)11 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)11 CloudbreakOrchestratorException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException)10 HashMap (java.util.HashMap)10 List (java.util.List)10 Map (java.util.Map)10 Set (java.util.Set)9 Inject (javax.inject.Inject)9 AmbariConnectionException (com.sequenceiq.ambari.client.AmbariConnectionException)8 Orchestrator (com.sequenceiq.cloudbreak.domain.Orchestrator)8 ArrayList (java.util.ArrayList)8 HashSet (java.util.HashSet)8