use of com.sequenceiq.cloudbreak.cloud.model.Location in project cloudbreak by hortonworks.
the class ServiceProviderConnectorAdapter method deleteStack.
public void deleteStack(Stack stack, Credential credential) {
LOGGER.debug("Assembling terminate stack event for stack: {}", 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());
List<CloudResource> resources = cloudResourceConverter.convert(stack.getResources());
CloudStack cloudStack = cloudStackConverter.convert(stack);
TerminateStackRequest<TerminateStackResult> terminateRequest = new TerminateStackRequest<>(cloudContext, cloudStack, cloudCredential, resources);
LOGGER.info("Triggering terminate stack event: {}", terminateRequest);
eventBus.notify(terminateRequest.selector(), eventFactory.createEvent(terminateRequest));
try {
TerminateStackResult res = terminateRequest.await();
LOGGER.info("Terminate stack result: {}", res);
if (res.getStatus().equals(EventStatus.FAILED)) {
if (res.getErrorDetails() != null) {
LOGGER.error("Failed to terminate the stack", res.getErrorDetails());
throw new OperationException(res.getErrorDetails());
}
throw new OperationException(format("Failed to terminate the stack: %s due to %s", cloudContext, res.getStatusReason()));
}
} catch (InterruptedException e) {
LOGGER.error("Error while terminating the stack", e);
throw new OperationException(e);
}
}
use of com.sequenceiq.cloudbreak.cloud.model.Location in project cloudbreak by hortonworks.
the class ServiceProviderConnectorAdapter method getTemplate.
public String getTemplate(Stack 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());
GetPlatformTemplateRequest getPlatformTemplateRequest = new GetPlatformTemplateRequest(cloudContext, cloudCredential);
eventBus.notify(getPlatformTemplateRequest.selector(), eventFactory.createEvent(getPlatformTemplateRequest));
try {
GetPlatformTemplateResult res = getPlatformTemplateRequest.await();
LOGGER.info("Get template result: {}", res);
if (res.getStatus().equals(EventStatus.FAILED)) {
LOGGER.error("Failed to get template", res.getErrorDetails());
throw new OperationException(res.getErrorDetails());
}
return res.getTemplate();
} catch (InterruptedException e) {
LOGGER.error("Error while getting template: " + cloudContext, e);
throw new OperationException(e);
}
}
use of com.sequenceiq.cloudbreak.cloud.model.Location in project cloudbreak by hortonworks.
the class ServiceProviderMetadataAdapter method collectMetadata.
public List<CloudVmMetaDataStatus> collectMetadata(Stack 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());
List<CloudInstance> cloudInstances = cloudStackConverter.buildInstances(stack);
List<CloudResource> cloudResources = cloudResourceConverter.convert(stack.getResources());
CollectMetadataRequest cmr = new CollectMetadataRequest(cloudContext, cloudCredential, cloudResources, cloudInstances);
LOGGER.info("Triggering event: {}", cmr);
eventBus.notify(CloudPlatformRequest.selector(CollectMetadataRequest.class), eventFactory.createEvent(cmr));
try {
CollectMetadataResult res = cmr.await();
LOGGER.info("Result: {}", res);
if (res.getErrorDetails() != null) {
LOGGER.error("Failed to collect metadata", res.getErrorDetails());
return Collections.emptyList();
}
return res.getResults();
} catch (InterruptedException e) {
LOGGER.error(format("Error while executing collectMetadata, stack: %s", cloudContext), e);
throw new OperationException(e);
}
}
use of com.sequenceiq.cloudbreak.cloud.model.Location in project cloudbreak by hortonworks.
the class AbstractStackDownscaleAction method createFlowContext.
@Override
protected StackScalingFlowContext createFlowContext(String flowId, StateContext<StackDownscaleState, StackDownscaleEvent> stateContext, P payload) {
Map<Object, Object> variables = stateContext.getExtendedState().getVariables();
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());
String instanceGroupName = extractInstanceGroupName(payload, variables);
Set<String> instanceIds = extractInstanceIds(payload, variables, stack);
Integer adjustment = extractAdjustment(payload, variables);
CloudStack cloudStack = cloudStackConverter.convertForDownscale(stack, instanceIds);
return new StackScalingFlowContext(flowId, stack, cloudContext, cloudCredential, cloudStack, instanceGroupName, instanceIds, adjustment);
}
use of com.sequenceiq.cloudbreak.cloud.model.Location 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);
}
Aggregations