use of com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor in project cloudbreak by hortonworks.
the class HostAttributeDecoratorTest method testAddHostAttributes.
@Test
public void testAddHostAttributes() {
Blueprint blueprint = mock(Blueprint.class);
when(stack.getCluster()).thenReturn(cluster);
when(cluster.getBlueprint()).thenReturn(blueprint);
when(stackUtil.collectNodes(any())).thenReturn(Set.of(new Node(null, null, null, null, "fqdn1", "hg1"), new Node(null, null, null, null, "fqdn2", "hg2"), new Node(null, null, null, null, "fqdn3", "hg3"), new Node(null, null, null, null, "fqdn4", null)));
when(blueprint.getBlueprintText()).thenReturn("");
Map<String, Map<String, ServiceAttributes>> yarnAttrs = new HashMap<>();
yarnAttrs.put("hg3", Collections.singletonMap(YarnRoles.YARN, new ServiceAttributes(ServiceComponent.of(YarnRoles.YARN, YarnRoles.NODEMANAGER), Collections.singletonMap(YarnConstants.ATTRIBUTE_NAME_NODE_INSTANCE_TYPE, YarnConstants.ATTRIBUTE_NODE_INSTANCE_TYPE_COMPUTE))));
CmTemplateProcessor blueprintTextProcessor = mock(CmTemplateProcessor.class);
when(blueprintTextProcessor.getHostGroupBasedServiceAttributes(any())).thenReturn(yarnAttrs);
when(cmTemplateProcessorFactory.get(any(String.class))).thenReturn(blueprintTextProcessor);
Map<String, SaltPillarProperties> result = underTest.createHostAttributePillars(stack);
SaltPillarProperties resultPillar = result.get("hostattrs");
assertEquals("/nodes/hostattrs.sls", resultPillar.getPath());
Map<String, Object> props = resultPillar.getProperties();
Map<String, Object> values = (Map<String, Object>) props.get("hostattrs");
assertEquals(4, values.size());
assertNotNull(values.get("fqdn1"));
assertNotNull(values.get("fqdn2"));
assertNotNull(values.get("fqdn3"));
assertNotNull(values.get("fqdn4"));
Map<String, Object> nodeValue;
Map<String, Map<String, String>> attrs = null;
nodeValue = (Map<String, Object>) values.get("fqdn1");
assertEquals(2, nodeValue.size());
assertEquals("hg1", nodeValue.get("hostGroup"));
attrs = (Map<String, Map<String, String>>) nodeValue.get("attributes");
assertEquals(0, attrs.size());
nodeValue = (Map<String, Object>) values.get("fqdn2");
assertEquals(2, nodeValue.size());
assertEquals("hg2", nodeValue.get("hostGroup"));
attrs = (Map<String, Map<String, String>>) nodeValue.get("attributes");
assertEquals(0, attrs.size());
nodeValue = (Map<String, Object>) values.get("fqdn3");
assertEquals(2, nodeValue.size());
assertEquals("hg3", nodeValue.get("hostGroup"));
attrs = (Map<String, Map<String, String>>) nodeValue.get("attributes");
assertEquals(1, attrs.size());
assertEquals(1, attrs.get(YarnRoles.YARN).size());
assertEquals(YarnConstants.ATTRIBUTE_NAME_NODE_INSTANCE_TYPE, attrs.get(YarnRoles.YARN).entrySet().iterator().next().getKey());
assertEquals(YarnConstants.ATTRIBUTE_NODE_INSTANCE_TYPE_COMPUTE, attrs.get(YarnRoles.YARN).entrySet().iterator().next().getValue());
nodeValue = (Map<String, Object>) values.get("fqdn4");
assertEquals(1, nodeValue.size());
attrs = (Map<String, Map<String, String>>) nodeValue.get("attributes");
assertEquals(0, attrs.size());
}
use of com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor in project cloudbreak by hortonworks.
the class ServiceEndpointCollector method getExposedServices.
/**
* Get all exposed services for blueprint, there are filtered by visibility
*
* @param blueprintText given blueprintText
* @return all visible exposed services for the given blueprint
*/
private Collection<ExposedService> getExposedServices(String blueprintText, List<String> entitlements) {
CmTemplateProcessor processor = cmTemplateProcessorFactory.get(blueprintText);
List<String> components = processor.getAllComponents().stream().map(ServiceComponent::getComponent).collect(Collectors.toList());
return exposedServiceCollector.knoxServicesForComponents(processor.getVersion(), components).stream().filter(ExposedService::isVisible).filter(e -> serviceEndpointCollectorEntitlementComparator.entitlementSupported(entitlements, e.getEntitlement())).collect(Collectors.toList());
}
use of com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor in project cloudbreak by hortonworks.
the class LoadBalancerConfigService method getOozieHAInstanceGroup.
private Optional<InstanceGroup> getOozieHAInstanceGroup(Stack stack) {
Cluster cluster = stack.getCluster();
if (cluster != null) {
CmTemplateProcessor cmTemplateProcessor = new CmTemplateProcessor(cluster.getBlueprint().getBlueprintText());
String cdhVersion = cmTemplateProcessor.getStackVersion();
if (cdhVersion != null && isVersionNewerOrEqualThanLimited(cdhVersion, CLOUDERA_STACK_VERSION_7_2_11)) {
Set<String> oozieGroupNames = getOozieGroups(cmTemplateProcessor);
return stack.getInstanceGroups().stream().filter(ig -> oozieGroupNames.contains(ig.getGroupName())).filter(ig -> ig.getNodeCount() > 1).findFirst();
}
}
return Optional.empty();
}
use of com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor in project cloudbreak by hortonworks.
the class ComponentLocatorService method getImpalaCoordinatorLocations.
public Map<String, List<String>> getImpalaCoordinatorLocations(Cluster cluster) {
Map<String, List<String>> result = new HashMap<>();
String blueprintText = cluster.getBlueprint().getBlueprintText();
CmTemplateProcessor processor = cmTemplateProcessorFactory.get(blueprintText);
for (HostGroup hg : hostGroupService.getByCluster(cluster.getId())) {
Set<String> hgComponents = new HashSet<>(processor.getImpalaCoordinatorsInHostGroup(hg.getName()));
fillList(result, hg, hgComponents);
}
return result;
}
use of com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor in project cloudbreak by hortonworks.
the class ClusterDiagnosticsService method getClusterComponents.
public List<String> getClusterComponents(String stackCrn) {
List<String> components = new ArrayList<>();
Stack stack = stackService.getByCrn(stackCrn);
if (stack != null) {
Cluster cluster = stack.getCluster();
if (cluster != null && cluster.getBlueprint() != null) {
CmTemplateProcessor cmTemplateProcessor = cmTemplateProcessorFactory.get(cluster.getBlueprint().getBlueprintText());
components = cmTemplateProcessor.getAllComponents().stream().map(ServiceComponent::getComponent).collect(Collectors.toCollection(ArrayList::new));
}
}
return components;
}
Aggregations