Search in sources :

Example 1 with StackImageUpdateTriggerEvent

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);
}
Also used : StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) FlowTriggerEventQueue(com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) StackSyncTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackSyncTriggerEvent) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) StackImageUpdateTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackImageUpdateTriggerEvent)

Example 2 with StackImageUpdateTriggerEvent

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));
        }
    };
}
Also used : StackContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackContext) StackImageUpdateTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackImageUpdateTriggerEvent) Map(java.util.Map) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) OperationException(com.sequenceiq.cloudbreak.service.OperationException) ImageUpdateEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.ImageUpdateEvent) Bean(org.springframework.context.annotation.Bean)

Example 3 with StackImageUpdateTriggerEvent

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));
}
Also used : FlowEvent(com.sequenceiq.flow.core.FlowEvent) FlowEvent(com.sequenceiq.flow.core.FlowEvent) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) Event(reactor.bus.Event) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) ImageUpdateEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.ImageUpdateEvent) StackImageUpdateTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackImageUpdateTriggerEvent) StackImageUpdateTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackImageUpdateTriggerEvent) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.Test)

Example 4 with StackImageUpdateTriggerEvent

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));
}
Also used : FlowEvent(com.sequenceiq.flow.core.FlowEvent) FlowEvent(com.sequenceiq.flow.core.FlowEvent) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) Event(reactor.bus.Event) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) ImageUpdateEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.ImageUpdateEvent) StackImageUpdateTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackImageUpdateTriggerEvent) StackImageUpdateTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackImageUpdateTriggerEvent) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.Test)

Example 5 with StackImageUpdateTriggerEvent

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());
}
Also used : ImageChangeDto(com.sequenceiq.cloudbreak.service.image.ImageChangeDto) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StackImageUpdateTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackImageUpdateTriggerEvent) Test(org.junit.Test)

Aggregations

StackImageUpdateTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.StackImageUpdateTriggerEvent)7 StackEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackEvent)4 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)3 ImageUpdateEvent (com.sequenceiq.cloudbreak.reactor.api.event.stack.ImageUpdateEvent)3 Test (org.junit.Test)3 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)2 ResourceEvent (com.sequenceiq.cloudbreak.event.ResourceEvent)2 StackFailureEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent)2 FlowEvent (com.sequenceiq.flow.core.FlowEvent)2 FlowTriggerEventQueue (com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue)2 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)2 Event (reactor.bus.Event)2 Acceptable (com.sequenceiq.cloudbreak.common.event.Acceptable)1 ClusterUpgradeTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.ClusterUpgradeTriggerEvent)1 StackSyncTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.StackSyncTriggerEvent)1 StackContext (com.sequenceiq.cloudbreak.core.flow2.stack.StackContext)1 ClusterRepairTriggerEvent (com.sequenceiq.cloudbreak.reactor.api.event.orchestration.ClusterRepairTriggerEvent)1 OperationException (com.sequenceiq.cloudbreak.service.OperationException)1 ImageChangeDto (com.sequenceiq.cloudbreak.service.image.ImageChangeDto)1 StatedImage (com.sequenceiq.cloudbreak.service.image.StatedImage)1