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()));
}
};
}
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));
}
};
}
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));
}
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));
}
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()));
}
};
}
Aggregations