Search in sources :

Example 6 with FlowEvent

use of com.sequenceiq.flow.core.FlowEvent in project cloudbreak by hortonworks.

the class StackImageUpdateActionsTest method checkPackageVersionsNotOk.

@Test
public void checkPackageVersionsNotOk() {
    FlowEvent flowEvent = Mockito.mock(FlowEvent.class);
    when(stateContext.getEvent()).thenReturn(flowEvent);
    when(flowEvent.name()).thenReturn(EVENT_NAME);
    ImageUpdateEvent payload = new ImageUpdateEvent(StackImageUpdateEvent.CHECK_IMAGE_VERESIONS_FINISHED_EVENT.event(), 1L, statedImage);
    when(stateContext.getMessageHeader(HEADERS.DATA.name())).thenReturn(payload);
    when(state.getId()).thenReturn(StackImageUpdateState.CHECK_PACKAGE_VERSIONS_STATE);
    when(stackImageUpdateService.checkPackageVersions(any(Stack.class), any(StatedImage.class))).thenReturn(CheckResult.failed(""));
    checkPackageVersionsAction.setFailureEvent(StackImageUpdateEvent.STACK_IMAGE_UPDATE_FAILED_EVENT);
    checkPackageVersionsAction.execute(stateContext);
    verify(stackImageUpdateService, times(1)).checkPackageVersions(any(Stack.class), any(StatedImage.class));
    verify(eventBus, times(1)).notify(eq(StackImageUpdateEvent.CHECK_PACKAGE_VERSIONS_FINISHED_EVENT.event()), any(Event.class));
    verify(eventBus, times(0)).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) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) ImageUpdateEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.ImageUpdateEvent) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.Test)

Example 7 with FlowEvent

use of com.sequenceiq.flow.core.FlowEvent 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 8 with FlowEvent

use of com.sequenceiq.flow.core.FlowEvent in project cloudbreak by hortonworks.

the class StackImageUpdateActionsTest method prepareImageAction.

@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), eq(variables));
    verify(eventBus, times(1)).notify(eq(CloudPlatformRequest.selector(PrepareImageRequest.class)), any(Event.class));
}
Also used : FlowEvent(com.sequenceiq.flow.core.FlowEvent) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) 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) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.Test)

Example 9 with FlowEvent

use of com.sequenceiq.flow.core.FlowEvent in project cloudbreak by hortonworks.

the class StackImageUpdateActionsTest method finishAction.

@Test
public void finishAction() {
    FlowEvent flowEvent = Mockito.mock(FlowEvent.class);
    when(stateContext.getEvent()).thenReturn(flowEvent);
    when(flowEvent.name()).thenReturn(EVENT_NAME);
    CloudPlatformResult payload = new CloudPlatformResult(1L);
    when(stateContext.getMessageHeader(HEADERS.DATA.name())).thenReturn(payload);
    when(state.getId()).thenReturn(StackImageUpdateState.STACK_IMAGE_UPDATE_FINISHED);
    finishAction.execute(stateContext);
    verify(flowMessageService, times(1)).fireEventAndLog(anyLong(), eq(Status.AVAILABLE.name()), eq(ResourceEvent.STACK_IMAGE_UPDATE_FINISHED));
}
Also used : FlowEvent(com.sequenceiq.flow.core.FlowEvent) CloudPlatformResult(com.sequenceiq.cloudbreak.cloud.event.CloudPlatformResult) Test(org.junit.Test)

Example 10 with FlowEvent

use of com.sequenceiq.flow.core.FlowEvent in project cloudbreak by hortonworks.

the class FlowSelectors method assertUniquenessInFlowEventNames.

public void assertUniquenessInFlowEventNames(String packagePrefix) {
    Reflections reflections = new Reflections(packagePrefix, new SubTypesScanner());
    Set<Class<? extends FlowEvent>> eventClasses = reflections.getSubTypesOf(FlowEvent.class);
    assertThat(eventClasses).withFailMessage("No FlowEvent subtypes found in package %s. Please check your 'packagePrefix' parameter.", packagePrefix).isNotEmpty();
    Map<String, List<String>> names = new HashMap<>();
    eventClasses.forEach(enumClass -> Arrays.stream(enumClass.getEnumConstants()).forEach(item -> names.compute(item.event(), (eventName, enumList) -> enumList == null ? new ArrayList<>(Arrays.asList(enumClass.getSimpleName())) : addToListAndReturn(enumList, enumClass.getSimpleName()))));
    Map<String, List<String>> duplicates = names.entrySet().stream().filter(e -> e.getValue().size() > 1).collect(Collectors.toMap(Entry::getKey, Entry::getValue, this::mergeLists, TreeMap::new));
    assertThat(duplicates).withFailMessage(() -> printDuplicates(duplicates)).isEmpty();
}
Also used : Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) FlowEvent(com.sequenceiq.flow.core.FlowEvent) Set(java.util.Set) HashMap(java.util.HashMap) Reflections(org.reflections.Reflections) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) SubTypesScanner(org.reflections.scanners.SubTypesScanner) List(java.util.List) TreeMap(java.util.TreeMap) Map(java.util.Map) Entry(java.util.Map.Entry) FlowEvent(com.sequenceiq.flow.core.FlowEvent) HashMap(java.util.HashMap) SubTypesScanner(org.reflections.scanners.SubTypesScanner) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Reflections(org.reflections.Reflections)

Aggregations

FlowEvent (com.sequenceiq.flow.core.FlowEvent)11 Test (org.junit.Test)9 StackImageUpdateTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.StackImageUpdateTriggerEvent)8 ResourceEvent (com.sequenceiq.cloudbreak.event.ResourceEvent)8 StackEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackEvent)8 StackFailureEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent)8 ImageUpdateEvent (com.sequenceiq.cloudbreak.reactor.api.event.stack.ImageUpdateEvent)8 Event (reactor.bus.Event)8 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)7 StatedImage (com.sequenceiq.cloudbreak.service.image.StatedImage)3 HashMap (java.util.HashMap)2 CloudPlatformResult (com.sequenceiq.cloudbreak.cloud.event.CloudPlatformResult)1 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)1 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)1 Resource (com.sequenceiq.cloudbreak.domain.Resource)1 StackView (com.sequenceiq.cloudbreak.domain.view.StackView)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1