Search in sources :

Example 1 with HostBootstrapApiContext

use of com.sequenceiq.cloudbreak.core.bootstrap.service.host.context.HostBootstrapApiContext in project cloudbreak by hortonworks.

the class ClusterBootstrapper method bootstrapNewNodesOnHost.

private void bootstrapNewNodesOnHost(Stack stack, List<GatewayConfig> allGatewayConfigs, Set<Node> nodes, Set<Node> allNodes) throws CloudbreakException, CloudbreakOrchestratorException {
    HostOrchestrator hostOrchestrator = hostOrchestratorResolver.get(stack.getOrchestrator().getType());
    Cluster cluster = stack.getCluster();
    Boolean enableKnox = cluster.getGateway().getEnableGateway();
    for (InstanceMetaData gateway : stack.getGatewayInstanceMetadata()) {
        GatewayConfig gatewayConfig = gatewayConfigService.getGatewayConfig(stack, gateway, enableKnox);
        PollingResult bootstrapApiPolling = hostBootstrapApiPollingService.pollWithTimeoutSingleFailure(hostBootstrapApiCheckerTask, new HostBootstrapApiContext(stack, gatewayConfig, hostOrchestrator), POLL_INTERVAL, MAX_POLLING_ATTEMPTS);
        validatePollingResultForCancellation(bootstrapApiPolling, "Polling of bootstrap API was cancelled.");
    }
    byte[] stateZip = null;
    ClusterComponent stateComponent = clusterComponentProvider.getComponent(cluster.getId(), ComponentType.SALT_STATE);
    if (stateComponent != null) {
        String content = (String) stateComponent.getAttributes().getMap().getOrDefault(ComponentType.SALT_STATE.name(), "");
        if (!content.isEmpty()) {
            stateZip = Base64.decodeBase64(content);
        }
    }
    hostOrchestrator.bootstrapNewNodes(allGatewayConfigs, nodes, allNodes, stateZip, clusterDeletionBasedModel(stack.getId(), null));
    InstanceMetaData primaryGateway = stack.getPrimaryGatewayInstance();
    GatewayConfig gatewayConfig = gatewayConfigService.getGatewayConfig(stack, primaryGateway, enableKnox);
    PollingResult allNodesAvailabilityPolling = hostClusterAvailabilityPollingService.pollWithTimeoutSingleFailure(hostClusterAvailabilityCheckerTask, new HostOrchestratorClusterContext(stack, hostOrchestrator, gatewayConfig, nodes), POLL_INTERVAL, MAX_POLLING_ATTEMPTS);
    validatePollingResultForCancellation(allNodesAvailabilityPolling, "Polling of new nodes availability was cancelled.");
    if (TIMEOUT.equals(allNodesAvailabilityPolling)) {
        clusterBootstrapperErrorHandler.terminateFailedNodes(hostOrchestrator, null, stack, gatewayConfig, nodes);
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) HostOrchestratorClusterContext(com.sequenceiq.cloudbreak.core.bootstrap.service.host.context.HostOrchestratorClusterContext) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) ClusterComponent(com.sequenceiq.cloudbreak.domain.ClusterComponent) PollingResult(com.sequenceiq.cloudbreak.service.PollingResult) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) HostBootstrapApiContext(com.sequenceiq.cloudbreak.core.bootstrap.service.host.context.HostBootstrapApiContext) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 2 with HostBootstrapApiContext

use of com.sequenceiq.cloudbreak.core.bootstrap.service.host.context.HostBootstrapApiContext 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)

Aggregations

HostBootstrapApiContext (com.sequenceiq.cloudbreak.core.bootstrap.service.host.context.HostBootstrapApiContext)2 HostOrchestratorClusterContext (com.sequenceiq.cloudbreak.core.bootstrap.service.host.context.HostOrchestratorClusterContext)2 ClusterComponent (com.sequenceiq.cloudbreak.domain.ClusterComponent)2 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)2 HostOrchestrator (com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator)2 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)2 PollingResult (com.sequenceiq.cloudbreak.service.PollingResult)2 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)1 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)1 Orchestrator (com.sequenceiq.cloudbreak.domain.Orchestrator)1 Json (com.sequenceiq.cloudbreak.domain.json.Json)1 CloudbreakOrchestratorCancelledException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorCancelledException)1 CloudbreakOrchestratorException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException)1 Node (com.sequenceiq.cloudbreak.orchestrator.model.Node)1 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1