use of com.sequenceiq.datalake.flow.SdxContext in project cloudbreak by hortonworks.
the class DatalakeBackupActions method triggerDatalakeBackup.
@Bean(name = "DATALAKE_TRIGGERING_BACKUP_STATE")
public Action<?, ?> triggerDatalakeBackup() {
return new AbstractSdxAction<>(DatalakeTriggerBackupEvent.class) {
@Override
protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, DatalakeTriggerBackupEvent payload) {
return SdxContext.from(flowParameters, payload);
}
@Override
protected void prepareExecution(DatalakeTriggerBackupEvent payload, Map<Object, Object> variables) {
variables.put(OPERATION_ID, payload.getDrStatus().getOperationId());
variables.put(REASON, payload.getReason().name());
super.prepareExecution(payload, variables);
}
@Override
protected void doExecute(SdxContext context, DatalakeTriggerBackupEvent payload, Map<Object, Object> variables) {
LOGGER.info("Triggering data lake backup for {}", payload.getResourceId());
SdxCluster sdxCluster = sdxService.getById(payload.getResourceId());
eventSenderService.sendEventAndNotification(sdxCluster, context.getFlowTriggerUserCrn(), ResourceEvent.DATALAKE_BACKUP_IN_PROGRESS);
DatalakeBackupStatusResponse backupStatusResponse = sdxBackupRestoreService.triggerDatalakeBackup(payload.getResourceId(), payload.getBackupLocation(), payload.getBackupName(), payload.getUserId());
variables.put(BACKUP_ID, backupStatusResponse.getBackupId());
variables.put(OPERATION_ID, backupStatusResponse.getBackupId());
payload.getDrStatus().setOperationId(backupStatusResponse.getBackupId());
if (!backupStatusResponse.failed()) {
sendEvent(context, DatalakeDatabaseBackupStartEvent.from(payload, backupStatusResponse.getBackupId()));
} else {
sendEvent(context, DATALAKE_BACKUP_FAILED_EVENT.event(), payload);
}
}
@Override
protected Object getFailurePayload(DatalakeTriggerBackupEvent payload, Optional<SdxContext> flowContext, Exception ex) {
return DatalakeBackupFailedEvent.from(payload, ex);
}
};
}
use of com.sequenceiq.datalake.flow.SdxContext in project cloudbreak by hortonworks.
the class SdxCmDiagnosticsActions method startCmDiagnosticsCollection.
@Bean(name = "CM_DIAGNOSTICS_COLLECTION_START_STATE")
public Action<?, ?> startCmDiagnosticsCollection() {
return new AbstractSdxAction<>(SdxCmDiagnosticsCollectionEvent.class) {
@Override
protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, SdxCmDiagnosticsCollectionEvent payload) {
return SdxContext.from(flowParameters, payload);
}
@Override
protected void doExecute(SdxContext context, SdxCmDiagnosticsCollectionEvent payload, Map<Object, Object> variables) {
LOGGER.debug("Start CM based diagnostics collection for sdx cluster with id: {}", context.getSdxId());
FlowIdentifier flowIdentifier = diagnosticsFlowService.startCmDiagnosticsCollection(payload.getProperties());
SdxCmDiagnosticsCollectionEvent event = new SdxCmDiagnosticsCollectionEvent(payload.getResourceId(), payload.getUserId(), payload.getProperties(), flowIdentifier);
sendEvent(context, SDX_CM_DIAGNOSTICS_COLLECTION_IN_PROGRESS_EVENT.event(), event);
}
@Override
protected Object getFailurePayload(SdxCmDiagnosticsCollectionEvent payload, Optional<SdxContext> flowContext, Exception ex) {
return SdxCmDiagnosticsFailedEvent.from(payload, ex);
}
};
}
use of com.sequenceiq.datalake.flow.SdxContext 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());
}
use of com.sequenceiq.datalake.flow.SdxContext in project cloudbreak by hortonworks.
the class DatalakeRestoreActionsTest method testRestoreWithNoFlowChain.
@Test
public void testRestoreWithNoFlowChain() throws Exception {
when(sdxBackupRestoreService.triggerDatalakeRestore(eq(OLD_SDX_ID), any(), any(), eq(USER_CRN))).thenReturn(new DatalakeRestoreStatusResponse(BACKUP_ID, RESTORE_ID, State.STARTED, Optional.empty()));
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.from(new FlowParameters(FLOW_ID, FLOW_ID, null), event);
testSupport.doExecute(context, event, new HashMap());
ArgumentCaptor<DatalakeDatabaseRestoreStartEvent> captor = ArgumentCaptor.forClass(DatalakeDatabaseRestoreStartEvent.class);
verify(reactorEventFactory, times(1)).createEvent(any(), captor.capture());
DatalakeDatabaseRestoreStartEvent captorValue = captor.getValue();
Assertions.assertEquals(OLD_SDX_ID, captorValue.getResourceId());
}
use of com.sequenceiq.datalake.flow.SdxContext 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());
}
Aggregations