use of com.cloudera.api.swagger.model.ApiClusterTemplateRoleConfigGroupInfo in project cloudbreak by hortonworks.
the class CmTemplateProcessorTest method testAddInstantiatorWithBaseRoles.
@Test
public void testAddInstantiatorWithBaseRoles() {
underTest = new CmTemplateProcessor(getBlueprintText("input/clouderamanager.bp"));
ClouderaManagerRepo clouderaManagerRepoDetails = new ClouderaManagerRepo();
clouderaManagerRepoDetails.setVersion(CMRepositoryVersionUtil.CLOUDERAMANAGER_VERSION_6_3_0.getVersion());
GeneralClusterConfigs generalClusterConfigs = new GeneralClusterConfigs();
generalClusterConfigs.setClusterName("cluster");
TemplatePreparationObject.Builder tpoBuilder = new TemplatePreparationObject.Builder().withGeneralClusterConfigs(generalClusterConfigs);
TemplatePreparationObject templatePreparationObject = tpoBuilder.build();
underTest.addInstantiator(clouderaManagerRepoDetails, templatePreparationObject, "dszabo-sdx");
ApiClusterTemplateInstantiator instantiator = underTest.getTemplate().getInstantiator();
List<ApiClusterTemplateRoleConfigGroupInfo> roleConfigGroups = instantiator.getRoleConfigGroups();
List<String> refNames = roleConfigGroups.stream().map(ApiClusterTemplateRoleConfigGroupInfo::getRcgRefName).collect(Collectors.toList());
assertEquals(2, refNames.size());
assertTrue(refNames.containsAll(List.of("yarn-NODEMANAGER-BASE", "hdfs-DATANODE-BASE")));
assertEquals("cluster", instantiator.getClusterName());
}
use of com.cloudera.api.swagger.model.ApiClusterTemplateRoleConfigGroupInfo in project cloudbreak by hortonworks.
the class CmTemplateProcessor method addInstantiator.
public void addInstantiator(ClouderaManagerRepo clouderaManagerRepoDetails, TemplatePreparationObject templatePreparationObject, String sdxContextName) {
ApiClusterTemplateInstantiator instantiator = ofNullable(cmTemplate.getInstantiator()).orElseGet(ApiClusterTemplateInstantiator::new);
if (instantiator.getClusterName() == null) {
instantiator.setClusterName(templatePreparationObject.getGeneralClusterConfigs().getClusterName());
}
addCmVersionDependantConfigs(clouderaManagerRepoDetails, templatePreparationObject, instantiator);
for (ApiClusterTemplateService service : ofNullable(cmTemplate.getServices()).orElse(List.of())) {
List<String> nonBaseRefs = ofNullable(service.getRoleConfigGroups()).orElse(List.of()).stream().filter(rcg -> rcg.getBase() == null || !rcg.getBase()).map(ApiClusterTemplateRoleConfigGroup::getRefName).collect(Collectors.toList());
for (String nonBaseRef : nonBaseRefs) {
instantiator.addRoleConfigGroupsItem(new ApiClusterTemplateRoleConfigGroupInfo().rcgRefName(nonBaseRef));
}
}
ofNullable(sdxContextName).map(name -> List.of(new ApiDataContextRef().name(name))).map(apiDataContextRefs -> new ApiClusterTemplateClusterSpec().dataContextRefs(apiDataContextRefs)).ifPresent(instantiator::clusterSpec);
cmTemplate.setInstantiator(instantiator);
}
use of com.cloudera.api.swagger.model.ApiClusterTemplateRoleConfigGroupInfo 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.ApiClusterTemplateRoleConfigGroupInfo in project cloudbreak by hortonworks.
the class CmTemplateProcessorTest method testAddInstantiatorWithoutBaseRoles.
@Test
public void testAddInstantiatorWithoutBaseRoles() {
underTest = new CmTemplateProcessor(getBlueprintText("input/clouderamanager-custom-ref.bp"));
ClouderaManagerRepo clouderaManagerRepoDetails = new ClouderaManagerRepo();
clouderaManagerRepoDetails.setVersion(CMRepositoryVersionUtil.CLOUDERAMANAGER_VERSION_6_3_0.getVersion());
GeneralClusterConfigs generalClusterConfigs = new GeneralClusterConfigs();
generalClusterConfigs.setClusterName("cluster");
TemplatePreparationObject.Builder tpoBuilder = new TemplatePreparationObject.Builder().withGeneralClusterConfigs(generalClusterConfigs);
TemplatePreparationObject templatePreparationObject = tpoBuilder.build();
underTest.addInstantiator(clouderaManagerRepoDetails, templatePreparationObject, "dszabo-sdx");
ApiClusterTemplateInstantiator instantiator = underTest.getTemplate().getInstantiator();
List<ApiClusterTemplateRoleConfigGroupInfo> roleConfigGroups = instantiator.getRoleConfigGroups();
assertNull(roleConfigGroups);
}
Aggregations