Search in sources :

Example 16 with Node

use of com.sequenceiq.cloudbreak.orchestrator.model.Node in project cloudbreak by hortonworks.

the class ClusterBootstrapper method prepareBootstrapSegments.

private List<Set<Node>> prepareBootstrapSegments(Iterable<Node> nodes, int maxBootstrapNodes, String gatewayIp) {
    List<Set<Node>> result = new ArrayList<>();
    Set<Node> newNodes = new HashSet<>();
    Node gatewayNode = getGateWayNode(nodes, gatewayIp);
    if (gatewayNode != null) {
        newNodes.add(gatewayNode);
    }
    for (Node node : nodes) {
        if (!gatewayIp.equals(node.getPublicIp())) {
            newNodes.add(node);
            if (newNodes.size() >= maxBootstrapNodes) {
                result.add(newNodes);
                newNodes = new HashSet<>();
            }
        }
    }
    if (!newNodes.isEmpty()) {
        result.add(newNodes);
    }
    return result;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 17 with Node

use of com.sequenceiq.cloudbreak.orchestrator.model.Node 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)

Example 18 with Node

use of com.sequenceiq.cloudbreak.orchestrator.model.Node in project cloudbreak by hortonworks.

the class ClusterBootstrapper method bootstrapOnHost.

@SuppressFBWarnings("REC_CATCH_EXCEPTION")
@SuppressWarnings("unchecked")
public void bootstrapOnHost(Stack stack) throws CloudbreakException {
    Set<Node> nodes = new HashSet<>();
    String domain = hostDiscoveryService.determineDomain(stack.getCustomDomain(), stack.getName(), stack.isClusterNameAsSubdomain());
    for (InstanceMetaData im : stack.getRunningInstanceMetaData()) {
        if (im.getPrivateIp() == null && im.getPublicIpWrapper() == null) {
            LOGGER.warn("Skipping instance metadata because the public ip and private ips are null '{}'.", im);
        } else {
            String generatedHostName = hostDiscoveryService.generateHostname(stack.getCustomHostname(), im.getInstanceGroupName(), im.getPrivateId(), stack.isHostgroupNameAsHostname());
            nodes.add(new Node(im.getPrivateIp(), im.getPublicIpWrapper(), generatedHostName, domain, im.getInstanceGroupName()));
        }
    }
    try {
        HostOrchestrator hostOrchestrator = hostOrchestratorResolver.get(stack.getOrchestrator().getType());
        List<GatewayConfig> allGatewayConfig = new ArrayList<>();
        Boolean enableKnox = stack.getCluster().getGateway().getEnableGateway();
        for (InstanceMetaData gateway : stack.getGatewayInstanceMetadata()) {
            GatewayConfig gatewayConfig = gatewayConfigService.getGatewayConfig(stack, gateway, enableKnox);
            allGatewayConfig.add(gatewayConfig);
            PollingResult bootstrapApiPolling = hostBootstrapApiPollingService.pollWithTimeoutSingleFailure(hostBootstrapApiCheckerTask, new HostBootstrapApiContext(stack, gatewayConfig, hostOrchestrator), POLL_INTERVAL, MAX_POLLING_ATTEMPTS);
            validatePollingResultForCancellation(bootstrapApiPolling, "Polling of bootstrap API was cancelled.");
        }
        ClusterComponent saltComponent = clusterComponentProvider.getComponent(stack.getCluster().getId(), ComponentType.SALT_STATE);
        if (saltComponent == null) {
            byte[] stateConfigZip = hostOrchestrator.getStateConfigZip();
            saltComponent = new ClusterComponent(ComponentType.SALT_STATE, new Json(singletonMap(ComponentType.SALT_STATE.name(), Base64.encodeBase64String(stateConfigZip))), stack.getCluster());
            clusterComponentProvider.store(saltComponent);
        }
        hostOrchestrator.bootstrap(allGatewayConfig, nodes, clusterDeletionBasedModel(stack.getId(), null));
        InstanceMetaData primaryGateway = stack.getPrimaryGatewayInstance();
        GatewayConfig gatewayConfig = gatewayConfigService.getGatewayConfig(stack, primaryGateway, enableKnox);
        String gatewayIp = gatewayConfigService.getGatewayIp(stack, primaryGateway);
        PollingResult allNodesAvailabilityPolling = hostClusterAvailabilityPollingService.pollWithTimeoutSingleFailure(hostClusterAvailabilityCheckerTask, new HostOrchestratorClusterContext(stack, hostOrchestrator, gatewayConfig, nodes), POLL_INTERVAL, MAX_POLLING_ATTEMPTS);
        validatePollingResultForCancellation(allNodesAvailabilityPolling, "Polling of all nodes availability was cancelled.");
        Orchestrator orchestrator = stack.getOrchestrator();
        orchestrator.setApiEndpoint(gatewayIp + ':' + stack.getGatewayPort());
        orchestrator.setType(hostOrchestrator.name());
        orchestratorRepository.save(orchestrator);
        if (TIMEOUT.equals(allNodesAvailabilityPolling)) {
            clusterBootstrapperErrorHandler.terminateFailedNodes(hostOrchestrator, null, stack, gatewayConfig, nodes);
        }
    } catch (Exception e) {
        throw new CloudbreakException(e);
    }
}
Also used : HostOrchestratorClusterContext(com.sequenceiq.cloudbreak.core.bootstrap.service.host.context.HostOrchestratorClusterContext) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) ClusterComponent(com.sequenceiq.cloudbreak.domain.ClusterComponent) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) ArrayList(java.util.ArrayList) HostBootstrapApiContext(com.sequenceiq.cloudbreak.core.bootstrap.service.host.context.HostBootstrapApiContext) Json(com.sequenceiq.cloudbreak.domain.json.Json) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) CloudbreakOrchestratorCancelledException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorCancelledException) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) PollingResult(com.sequenceiq.cloudbreak.service.PollingResult) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) HashSet(java.util.HashSet) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 19 with Node

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

use of com.sequenceiq.cloudbreak.orchestrator.model.Node in project cloudbreak by hortonworks.

the class SaltOrchestratorTest method setUp.

@Before
public void setUp() throws Exception {
    gatewayConfig = new GatewayConfig("1.1.1.1", "10.0.0.1", "172.16.252.43", "10-0-0-1", 9443, "servercert", "clientcert", "clientkey", "saltpasswd", "saltbootpassword", "signkey", false, true, null, null);
    targets = new HashSet<>();
    targets.add(new Node("10.0.0.1", "1.1.1.1", "10-0-0-1.example.com", "hg"));
    targets.add(new Node("10.0.0.2", "1.1.1.2", "10-0-0-2.example.com", "hg"));
    targets.add(new Node("10.0.0.3", "1.1.1.3", "10-0-0-3.example.com", "hg"));
    saltConnector = mock(SaltConnector.class);
    whenNew(SaltConnector.class).withAnyArguments().thenReturn(saltConnector);
    parallelOrchestratorComponentRunner = mock(ParallelOrchestratorComponentRunner.class);
    when(parallelOrchestratorComponentRunner.submit(any())).thenReturn(CompletableFuture.completedFuture(true));
    when(hostDiscoveryService.determineDomain("test", "test", false)).thenReturn(".example.com");
    exitCriteria = mock(ExitCriteria.class);
    exitCriteriaModel = mock(ExitCriteriaModel.class);
}
Also used : ExitCriteriaModel(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel) ParallelOrchestratorComponentRunner(com.sequenceiq.cloudbreak.orchestrator.executor.ParallelOrchestratorComponentRunner) ExitCriteria(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteria) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Before(org.junit.Before)

Aggregations

Node (com.sequenceiq.cloudbreak.orchestrator.model.Node)25 HashSet (java.util.HashSet)13 SaltConnector (com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector)12 CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)11 CloudbreakOrchestratorException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException)10 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)10 ArrayList (java.util.ArrayList)9 IOException (java.io.IOException)8 HostOrchestrator (com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator)7 Map (java.util.Map)7 Set (java.util.Set)7 Test (org.junit.Test)7 SaltConfig (com.sequenceiq.cloudbreak.orchestrator.model.SaltConfig)6 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)6 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)5 OrchestratorBootstrap (com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrap)5 CloudbreakOrchestratorCancelledException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorCancelledException)5 GrainAddRunner (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainAddRunner)5 HighStateRunner (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.HighStateRunner)5 SyncGrainsRunner (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.SyncGrainsRunner)5