use of com.sequenceiq.freeipa.flow.stack.StackContext in project cloudbreak by hortonworks.
the class ImageChangeActionTest method testStoreImageEntity.
@Test
public void testStoreImageEntity() 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());
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));
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_CHANGED_IN_DB_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 AbstractDownscaleAction method createFlowContext.
@Override
protected StackContext createFlowContext(FlowParameters flowParameters, StateContext<DownscaleState, DownscaleFlowEvent> stateContext, P payload) {
Stack stack = stackService.getByIdWithListsInTransaction(payload.getResourceId());
MDCBuilder.buildMdcContext(stack);
addMdcOperationIdIfPresent(stateContext.getExtendedState().getVariables());
Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
CloudContext cloudContext = CloudContext.Builder.builder().withId(stack.getId()).withName(stack.getName()).withCrn(stack.getResourceCrn()).withPlatform(stack.getCloudPlatform()).withVariant(stack.getPlatformvariant()).withLocation(location).withUserName(stack.getOwner()).withAccountId(stack.getAccountId()).build();
CloudCredential cloudCredential = credentialConverter.convert(credentialService.getCredentialByEnvCrn(stack.getEnvironmentCrn()));
CloudStack cloudStack = cloudStackConverter.convert(stack);
return new StackContext(flowParameters, stack, cloudContext, cloudCredential, cloudStack);
}
use of com.sequenceiq.freeipa.flow.stack.StackContext in project cloudbreak by hortonworks.
the class FreeIpaDownscaleActions method updateMetadataAction.
@Bean(name = "DOWNSCALE_UPDATE_METADATA_STATE")
public Action<?, ?> updateMetadataAction() {
return new AbstractDownscaleAction<>(RemoveHostsFromOrchestrationSuccess.class) {
@Inject
private InstanceGroupService instanceGroupService;
@Override
protected void doExecute(StackContext context, RemoveHostsFromOrchestrationSuccess payload, Map<Object, Object> variables) {
Stack stack = context.getStack();
stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Updating metadata");
List<String> repairInstanceIds = getInstanceIds(variables);
terminationService.finalizeTermination(stack.getId(), repairInstanceIds);
terminationService.finalizeTerminationForInstancesWithoutInstanceIds(stack.getId());
if (!isRepair(variables)) {
int nodeCount = getInstanceCountByGroup(variables);
instanceGroupService.findByStackId(stack.getId()).forEach(instanceGroup -> {
instanceGroup.setNodeCount(nodeCount);
instanceGroupService.save(instanceGroup);
});
}
sendEvent(context, UPDATE_METADATA_FINISHED_EVENT.selector(), new StackEvent(stack.getId()));
}
};
}
use of com.sequenceiq.freeipa.flow.stack.StackContext in project cloudbreak by hortonworks.
the class FreeIpaDownscaleActions method updateEnvironmentStackConfigAction.
@Bean(name = "DOWNSCALE_UPDATE_ENVIRONMENT_STACK_CONFIG_STATE")
public Action<?, ?> updateEnvironmentStackConfigAction() {
return new AbstractDownscaleAction<>(StackEvent.class) {
@Inject
private EnvironmentEndpoint environmentEndpoint;
@Inject
private WebApplicationExceptionMessageExtractor webApplicationExceptionMessageExtractor;
@Override
protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) {
Stack stack = context.getStack();
stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Updating environment stack config");
try {
if (!isRepair(variables) || !isChainedAction(variables) || isFinalChain(variables)) {
ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> environmentEndpoint.updateConfigsInEnvironmentByCrn(stack.getEnvironmentCrn()));
}
sendEvent(context, DOWNSCALE_UPDATE_ENVIRONMENT_STACK_CONFIG_FINISHED_EVENT.selector(), new StackEvent(stack.getId()));
} catch (ClientErrorException e) {
String errorMessage = webApplicationExceptionMessageExtractor.getErrorMessage(e);
LOGGER.error("Failed to update the stack config due to {}", errorMessage, e);
sendEvent(context, DOWNSCALE_UPDATE_ENVIRONMENT_STACK_CONFIG_FAILED_EVENT.selector(), new DownscaleFailureEvent(stack.getId(), "Updating environment stack config", Set.of(), Map.of(), e));
} catch (Exception e) {
LOGGER.error("Failed to update the stack config", e);
sendEvent(context, DOWNSCALE_UPDATE_ENVIRONMENT_STACK_CONFIG_FAILED_EVENT.selector(), new DownscaleFailureEvent(stack.getId(), "Updating environment stack config", Set.of(), Map.of(), e));
}
}
};
}
use of com.sequenceiq.freeipa.flow.stack.StackContext in project cloudbreak by hortonworks.
the class FreeIpaDownscaleActions method removeReplicationAgreementsAction.
@Bean(name = "DOWNSCALE_REMOVE_REPLICATION_AGREEMENTS_STATE")
public Action<?, ?> removeReplicationAgreementsAction() {
return new AbstractDownscaleAction<>(RemoveServersResponse.class) {
@Override
protected void doExecute(StackContext context, RemoveServersResponse payload, Map<Object, Object> variables) {
CleanupEvent cleanupEvent = buildCleanupEvent(context, getDownscaleHosts(variables));
stackUpdater.updateStackStatus(context.getStack().getId(), getInProgressStatus(variables), "Removing servers");
RemoveReplicationAgreementsRequest request = new RemoveReplicationAgreementsRequest(cleanupEvent);
sendEvent(context, request);
}
};
}
Aggregations