Search in sources :

Example 36 with Cluster

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

the class LoadBalancerConfigService method getKnoxGatewayGroups.

public Set<String> getKnoxGatewayGroups(Stack stack) {
    LOGGER.debug("Fetching list of instance groups with Knox gateway installed");
    Set<String> groupNames = new HashSet<>();
    Cluster cluster = stack.getCluster();
    if (cluster != null) {
        LOGGER.debug("Checking if Knox gateway is explicitly defined");
        CmTemplateProcessor cmTemplateProcessor = new CmTemplateProcessor(cluster.getBlueprint().getBlueprintText());
        groupNames = cmTemplateProcessor.getHostGroupsWithComponent(KnoxRoles.KNOX_GATEWAY);
    }
    if (groupNames.isEmpty()) {
        LOGGER.debug("Knox gateway is not explicitly defined; searching for CM gateway hosts");
        groupNames = stack.getInstanceGroups().stream().filter(i -> InstanceGroupType.isGateway(i.getInstanceGroupType())).map(InstanceGroup::getGroupName).collect(Collectors.toSet());
    }
    if (groupNames.isEmpty()) {
        LOGGER.info("No Knox gateway instance groups found");
    }
    return groupNames;
}
Also used : Arrays(java.util.Arrays) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) OozieRoles(com.sequenceiq.cloudbreak.cmtemplate.configproviders.oozie.OozieRoles) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) ProviderParameterCalculator(com.sequenceiq.cloudbreak.common.mappable.ProviderParameterCalculator) PublicEndpointAccessGateway(com.sequenceiq.common.api.type.PublicEndpointAccessGateway) Map(java.util.Map) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) SubnetSelector(com.sequenceiq.cloudbreak.converter.v4.environment.network.SubnetSelector) AzureStackV4Parameters(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.stack.AzureStackV4Parameters) LoadBalancerPersistenceService(com.sequenceiq.cloudbreak.service.stack.LoadBalancerPersistenceService) Set(java.util.Set) LoadBalancerSku(com.sequenceiq.common.api.type.LoadBalancerSku) Collectors(java.util.stream.Collectors) KnoxRoles(com.sequenceiq.cloudbreak.cmtemplate.configproviders.knox.KnoxRoles) Json(com.sequenceiq.cloudbreak.common.json.Json) List(java.util.List) Optional(java.util.Optional) GCP(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform.GCP) CmTemplateProcessor(com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor) CLOUDERA_STACK_VERSION_7_2_11(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil.CLOUDERA_STACK_VERSION_7_2_11) OOZIE_HTTPS_PORT(com.sequenceiq.cloudbreak.cmtemplate.configproviders.oozie.OozieHAConfigProvider.OOZIE_HTTPS_PORT) NetworkConstants(com.sequenceiq.cloudbreak.common.network.NetworkConstants) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) TargetGroup(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup) Network(com.sequenceiq.cloudbreak.domain.Network) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) AWS(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform.AWS) Service(org.springframework.stereotype.Service) CMRepositoryVersionUtil.isVersionNewerOrEqualThanLimited(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil.isVersionNewerOrEqualThanLimited) NetworkV4Base(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.NetworkV4Base) Map.entry(java.util.Map.entry) AzureInstanceGroupParameters(com.sequenceiq.cloudbreak.cloud.model.instance.AzureInstanceGroupParameters) LoadBalancerCreation(com.sequenceiq.common.api.type.LoadBalancerCreation) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Logger(org.slf4j.Logger) AvailabilitySetNameService(com.sequenceiq.cloudbreak.cloud.model.instance.AvailabilitySetNameService) TargetGroupType(com.sequenceiq.common.api.type.TargetGroupType) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) StackType(com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType) Preconditions(com.google.common.base.Preconditions) AZURE(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform.AZURE) Collections(java.util.Collections) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) CmTemplateProcessor(com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor) HashSet(java.util.HashSet) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)

Example 37 with Cluster

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

the class AltusMachineUserService method storeDataBusCredential.

/**
 * Store databus access / secret keypair and machine user name in the cluster if altus credential exists
 * @param altusCredential dto for databus access/private key
 * @param stack component will be attached to this stack
 * @return domain object that holds databus credential
 */
public DataBusCredential storeDataBusCredential(Optional<AltusCredential> altusCredential, Stack stack) {
    if (altusCredential.isPresent()) {
        DataBusCredential dataBusCredential = new DataBusCredential();
        dataBusCredential.setMachineUserName(getFluentDatabusMachineUserName(stack));
        dataBusCredential.setAccessKey(altusCredential.get().getAccessKey());
        dataBusCredential.setPrivateKey(altusCredential.get().getPrivateKey() != null ? new String(altusCredential.get().getPrivateKey()) : null);
        String databusCredentialJsonString = new Json(dataBusCredential).getValue();
        Cluster cluster = stack.getCluster();
        if (cluster != null) {
            cluster.setDatabusCredential(databusCredentialJsonString);
            clusterService.updateCluster(cluster);
        }
        return dataBusCredential;
    }
    return null;
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Json(com.sequenceiq.cloudbreak.common.json.Json) DataBusCredential(com.sequenceiq.common.api.telemetry.model.DataBusCredential)

Example 38 with Cluster

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

the class BlueprintService method prepareDeletion.

@Override
protected void prepareDeletion(Blueprint blueprint) {
    Set<Cluster> notDeletedClustersWithThisCd = getNotDeletedClustersWithBlueprint(blueprint);
    if (!notDeletedClustersWithThisCd.isEmpty()) {
        if (notDeletedClustersWithThisCd.size() > 1) {
            List<String> clusters = notDeletedClustersWithThisCd.stream().filter(it -> !it.getStack().getType().equals(StackType.TEMPLATE)).map(it -> it.getStack().getName()).collect(Collectors.toList());
            List<Long> stackTemplateIds = notDeletedClustersWithThisCd.stream().filter(it -> it.getStack().getType().equals(StackType.TEMPLATE)).map(it -> it.getStack().getId()).collect(Collectors.toList());
            Set<String> clusterDefinitions = getClusterDefinitionNameByStackTemplateIds(stackTemplateIds);
            throw new BadRequestException(String.format("There are clusters or cluster definitions associated with cluster template '%s'. " + "The cluster template used by %s cluster(s) (%s) and %s cluster definitions (%s). " + "Please remove these before deleting the cluster template.", blueprint.getName(), clusters.size(), String.join(", ", clusters), clusterDefinitions.size(), String.join(", ", clusterDefinitions)));
        }
        Cluster cluster = notDeletedClustersWithThisCd.iterator().next();
        String clusterType = getClusterType(cluster);
        String clusterDefinitionName = getClusterDefinitionNameByStackTemplateIds(List.of(cluster.getStack().getId())).stream().findFirst().orElseThrow(() -> new NotFoundException("Cannot find the cluster definition for the stack template"));
        throw new BadRequestException(String.format("There is a %s ['%s'] which uses cluster template '%s'. Please remove this " + "cluster before deleting the cluster template.", clusterType, clusterDefinitionName, blueprint.getName()));
    }
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) ClusterService(com.sequenceiq.cloudbreak.service.cluster.ClusterService) StringUtils(org.apache.commons.lang3.StringUtils) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) CdpResourceType(com.sequenceiq.common.api.type.CdpResourceType) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) AuthorizationResourceType(com.sequenceiq.authorization.resource.AuthorizationResourceType) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) EnumSet(java.util.EnumSet) CloudResourceAdvisor(com.sequenceiq.cloudbreak.service.stack.CloudResourceAdvisor) ConstraintViolationException(org.hibernate.exception.ConstraintViolationException) FieldError(org.springframework.validation.FieldError) WorkspaceResourceRepository(com.sequenceiq.cloudbreak.workspace.repository.workspace.WorkspaceResourceRepository) Collection(java.util.Collection) BlueprintView(com.sequenceiq.cloudbreak.domain.view.BlueprintView) Set(java.util.Set) DELETE_COMPLETED(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.DELETE_COMPLETED) NotNull(javax.validation.constraints.NotNull) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) Collectors(java.util.stream.Collectors) DEFAULT(com.sequenceiq.cloudbreak.api.endpoint.v4.common.ResourceStatus.DEFAULT) SERVICE_MANAGED(com.sequenceiq.cloudbreak.api.endpoint.v4.common.ResourceStatus.SERVICE_MANAGED) List(java.util.List) CmCloudStorageConfigProvider(com.sequenceiq.cloudbreak.cmtemplate.cloudstorage.CmCloudStorageConfigProvider) MapBindingResult(org.springframework.validation.MapBindingResult) MDCUtils(com.sequenceiq.cloudbreak.logger.MDCUtils) ConfigQueryEntry(com.sequenceiq.common.api.cloudstorage.query.ConfigQueryEntry) Optional(java.util.Optional) HueWorkaroundValidatorService(com.sequenceiq.cloudbreak.validation.HueWorkaroundValidatorService) CmTemplateProcessor(com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor) BlueprintStatusView(com.sequenceiq.cloudbreak.domain.projection.BlueprintStatusView) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) PlatformRecommendation(com.sequenceiq.cloudbreak.cloud.model.PlatformRecommendation) ResourceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.ResourceStatus) ScaleRecommendation(com.sequenceiq.cloudbreak.cloud.model.ScaleRecommendation) BlueprintRepository(com.sequenceiq.cloudbreak.repository.BlueprintRepository) OwnerAssignmentService(com.sequenceiq.authorization.service.OwnerAssignmentService) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) HashMap(java.util.HashMap) CompositeAuthResourcePropertyProvider(com.sequenceiq.authorization.service.CompositeAuthResourcePropertyProvider) BlueprintViewRepository(com.sequenceiq.cloudbreak.repository.BlueprintViewRepository) USER_MANAGED(com.sequenceiq.cloudbreak.api.endpoint.v4.common.ResourceStatus.USER_MANAGED) HashSet(java.util.HashSet) Inject(javax.inject.Inject) CrnResourceDescriptor(com.sequenceiq.cloudbreak.auth.crn.CrnResourceDescriptor) HueRoles(com.sequenceiq.cloudbreak.cmtemplate.configproviders.hue.HueRoles) ObjectUtils(org.apache.commons.lang3.ObjectUtils) Service(org.springframework.stereotype.Service) FileSystemConfigQueryObject(com.sequenceiq.cloudbreak.template.filesystem.FileSystemConfigQueryObject) Builder(com.sequenceiq.cloudbreak.template.filesystem.FileSystemConfigQueryObject.Builder) CentralBlueprintParameterQueryService(com.sequenceiq.cloudbreak.cmtemplate.CentralBlueprintParameterQueryService) NotFoundException.notFound(com.sequenceiq.cloudbreak.common.exception.NotFoundException.notFound) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Logger(org.slf4j.Logger) AutoscaleRecommendation(com.sequenceiq.cloudbreak.cloud.model.AutoscaleRecommendation) BlueprintLoaderService(com.sequenceiq.cloudbreak.init.blueprint.BlueprintLoaderService) DEFAULT_DELETED(com.sequenceiq.cloudbreak.api.endpoint.v4.common.ResourceStatus.DEFAULT_DELETED) RegionAwareCrnGenerator(com.sequenceiq.cloudbreak.auth.crn.RegionAwareCrnGenerator) CompactView(com.sequenceiq.cloudbreak.domain.view.CompactView) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) NameOrCrn(com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn) ClusterTemplateViewService(com.sequenceiq.cloudbreak.service.template.ClusterTemplateViewService) User(com.sequenceiq.cloudbreak.workspace.model.User) BlueprintUtils(com.sequenceiq.cloudbreak.cmtemplate.utils.BlueprintUtils) StackType(com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType) AbstractWorkspaceAwareResourceService(com.sequenceiq.cloudbreak.service.AbstractWorkspaceAwareResourceService) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException)

Example 39 with Cluster

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

the class ClusterProxyRegistrationHandler method registerCluster.

private Selectable registerCluster(ClusterProxyRegistrationRequest request) {
    Stack stack = stackService.getByIdWithListsInTransaction(request.getResourceId());
    try {
        if (!clusterProxyEnablementService.isClusterProxyApplicable(request.getCloudPlatform())) {
            LOGGER.info("Cluster Proxy integration is DISABLED, skipping registering with Cluster Proxy service. Cluster CRN: {}", stack.getResourceCrn());
            return new ClusterProxyRegistrationSuccess(request.getResourceId());
        }
        ConfigRegistrationResponse registerResponse = clusterProxyService.registerCluster(stack);
        Cluster cluster = stack.getCluster();
        if (cluster.hasGateway()) {
            LOGGER.debug("Updating Gateway for cluster {} in environment {} with public key certificate retrieved from Cluster Proxy", cluster.getId(), stack.getEnvironmentCrn());
            Gateway gateway = cluster.getGateway();
            gateway.setTokenCert(registerResponse.getX509Unwrapped());
            gatewayService.save(gateway);
        }
        return new ClusterProxyRegistrationSuccess(request.getResourceId());
    } catch (Exception e) {
        LOGGER.error("Error occurred when registering cluster {} in environment {} to cluster proxy", stack.getCluster().getId(), stack.getEnvironmentCrn(), e);
        return new ClusterProxyRegistrationFailed(request.getResourceId(), e);
    }
}
Also used : ClusterProxyRegistrationFailed(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.ClusterProxyRegistrationFailed) Gateway(com.sequenceiq.cloudbreak.domain.stack.cluster.gateway.Gateway) ConfigRegistrationResponse(com.sequenceiq.cloudbreak.clusterproxy.ConfigRegistrationResponse) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ClusterProxyRegistrationSuccess(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.ClusterProxyRegistrationSuccess) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 40 with Cluster

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

the class ClusterService method getStackRepositoryJson.

public String getStackRepositoryJson(Long stackId) {
    Stack stack = stackService.getById(stackId);
    Cluster cluster = stack.getCluster();
    if (cluster == null) {
        throw new BadRequestException(String.format("There is no cluster installed on stack '%s'.", stack.getName()));
    }
    StackRepoDetails repoDetails = clusterComponentConfigProvider.getStackRepoDetails(cluster.getId());
    String stackRepoId = repoDetails.getStack().get(REPO_ID_TAG);
    return clusterApiConnectors.getConnector(stack).clusterModificationService().getStackRepositoryJson(repoDetails, stackRepoId);
}
Also used : StackRepoDetails(com.sequenceiq.cloudbreak.cloud.model.component.StackRepoDetails) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

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