Search in sources :

Example 1 with StackFailureEvent

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());
        }
    };
}
Also used : StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) StackFailureEvent(com.sequenceiq.freeipa.flow.stack.StackFailureEvent) BackupContext(com.sequenceiq.freeipa.flow.freeipa.backup.full.BackupContext) OperationService(com.sequenceiq.freeipa.service.operation.OperationService) Map(java.util.Map) Flow(com.sequenceiq.flow.core.Flow) Bean(org.springframework.context.annotation.Bean)

Example 2 with StackFailureEvent

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);
        }
    };
}
Also used : Action(org.springframework.statemachine.action.Action) PrepareImageRequest(com.sequenceiq.cloudbreak.cloud.event.setup.PrepareImageRequest) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) ImageService(com.sequenceiq.freeipa.service.image.ImageService) ImageChangeEvent(com.sequenceiq.freeipa.flow.stack.image.change.event.ImageChangeEvent) LoggerFactory(org.slf4j.LoggerFactory) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) Image(com.sequenceiq.cloudbreak.cloud.model.Image) ResourceToCloudResourceConverter(com.sequenceiq.freeipa.converter.cloud.ResourceToCloudResourceConverter) IMAGE_CHANGE_FAILED_EVENT(com.sequenceiq.freeipa.flow.stack.image.change.event.ImageChangeEvents.IMAGE_CHANGE_FAILED_EVENT) Inject(javax.inject.Inject) ResourceService(com.sequenceiq.freeipa.service.resource.ResourceService) Map(java.util.Map) Resource(com.sequenceiq.freeipa.entity.Resource) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) IMAGE_CHANGE_FINISHED_EVENT(com.sequenceiq.freeipa.flow.stack.image.change.event.ImageChangeEvents.IMAGE_CHANGE_FINISHED_EVENT) PayloadConverter(com.sequenceiq.flow.core.PayloadConverter) StackFailureEvent(com.sequenceiq.freeipa.flow.stack.StackFailureEvent) Logger(org.slf4j.Logger) UpdateImageRequest(com.sequenceiq.cloudbreak.cloud.event.resource.UpdateImageRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Collection(java.util.Collection) ImageConverter(com.sequenceiq.freeipa.converter.image.ImageConverter) Collectors(java.util.stream.Collectors) Configuration(org.springframework.context.annotation.Configuration) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) CloudPlatformResult(com.sequenceiq.cloudbreak.cloud.event.CloudPlatformResult) List(java.util.List) Optional(java.util.Optional) Bean(org.springframework.context.annotation.Bean) Optional(java.util.Optional) StackFailureEvent(com.sequenceiq.freeipa.flow.stack.StackFailureEvent) ResourceToCloudResourceConverter(com.sequenceiq.freeipa.converter.cloud.ResourceToCloudResourceConverter) ResourceService(com.sequenceiq.freeipa.service.resource.ResourceService) Resource(com.sequenceiq.freeipa.entity.Resource) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) UpdateImageRequest(com.sequenceiq.cloudbreak.cloud.event.resource.UpdateImageRequest) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 3 with StackFailureEvent

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);
        }
    };
}
Also used : Optional(java.util.Optional) StackFailureEvent(com.sequenceiq.freeipa.flow.stack.StackFailureEvent) ImageConverter(com.sequenceiq.freeipa.converter.image.ImageConverter) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Image(com.sequenceiq.cloudbreak.cloud.model.Image) ImageService(com.sequenceiq.freeipa.service.image.ImageService) ImageChangeEvent(com.sequenceiq.freeipa.flow.stack.image.change.event.ImageChangeEvent) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) Map(java.util.Map) PrepareImageRequest(com.sequenceiq.cloudbreak.cloud.event.setup.PrepareImageRequest) Bean(org.springframework.context.annotation.Bean)

Example 4 with StackFailureEvent

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);
    }
}
Also used : CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) StackFailureEvent(com.sequenceiq.freeipa.flow.stack.StackFailureEvent) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) OrchestratorStateParams(com.sequenceiq.cloudbreak.orchestrator.host.OrchestratorStateParams) Stack(com.sequenceiq.freeipa.entity.Stack)

Example 5 with StackFailureEvent

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());
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) CreateFullBackupEvent(com.sequenceiq.freeipa.flow.freeipa.backup.full.event.CreateFullBackupEvent) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) StackFailureEvent(com.sequenceiq.freeipa.flow.stack.StackFailureEvent) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) OrchestratorStateParams(com.sequenceiq.cloudbreak.orchestrator.host.OrchestratorStateParams) Stack(com.sequenceiq.freeipa.entity.Stack) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Test(org.junit.jupiter.api.Test)

Aggregations

StackFailureEvent (com.sequenceiq.freeipa.flow.stack.StackFailureEvent)7 StackEvent (com.sequenceiq.freeipa.flow.stack.StackEvent)5 Map (java.util.Map)4 Bean (org.springframework.context.annotation.Bean)4 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)3 CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)3 Stack (com.sequenceiq.freeipa.entity.Stack)3 PrepareImageRequest (com.sequenceiq.cloudbreak.cloud.event.setup.PrepareImageRequest)2 Image (com.sequenceiq.cloudbreak.cloud.model.Image)2 Node (com.sequenceiq.cloudbreak.common.orchestration.Node)2 OrchestratorStateParams (com.sequenceiq.cloudbreak.orchestrator.host.OrchestratorStateParams)2 Flow (com.sequenceiq.flow.core.Flow)2 HandlerEvent (com.sequenceiq.flow.reactor.api.handler.HandlerEvent)2 ImageConverter (com.sequenceiq.freeipa.converter.image.ImageConverter)2 CreateFullBackupEvent (com.sequenceiq.freeipa.flow.freeipa.backup.full.event.CreateFullBackupEvent)2 StackContext (com.sequenceiq.freeipa.flow.stack.StackContext)2 ImageChangeEvent (com.sequenceiq.freeipa.flow.stack.image.change.event.ImageChangeEvent)2 ImageService (com.sequenceiq.freeipa.service.image.ImageService)2 Optional (java.util.Optional)2 Test (org.junit.jupiter.api.Test)2