Search in sources :

Example 1 with UpscaleStackRequest

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

the class StackUpscaleActions method addInstances.

@Bean(name = "ADD_INSTANCES_STATE")
public Action<?, ?> addInstances() {
    return new AbstractStackUpscaleAction<StackScaleTriggerEvent>(StackScaleTriggerEvent.class) {

        @Override
        protected void prepareExecution(StackScaleTriggerEvent payload, Map<Object, Object> variables) {
            variables.put(INSTANCEGROUPNAME, payload.getInstanceGroup());
            variables.put(ADJUSTMENT, payload.getAdjustment());
            variables.put(HOSTNAMES, payload.getHostNames());
        }

        @Override
        protected void doExecute(StackScalingFlowContext context, StackScaleTriggerEvent payload, Map<Object, Object> variables) {
            stackUpscaleService.startAddInstances(context.getStack(), payload.getAdjustment());
            sendEvent(context);
        }

        @Override
        protected Selectable createRequest(StackScalingFlowContext context) {
            LOGGER.debug("Assembling upscale stack event for stack: {}", context.getStack());
            InstanceGroup group = context.getStack().getInstanceGroupByInstanceGroupName(context.getInstanceGroupName());
            group.setNodeCount(group.getNodeCount() + context.getAdjustment());
            CloudStack cloudStack = cloudStackConverter.convert(context.getStack());
            instanceMetadataService.saveInstanceRequests(context.getStack(), cloudStack.getGroups());
            List<CloudResource> resources = cloudResourceConverter.convert(context.getStack().getResources());
            return new UpscaleStackRequest<UpscaleStackResult>(context.getCloudContext(), context.getCloudCredential(), cloudStack, resources);
        }
    };
}
Also used : StackScaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackScaleTriggerEvent) UpscaleStackRequest(com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Map(java.util.Map) StackScalingFlowContext(com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Bean(org.springframework.context.annotation.Bean)

Example 2 with UpscaleStackRequest

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

the class UpscaleStackHandler method accept.

@Override
public void accept(Event<UpscaleStackRequest> upscaleStackRequestEvent) {
    LOGGER.info("Received event: {}", upscaleStackRequestEvent);
    UpscaleStackRequest request = upscaleStackRequestEvent.getData();
    CloudContext cloudContext = request.getCloudContext();
    try {
        CloudConnector connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
        AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
        List<CloudResourceStatus> resourceStatus = connector.resources().upscale(ac, request.getCloudStack(), request.getResourceList());
        List<CloudResource> resources = ResourceLists.transform(resourceStatus);
        PollTask<ResourcesStatePollerResult> task = statusCheckFactory.newPollResourcesStateTask(ac, resources, true);
        ResourcesStatePollerResult statePollerResult = ResourcesStatePollerResults.build(cloudContext, resourceStatus);
        if (!task.completed(statePollerResult)) {
            statePollerResult = syncPollingScheduler.schedule(task);
        }
        UpscaleStackResult result = ResourcesStatePollerResults.transformToUpscaleStackResult(statePollerResult, request);
        request.getResult().onNext(result);
        eventBus.notify(result.selector(), new Event<>(upscaleStackRequestEvent.getHeaders(), result));
        LOGGER.info("Upscale successfully finished for {}", cloudContext);
    } catch (Exception e) {
        UpscaleStackResult result = new UpscaleStackResult(e.getMessage(), e, request);
        request.getResult().onNext(result);
        eventBus.notify(CloudPlatformResult.failureSelector(UpscaleStackResult.class), new Event<>(upscaleStackRequestEvent.getHeaders(), result));
    }
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) UpscaleStackResult(com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackResult) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) Event(reactor.bus.Event) UpscaleStackRequest(com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ResourcesStatePollerResult(com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult)

Aggregations

UpscaleStackRequest (com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackRequest)2 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)2 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)1 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)1 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 UpscaleStackResult (com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackResult)1 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)1 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)1 ResourcesStatePollerResult (com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult)1 StackScaleTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.StackScaleTriggerEvent)1 StackScalingFlowContext (com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext)1 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)1 Map (java.util.Map)1 Bean (org.springframework.context.annotation.Bean)1 Event (reactor.bus.Event)1