Search in sources :

Example 1 with RdsDeletionWaitRequest

use of com.sequenceiq.datalake.flow.delete.event.RdsDeletionWaitRequest in project cloudbreak by hortonworks.

the class RdsDeletionHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<RdsDeletionWaitRequest> event) {
    RdsDeletionWaitRequest rdsWaitRequest = event.getData();
    Long sdxId = rdsWaitRequest.getResourceId();
    String userId = rdsWaitRequest.getUserId();
    Selectable response;
    try {
        sdxClusterRepository.findById(sdxId).ifPresent(sdxCluster -> {
            if (sdxCluster.hasExternalDatabase() && StringUtils.isNotEmpty(sdxCluster.getDatabaseCrn())) {
                LOGGER.debug("start polling database termination for sdx: {}", sdxId);
                databaseService.terminate(sdxCluster, rdsWaitRequest.isForced());
            } else {
                LOGGER.debug("skipping deletion of database for sdx: {}", sdxId);
            }
            setDeletedStatus(sdxCluster);
        });
        response = new RdsDeletionSuccessEvent(sdxId, userId);
    } catch (UserBreakException userBreakException) {
        LOGGER.error("Database polling exited before timeout. Cause: ", userBreakException);
        response = new SdxDeletionFailedEvent(sdxId, userId, userBreakException, rdsWaitRequest.isForced());
    } catch (PollerStoppedException pollerStoppedException) {
        LOGGER.error("Database poller stopped for sdx: {}", sdxId, pollerStoppedException);
        response = new SdxDeletionFailedEvent(sdxId, userId, new PollerStoppedException("Database deletion timed out after " + durationInMinutes + " minutes"), rdsWaitRequest.isForced());
    } catch (PollerException exception) {
        LOGGER.error("Database polling failed for sdx: {}", sdxId, exception);
        response = new SdxDeletionFailedEvent(sdxId, userId, exception, rdsWaitRequest.isForced());
    } catch (Exception anotherException) {
        LOGGER.error("Something wrong happened in sdx database deletion wait phase", anotherException);
        response = new SdxDeletionFailedEvent(sdxId, userId, anotherException, rdsWaitRequest.isForced());
    }
    return response;
}
Also used : UserBreakException(com.dyngr.exception.UserBreakException) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) PollerException(com.dyngr.exception.PollerException) SdxDeletionFailedEvent(com.sequenceiq.datalake.flow.delete.event.SdxDeletionFailedEvent) RdsDeletionSuccessEvent(com.sequenceiq.datalake.flow.delete.event.RdsDeletionSuccessEvent) RdsDeletionWaitRequest(com.sequenceiq.datalake.flow.delete.event.RdsDeletionWaitRequest) PollerStoppedException(com.dyngr.exception.PollerStoppedException) UserBreakException(com.dyngr.exception.UserBreakException) PollerException(com.dyngr.exception.PollerException) PollerStoppedException(com.dyngr.exception.PollerStoppedException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException)

Aggregations

PollerException (com.dyngr.exception.PollerException)1 PollerStoppedException (com.dyngr.exception.PollerStoppedException)1 UserBreakException (com.dyngr.exception.UserBreakException)1 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)1 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)1 RdsDeletionSuccessEvent (com.sequenceiq.datalake.flow.delete.event.RdsDeletionSuccessEvent)1 RdsDeletionWaitRequest (com.sequenceiq.datalake.flow.delete.event.RdsDeletionWaitRequest)1 SdxDeletionFailedEvent (com.sequenceiq.datalake.flow.delete.event.SdxDeletionFailedEvent)1