use of com.sequenceiq.freeipa.flow.stack.StackFailureEvent 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.StackFailureEvent 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.StackFailureEvent 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.StackFailureEvent in project cloudbreak by hortonworks.
the class CreateFullBackupHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<CreateFullBackupEvent> event) {
Stack stack = stackService.getByIdWithListsInTransaction(event.getData().getResourceId());
MDCBuilder.buildMdcContext(stack);
Set<Node> nodes = nodeService.mapInstancesToNodes(stack.getNotDeletedInstanceMetaDataSet());
OrchestratorStateParams stateParameters = createOrchestratorStateParams(stack, nodes);
try {
runBackupForNodesSequentially(nodes, stateParameters);
return new StackEvent(FullBackupEvent.FULL_BACKUP_SUCCESSFUL_EVENT.event(), event.getData().getResourceId());
} catch (CloudbreakOrchestratorFailedException | CloneNotSupportedException e) {
LOGGER.error("Full backup failed for node: {}", stateParameters.getTargetHostNames(), e);
return new StackFailureEvent(FullBackupEvent.FULL_BACKUP_FAILED_EVENT.event(), event.getData().getResourceId(), e);
}
}
use of com.sequenceiq.freeipa.flow.stack.StackFailureEvent in project cloudbreak by hortonworks.
the class CreateFullBackupHandlerTest method testOrchestratorThrowException.
@Test
public void testOrchestratorThrowException() 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");
Set<Node> nodes = Set.of(node1);
when(nodeService.mapInstancesToNodes(metaDataSet)).thenReturn(nodes);
GatewayConfig gatewayConfig = mock(GatewayConfig.class);
when(gatewayConfigService.getPrimaryGatewayConfig(stack)).thenReturn(gatewayConfig);
doThrow(new CloudbreakOrchestratorFailedException("tada")).when(orchestrator).runOrchestratorState(any(OrchestratorStateParams.class));
StackFailureEvent result = (StackFailureEvent) underTest.doAccept(new HandlerEvent<>(new Event<>(new CreateFullBackupEvent(2L))));
assertEquals(2L, result.getResourceId());
assertEquals(FullBackupEvent.FULL_BACKUP_FAILED_EVENT.event(), result.selector());
assertEquals("tada", result.getException().getMessage());
}
Aggregations