Search in sources :

Example 1 with ImageService

use of com.sequenceiq.freeipa.service.image.ImageService in project cloudbreak by hortonworks.

the class ImageChangeActions method prepareImage.

@Bean(name = "PREPARE_IMAGE_STATE")
public AbstractImageChangeAction<?> prepareImage() {
    return new AbstractImageChangeAction<>(ImageChangeEvent.class) {

        @Inject
        private ImageConverter imageConverter;

        @Inject
        private ImageService imageService;

        @Override
        protected void doExecute(StackContext context, ImageChangeEvent payload, Map<Object, Object> variables) throws Exception {
            CloudStack cloudStack = getCloudStackConverter().convert(context.getStack());
            Image image = imageConverter.convert(imageService.getByStack(context.getStack()));
            PrepareImageRequest<Object> request = new PrepareImageRequest<>(context.getCloudContext(), context.getCloudCredential(), cloudStack, image);
            LOGGER.info("Prepare image: {}", image);
            sendEvent(context, request);
        }

        @Override
        protected Object getFailurePayload(ImageChangeEvent payload, Optional<StackContext> flowContext, Exception ex) {
            LOGGER.error("[PREPARE_IMAGE_STATE] failed", ex);
            return new StackFailureEvent(IMAGE_CHANGE_FAILED_EVENT.event(), payload.getResourceId(), ex);
        }
    };
}
Also used : Optional(java.util.Optional) StackFailureEvent(com.sequenceiq.freeipa.flow.stack.StackFailureEvent) ImageConverter(com.sequenceiq.freeipa.converter.image.ImageConverter) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Image(com.sequenceiq.cloudbreak.cloud.model.Image) ImageService(com.sequenceiq.freeipa.service.image.ImageService) ImageChangeEvent(com.sequenceiq.freeipa.flow.stack.image.change.event.ImageChangeEvent) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) Map(java.util.Map) PrepareImageRequest(com.sequenceiq.cloudbreak.cloud.event.setup.PrepareImageRequest) Bean(org.springframework.context.annotation.Bean)

Aggregations

PrepareImageRequest (com.sequenceiq.cloudbreak.cloud.event.setup.PrepareImageRequest)1 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)1 Image (com.sequenceiq.cloudbreak.cloud.model.Image)1 ImageConverter (com.sequenceiq.freeipa.converter.image.ImageConverter)1 StackContext (com.sequenceiq.freeipa.flow.stack.StackContext)1 StackFailureEvent (com.sequenceiq.freeipa.flow.stack.StackFailureEvent)1 ImageChangeEvent (com.sequenceiq.freeipa.flow.stack.image.change.event.ImageChangeEvent)1 ImageService (com.sequenceiq.freeipa.service.image.ImageService)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Bean (org.springframework.context.annotation.Bean)1