use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.STOPPED in project cloudbreak by hortonworks.
the class StartExternalDatabaseHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<StartExternalDatabaseRequest> event) {
LOGGER.debug("In StartExternalDatabaseHandler.doAccept");
StartExternalDatabaseRequest 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 start in Cloudbreak service is required for WORKLOAD stacks only.");
result = new StartExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STARTED_EVENT.event(), stack.getName(), null);
} else if (externalDatabase.isEmbedded()) {
LOGGER.info("External database for stack {} is not requested. Start is not possible.", stack.getName());
result = new StartExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STARTED_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 StartExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STARTED_EVENT.event(), stack.getName(), null);
} else {
LOGGER.debug("Updating stack {} status from {} to {}", stack.getName(), stack.getStatus().name(), DetailedStackStatus.EXTERNAL_DATABASE_START_IN_PROGRESS.name());
stackUpdaterService.updateStatus(stack.getId(), DetailedStackStatus.EXTERNAL_DATABASE_START_IN_PROGRESS, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_START_COMMANCED, "External database start in progress");
startService.startDatabase(stack.getCluster(), externalDatabase, environment);
LOGGER.debug("Updating stack {} status from {} to {}", stack.getName(), stack.getStatus().name(), DetailedStackStatus.EXTERNAL_DATABASE_START_FINISHED.name());
stackUpdaterService.updateStatus(stack.getId(), DetailedStackStatus.EXTERNAL_DATABASE_START_FINISHED, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_START_FINISHED, "External database start finished");
result = new StartExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STARTED_EVENT.event(), stack.getName(), stack.getCluster().getDatabaseServerCrn());
}
} catch (UserBreakException e) {
LOGGER.error("Database 'start' polling exited before timeout. Cause: ", e);
result = startFailedEvent(stack, e);
} catch (PollerStoppedException e) {
LOGGER.error(String.format("Database 'start' poller stopped for stack: %s", stack.getName()), e);
result = startFailedEvent(stack, e);
} catch (PollerException e) {
LOGGER.error(String.format("Database 'start' polling failed for stack: %s", stack.getName()), e);
result = startFailedEvent(stack, e);
}
return result;
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.STOPPED in project cloudbreak by hortonworks.
the class ClusterUpgradeAvailabilityService method checkForUpgradesByName.
public UpgradeV4Response checkForUpgradesByName(Stack stack, boolean lockComponents, boolean replaceVms, InternalUpgradeSettings internalUpgradeSettings) {
UpgradeV4Response upgradeOptions = checkForUpgrades(stack, lockComponents, internalUpgradeSettings);
upgradeOptions.setReplaceVms(replaceVms);
if (StringUtils.isEmpty(upgradeOptions.getReason())) {
if (!stack.getStatus().isAvailable()) {
upgradeOptions.setReason(String.format("Cannot upgrade cluster because it is in %s state.", stack.getStatus()));
LOGGER.warn(upgradeOptions.getReason());
} else if (instanceMetaDataService.anyInstanceStopped(stack.getId())) {
upgradeOptions.setReason("Cannot upgrade cluster because there is stopped instance.");
LOGGER.warn(upgradeOptions.getReason());
} else if (shouldValidateForRepair(lockComponents, replaceVms)) {
LOGGER.debug("Validate for repair");
Result<Map<HostGroupName, Set<InstanceMetaData>>, RepairValidation> validationResult = clusterRepairService.repairWithDryRun(stack.getId());
if (validationResult.isError()) {
upgradeOptions.setReason(String.join(",", validationResult.getError().getValidationErrors()));
LOGGER.warn(String.format("Cannot upgrade cluster because: %s", upgradeOptions.getReason()));
}
}
}
return upgradeOptions;
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.STOPPED in project cloudbreak by hortonworks.
the class StackOperationServiceTest method testStartWhenClusterStopFailed.
@Test
public void testStartWhenClusterStopFailed() {
Stack stack = new Stack();
stack.setId(9876L);
stack.setStackStatus(new StackStatus(stack, Status.STOPPED, "", STOPPED));
Cluster cluster = new Cluster();
stack.setCluster(cluster);
underTest.start(stack);
verify(flowManager, times(1)).triggerStackStart(stack.getId());
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.STOPPED in project cloudbreak by hortonworks.
the class StackOperationServiceTest method shouldNotTriggerStopWhenStackRunsOnSpotInstances.
@Test
public void shouldNotTriggerStopWhenStackRunsOnSpotInstances() {
Stack stack = new Stack();
stack.setId(9876L);
stack.setStackStatus(new StackStatus(stack, AVAILABLE));
when(stackStopRestrictionService.isInfrastructureStoppable(any())).thenReturn(StopRestrictionReason.NONE);
when(spotInstanceUsageCondition.isStackRunsOnSpotInstances(stack)).thenReturn(true);
when(stackService.getByIdWithLists(stack.getId())).thenReturn(stack);
assertThatThrownBy(() -> underTest.updateStatus(stack.getId(), StatusRequest.STOPPED, true)).isInstanceOf(BadRequestException.class).hasMessage(String.format("Cannot update the status of stack '%s' to STOPPED, because it runs on spot instances", stack.getName()));
verify(stackUpdater, never()).updateStackStatus(any(), any(DetailedStackStatus.class));
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.STOPPED in project cloudbreak by hortonworks.
the class ClusterUpgradeAvailabilityServiceTest method testCheckForUpgradesByNameAndSomeInstancesAreStopped.
@Test
public void testCheckForUpgradesByNameAndSomeInstancesAreStopped() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
Stack stack = createStack(createStackStatus(Status.AVAILABLE), StackType.WORKLOAD);
com.sequenceiq.cloudbreak.cloud.model.Image currentImage = createCurrentImage();
ImageCatalog imageCatalogDomain = createImageCatalogDomain();
Image currentImageFromCatalog = mock(com.sequenceiq.cloudbreak.cloud.model.catalog.Image.class);
Image properImage = mock(com.sequenceiq.cloudbreak.cloud.model.catalog.Image.class);
Image otherImage = mock(com.sequenceiq.cloudbreak.cloud.model.catalog.Image.class);
CloudbreakImageCatalogV3 imageCatalog = createImageCatalog(List.of(properImage, otherImage, currentImageFromCatalog));
ImageFilterParams imageFilterParams = createImageFilterParams(stack, currentImageFromCatalog);
UpgradeV4Response response = new UpgradeV4Response();
when(imageFilterParamsFactory.create(currentImageFromCatalog, lockComponents, stack, INTERNAL_UPGRADE_SETTINGS)).thenReturn(imageFilterParams);
when(imageService.getImage(stack.getId())).thenReturn(currentImage);
when(imageCatalogService.getImageCatalogByName(stack.getWorkspace().getId(), CATALOG_NAME)).thenReturn(imageCatalogDomain);
when(imageCatalogProvider.getImageCatalogV3(CATALOG_URL)).thenReturn(imageCatalog);
ImageFilterResult filteredImages = createFilteredImages(properImage);
when(clusterUpgradeImageFilter.filter(ACCOUNT_ID, imageCatalog, imageFilterParams)).thenReturn(filteredImages);
when(upgradeOptionsResponseFactory.createV4Response(currentImageFromCatalog, filteredImages, stack.getCloudPlatform(), stack.getRegion(), currentImage.getImageCatalogName())).thenReturn(response);
when(imageProvider.getCurrentImageFromCatalog(CURRENT_IMAGE_ID, imageCatalog)).thenReturn(currentImageFromCatalog);
when(instanceMetaDataService.anyInstanceStopped(stack.getId())).thenReturn(true);
UpgradeV4Response actual = underTest.checkForUpgradesByName(stack, lockComponents, true, INTERNAL_UPGRADE_SETTINGS);
assertEquals("Cannot upgrade cluster because there is stopped instance.", actual.getReason());
assertEquals(response, actual);
verify(imageService).getImage(stack.getId());
verify(imageCatalogProvider).getImageCatalogV3(CATALOG_URL);
verify(clusterUpgradeImageFilter).filter(ACCOUNT_ID, imageCatalog, imageFilterParams);
verify(upgradeOptionsResponseFactory).createV4Response(currentImageFromCatalog, filteredImages, stack.getCloudPlatform(), stack.getRegion(), currentImage.getImageCatalogName());
}
Aggregations