use of com.sequenceiq.datalake.flow.SdxEvent in project cloudbreak by hortonworks.
the class SdxDetachActions method sdxAttachNewCluster.
@Bean(name = "SDX_ATTACH_NEW_CLUSTER_STATE")
public Action<?, ?> sdxAttachNewCluster() {
return new AbstractSdxAction<>(SdxEvent.class) {
@Override
protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, SdxEvent payload) {
return SdxContext.from(flowParameters, payload);
}
@Override
protected void doExecute(SdxContext context, SdxEvent payload, Map<Object, Object> variables) throws Exception {
SdxCluster detachedCluster = (SdxCluster) variables.get(DETACHED_SDX);
sdxDetachService.markAsDetached(detachedCluster.getId());
eventSenderService.notifyEvent(detachedCluster, context, ResourceEvent.SDX_DETACH_FINISHED);
LOGGER.info("Detaching of SDX with ID {} finished.", detachedCluster.getId());
if (!((boolean) variables.get(IS_DETACH_DURING_RECOVERY))) {
SdxCluster resizedCluster = (SdxCluster) variables.get(RESIZED_SDX);
LOGGER.info("Attaching of SDX cluster with ID {} in progress.", resizedCluster.getId());
MDCBuilder.buildMdcContext(resizedCluster);
resizedCluster = sdxAttachService.saveSdxAndAssignResourceOwnerRole(resizedCluster);
sdxAttachService.markAsAttached(resizedCluster);
LOGGER.info("Attaching of SDX cluster with ID {} is complete.", resizedCluster.getId());
context.setSdxId(resizedCluster.getId());
}
sendEvent(context, SDX_ATTACH_NEW_CLUSTER_SUCCESS_EVENT.event(), payload);
}
@Override
protected Object getFailurePayload(SdxEvent payload, Optional<SdxContext> flowContext, Exception e) {
LOGGER.error("Failed to attach new cluster during detach.", e);
return SdxDetachFailedEvent.from(payload, e);
}
};
}
use of com.sequenceiq.datalake.flow.SdxEvent in project cloudbreak by hortonworks.
the class StartDatahubActions method startDatahubStartAction.
@Bean(name = "START_DATAHUB_STATE")
public Action<?, ?> startDatahubStartAction() {
return new AbstractSdxAction<>(SdxEvent.class) {
@Override
protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, SdxEvent payload) {
return SdxContext.from(flowParameters, payload);
}
@Override
protected void doExecute(SdxContext context, SdxEvent payload, Map<Object, Object> variables) throws Exception {
LOGGER.info("Execute start datahub for sdx: {}", payload.getResourceId());
String userId = payload.getUserId();
Long resourceId = payload.getResourceId();
try {
sdxStartService.startAllDatahubs(resourceId);
sendEvent(context, new SdxEvent(START_DATAHUB_IN_PROGRESS_EVENT.event(), resourceId, userId));
} catch (Exception e) {
LOGGER.error("Failed to start datahub, sdx: {}, user: {}", resourceId, userId, e);
sendEvent(context, new SdxEvent(START_DATAHUB_FAILED_EVENT.event(), resourceId, userId));
}
}
@Override
protected Object getFailurePayload(SdxEvent payload, Optional<SdxContext> flowContext, Exception ex) {
return StartDatahubFailedEvent.from(payload, ex);
}
};
}
use of com.sequenceiq.datalake.flow.SdxEvent in project cloudbreak by hortonworks.
the class SdxCmSyncActions method callCoreCmSync.
@Bean(name = "CORE_CM_SYNC_STATE")
public Action<?, ?> callCoreCmSync() {
return new AbstractSdxCmSyncAction<>(SdxCmSyncStartEvent.class) {
@Override
protected void doExecute(SdxContext context, SdxCmSyncStartEvent payload, Map<Object, Object> variables) throws Exception {
LOGGER.debug("Calling cm sync on core");
sdxCmSyncService.callCmSync(payload.getResourceId());
sendEvent(context, new SdxEvent(SDX_CM_SYNC_IN_PROGRESS_EVENT.event(), context));
}
};
}
use of com.sequenceiq.datalake.flow.SdxEvent in project cloudbreak by hortonworks.
the class SdxCmSyncActions method waitForCoreCmSync.
@Bean(name = "CORE_CM_SYNC_IN_PROGRESS_STATE")
public Action<?, ?> waitForCoreCmSync() {
return new AbstractSdxCmSyncAction<>(SdxEvent.class) {
@Override
protected void doExecute(SdxContext context, SdxEvent payload, Map<Object, Object> variables) {
SdxCmSyncWaitEvent sdxCmSyncWaitEvent = new SdxCmSyncWaitEvent(context);
sendEvent(context, sdxCmSyncWaitEvent);
}
};
}
use of com.sequenceiq.datalake.flow.SdxEvent in project cloudbreak by hortonworks.
the class SdxCmSyncWaitHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<SdxCmSyncWaitEvent> event) {
LOGGER.debug("Entering handler for calling sync CM and parcel versions from CM server");
SdxCmSyncWaitEvent sdxCmSyncWaitEvent = event.getData();
try {
SdxCluster sdxCluster = sdxService.getById(sdxCmSyncWaitEvent.getResourceId());
PollingConfig pollingConfig = new PollingConfig(sleepTimeInSec, TimeUnit.SECONDS, durationInMinutes, TimeUnit.MINUTES).withStopPollingIfExceptionOccurred(true);
sdxWaitService.waitForCloudbreakFlow(sdxCluster, pollingConfig, "Sync cm");
return new SdxEvent(SDX_CM_SYNC_FINISHED_EVENT.event(), event.getData().getResourceId(), event.getData().getUserId());
} catch (SdxWaitException e) {
LOGGER.warn("Error happened during waiting for syncing CM and parcel versions from a datalake CM to component table {}, error: ", sdxCmSyncWaitEvent.getResourceId(), e);
return new SdxCmSyncFailedEvent(sdxCmSyncWaitEvent.getResourceId(), sdxCmSyncWaitEvent.getUserId(), e);
}
}
Aggregations