Search in sources :

Example 51 with Stack

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

the class StackStartActions method stackStartAction.

@Bean(name = "START_STATE")
public Action<?, ?> stackStartAction() {
    return new AbstractStackStartAction<>(StackEvent.class) {

        @Override
        protected void doExecute(StackStartStopContext context, StackEvent payload, Map<Object, Object> variables) {
            stackStartStopService.startStackStart(context);
            sendEvent(context);
        }

        @Override
        protected Selectable createRequest(StackStartStopContext context) {
            Stack stack = context.getStack();
            LOGGER.debug("Assembling start request for stack: {}", stack);
            List<CloudInstance> cloudInstances = instanceMetaDataToCloudInstanceConverter.convert(stack.getNotDeletedAndNotZombieInstanceMetaDataList(), stack.getEnvironmentCrn(), stack.getStackAuthentication());
            List<CloudResource> resources = stack.getResources().stream().map(s -> resourceToCloudResourceConverter.convert(s)).collect(Collectors.toList());
            cloudInstances.forEach(instance -> context.getStack().getParameters().forEach(instance::putParameter));
            return new StartInstancesRequest(context.getCloudContext(), context.getCloudCredential(), resources, cloudInstances);
        }
    };
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Action(org.springframework.statemachine.action.Action) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Payload(com.sequenceiq.cloudbreak.common.event.Payload) AvailabilityZone.availabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone.availabilityZone) LoggerFactory(org.slf4j.LoggerFactory) StackToCloudStackConverter(com.sequenceiq.cloudbreak.converter.spi.StackToCloudStackConverter) Location.location(com.sequenceiq.cloudbreak.cloud.model.Location.location) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ResourceToCloudResourceConverter(com.sequenceiq.cloudbreak.converter.spi.ResourceToCloudResourceConverter) ResourceService(com.sequenceiq.cloudbreak.service.resource.ResourceService) InstanceMetaDataToCloudInstanceConverter(com.sequenceiq.cloudbreak.converter.spi.InstanceMetaDataToCloudInstanceConverter) StateContext(org.springframework.statemachine.StateContext) Map(java.util.Map) Location(com.sequenceiq.cloudbreak.cloud.model.Location) StartInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.StartInstancesRequest) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) StartInstancesResult(com.sequenceiq.cloudbreak.cloud.event.instance.StartInstancesResult) AbstractStackAction(com.sequenceiq.cloudbreak.core.flow2.AbstractStackAction) AbstractStackFailureAction(com.sequenceiq.cloudbreak.core.flow2.stack.AbstractStackFailureAction) Logger(org.slf4j.Logger) CollectMetadataResult(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult) CollectMetadataRequest(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) StackFailureContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackFailureContext) Region.region(com.sequenceiq.cloudbreak.cloud.model.Region.region) FlowParameters(com.sequenceiq.flow.core.FlowParameters) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Collectors(java.util.stream.Collectors) Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) StackUtil(com.sequenceiq.cloudbreak.util.StackUtil) MetricType(com.sequenceiq.cloudbreak.service.metrics.MetricType) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Optional(java.util.Optional) Bean(org.springframework.context.annotation.Bean) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) StartInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.StartInstancesRequest) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Map(java.util.Map) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Bean(org.springframework.context.annotation.Bean)

Example 52 with Stack

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

the class LoadBalancerRecreatorService method recreate.

@Override
public void recreate(CreateResourcesRequest request, AwsContext awsContext, AuthenticatedContext ac) throws Exception {
    LOGGER.info("Launching elastic load balancers");
    CloudCredential cloudCredential = ac.getCloudCredential();
    String region = ac.getCloudContext().getLocation().getRegion().value();
    AwsCredentialView awsCredentialView = new AwsCredentialView(cloudCredential);
    AmazonElasticLoadBalancingClient elasticLoadBalancingClient = commonAwsClient.createElasticLoadBalancingClient(awsCredentialView, region);
    CloudStack cloudStack = request.getCloudStack();
    loadBalancerLaunchService.launchLoadBalancerResources(ac, cloudStack, persistenceNotifier, elasticLoadBalancingClient, false);
    List<CloudLoadBalancerMetadata> cloudLoadBalancerMetadata = collectLoadBalancerMetadata(ac, ac.getCloudContext().getId());
    Stack stack = stackService.getByIdWithLists(ac.getCloudContext().getId());
    metadataSetupService.saveLoadBalancerMetadata(stack, cloudLoadBalancerMetadata);
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) AmazonElasticLoadBalancingClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonElasticLoadBalancingClient) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack)

Example 53 with Stack

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

the class AbstractStackDownscaleAction method createFlowContext.

@Override
protected StackScalingFlowContext createFlowContext(FlowParameters flowParameters, StateContext<StackDownscaleState, StackDownscaleEvent> stateContext, P payload) {
    Map<Object, Object> variables = stateContext.getExtendedState().getVariables();
    LOGGER.info("Variables in AbstractStackDownscaleAction: {}", variables);
    Stack stack = stackService.getByIdWithListsInTransaction(payload.getResourceId());
    stack.setResources(new HashSet<>(resourceService.getAllByStackId(payload.getResourceId())));
    MDCBuilder.buildMdcContext(stack);
    Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
    CloudContext cloudContext = getCloudContext(stack, location);
    CloudCredential cloudCredential = stackUtil.getCloudCredential(stack);
    CloudStack cloudStack = cloudStackConverter.convert(stack);
    if (payload instanceof StackDownscaleTriggerEvent) {
        return createStackScalingFlowContextFromPayload(flowParameters, (StackDownscaleTriggerEvent) payload, variables, stack, cloudContext, cloudCredential, cloudStack);
    } else {
        return createStackScalingFlowContextFromVariables(flowParameters, variables, stack, cloudContext, cloudCredential, cloudStack);
    }
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) StackDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackDownscaleTriggerEvent) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Example 54 with Stack

use of com.sequenceiq.cloudbreak.domain.stack.Stack 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 55 with Stack

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

the class AbstractStackCreationAction method createFlowContext.

@Override
protected StackCreationContext createFlowContext(FlowParameters flowParameters, StateContext<StackCreationState, StackCreationEvent> stateContext, P payload) {
    Stack stack = stackService.getByIdWithListsInTransaction(payload.getResourceId());
    stack.setResources(new HashSet<>(resourceService.getAllByStackId(payload.getResourceId())));
    Map<Object, Object> variables = stateContext.getExtendedState().getVariables();
    ProvisionType provisionType = (ProvisionType) variables.getOrDefault(PROVISION_TYPE, ProvisionType.REGULAR);
    MDCBuilder.buildMdcContext(stack);
    Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
    CloudContext cloudContext = CloudContext.Builder.builder().withId(stack.getId()).withName(stack.getName()).withCrn(stack.getResourceCrn()).withPlatform(stack.getCloudPlatform()).withVariant(stack.getPlatformVariant()).withUserName(stack.getCreator().getUserName()).withLocation(location).withWorkspaceId(stack.getWorkspace().getId()).withAccountId(Crn.safeFromString(stack.getResourceCrn()).getAccountId()).withTenantId(stack.getTenant().getId()).build();
    CloudCredential cloudCredential = stackUtil.getCloudCredential(stack);
    CloudStack cloudStack = cloudStackConverter.convert(stack);
    return new StackCreationContext(flowParameters, stack, cloudContext, cloudCredential, cloudStack, provisionType);
}
Also used : StackCreationContext(com.sequenceiq.cloudbreak.core.flow2.stack.start.StackCreationContext) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) ProvisionType(com.sequenceiq.cloudbreak.reactor.api.event.stack.ProvisionType) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Aggregations

Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1041 Test (org.junit.jupiter.api.Test)326 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)255 Test (org.junit.Test)208 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)158 Map (java.util.Map)114 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)113 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)112 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)111 List (java.util.List)101 Set (java.util.Set)101 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)100 Collectors (java.util.stream.Collectors)84 Optional (java.util.Optional)83 HashSet (java.util.HashSet)82 Inject (javax.inject.Inject)80 Logger (org.slf4j.Logger)78 LoggerFactory (org.slf4j.LoggerFactory)78 DetailedStackStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus)69 StackStatus (com.sequenceiq.cloudbreak.domain.stack.StackStatus)67