Search in sources :

Example 6 with CancellationException

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

the class AmbariClusterSetupService method waitForServer.

@Override
public void waitForServer(Stack stack) throws CloudbreakException {
    AmbariClient defaultClient = clientFactory.getDefaultAmbariClient(stack);
    AmbariClient client = clientFactory.getAmbariClient(stack, stack.getCluster());
    PollingResult pollingResult = ambariPollingServiceProvider.ambariStartupPollerObjectPollingService(stack, defaultClient, client);
    if (isSuccess(pollingResult)) {
        LOGGER.info("Ambari has successfully started! Polling result: {}", pollingResult);
    } else if (isExited(pollingResult)) {
        throw new CancellationException("Polling of Ambari server start has been cancelled.");
    } else {
        LOGGER.info("Could not start Ambari. polling result: {}", pollingResult);
        throw new CloudbreakException(String.format("Could not start Ambari. polling result: '%s'", pollingResult));
    }
}
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)

Example 7 with CancellationException

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

the class AmbariClusterSecurityServiceTest method testDisableSecurityWhenCancellationExceptionOccursThenShouldThrowCancellationException.

@Test
public void testDisableSecurityWhenCancellationExceptionOccursThenShouldThrowCancellationException() throws CloudbreakException {
    Stack stack = TestUtil.stack();
    Cluster cluster = TestUtil.cluster();
    stack.setCluster(cluster);
    AmbariClient ambariClient = Mockito.mock(AmbariClient.class);
    when(clientFactory.getAmbariClient(stack, stack.getCluster())).thenReturn(ambariClient);
    when(ambariClient.disableKerberos()).thenReturn(1);
    Map<String, Integer> operationRequests = singletonMap("DISABLE_KERBEROS_REQUEST", 1);
    ImmutablePair<PollingResult, Exception> pair = new ImmutablePair<>(PollingResult.EXIT, null);
    String failed = "failed";
    when(ambariOperationService.waitForOperations(stack, ambariClient, operationRequests, DISABLE_KERBEROS_STATE)).thenThrow(new CancellationException("cancel"));
    when(cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_DISABLE_KERBEROS_FAILED.code())).thenReturn("failed");
    doThrow(new CancellationException("cancel")).when(ambariClusterConnectorPollingResultChecker).checkPollingResult(pair.getLeft(), failed);
    thrown.expect(CancellationException.class);
    thrown.expectMessage("cancel");
    underTest.disableSecurity(stack);
    verify(ambariOperationService, times(1)).waitForOperations(stack, ambariClient, operationRequests, DISABLE_KERBEROS_STATE);
    verify(cloudbreakMessagesService, times(1)).getMessage(AMBARI_CLUSTER_DISABLE_KERBEROS_FAILED.code());
    verify(ambariClusterConnectorPollingResultChecker, times(1)).checkPollingResult(pair.getLeft(), failed);
}
Also used : ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) PollingResult(com.sequenceiq.cloudbreak.service.PollingResult) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) Matchers.anyString(org.mockito.Matchers.anyString) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) AmbariConnectionException(com.sequenceiq.ambari.client.AmbariConnectionException) ExpectedException(org.junit.rules.ExpectedException) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) Stack(com.sequenceiq.cloudbreak.domain.Stack) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) Test(org.junit.Test)

Example 8 with CancellationException

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

the class AmbariClusterSecurityServiceTest method testPrepareSecurityWhenCancellationExceptionOccursThenShouldThrowCancellationException.

@Test
public void testPrepareSecurityWhenCancellationExceptionOccursThenShouldThrowCancellationException() throws CloudbreakException {
    Stack stack = TestUtil.stack();
    Cluster cluster = TestUtil.cluster();
    stack.setCluster(cluster);
    AmbariClient ambariClient = Mockito.mock(AmbariClient.class);
    when(clientFactory.getAmbariClient(stack, stack.getCluster())).thenReturn(ambariClient);
    when(ambariClient.startService(anyString())).thenReturn(1);
    when(ambariClient.stopService(anyString())).thenReturn(1);
    Map<String, Integer> operationRequests = new HashMap<>();
    operationRequests.put("ZOOKEEPER_SERVICE_STATE", 1);
    operationRequests.put("HDFS_SERVICE_STATE", 1);
    operationRequests.put("YARN_SERVICE_STATE", 1);
    operationRequests.put("MAPREDUCE2_SERVICE_STATE", 1);
    operationRequests.put("KERBEROS_SERVICE_STATE", 1);
    ImmutablePair<PollingResult, Exception> pair = new ImmutablePair<>(PollingResult.EXIT, null);
    String failed = "failed";
    when(ambariOperationService.waitForOperations(stack, ambariClient, operationRequests, PREPARE_DEKERBERIZING)).thenThrow(new CancellationException("cancel"));
    when(cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_PREPARE_DEKERBERIZING_FAILED.code())).thenReturn("failed");
    doThrow(new CancellationException("cancel")).when(ambariClusterConnectorPollingResultChecker).checkPollingResult(pair.getLeft(), failed);
    thrown.expect(CancellationException.class);
    thrown.expectMessage("cancel");
    underTest.prepareSecurity(stack);
    verify(ambariOperationService, times(1)).waitForOperations(stack, ambariClient, operationRequests, PREPARE_DEKERBERIZING);
    verify(cloudbreakMessagesService, times(1)).getMessage(AMBARI_CLUSTER_PREPARE_DEKERBERIZING_FAILED.code());
    verify(ambariClusterConnectorPollingResultChecker, times(1)).checkPollingResult(pair.getLeft(), failed);
}
Also used : ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) HashMap(java.util.HashMap) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) PollingResult(com.sequenceiq.cloudbreak.service.PollingResult) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) Matchers.anyString(org.mockito.Matchers.anyString) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) AmbariConnectionException(com.sequenceiq.ambari.client.AmbariConnectionException) ExpectedException(org.junit.rules.ExpectedException) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) Stack(com.sequenceiq.cloudbreak.domain.Stack) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) Test(org.junit.Test)

Example 9 with CancellationException

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

the class ResourceCreateThread method call.

@Override
public ResourceRequestResult<List<CloudResourceStatus>> call() {
    List<CloudResourceStatus> results = new ArrayList<>();
    Collection<CloudResource> buildableResources = new ArrayList<>();
    try {
        for (ComputeResourceBuilder builder : resourceBuilders.compute(auth.getCloudContext().getPlatform())) {
            LOGGER.info("Building {} resources of {} instance group", builder.resourceType(), group.getName());
            List<CloudResource> cloudResources = builder.create(context, privateId, auth, group, image);
            if (!cloudResources.isEmpty()) {
                buildableResources.addAll(cloudResources);
                createResource(auth, cloudResources);
                PollGroup pollGroup = InMemoryStateStore.getStack(auth.getCloudContext().getId());
                if (pollGroup != null && CANCELLED.equals(pollGroup)) {
                    throw new CancellationException(format("Building of %s has been cancelled", cloudResources));
                }
                List<CloudResource> resources = builder.build(context, privateId, auth, group, image, cloudResources, tags);
                updateResource(auth, resources);
                context.addComputeResources(privateId, resources);
                PollTask<List<CloudResourceStatus>> task = resourcePollTaskFactory.newPollResourceTask(builder, auth, resources, context, true);
                List<CloudResourceStatus> pollerResult = syncPollingScheduler.schedule(task);
                for (CloudResourceStatus resourceStatus : pollerResult) {
                    resourceStatus.setPrivateId(privateId);
                }
                results.addAll(pollerResult);
            }
        }
    } catch (CancellationException e) {
        throw e;
    } catch (Exception e) {
        LOGGER.error("", e);
        results.clear();
        for (CloudResource buildableResource : buildableResources) {
            results.add(new CloudResourceStatus(buildableResource, ResourceStatus.FAILED, e.getMessage(), privateId));
        }
        return new ResourceRequestResult<>(FutureResult.FAILED, results);
    }
    return new ResourceRequestResult<>(FutureResult.SUCCESS, results);
}
Also used : ArrayList(java.util.ArrayList) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) PollGroup(com.sequenceiq.cloudbreak.cloud.scheduler.PollGroup) ComputeResourceBuilder(com.sequenceiq.cloudbreak.cloud.template.ComputeResourceBuilder) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) ArrayList(java.util.ArrayList) List(java.util.List) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Example 10 with CancellationException

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

the class ClusterBootstrapper method bootstrapNewNodes.

public void bootstrapNewNodes(Long stackId, Set<String> upscaleCandidateAddresses, Collection<String> recoveryHostNames) throws CloudbreakException {
    Stack stack = stackRepository.findOneWithLists(stackId);
    Set<Node> nodes = new HashSet<>();
    Set<Node> allNodes = new HashSet<>();
    boolean recoveredNodes = Integer.valueOf(recoveryHostNames.size()).equals(upscaleCandidateAddresses.size());
    Set<InstanceMetaData> metaDataSet = stack.getRunningInstanceMetaData().stream().filter(im -> im.getPrivateIp() != null && im.getPublicIpWrapper() != null).collect(Collectors.toSet());
    String clusterDomain = metaDataSet.stream().filter(im -> isNoneBlank(im.getDiscoveryFQDN())).findAny().get().getDomain();
    for (InstanceMetaData im : metaDataSet) {
        Node node = createNode(stack.getCustomHostname(), im, clusterDomain, stack.isHostgroupNameAsHostname());
        if (upscaleCandidateAddresses.contains(im.getPrivateIp())) {
            // but only when we would have generated a hostname, otherwise use the cloud provider's default mechanism
            if (recoveredNodes && isNoneBlank(node.getHostname())) {
                Iterator<String> iterator = recoveryHostNames.iterator();
                node.setHostname(iterator.next().split("\\.")[0]);
                iterator.remove();
                LOGGER.info("Set the hostname to {} for address: {}", node.getHostname(), im.getPrivateIp());
            }
            nodes.add(node);
        }
        allNodes.add(node);
    }
    try {
        String stackOrchestratorType = stack.getOrchestrator().getType();
        OrchestratorType orchestratorType = orchestratorTypeResolver.resolveType(stack.getOrchestrator().getType());
        if (orchestratorType.hostOrchestrator()) {
            List<GatewayConfig> allGatewayConfigs = gatewayConfigService.getAllGatewayConfigs(stack);
            bootstrapNewNodesOnHost(stack, allGatewayConfigs, nodes, allNodes);
        } else if (orchestratorType.containerOrchestrator()) {
            LOGGER.info("Skipping bootstrap of the new machines because the stack's orchestrator type is '{}'.", stackOrchestratorType);
        } else {
            LOGGER.error("Orchestrator not found: {}", stackOrchestratorType);
            throw new CloudbreakException("HostOrchestrator not found: " + stackOrchestratorType);
        }
    } catch (CloudbreakOrchestratorCancelledException e) {
        throw new CancellationException(e.getMessage());
    } catch (CloudbreakOrchestratorException e) {
        throw new CloudbreakException(e);
    }
}
Also used : CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) ComponentType(com.sequenceiq.cloudbreak.common.type.ComponentType) CloudbreakOrchestratorCancelledException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorCancelledException) LoggerFactory(org.slf4j.LoggerFactory) HostDiscoveryService(com.sequenceiq.cloudbreak.common.service.HostDiscoveryService) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) Base64(org.apache.commons.codec.binary.Base64) TIMEOUT(com.sequenceiq.cloudbreak.service.PollingResult.TIMEOUT) OrchestratorRepository(com.sequenceiq.cloudbreak.repository.OrchestratorRepository) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) ContainerOrchestratorClusterContext(com.sequenceiq.cloudbreak.core.bootstrap.service.container.context.ContainerOrchestratorClusterContext) Collection(java.util.Collection) Set(java.util.Set) EXIT(com.sequenceiq.cloudbreak.service.PollingResult.EXIT) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) Collectors(java.util.stream.Collectors) HostOrchestratorClusterContext(com.sequenceiq.cloudbreak.core.bootstrap.service.host.context.HostOrchestratorClusterContext) GatewayConfigService(com.sequenceiq.cloudbreak.service.GatewayConfigService) List(java.util.List) ContainerClusterAvailabilityCheckerTask(com.sequenceiq.cloudbreak.core.bootstrap.service.container.ContainerClusterAvailabilityCheckerTask) HostOrchestratorResolver(com.sequenceiq.cloudbreak.core.bootstrap.service.host.HostOrchestratorResolver) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) ContainerBootstrapApiContext(com.sequenceiq.cloudbreak.core.bootstrap.service.container.context.ContainerBootstrapApiContext) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) StringUtils.isNoneBlank(org.apache.commons.lang3.StringUtils.isNoneBlank) PollingService(com.sequenceiq.cloudbreak.service.PollingService) StackRepository(com.sequenceiq.cloudbreak.repository.StackRepository) ContainerOrchestratorResolver(com.sequenceiq.cloudbreak.core.bootstrap.service.container.ContainerOrchestratorResolver) ContainerBootstrapApiCheckerTask(com.sequenceiq.cloudbreak.core.bootstrap.service.container.ContainerBootstrapApiCheckerTask) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) HostBootstrapApiContext(com.sequenceiq.cloudbreak.core.bootstrap.service.host.context.HostBootstrapApiContext) ClusterComponent(com.sequenceiq.cloudbreak.domain.ClusterComponent) Collections.singletonMap(java.util.Collections.singletonMap) Json(com.sequenceiq.cloudbreak.domain.json.Json) ClusterComponentConfigProvider(com.sequenceiq.cloudbreak.service.ClusterComponentConfigProvider) PollingResult(com.sequenceiq.cloudbreak.service.PollingResult) Stack(com.sequenceiq.cloudbreak.domain.Stack) HostClusterAvailabilityCheckerTask(com.sequenceiq.cloudbreak.core.bootstrap.service.host.HostClusterAvailabilityCheckerTask) ClusterDeletionBasedExitCriteriaModel.clusterDeletionBasedModel(com.sequenceiq.cloudbreak.core.bootstrap.service.ClusterDeletionBasedExitCriteriaModel.clusterDeletionBasedModel) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) HostBootstrapApiCheckerTask(com.sequenceiq.cloudbreak.core.bootstrap.service.host.HostBootstrapApiCheckerTask) Component(org.springframework.stereotype.Component) OrchestratorType(com.sequenceiq.cloudbreak.common.model.OrchestratorType) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) OrchestratorType(com.sequenceiq.cloudbreak.common.model.OrchestratorType) Stack(com.sequenceiq.cloudbreak.domain.Stack) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) 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) HashSet(java.util.HashSet) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

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