@Test public void checkImageVersion() { FlowEvent flowEvent = Mockito.mock(FlowEvent.class); when(stateContext.getEvent()).thenReturn(flowEvent); when(flowEvent.name()).thenReturn(EVENT_NAME); StackImageUpdateTriggerEvent payload = new StackImageUpdateTriggerEvent(StackImageUpdateEvent.STACK_IMAGE_UPDATE_EVENT.event(), 1L, "imageId"); when(stateContext.getMessageHeader(HEADERS.DATA.name())).thenReturn(payload); when(state.getId()).thenReturn(StackImageUpdateState.CHECK_IMAGE_VERSIONS_STATE); when(stackImageUpdateService.isCbVersionOk(any(Stack.class))).thenReturn(true); checkImageAction.execute(stateContext); verify(flowMessageService, times(1)).fireEventAndLog(anyLong(), eq(Status.UPDATE_IN_PROGRESS.name()), eq(ResourceEvent.STACK_IMAGE_UPDATE_STARTED)); verify(stackImageUpdateService, times(1)).getNewImageIfVersionsMatch(any(Stack.class), anyString(), eq(null), eq(null)); verify(eventBus, times(1)).notify(eq(StackImageUpdateEvent.CHECK_IMAGE_VERESIONS_FINISHED_EVENT.event()), any(Event.class)); }
@Bean(name = "CHECK_IMAGE_VERSIONS_STATE") public AbstractStackImageUpdateAction<?> checkImageVersion() { return new AbstractStackImageUpdateAction<>(StackImageUpdateTriggerEvent.class) { @Override protected void doExecute(StackContext context, StackImageUpdateTriggerEvent payload, Map<Object, Object> variables) { getFlowMessageService().fireEventAndLog(context.getStack().getId(), Status.UPDATE_IN_PROGRESS.name(), STACK_IMAGE_UPDATE_STARTED); if (!getStackImageUpdateService().isCbVersionOk(context.getStack())) { throw new OperationException("Stack must be created at least with Cloudbreak version [" + StackImageUpdateService.MIN_VERSION + ']'); } StatedImage newImage = getStackImageUpdateService().getNewImageIfVersionsMatch(context.getStack(), payload.getNewImageId(), payload.getImageCatalogName(), payload.getImageCatalogUrl()); sendEvent(context, new ImageUpdateEvent(StackImageUpdateEvent.CHECK_IMAGE_VERESIONS_FINISHED_EVENT.event(), context.getStack().getId(), newImage)); } }; }
StackImageUpdateActions { @Bean(name = "CHECK_IMAGE_VERSIONS_STATE") public AbstractStackImageUpdateAction<?> checkImageVersion() { return new AbstractStackImageUpdateAction<>(StackImageUpdateTriggerEvent.class) { @Override protected void doExecute(StackContext context, StackImageUpdateTriggerEvent payload, Map<Object, Object> variables) { getFlowMessageService().fireEventAndLog(context.getStack().getId(), Status.UPDATE_IN_PROGRESS.name(), STACK_IMAGE_UPDATE_STARTED); if (!getStackImageUpdateService().isCbVersionOk(context.getStack())) { throw new OperationException("Stack must be created at least with Cloudbreak version [" + StackImageUpdateService.MIN_VERSION + ']'); } StatedImage newImage = getStackImageUpdateService().getNewImageIfVersionsMatch(context.getStack(), payload.getNewImageId(), payload.getImageCatalogName(), payload.getImageCatalogUrl()); sendEvent(context, new ImageUpdateEvent(StackImageUpdateEvent.CHECK_IMAGE_VERESIONS_FINISHED_EVENT.event(), context.getStack().getId(), newImage)); } }; } }
StackImageUpdateActions { @Bean(name = "CHECK_IMAGE_VERSIONS_STATE") public AbstractStackImageUpdateAction<?> checkImageVersion() { return new AbstractStackImageUpdateAction<>(StackImageUpdateTriggerEvent.class) { @Override protected void doExecute(StackContext context, StackImageUpdateTriggerEvent payload, Map<Object, Object> variables) { getFlowMessageService().fireEventAndLog(context.getStack().getId(), Status.UPDATE_IN_PROGRESS.name(), STACK_IMAGE_UPDATE_STARTED); if (!getStackImageUpdateService().isCbVersionOk(context.getStack())) { throw new OperationException("Stack must be created at least with Cloudbreak version [" + StackImageUpdateService.MIN_VERSION + ']'); } StatedImage newImage = getStackImageUpdateService().getNewImageIfVersionsMatch(context.getStack(), payload.getNewImageId(), payload.getImageCatalogName(), payload.getImageCatalogUrl()); sendEvent(context, new ImageUpdateEvent(StackImageUpdateEvent.CHECK_IMAGE_VERESIONS_FINISHED_EVENT.event(), context.getStack().getId(), newImage)); } }; }  }
StackImageUpdateActions { @Bean(name = "CHECK_IMAGE_VERSIONS_STATE") public AbstractStackImageUpdateAction<?> checkImageVersion() { return new AbstractStackImageUpdateAction<>(StackImageUpdateTriggerEvent.class) { @Override protected void doExecute(StackContext context, StackImageUpdateTriggerEvent payload, Map<Object, Object> variables) { getFlowMessageService().fireEventAndLog(context.getStack().getId(), Status.UPDATE_IN_PROGRESS.name(), STACK_IMAGE_UPDATE_STARTED); if (!getStackImageUpdateService().isCbVersionOk(context.getStack())) { throw new OperationException("Stack must be created at least with Cloudbreak version [" + StackImageUpdateService.MIN_VERSION + ']'); } StatedImage newImage = getStackImageUpdateService().getNewImageIfVersionsMatch(context.getStack(), payload.getNewImageId(), payload.getImageCatalogName(), payload.getImageCatalogUrl()); sendEvent(context, new ImageUpdateEvent(StackImageUpdateEvent.CHECK_IMAGE_VERESIONS_FINISHED_EVENT.event(), context.getStack().getId(), newImage)); } }; }  @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 = "CHECK_IMAGE_VERSIONS_STATE") public AbstractStackImageUpdateAction<?> checkImageVersion() { return new AbstractStackImageUpdateAction<>(StackImageUpdateTriggerEvent.class) { @Override protected void doExecute(StackContext context, StackImageUpdateTriggerEvent payload, Map<Object, Object> variables) { getFlowMessageService().fireEventAndLog(context.getStack().getId(), Status.UPDATE_IN_PROGRESS.name(), STACK_IMAGE_UPDATE_STARTED); if (!getStackImageUpdateService().isCbVersionOk(context.getStack())) { throw new OperationException("Stack must be created at least with Cloudbreak version [" + StackImageUpdateService.MIN_VERSION + ']'); } StatedImage newImage = getStackImageUpdateService().getNewImageIfVersionsMatch(context.getStack(), payload.getNewImageId(), payload.getImageCatalogName(), payload.getImageCatalogUrl()); sendEvent(context, new ImageUpdateEvent(StackImageUpdateEvent.CHECK_IMAGE_VERESIONS_FINISHED_EVENT.event(), context.getStack().getId(), newImage)); } }; }  @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();  }