class StackImageUpdateActions {

    @Bean(name = "UPDATE_IMAGE_STATE")
    public AbstractStackImageUpdateAction<?> updateImage() {
        return new AbstractStackImageUpdateAction<>(ImageUpdateEvent.class) {
            @Override
            protected void doExecute(StackContext context, ImageUpdateEvent payload, Map<Object, Object> variables) {
                try {
                    variables.put(ORIGINAL_IMAGE, getImageService().getImage(context.getStack().getId()));
                } catch (CloudbreakImageNotFoundException e) {
                    LOGGER.debug("Image not found", e);
                    throw new CloudbreakServiceException(e.getMessage(), e);
                }
                getStackImageUpdateService().storeNewImageComponent(context.getStack(), payload.getImage());
                sendEvent(context, new StackEvent(StackImageUpdateEvent.UPDATE_IMAGE_FINESHED_EVENT.event(), context.getStack().getId()));
            }
        };
    }

}