Search in sources :

Example 6 with FlowChainLog

use of com.sequenceiq.flow.domain.FlowChainLog in project cloudbreak by hortonworks.

the class FlowChainLogServiceTest method testFlowChainLogWhichIsEmpty.

@Test
public void testFlowChainLogWhichIsEmpty() {
    // This is mainly for flows launched before 2.39
    FlowChainLog flowChainLog = new FlowChainLog();
    when(flowLogRepository.findFirstByFlowChainIdOrderByCreatedDesc(any())).thenReturn(Optional.of(flowChainLog));
    String flowChainType = underTest.getFlowChainType("chainId");
    assertNull("For empty flowChainLog the reurn must be null", flowChainType);
}
Also used : FlowChainLog(com.sequenceiq.flow.domain.FlowChainLog) Test(org.junit.Test)

Example 7 with FlowChainLog

use of com.sequenceiq.flow.domain.FlowChainLog in project cloudbreak by hortonworks.

the class FlowChainLogServiceTest method testFindAllLatestFlowChainsInTree.

@Test
public void testFindAllLatestFlowChainsInTree() {
    FlowChainLog flowChainLogA = flowChainLog("A", NO_PARENT, 1);
    FlowChainLog flowChainLogB = flowChainLog("B", flowChainLogA.getFlowChainId(), 2);
    FlowChainLog flowChainLogC = flowChainLog("C", flowChainLogA.getFlowChainId(), 3);
    FlowChainLog flowChainLogD = flowChainLog("D", flowChainLogC.getFlowChainId(), 4);
    FlowChainLog flowChainLogES1 = flowChainLog("E", flowChainLogC.getFlowChainId(), 5);
    FlowChainLog flowChainLogES2 = flowChainLog("E", flowChainLogC.getFlowChainId(), 6);
    setUpParent(flowChainLogB, flowChainLogA);
    setUpChildren(flowChainLogA, List.of(flowChainLogC, flowChainLogB));
    setUpChildren(flowChainLogC, List.of(flowChainLogES2, flowChainLogES1, flowChainLogD));
    List<FlowChainLog> result = underTest.collectRelatedFlowChains(flowChainLogB);
    assertEquals(List.of(flowChainLogA, flowChainLogB, flowChainLogC, flowChainLogD, flowChainLogES2), result);
}
Also used : FlowChainLog(com.sequenceiq.flow.domain.FlowChainLog) Test(org.junit.Test)

Example 8 with FlowChainLog

use of com.sequenceiq.flow.domain.FlowChainLog in project cloudbreak by hortonworks.

the class FlowChainLogServiceTest method flowChainLog.

private FlowChainLog flowChainLog(String flowChainId, String parentFlowChainId, long created) {
    FlowChainLog flowChainLog = new FlowChainLog();
    flowChainLog.setFlowChainId(flowChainId);
    flowChainLog.setParentFlowChainId(parentFlowChainId);
    flowChainLog.setCreated(created);
    return flowChainLog;
}
Also used : FlowChainLog(com.sequenceiq.flow.domain.FlowChainLog)

Example 9 with FlowChainLog

use of com.sequenceiq.flow.domain.FlowChainLog in project cloudbreak by hortonworks.

the class DatalakeRestoreActions method triggerDatalakeRestore.

@Bean(name = "DATALAKE_TRIGGERING_RESTORE_STATE")
public Action<?, ?> triggerDatalakeRestore() {
    return new AbstractSdxAction<>(DatalakeTriggerRestoreEvent.class) {

        @Override
        protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, DatalakeTriggerRestoreEvent payload) {
            // When SDX is created as part of re-size flow chain, SDX in payload will not have the correct ID.
            Optional<FlowLog> lastFlowLog = flowLogService.getLastFlowLog(flowParameters.getFlowId());
            if (lastFlowLog.isPresent()) {
                SdxContext sdxContext;
                Optional<FlowChainLog> flowChainLog = flowChainLogService.findFirstByFlowChainIdOrderByCreatedDesc(lastFlowLog.get().getFlowChainId());
                if (flowChainLog.isPresent() && flowChainLog.get().getFlowChainType().equals(DatalakeResizeFlowEventChainFactory.class.getSimpleName())) {
                    SdxCluster sdxCluster = sdxService.getByNameInAccount(payload.getUserId(), payload.getSdxName());
                    LOGGER.info("Updating the Sdx-id in context from {} to {}", payload.getResourceId(), sdxCluster.getId());
                    payload.getDrStatus().setSdxClusterId(sdxCluster.getId());
                    sdxContext = SdxContext.from(flowParameters, payload);
                    sdxContext.setSdxId(sdxCluster.getId());
                    return sdxContext;
                }
            }
            return SdxContext.from(flowParameters, payload);
        }

        @Override
        protected void prepareExecution(DatalakeTriggerRestoreEvent payload, Map<Object, Object> variables) {
            super.prepareExecution(payload, variables);
        }

        @Override
        protected void doExecute(SdxContext context, DatalakeTriggerRestoreEvent payload, Map<Object, Object> variables) {
            DatalakeRestoreStatusResponse restoreStatusResponse = sdxBackupRestoreService.triggerDatalakeRestore(context.getSdxId(), payload.getBackupId(), payload.getBackupLocationOverride(), payload.getUserId());
            variables.put(RESTORE_ID, restoreStatusResponse.getRestoreId());
            variables.put(BACKUP_ID, restoreStatusResponse.getBackupId());
            variables.put(OPERATION_ID, restoreStatusResponse.getRestoreId());
            payload.getDrStatus().setOperationId(restoreStatusResponse.getRestoreId());
            if (!restoreStatusResponse.failed()) {
                sendEvent(context, DatalakeDatabaseRestoreStartEvent.from(payload, context.getSdxId(), restoreStatusResponse.getBackupId(), restoreStatusResponse.getRestoreId()));
            } else {
                LOGGER.error("Datalake restore has failed for {} ", context.getSdxId());
                sendEvent(context, DATALAKE_RESTORE_FAILED_EVENT.event(), payload);
            }
        }

        @Override
        protected Object getFailurePayload(DatalakeTriggerRestoreEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return DatalakeRestoreFailedEvent.from(flowContext, payload, ex);
        }
    };
}
Also used : Optional(java.util.Optional) FlowLog(com.sequenceiq.flow.domain.FlowLog) StateContext(org.springframework.statemachine.StateContext) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) SdxContext(com.sequenceiq.datalake.flow.SdxContext) FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) DatalakeTriggerRestoreEvent(com.sequenceiq.datalake.flow.dr.restore.event.DatalakeTriggerRestoreEvent) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) FlowChainLog(com.sequenceiq.flow.domain.FlowChainLog) Map(java.util.Map) DatalakeRestoreStatusResponse(com.sequenceiq.cloudbreak.datalakedr.model.DatalakeRestoreStatusResponse) Bean(org.springframework.context.annotation.Bean)

Example 10 with FlowChainLog

use of com.sequenceiq.flow.domain.FlowChainLog in project cloudbreak by hortonworks.

the class DatalakeRestoreActionsTest method testGetNewSdxIdForResizeCreateFlowContext.

@Test
public void testGetNewSdxIdForResizeCreateFlowContext() throws Exception {
    SdxCluster sdxCluster = genCluster();
    FlowParameters flowParameters = new FlowParameters(FLOW_ID, null, null);
    when(sdxService.getByNameInAccount(eq(USER_CRN), eq(DATALAKE_NAME))).thenReturn(sdxCluster);
    when(flowLogService.getLastFlowLog(anyString())).thenReturn(Optional.of(new FlowLog()));
    FlowChainLog flowChainLog = new FlowChainLog();
    flowChainLog.setFlowChainType(DatalakeResizeFlowEventChainFactory.class.getSimpleName());
    when(flowChainLogService.findFirstByFlowChainIdOrderByCreatedDesc(any())).thenReturn(Optional.of(flowChainLog));
    DatalakeTriggerRestoreEvent event = new DatalakeTriggerRestoreEvent(DATALAKE_TRIGGER_RESTORE_EVENT.event(), OLD_SDX_ID, DATALAKE_NAME, USER_CRN, null, BACKUP_LOCATION, null, DatalakeRestoreFailureReason.RESTORE_ON_RESIZE);
    AbstractAction action = (AbstractAction) underTest.triggerDatalakeRestore();
    initActionPrivateFields(action);
    AbstractActionTestSupport testSupport = new AbstractActionTestSupport(action);
    SdxContext context = (SdxContext) testSupport.createFlowContext(flowParameters, null, event);
    Assert.assertEquals(NEW_SDX_ID, context.getSdxId());
    Assert.assertEquals(USER_CRN, context.getUserId());
    Assert.assertEquals(FLOW_ID, context.getFlowId());
    Assert.assertEquals(NEW_SDX_ID, event.getDrStatus().getSdxClusterId());
    flowChainLog.setFlowChainType(DatalakeUpgradeFlowEventChainFactory.class.getSimpleName());
    context = (SdxContext) testSupport.createFlowContext(flowParameters, null, event);
    Assert.assertEquals(OLD_SDX_ID, context.getSdxId());
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) DatalakeTriggerRestoreEvent(com.sequenceiq.datalake.flow.dr.restore.event.DatalakeTriggerRestoreEvent) DatalakeUpgradeFlowEventChainFactory(com.sequenceiq.datalake.flow.chain.DatalakeUpgradeFlowEventChainFactory) FlowLog(com.sequenceiq.flow.domain.FlowLog) AbstractActionTestSupport(com.sequenceiq.flow.core.AbstractActionTestSupport) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) DatalakeResizeFlowEventChainFactory(com.sequenceiq.datalake.flow.chain.DatalakeResizeFlowEventChainFactory) FlowChainLog(com.sequenceiq.flow.domain.FlowChainLog) AbstractAction(com.sequenceiq.flow.core.AbstractAction) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Test(org.junit.jupiter.api.Test)

Aggregations

FlowChainLog (com.sequenceiq.flow.domain.FlowChainLog)18 FlowLog (com.sequenceiq.flow.domain.FlowLog)6 Test (org.junit.Test)4 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)3 SdxContext (com.sequenceiq.datalake.flow.SdxContext)3 FlowCheckResponse (com.sequenceiq.flow.api.model.FlowCheckResponse)3 FlowParameters (com.sequenceiq.flow.core.FlowParameters)3 Optional (java.util.Optional)3 Payload (com.sequenceiq.cloudbreak.common.event.Payload)2 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)2 DatalakeTriggerRestoreEvent (com.sequenceiq.datalake.flow.dr.restore.event.DatalakeTriggerRestoreEvent)2 AbstractSdxAction (com.sequenceiq.datalake.service.AbstractSdxAction)2 FlowTriggerEventQueue (com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue)2 List (java.util.List)2 Map (java.util.Map)2 Queue (java.util.Queue)2 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Sets (com.google.common.collect.Sets)1 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)1 CrnParseException (com.sequenceiq.cloudbreak.auth.crn.CrnParseException)1