Search in sources :

Example 1 with CDPConfigKey

use of com.sequenceiq.datalake.service.sdx.CDPConfigKey in project cloudbreak by hortonworks.

the class CDPConfigServiceTest method cdpStackRequests.

@Test
void cdpStackRequests() {
    ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> {
        when(supportedRuntimes.isEmpty()).thenReturn(true);
        cdpConfigService.initCdpStackRequests();
        assertNotNull(cdpConfigService.getConfigForKey(new CDPConfigKey(CloudPlatform.AWS, SdxClusterShape.LIGHT_DUTY, RUNTIME_7212)));
        assertNotNull(cdpConfigService.getConfigForKey(new CDPConfigKey(CloudPlatform.AWS, SdxClusterShape.LIGHT_DUTY, RUNTIME_710)));
        assertNotNull(cdpConfigService.getConfigForKey(new CDPConfigKey(CloudPlatform.AZURE, SdxClusterShape.LIGHT_DUTY, RUNTIME_7212)));
        assertNotNull(cdpConfigService.getConfigForKey(new CDPConfigKey(CloudPlatform.AZURE, SdxClusterShape.LIGHT_DUTY, RUNTIME_7212)));
        assertNotNull(cdpConfigService.getConfigForKey(new CDPConfigKey(CloudPlatform.YARN, SdxClusterShape.LIGHT_DUTY, RUNTIME_7212)));
        assertNotNull(cdpConfigService.getConfigForKey(new CDPConfigKey(CloudPlatform.YARN, SdxClusterShape.LIGHT_DUTY, RUNTIME_710)));
        assertNotNull(cdpConfigService.getConfigForKey(new CDPConfigKey(CloudPlatform.MOCK, SdxClusterShape.LIGHT_DUTY, RUNTIME_7212)));
        assertNotNull(cdpConfigService.getConfigForKey(new CDPConfigKey(CloudPlatform.MOCK, SdxClusterShape.LIGHT_DUTY, RUNTIME_710)));
        assertTrue(cdpConfigService.getConfigForKey(new CDPConfigKey(CloudPlatform.AWS, SdxClusterShape.MEDIUM_DUTY_HA, RUNTIME_7214)).getCluster().getBlueprintName().contains("Profiler"));
        assertFalse(cdpConfigService.getConfigForKey(new CDPConfigKey(CloudPlatform.AWS, SdxClusterShape.MEDIUM_DUTY_HA, RUNTIME_7212)).getCluster().getBlueprintName().contains("Profiler"));
        assertFalse(cdpConfigService.getConfigForKey(new CDPConfigKey(CloudPlatform.AWS, SdxClusterShape.LIGHT_DUTY, RUNTIME_7214)).getCluster().getBlueprintName().contains("Profiler"));
        lenient().when(entitlementService.isEntitledFor(anyString(), eq(Entitlement.CDP_DATA_LAKE_MEDIUM_DUTY_WITH_PROFILER))).thenReturn(Boolean.FALSE);
        assertFalse(cdpConfigService.getConfigForKey(new CDPConfigKey(CloudPlatform.AWS, SdxClusterShape.MEDIUM_DUTY_HA, RUNTIME_7214)).getCluster().getBlueprintName().contains("Profiler"));
    });
}
Also used : CDPConfigKey(com.sequenceiq.datalake.service.sdx.CDPConfigKey) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with CDPConfigKey

use of com.sequenceiq.datalake.service.sdx.CDPConfigKey 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)

Aggregations

CDPConfigKey (com.sequenceiq.datalake.service.sdx.CDPConfigKey)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 Entitlement (com.sequenceiq.cloudbreak.auth.altus.model.Entitlement)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 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 Arrays (java.util.Arrays)1