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);
}
};
}
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);
}
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);
}
};
}
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());
}
Aggregations