Search in sources :

Example 11 with Node

use of com.sequenceiq.cloudbreak.common.orchestration.Node in project cloudbreak by hortonworks.

the class TargetedUpscaleSupportService method getActualDnsResolverType.

public DnsResolverType getActualDnsResolverType(Stack stack) {
    LOGGER.debug("Original value of domainDnsResolver field for stack {} is {}", stack.getResourceCrn(), stack.getDomainDnsResolver());
    if (!isUnboundEliminationSupported(stack.getResourceCrn())) {
        LOGGER.debug("Since unbound elimination is not supported, then targeted upscale also won't be supported, " + "thus all 00-cluster.conf will be regenerated for all nodes of stack {}.", stack.getResourceCrn());
        return DnsResolverType.LOCAL_UNBOUND;
    } else {
        GatewayConfig primaryGatewayConfig = gatewayConfigService.getPrimaryGatewayConfig(stack);
        Set<Node> reachableNodes = stackUtil.collectReachableNodes(stack);
        Set<String> reachableHostnames = reachableNodes.stream().map(Node::getHostname).collect(Collectors.toSet());
        boolean unboundClusterConfigPresentOnAnyNodes = hostOrchestrator.unboundClusterConfigPresentOnAnyNodes(primaryGatewayConfig, reachableHostnames);
        LOGGER.debug("Result of check whether unbound config is present on nodes of stack [{}] is: {}", stack.getResourceCrn(), unboundClusterConfigPresentOnAnyNodes);
        if (unboundClusterConfigPresentOnAnyNodes) {
            LOGGER.debug("Although unbound elimination is enabled in account, 00-cluster.conf files still present on at least one node, " + "thus we will fall back to use local unbound service on all nodes of stack {}", stack.getResourceCrn());
            return DnsResolverType.LOCAL_UNBOUND;
        } else {
            LOGGER.debug("Unbound elimination is enabled in account and 00-cluster.conf files were removed from all nodes, " + "thus we can use freeIPA of environment {} to resolve DNS within environment's domain for stack {}", stack.getEnvironmentCrn(), stack.getResourceCrn());
            return DnsResolverType.FREEIPA_FOR_ENV;
        }
    }
}
Also used : Node(com.sequenceiq.cloudbreak.common.orchestration.Node) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 12 with Node

use of com.sequenceiq.cloudbreak.common.orchestration.Node in project cloudbreak by hortonworks.

the class MountDisks method mountDisks.

private void mountDisks(Stack stack, Set<Node> nodesWithDiskData, Set<Node> allNodes) throws CloudbreakException {
    Cluster cluster = stack.getCluster();
    try {
        List<GatewayConfig> gatewayConfigs = gatewayConfigService.getAllGatewayConfigs(stack);
        ExitCriteriaModel exitCriteriaModel = clusterDeletionBasedModel(stack.getId(), cluster.getId());
        Map<String, Map<String, String>> mountInfo;
        if (isCbVersionPostOptimisation(stack)) {
            mountInfo = hostOrchestrator.formatAndMountDisksOnNodes(stack, gatewayConfigs, nodesWithDiskData, allNodes, exitCriteriaModel, stack.getPlatformVariant());
        } else {
            mountInfo = hostOrchestrator.formatAndMountDisksOnNodesLegacy(gatewayConfigs, nodesWithDiskData, allNodes, exitCriteriaModel, stack.getPlatformVariant());
        }
        mountInfo.forEach((hostname, value) -> {
            Optional<String> instanceIdOptional = stack.getInstanceMetaDataAsList().stream().filter(instanceMetaData -> hostname.equals(instanceMetaData.getDiscoveryFQDN())).filter(instanceMetaData -> InstanceStatus.CREATED.equals(instanceMetaData.getInstanceStatus())).map(InstanceMetaData::getInstanceId).findFirst();
            if (instanceIdOptional.isPresent()) {
                String uuids = value.getOrDefault("uuids", "");
                String fstab = value.getOrDefault("fstab", "");
                if (!StringUtils.isEmpty(uuids) && !StringUtils.isEmpty(fstab)) {
                    persistUuidAndFstab(stack, instanceIdOptional.get(), hostname, uuids, fstab);
                }
            }
        });
    } catch (CloudbreakOrchestratorFailedException e) {
        LOGGER.error("Failed to mount disks", e);
        throw new CloudbreakSecuritySetupException(e);
    }
}
Also used : ExitCriteriaModel(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) LoggerFactory(org.slf4j.LoggerFactory) ComponentConfigProviderService(com.sequenceiq.cloudbreak.service.ComponentConfigProviderService) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ResourceService(com.sequenceiq.cloudbreak.service.resource.ResourceService) Service(org.springframework.stereotype.Service) Map(java.util.Map) CloudbreakSecuritySetupException(com.sequenceiq.cloudbreak.core.CloudbreakSecuritySetupException) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) ClusterDeletionBasedExitCriteriaModel.clusterDeletionBasedModel(com.sequenceiq.cloudbreak.core.bootstrap.service.ClusterDeletionBasedExitCriteriaModel.clusterDeletionBasedModel) Logger(org.slf4j.Logger) CloudbreakDetails(com.sequenceiq.cloudbreak.cloud.model.CloudbreakDetails) ResourceAttributeUtil(com.sequenceiq.cloudbreak.cluster.util.ResourceAttributeUtil) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) Set(java.util.Set) ExitCriteriaModel(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel) VersionComparator(com.sequenceiq.cloudbreak.util.VersionComparator) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Collectors(java.util.stream.Collectors) GatewayConfigService(com.sequenceiq.cloudbreak.service.GatewayConfigService) List(java.util.List) StackUtil(com.sequenceiq.cloudbreak.util.StackUtil) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Optional(java.util.Optional) StringUtils.substringBefore(org.apache.commons.lang3.StringUtils.substringBefore) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) StringUtils(org.springframework.util.StringUtils) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) CloudbreakSecuritySetupException(com.sequenceiq.cloudbreak.core.CloudbreakSecuritySetupException) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Map(java.util.Map) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 13 with Node

use of com.sequenceiq.cloudbreak.common.orchestration.Node in project cloudbreak by hortonworks.

the class LoggingAgentAutoRestartPatchService method doApply.

@Override
boolean doApply(Stack stack) throws ExistingStackPatchApplyException {
    if (isPrimaryGatewayReachable(stack)) {
        try {
            byte[] currentSaltState = getCurrentSaltStateStack(stack);
            List<String> saltStateDefinitions = Arrays.asList("salt-common", "salt");
            List<String> loggingAgentSaltStateDef = List.of("/salt/fluent");
            byte[] fluentSaltStateConfig = compressUtil.generateCompressedOutputFromFolders(saltStateDefinitions, loggingAgentSaltStateDef);
            boolean loggingAgentContentMatches = compressUtil.compareCompressedContent(currentSaltState, fluentSaltStateConfig, loggingAgentSaltStateDef);
            if (!loggingAgentContentMatches) {
                Set<InstanceMetaData> instanceMetaDataSet = instanceMetaDataService.findNotTerminatedAndNotZombieForStack(stack.getId());
                List<GatewayConfig> gatewayConfigs = gatewayConfigService.getAllGatewayConfigs(stack);
                ClusterDeletionBasedExitCriteriaModel exitModel = ClusterDeletionBasedExitCriteriaModel.nonCancellableModel();
                Set<Node> availableNodes = getAvailableNodes(instanceMetaDataSet, gatewayConfigs, exitModel);
                if (CollectionUtils.isEmpty(availableNodes)) {
                    LOGGER.info("Not found any available nodes for patch, stack: " + stack.getName());
                    return false;
                } else {
                    getTelemetryOrchestrator().executeLoggingAgentDiagnostics(fluentSaltStateConfig, gatewayConfigs, availableNodes, exitModel);
                    byte[] newFullSaltState = compressUtil.updateCompressedOutputFolders(saltStateDefinitions, loggingAgentSaltStateDef, currentSaltState);
                    clusterBootstrapper.updateSaltComponent(stack, newFullSaltState);
                    LOGGER.debug("Logging agent partial salt refresh and diagnostics successfully finished for stack {}", stack.getName());
                    return true;
                }
            } else {
                LOGGER.debug("Logging agent partial salt refresh and diagnostics is not required for stack {}", stack.getName());
                return true;
            }
        } catch (ExistingStackPatchApplyException e) {
            throw e;
        } catch (Exception e) {
            throw new ExistingStackPatchApplyException(e.getMessage(), e);
        }
    } else {
        LOGGER.info("Salt partial update cannot run, because primary gateway is unreachable of stack: " + stack.getResourceCrn());
        return false;
    }
}
Also used : Node(com.sequenceiq.cloudbreak.common.orchestration.Node) CloudbreakRuntimeException(com.sequenceiq.cloudbreak.service.CloudbreakRuntimeException) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ClusterDeletionBasedExitCriteriaModel(com.sequenceiq.cloudbreak.core.bootstrap.service.ClusterDeletionBasedExitCriteriaModel) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 14 with Node

use of com.sequenceiq.cloudbreak.common.orchestration.Node in project cloudbreak by hortonworks.

the class MeteringAzureMetadataPatchService method upgradeMeteringOnNodes.

private boolean upgradeMeteringOnNodes(Stack stack) throws ExistingStackPatchApplyException, IOException, CloudbreakOrchestratorFailedException {
    byte[] currentSaltState = getCurrentSaltStateStack(stack);
    List<String> saltStateDefinitions = Arrays.asList("salt-common", "salt");
    List<String> meteringSaltStateDef = List.of("/salt/metering");
    byte[] meteringSaltStateConfig = compressUtil.generateCompressedOutputFromFolders(saltStateDefinitions, meteringSaltStateDef);
    boolean meteringContentMatches = compressUtil.compareCompressedContent(currentSaltState, meteringSaltStateConfig, meteringSaltStateDef);
    if (!meteringContentMatches) {
        Set<InstanceMetaData> instanceMetaDataSet = instanceMetaDataService.findNotTerminatedAndNotZombieForStack(stack.getId());
        List<GatewayConfig> gatewayConfigs = gatewayConfigService.getAllGatewayConfigs(stack);
        ClusterDeletionBasedExitCriteriaModel exitModel = ClusterDeletionBasedExitCriteriaModel.nonCancellableModel();
        getTelemetryOrchestrator().updateMeteringSaltDefinition(meteringSaltStateConfig, gatewayConfigs, exitModel);
        Set<Node> availableNodes = getAvailableNodes(instanceMetaDataSet, gatewayConfigs, exitModel);
        if (CollectionUtils.isEmpty(availableNodes)) {
            LOGGER.info("Not found any available nodes for patch, stack: " + stack.getName());
            return false;
        } else {
            getTelemetryOrchestrator().upgradeMetering(gatewayConfigs, availableNodes, exitModel, meteringAzureMetadataPatchConfig.getDateBefore(), meteringAzureMetadataPatchConfig.getCustomRpmUrl());
            byte[] newFullSaltState = compressUtil.updateCompressedOutputFolders(saltStateDefinitions, meteringSaltStateDef, currentSaltState);
            clusterBootstrapper.updateSaltComponent(stack, newFullSaltState);
            LOGGER.debug("Metering partial salt refresh successfully finished for stack {}", stack.getName());
            return true;
        }
    } else {
        LOGGER.debug("Metering partial salt refresh is not required for stack {}", stack.getName());
        return true;
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) ClusterDeletionBasedExitCriteriaModel(com.sequenceiq.cloudbreak.core.bootstrap.service.ClusterDeletionBasedExitCriteriaModel) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 15 with Node

use of com.sequenceiq.cloudbreak.common.orchestration.Node in project cloudbreak by hortonworks.

the class SaltCheckerConclusionStepTest method checkShouldFallbackIfNodeStatusCheckFailsAndBeSuccessfulIfNoUnreachableNodeFound.

@Test
public void checkShouldFallbackIfNodeStatusCheckFailsAndBeSuccessfulIfNoUnreachableNodeFound() throws NodesUnreachableException {
    when(nodeStatusService.saltPing(eq(1L))).thenThrow(new CloudbreakServiceException("error"));
    when(stackService.getByIdWithListsInTransaction(eq(1L))).thenReturn(new Stack());
    Set<Node> nodes = Set.of(createNode("host1"), createNode("host2"));
    when(stackUtil.collectNodes(any())).thenReturn(nodes);
    when(stackUtil.collectAndCheckReachableNodes(any(), anyCollection())).thenReturn(nodes);
    Conclusion stepResult = underTest.check(1L);
    assertFalse(stepResult.isFailureFound());
    assertNull(stepResult.getConclusion());
    assertNull(stepResult.getDetails());
    assertEquals(SaltCheckerConclusionStep.class, stepResult.getConclusionStepClass());
    verify(nodeStatusService, times(1)).saltPing(eq(1L));
    verify(stackService, times(1)).getByIdWithListsInTransaction(eq(1L));
    verify(stackUtil, times(1)).collectNodes(any());
    verify(stackUtil, times(1)).collectAndCheckReachableNodes(any(), any());
}
Also used : CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Aggregations

Node (com.sequenceiq.cloudbreak.common.orchestration.Node)126 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)57 HashSet (java.util.HashSet)42 Map (java.util.Map)32 JsonNode (com.fasterxml.jackson.databind.JsonNode)30 CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)29 Test (org.junit.Test)29 HashMap (java.util.HashMap)28 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)27 CloudbreakOrchestratorException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException)26 ArrayList (java.util.ArrayList)26 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)25 ExitCriteriaModel (com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel)25 Set (java.util.Set)25 Test (org.junit.jupiter.api.Test)25 List (java.util.List)22 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)21 IOException (java.io.IOException)21 Collectors (java.util.stream.Collectors)21 BootstrapParams (com.sequenceiq.cloudbreak.orchestrator.model.BootstrapParams)19