use of com.dyngr.exception.PollerStoppedException in project cloudbreak by hortonworks.
the class StopExternalDatabaseHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<StopExternalDatabaseRequest> event) {
LOGGER.debug("In StopExternalDatabaseHandler.doAccept");
StopExternalDatabaseRequest request = event.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());
LOGGER.debug("Getting environment CRN for stack {}", stack.getName());
DetailedEnvironmentResponse environment = environmentClientService.getByCrn(stack.getEnvironmentCrn());
Selectable result;
try {
if (StackType.WORKLOAD != stack.getType()) {
LOGGER.debug("External database stop in Cloudbreak service is required for WORKLOAD stacks only.");
result = new StopExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STOPPED_EVENT.event(), stack.getName(), null);
} else if (externalDatabase.isEmbedded()) {
LOGGER.info("External database for stack {} is not requested. Stop is not possible.", stack.getName());
result = new StopExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STOPPED_EVENT.event(), stack.getName(), null);
} else if (!externalDatabaseConfig.isExternalDatabasePauseSupportedFor(CloudPlatform.valueOf(environment.getCloudPlatform()))) {
LOGGER.debug("External database pause is not supported for '{}' cloud platform.", environment.getCloudPlatform());
result = new StopExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STOPPED_EVENT.event(), stack.getName(), null);
} else {
LOGGER.debug("Updating stack {} status from {} to {}", stack.getName(), stack.getStatus().name(), DetailedStackStatus.EXTERNAL_DATABASE_STOP_IN_PROGRESS.name());
stackUpdaterService.updateStatus(stack.getId(), DetailedStackStatus.EXTERNAL_DATABASE_STOP_IN_PROGRESS, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_STOP_COMMANCED, "External database stop in progress");
stopService.stopDatabase(stack.getCluster(), externalDatabase, environment);
LOGGER.debug("Updating stack {} status from {} to {}", stack.getName(), stack.getStatus().name(), DetailedStackStatus.EXTERNAL_DATABASE_STOP_FINISHED.name());
stackUpdaterService.updateStatus(stack.getId(), DetailedStackStatus.EXTERNAL_DATABASE_STOP_FINISHED, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_STOP_FINISHED, "External database stop finished");
result = new StopExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STOPPED_EVENT.event(), stack.getName(), stack.getCluster().getDatabaseServerCrn());
}
} catch (UserBreakException e) {
LOGGER.error("Database 'stop' polling exited before timeout. Cause: ", e);
result = stopFailedEvent(stack, e);
} catch (PollerStoppedException e) {
LOGGER.error(String.format("Database 'stop' poller stopped for stack: %s", stack.getName()), e);
result = stopFailedEvent(stack, e);
} catch (PollerException e) {
LOGGER.error(String.format("Database 'stop' polling failed for stack: %s", stack.getName()), e);
result = stopFailedEvent(stack, e);
}
return result;
}
use of com.dyngr.exception.PollerStoppedException in project cloudbreak by hortonworks.
the class SdxValidationHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<SdxValidationRequest> event) {
SdxValidationRequest request = event.getData();
Long sdxId = request.getResourceId();
String userId = request.getUserId();
try {
DetailedEnvironmentResponse environment = environmentService.waitNetworkAndGetEnvironment(sdxId);
Optional<SdxCluster> sdxCluster = sdxClusterRepository.findById(sdxId);
if (sdxCluster.isPresent()) {
sdxRecommendationService.validateVmTypeOverride(environment, sdxCluster.get());
return new SdxValidationSuccessEvent(sdxId, userId);
} else {
throw notFound("SDX cluster", sdxId).get();
}
} catch (UserBreakException userBreakException) {
LOGGER.error("Env polling exited before timeout. Cause: ", userBreakException);
return new SdxCreateFailedEvent(sdxId, userId, userBreakException);
} catch (PollerStoppedException pollerStoppedException) {
LOGGER.error("Env poller stopped for sdx: {}", sdxId, pollerStoppedException);
return new SdxCreateFailedEvent(sdxId, userId, new PollerStoppedException("Env wait timed out after " + durationInMinutes + " minutes in sdx validation phase"));
} catch (PollerException exception) {
LOGGER.error("Env polling failed for sdx: {}", sdxId, exception);
return new SdxCreateFailedEvent(sdxId, userId, exception);
} catch (Exception e) {
LOGGER.error("Sdx validation failed", e);
return new SdxCreateFailedEvent(sdxId, userId, e);
}
}
use of com.dyngr.exception.PollerStoppedException in project cloudbreak by hortonworks.
the class StackCreationHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<StackCreationWaitRequest> handlerEvent) {
StackCreationWaitRequest stackCreationWaitRequest = handlerEvent.getData();
Long sdxId = stackCreationWaitRequest.getResourceId();
String userId = stackCreationWaitRequest.getUserId();
Selectable response;
try {
LOGGER.debug("start polling stack creation process for id: {}", sdxId);
PollingConfig pollingConfig = new PollingConfig(sleepTimeInSec, TimeUnit.SECONDS, durationInMinutes, TimeUnit.MINUTES);
StackV4Response stackV4Response = provisionerService.waitCloudbreakClusterCreation(sdxId, pollingConfig);
SdxCluster sdxCluster = sdxService.getById(sdxId);
sdxService.updateRuntimeVersionFromStackResponse(sdxCluster, stackV4Response);
setStackCreatedStatus(sdxId);
response = new StackCreationSuccessEvent(sdxId, userId);
} catch (UserBreakException userBreakException) {
LOGGER.error("Polling exited before timeout for SDX: {}. Cause: ", sdxId, userBreakException);
response = new SdxCreateFailedEvent(sdxId, userId, userBreakException);
} catch (PollerStoppedException pollerStoppedException) {
LOGGER.error("Poller stopped for SDX: {}", sdxId, pollerStoppedException);
response = new SdxCreateFailedEvent(sdxId, userId, new PollerStoppedException("Datalake stack creation timed out after " + durationInMinutes + " minutes"));
} catch (PollerException exception) {
LOGGER.error("Polling failed for stack: {}", sdxId, exception);
response = new SdxCreateFailedEvent(sdxId, userId, exception);
} catch (Exception anotherException) {
LOGGER.error("Something wrong happened in stack creation wait phase", anotherException);
response = new SdxCreateFailedEvent(sdxId, userId, anotherException);
}
return response;
}
use of com.dyngr.exception.PollerStoppedException in project cloudbreak by hortonworks.
the class SdxCertRotationWaitHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<SdxCertRotationWaitEvent> event) {
SdxEvent sdxEvent = event.getData();
Long sdxId = sdxEvent.getResourceId();
String userId = sdxEvent.getUserId();
Selectable response;
try {
LOGGER.debug("Start polling stack cert rotation process for id: {}", sdxId);
PollingConfig pollingConfig = new PollingConfig(sleepTimeInSec, TimeUnit.SECONDS, durationInMinutes, TimeUnit.MINUTES);
certRotationService.waitForCloudbreakClusterCertRotation(sdxId, pollingConfig);
response = new SdxEvent(SdxCertRotationEvent.CERT_ROTATION_FINISHED_EVENT.event(), sdxId, userId);
} catch (UserBreakException userBreakException) {
LOGGER.error("Cert rotation polling exited before timeout. Cause: ", userBreakException);
response = new SdxCertRotationFailedEvent(sdxId, userId, userBreakException);
} catch (PollerStoppedException pollerStoppedException) {
LOGGER.error("Cert rotation poller stopped for stack: {}", sdxId);
response = new SdxCertRotationFailedEvent(sdxId, userId, new PollerStoppedException("Datalake cert rotation timed out after " + durationInMinutes + " minutes"));
} catch (PollerException exception) {
LOGGER.error("Cert rotation polling failed for stack: {}", sdxId);
response = new SdxCertRotationFailedEvent(sdxId, userId, exception);
}
return response;
}
use of com.dyngr.exception.PollerStoppedException in project cloudbreak by hortonworks.
the class CertRenewalServiceTest method testCertRenewalPollingWhenExceptionThrown.
@Test
public void testCertRenewalPollingWhenExceptionThrown() {
when(sdxService.getById(anyLong())).thenReturn(sdxCluster);
doThrow(new PollerStoppedException("Timeout")).when(cloudbreakPoller).pollUpdateUntilAvailable(anyString(), any(), any());
assertThrows(PollerStoppedException.class, () -> underTest.waitForCloudbreakClusterCertRenewal(1L, pollingConfig));
verify(sdxService).getById(1L);
verify(cloudbreakPoller).pollUpdateUntilAvailable("Certificate renewal", sdxCluster, pollingConfig);
verifyNoInteractions(sdxStatusService);
}
Aggregations