use of com.sequenceiq.freeipa.flow.stack.StackContext in project cloudbreak by hortonworks.
the class StackProvisionService method setupTls.
public void setupTls(StackContext context) throws CloudbreakException {
Stack stack = context.getStack();
Set<InstanceMetaData> instanceMetaDataSet = stack.getInstanceGroups().stream().flatMap(instanceGroup -> instanceGroup.getAllInstanceMetaData().stream()).collect(Collectors.toSet());
for (InstanceMetaData gwInstance : instanceMetaDataSet) {
tlsSetupService.setupTls(stack.getId(), gwInstance);
}
}
use of com.sequenceiq.freeipa.flow.stack.StackContext in project cloudbreak by hortonworks.
the class ImageChangeActions method setImageOnProvider.
@Bean(name = "SET_IMAGE_ON_PROVIDER_STATE")
public AbstractImageChangeAction<?> setImageOnProvider() {
return new AbstractImageChangeAction<>(StackEvent.class) {
@Inject
private ResourceService resourceService;
@Inject
private ResourceToCloudResourceConverter cloudResourceConverter;
@Override
protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) throws Exception {
CloudStack cloudStack = getCloudStackConverter().convert(context.getStack());
Collection<Resource> resources = resourceService.findAllByStackId(context.getStack().getId());
List<CloudResource> cloudResources = resources.stream().map(resource -> cloudResourceConverter.convert(resource)).collect(Collectors.toList());
UpdateImageRequest<Selectable> request = new UpdateImageRequest<>(context.getCloudContext(), context.getCloudCredential(), cloudStack, cloudResources);
sendEvent(context, request);
}
@Override
protected Object getFailurePayload(StackEvent payload, Optional<StackContext> flowContext, Exception ex) {
LOGGER.error("[SET_IMAGE_ON_PROVIDER_STATE] failed", ex);
return new StackFailureEvent(IMAGE_CHANGE_FAILED_EVENT.event(), payload.getResourceId(), ex);
}
};
}
use of com.sequenceiq.freeipa.flow.stack.StackContext 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.StackContext 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.StackContext 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