Search in sources :

Example 1 with ServiceAttributes

use of com.sequenceiq.cloudbreak.template.model.ServiceAttributes 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());
}
Also used : HashMap(java.util.HashMap) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) SaltPillarProperties(com.sequenceiq.cloudbreak.orchestrator.model.SaltPillarProperties) ServiceAttributes(com.sequenceiq.cloudbreak.template.model.ServiceAttributes) CmTemplateProcessor(com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 2 with ServiceAttributes

use of com.sequenceiq.cloudbreak.template.model.ServiceAttributes in project cloudbreak by hortonworks.

the class CmTemplateProcessorTest method testYARNServiceAttributes.

@Test
public void testYARNServiceAttributes() {
    Versioned blueprintVersion = () -> "7.2.11";
    underTest = new CmTemplateProcessor(getBlueprintText("input/custom-hostgroups-for-nms.bp"));
    assertEquals(7, underTest.getHostTemplateNames().size());
    Map<String, Map<String, ServiceAttributes>> attrs = underTest.getHostGroupBasedServiceAttributes(blueprintVersion);
    assertEquals(4, attrs.size());
    Map<String, ServiceAttributes> serviceAttributesMap;
    serviceAttributesMap = attrs.get("worker");
    assertEquals(1, serviceAttributesMap.get(YarnRoles.YARN).getAttributes().size());
    assertEquals(YarnConstants.ATTRIBUTE_NAME_NODE_INSTANCE_TYPE, serviceAttributesMap.get(YarnRoles.YARN).getAttributes().keySet().iterator().next());
    assertEquals(YarnConstants.ATTRIBUTE_NODE_INSTANCE_TYPE_WORKER, serviceAttributesMap.get(YarnRoles.YARN).getAttributes().values().iterator().next());
    serviceAttributesMap = attrs.get("compute");
    assertEquals(1, serviceAttributesMap.get(YarnRoles.YARN).getAttributes().size());
    assertEquals(YarnConstants.ATTRIBUTE_NAME_NODE_INSTANCE_TYPE, serviceAttributesMap.get(YarnRoles.YARN).getAttributes().keySet().iterator().next());
    assertEquals(YarnConstants.ATTRIBUTE_NODE_INSTANCE_TYPE_COMPUTE, serviceAttributesMap.get(YarnRoles.YARN).getAttributes().values().iterator().next());
    // Verify that custom hostGroup names also get marked as "compute" or "worker"
    serviceAttributesMap = attrs.get("customnm1");
    assertEquals(1, serviceAttributesMap.get(YarnRoles.YARN).getAttributes().size());
    assertEquals(YarnConstants.ATTRIBUTE_NAME_NODE_INSTANCE_TYPE, serviceAttributesMap.get(YarnRoles.YARN).getAttributes().keySet().iterator().next());
    assertEquals(YarnConstants.ATTRIBUTE_NODE_INSTANCE_TYPE_WORKER, serviceAttributesMap.get(YarnRoles.YARN).getAttributes().values().iterator().next());
    serviceAttributesMap = attrs.get("customnm2");
    assertEquals(1, serviceAttributesMap.get(YarnRoles.YARN).getAttributes().size());
    assertEquals(YarnConstants.ATTRIBUTE_NAME_NODE_INSTANCE_TYPE, serviceAttributesMap.get(YarnRoles.YARN).getAttributes().keySet().iterator().next());
    assertEquals(YarnConstants.ATTRIBUTE_NODE_INSTANCE_TYPE_COMPUTE, serviceAttributesMap.get(YarnRoles.YARN).getAttributes().values().iterator().next());
}
Also used : Versioned(com.sequenceiq.cloudbreak.common.type.Versioned) ServiceAttributes(com.sequenceiq.cloudbreak.template.model.ServiceAttributes) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) Test(org.junit.jupiter.api.Test)

Aggregations

ServiceAttributes (com.sequenceiq.cloudbreak.template.model.ServiceAttributes)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 CmTemplateProcessor (com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor)1 Node (com.sequenceiq.cloudbreak.common.orchestration.Node)1 Versioned (com.sequenceiq.cloudbreak.common.type.Versioned)1 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)1 SaltPillarProperties (com.sequenceiq.cloudbreak.orchestrator.model.SaltPillarProperties)1 TreeMap (java.util.TreeMap)1 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1