Search in sources :

Example 1 with ImageUpdateEvent

use of com.sequenceiq.cloudbreak.reactor.api.event.stack.ImageUpdateEvent in project cloudbreak by hortonworks.

the class StackImageUpdateActions method updateImage.

@Bean(name = "UPDATE_IMAGE_STATE")
public AbstractStackImageUpdateAction<?> updateImage() {
    return new AbstractStackImageUpdateAction<>(ImageUpdateEvent.class) {

        @Override
        protected void doExecute(StackContext context, ImageUpdateEvent payload, Map<Object, Object> variables) {
            try {
                variables.put(ORIGINAL_IMAGE, getImageService().getImage(context.getStack().getId()));
            } catch (CloudbreakImageNotFoundException e) {
                LOGGER.debug("Image not found", e);
                throw new CloudbreakServiceException(e.getMessage(), e);
            }
            getStackImageService().storeNewImageComponent(context.getStack(), payload.getImage());
            sendEvent(context, new StackEvent(StackImageUpdateEvent.UPDATE_IMAGE_FINESHED_EVENT.event(), context.getStack().getId()));
        }
    };
}
Also used : StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) StackContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackContext) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Map(java.util.Map) ImageUpdateEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.ImageUpdateEvent) Bean(org.springframework.context.annotation.Bean)

Example 2 with ImageUpdateEvent

use of com.sequenceiq.cloudbreak.reactor.api.event.stack.ImageUpdateEvent 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 ImageUpdateEvent

use of com.sequenceiq.cloudbreak.reactor.api.event.stack.ImageUpdateEvent in project cloudbreak by hortonworks.

the class StackImageUpdateActionsTest method checkPackageVersions.

@Test
public void checkPackageVersions() {
    FlowEvent flowEvent = Mockito.mock(FlowEvent.class);
    when(stateContext.getEvent()).thenReturn(flowEvent);
    when(flowEvent.name()).thenReturn(EVENT_NAME);
    ImageUpdateEvent payload = new ImageUpdateEvent(StackImageUpdateEvent.STACK_IMAGE_UPDATE_EVENT.event(), 1L, statedImage);
    when(stateContext.getMessageHeader(HEADERS.DATA.name())).thenReturn(payload);
    when(state.getId()).thenReturn(StackImageUpdateState.CHECK_IMAGE_VERSIONS_STATE);
    when(stackImageUpdateService.checkPackageVersions(any(Stack.class), any(StatedImage.class))).thenReturn(CheckResult.ok());
    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));
}
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 4 with ImageUpdateEvent

use of com.sequenceiq.cloudbreak.reactor.api.event.stack.ImageUpdateEvent in project cloudbreak by hortonworks.

the class StackImageUpdateActionsTest method updateImage.

@Test
public void updateImage() {
    FlowEvent flowEvent = Mockito.mock(FlowEvent.class);
    when(stateContext.getEvent()).thenReturn(flowEvent);
    when(flowEvent.name()).thenReturn(EVENT_NAME);
    ImageUpdateEvent payload = new ImageUpdateEvent(StackImageUpdateEvent.CHECK_PACKAGE_VERSIONS_FINISHED_EVENT.event(), 1L, statedImage);
    when(stateContext.getMessageHeader(HEADERS.DATA.name())).thenReturn(payload);
    when(state.getId()).thenReturn(StackImageUpdateState.UPDATE_IMAGE_STATE);
    updateImageAction.execute(stateContext);
    verify(stackImageService, times(1)).storeNewImageComponent(any(Stack.class), any(StatedImage.class));
    verify(eventBus, times(1)).notify(eq(StackImageUpdateEvent.UPDATE_IMAGE_FINESHED_EVENT.event()), any(Event.class));
    assertTrue(variables.containsKey(AbstractStackImageUpdateAction.ORIGINAL_IMAGE));
}
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 5 with ImageUpdateEvent

use of com.sequenceiq.cloudbreak.reactor.api.event.stack.ImageUpdateEvent in project cloudbreak by hortonworks.

the class StackImageUpdateActions method checkPackageVersions.

@Bean(name = "CHECK_PACKAGE_VERSIONS_STATE")
public AbstractStackImageUpdateAction<?> checkPackageVersions() {
    return new AbstractStackImageUpdateAction<>(ImageUpdateEvent.class) {

        @Override
        protected void doExecute(StackContext context, ImageUpdateEvent payload, Map<Object, Object> variables) {
            CheckResult checkResult = getStackImageUpdateService().checkPackageVersions(context.getStack(), payload.getImage());
            if (checkResult.getStatus() == EventStatus.FAILED) {
                LOGGER.info("Check package versions failed: {}", checkResult);
            }
            sendEvent(context, new ImageUpdateEvent(StackImageUpdateEvent.CHECK_PACKAGE_VERSIONS_FINISHED_EVENT.event(), context.getStack().getId(), payload.getImage()));
        }
    };
}
Also used : StackContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackContext) CheckResult(com.sequenceiq.cloudbreak.core.flow2.CheckResult) Map(java.util.Map) ImageUpdateEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.ImageUpdateEvent) Bean(org.springframework.context.annotation.Bean)

Aggregations

ImageUpdateEvent (com.sequenceiq.cloudbreak.reactor.api.event.stack.ImageUpdateEvent)6 StackImageUpdateTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.StackImageUpdateTriggerEvent)4 StackEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackEvent)4 StatedImage (com.sequenceiq.cloudbreak.service.image.StatedImage)4 StackContext (com.sequenceiq.cloudbreak.core.flow2.stack.StackContext)3 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)3 ResourceEvent (com.sequenceiq.cloudbreak.event.ResourceEvent)3 StackFailureEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent)3 FlowEvent (com.sequenceiq.flow.core.FlowEvent)3 Map (java.util.Map)3 Test (org.junit.Test)3 Bean (org.springframework.context.annotation.Bean)3 Event (reactor.bus.Event)3 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)1 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)1 CheckResult (com.sequenceiq.cloudbreak.core.flow2.CheckResult)1 OperationException (com.sequenceiq.cloudbreak.service.OperationException)1