Search in sources :

Example 1 with STOPPED

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;
}
Also used : UserBreakException(com.dyngr.exception.UserBreakException) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) StartExternalDatabaseResult(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StartExternalDatabaseResult) PollerException(com.dyngr.exception.PollerException) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) StartExternalDatabaseRequest(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StartExternalDatabaseRequest) PollerStoppedException(com.dyngr.exception.PollerStoppedException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) DatabaseAvailabilityType(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.database.DatabaseAvailabilityType)

Example 2 with STOPPED

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;
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) RepairValidation(com.sequenceiq.cloudbreak.service.cluster.model.RepairValidation) Map(java.util.Map)

Example 3 with STOPPED

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());
}
Also used : StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with STOPPED

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));
}
Also used : StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with STOPPED

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());
}
Also used : CloudbreakImageCatalogV3(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) ImageFilterParams(com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterParams) ImageFilterResult(com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterResult) Test(org.junit.Test)

Aggregations

Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)12 Test (org.junit.jupiter.api.Test)7 DetailedStackStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus)6 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)6 StackStatus (com.sequenceiq.cloudbreak.domain.stack.StackStatus)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 PollerException (com.dyngr.exception.PollerException)5 PollerStoppedException (com.dyngr.exception.PollerStoppedException)5 UserBreakException (com.dyngr.exception.UserBreakException)5 DatabaseAvailabilityType (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.database.DatabaseAvailabilityType)4 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)4 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Set (java.util.Set)3 Inject (javax.inject.Inject)3 InstanceStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus)2 StackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response)2 StackViewV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response)2 UpgradeV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response)2