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);
}
}
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;
}
Aggregations