Search in sources :

Example 11 with CancellationException

use of com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException in project cloudbreak by hortonworks.

the class ClusterHostServiceRunner method addAmbariServices.

@Transactional
public Map<String, String> addAmbariServices(Long stackId, String hostGroupName, Integer scalingAdjustment) throws CloudbreakException {
    Map<String, String> candidates;
    try {
        Stack stack = stackRepository.findOneWithLists(stackId);
        Cluster cluster = stack.getCluster();
        candidates = collectUpscaleCandidates(cluster.getId(), hostGroupName, scalingAdjustment);
        Set<Node> allNodes = collectNodes(stack);
        HostOrchestrator hostOrchestrator = hostOrchestratorResolver.get(stack.getOrchestrator().getType());
        List<GatewayConfig> gatewayConfigs = gatewayConfigService.getAllGatewayConfigs(stack);
        SaltConfig saltConfig = createSaltConfig(stack, cluster, gatewayConfigService.getPrimaryGatewayConfig(stack), gatewayConfigs);
        hostOrchestrator.runService(gatewayConfigs, allNodes, saltConfig, clusterDeletionBasedModel(stack.getId(), cluster.getId()));
    } catch (CloudbreakOrchestratorCancelledException e) {
        throw new CancellationException(e.getMessage());
    } catch (CloudbreakOrchestratorException | IOException e) {
        throw new CloudbreakException(e);
    }
    return candidates;
}
Also used : HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) SaltConfig(com.sequenceiq.cloudbreak.orchestrator.model.SaltConfig) IOException(java.io.IOException) Stack(com.sequenceiq.cloudbreak.domain.Stack) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) CloudbreakOrchestratorCancelledException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorCancelledException) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Transactional(javax.transaction.Transactional)

Example 12 with CancellationException

use of com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException 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 13 with CancellationException

use of com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException 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 14 with CancellationException

use of com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException in project cloudbreak by hortonworks.

the class AmbariClusterSecurityService method disableSecurity.

@Override
public void disableSecurity(Stack stack) {
    try {
        AmbariClient ambariClient = clientFactory.getAmbariClient(stack, stack.getCluster());
        int opId = ambariClient.disableKerberos();
        if (opId == -1) {
            return;
        }
        Map<String, Integer> operationRequests = singletonMap("DISABLE_KERBEROS_REQUEST", opId);
        Pair<PollingResult, Exception> pair = ambariOperationService.waitForOperations(stack, ambariClient, operationRequests, DISABLE_KERBEROS_STATE);
        ambariClusterConnectorPollingResultChecker.checkPollingResult(pair.getLeft(), cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_DISABLE_KERBEROS_FAILED.code()));
    } catch (CancellationException cancellationException) {
        throw cancellationException;
    } catch (Exception e) {
        throw new AmbariOperationFailedException(e.getMessage(), e);
    }
}
Also used : CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) PollingResult(com.sequenceiq.cloudbreak.service.PollingResult) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) AmbariClient(com.sequenceiq.ambari.client.AmbariClient)

Aggregations

CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)14 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)13 PollingResult (com.sequenceiq.cloudbreak.service.PollingResult)10 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)9 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)5 Stack (com.sequenceiq.cloudbreak.domain.Stack)5 CloudbreakOrchestratorCancelledException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorCancelledException)4 CloudbreakOrchestratorException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException)4 AmbariConnectionException (com.sequenceiq.ambari.client.AmbariConnectionException)3 HostOrchestrator (com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator)3 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)3 Node (com.sequenceiq.cloudbreak.orchestrator.model.Node)3 List (java.util.List)3 HostMetadata (com.sequenceiq.cloudbreak.domain.HostMetadata)2 ArrayList (java.util.ArrayList)2 Collections.singletonMap (java.util.Collections.singletonMap)2 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)2 Test (org.junit.Test)2 ExpectedException (org.junit.rules.ExpectedException)2 Matchers.anyString (org.mockito.Matchers.anyString)2