Search in sources :

Example 46 with Cluster

use of com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster in project cloudbreak by hortonworks.

the class StackOperationService method updateStatus.

public FlowIdentifier updateStatus(Long stackId, StatusRequest status, boolean updateCluster) {
    Stack stack = stackService.getByIdWithLists(stackId);
    Cluster cluster = null;
    if (stack.getCluster() != null) {
        cluster = clusterService.findOneWithLists(stack.getCluster().getId()).orElse(null);
    }
    switch(status) {
        case SYNC:
            return sync(stack, false);
        case FULL_SYNC:
            return sync(stack, true);
        case REPAIR_FAILED_NODES:
            return repairFailedNodes(stack);
        case STOPPED:
            return stop(stack, cluster, updateCluster);
        case STARTED:
            return start(stack);
        default:
            throw new BadRequestException("Cannot update the status of stack because status request not valid.");
    }
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 47 with Cluster

use of com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster in project cloudbreak by hortonworks.

the class TelemetryService method createTelemetryConfigs.

@Override
public Map<String, SaltPillarProperties> createTelemetryConfigs(Long stackId, Set<TelemetryComponentType> components) {
    Stack stack = stackService.getById(stackId);
    Cluster cluster = stack.getCluster();
    DataBusCredential dataBusCredential = getDatabusCredential(cluster).orElse(null);
    Telemetry telemetry = componentConfigProviderService.getTelemetry(stackId);
    LOGGER.debug("Generating telemetry configs for stack '{}'", stack.getResourceCrn());
    return telemetryDecorator.decoratePillar(new HashMap<>(), stack, telemetry, dataBusCredential);
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Telemetry(com.sequenceiq.common.api.telemetry.model.Telemetry) DataBusCredential(com.sequenceiq.common.api.telemetry.model.DataBusCredential) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 48 with Cluster

use of com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster in project cloudbreak by hortonworks.

the class ClusterTemplateService method prepareCreation.

@Override
protected void prepareCreation(ClusterTemplate resource) {
    measure(() -> validateBeforeCreate(resource), LOGGER, "Cluster definition validated in {}ms");
    if (resource.getStatus().isNonDefault()) {
        Stack stackTemplate = resource.getStackTemplate();
        stackTemplate.setName(UUID.randomUUID().toString());
        if (stackTemplate.getOrchestrator() != null) {
            orchestratorService.save(stackTemplate.getOrchestrator());
        }
        Network network = stackTemplate.getNetwork();
        if (network != null) {
            network.setWorkspace(stackTemplate.getWorkspace());
            networkService.pureSave(network);
        }
        Cluster cluster = stackTemplate.getCluster();
        if (cluster != null) {
            cluster.setWorkspace(stackTemplate.getWorkspace());
            clusterService.saveWithRef(cluster);
        }
        stackTemplate.setResourceCrn(createCRN(ThreadBasedUserCrnProvider.getAccountId()));
        stackTemplate = stackTemplateService.pureSave(stackTemplate);
        componentConfigProviderService.store(new ArrayList<>(stackTemplate.getComponents()));
        if (cluster != null) {
            cluster.setStack(stackTemplate);
            clusterService.save(cluster);
        }
        if (stackTemplate.getInstanceGroups() != null && !stackTemplate.getInstanceGroups().isEmpty()) {
            instanceGroupService.saveAll(stackTemplate.getInstanceGroups(), stackTemplate.getWorkspace());
        }
    }
    resource.setCreated(System.currentTimeMillis());
}
Also used : Network(com.sequenceiq.cloudbreak.domain.Network) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 49 with Cluster

use of com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster in project cloudbreak by hortonworks.

the class ClouderaManagerModificationService method stopCluster.

@Override
public void stopCluster(boolean disableKnoxAutorestart) throws CloudbreakException {
    Cluster cluster = stack.getCluster();
    ClustersResourceApi clustersResourceApi = clouderaManagerApiFactory.getClustersResourceApi(apiClient);
    try {
        LOGGER.debug("Stopping all Cloudera Runtime services");
        if (clouderaManagerPollingServiceProvider.checkCmStatus(stack, apiClient).isTimeout()) {
            skipStopWithStoppedCm();
        } else {
            stopWithRunningCm(disableKnoxAutorestart, cluster, clustersResourceApi);
        }
    } catch (ApiException e) {
        LOGGER.info("Couldn't stop Cloudera Manager services", e);
        throw new ClouderaManagerOperationFailedException(e.getMessage(), e);
    }
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ClustersResourceApi(com.cloudera.api.swagger.ClustersResourceApi) ApiException(com.cloudera.api.swagger.client.ApiException)

Example 50 with Cluster

use of com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster in project cloudbreak by hortonworks.

the class ClouderaManagerModificationService method doRestartServicesIfNeeded.

private int doRestartServicesIfNeeded(ClustersResourceApi clustersResourceApi, boolean waitForCommandExecutionOnly) throws ApiException, CloudbreakException {
    ApiCommandList apiCommandList = clustersResourceApi.listActiveCommands(stack.getName(), SUMMARY);
    Optional<ApiCommand> optionalRestartCommand = apiCommandList.getItems().stream().filter(cmd -> "Restart".equals(cmd.getName())).findFirst();
    ApiCommand restartCommand = null;
    if (optionalRestartCommand.isPresent()) {
        restartCommand = optionalRestartCommand.get();
        LOGGER.debug("Restart for Cluster services is already running with id: [{}]", restartCommand.getId());
    } else if (!waitForCommandExecutionOnly) {
        LOGGER.info("Restarting cluster services.");
        ApiRestartClusterArgs restartClusterArgs = new ApiRestartClusterArgs();
        restartClusterArgs.setRedeployClientConfiguration(true);
        restartCommand = clustersResourceApi.restartCommand(stack.getName(), restartClusterArgs);
        eventService.fireCloudbreakEvent(stack.getId(), UPDATE_IN_PROGRESS.name(), CLUSTER_CM_CLUSTER_SERVICES_RESTARTING);
    }
    if (restartCommand != null) {
        ExtendedPollingResult pollingResult = clouderaManagerPollingServiceProvider.startPollingCmServicesRestart(stack, apiClient, restartCommand.getId());
        handlePollingResult(pollingResult, "Cluster was terminated while restarting services.", "Timeout happened while restarting services.");
    }
    return getCommandId(restartCommand);
}
Also used : CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) ApiBatchRequestElement(com.cloudera.api.swagger.model.ApiBatchRequestElement) ClusterClientInitException(com.sequenceiq.cloudbreak.cluster.service.ClusterClientInitException) LoggerFactory(org.slf4j.LoggerFactory) ApiService(com.cloudera.api.swagger.model.ApiService) ApiException(com.cloudera.api.swagger.client.ApiException) ClouderaManagerProductsProvider(com.sequenceiq.cloudbreak.cluster.service.ClouderaManagerProductsProvider) ParcelStatus(com.sequenceiq.cloudbreak.cm.model.ParcelStatus) ClustersResourceApi(com.cloudera.api.swagger.ClustersResourceApi) BigDecimal(java.math.BigDecimal) ApiCommandList(com.cloudera.api.swagger.model.ApiCommandList) ClouderaManagerProduct(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerProduct) CloudbreakEventService(com.sequenceiq.cloudbreak.structuredevent.event.CloudbreakEventService) BatchResourceApi(com.cloudera.api.swagger.BatchResourceApi) Locale(java.util.Locale) Map(java.util.Map) ApiHostRefList(com.cloudera.api.swagger.model.ApiHostRefList) ClouderaManagerResourceApi(com.cloudera.api.swagger.ClouderaManagerResourceApi) HostTemplatesResourceApi(com.cloudera.api.swagger.HostTemplatesResourceApi) CLOUDERAMANAGER_VERSION_7_6_0(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil.CLOUDERAMANAGER_VERSION_7_6_0) Telemetry(com.sequenceiq.common.api.telemetry.model.Telemetry) ParcelResourceApi(com.cloudera.api.swagger.ParcelResourceApi) ParcelOperationStatus(com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus) Versioned(com.sequenceiq.cloudbreak.common.type.Versioned) Predicate(java.util.function.Predicate) Collection(java.util.Collection) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) PollingResultErrorHandler(com.sequenceiq.cloudbreak.cm.polling.PollingResultErrorHandler) Set(java.util.Set) ApiBatchResponse(com.cloudera.api.swagger.model.ApiBatchResponse) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) Collectors(java.util.stream.Collectors) ClouderaManagerRepo(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo) Objects(java.util.Objects) List(java.util.List) ApiEntityTag(com.cloudera.api.swagger.model.ApiEntityTag) ApiRestartClusterArgs(com.cloudera.api.swagger.model.ApiRestartClusterArgs) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) PollingResult(com.sequenceiq.cloudbreak.polling.PollingResult) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) ClusterModificationService(com.sequenceiq.cloudbreak.cluster.api.ClusterModificationService) ApiCallback(com.cloudera.api.swagger.client.ApiCallback) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ApiCommand(com.cloudera.api.swagger.model.ApiCommand) ApiClient(com.cloudera.api.swagger.client.ApiClient) ClouderaManagerClientInitException(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException) ApiConfigStalenessStatus(com.cloudera.api.swagger.model.ApiConfigStalenessStatus) CLUSTER_CM_CLUSTER_SERVICES_STARTING(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_CM_CLUSTER_SERVICES_STARTING) Function(java.util.function.Function) Scope(org.springframework.context.annotation.Scope) ServicesResourceApi(com.cloudera.api.swagger.ServicesResourceApi) ClouderaManagerPollingServiceProvider(com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerPollingServiceProvider) Inject(javax.inject.Inject) StackRepoDetails(com.sequenceiq.cloudbreak.cloud.model.component.StackRepoDetails) ClouderaManagerApiClientProvider(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerApiClientProvider) UPDATE_IN_PROGRESS(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.UPDATE_IN_PROGRESS) Service(org.springframework.stereotype.Service) ApiHost(com.cloudera.api.swagger.model.ApiHost) CMRepositoryVersionUtil.isVersionNewerOrEqualThanLimited(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil.isVersionNewerOrEqualThanLimited) CLUSTER_CM_CLUSTER_SERVICES_RESTARTING(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_CM_CLUSTER_SERVICES_RESTARTING) ApiBatchRequest(com.cloudera.api.swagger.model.ApiBatchRequest) CLOUDERAMANAGER_VERSION_7_5_1(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil.CLOUDERAMANAGER_VERSION_7_5_1) ApiServiceState(com.cloudera.api.swagger.model.ApiServiceState) ClusterComponentConfigProvider(com.sequenceiq.cloudbreak.cluster.service.ClusterComponentConfigProvider) CLUSTER_CM_UPDATED_REMOTE_DATA_CONTEXT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_CM_UPDATED_REMOTE_DATA_CONTEXT) Logger(org.slf4j.Logger) CLOUDERAMANAGER_VERSION_7_1_0(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil.CLOUDERAMANAGER_VERSION_7_1_0) CLUSTER_CM_CLUSTER_SERVICES_STARTED(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_CM_CLUSTER_SERVICES_STARTED) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) URLUtils(com.sequenceiq.cloudbreak.util.URLUtils) ApplicationContext(org.springframework.context.ApplicationContext) Consumer(java.util.function.Consumer) ClusterComponent(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) HTTPMethod(com.cloudera.api.swagger.model.HTTPMethod) CLUSTER_CM_UPDATING_REMOTE_DATA_CONTEXT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_CM_UPDATING_REMOTE_DATA_CONTEXT) ApiHostRef(com.cloudera.api.swagger.model.ApiHostRef) StackType(com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType) MgmtServiceResourceApi(com.cloudera.api.swagger.MgmtServiceResourceApi) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) ParcelsResourceApi(com.cloudera.api.swagger.ParcelsResourceApi) ClouderaManagerApiFactory(com.sequenceiq.cloudbreak.cm.client.retry.ClouderaManagerApiFactory) ApiCommand(com.cloudera.api.swagger.model.ApiCommand) ApiCommandList(com.cloudera.api.swagger.model.ApiCommandList) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) ApiRestartClusterArgs(com.cloudera.api.swagger.model.ApiRestartClusterArgs)

Aggregations

Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)407 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)248 Test (org.junit.jupiter.api.Test)125 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)63 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)60 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)58 Optional (java.util.Optional)51 Test (org.junit.Test)50 List (java.util.List)49 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)47 Set (java.util.Set)43 Json (com.sequenceiq.cloudbreak.common.json.Json)39 Map (java.util.Map)39 Collectors (java.util.stream.Collectors)39 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)37 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)36 Inject (javax.inject.Inject)36 Logger (org.slf4j.Logger)36 LoggerFactory (org.slf4j.LoggerFactory)36 DetailedStackStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus)35