Search in sources :

Example 1 with Entitlement

use of com.sequenceiq.cloudbreak.auth.altus.model.Entitlement in project cloudbreak by hortonworks.

the class CDPConfigService method initCdpStackRequests.

@PostConstruct
public void initCdpStackRequests() {
    PathMatchingResourcePatternResolver pathMatchingResourcePatternResolver = new PathMatchingResourcePatternResolver();
    try {
        Resource[] resources = pathMatchingResourcePatternResolver.getResources("classpath:duties/*/**/*.json");
        for (Resource resource : resources) {
            Matcher matcher = RESOURCE_TEMPLATE_PATTERN.matcher(resource.getURL().getPath());
            if (matcher.find()) {
                String runtimeVersion = matcher.group(RUNTIME_GROUP);
                if (supportedRuntimes.isEmpty() || supportedRuntimes.contains(runtimeVersion)) {
                    CloudPlatform cloudPlatform = CloudPlatform.valueOf(matcher.group(CLOUDPLATFORM_GROUP).toUpperCase());
                    SdxClusterShape sdxClusterShape = SdxClusterShape.valueOf(matcher.group(CLUSTERSHAPE_GROUP).toUpperCase());
                    CDPConfigKey cdpConfigKey = new CDPConfigKey(cloudPlatform, sdxClusterShape, runtimeVersion);
                    String entitlementString = matcher.group(ENTITLEMENT_GROUP) != null ? StringUtils.substring(matcher.group(ENTITLEMENT_GROUP), 1) : null;
                    Optional<Entitlement> entitlementOptional = Arrays.stream(Entitlement.values()).filter(entitlement -> StringUtils.equals(entitlement.name().toLowerCase(), entitlementString)).findFirst();
                    String templateString = IOUtils.toString(resource.getInputStream(), StandardCharsets.UTF_8.name());
                    if (!cdpStackRequests.containsKey(cdpConfigKey)) {
                        cdpStackRequests.put(cdpConfigKey, Maps.newHashMap());
                    }
                    cdpStackRequests.get(cdpConfigKey).putIfAbsent(entitlementOptional, templateString);
                }
            }
        }
        LOGGER.info("Cdp configs for datalakes: {}", cdpStackRequests);
    } catch (IOException e) {
        LOGGER.error("Can't read CDP template files", e);
        throw new IllegalStateException("Can't read CDP template files", e);
    }
}
Also used : Arrays(java.util.Arrays) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) SdxClusterShape(com.sequenceiq.sdx.api.model.SdxClusterShape) ImageCatalogService(com.sequenceiq.datalake.service.imagecatalog.ImageCatalogService) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) JsonUtil(com.sequenceiq.cloudbreak.common.json.JsonUtil) StringUtils(org.apache.commons.lang3.StringUtils) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) Strings(com.google.common.base.Strings) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) CDPConfigKey(com.sequenceiq.datalake.service.sdx.CDPConfigKey) Matcher(java.util.regex.Matcher) Service(org.springframework.stereotype.Service) Map(java.util.Map) AdvertisedRuntime(com.sequenceiq.sdx.api.model.AdvertisedRuntime) Entitlement(com.sequenceiq.cloudbreak.auth.altus.model.Entitlement) Resource(org.springframework.core.io.Resource) MapUtils(org.apache.commons.collections4.MapUtils) Logger(org.slf4j.Logger) Versioned(com.sequenceiq.cloudbreak.common.type.Versioned) Predicate(java.util.function.Predicate) Set(java.util.Set) IOException(java.io.IOException) VersionComparator(com.sequenceiq.cloudbreak.util.VersionComparator) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) StandardCharsets(java.nio.charset.StandardCharsets) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) PostConstruct(javax.annotation.PostConstruct) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) VisibleForTesting(com.google.common.annotations.VisibleForTesting) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) Matcher(java.util.regex.Matcher) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) SdxClusterShape(com.sequenceiq.sdx.api.model.SdxClusterShape) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) Entitlement(com.sequenceiq.cloudbreak.auth.altus.model.Entitlement) CDPConfigKey(com.sequenceiq.datalake.service.sdx.CDPConfigKey) PostConstruct(javax.annotation.PostConstruct)

Example 2 with Entitlement

use of com.sequenceiq.cloudbreak.auth.altus.model.Entitlement in project cloudbreak by hortonworks.

the class CmTemplateProcessor method getRecommendationByBlacklist.

private <T extends Enum<T>> Set<String> getRecommendationByBlacklist(Class<T> enumClass, boolean emptyServiceListBlacklisted, Map<String, Set<String>> componentsByHostGroup, Versioned version, List<String> entitlements) {
    LOGGER.info("Get recommendation by blacklisted {} with entitlements {}.", enumClass, entitlements);
    Set<String> recos = new HashSet<>();
    for (Entry<String, Set<String>> hostGroupServices : componentsByHostGroup.entrySet()) {
        if (emptyServiceListBlacklisted && hostGroupServices.getValue().isEmpty()) {
            continue;
        }
        boolean foundBlackListItem = false;
        for (String service : hostGroupServices.getValue()) {
            com.google.common.base.Optional<T> enumValue = Enums.getIfPresent(enumClass, service);
            if (enumValue.isPresent()) {
                if (EntitledForServiceScale.class.isAssignableFrom(enumClass)) {
                    EntitledForServiceScale entitledForServiceScale = (EntitledForServiceScale) enumValue.get();
                    Entitlement entitledFor = entitledForServiceScale.getEntitledFor();
                    if (!entitlements.contains(entitledFor.name()) && !isVersionEnablesScaling(version, entitledForServiceScale)) {
                        foundBlackListItem = true;
                        break;
                    }
                } else {
                    foundBlackListItem = true;
                    break;
                }
            }
        }
        if (!foundBlackListItem) {
            recos.add(hostGroupServices.getKey());
        }
    }
    return recos;
}
Also used : Collectors.toSet(java.util.stream.Collectors.toSet) Set(java.util.Set) HashSet(java.util.HashSet) Entitlement(com.sequenceiq.cloudbreak.auth.altus.model.Entitlement) HashSet(java.util.HashSet)

Aggregations

Entitlement (com.sequenceiq.cloudbreak.auth.altus.model.Entitlement)2 Set (java.util.Set)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Strings (com.google.common.base.Strings)1 Maps (com.google.common.collect.Maps)1 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)1 ThreadBasedUserCrnProvider (com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider)1 EntitlementService (com.sequenceiq.cloudbreak.auth.altus.EntitlementService)1 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)1 JsonUtil (com.sequenceiq.cloudbreak.common.json.JsonUtil)1 CloudPlatform (com.sequenceiq.cloudbreak.common.mappable.CloudPlatform)1 Versioned (com.sequenceiq.cloudbreak.common.type.Versioned)1 VersionComparator (com.sequenceiq.cloudbreak.util.VersionComparator)1 ImageCatalogService (com.sequenceiq.datalake.service.imagecatalog.ImageCatalogService)1 CDPConfigKey (com.sequenceiq.datalake.service.sdx.CDPConfigKey)1 AdvertisedRuntime (com.sequenceiq.sdx.api.model.AdvertisedRuntime)1 SdxClusterShape (com.sequenceiq.sdx.api.model.SdxClusterShape)1 IOException (java.io.IOException)1 StandardCharsets (java.nio.charset.StandardCharsets)1 ArrayList (java.util.ArrayList)1