use of com.sequenceiq.cloudbreak.cloud.model.CloudResource in project cloudbreak by hortonworks.
the class AwsResourceConnector method terminate.
@Override
public List<CloudResourceStatus> terminate(AuthenticatedContext ac, CloudStack stack, List<CloudResource> resources) {
LOGGER.info("Deleting stack: {}", ac.getCloudContext().getId());
AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential());
String regionName = ac.getCloudContext().getLocation().getRegion().value();
if (resources != null && !resources.isEmpty()) {
AmazonCloudFormationClient cfClient = awsClient.createCloudFormationClient(credentialView, regionName);
CloudResource stackResource = getCloudFormationStackResource(resources);
if (stackResource == null) {
return Collections.emptyList();
}
String cFStackName = stackResource.getName();
LOGGER.info("Deleting CloudFormation stack for stack: {} [cf stack id: {}]", cFStackName, ac.getCloudContext().getId());
DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest().withStackName(cFStackName);
try {
retryService.testWith2SecDelayMax5Times(() -> {
try {
cfClient.describeStacks(describeStacksRequest);
} catch (AmazonServiceException e) {
if (!e.getErrorMessage().contains(cFStackName + " does not exist")) {
throw e;
}
throw new ActionWentFailException("Stack not exists");
}
return Boolean.TRUE;
});
} catch (ActionWentFailException ignored) {
LOGGER.info(String.format("Stack not found with name: %s", cFStackName));
AmazonEC2Client amazonEC2Client = awsClient.createAccess(credentialView, regionName);
releaseReservedIp(amazonEC2Client, resources);
return Collections.emptyList();
}
resumeAutoScalingPolicies(ac, stack);
DeleteStackRequest deleteStackRequest = new DeleteStackRequest().withStackName(cFStackName);
cfClient.deleteStack(deleteStackRequest);
PollTask<Boolean> task = awsPollTaskFactory.newAwsTerminateStackStatusCheckerTask(ac, cfClient, DELETE_COMPLETE, DELETE_FAILED, ERROR_STATUSES, cFStackName);
try {
Boolean statePollerResult = task.call();
if (!task.completed(statePollerResult)) {
syncPollingScheduler.schedule(task);
}
} catch (Exception e) {
throw new CloudConnectorException(e.getMessage(), e);
}
AmazonEC2Client amazonEC2Client = awsClient.createAccess(credentialView, regionName);
releaseReservedIp(amazonEC2Client, resources);
deleteKeyPair(ac, stack);
} else if (resources != null) {
AmazonEC2Client amazonEC2Client = awsClient.createAccess(credentialView, regionName);
releaseReservedIp(amazonEC2Client, resources);
LOGGER.info("No CloudFormation stack saved for stack.");
} else {
LOGGER.info("No resources to release.");
}
return check(ac, resources);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudResource in project cloudbreak by hortonworks.
the class StackCreationActions method provisioningFinishedAction.
@Bean(name = "PROVISIONING_FINISHED_STATE")
public Action<?, ?> provisioningFinishedAction() {
return new AbstractStackCreationAction<LaunchStackResult>(LaunchStackResult.class) {
@Override
protected void doExecute(StackContext context, LaunchStackResult payload, Map<Object, Object> variables) {
Stack stack = stackCreationService.provisioningFinished(context, payload, variables);
StackContext newContext = new StackContext(context.getFlowId(), stack, context.getCloudContext(), context.getCloudCredential(), context.getCloudStack());
sendEvent(newContext);
}
@Override
protected Selectable createRequest(StackContext context) {
List<CloudInstance> cloudInstances = cloudStackConverter.buildInstances(context.getStack());
List<CloudResource> cloudResources = cloudResourceConverter.convert(context.getStack().getResources());
return new CollectMetadataRequest(context.getCloudContext(), context.getCloudCredential(), cloudResources, cloudInstances);
}
};
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudResource in project cloudbreak by hortonworks.
the class StackDownscaleActions method stackDownscaleCollectResourcesAction.
@Bean(name = "DOWNSCALE_COLLECT_RESOURCES_STATE")
public Action<?, ?> stackDownscaleCollectResourcesAction() {
return new AbstractStackDownscaleAction<StackDownscaleTriggerEvent>(StackDownscaleTriggerEvent.class) {
@Override
protected void doExecute(StackScalingFlowContext context, StackDownscaleTriggerEvent payload, Map<Object, Object> variables) {
stackDownscaleService.startStackDownscale(context, payload);
Stack stack = context.getStack();
LOGGER.debug("Assembling downscale stack event for stack: {}", stack);
List<CloudResource> resources = cloudResourceConverter.convert(stack.getResources());
variables.put(RESOURCES, resources);
List<CloudInstance> instances = new ArrayList<>();
InstanceGroup group = stack.getInstanceGroupByInstanceGroupName(context.getInstanceGroupName());
for (InstanceMetaData metaData : group.getAllInstanceMetaData()) {
if (context.getInstanceIds().contains(metaData.getInstanceId())) {
CloudInstance cloudInstance = metadataConverter.convert(metaData);
instances.add(cloudInstance);
}
}
variables.put(INSTANCES, instances);
Selectable request = new DownscaleStackCollectResourcesRequest(context.getCloudContext(), context.getCloudCredential(), context.getCloudStack(), resources, instances);
sendEvent(context.getFlowId(), request);
}
};
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudResource in project cloudbreak by hortonworks.
the class AbstractStackTerminationAction method createFlowContext.
@Override
protected StackTerminationContext createFlowContext(String flowId, StateContext<StackTerminationState, StackTerminationEvent> stateContext, P payload) {
Stack stack = stackService.getByIdWithLists(payload.getStackId());
MDCBuilder.buildMdcContext(stack);
Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.cloudPlatform(), stack.getOwner(), stack.getPlatformVariant(), location);
CloudCredential cloudCredential = credentialConverter.convert(stack.getCredential());
CloudStack cloudStack = cloudStackConverter.convert(stack);
List<CloudResource> resources = cloudResourceConverter.convert(stack.getResources());
return new StackTerminationContext(flowId, stack, cloudContext, cloudCredential, cloudStack, resources);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudResource in project cloudbreak by hortonworks.
the class AbstractInstanceTerminationAction method createFlowContext.
@Override
protected InstanceTerminationContext createFlowContext(String flowId, StateContext<InstanceTerminationState, InstanceTerminationEvent> stateContext, P payload) {
Stack stack = stackService.getByIdWithLists(payload.getStackId());
MDCBuilder.buildMdcContext(stack);
Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.cloudPlatform(), stack.getOwner(), stack.getPlatformVariant(), location);
CloudCredential cloudCredential = credentialConverter.convert(stack.getCredential());
Set<String> instanceIds = payload.getInstanceIds();
CloudStack cloudStack = cloudStackConverter.convert(stack, instanceIds);
List<CloudResource> cloudResources = cloudResourceConverter.convert(stack.getResources());
List<InstanceMetaData> instanceMetaDataList = new ArrayList<>();
List<CloudInstance> cloudInstances = new ArrayList<>();
for (String instanceId : instanceIds) {
InstanceMetaData instanceMetaData = instanceMetaDataRepository.findByInstanceId(stack.getId(), instanceId);
CloudInstance cloudInstance = metadataConverter.convert(instanceMetaData);
instanceMetaDataList.add(instanceMetaData);
cloudInstances.add(cloudInstance);
}
return new InstanceTerminationContext(flowId, stack, cloudContext, cloudCredential, cloudStack, cloudResources, cloudInstances, instanceMetaDataList);
}
Aggregations