Search in sources :

Example 21 with InstanceMetaData

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

the class StackImageUpdateService method checkPackageVersions.

public CheckResult checkPackageVersions(Stack stack, StatedImage newImage) {
    Set<InstanceMetaData> instanceMetaDataSet = stack.getNotDeletedAndNotZombieInstanceMetaDataSet();
    CheckResult instanceHaveMultipleVersionResult = packageVersionChecker.checkInstancesHaveMultiplePackageVersions(instanceMetaDataSet);
    if (instanceHaveMultipleVersionResult.getStatus() == EventStatus.FAILED) {
        LOGGER.debug("Check packages - Instances do have multiple package versions: {}", instanceHaveMultipleVersionResult);
        return instanceHaveMultipleVersionResult;
    }
    CheckResult instancesHaveAllMandatoryPackageVersionResult = packageVersionChecker.checkInstancesHaveAllMandatoryPackageVersion(instanceMetaDataSet);
    if (instancesHaveAllMandatoryPackageVersionResult.getStatus() == EventStatus.FAILED) {
        LOGGER.debug("Check packages - Instances are missing one or more package versions: {}", instancesHaveAllMandatoryPackageVersionResult);
        return instancesHaveAllMandatoryPackageVersionResult;
    }
    CheckResult compareImageAndInstancesMandatoryPackageVersion = packageVersionChecker.compareImageAndInstancesMandatoryPackageVersion(newImage, instanceMetaDataSet);
    if (compareImageAndInstancesMandatoryPackageVersion.getStatus() == EventStatus.FAILED) {
        LOGGER.debug("Check packages - Image and instances mandatory packages do differ: {}", compareImageAndInstancesMandatoryPackageVersion);
        return compareImageAndInstancesMandatoryPackageVersion;
    }
    return CheckResult.ok();
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CheckResult(com.sequenceiq.cloudbreak.core.flow2.CheckResult)

Example 22 with InstanceMetaData

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

the class StackDownscaleService method finishStackDownscale.

public void finishStackDownscale(StackScalingFlowContext context, Collection<Long> privateIds) throws TransactionExecutionException {
    Stack stack = context.getStack();
    stackScalingService.updateInstancesToTerminated(privateIds, stack.getId());
    List<InstanceMetaData> instanceMetaDatas = stack.getInstanceGroups().stream().flatMap(instanceGroup -> instanceGroup.getInstanceMetaDataSet().stream()).filter(im -> privateIds.contains(im.getPrivateId())).collect(toList());
    if (context.isRepair()) {
        fillDiscoveryFQDNForRepair(stack, instanceMetaDatas);
    }
    cleanupDnsRecords(stack, instanceMetaDatas);
    List<String> deletedInstanceIds = instanceMetaDatas.stream().map(instanceMetaData -> instanceMetaData.getInstanceId() != null ? instanceMetaData.getInstanceId() : instanceMetaData.getPrivateId().toString()).collect(Collectors.toList());
    stackUpdater.updateStackStatus(stack.getId(), DetailedStackStatus.DOWNSCALE_COMPLETED, String.format("Downscale of the cluster infrastructure finished successfully. Terminated node(s): %s", deletedInstanceIds));
    flowMessageService.fireEventAndLog(stack.getId(), AVAILABLE.name(), STACK_DOWNSCALE_SUCCESS, String.join(",", deletedInstanceIds));
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) Resource(com.sequenceiq.cloudbreak.domain.Resource) AVAILABLE(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.AVAILABLE) STACK_DOWNSCALE_INSTANCES(com.sequenceiq.cloudbreak.event.ResourceEvent.STACK_DOWNSCALE_INSTANCES) LoggerFactory(org.slf4j.LoggerFactory) CloudbreakRuntimeException(com.sequenceiq.cloudbreak.service.CloudbreakRuntimeException) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Inject(javax.inject.Inject) ResourceService(com.sequenceiq.cloudbreak.service.resource.ResourceService) UPDATE_IN_PROGRESS(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.UPDATE_IN_PROGRESS) Service(org.springframework.stereotype.Service) CloudbreakFlowMessageService(com.sequenceiq.cloudbreak.core.flow2.stack.CloudbreakFlowMessageService) StackUpdater(com.sequenceiq.cloudbreak.service.StackUpdater) InstanceMetadataProcessor(com.sequenceiq.cloudbreak.service.freeipa.InstanceMetadataProcessor) UPDATE_FAILED(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.UPDATE_FAILED) Logger(org.slf4j.Logger) ResourceAttributeUtil(com.sequenceiq.cloudbreak.cluster.util.ResourceAttributeUtil) Collection(java.util.Collection) StackDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackDownscaleTriggerEvent) StackFailureContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackFailureContext) Set(java.util.Set) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Collectors(java.util.stream.Collectors) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) STACK_DOWNSCALE_FAILED(com.sequenceiq.cloudbreak.event.ResourceEvent.STACK_DOWNSCALE_FAILED) StringUtils(com.amazonaws.util.StringUtils) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) STACK_DOWNSCALE_SUCCESS(com.sequenceiq.cloudbreak.event.ResourceEvent.STACK_DOWNSCALE_SUCCESS) Optional(java.util.Optional) FreeIpaCleanupService(com.sequenceiq.cloudbreak.service.freeipa.FreeIpaCleanupService) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) StackScalingService(com.sequenceiq.cloudbreak.service.stack.flow.StackScalingService) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 23 with InstanceMetaData

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

the class StackCreationActions method getTlsInfoAction.

@Bean(name = "GET_TLS_INFO_STATE")
public Action<?, ?> getTlsInfoAction() {
    return new AbstractStackCreationAction<>(GetTlsInfoResult.class) {

        @Override
        protected void doExecute(StackCreationContext context, GetTlsInfoResult payload, Map<Object, Object> variables) {
            Stack stack = stackCreationService.saveTlsInfo(context, payload.getTlsInfo());
            StackCreationContext newContext = new StackCreationContext(context.getFlowParameters(), stack, context.getCloudContext(), context.getCloudCredential(), context.getCloudStack());
            sendEvent(newContext);
        }

        @Override
        protected Selectable createRequest(StackCreationContext context) {
            Stack stack = context.getStack();
            InstanceMetaData gatewayMetaData = stack.getPrimaryGatewayInstance();
            DetailedEnvironmentResponse environment = environmentClientService.getByCrnAsInternal(stack.getEnvironmentCrn());
            CloudInstance gatewayInstance = metadataConverter.convert(gatewayMetaData, environment, stack.getStackAuthentication());
            return new GetSSHFingerprintsRequest<GetSSHFingerprintsResult>(context.getCloudContext(), context.getCloudCredential(), gatewayInstance);
        }
    };
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) StackCreationContext(com.sequenceiq.cloudbreak.core.flow2.stack.start.StackCreationContext) GetSSHFingerprintsRequest(com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsRequest) GetTlsInfoResult(com.sequenceiq.cloudbreak.cloud.event.instance.GetTlsInfoResult) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Map(java.util.Map) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Bean(org.springframework.context.annotation.Bean)

Example 24 with InstanceMetaData

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

the class InstanceTerminationService method finishInstanceTermination.

public void finishInstanceTermination(InstanceTerminationContext context, RemoveInstanceResult payload) throws TransactionService.TransactionExecutionException {
    Stack stack = context.getStack();
    List<InstanceMetaData> instanceMetaDataList = context.getInstanceMetaDataList();
    Set<Long> privateIds = instanceMetaDataList.stream().map(InstanceMetaData::getPrivateId).collect(Collectors.toSet());
    stackScalingService.updateInstancesToTerminated(privateIds, stack.getId());
    LOGGER.debug("Terminate instance result: {}", payload);
    stackUpdater.updateStackStatus(stack.getId(), DetailedStackStatus.AVAILABLE, "Instance removed");
    flowMessageService.fireEventAndLog(stack.getId(), AVAILABLE.name(), STACK_REMOVING_INSTANCE_FINISHED);
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 25 with InstanceMetaData

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

the class StackUpscaleActions method finishExtendMetadata.

@Bean(name = "EXTEND_METADATA_FINISHED_STATE")
public Action<?, ?> finishExtendMetadata() {
    return new AbstractStackUpscaleAction<>(CollectMetadataResult.class) {

        @Override
        protected void doExecute(StackScalingFlowContext context, CollectMetadataResult payload, Map<Object, Object> variables) throws TransactionExecutionException {
            Integer adjustment = context.getHostGroupWithAdjustment().values().stream().reduce(0, Integer::sum);
            Set<String> upscaleCandidateAddresses = stackUpscaleService.finishExtendMetadata(context.getStack(), adjustment, payload);
            variables.put(UPSCALE_CANDIDATE_ADDRESSES, upscaleCandidateAddresses);
            Set<String> hostGroups = context.getHostGroupWithAdjustment().keySet();
            List<InstanceGroup> scaledInstanceGroups = instanceGroupService.findByStackIdAndInstanceGroupNames(payload.getResourceId(), hostGroups);
            boolean gatewayWasUpscaled = scaledInstanceGroups.stream().anyMatch(instanceGroup -> InstanceGroupType.GATEWAY.equals(instanceGroup.getInstanceGroupType()));
            if (gatewayWasUpscaled) {
                LOGGER.info("Gateway type instance group");
                Stack stack = stackService.getByIdWithListsInTransaction(context.getStack().getId());
                InstanceMetaData gatewayMetaData = stack.getPrimaryGatewayInstance();
                if (null == gatewayMetaData) {
                    throw new CloudbreakServiceException("Could not get gateway instance metadata from the cloud provider.");
                }
                DetailedEnvironmentResponse environment = environmentClientService.getByCrnAsInternal(stack.getEnvironmentCrn());
                CloudInstance gatewayInstance = metadataConverter.convert(gatewayMetaData, environment, stack.getStackAuthentication());
                LOGGER.info("Send GetSSHFingerprintsRequest because we need to collect SSH fingerprints");
                Selectable sshFingerPrintReq = new GetSSHFingerprintsRequest<GetSSHFingerprintsResult>(context.getCloudContext(), context.getCloudCredential(), gatewayInstance);
                sendEvent(context, sshFingerPrintReq);
            } else {
                StackEvent bootstrapPayload = new StackEvent(context.getStack().getId());
                sendEvent(context, StackUpscaleEvent.BOOTSTRAP_NEW_NODES_EVENT.event(), bootstrapPayload);
            }
        }
    };
}
Also used : CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CollectMetadataResult(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult) StackScalingFlowContext(com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) GetSSHFingerprintsRequest(com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsRequest) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Map(java.util.Map) HashMap(java.util.HashMap) Bean(org.springframework.context.annotation.Bean)

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