Search in sources :

Example 6 with STOPPED

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.STOPPED in project cloudbreak by hortonworks.

the class StackUpgradeOperations method validateAttachedDataHubsForDataLake.

private void validateAttachedDataHubsForDataLake(String accountId, Long workspaceId, Stack stack, UpgradeV4Response upgradeResponse) {
    if (entitlementService.runtimeUpgradeEnabled(accountId) && StackType.DATALAKE == stack.getType()) {
        LOGGER.info("Checking that the attached DataHubs of the Data lake are both in stopped state and upgradeable only in case if " + "Data lake runtime upgrade is enabled in [{}] account on [{}] cluster.", accountId, stack.getName());
        StackViewV4Responses stackViewV4Responses = stackOperations.listByEnvironmentCrn(workspaceId, stack.getEnvironmentCrn(), List.of(StackType.WORKLOAD));
        if (!entitlementService.datahubRuntimeUpgradeEnabled(accountId)) {
            upgradeResponse.appendReason(upgradePreconditionService.checkForNonUpgradeableAttachedClusters(stackViewV4Responses));
        }
        upgradeResponse.appendReason(upgradePreconditionService.checkForRunningAttachedClusters(stackViewV4Responses, stack));
    }
}
Also used : StackViewV4Responses(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Responses)

Example 7 with STOPPED

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.STOPPED in project cloudbreak by hortonworks.

the class SdxServiceTest method testDeleteSdxWhenSdxHasStoppedDataHubsShouldThrowBadRequest.

@Test
void testDeleteSdxWhenSdxHasStoppedDataHubsShouldThrowBadRequest() {
    SdxCluster sdxCluster = getSdxCluster();
    when(sdxClusterRepository.findByAccountIdAndClusterNameAndDeletedIsNull(anyString(), anyString())).thenReturn(Optional.of(sdxCluster));
    StackViewV4Response stackViewV4Response = new StackViewV4Response();
    stackViewV4Response.setName("existingDistroXCluster");
    stackViewV4Response.setStatus(Status.STOPPED);
    mockCBCallForDistroXClusters(Sets.newHashSet(stackViewV4Response));
    BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> underTest.deleteSdx(USER_CRN, "sdx-cluster-name", false));
    assertEquals("The following stopped Data Hubs clusters(s) must be terminated before SDX deleting [existingDistroXCluster]." + " Use --force to skip this check.", badRequestException.getMessage());
}
Also used : StackViewV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 8 with STOPPED

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.STOPPED in project cloudbreak by hortonworks.

the class SdxServiceTest method testDeleteSdxWhenSdxHasAttachedDataHubsShouldThrowBadRequestBecauseSdxCanNotDeletedIfAttachedClustersAreAvailable.

@Test
void testDeleteSdxWhenSdxHasAttachedDataHubsShouldThrowBadRequestBecauseSdxCanNotDeletedIfAttachedClustersAreAvailable() {
    SdxCluster sdxCluster = getSdxCluster();
    when(sdxClusterRepository.findByAccountIdAndClusterNameAndDeletedIsNull(anyString(), anyString())).thenReturn(Optional.of(sdxCluster));
    StackViewV4Response stackViewV4Response = new StackViewV4Response();
    stackViewV4Response.setName("existingDistroXCluster");
    stackViewV4Response.setStatus(Status.AVAILABLE);
    mockCBCallForDistroXClusters(Sets.newHashSet(stackViewV4Response));
    BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> underTest.deleteSdx(USER_CRN, "sdx-cluster-name", false));
    assertEquals("The following Data Hub cluster(s) must be stopped before attempting SDX deletion [existingDistroXCluster].", badRequestException.getMessage());
}
Also used : StackViewV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 9 with STOPPED

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.STOPPED in project cloudbreak by hortonworks.

the class ClusterStatusSyncHandler method onApplicationEvent.

@Override
public void onApplicationEvent(ClusterStatusSyncEvent event) {
    long autoscaleClusterId = event.getClusterId();
    Cluster cluster = clusterService.findById(autoscaleClusterId);
    if (cluster == null) {
        return;
    }
    LoggingUtils.buildMdcContext(cluster);
    StackStatusV4Response statusResponse = cloudbreakCommunicator.getStackStatusByCrn(cluster.getStackCrn());
    boolean clusterAvailable;
    if (Boolean.TRUE.equals(cluster.isStopStartScalingEnabled())) {
        clusterAvailable = Optional.ofNullable(statusResponse.getStatus()).map(Status::isAvailable).orElse(false);
    // TODO CB-15146: This may need to change depending on the final form of how we check which operations are to be allowed
    // when there are some STOPPED instances
    } else {
        clusterAvailable = Optional.ofNullable(statusResponse.getStatus()).map(Status::isAvailable).orElse(false) && Optional.ofNullable(statusResponse.getClusterStatus()).map(Status::isAvailable).orElse(false);
    }
    LOGGER.info("Computed clusterAvailable: {}", clusterAvailable);
    LOGGER.info("Analysing CBCluster Status '{}' for Cluster '{}. Available(Determined)={}' ", statusResponse, cluster.getStackCrn(), clusterAvailable);
    updateClusterState(cluster, statusResponse, clusterAvailable);
}
Also used : Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) Cluster(com.sequenceiq.periscope.domain.Cluster) StackStatusV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackStatusV4Response)

Example 10 with STOPPED

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.STOPPED 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)

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