Search in sources :

Example 16 with PollerStoppedException

use of com.dyngr.exception.PollerStoppedException in project cloudbreak by hortonworks.

the class SdxStopWaitHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<SdxStopWaitRequest> event) {
    SdxStopWaitRequest waitRequest = event.getData();
    Long sdxId = waitRequest.getResourceId();
    String userId = waitRequest.getUserId();
    Selectable response;
    try {
        LOGGER.debug("Stop polling stack stopping process for id: {}", sdxId);
        PollingConfig pollingConfig = new PollingConfig(sleepTimeInSec, TimeUnit.SECONDS, durationInMinutes, TimeUnit.MINUTES);
        sdxStopService.waitCloudbreakCluster(sdxId, pollingConfig);
        response = new SdxStopSuccessEvent(sdxId, userId);
    } catch (UserBreakException userBreakException) {
        LOGGER.error("Stop polling exited before timeout. Cause: ", userBreakException);
        response = new SdxStopFailedEvent(sdxId, userId, userBreakException);
    } catch (PollerStoppedException pollerStoppedException) {
        LOGGER.error("Stop poller stopped for stack: {}", sdxId);
        response = new SdxStopFailedEvent(sdxId, userId, new PollerStoppedException("Datalake stop timed out after " + durationInMinutes + " minutes"));
    } catch (PollerException exception) {
        LOGGER.error("Stop polling failed for stack: {}", sdxId);
        response = new SdxStopFailedEvent(sdxId, userId, exception);
    }
    return response;
}
Also used : SdxStopWaitRequest(com.sequenceiq.datalake.flow.stop.event.SdxStopWaitRequest) UserBreakException(com.dyngr.exception.UserBreakException) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) PollerException(com.dyngr.exception.PollerException) SdxStopFailedEvent(com.sequenceiq.datalake.flow.stop.event.SdxStopFailedEvent) PollingConfig(com.sequenceiq.datalake.service.sdx.PollingConfig) SdxStopSuccessEvent(com.sequenceiq.datalake.flow.stop.event.SdxStopSuccessEvent) PollerStoppedException(com.dyngr.exception.PollerStoppedException)

Example 17 with PollerStoppedException

use of com.dyngr.exception.PollerStoppedException in project cloudbreak by hortonworks.

the class ProvisionerServiceTest method waitCloudbreakClusterCreationFailedByTimeout.

@Test
void waitCloudbreakClusterCreationFailedByTimeout() {
    long clusterId = CLUSTER_ID.incrementAndGet();
    SdxCluster sdxCluster = new SdxCluster();
    sdxCluster.setId(clusterId);
    sdxCluster.setClusterShape(SdxClusterShape.MEDIUM_DUTY_HA);
    sdxCluster.setEnvName("envir");
    sdxCluster.setInitiatorUserCrn(USER_CRN);
    sdxCluster.setAccountId("hortonworks");
    sdxCluster.setTags(Json.silent(new HashMap<>()));
    when(sdxService.getById(clusterId)).thenReturn(sdxCluster);
    PollingConfig pollingConfig = new PollingConfig(10, TimeUnit.MILLISECONDS, 100, TimeUnit.MILLISECONDS);
    doThrow(new PollerStoppedException("Stopped.")).when(cloudbreakPoller).pollCreateUntilAvailable(sdxCluster, pollingConfig);
    Assertions.assertThrows(PollerStoppedException.class, () -> underTest.waitCloudbreakClusterCreation(clusterId, pollingConfig));
    verify(sdxStatusService, times(1)).setStatusForDatalakeAndNotify(DatalakeStatusEnum.STACK_CREATION_IN_PROGRESS, "Datalake stack creation in progress", sdxCluster);
}
Also used : HashMap(java.util.HashMap) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) PollerStoppedException(com.dyngr.exception.PollerStoppedException) Test(org.junit.jupiter.api.Test)

Example 18 with PollerStoppedException

use of com.dyngr.exception.PollerStoppedException in project cloudbreak by hortonworks.

the class SdxCertRenewWaitHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<SdxCertRenewalWaitEvent> event) {
    SdxEvent sdxEvent = event.getData();
    Long sdxId = sdxEvent.getResourceId();
    String userId = sdxEvent.getUserId();
    Selectable response;
    try {
        LOGGER.debug("Start polling stack cert renewal process.");
        PollingConfig pollingConfig = new PollingConfig(sleepTimeInSec, TimeUnit.SECONDS, durationInMinutes, TimeUnit.MINUTES);
        certRenewalService.waitForCloudbreakClusterCertRenewal(sdxId, pollingConfig);
        response = new SdxEvent(SdxCertRenewalEvent.CERT_RENEWAL_FINISHED_EVENT.event(), sdxId, userId);
    } catch (UserBreakException userBreakException) {
        LOGGER.error("Cert renewal polling exited before timeout. Cause: ", userBreakException);
        response = new SdxCertRenewalFailedEvent(sdxId, userId, userBreakException.getMessage());
    } catch (PollerStoppedException pollerStoppedException) {
        LOGGER.error("Cert renewal poller stopped.");
        response = new SdxCertRenewalFailedEvent(sdxId, userId, "Datalake cert renewal timed out after " + durationInMinutes + " minutes");
    } catch (PollerException exception) {
        LOGGER.error("Cert renewal polling failed. Cause: ", exception);
        response = new SdxCertRenewalFailedEvent(sdxId, userId, exception.getMessage());
    }
    return response;
}
Also used : UserBreakException(com.dyngr.exception.UserBreakException) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) PollerException(com.dyngr.exception.PollerException) SdxEvent(com.sequenceiq.datalake.flow.SdxEvent) SdxCertRenewalFailedEvent(com.sequenceiq.datalake.flow.cert.renew.event.SdxCertRenewalFailedEvent) PollingConfig(com.sequenceiq.datalake.service.sdx.PollingConfig) PollerStoppedException(com.dyngr.exception.PollerStoppedException)

Example 19 with PollerStoppedException

use of com.dyngr.exception.PollerStoppedException in project cloudbreak by hortonworks.

the class CreateExternalDatabaseHandler method accept.

@Override
public void accept(Event<CreateExternalDatabaseRequest> createExternalDatabaseRequest) {
    LOGGER.debug("In CreateExternalDatabaseHandler.accept");
    CreateExternalDatabaseRequest request = createExternalDatabaseRequest.getData();
    Stack stack = stackService.getById(request.getResourceId());
    DatabaseAvailabilityType externalDatabase = ObjectUtils.defaultIfNull(stack.getExternalDatabaseCreationType(), DatabaseAvailabilityType.NONE);
    LOGGER.debug("External database: {} for stack {}", externalDatabase.name(), stack.getName());
    Selectable result;
    try {
        String resourceCrn = null;
        if (externalDatabase.isEmbedded()) {
            LOGGER.info("External database for stack {} is not requested.", stack.getName());
        } else {
            LOGGER.debug("Updating stack {} status from {} to {}", stack.getName(), stack.getStatus().name(), DetailedStackStatus.EXTERNAL_DATABASE_CREATION_IN_PROGRESS.name());
            stackUpdaterService.updateStatus(stack.getId(), DetailedStackStatus.EXTERNAL_DATABASE_CREATION_IN_PROGRESS, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_CREATION_STARTED, "External database creation in progress");
            LOGGER.debug("Getting environment CRN for stack {}", stack.getName());
            DetailedEnvironmentResponse environment = environmentClientService.getByCrn(stack.getEnvironmentCrn());
            environmentValidator.checkValidEnvironment(stack.getName(), externalDatabase, environment);
            provisionService.provisionDatabase(stack.getCluster(), externalDatabase, environment);
            LOGGER.debug("Updating stack {} status from {} to {}", stack.getName(), stack.getStatus().name(), DetailedStackStatus.PROVISION_REQUESTED.name());
            stackUpdaterService.updateStatus(stack.getId(), DetailedStackStatus.PROVISION_REQUESTED, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_CREATION_FINISHED, "External database creation finished");
            resourceCrn = stack.getCluster().getDatabaseServerCrn();
        }
        result = new CreateExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_WAIT_SUCCESS_EVENT.event(), stack.getName(), resourceCrn);
    } catch (UserBreakException e) {
        LOGGER.info("Database polling exited before timeout. Cause: ", e);
        result = createFailedEvent(stack, e);
    } catch (PollerStoppedException e) {
        LOGGER.info(String.format("Database poller stopped for stack: %s", stack.getName()), e);
        result = createFailedEvent(stack, e);
    } catch (PollerException e) {
        LOGGER.info(String.format("Database polling failed for stack: %s", stack.getName()), e);
        result = createFailedEvent(stack, e);
    } catch (Exception e) {
        LOGGER.error(String.format("Exception during DB creation for stack/cluster: %s", stack.getName()), e);
        result = createFailedEvent(stack, e);
    }
    LOGGER.debug("Sending reactor notification for selector {}", result.selector());
    eventBus.notify(result.selector(), new Event<>(createExternalDatabaseRequest.getHeaders(), result));
}
Also used : UserBreakException(com.dyngr.exception.UserBreakException) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) CreateExternalDatabaseRequest(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.CreateExternalDatabaseRequest) PollerException(com.dyngr.exception.PollerException) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) CreateExternalDatabaseResult(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.CreateExternalDatabaseResult) PollerStoppedException(com.dyngr.exception.PollerStoppedException) UserBreakException(com.dyngr.exception.UserBreakException) PollerException(com.dyngr.exception.PollerException) PollerStoppedException(com.dyngr.exception.PollerStoppedException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) DatabaseAvailabilityType(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.database.DatabaseAvailabilityType)

Example 20 with PollerStoppedException

use of com.dyngr.exception.PollerStoppedException in project cloudbreak by hortonworks.

the class TerminateExternalDatabaseHandler method accept.

@Override
public void accept(Event<TerminateExternalDatabaseRequest> terminateExternalDatabaseRequest) {
    LOGGER.debug("In TerminateExternalDatabaseHandler.accept");
    TerminateExternalDatabaseRequest request = terminateExternalDatabaseRequest.getData();
    Stack stack = stackService.getById(request.getResourceId());
    DatabaseAvailabilityType externalDatabase = ObjectUtils.defaultIfNull(stack.getExternalDatabaseCreationType(), DatabaseAvailabilityType.NONE);
    LOGGER.debug("External database: {} for stack {}", externalDatabase.name(), stack.getName());
    Selectable result;
    try {
        if (externalDatabase.isEmbedded()) {
            LOGGER.info("External database for stack {} is not requested. Termination is not necessary.", stack.getName());
            result = new TerminateExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_WAIT_TERMINATION_SUCCESS_EVENT.event(), stack.getName(), null);
        } else {
            LOGGER.debug("Updating stack {} status from {} to {}", stack.getName(), stack.getStatus().name(), DetailedStackStatus.EXTERNAL_DATABASE_DELETION_IN_PROGRESS.name());
            stackUpdaterService.updateStatus(stack.getId(), DetailedStackStatus.EXTERNAL_DATABASE_DELETION_IN_PROGRESS, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_DELETION_STARTED, "External database deletion in progress");
            LOGGER.debug("Getting environment CRN for stack {}", stack.getName());
            DetailedEnvironmentResponse environment = environmentClientService.getByCrn(stack.getEnvironmentCrn());
            terminationService.terminateDatabase(stack.getCluster(), externalDatabase, environment, request.isForced());
            LOGGER.debug("Updating stack {} status from {} to {}", stack.getName(), stack.getStatus().name(), DetailedStackStatus.AVAILABLE.name());
            stackUpdaterService.updateStatus(stack.getId(), DetailedStackStatus.AVAILABLE, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_DELETION_FINISHED, "External database deletion finished");
            result = new TerminateExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_WAIT_TERMINATION_SUCCESS_EVENT.event(), stack.getName(), stack.getCluster().getDatabaseServerCrn());
        }
    } catch (UserBreakException e) {
        LOGGER.info("Database termination polling exited before timeout. Cause: ", e);
        result = terminateFailedEvent(stack, e);
    } catch (PollerStoppedException e) {
        LOGGER.info(String.format("Database termination poller stopped for stack: %s", stack.getName()), e);
        result = terminateFailedEvent(stack, e);
    } catch (PollerException e) {
        LOGGER.info(String.format("Database termination polling failed for stack: %s", stack.getName()), e);
        result = terminateFailedEvent(stack, e);
    } catch (Exception e) {
        LOGGER.error(String.format("Exception during DB termination for stack/cluster: %s", stack.getName()), e);
        result = terminateFailedEvent(stack, e);
    }
    LOGGER.debug("Sending reactor notification for selector {}", result.selector());
    eventBus.notify(result.selector(), new Event<>(terminateExternalDatabaseRequest.getHeaders(), result));
}
Also used : UserBreakException(com.dyngr.exception.UserBreakException) TerminateExternalDatabaseResult(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.TerminateExternalDatabaseResult) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) PollerException(com.dyngr.exception.PollerException) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) PollerStoppedException(com.dyngr.exception.PollerStoppedException) UserBreakException(com.dyngr.exception.UserBreakException) PollerException(com.dyngr.exception.PollerException) PollerStoppedException(com.dyngr.exception.PollerStoppedException) TerminateExternalDatabaseRequest(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.TerminateExternalDatabaseRequest) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) DatabaseAvailabilityType(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.database.DatabaseAvailabilityType)

Aggregations

PollerStoppedException (com.dyngr.exception.PollerStoppedException)43 PollerException (com.dyngr.exception.PollerException)31 UserBreakException (com.dyngr.exception.UserBreakException)30 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)28 PollingConfig (com.sequenceiq.datalake.service.sdx.PollingConfig)21 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)7 Test (org.junit.jupiter.api.Test)7 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)5 SdxCreateFailedEvent (com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent)5 DatabaseAvailabilityType (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.database.DatabaseAvailabilityType)4 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)4 SdxEvent (com.sequenceiq.datalake.flow.SdxEvent)4 SdxStopFailedEvent (com.sequenceiq.datalake.flow.stop.event.SdxStopFailedEvent)4 DatalakeUpgradeFailedEvent (com.sequenceiq.datalake.flow.datalake.upgrade.event.DatalakeUpgradeFailedEvent)3 SdxDiagnosticsSuccessEvent (com.sequenceiq.datalake.flow.diagnostics.event.SdxDiagnosticsSuccessEvent)3 Event (reactor.bus.Event)3 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)2 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)2 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)2 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)2