Search in sources :

Example 1 with DatahubRefreshStartEvent

use of com.sequenceiq.datalake.flow.refresh.event.DatahubRefreshStartEvent in project cloudbreak by hortonworks.

the class DatahubRefreshActions method startDatahubRefreshAction.

@Bean(name = "DATAHUB_REFRESH_START_STATE")
public Action<?, ?> startDatahubRefreshAction() {
    return new AbstractSdxAction<>(DatahubRefreshStartEvent.class) {

        @Override
        protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, DatahubRefreshStartEvent payload) {
            // Only called as a part of a resize operation so we should update the cluster to reference the newly created one
            SdxCluster sdxCluster = sdxService.getByNameInAccount(payload.getUserId(), payload.getSdxName());
            LOGGER.info("Updating the Sdx-id in context from {} to {}", payload.getResourceId(), sdxCluster.getId());
            SdxContext sdxContext = SdxContext.from(flowParameters, payload);
            sdxContext.setSdxId(sdxCluster.getId());
            return sdxContext;
        }

        @Override
        protected void doExecute(SdxContext context, DatahubRefreshStartEvent payload, Map<Object, Object> variables) throws Exception {
            payload = new DatahubRefreshStartEvent(context.getSdxId(), payload.getSdxName(), payload.getUserId());
            LOGGER.info("Start datahub refresh associated with Sdx: {}", payload.getSdxName());
            SdxCluster sdxCluster = sdxService.getById(context.getSdxId());
            variables.put(SDX, sdxCluster);
            eventSenderService.sendEventAndNotification(sdxCluster, context.getFlowTriggerUserCrn(), ResourceEvent.ENVIRONMENT_RESTART_DATAHUB_STARTED);
            sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.RUNNING, "Datahub refresh in progress", payload.getResourceId());
            sdxRefreshService.refreshAllDatahub(payload.getResourceId());
            sendEvent(context, DatahubRefreshFlowEvent.DATAHUB_REFRESH_IN_PROGRESS_EVENT.selector(), payload);
        }

        @Override
        protected Object getFailurePayload(DatahubRefreshStartEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return new DatahubRefreshFailedEvent(payload.getResourceId(), payload.getUserId(), ex);
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) Optional(java.util.Optional) DatahubRefreshFailedEvent(com.sequenceiq.datalake.flow.refresh.event.DatahubRefreshFailedEvent) StateContext(org.springframework.statemachine.StateContext) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) Map(java.util.Map) DatahubRefreshStartEvent(com.sequenceiq.datalake.flow.refresh.event.DatahubRefreshStartEvent) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 2 with DatahubRefreshStartEvent

use of com.sequenceiq.datalake.flow.refresh.event.DatahubRefreshStartEvent in project cloudbreak by hortonworks.

the class DatalakeResizeFlowEventChainFactory method createFlowTriggerEventQueue.

@Override
public FlowTriggerEventQueue createFlowTriggerEventQueue(DatalakeResizeFlowChainStartEvent event) {
    Queue<Selectable> chain = new ConcurrentLinkedQueue<>();
    if (event.shouldTakeBackup()) {
        // Take a backup
        chain.add(new DatalakeTriggerBackupEvent(DATALAKE_TRIGGER_BACKUP_EVENT.event(), event.getResourceId(), event.getUserId(), event.getBackupLocation(), "resize" + System.currentTimeMillis(), DatalakeBackupFailureReason.BACKUP_ON_RESIZE, event.accepted()));
        // Stop datalake
        chain.add(new SdxStartStopEvent(SDX_STOP_EVENT.event(), event.getResourceId(), event.getUserId(), STOP_DATAHUBS));
    } else {
        chain.add(new SdxStartStopEvent(SDX_STOP_EVENT.event(), event.getResourceId(), event.getUserId(), STOP_DATAHUBS, event.accepted()));
    }
    // Detach sdx from environment
    chain.add(new SdxStartDetachEvent(SDX_DETACH_EVENT.event(), event.getResourceId(), event.getSdxCluster(), event.getUserId()));
    // Create new
    chain.add(new SdxEvent(SDX_VALIDATION_EVENT.event(), event.getResourceId(), event.getSdxCluster().getClusterName(), event.getUserId()));
    if (event.shouldPerformRestore()) {
        // restore the new cluster
        chain.add(new DatalakeTriggerRestoreEvent(DATALAKE_TRIGGER_RESTORE_EVENT.event(), event.getResourceId(), event.getSdxCluster().getClusterName(), event.getUserId(), null, event.getBackupLocation(), null, DatalakeRestoreFailureReason.RESTORE_ON_RESIZE));
    }
    // Delete the detached Sdx
    chain.add(new SdxDeleteStartEvent(SDX_DELETE_EVENT.event(), event.getResourceId(), event.getUserId(), true));
    chain.add(new DatahubRefreshStartEvent(event.getResourceId(), event.getSdxCluster().getClusterName(), event.getUserId()));
    return new FlowTriggerEventQueue(getName(), event, chain);
}
Also used : DatalakeTriggerRestoreEvent(com.sequenceiq.datalake.flow.dr.restore.event.DatalakeTriggerRestoreEvent) FlowTriggerEventQueue(com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) SdxStartStopEvent(com.sequenceiq.datalake.flow.stop.event.SdxStartStopEvent) SdxStartDetachEvent(com.sequenceiq.datalake.flow.detach.event.SdxStartDetachEvent) SdxEvent(com.sequenceiq.datalake.flow.SdxEvent) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) SdxDeleteStartEvent(com.sequenceiq.datalake.flow.delete.event.SdxDeleteStartEvent) DatahubRefreshStartEvent(com.sequenceiq.datalake.flow.refresh.event.DatahubRefreshStartEvent) DatalakeTriggerBackupEvent(com.sequenceiq.datalake.flow.dr.backup.event.DatalakeTriggerBackupEvent)

Example 3 with DatahubRefreshStartEvent

use of com.sequenceiq.datalake.flow.refresh.event.DatahubRefreshStartEvent in project cloudbreak by hortonworks.

the class DatahubRefreshActions method datahubRefreshInProgressAction.

@Bean(name = "DATAHUB_REFRESH_IN_PROGRESS_STATE")
public Action<?, ?> datahubRefreshInProgressAction() {
    return new AbstractSdxAction<>(DatahubRefreshStartEvent.class) {

        @Override
        protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, DatahubRefreshStartEvent payload) {
            return SdxContext.from(flowParameters, payload);
        }

        @Override
        protected void doExecute(SdxContext context, DatahubRefreshStartEvent payload, Map<Object, Object> variables) throws Exception {
            LOGGER.info("Datahub refresh in progress for: {}", payload.getResourceId());
            sendEvent(context, new DatahubRefreshWaitEvent(payload.getResourceId(), payload.getUserId()));
        }

        @Override
        protected Object getFailurePayload(DatahubRefreshStartEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return new DatahubRefreshFailedEvent(payload.getResourceId(), payload.getUserId(), ex);
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) DatahubRefreshWaitEvent(com.sequenceiq.datalake.flow.refresh.event.DatahubRefreshWaitEvent) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) Optional(java.util.Optional) DatahubRefreshFailedEvent(com.sequenceiq.datalake.flow.refresh.event.DatahubRefreshFailedEvent) StateContext(org.springframework.statemachine.StateContext) Map(java.util.Map) DatahubRefreshStartEvent(com.sequenceiq.datalake.flow.refresh.event.DatahubRefreshStartEvent) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 4 with DatahubRefreshStartEvent

use of com.sequenceiq.datalake.flow.refresh.event.DatahubRefreshStartEvent in project cloudbreak by hortonworks.

the class DatahubRefreshActionsTest method testStartTriggersCall.

@Test
public void testStartTriggersCall() throws Exception {
    DatahubRefreshStartEvent event = new DatahubRefreshStartEvent(SDX_ID, SDX_NAME, USER_CRN);
    AbstractAction action = (AbstractAction) underTest.startDatahubRefreshAction();
    initActionPrivateFields(action);
    AbstractActionTestSupport testSupport = new AbstractActionTestSupport(action);
    SdxContext context = SdxContext.from(new FlowParameters(FLOW_ID, USER_CRN, null), event);
    testSupport.doExecute(context, event, new HashMap());
    ArgumentCaptor<DatahubRefreshStartEvent> captor = ArgumentCaptor.forClass(DatahubRefreshStartEvent.class);
    verify(reactorEventFactory, times(1)).createEvent(any(), captor.capture());
    DatahubRefreshStartEvent captorValue = captor.getValue();
    Assertions.assertEquals(SDX_NAME, captorValue.getSdxName());
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) HashMap(java.util.HashMap) AbstractActionTestSupport(com.sequenceiq.flow.core.AbstractActionTestSupport) AbstractAction(com.sequenceiq.flow.core.AbstractAction) DatahubRefreshStartEvent(com.sequenceiq.datalake.flow.refresh.event.DatahubRefreshStartEvent) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Test(org.junit.jupiter.api.Test)

Aggregations

DatahubRefreshStartEvent (com.sequenceiq.datalake.flow.refresh.event.DatahubRefreshStartEvent)4 SdxContext (com.sequenceiq.datalake.flow.SdxContext)3 FlowParameters (com.sequenceiq.flow.core.FlowParameters)3 DatahubRefreshFailedEvent (com.sequenceiq.datalake.flow.refresh.event.DatahubRefreshFailedEvent)2 AbstractSdxAction (com.sequenceiq.datalake.service.AbstractSdxAction)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Bean (org.springframework.context.annotation.Bean)2 StateContext (org.springframework.statemachine.StateContext)2 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)1 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)1 SdxEvent (com.sequenceiq.datalake.flow.SdxEvent)1 SdxDeleteStartEvent (com.sequenceiq.datalake.flow.delete.event.SdxDeleteStartEvent)1 SdxStartDetachEvent (com.sequenceiq.datalake.flow.detach.event.SdxStartDetachEvent)1 DatalakeTriggerBackupEvent (com.sequenceiq.datalake.flow.dr.backup.event.DatalakeTriggerBackupEvent)1 DatalakeTriggerRestoreEvent (com.sequenceiq.datalake.flow.dr.restore.event.DatalakeTriggerRestoreEvent)1 DatahubRefreshWaitEvent (com.sequenceiq.datalake.flow.refresh.event.DatahubRefreshWaitEvent)1 SdxStartStopEvent (com.sequenceiq.datalake.flow.stop.event.SdxStartStopEvent)1 AbstractAction (com.sequenceiq.flow.core.AbstractAction)1 AbstractActionTestSupport (com.sequenceiq.flow.core.AbstractActionTestSupport)1