use of com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackCollectResourcesRequest in project cloudbreak by hortonworks.
the class DownscaleStackCollectResourcesHandler method accept.
@Override
public void accept(Event<DownscaleStackCollectResourcesRequest> collectResourcesRequestEvent) {
LOGGER.info("Received event: {}", collectResourcesRequestEvent);
DownscaleStackCollectResourcesRequest request = collectResourcesRequestEvent.getData();
DownscaleStackCollectResourcesResult result;
try {
CloudContext cloudContext = request.getCloudContext();
CloudConnector connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
Object resourcesToScale = connector.resources().collectResourcesToRemove(ac, request.getCloudStack(), request.getCloudResources(), request.getInstances());
LOGGER.info("Collect resources successfully finished for {}", cloudContext);
result = new DownscaleStackCollectResourcesResult(request, resourcesToScale);
} catch (RuntimeException e) {
LOGGER.error("Failed to handle DownscaleStackCollectResourcesRequest.", e);
result = new DownscaleStackCollectResourcesResult(e.getMessage(), e, request);
}
request.getResult().onNext(result);
LOGGER.info("DownscaleStackCollectResourcesRequest finished");
eventBus.notify(result.selector(), new Event<>(collectResourcesRequestEvent.getHeaders(), result));
}
use of com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackCollectResourcesRequest 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);
}
};
}
Aggregations