use of com.sequenceiq.flow.core.FlowParameters 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.flow.core.FlowParameters in project cloudbreak by hortonworks.
the class SdxDeleteActions method finishedAction.
@Bean(name = "SDX_DELETION_FINISHED_STATE")
public Action<?, ?> finishedAction() {
return new AbstractSdxAction<>(RdsDeletionSuccessEvent.class) {
@Override
protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, RdsDeletionSuccessEvent payload) {
return SdxContext.from(flowParameters, payload);
}
@Override
protected void doExecute(SdxContext context, RdsDeletionSuccessEvent payload, Map<Object, Object> variables) throws Exception {
Long datalakeId = payload.getResourceId();
LOGGER.info("Datalake delete finalized: {}", datalakeId);
SdxCluster sdxCluster = sdxService.getById(datalakeId);
if (sdxCluster != null) {
metricService.incrementMetricCounter(MetricType.SDX_DELETION_FINISHED, sdxCluster);
}
eventSenderService.notifyEvent(context, ResourceEvent.SDX_CLUSTER_DELETION_FINISHED);
sendEvent(context, SDX_DELETE_FINALIZED_EVENT.event(), payload);
}
@Override
protected Object getFailurePayload(RdsDeletionSuccessEvent payload, Optional<SdxContext> flowContext, Exception ex) {
return null;
}
};
}
use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.
the class SdxDeleteActions method failedAction.
@Bean(name = "SDX_DELETION_FAILED_STATE")
public Action<?, ?> failedAction() {
return new AbstractSdxAction<>(SdxDeletionFailedEvent.class) {
@Override
protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, SdxDeletionFailedEvent payload) {
return SdxContext.from(flowParameters, payload);
}
@Override
protected void doExecute(SdxContext context, SdxDeletionFailedEvent payload, Map<Object, Object> variables) throws Exception {
Exception exception = payload.getException();
String statusReason = "Datalake deletion failed";
String errorMessage = webApplicationExceptionMessageExtractor.getErrorMessage(exception);
if (StringUtils.hasText(errorMessage)) {
statusReason = statusReason + ". " + errorMessage;
} else if (exception.getMessage() != null) {
statusReason = statusReason + ". " + exception.getMessage();
}
LOGGER.error(statusReason, exception);
try {
SdxCluster sdxCluster = sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.DELETE_FAILED, statusReason, payload.getResourceId());
metricService.incrementMetricCounter(MetricType.SDX_DELETION_FAILED, sdxCluster);
if (sdxCluster.isDetached()) {
eventSenderService.sendEventAndNotification(sdxCluster, context.getFlowTriggerUserCrn(), ResourceEvent.SDX_DETACHED_CLUSTER_DELETION_FAILED, List.of(sdxCluster.getClusterName()));
} else {
eventSenderService.notifyEvent(context, ResourceEvent.SDX_CLUSTER_DELETION_FAILED);
}
} catch (NotFoundException notFoundException) {
LOGGER.info("Can not set status to SDX_DELETION_FAILED because data lake was not found");
}
sendEvent(context, SDX_DELETE_FAILED_HANDLED_EVENT.event(), payload);
}
@Override
protected Object getFailurePayload(SdxDeletionFailedEvent payload, Optional<SdxContext> flowContext, Exception ex) {
return null;
}
};
}
use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.
the class SdxDiagnosticsActions method startDiagnosticsCollection.
@Bean(name = "DIAGNOSTICS_COLLECTION_START_STATE")
public Action<?, ?> startDiagnosticsCollection() {
return new AbstractSdxAction<>(SdxDiagnosticsCollectionEvent.class) {
@Override
protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, SdxDiagnosticsCollectionEvent payload) {
return SdxContext.from(flowParameters, payload);
}
@Override
protected void doExecute(SdxContext context, SdxDiagnosticsCollectionEvent payload, Map<Object, Object> variables) {
LOGGER.debug("Start diagnostics collection for sdx cluster with id: {}", context.getSdxId());
payload.getProperties().put(DIAGNOSTICS_UUID_PARAM, context.getFlowId());
FlowIdentifier flowIdentifier = diagnosticsFlowService.startDiagnosticsCollection(payload.getProperties());
SdxDiagnosticsCollectionEvent event = new SdxDiagnosticsCollectionEvent(payload.getResourceId(), payload.getUserId(), payload.getProperties(), flowIdentifier);
sendEvent(context, SDX_DIAGNOSTICS_COLLECTION_IN_PROGRESS_EVENT.event(), event);
}
@Override
protected Object getFailurePayload(SdxDiagnosticsCollectionEvent payload, Optional<SdxContext> flowContext, Exception ex) {
return SdxDiagnosticsFailedEvent.from(payload, ex);
}
};
}
use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.
the class DatalakeUpgradeActions method imageChange.
@Bean(name = "DATALAKE_IMAGE_CHANGE_STATE")
public Action<?, ?> imageChange() {
return new AbstractSdxAction<>(DatalakeImageChangeEvent.class) {
@Override
protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, DatalakeImageChangeEvent payload) {
return SdxContext.from(flowParameters, payload);
}
@Override
protected void doExecute(SdxContext context, DatalakeImageChangeEvent payload, Map<Object, Object> variables) {
LOGGER.info("Start Datalake upgrade image change for {} ", payload.getResourceId());
sdxUpgradeService.updateRuntimeVersionFromCloudbreak(payload.getResourceId());
String catalogName = sdxUpgradeService.getCurrentImageCatalogName(payload.getResourceId());
UpgradeOptionV4Response upgrade = new UpgradeOptionV4Response().upgrade(new ImageInfoV4Response().imageId(payload.getImageId()).imageCatalogName(catalogName));
sdxUpgradeService.changeImage(payload.getResourceId(), upgrade);
sendEvent(context, new DatalakeChangeImageWaitRequest(DATALAKE_IMAGE_CHANGE_IN_PROGRESS_EVENT.event(), context.getSdxId(), context.getUserId(), upgrade));
}
@Override
protected Object getFailurePayload(DatalakeImageChangeEvent payload, Optional<SdxContext> flowContext, Exception ex) {
return DatalakeUpgradeFailedEvent.from(payload, ex);
}
};
}
Aggregations