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));
}
}
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());
}
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());
}
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);
}
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));
}
Aggregations