use of com.sequenceiq.flow.core.CommonContext in project cloudbreak by hortonworks.
the class EnvStartActions method startDatahub.
@Bean(name = "START_DATAHUB_STATE")
public Action<?, ?> startDatahub() {
return new AbstractEnvStartAction<>(EnvStartEvent.class) {
@Override
protected void doExecute(CommonContext context, EnvStartEvent payload, Map<Object, Object> variables) {
EnvironmentStatus environmentStatus = EnvironmentStatus.START_DATAHUB_STARTED;
ResourceEvent resourceEvent = ResourceEvent.ENVIRONMENT_START_DATAHUB_STARTED;
EnvStartState envStartState = EnvStartState.START_DATAHUB_STATE;
EnvironmentDto envDto = environmentStatusUpdateService.updateEnvironmentStatusAndNotify(context, payload, environmentStatus, resourceEvent, envStartState);
EnvironmentStartDto environmentStartDto = EnvironmentStartDto.builder().withDataHubStart(payload.getDataHubStartAction()).withEnvironmentDto(envDto).withId(envDto.getId()).build();
sendEvent(context, EnvStartHandlerSelectors.START_DATAHUB_HANDLER_EVENT.selector(), environmentStartDto);
}
};
}
use of com.sequenceiq.flow.core.CommonContext in project cloudbreak by hortonworks.
the class EnvStopActions method stopFreeipa.
@Bean(name = "STOP_FREEIPA_STATE")
public Action<?, ?> stopFreeipa() {
return new AbstractEnvStopAction<>(EnvStopEvent.class) {
@Override
protected void doExecute(CommonContext context, EnvStopEvent payload, Map<Object, Object> variables) {
EnvironmentStatus environmentStatus = EnvironmentStatus.STOP_FREEIPA_STARTED;
ResourceEvent resourceEvent = ResourceEvent.ENVIRONMENT_STOP_FREEIPA_STARTED;
EnvStopState envStopState = EnvStopState.STOP_FREEIPA_STATE;
EnvironmentDto envDto = environmentStatusUpdateService.updateEnvironmentStatusAndNotify(context, payload, environmentStatus, resourceEvent, envStopState);
sendEvent(context, EnvStopHandlerSelectors.STOP_FREEIPA_HANDLER_EVENT.selector(), envDto);
}
};
}
use of com.sequenceiq.flow.core.CommonContext in project cloudbreak by hortonworks.
the class EnvStopActions method failedAction.
@Bean(name = "ENV_STOP_FAILED_STATE")
public Action<?, ?> failedAction() {
return new AbstractEnvStopAction<>(EnvStopFailedEvent.class) {
@Override
protected void doExecute(CommonContext context, EnvStopFailedEvent payload, Map<Object, Object> variables) {
LOGGER.warn(String.format("Failed to stop environment '%s'. Status: '%s'.", payload.getEnvironmentDto(), payload.getEnvironmentStatus()), payload.getException());
EnvironmentDto environmentDto = environmentStatusUpdateService.updateFailedEnvironmentStatusAndNotify(context, payload, payload.getEnvironmentStatus(), convertStatus(payload.getEnvironmentStatus()), EnvStopState.ENV_STOP_FAILED_STATE);
metricService.incrementMetricCounter(MetricType.ENV_STOP_FAILED, environmentDto, payload.getException());
sendEvent(context, HANDLED_FAILED_ENV_STOP_EVENT.event(), payload);
}
};
}
use of com.sequenceiq.flow.core.CommonContext in project cloudbreak by hortonworks.
the class EnvStopActions method stopDatahub.
@Bean(name = "STOP_DATAHUB_STATE")
public Action<?, ?> stopDatahub() {
return new AbstractEnvStopAction<>(EnvStopEvent.class) {
@Override
protected void doExecute(CommonContext context, EnvStopEvent payload, Map<Object, Object> variables) {
EnvironmentStatus environmentStatus = EnvironmentStatus.STOP_DATAHUB_STARTED;
ResourceEvent resourceEvent = ResourceEvent.ENVIRONMENT_STOP_DATAHUB_STARTED;
EnvStopState envStopState = EnvStopState.STOP_DATAHUB_STATE;
EnvironmentDto envDto = environmentStatusUpdateService.updateEnvironmentStatusAndNotify(context, payload, environmentStatus, resourceEvent, envStopState);
sendEvent(context, EnvStopHandlerSelectors.STOP_DATAHUB_HANDLER_EVENT.selector(), envDto);
}
};
}
use of com.sequenceiq.flow.core.CommonContext in project cloudbreak by hortonworks.
the class EnvClustersDeleteActions method failedAction.
@Bean(name = "ENV_CLUSTERS_DELETE_FAILED_STATE")
public Action<?, ?> failedAction() {
return new AbstractEnvClustersDeleteAction<>(EnvClusterDeleteFailedEvent.class) {
@Override
protected void doExecute(CommonContext context, EnvClusterDeleteFailedEvent payload, Map<Object, Object> variables) {
LOGGER.warn("Failed to delete environment", payload.getException());
Exception e = payload.getException();
environmentService.findEnvironmentById(payload.getResourceId()).ifPresentOrElse(environment -> {
environment.setStatusReason(payload.getMessage() == null ? e.getMessage() : payload.getMessage());
environment.setStatus(EnvironmentStatus.DELETE_FAILED);
Environment result = environmentService.save(environment);
EnvironmentDto environmentDto = environmentService.getEnvironmentDto(result);
metricService.incrementMetricCounter(MetricType.ENV_CLUSTERS_DELETION_FAILED, environmentDto, payload.getException());
eventService.sendEventAndNotification(environmentDto, context.getFlowTriggerUserCrn(), ResourceEvent.ENVIRONMENT_DELETION_FAILED);
}, () -> LOGGER.error("Cannot set delete failed to env because the environment does not exist: {}. " + "But the flow will continue, how can this happen?", payload.getResourceId()));
LOGGER.info("Flow entered into ENV_CLUSTERS_DELETE_FAILED_STATE");
sendEvent(context, HANDLED_FAILED_ENV_CLUSTERS_DELETE_EVENT.event(), payload);
}
@Override
protected CommonContext createFlowContext(FlowParameters flowParameters, StateContext<EnvClustersDeleteState, EnvClustersDeleteStateSelectors> stateContext, EnvClusterDeleteFailedEvent payload) {
Flow flow = getFlow(flowParameters.getFlowId());
flow.setFlowFailed(payload.getException());
return new CommonContext(flowParameters);
}
};
}
Aggregations