use of com.sequenceiq.datalake.flow.refresh.event.DatahubRefreshFailedEvent 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.DatahubRefreshFailedEvent in project cloudbreak by hortonworks.
the class DatahubRefreshHandlerTest method acceptWithExceptions.
@ParameterizedTest
@ValueSource(classes = { UserBreakException.class, PollerStoppedException.class, PollerException.class })
void acceptWithExceptions(Class<? extends Throwable> errorClass) throws Exception {
DatahubRefreshWaitEvent request = new DatahubRefreshWaitEvent(SDX_ID, "user");
Event.Headers headers = new Event.Headers();
Event<DatahubRefreshWaitEvent> event = new Event<>(headers, request);
doThrow(errorClass).when(sdxRefreshService).waitCloudbreakCluster(eq(SDX_ID), any(PollingConfig.class));
Selectable selectable = new ExceptionCatcherEventHandlerTestSupport<>(underTest).doAccept(event);
DatahubRefreshFailedEvent failedEvent = new DatahubRefreshFailedEvent(SDX_ID, "user", new Exception("error"));
assertThat(selectable).usingRecursiveComparison().isEqualTo(failedEvent);
}
use of com.sequenceiq.datalake.flow.refresh.event.DatahubRefreshFailedEvent 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.DatahubRefreshFailedEvent in project cloudbreak by hortonworks.
the class DatahubRefreshWaitHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<DatahubRefreshWaitEvent> event) {
SdxEvent sdxEvent = event.getData();
Long sdxId = sdxEvent.getResourceId();
String userId = sdxEvent.getUserId();
Selectable response;
try {
LOGGER.debug("Start polling datahub refresh process for id: {}", sdxId);
PollingConfig pollingConfig = new PollingConfig(sleepTimeInSec, TimeUnit.SECONDS, durationInMinutes, TimeUnit.MINUTES);
sdxRefreshService.waitCloudbreakCluster(sdxId, pollingConfig);
response = new SdxEvent(DatahubRefreshFlowEvent.DATAHUB_REFRESH_FINISHED_EVENT.event(), sdxId, userId);
} catch (UserBreakException userBreakException) {
LOGGER.error("Datahub refresh polling exited before timeout. Cause: ", userBreakException);
response = new DatahubRefreshFailedEvent(sdxId, userId, userBreakException);
} catch (PollerStoppedException pollerStoppedException) {
LOGGER.error("Datahub refresh poller stopped for stack: {}", sdxId);
response = new DatahubRefreshFailedEvent(sdxId, userId, new PollerStoppedException("Datahub refresh timed out after " + durationInMinutes + " minutes"));
} catch (PollerException exception) {
LOGGER.error("Datahub refresh polling failed for stack: {}", sdxId);
response = new DatahubRefreshFailedEvent(sdxId, userId, exception);
}
return response;
}
Aggregations