Search in sources :

Example 26 with StackEvent

use of com.sequenceiq.freeipa.flow.stack.StackEvent 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 27 with StackEvent

use of com.sequenceiq.freeipa.flow.stack.StackEvent in project cloudbreak by hortonworks.

the class FlowOperationServiceTest method testGetOperationProgressByResourceCrn.

@Test
public void testGetOperationProgressByResourceCrn() {
    // GIVEN
    ProvisionFlowEventChainFactory provisionFlowEventChainFactory = new ProvisionFlowEventChainFactory();
    FlowTriggerEventQueue eventQueue = provisionFlowEventChainFactory.createFlowTriggerEventQueue(new StackEvent(null, null));
    given(flowService.getLastFlowOperationByResourceCrn(anyString())).willReturn(Optional.of(operationFlowsView));
    given(operationFlowsView.getOperationType()).willReturn(OperationType.PROVISION);
    given(operationDetailsPopulator.createOperationView(operationFlowsView, OperationResource.FREEIPA, EXPECTED_TYPE_LIST)).willReturn(new OperationView());
    // WHEN
    underTest.getOperationProgressByEnvironmentCrn(TEST_ENV_CRN, false);
    // THEN
    verify(operationDetailsPopulator, times(1)).createOperationView(operationFlowsView, OperationResource.FREEIPA, EXPECTED_TYPE_LIST);
    // Checks that the number of provision flows are the same as in the operation check
    assertEquals(EXPECTED_TYPE_LIST.size(), eventQueue.getQueue().size());
}
Also used : FlowTriggerEventQueue(com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) ProvisionFlowEventChainFactory(com.sequenceiq.freeipa.flow.chain.ProvisionFlowEventChainFactory) OperationView(com.sequenceiq.flow.api.model.operation.OperationView) Test(org.junit.jupiter.api.Test)

Example 28 with StackEvent

use of com.sequenceiq.freeipa.flow.stack.StackEvent in project cloudbreak by hortonworks.

the class FreeIpaUpscaleActions method upscaleFinsihedAction.

@Bean(name = "UPSCALE_FINISHED_STATE")
public Action<?, ?> upscaleFinsihedAction() {
    return new AbstractUpscaleAction<>(StackEvent.class) {

        @Inject
        private OperationService operationService;

        @Override
        protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) {
            Stack stack = context.getStack();
            stackUpdater.updateStackStatus(stack.getId(), getUpscaleCompleteStatus(variables), "Upscale complete");
            if (shouldCompleteOperation(variables)) {
                SuccessDetails successDetails = new SuccessDetails(stack.getEnvironmentCrn());
                successDetails.getAdditionalDetails().put("Hosts", getUpscaleHosts(variables));
                operationService.completeOperation(stack.getAccountId(), getOperationId(variables), List.of(successDetails), Collections.emptyList());
            }
            sendEvent(context, UPSCALE_FINISHED_EVENT.selector(), new StackEvent(stack.getId()));
        }
    };
}
Also used : SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) OperationService(com.sequenceiq.freeipa.service.operation.OperationService) Map(java.util.Map) Stack(com.sequenceiq.freeipa.entity.Stack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Bean(org.springframework.context.annotation.Bean)

Example 29 with StackEvent

use of com.sequenceiq.freeipa.flow.stack.StackEvent in project cloudbreak by hortonworks.

the class FreeIpaUpscaleActions method installFreeIpaAction.

@Bean(name = "UPSCALE_FREEIPA_INSTALL_STATE")
public Action<?, ?> installFreeIpaAction() {
    return new AbstractUpscaleAction<>(StackEvent.class) {

        @Override
        protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) {
            Stack stack = context.getStack();
            stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Installing FreeIPA");
            InstallFreeIpaServicesRequest request = new InstallFreeIpaServicesRequest(stack.getId());
            sendEvent(context, request.selector(), request);
        }
    };
}
Also used : StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) Map(java.util.Map) Stack(com.sequenceiq.freeipa.entity.Stack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) InstallFreeIpaServicesRequest(com.sequenceiq.freeipa.flow.freeipa.provision.event.services.InstallFreeIpaServicesRequest) Bean(org.springframework.context.annotation.Bean)

Example 30 with StackEvent

use of com.sequenceiq.freeipa.flow.stack.StackEvent in project cloudbreak by hortonworks.

the class FreeIpaUpscaleActions method saveMetadataAction.

@Bean(name = "UPSCALE_SAVE_METADATA_STATE")
public Action<?, ?> saveMetadataAction() {
    return new AbstractUpscaleAction<>(CollectMetadataResult.class) {

        @Override
        protected void doExecute(StackContext context, CollectMetadataResult payload, Map<Object, Object> variables) {
            Stack stack = context.getStack();
            stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Saving metadata");
            List<String> instanceIds = payload.getResults().stream().map(CloudVmMetaDataStatus::getCloudVmInstanceStatus).map(CloudVmInstanceStatus::getCloudInstance).map(CloudInstance::getInstanceId).collect(Collectors.toList());
            setInstanceIds(variables, instanceIds);
            metadataSetupService.saveInstanceMetaData(stack, payload.getResults(), com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus.CREATED);
            sendEvent(context, UPSCALE_SAVE_METADATA_FINISHED_EVENT.selector(), new StackEvent(stack.getId()));
        }
    };
}
Also used : StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CollectMetadataResult(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult) Map(java.util.Map) Stack(com.sequenceiq.freeipa.entity.Stack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Bean(org.springframework.context.annotation.Bean)

Aggregations

StackEvent (com.sequenceiq.freeipa.flow.stack.StackEvent)54 Map (java.util.Map)40 Bean (org.springframework.context.annotation.Bean)40 Stack (com.sequenceiq.freeipa.entity.Stack)38 StackContext (com.sequenceiq.freeipa.flow.stack.StackContext)28 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)17 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)12 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)11 OperationService (com.sequenceiq.freeipa.service.operation.OperationService)11 SuccessDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails)10 ClientErrorException (javax.ws.rs.ClientErrorException)10 EnvironmentEndpoint (com.sequenceiq.environment.api.v1.environment.endpoint.EnvironmentEndpoint)9 Flow (com.sequenceiq.flow.core.Flow)9 FlowParameters (com.sequenceiq.flow.core.FlowParameters)8 List (java.util.List)8 Collectors (java.util.stream.Collectors)8 Inject (javax.inject.Inject)8 Logger (org.slf4j.Logger)8 LoggerFactory (org.slf4j.LoggerFactory)8 Configuration (org.springframework.context.annotation.Configuration)8