Search in sources :

Example 1 with RdsWaitRequest

use of com.sequenceiq.datalake.flow.create.event.RdsWaitRequest in project cloudbreak by hortonworks.

the class RdsWaitHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<RdsWaitRequest> event) {
    RdsWaitRequest rdsWaitRequest = event.getData();
    Long sdxId = rdsWaitRequest.getResourceId();
    String userId = rdsWaitRequest.getUserId();
    try {
        DetailedEnvironmentResponse env = environmentService.waitNetworkAndGetEnvironment(sdxId);
        Optional<SdxCluster> sdxCluster = sdxClusterRepository.findById(sdxId);
        if (sdxCluster.isPresent()) {
            if (sdxCluster.get().hasExternalDatabase()) {
                validForDatabaseCreation(sdxId, env);
                LOGGER.debug("start polling database for sdx: {}", sdxId);
                databaseService.create(sdxCluster.get(), env);
                setRdsCreatedStatus(sdxCluster.get());
                return new RdsWaitSuccessEvent(sdxId, userId);
            } else {
                LOGGER.debug("skipping creation of database for sdx: {}", sdxId);
                return new RdsWaitSuccessEvent(sdxId, userId);
            }
        } else {
            throw notFound("SDX cluster", sdxId).get();
        }
    } catch (UserBreakException userBreakException) {
        LOGGER.error("Database polling exited before timeout. Cause: ", userBreakException);
        return new SdxCreateFailedEvent(sdxId, userId, userBreakException);
    } catch (PollerStoppedException pollerStoppedException) {
        LOGGER.error("Database poller stopped for sdx: {}", sdxId, pollerStoppedException);
        return new SdxCreateFailedEvent(sdxId, userId, new PollerStoppedException("Database creation timed out after " + durationInMinutes + " minutes"));
    } catch (PollerException exception) {
        LOGGER.error("Database polling failed for sdx: {}", sdxId, exception);
        return new SdxCreateFailedEvent(sdxId, userId, exception);
    } catch (Exception anotherException) {
        LOGGER.error("Something wrong happened in sdx database creation wait phase", anotherException);
        return new SdxCreateFailedEvent(sdxId, userId, anotherException);
    }
}
Also used : UserBreakException(com.dyngr.exception.UserBreakException) SdxCreateFailedEvent(com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent) RdsWaitSuccessEvent(com.sequenceiq.datalake.flow.create.event.RdsWaitSuccessEvent) PollerException(com.dyngr.exception.PollerException) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) RdsWaitRequest(com.sequenceiq.datalake.flow.create.event.RdsWaitRequest) PollerStoppedException(com.dyngr.exception.PollerStoppedException) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) UserBreakException(com.dyngr.exception.UserBreakException) PollerException(com.dyngr.exception.PollerException) PollerStoppedException(com.dyngr.exception.PollerStoppedException)

Example 2 with RdsWaitRequest

use of com.sequenceiq.datalake.flow.create.event.RdsWaitRequest in project cloudbreak by hortonworks.

the class SdxCreateActions method rdsCreation.

@Bean(name = "SDX_CREATION_WAIT_RDS_STATE")
public Action<?, ?> rdsCreation() {
    return new AbstractSdxAction<>(StorageValidationSuccessEvent.class) {

        @Override
        protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, StorageValidationSuccessEvent payload) {
            return SdxContext.from(flowParameters, payload);
        }

        @Override
        protected void doExecute(SdxContext context, StorageValidationSuccessEvent payload, Map<Object, Object> variables) throws Exception {
            RdsWaitRequest req = new RdsWaitRequest(context);
            sendEvent(context, req.selector(), req);
        }

        @Override
        protected Object getFailurePayload(StorageValidationSuccessEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return SdxCreateFailedEvent.from(payload, ex);
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) Optional(java.util.Optional) StorageValidationSuccessEvent(com.sequenceiq.datalake.flow.create.event.StorageValidationSuccessEvent) StateContext(org.springframework.statemachine.StateContext) Map(java.util.Map) RdsWaitRequest(com.sequenceiq.datalake.flow.create.event.RdsWaitRequest) DatalakeStatusUpdateException(com.sequenceiq.datalake.service.sdx.status.DatalakeStatusUpdateException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Aggregations

RdsWaitRequest (com.sequenceiq.datalake.flow.create.event.RdsWaitRequest)2 PollerException (com.dyngr.exception.PollerException)1 PollerStoppedException (com.dyngr.exception.PollerStoppedException)1 UserBreakException (com.dyngr.exception.UserBreakException)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)1 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)1 SdxContext (com.sequenceiq.datalake.flow.SdxContext)1 RdsWaitSuccessEvent (com.sequenceiq.datalake.flow.create.event.RdsWaitSuccessEvent)1 SdxCreateFailedEvent (com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent)1 StorageValidationSuccessEvent (com.sequenceiq.datalake.flow.create.event.StorageValidationSuccessEvent)1 AbstractSdxAction (com.sequenceiq.datalake.service.AbstractSdxAction)1 DatalakeStatusUpdateException (com.sequenceiq.datalake.service.sdx.status.DatalakeStatusUpdateException)1 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)1 FlowParameters (com.sequenceiq.flow.core.FlowParameters)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Bean (org.springframework.context.annotation.Bean)1 StateContext (org.springframework.statemachine.StateContext)1