ClusterBlueprintRenderer extends BaseRenderer implements Renderer { @Override public Result finalizeResult(Result queryResult) { TreeNode<Resource> resultTree = queryResult.getResultTree(); Result result = new ResultImpl(true); TreeNode<Resource> blueprintResultTree = result.getResultTree(); if (isCollection(resultTree)) { blueprintResultTree.setProperty("isCollection", "true"); } for (TreeNode<Resource> node : resultTree.getChildren()) { Resource blueprintResource = createBlueprintResource(node); blueprintResultTree.addChild(new TreeNodeImpl<Resource>( blueprintResultTree, blueprintResource, node.getName())); } return result; }  @Override TreeNode<Set<String>> finalizeProperties(
      TreeNode<QueryInfo> queryProperties, boolean isCollection); @Override Result finalizeResult(Result queryResult); @Override ResultPostProcessor getResultPostProcessor(Request request); @Override boolean requiresPropertyProviderInput();  }
@Test public void testGetSettings_instance(){ Result result = new ResultImpl(true); TreeNode<Resource> resultTree = createResultTreeSettingsObject(result.getResultTree()); ClusterBlueprintRenderer renderer = new TestBlueprintRenderer(topology); Result blueprintResult = renderer.finalizeResult(result); TreeNode<Resource> blueprintTree = blueprintResult.getResultTree(); TreeNode<Resource> blueprintNode = blueprintTree.getChildren().iterator().next(); Resource blueprintResource = blueprintNode.getObject(); Map<String, Map<String, Object>> propertiesMap = blueprintResource.getPropertiesMap(); Map<String,Object> children = propertiesMap.get(""); assertTrue(children.containsKey("settings")); List<Map<String,Object>> settingValues = (ArrayList)children.get("settings"); Boolean isRecoverySettings = false; Boolean isComponentSettings = false; Boolean isServiceSettings = false; for(Map<String,Object> settingProp : settingValues){ if(settingProp.containsKey("recovery_settings")){ isRecoverySettings = true; HashSet<Map<String,String>> checkPropSize = (HashSet)settingProp.get("recovery_settings"); assertEquals(1,checkPropSize.size()); assertEquals("true",checkPropSize.iterator().next().get("recovery_enabled")); } if(settingProp.containsKey("component_settings")){ isComponentSettings = true; HashSet<Map<String,String>> checkPropSize = (HashSet)settingProp.get("component_settings"); assertEquals(1,checkPropSize.size()); Map<String, String> finalProp = checkPropSize.iterator().next(); assertEquals("Component:1",finalProp.get("name")); assertEquals("true",finalProp.get("recovery_enabled")); } if(settingProp.containsKey("service_settings")){ isServiceSettings = true; HashSet<Map<String,String>> checkPropSize = (HashSet)settingProp.get("service_settings"); assertEquals(2,checkPropSize.size()); for(Map<String,String> finalProp : checkPropSize){ if(finalProp.containsKey("credential_store_enabled")){ assertEquals("Service:1",finalProp.get("name")); assertEquals("true",finalProp.get("recovery_enabled")); } assertFalse(finalProp.get("name").equals("Service:3")); } } } assertTrue(isRecoverySettings); assertTrue(isComponentSettings); assertTrue(isServiceSettings); }
@Test public void testFinalizeResult_kerberos() throws Exception{ setupMocksForKerberosEnabledCluster(); Result result = new ResultImpl(true); createClusterResultTree(result.getResultTree()); ClusterBlueprintRenderer renderer = new TestBlueprintRenderer(topology); Result blueprintResult = renderer.finalizeResult(result); TreeNode<Resource> blueprintTree = blueprintResult.getResultTree(); assertNull(blueprintTree.getStringProperty("isCollection")); assertEquals(1, blueprintTree.getChildren().size()); TreeNode<Resource> blueprintNode = blueprintTree.getChildren().iterator().next(); assertEquals(0, blueprintNode.getChildren().size()); Resource blueprintResource = blueprintNode.getObject(); Map<String, Map<String, Object>> properties = blueprintResource.getPropertiesMap(); assertEquals("HDP", properties.get("Blueprints").get("stack_name")); assertEquals("1.3.3", properties.get("Blueprints").get("stack_version")); Map<String, Object> securityProperties = (Map<String, Object>) properties.get("Blueprints").get("security"); assertEquals("KERBEROS", securityProperties.get("type")); assertNotNull(((Map<String, Object>) securityProperties.get("kerberos_descriptor")).get("properties")); }
@Test public void testFinalizeResult() throws Exception{ Result result = new ResultImpl(true); createClusterResultTree(result.getResultTree()); ClusterBlueprintRenderer renderer = new TestBlueprintRenderer(topology); Result blueprintResult = renderer.finalizeResult(result); TreeNode<Resource> blueprintTree = blueprintResult.getResultTree(); assertNull(blueprintTree.getStringProperty("isCollection")); assertEquals(1, blueprintTree.getChildren().size()); TreeNode<Resource> blueprintNode = blueprintTree.getChildren().iterator().next(); assertEquals(0, blueprintNode.getChildren().size()); Resource blueprintResource = blueprintNode.getObject(); Map<String, Map<String, Object>> properties = blueprintResource.getPropertiesMap(); assertEquals("HDP", properties.get("Blueprints").get("stack_name")); assertEquals("1.3.3", properties.get("Blueprints").get("stack_version")); Collection<Map<String, Object>> host_groups = (Collection<Map<String, Object>>) properties.get("").get("host_groups"); assertEquals(2, host_groups.size()); for (Map<String, Object> hostGroupProperties : host_groups) { String host_group_name = (String) hostGroupProperties.get("name"); if (host_group_name.equals("host_group_1")) { assertEquals("1", hostGroupProperties.get("cardinality")); Collection<Map<String, String>> components = (Collection<Map<String, String>>) hostGroupProperties.get("components"); assertEquals(5, components.size()); Set<String> expectedValues = new HashSet<String>( Arrays.asList("JOBTRACKER", "TASKTRACKER", "NAMENODE", "DATANODE", "AMBARI_SERVER")); Set<String> actualValues = new HashSet<String>(); for (Map<String, String> componentProperties : components) { assertEquals(1, componentProperties.size()); actualValues.add(componentProperties.get("name")); } assertEquals(expectedValues, actualValues); } else if (host_group_name.equals("host_group_2")) { assertEquals("2", hostGroupProperties.get("cardinality")); Collection<Map<String, String>> components = (Collection<Map<String, String>>) hostGroupProperties.get("components"); assertEquals(2, components.size()); Set<String> expectedValues = new HashSet<String>( Arrays.asList("TASKTRACKER", "DATANODE")); Set<String> actualValues = new HashSet<String>(); for (Map<String, String> componentProperties : components) { assertEquals(1, componentProperties.size()); actualValues.add(componentProperties.get("name")); } assertEquals(expectedValues, actualValues); } } }
@Test public void testFinalizeResultWithAttributes() throws Exception{ ServiceInfo hdfsService = new ServiceInfo(); hdfsService.setName("HDFS"); ServiceInfo mrService = new ServiceInfo(); mrService.setName("MAPREDUCE"); Result result = new ResultImpl(true); Map<String, Object> testDesiredConfigMap = new HashMap<String, Object>(); DesiredConfig testDesiredConfig = new DesiredConfig(); testDesiredConfig.setTag("test-tag-one"); testDesiredConfigMap.put("test-type-one", testDesiredConfig); createClusterResultTree(result.getResultTree(), testDesiredConfigMap); ClusterBlueprintRenderer renderer = new TestBlueprintRenderer(topology); Result blueprintResult = renderer.finalizeResult(result); TreeNode<Resource> blueprintTree = blueprintResult.getResultTree(); assertNull(blueprintTree.getStringProperty("isCollection")); assertEquals(1, blueprintTree.getChildren().size()); TreeNode<Resource> blueprintNode = blueprintTree.getChildren().iterator().next(); assertEquals(0, blueprintNode.getChildren().size()); Resource blueprintResource = blueprintNode.getObject(); Map<String, Map<String, Object>> properties = blueprintResource.getPropertiesMap(); assertEquals("HDP", properties.get("Blueprints").get("stack_name")); assertEquals("1.3.3", properties.get("Blueprints").get("stack_version")); Collection<Map<String, Object>> host_groups = (Collection<Map<String, Object>>) properties.get("").get("host_groups"); assertEquals(2, host_groups.size()); for (Map<String, Object> hostGroupProperties : host_groups) { String host_group_name = (String) hostGroupProperties.get("name"); if (host_group_name.equals("host_group_1")) { assertEquals("1", hostGroupProperties.get("cardinality")); Collection<Map<String, String>> components = (Collection<Map<String, String>>) hostGroupProperties.get("components"); assertEquals(5, components.size()); Set<String> expectedValues = new HashSet<String>( Arrays.asList("JOBTRACKER", "TASKTRACKER", "NAMENODE", "DATANODE", "AMBARI_SERVER")); Set<String> actualValues = new HashSet<String>(); for (Map<String, String> componentProperties : components) { assertEquals(1, componentProperties.size()); actualValues.add(componentProperties.get("name")); } assertEquals(expectedValues, actualValues); } else if (host_group_name.equals("host_group_2")) { assertEquals("2", hostGroupProperties.get("cardinality")); Collection<Map<String, String>> components = (Collection<Map<String, String>>) hostGroupProperties.get("components"); assertEquals(2, components.size()); Set<String> expectedValues = new HashSet<String>( Arrays.asList("TASKTRACKER", "DATANODE")); Set<String> actualValues = new HashSet<String>(); for (Map<String, String> componentProperties : components) { assertEquals(1, componentProperties.size()); actualValues.add(componentProperties.get("name")); } assertEquals(expectedValues, actualValues); } } List<Map<String, Map<String, Map<String, ?>>>> configurationsResult = (List<Map<String, Map<String, Map<String, ?>>>>)blueprintResource.getPropertyValue("configurations"); assertEquals("Incorrect number of config maps added", 1, configurationsResult.size()); Map<String, Map<String, ?>> configMap = configurationsResult.iterator().next().get("test-type-one"); assertNotNull("Expected config map was not included", configMap); assertEquals("Incorrect number of maps added under expected type", 2, configMap.size()); assertTrue("Expected properties map was not found", configMap.containsKey("properties")); assertTrue("Expected properties_attributes map was not found", configMap.containsKey("properties_attributes")); Map<String, ?> propertiesResult = configMap.get("properties"); assertEquals("Incorrect number of config properties found", 1, propertiesResult.size()); Map<String, ?> attributesResult = configMap.get("properties_attributes"); assertEquals("Incorrect number of config attributes found", 1, attributesResult.size()); assertEquals("Incorrect property value included", "valueOne", propertiesResult.get("propertyOne")); assertNotNull("Expected attribute not found in exported Blueprint", attributesResult.get("final")); assertTrue("Attribute type map was not included", attributesResult.get("final") instanceof Map); Map<String, ?> finalMap = (Map<String, ?>)attributesResult.get("final"); assertEquals("Attribute value is not correct", "true", finalMap.get("propertyOne")); }