Search in sources :

Example 26 with InstanceMetaData

use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData in project cloudbreak by hortonworks.

the class StackUpscaleActions method cleanupFreeIpaAction.

@Bean(name = "CLEANUP_FREEIPA_UPSCALE_STATE")
public Action<?, ?> cleanupFreeIpaAction() {
    return new AbstractStackUpscaleAction<>(ExtendHostMetadataResult.class) {

        @Inject
        private InstanceMetaDataService instanceMetaDataService;

        @Override
        protected void doExecute(StackScalingFlowContext context, ExtendHostMetadataResult payload, Map<Object, Object> variables) {
            Set<InstanceMetaData> instanceMetaData = instanceMetaDataService.findNotTerminatedAndNotZombieForStack(context.getStack().getId());
            Set<String> ips = payload.getRequest().getUpscaleCandidateAddresses();
            Set<String> hostNames = instanceMetaData.stream().filter(im -> ips.contains(im.getPrivateIp())).filter(im -> im.getDiscoveryFQDN() != null).map(InstanceMetaData::getDiscoveryFQDN).collect(Collectors.toSet());
            CleanupFreeIpaEvent cleanupFreeIpaEvent = new CleanupFreeIpaEvent(context.getStack().getId(), hostNames, ips, context.isRepair());
            sendEvent(context, cleanupFreeIpaEvent);
        }
    };
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Action(org.springframework.statemachine.action.Action) StackScaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackScaleTriggerEvent) LoggerFactory(org.slf4j.LoggerFactory) StackToCloudStackConverter(com.sequenceiq.cloudbreak.converter.spi.StackToCloudStackConverter) EventSelectorUtil(com.sequenceiq.flow.event.EventSelectorUtil) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceGroupService(com.sequenceiq.cloudbreak.service.stack.InstanceGroupService) InstanceMetaDataToCloudInstanceConverter(com.sequenceiq.cloudbreak.converter.spi.InstanceMetaDataToCloudInstanceConverter) Map(java.util.Map) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) StackScalingFlowContext(com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext) BootstrapNewNodesResult(com.sequenceiq.cloudbreak.reactor.api.event.resource.BootstrapNewNodesResult) UpscaleStackRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpscaleStackRequest) AbstractStackFailureAction(com.sequenceiq.cloudbreak.core.flow2.stack.AbstractStackFailureAction) UpscaleStackValidationRequest(com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackValidationRequest) Collection(java.util.Collection) StackFailureContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackFailureContext) Set(java.util.Set) HOST_GROUP_WITH_HOSTNAMES(com.sequenceiq.cloudbreak.core.flow2.stack.upscale.AbstractStackUpscaleAction.HOST_GROUP_WITH_HOSTNAMES) Collectors(java.util.stream.Collectors) UpscaleStackValidationResult(com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackValidationResult) Configuration(org.springframework.context.annotation.Configuration) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) AdjustmentType(com.sequenceiq.common.api.type.AdjustmentType) List(java.util.List) UpdateDomainDnsResolverResult(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverResult) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) ExtendHostMetadataRequest(com.sequenceiq.cloudbreak.reactor.api.event.resource.ExtendHostMetadataRequest) Optional(java.util.Optional) StackCreationEvent(com.sequenceiq.cloudbreak.core.flow2.stack.provision.StackCreationEvent) BootstrapNewNodesRequest(com.sequenceiq.cloudbreak.reactor.api.event.resource.BootstrapNewNodesRequest) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) HashMap(java.util.HashMap) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) ClusterPublicEndpointManagementService(com.sequenceiq.cloudbreak.service.publicendpoint.ClusterPublicEndpointManagementService) HOST_GROUP_WITH_ADJUSTMENT(com.sequenceiq.cloudbreak.core.flow2.stack.upscale.AbstractStackUpscaleAction.HOST_GROUP_WITH_ADJUSTMENT) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) CleanupFreeIpaEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.CleanupFreeIpaEvent) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ResourceToCloudResourceConverter(com.sequenceiq.cloudbreak.converter.spi.ResourceToCloudResourceConverter) ExtendHostMetadataResult(com.sequenceiq.cloudbreak.reactor.api.event.resource.ExtendHostMetadataResult) UpscaleStackResult(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpscaleStackResult) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) GetSSHFingerprintsResult(com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsResult) UpdateDomainDnsResolverRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverRequest) Logger(org.slf4j.Logger) GetSSHFingerprintsRequest(com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsRequest) CollectMetadataResult(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult) CollectMetadataRequest(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) EnvironmentClientService(com.sequenceiq.cloudbreak.service.environment.EnvironmentClientService) ClusterProxyEnablementService(com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyEnablementService) ClusterProxyReRegistrationRequest(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.ClusterProxyReRegistrationRequest) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) MetricType(com.sequenceiq.cloudbreak.service.metrics.MetricType) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Bean(org.springframework.context.annotation.Bean) CleanupFreeIpaEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.CleanupFreeIpaEvent) ExtendHostMetadataResult(com.sequenceiq.cloudbreak.reactor.api.event.resource.ExtendHostMetadataResult) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) Map(java.util.Map) HashMap(java.util.HashMap) StackScalingFlowContext(com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext) Bean(org.springframework.context.annotation.Bean)

Example 27 with InstanceMetaData

use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData in project cloudbreak by hortonworks.

the class CollectDownscaleCandidatesHandler method collectCandidates.

private Set<Long> collectCandidates(CollectDownscaleCandidatesRequest request, Stack stack) throws CloudbreakException {
    Set<Long> privateIds = new HashSet<>();
    LOGGER.debug("Collecting candidates for downscale based on [{}] and stack CRN [{}].", request, stack.getResourceCrn());
    for (Map.Entry<String, Integer> entry : request.getHostGroupWithAdjustment().entrySet()) {
        String hostGroupName = entry.getKey();
        HostGroup hostGroup = hostGroupService.getByClusterIdAndName(stack.getCluster().getId(), hostGroupName).orElseThrow(NotFoundException.notFound("hostgroup", hostGroupName));
        LOGGER.debug("Host group has been found for cluster! It's name: {}", hostGroup.getName());
        List<InstanceMetaData> metaDataForInstanceGroup = instanceMetaDataService.findAliveInstancesInInstanceGroup(hostGroup.getInstanceGroup().getId());
        Set<InstanceMetaData> collectedCandidates = clusterApiConnectors.getConnector(stack).clusterDecomissionService().collectDownscaleCandidates(hostGroup, entry.getValue(), new HashSet<>(metaDataForInstanceGroup));
        String collectedHostsAsString = collectedCandidates.stream().map(instanceMetaData -> instanceMetaData.getDiscoveryFQDN() != null ? "FQDN: " + instanceMetaData.getDiscoveryFQDN() : "Private id: " + instanceMetaData.getPrivateId()).collect(Collectors.joining(", "));
        LOGGER.debug("The following hosts has been collected as candidates for downscale: [{}]", collectedHostsAsString);
        flowMessageService.fireEventAndLog(stack.getId(), AVAILABLE.name(), STACK_SELECT_FOR_DOWNSCALE, collectedHostsAsString);
        privateIds.addAll(collectedCandidates.stream().map(InstanceMetaData::getPrivateId).collect(Collectors.toSet()));
    }
    return privateIds;
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) STACK_SELECT_FOR_DOWNSCALE(com.sequenceiq.cloudbreak.event.ResourceEvent.STACK_SELECT_FOR_DOWNSCALE) Resource(com.sequenceiq.cloudbreak.domain.Resource) AVAILABLE(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.AVAILABLE) LoggerFactory(org.slf4j.LoggerFactory) EventSelectorUtil(com.sequenceiq.flow.event.EventSelectorUtil) HostGroupService(com.sequenceiq.cloudbreak.service.hostgroup.HostGroupService) CollectionUtils.isEmpty(org.apache.commons.collections4.CollectionUtils.isEmpty) CollectionUtils(org.apache.commons.collections4.CollectionUtils) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ResourceService(com.sequenceiq.cloudbreak.service.resource.ResourceService) Event(reactor.bus.Event) CloudbreakFlowMessageService(com.sequenceiq.cloudbreak.core.flow2.stack.CloudbreakFlowMessageService) Map(java.util.Map) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) EventHandler(com.sequenceiq.flow.reactor.api.handler.EventHandler) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) Logger(org.slf4j.Logger) Collection(java.util.Collection) Set(java.util.Set) EventBus(reactor.bus.EventBus) Collectors(java.util.stream.Collectors) List(java.util.List) Component(org.springframework.stereotype.Component) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CollectDownscaleCandidatesRequest(com.sequenceiq.cloudbreak.reactor.api.event.resource.CollectDownscaleCandidatesRequest) ClusterApiConnectors(com.sequenceiq.cloudbreak.service.cluster.ClusterApiConnectors) CollectDownscaleCandidatesResult(com.sequenceiq.cloudbreak.reactor.api.event.resource.CollectDownscaleCandidatesResult) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Map(java.util.Map) HashSet(java.util.HashSet)

Example 28 with InstanceMetaData

use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData in project cloudbreak by hortonworks.

the class DecommissionHandler method accept.

@Override
public void accept(Event<DecommissionRequest> event) {
    DecommissionRequest request = event.getData();
    DecommissionResult result;
    Set<String> hostNames = Collections.emptySet();
    boolean forced = request.getDetails() != null && request.getDetails().isForced();
    try {
        Stack stack = stackService.getByIdWithListsInTransaction(request.getResourceId());
        hostNames = getHostNamesForPrivateIds(request, stack);
        ClusterDecomissionService clusterDecomissionService = getClusterDecomissionService(stack);
        Map<String, InstanceMetaData> hostsToRemove = new HashMap<>();
        Set<String> hostGroupNames = request.getHostGroupNames();
        for (String hostGroup : hostGroupNames) {
            hostsToRemove.putAll(getRemovableHosts(clusterDecomissionService, stack, hostGroup, hostNames));
        }
        updateInstancesToDeleteRequested(hostsToRemove.values());
        if (!hostsToRemove.isEmpty()) {
            executePreTerminationRecipes(stack, hostsToRemove.keySet());
        }
        Optional<String> runtimeVersion = runtimeVersionService.getRuntimeVersion(stack.getCluster().getId());
        if (entitlementService.bulkHostsRemovalFromCMSupported(Crn.fromString(stack.getResourceCrn()).getAccountId()) && CMRepositoryVersionUtil.isCmBulkHostsRemovalAllowed(runtimeVersion)) {
            result = bulkHostsRemoval(request, hostNames, forced, stack, clusterDecomissionService, hostsToRemove);
        } else {
            result = singleHostsRemoval(request, hostNames, forced, stack, clusterDecomissionService, hostsToRemove);
        }
    } catch (Exception e) {
        LOGGER.info("Exception occurred during decommission.", e);
        if (isTolerableError(e) && forced && !request.getDetails().isRepair()) {
            eventService.fireCloudbreakEvent(request.getResourceId(), UPDATE_IN_PROGRESS.name(), CLUSTER_DECOMMISSION_FAILED_FORCE_DELETE_CONTINUE, Collections.singletonList(e.getMessage()));
            result = new DecommissionResult(request, hostNames);
        } else {
            result = new DecommissionResult(e.getMessage(), e, request, hostNames, UNKNOWN_ERROR_PHASE);
        }
    }
    eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
}
Also used : HashMap(java.util.HashMap) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) ClusterClientInitException(com.sequenceiq.cloudbreak.cluster.service.ClusterClientInitException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) FreeIpaOperationFailedException(com.sequenceiq.cloudbreak.service.freeipa.FreeIpaOperationFailedException) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ClusterDecomissionService(com.sequenceiq.cloudbreak.cluster.api.ClusterDecomissionService) DecommissionRequest(com.sequenceiq.cloudbreak.reactor.api.event.resource.DecommissionRequest) DecommissionResult(com.sequenceiq.cloudbreak.reactor.api.event.resource.DecommissionResult)

Example 29 with InstanceMetaData

use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData in project cloudbreak by hortonworks.

the class UnhealthyInstancesDetectionHandler method accept.

@Override
public void accept(Event<UnhealthyInstancesDetectionRequest> event) {
    UnhealthyInstancesDetectionRequest request = event.getData();
    UnhealthyInstancesDetectionResult result;
    Long stackId = request.getResourceId();
    Stack stack = stackService.getByIdWithTransaction(stackId);
    try {
        Set<InstanceMetaData> candidateUnhealthyInstances = unhealthyInstanceSelector.selectCandidateUnhealthyInstances(stack.getId());
        if (candidateUnhealthyInstances.isEmpty()) {
            result = new UnhealthyInstancesDetectionResult(request, Collections.emptySet());
        } else {
            Set<String> unhealthyInstances = unhealthyInstancesFinalizer.finalizeUnhealthyInstances(stack, candidateUnhealthyInstances);
            result = new UnhealthyInstancesDetectionResult(request, unhealthyInstances);
        }
    } catch (RuntimeException e) {
        String msg = String.format("Could not get statuses for unhealty instances: %s", e.getMessage());
        LOG.info(msg, e);
        result = new UnhealthyInstancesDetectionResult(msg, e, request);
    }
    eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
}
Also used : UnhealthyInstancesDetectionResult(com.sequenceiq.cloudbreak.reactor.api.event.resource.UnhealthyInstancesDetectionResult) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) UnhealthyInstancesDetectionRequest(com.sequenceiq.cloudbreak.reactor.api.event.resource.UnhealthyInstancesDetectionRequest) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 30 with InstanceMetaData

use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData in project cloudbreak by hortonworks.

the class StackStatusCheckerJob method doSync.

private void doSync(Stack stack) {
    ClusterApi connector = clusterApiConnectors.getConnector(stack);
    Set<InstanceMetaData> runningInstances = instanceMetaDataService.findNotTerminatedAndNotZombieForStack(stack.getId());
    try {
        if (isClusterManagerRunning(stack, connector)) {
            ExtendedHostStatuses extendedHostStatuses = getExtendedHostStatuses(stack, connector);
            Map<HostName, Set<HealthCheck>> hostStatuses = extendedHostStatuses.getHostsHealth();
            LOGGER.debug("Cluster '{}' state check, host certicates expiring: [{}], cm running, hoststates: {}", stack.getId(), extendedHostStatuses.isAnyCertExpiring(), hostStatuses);
            reportHealthAndSyncInstances(stack, runningInstances, getFailedInstancesInstanceMetadata(extendedHostStatuses, runningInstances), getNewHealthyHostNames(extendedHostStatuses, runningInstances), extendedHostStatuses.isAnyCertExpiring());
        } else {
            syncInstances(stack, runningInstances, false);
        }
    } catch (RuntimeException e) {
        LOGGER.warn("Error during sync", e);
        syncInstances(stack, runningInstances, false);
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ExtendedHostStatuses(com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses) ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi) Collectors.toSet(java.util.stream.Collectors.toSet) EnumSet(java.util.EnumSet) Set(java.util.Set) HostName(com.sequenceiq.cloudbreak.cloud.model.HostName)

Aggregations

InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)415 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)165 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)152 Test (org.junit.jupiter.api.Test)143 Map (java.util.Map)92 HashSet (java.util.HashSet)90 Set (java.util.Set)86 List (java.util.List)84 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)77 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)73 Collectors (java.util.stream.Collectors)71 ArrayList (java.util.ArrayList)62 Test (org.junit.Test)60 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)57 Optional (java.util.Optional)52 StackService (com.sequenceiq.cloudbreak.service.stack.StackService)48 Inject (javax.inject.Inject)47 Logger (org.slf4j.Logger)47 LoggerFactory (org.slf4j.LoggerFactory)47 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)45