@Test public void prepareImageAction() { FlowEvent flowEvent = Mockito.mock(FlowEvent.class); when(stateContext.getEvent()).thenReturn(flowEvent); when(flowEvent.name()).thenReturn(EVENT_NAME); StackEvent payload = new StackEvent(StackImageUpdateEvent.UPDATE_IMAGE_FINESHED_EVENT.event(), 1L); when(stateContext.getMessageHeader(HEADERS.DATA.name())).thenReturn(payload); when(state.getId()).thenReturn(StackImageUpdateState.IMAGE_PREPARE_STATE); prepareImageAction.execute(stateContext); verify(stackCreationService, times(1)).prepareImage(any(Stack.class)); verify(eventBus, times(1)).notify(eq(CloudPlatformRequest.selector(PrepareImageRequest.class)), any(Event.class)); }
@Bean(name = "IMAGE_PREPARE_STATE") public AbstractStackImageUpdateAction<?> prepareImageAction() { return new AbstractStackImageUpdateAction<>(StackEvent.class) { @Override protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) { getStackCreationService().prepareImage(context.getStack()); try { CloudStack cloudStack = getCloudStackConverter().convert(context.getStack()); Image image = getImageService().getImage(context.getCloudContext().getId()); PrepareImageRequest<Selectable> request = new PrepareImageRequest<>(context.getCloudContext(), context.getCloudCredential(), cloudStack, image); sendEvent(context, request); } catch (CloudbreakImageNotFoundException e) { throw new CloudbreakServiceException(e); } } }; }
StackImageUpdateActions { @Bean(name = "IMAGE_PREPARE_STATE") public AbstractStackImageUpdateAction<?> prepareImageAction() { return new AbstractStackImageUpdateAction<>(StackEvent.class) { @Override protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) { getStackCreationService().prepareImage(context.getStack()); try { CloudStack cloudStack = getCloudStackConverter().convert(context.getStack()); Image image = getImageService().getImage(context.getCloudContext().getId()); PrepareImageRequest<Selectable> request = new PrepareImageRequest<>(context.getCloudContext(), context.getCloudCredential(), cloudStack, image); sendEvent(context, request); } catch (CloudbreakImageNotFoundException e) { throw new CloudbreakServiceException(e); } } }; } }
StackImageUpdateActions { @Bean(name = "IMAGE_PREPARE_STATE") public AbstractStackImageUpdateAction<?> prepareImageAction() { return new AbstractStackImageUpdateAction<>(StackEvent.class) { @Override protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) { getStackCreationService().prepareImage(context.getStack()); try { CloudStack cloudStack = getCloudStackConverter().convert(context.getStack()); Image image = getImageService().getImage(context.getCloudContext().getId()); PrepareImageRequest<Selectable> request = new PrepareImageRequest<>(context.getCloudContext(), context.getCloudCredential(), cloudStack, image); sendEvent(context, request); } catch (CloudbreakImageNotFoundException e) { throw new CloudbreakServiceException(e); } } }; }  }
StackImageUpdateActions { @Bean(name = "IMAGE_PREPARE_STATE") public AbstractStackImageUpdateAction<?> prepareImageAction() { return new AbstractStackImageUpdateAction<>(StackEvent.class) { @Override protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) { getStackCreationService().prepareImage(context.getStack()); try { CloudStack cloudStack = getCloudStackConverter().convert(context.getStack()); Image image = getImageService().getImage(context.getCloudContext().getId()); PrepareImageRequest<Selectable> request = new PrepareImageRequest<>(context.getCloudContext(), context.getCloudCredential(), cloudStack, image); sendEvent(context, request); } catch (CloudbreakImageNotFoundException e) { throw new CloudbreakServiceException(e); } } }; }  @Bean(name = "CHECK_IMAGE_VERSIONS_STATE") AbstractStackImageUpdateAction<?> checkImageVersion(); @Bean(name = "CHECK_PACKAGE_VERSIONS_STATE") AbstractStackImageUpdateAction<?> checkPackageVersions(); @Bean(name = "UPDATE_IMAGE_STATE") AbstractStackImageUpdateAction<?> updateImage(); @Bean(name = "IMAGE_PREPARE_STATE") AbstractStackImageUpdateAction<?> prepareImageAction(); @Bean(name = "SET_IMAGE_STATE") AbstractStackImageUpdateAction<?> setImageAction(); @Bean(name = "STACK_IMAGE_UPDATE_FINISHED") AbstractStackImageUpdateAction<?> finishAction(); @Bean(name = "STACK_IMAGE_UPDATE_FAILED_STATE") AbstractStackFailureAction<StackImageUpdateState, StackImageUpdateEvent> handleImageUpdateFailure(); }
StackImageUpdateActions { @Bean(name = "IMAGE_PREPARE_STATE") public AbstractStackImageUpdateAction<?> prepareImageAction() { return new AbstractStackImageUpdateAction<>(StackEvent.class) { @Override protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) { getStackCreationService().prepareImage(context.getStack()); try { CloudStack cloudStack = getCloudStackConverter().convert(context.getStack()); Image image = getImageService().getImage(context.getCloudContext().getId()); PrepareImageRequest<Selectable> request = new PrepareImageRequest<>(context.getCloudContext(), context.getCloudCredential(), cloudStack, image); sendEvent(context, request); } catch (CloudbreakImageNotFoundException e) { throw new CloudbreakServiceException(e); } } }; }  @Bean(name = "CHECK_IMAGE_VERSIONS_STATE") AbstractStackImageUpdateAction<?> checkImageVersion(); @Bean(name = "CHECK_PACKAGE_VERSIONS_STATE") AbstractStackImageUpdateAction<?> checkPackageVersions(); @Bean(name = "UPDATE_IMAGE_STATE") AbstractStackImageUpdateAction<?> updateImage(); @Bean(name = "IMAGE_PREPARE_STATE") AbstractStackImageUpdateAction<?> prepareImageAction(); @Bean(name = "SET_IMAGE_STATE") AbstractStackImageUpdateAction<?> setImageAction(); @Bean(name = "STACK_IMAGE_UPDATE_FINISHED") AbstractStackImageUpdateAction<?> finishAction(); @Bean(name = "STACK_IMAGE_UPDATE_FAILED_STATE") AbstractStackFailureAction<StackImageUpdateState, StackImageUpdateEvent> handleImageUpdateFailure();  }