Search in sources :

Example 1 with DownscaleStackCollectResourcesResult

use of com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackCollectResourcesResult 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));
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) DownscaleStackCollectResourcesRequest(com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackCollectResourcesRequest) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) DownscaleStackCollectResourcesResult(com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackCollectResourcesResult) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)

Example 2 with DownscaleStackCollectResourcesResult

use of com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackCollectResourcesResult in project cloudbreak by hortonworks.

the class StackDownscaleActions method stackDownscaleAction.

@Bean(name = "DOWNSCALE_STATE")
public Action<?, ?> stackDownscaleAction() {
    return new AbstractStackDownscaleAction<DownscaleStackCollectResourcesResult>(DownscaleStackCollectResourcesResult.class) {

        @Override
        protected void doExecute(StackScalingFlowContext context, DownscaleStackCollectResourcesResult payload, Map<Object, Object> variables) {
            Selectable request = new DownscaleStackRequest(context.getCloudContext(), context.getCloudCredential(), context.getCloudStack(), (List<CloudResource>) variables.get(RESOURCES), (List<CloudInstance>) variables.get(INSTANCES), payload.getResourcesToScale());
            sendEvent(context.getFlowId(), request);
        }
    };
}
Also used : Selectable(com.sequenceiq.cloudbreak.cloud.event.Selectable) DownscaleStackCollectResourcesResult(com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackCollectResourcesResult) DownscaleStackRequest(com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackRequest) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Aggregations

DownscaleStackCollectResourcesResult (com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackCollectResourcesResult)2 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)1 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)1 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 Selectable (com.sequenceiq.cloudbreak.cloud.event.Selectable)1 DownscaleStackCollectResourcesRequest (com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackCollectResourcesRequest)1 DownscaleStackRequest (com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackRequest)1 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)1 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)1 Map (java.util.Map)1 Bean (org.springframework.context.annotation.Bean)1