Search in sources :

Example 1 with PrepareImageRequest

use of com.sequenceiq.cloudbreak.cloud.event.setup.PrepareImageRequest in project cloudbreak by hortonworks.

the class StackCreationActions method prepareImageAction.

@Bean(name = "IMAGESETUP_STATE")
public Action<?, ?> prepareImageAction() {
    return new AbstractStackCreationAction<SetupResult>(SetupResult.class) {

        @Override
        protected void doExecute(StackContext context, SetupResult payload, Map<Object, Object> variables) {
            stackCreationService.prepareImage(context.getStack());
            sendEvent(context);
        }

        @Override
        protected Selectable createRequest(StackContext context) {
            try {
                CloudStack cloudStack = cloudStackConverter.convert(context.getStack());
                Image image = imageService.getImage(context.getCloudContext().getId());
                return new PrepareImageRequest<>(context.getCloudContext(), context.getCloudCredential(), cloudStack, image);
            } catch (CloudbreakImageNotFoundException e) {
                throw new CloudbreakServiceException(e);
            }
        }
    };
}
Also used : SetupResult(com.sequenceiq.cloudbreak.cloud.event.setup.SetupResult) StackContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackContext) CloudbreakServiceException(com.sequenceiq.cloudbreak.service.CloudbreakServiceException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Image(com.sequenceiq.cloudbreak.cloud.model.Image) Map(java.util.Map) PrepareImageRequest(com.sequenceiq.cloudbreak.cloud.event.setup.PrepareImageRequest) Bean(org.springframework.context.annotation.Bean)

Example 2 with PrepareImageRequest

use of com.sequenceiq.cloudbreak.cloud.event.setup.PrepareImageRequest in project cloudbreak by hortonworks.

the class PrepareImageHandler method accept.

@Override
public void accept(Event<PrepareImageRequest> event) {
    LOGGER.info("Received event: {}", event);
    PrepareImageRequest request = event.getData();
    CloudContext cloudContext = request.getCloudContext();
    try {
        CloudConnector connector = cloudPlatformConnectors.get(request.getCloudContext().getPlatformVariant());
        AuthenticatedContext auth = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
        Image image = request.getImage();
        CloudStack stack = request.getStack();
        connector.setup().prepareImage(auth, stack, image);
        PrepareImageResult result = new PrepareImageResult(request);
        request.getResult().onNext(result);
        eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
        LOGGER.info("Prepare image finished for {}", cloudContext);
    } catch (RuntimeException e) {
        PrepareImageResult failure = new PrepareImageResult(e, request);
        request.getResult().onNext(failure);
        eventBus.notify(failure.selector(), new Event<>(event.getHeaders(), failure));
    }
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Event(reactor.bus.Event) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) PrepareImageResult(com.sequenceiq.cloudbreak.cloud.event.setup.PrepareImageResult) Image(com.sequenceiq.cloudbreak.cloud.model.Image) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) PrepareImageRequest(com.sequenceiq.cloudbreak.cloud.event.setup.PrepareImageRequest)

Aggregations

PrepareImageRequest (com.sequenceiq.cloudbreak.cloud.event.setup.PrepareImageRequest)2 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)2 Image (com.sequenceiq.cloudbreak.cloud.model.Image)2 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)1 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)1 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 PrepareImageResult (com.sequenceiq.cloudbreak.cloud.event.setup.PrepareImageResult)1 SetupResult (com.sequenceiq.cloudbreak.cloud.event.setup.SetupResult)1 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)1 StackContext (com.sequenceiq.cloudbreak.core.flow2.stack.StackContext)1 CloudbreakServiceException (com.sequenceiq.cloudbreak.service.CloudbreakServiceException)1 Map (java.util.Map)1 Bean (org.springframework.context.annotation.Bean)1 Event (reactor.bus.Event)1