Search in sources :

Example 1 with CmTemplateProcessor

use of com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor in project cloudbreak by hortonworks.

the class ClusterStartHandler method accept.

@Override
public void accept(Event<ClusterStartRequest> event) {
    ClusterStartRequest request = event.getData();
    ClusterStartResult result;
    int requestId;
    try {
        Stack stack = stackService.getByIdWithListsInTransaction(request.getResourceId());
        Optional<Stack> datalakeStack = datalakeService.getDatalakeStackByDatahubStack(stack);
        CmTemplateProcessor blueprintProcessor = getCmTemplateProcessor(stack.getCluster());
        if (datalakeStack.isPresent() && clusterServicesRestartService.isRDCRefreshNeeded(stack, datalakeStack.get())) {
            requestId = clusterServicesRestartService.refreshClusterOnStart(stack, datalakeStack.get(), blueprintProcessor);
        } else {
            requestId = apiConnectors.getConnector(stack).startCluster();
        }
        handleStopStartScalingFeature(stack, blueprintProcessor);
        result = new ClusterStartResult(request, requestId);
    } catch (Exception e) {
        result = new ClusterStartResult(e.getMessage(), e, request);
    }
    eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
}
Also used : ClusterStartResult(com.sequenceiq.cloudbreak.reactor.api.event.cluster.ClusterStartResult) CmTemplateProcessor(com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor) ClusterStartRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.ClusterStartRequest) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 2 with CmTemplateProcessor

use of com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor in project cloudbreak by hortonworks.

the class LoadBalancerSANProvider method getLoadBalancerSAN.

public Optional<String> getLoadBalancerSAN(Stack stack) {
    checkNotNull(stack);
    checkNotNull(stack.getCluster());
    Cluster cluster = stack.getCluster();
    CmTemplateProcessor cmTemplateProcessor = new CmTemplateProcessor(cluster.getBlueprint().getBlueprintText());
    String cdhVersion = cmTemplateProcessor.getStackVersion();
    if (isVersionNewerOrEqualThanLimited(cdhVersion, CLOUDERA_STACK_VERSION_7_2_11)) {
        Set<LoadBalancer> loadBalancers = loadBalancerPersistenceService.findByStackId(stack.getId());
        if (!loadBalancers.isEmpty()) {
            Optional<LoadBalancer> loadBalancer = loadBalancerConfigService.selectLoadBalancerForFrontend(loadBalancers, LoadBalancerType.PUBLIC);
            return loadBalancer.flatMap(this::getBestSANForLB);
        }
    }
    return Optional.empty();
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) CmTemplateProcessor(com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor)

Example 3 with CmTemplateProcessor

use of com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor 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 4 with CmTemplateProcessor

use of com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor in project cloudbreak by hortonworks.

the class BlueprintConfigValidator method validate.

public void validate(Blueprint blueprint) {
    CmTemplateProcessor cmTemplateProcessor = new CmTemplateProcessor(blueprint.getBlueprintText());
    if (cmTemplateProcessor.isInstantiatorPresent()) {
        throw new BadRequestException("Instantiator is present in your Cloudera Manager template which is probably incorrect.");
    }
    if (cmTemplateProcessor.isRepositoriesPresent()) {
        throw new BadRequestException("Repositories are present in your Cloudera Manager template, this must be removed.");
    }
    Pattern passwordPattern = Pattern.compile("\\*\\*\\*");
    Matcher passwordMatch = passwordPattern.matcher(blueprint.getBlueprintText());
    if (passwordMatch.find()) {
        throw new BadRequestException("Password placeholder with **** is present in your Cloudera Manager template which is probably incorrect.");
    }
    Pattern volumePattern = Pattern.compile("/hadoopfs/fs(.*?)");
    Matcher volumeMatch = volumePattern.matcher(blueprint.getBlueprintText());
    if (volumeMatch.find()) {
        throw new BadRequestException("Volume configuration should not be part of your Cloudera Manager template.");
    }
    if (!cmTemplateProcessor.everyHostTemplateHasRoleConfigGroupsRefNames()) {
        throw new BadRequestException("RoleConfigGroupsRefNames is probably missing or misspelled in your Cloudera Manager template.");
    }
    if (!cmTemplateProcessor.everyServiceHasRoleConfigGroups()) {
        throw new BadRequestException("RoleConfigGroups is probably missing or misspelled in your Cloudera Manager template.");
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) CmTemplateProcessor(com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor)

Example 5 with CmTemplateProcessor

use of com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor in project cloudbreak by hortonworks.

the class BlueprintValidator method validate.

@Override
public void validate(Object target, Errors errors) {
    Blueprint blueprint = (Blueprint) target;
    if (blueprint.getBlueprintText().isEmpty()) {
        errors.rejectValue("blueprintText", "empty", "The blueprint text is empty");
    }
    CmTemplateProcessor cm = cmTemplateProcessorFactory.get(blueprint.getBlueprintText());
    validateHostNames(cm, errors);
    validateRoleType(cm, errors);
}
Also used : Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) CmTemplateProcessor(com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor)

Aggregations

CmTemplateProcessor (com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor)149 TemplatePreparationObject (com.sequenceiq.cloudbreak.template.TemplatePreparationObject)115 Test (org.junit.Test)84 ApiClusterTemplateConfig (com.cloudera.api.swagger.model.ApiClusterTemplateConfig)75 List (java.util.List)46 ArrayList (java.util.ArrayList)33 Test (org.junit.jupiter.api.Test)19 HostgroupView (com.sequenceiq.cloudbreak.template.views.HostgroupView)18 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)15 BlueprintView (com.sequenceiq.cloudbreak.template.views.BlueprintView)13 HashSet (java.util.HashSet)12 ClouderaManagerRepo (com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo)10 Builder (com.sequenceiq.cloudbreak.template.TemplatePreparationObject.Builder)10 Set (java.util.Set)10 ApiClusterTemplateService (com.cloudera.api.swagger.model.ApiClusterTemplateService)9 RDSConfig (com.sequenceiq.cloudbreak.domain.RDSConfig)8 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)8 Map (java.util.Map)8 BaseFileSystemConfigurationsView (com.sequenceiq.cloudbreak.template.filesystem.BaseFileSystemConfigurationsView)7 Collectors (java.util.stream.Collectors)7