use of com.sequenceiq.freeipa.flow.stack.StackEvent in project cloudbreak by hortonworks.
the class FullBackupActions method backupFailedAction.
@Bean(name = "BACKUP_FAILED_STATE")
public Action<?, ?> backupFailedAction() {
return new AbstractBackupAction<>(StackFailureEvent.class) {
@Inject
private OperationService operationService;
@Override
protected void doExecute(BackupContext context, StackFailureEvent payload, Map<Object, Object> variables) {
LOGGER.error("Full backup failed", payload.getException());
failFlow(context, payload);
if (isOperationIdSet(variables)) {
LOGGER.debug("Fail operation with id: [{}]", getOperationId(variables));
operationService.failOperation(context.getStack().getAccountId(), getOperationId(variables), payload.getException().getMessage());
}
sendEvent(context, new StackEvent(FULL_BACKUP_FAILURE_HANDLED_EVENT.event(), payload.getResourceId()));
}
private void failFlow(BackupContext context, StackFailureEvent payload) {
Flow flow = getFlow(context.getFlowParameters().getFlowId());
flow.setFlowFailed(payload.getException());
}
};
}
use of com.sequenceiq.freeipa.flow.stack.StackEvent in project cloudbreak by hortonworks.
the class FullBackupActions method backupFinishedAction.
@Bean(name = "BACKUP_FINISHED_STATE")
public Action<?, ?> backupFinishedAction() {
return new AbstractBackupAction<>(StackEvent.class) {
@Inject
private OperationService operationService;
@Override
protected void doExecute(BackupContext context, StackEvent payload, Map<Object, Object> variables) {
LOGGER.info("Full backup flow finished");
if (isOperationIdSet(variables) && (!isChainedAction(variables) || isFinalChain(variables))) {
LOGGER.debug("Complete operation with id: [{}]", getOperationId(variables));
Stack stack = context.getStack();
SuccessDetails successDetails = new SuccessDetails(stack.getEnvironmentCrn());
operationService.completeOperation(stack.getAccountId(), getOperationId(variables), Set.of(successDetails), Set.of());
}
sendEvent(context, new StackEvent(FULL_BACKUP_FINISHED_EVENT.event(), payload.getResourceId()));
}
};
}
use of com.sequenceiq.freeipa.flow.stack.StackEvent 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.StackEvent in project cloudbreak by hortonworks.
the class CreateFullBackupHandlerTest method testBackupSuccessful.
@Test
public void testBackupSuccessful() throws CloudbreakOrchestratorFailedException {
Stack stack = mock(Stack.class);
when(stackService.getByIdWithListsInTransaction(2L)).thenReturn(stack);
Set<InstanceMetaData> metaDataSet = Set.of();
when(stack.getNotDeletedInstanceMetaDataSet()).thenReturn(metaDataSet);
Node node1 = createNode("node1");
Node node2 = createNode("node2");
Set<Node> nodes = Set.of(node1, node2);
when(nodeService.mapInstancesToNodes(metaDataSet)).thenReturn(nodes);
GatewayConfig gatewayConfig = mock(GatewayConfig.class);
when(gatewayConfigService.getPrimaryGatewayConfig(stack)).thenReturn(gatewayConfig);
StackEvent result = (StackEvent) underTest.doAccept(new HandlerEvent<>(new Event<>(new CreateFullBackupEvent(2L))));
ArgumentCaptor<OrchestratorStateParams> captor = ArgumentCaptor.forClass(OrchestratorStateParams.class);
verify(orchestrator, times(2)).runOrchestratorState(captor.capture());
List<OrchestratorStateParams> stateParams = captor.getAllValues();
assertThat(stateParams, everyItem(allOf(hasProperty("primaryGatewayConfig", is(gatewayConfig)), hasProperty("state", is("freeipa.backup-full")), hasProperty("allNodes", is(nodes)))));
assertThat(stateParams, hasItem(hasProperty("targetHostNames", allOf(hasItem("node1"), iterableWithSize(1)))));
assertThat(stateParams, hasItem(hasProperty("targetHostNames", allOf(hasItem("node2"), iterableWithSize(1)))));
assertEquals(2L, result.getResourceId());
assertEquals(FullBackupEvent.FULL_BACKUP_SUCCESSFUL_EVENT.event(), result.selector());
}
use of com.sequenceiq.freeipa.flow.stack.StackEvent in project cloudbreak by hortonworks.
the class FreeIpaStopService method triggerStackStopIfNeeded.
private void triggerStackStopIfNeeded(Stack stack) {
MDCBuilder.buildMdcContext(stack);
if (!isStopNeeded(stack)) {
return;
}
LOGGER.debug("Trigger stop event, new status: {}", DetailedStackStatus.STOP_REQUESTED);
stackUpdater.updateStackStatus(stack, DetailedStackStatus.STOP_REQUESTED, "Stopping of stack infrastructure has been requested.");
flowManager.notify(STACK_STOP_EVENT.event(), new StackEvent(STACK_STOP_EVENT.event(), stack.getId()));
}
Aggregations