use of com.sequenceiq.cloudbreak.core.flow2.event.StackImageUpdateTriggerEvent in project cloudbreak by hortonworks.
the class StackImageUpdateFlowEventChainFactory method createFlowTriggerEventQueue.
@Override
public FlowTriggerEventQueue createFlowTriggerEventQueue(StackImageUpdateTriggerEvent event) {
Queue<Selectable> flowEventChain = new ConcurrentLinkedQueue<>();
flowEventChain.add(new StackSyncTriggerEvent(StackSyncEvent.STACK_SYNC_EVENT.event(), event.getResourceId(), true, event.accepted()));
flowEventChain.add(new StackEvent(CLUSTER_SYNC_EVENT.event(), event.getResourceId()));
flowEventChain.add(new StackImageUpdateTriggerEvent(StackImageUpdateEvent.STACK_IMAGE_UPDATE_EVENT.event(), event.getResourceId(), event.getNewImageId(), event.getImageCatalogName(), event.getImageCatalogUrl()));
return new FlowTriggerEventQueue(getName(), event, flowEventChain);
}
use of com.sequenceiq.cloudbreak.core.flow2.event.StackImageUpdateTriggerEvent in project cloudbreak by hortonworks.
the class StackImageUpdateActions method checkImageVersion.
@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));
}
};
}
use of com.sequenceiq.cloudbreak.core.flow2.event.StackImageUpdateTriggerEvent in project cloudbreak by hortonworks.
the class StackImageUpdateActionsTest method checkImageVersion.
@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));
}
use of com.sequenceiq.cloudbreak.core.flow2.event.StackImageUpdateTriggerEvent in project cloudbreak by hortonworks.
the class StackImageUpdateActionsTest method checkImageVersionNotOk.
@Test
public void checkImageVersionNotOk() {
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(false);
checkImageAction.setFailureEvent(StackImageUpdateEvent.STACK_IMAGE_UPDATE_FAILED_EVENT);
checkImageAction.execute(stateContext);
verify(flowMessageService, times(1)).fireEventAndLog(anyLong(), eq(Status.UPDATE_IN_PROGRESS.name()), eq(ResourceEvent.STACK_IMAGE_UPDATE_STARTED));
verify(stackImageUpdateService, times(0)).getNewImageIfVersionsMatch(any(Stack.class), anyString(), eq(null), eq(null));
verify(eventBus, times(0)).notify(eq(StackImageUpdateEvent.CHECK_IMAGE_VERESIONS_FINISHED_EVENT.event()), any(Event.class));
verify(eventBus, times(1)).notify(eq(StackImageUpdateEvent.STACK_IMAGE_UPDATE_FAILED_EVENT.event()), any(Event.class));
}
use of com.sequenceiq.cloudbreak.core.flow2.event.StackImageUpdateTriggerEvent in project cloudbreak by hortonworks.
the class ReactorFlowManagerTest method testTriggerStackImageUpdate.
@Test
public void testTriggerStackImageUpdate() {
long stackId = 1L;
String imageID = "imageID";
String imageCatalogName = "imageCatalogName";
String imageCatalogUrl = "imageCatalogUrl";
underTest.triggerStackImageUpdate(new ImageChangeDto(stackId, imageID, imageCatalogName, imageCatalogUrl));
ArgumentCaptor<Acceptable> captor = ArgumentCaptor.forClass(Acceptable.class);
verify(reactorNotifier).notify(eq(stackId), eq(FlowChainTriggers.STACK_IMAGE_UPDATE_TRIGGER_EVENT), captor.capture());
StackImageUpdateTriggerEvent event = (StackImageUpdateTriggerEvent) captor.getValue();
assertEquals(FlowChainTriggers.STACK_IMAGE_UPDATE_TRIGGER_EVENT, event.selector());
assertEquals(stack.getId(), event.getResourceId());
assertEquals(imageCatalogName, event.getImageCatalogName());
assertEquals(imageID, event.getNewImageId());
assertEquals(imageCatalogUrl, event.getImageCatalogUrl());
}
Aggregations