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);
}
};
}
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);
}
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);
}
}
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));
}
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);
}
Aggregations