use of com.cloudera.api.swagger.model.ApiClusterTemplateRoleConfigGroup in project cloudbreak by hortonworks.
the class StackResponseUtils method getRoleConfigNameForHostGroup.
public String getRoleConfigNameForHostGroup(StackV4Response stackResponse, String hostGroupName, String serviceType, String roleType) throws Exception {
String template = stackResponse.getCluster().getBlueprint().getBlueprint();
ApiClusterTemplate cmTemplate = JsonUtil.readValue(template, ApiClusterTemplate.class);
Set<String> hostGroupRoleConfigNames = cmTemplate.getHostTemplates().stream().filter(clusterTemplate -> clusterTemplate.getRefName().equalsIgnoreCase(hostGroupName)).findFirst().map(ApiClusterTemplateHostTemplate::getRoleConfigGroupsRefNames).orElse(List.of()).stream().collect(Collectors.toSet());
String roleReferenceName = cmTemplate.getServices().stream().filter(s -> s.getServiceType().equalsIgnoreCase(serviceType)).findFirst().map(ApiClusterTemplateService::getRoleConfigGroups).orElse(List.of()).stream().filter(rcg -> rcg.getRoleType().equalsIgnoreCase(roleType)).filter(rcg -> hostGroupRoleConfigNames.contains(rcg.getRefName())).map(ApiClusterTemplateRoleConfigGroup::getRefName).findFirst().orElseThrow(() -> new Exception(String.format("Unable to retrieve RoleConfigGroupRefName for Service '%s', RoleType '%s'," + " HostGroup '%s', Cluster '%s'", serviceType, roleType, hostGroupName, stackResponse.getCrn())));
return roleReferenceName;
}
use of com.cloudera.api.swagger.model.ApiClusterTemplateRoleConfigGroup in project cloudbreak by hortonworks.
the class RangerRazDatalakeConfigProviderTest method getAdditionalServicesWhenRazIsEnabledWithRightCm.
@ParameterizedTest(name = "{0}")
@MethodSource("razCloudPlatformAndCmVersionDataProvider")
@DisplayName("DL is used with the right CM and Raz is requested, Raz service needs to be added to the template")
void getAdditionalServicesWhenRazIsEnabledWithRightCm(String testCaseName, CloudPlatform cloudPlatform, String cmVersion) {
ClouderaManagerRepo cmRepo = new ClouderaManagerRepo();
cmRepo.setVersion(cmVersion);
GeneralClusterConfigs generalClusterConfigs = new GeneralClusterConfigs();
generalClusterConfigs.setEnableRangerRaz(true);
HostgroupView master = new HostgroupView("master", 0, InstanceGroupType.GATEWAY, List.of());
HostgroupView idbroker = new HostgroupView("idbroker", 0, InstanceGroupType.CORE, List.of());
TemplatePreparationObject preparationObject = Builder.builder().withStackType(StackType.DATALAKE).withCloudPlatform(cloudPlatform).withProductDetails(cmRepo, List.of()).withGeneralClusterConfigs(generalClusterConfigs).withHostgroupViews(Set.of(master, idbroker)).build();
Map<String, ApiClusterTemplateService> additionalServices = configProvider.getAdditionalServices(cmTemplateProcessor, preparationObject);
ApiClusterTemplateService service = additionalServices.get("master");
List<ApiClusterTemplateRoleConfigGroup> roleConfigGroups = service.getRoleConfigGroups();
Assertions.assertAll(() -> assertEquals(1, additionalServices.size()), () -> assertEquals("RANGER_RAZ", service.getServiceType()), () -> assertEquals("ranger-RANGER_RAZ", service.getRefName()), () -> assertEquals("RANGER_RAZ_SERVER", roleConfigGroups.get(0).getRoleType()), () -> assertEquals("ranger-RANGER_RAZ_SERVER", roleConfigGroups.get(0).getRefName()));
}
use of com.cloudera.api.swagger.model.ApiClusterTemplateRoleConfigGroup in project cloudbreak by hortonworks.
the class CmHostGroupRoleConfigProviderProcessor method updateConfigsInTemplate.
private void updateConfigsInTemplate(CmTemplateProcessor templateProcessor, Map<String, Map<String, List<ApiClusterTemplateConfig>>> newConfigsByRCG) {
List<ApiClusterTemplateHostTemplate> hostTemplates = getHostTemplates(templateProcessor);
Map<String, ApiClusterTemplateService> serviceByRCG = templateProcessor.getTemplate().getServices().stream().flatMap(service -> ofNullable(service.getRoleConfigGroups()).orElseGet(List::of).stream().map(rcg -> Pair.of(rcg, service))).collect(toMap(pair -> pair.getLeft().getRefName(), Pair::getRight));
Map<String, ApiClusterTemplateRoleConfigGroup> roleConfigGroupByName = templateProcessor.getTemplate().getServices().stream().flatMap(service -> ofNullable(service.getRoleConfigGroups()).orElseGet(List::of).stream()).collect(toMap(ApiClusterTemplateRoleConfigGroup::getRefName, Function.identity()));
ApiClusterTemplateInstantiator instantiator = templateProcessor.getTemplate().getInstantiator();
List<ApiClusterTemplateRoleConfigGroupInfo> instantiatorRoleConfigGroups = instantiator.getRoleConfigGroups();
for (Map.Entry<String, Map<String, List<ApiClusterTemplateConfig>>> entry : newConfigsByRCG.entrySet()) {
String configGroupName = entry.getKey();
ApiClusterTemplateRoleConfigGroup configGroup = roleConfigGroupByName.get(configGroupName);
ApiClusterTemplateService templateService = serviceByRCG.get(configGroupName);
Map<String, List<ApiClusterTemplateConfig>> configsByHostGroup = entry.getValue();
int groupCount = configsByHostGroup.size();
Optional<CmHostGroupRoleConfigProvider> provider = providers.stream().filter(it -> it.getServiceType().equals(templateService.getServiceType())).findFirst();
boolean sharedRoleType = true;
if (provider.isPresent()) {
sharedRoleType = provider.get().sharedRoleType(configGroup.getRoleType());
}
if (groupCount == 1 || sharedRoleType) {
templateProcessor.mergeRoleConfigs(configGroup, configsByHostGroup.values().iterator().next());
} else if (groupCount > 1) {
LOGGER.debug("Cloning config group {} into {} host groups: {}", configGroupName, groupCount, configsByHostGroup.keySet());
// "clone" config group for each host group
Map<String, ApiClusterTemplateRoleConfigGroup> clonesByHostGroup = configsByHostGroup.keySet().stream().map(hostGroupName -> Pair.of(hostGroupName, copyForHostGroup(configGroup, hostGroupName))).collect(toMap(Pair::getKey, Pair::getValue));
// add host group-specific configs to clones
configsByHostGroup.forEach((hostGroupName, newConfigs) -> templateProcessor.mergeRoleConfigs(clonesByHostGroup.get(hostGroupName), newConfigs));
// remove original from service
ApiClusterTemplateService service = serviceByRCG.get(configGroupName);
service.getRoleConfigGroups().removeIf(group -> Objects.equals(group.getRefName(), configGroupName));
// remove original from instantiator
if (instantiatorRoleConfigGroups != null) {
instantiatorRoleConfigGroups.removeIf(groupInfo -> Objects.equals(groupInfo.getRcgRefName(), configGroupName));
}
// add clones to service
service.getRoleConfigGroups().addAll(clonesByHostGroup.values());
// add clones to instantiator
clonesByHostGroup.values().forEach(group -> instantiator.addRoleConfigGroupsItem(new ApiClusterTemplateRoleConfigGroupInfo().rcgRefName(group.getRefName())));
// replace references in host groups
for (ApiClusterTemplateHostTemplate hostTemplate : hostTemplates) {
ApiClusterTemplateRoleConfigGroup rcgForHostGroup = clonesByHostGroup.get(hostTemplate.getRefName());
if (rcgForHostGroup != null) {
hostTemplate.getRoleConfigGroupsRefNames().remove(configGroupName);
hostTemplate.getRoleConfigGroupsRefNames().add(rcgForHostGroup.getRefName());
}
}
}
}
}
use of com.cloudera.api.swagger.model.ApiClusterTemplateRoleConfigGroup in project cloudbreak by hortonworks.
the class CmHostGroupRoleConfigProviderProcessor method copyForHostGroup.
private ApiClusterTemplateRoleConfigGroup copyForHostGroup(ApiClusterTemplateRoleConfigGroup original, String hostGroupName) {
String displayName = original.getDisplayName() != null ? (original.getDisplayName() + " in host group " + hostGroupName) : null;
String refName = original.getRefName().replaceAll("[^-]+$", hostGroupName);
return new ApiClusterTemplateRoleConfigGroup().base(false).configs(original.getConfigs()).displayName(displayName).refName(refName).roleType(original.getRoleType());
}
use of com.cloudera.api.swagger.model.ApiClusterTemplateRoleConfigGroup in project cloudbreak by hortonworks.
the class CmTemplateProcessorTest method testIfCustomRoleConfigsAreMerged.
@Test
public void testIfCustomRoleConfigsAreMerged() {
underTest = new CmTemplateProcessor(getBlueprintText("input/de-ha.bp"));
// present in cluster template/blueprint
List<ApiClusterTemplateConfig> hs2RoleConfigs = List.of(new ApiClusterTemplateConfig().name("hiveserver2_mv_files_thread").value("30"));
List<ApiClusterTemplateRoleConfigGroup> hs2Rcg = List.of(new ApiClusterTemplateRoleConfigGroup().roleType("hiveserver2").configs(hs2RoleConfigs));
// not present in cluster template/blueprint
List<ApiClusterTemplateConfig> gatewayRoleConfigs = List.of(new ApiClusterTemplateConfig().name("hive_client_java_heapsize").value("6442450944"));
List<ApiClusterTemplateRoleConfigGroup> gatewayRcg = List.of(new ApiClusterTemplateRoleConfigGroup().roleType("gateway").configs(gatewayRoleConfigs));
ApiClusterTemplateService hive = underTest.getTemplate().getServices().stream().filter(service -> "HIVE_ON_TEZ".equals(service.getServiceType())).findFirst().get();
List<ApiClusterTemplateConfig> existingGatewayConfigs = hive.getRoleConfigGroups().get(0).getConfigs();
List<ApiClusterTemplateConfig> existingHs2Configs = hive.getRoleConfigGroups().get(1).getConfigs();
underTest.mergeCustomRoleConfigs(hive, hs2Rcg);
underTest.mergeCustomRoleConfigs(hive, gatewayRcg);
assertEquals(existingHs2Configs.size(), hive.getRoleConfigGroups().get(1).getConfigs().size());
assertEquals((existingGatewayConfigs == null ? 0 : existingGatewayConfigs.size()) + gatewayRoleConfigs.size(), hive.getRoleConfigGroups().get(0).getConfigs().size());
}
Aggregations