use of com.sequenceiq.freeipa.flow.stack.image.change.event.ImageChangeEvent in project cloudbreak by hortonworks.
the class ImageChangeService method changeImage.
public FlowIdentifier changeImage(String accountId, ImageChangeRequest request) {
Stack stack = stackService.getByEnvironmentCrnAndAccountId(request.getEnvironmentCrn(), accountId);
MDCBuilder.buildMdcContext(stack);
ImageChangeEvent imageChangeEvent = new ImageChangeEvent(IMAGE_CHANGE_EVENT.event(), stack.getId(), request.getImageSettings());
LOGGER.info("Triggering image change flow with event: {}", imageChangeEvent);
return flowManager.notify(imageChangeEvent.selector(), imageChangeEvent);
}
use of com.sequenceiq.freeipa.flow.stack.image.change.event.ImageChangeEvent in project cloudbreak by hortonworks.
the class ImageChangeAction method doExecute.
@Override
protected void doExecute(StackContext context, ImageChangeEvent payload, Map<Object, Object> variables) throws Exception {
setOperationId(variables, payload.getOperationId());
ImageEntity originalImageEntity = storeOriginalImageRevision(payload, variables);
ImageEntity newImageEntity = imageService.changeImage(context.getStack(), payload.getRequest());
variables.put(ImageChangeActions.IMAGE_CHANGED_IN_DB, Boolean.TRUE);
if (originalImageEntity.equals(newImageEntity)) {
LOGGER.info("New and original image is the same, no change is required");
sendEvent(context, new ImageChangeEvent(IMAGE_CHANGE_NOT_REQUIRED_EVENT.event(), payload.getResourceId(), payload.getRequest()));
} else {
sendEvent(context, new ImageChangeEvent(IMAGE_CHANGED_IN_DB_EVENT.event(), payload.getResourceId(), payload.getRequest()));
}
}
use of com.sequenceiq.freeipa.flow.stack.image.change.event.ImageChangeEvent in project cloudbreak by hortonworks.
the class ImageChangeActions method prepareImage.
@Bean(name = "PREPARE_IMAGE_STATE")
public AbstractImageChangeAction<?> prepareImage() {
return new AbstractImageChangeAction<>(ImageChangeEvent.class) {
@Inject
private ImageConverter imageConverter;
@Inject
private ImageService imageService;
@Override
protected void doExecute(StackContext context, ImageChangeEvent payload, Map<Object, Object> variables) throws Exception {
CloudStack cloudStack = getCloudStackConverter().convert(context.getStack());
Image image = imageConverter.convert(imageService.getByStack(context.getStack()));
PrepareImageRequest<Object> request = new PrepareImageRequest<>(context.getCloudContext(), context.getCloudCredential(), cloudStack, image);
LOGGER.info("Prepare image: {}", image);
sendEvent(context, request);
}
@Override
protected Object getFailurePayload(ImageChangeEvent payload, Optional<StackContext> flowContext, Exception ex) {
LOGGER.error("[PREPARE_IMAGE_STATE] failed", ex);
return new StackFailureEvent(IMAGE_CHANGE_FAILED_EVENT.event(), payload.getResourceId(), ex);
}
};
}
use of com.sequenceiq.freeipa.flow.stack.image.change.event.ImageChangeEvent in project cloudbreak by hortonworks.
the class ImageChangeActionTest method testSameImage.
@Test
public void testSameImage() throws Exception {
StackContext stackContext = mock(StackContext.class);
Stack stack = new Stack();
when(stackContext.getStack()).thenReturn(stack);
when(stackContext.getFlowParameters()).thenReturn(new FlowParameters("flid", "userCrn", null));
ImageEntity imageEntity = new ImageEntity();
imageEntity.setId(2L);
ImageSettingsRequest request = new ImageSettingsRequest();
when(imageService.getByStackId(1L)).thenReturn(imageEntity);
when(imageService.changeImage(stack, request)).thenReturn(imageEntity);
when(auditReader.getRevisions(ImageEntity.class, imageEntity.getId())).thenReturn(List.of());
Map<Object, Object> variables = new HashMap<>();
underTest.doExecute(stackContext, new ImageChangeEvent(1L, request), variables);
assertEquals(Boolean.TRUE, variables.get(IMAGE_CHANGED_IN_DB));
assertFalse(variables.containsKey(ORIGINAL_IMAGE_REVISION));
assertFalse(variables.containsKey(IMAGE_ENTITY_ID));
assertEquals(imageEntity, variables.get(ORIGINAL_IMAGE));
ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(Object.class);
verify(reactorEventFactory).createEvent(anyMap(), captor.capture());
ImageChangeEvent event = (ImageChangeEvent) captor.getValue();
assertEquals(IMAGE_CHANGE_NOT_REQUIRED_EVENT.event(), event.selector());
assertEquals(1L, event.getResourceId());
assertEquals(request, event.getRequest());
}
use of com.sequenceiq.freeipa.flow.stack.image.change.event.ImageChangeEvent in project cloudbreak by hortonworks.
the class ImageChangeActionTest method testStoreRevision.
@Test
public void testStoreRevision() throws Exception {
StackContext stackContext = mock(StackContext.class);
Stack stack = new Stack();
when(stackContext.getStack()).thenReturn(stack);
when(stackContext.getFlowParameters()).thenReturn(new FlowParameters("flid", "userCrn", null));
ImageEntity imageEntity = new ImageEntity();
imageEntity.setId(2L);
when(imageService.getByStackId(1L)).thenReturn(imageEntity);
when(auditReader.getRevisions(ImageEntity.class, imageEntity.getId())).thenReturn(List.of(1, 2, 3));
Map<Object, Object> variables = new HashMap<>();
ImageSettingsRequest request = new ImageSettingsRequest();
underTest.doExecute(stackContext, new ImageChangeEvent(1L, request), variables);
assertEquals(Boolean.TRUE, variables.get(IMAGE_CHANGED_IN_DB));
assertEquals(3, variables.get(ORIGINAL_IMAGE_REVISION));
assertEquals(2L, variables.get(IMAGE_ENTITY_ID));
assertFalse(variables.containsKey(ORIGINAL_IMAGE));
ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(Object.class);
verify(reactorEventFactory).createEvent(anyMap(), captor.capture());
ImageChangeEvent event = (ImageChangeEvent) captor.getValue();
assertEquals(IMAGE_CHANGED_IN_DB_EVENT.event(), event.selector());
assertEquals(1L, event.getResourceId());
assertEquals(request, event.getRequest());
}
Aggregations