@Test public void testPopulateConfigurationList() throws Exception { StackEntity stackEntity = new StackEntity(); stackEntity.setStackName("test-stack-name"); stackEntity.setStackVersion("test-stack-version"); BlueprintEntity entity = createMock(BlueprintEntity.class); expect(entity.getStack()).andReturn(stackEntity).anyTimes(); HashMap<PropertyInfo.PropertyType, Set<String>> pwdProperties = new HashMap<PropertyInfo.PropertyType, Set<String>>() {{ put(PropertyInfo.PropertyType.PASSWORD, new HashSet<String>(){{ add("test.password"); }}); }}; StackInfo info = createMock(StackInfo.class); expect(info.getConfigPropertiesTypes("type1")).andReturn(new HashMap<PropertyInfo.PropertyType, Set<String>>()).anyTimes(); expect(info.getConfigPropertiesTypes("type2")).andReturn(new HashMap<PropertyInfo.PropertyType, Set<String>>()).anyTimes(); expect(info.getConfigPropertiesTypes("type3")).andReturn(pwdProperties).anyTimes(); expect(metaInfo.getStack("test-stack-name", "test-stack-version")).andReturn(info).anyTimes(); replay(info, metaInfo, entity); BlueprintConfigEntity config1 = new BlueprintConfigEntity(); config1.setType("type1"); config1.setConfigData("{\"key1\":\"value1\"}"); config1.setBlueprintEntity(entity); BlueprintConfigEntity config2 = new BlueprintConfigEntity(); config2.setType("type2"); config2.setConfigData("{\"key2\":\"value2\"}"); config2.setConfigAttributes("{}"); config2.setBlueprintEntity(entity); BlueprintConfigEntity config3 = new BlueprintConfigEntity(); config3.setType("type3"); config3.setConfigData("{\"key3\":\"value3\",\"key4\":\"value4\",\"test.password\":\"pwdValue\"}"); config3.setConfigAttributes("{\"final\":{\"key3\":\"attrValue1\",\"key4\":\"attrValue2\"}}"); config3.setBlueprintEntity(entity); List<Map<String, Map<String, Object>>> configs = provider.populateConfigurationList(Arrays.asList(config1, config2, config3)); assertNotNull(configs); assertEquals(3, configs.size()); Map<String, Map<String, Object>> configuration1 = configs.get(0); assertNotNull(configuration1); assertEquals(1, configuration1.size()); assertTrue(configuration1.containsKey("type1")); Map<String, Object> typeConfig1 = configuration1.get("type1"); assertNotNull(typeConfig1); assertEquals(1, typeConfig1.size()); assertTrue(typeConfig1.containsKey(BlueprintResourceProvider.PROPERTIES_PROPERTY_ID)); Map<String, String> confProperties1 = (Map<String, String>) typeConfig1.get(BlueprintResourceProvider.PROPERTIES_PROPERTY_ID); assertNotNull(confProperties1); assertEquals(1, confProperties1.size()); assertEquals("value1", confProperties1.get("key1")); Map<String, Map<String, Object>> configuration2 = configs.get(1); assertNotNull(configuration2); assertEquals(1, configuration2.size()); assertTrue(configuration2.containsKey("type2")); Map<String, Object> typeConfig2 = configuration2.get("type2"); assertNotNull(typeConfig2); assertEquals(1, typeConfig2.size()); assertTrue(typeConfig2.containsKey(BlueprintResourceProvider.PROPERTIES_PROPERTY_ID)); Map<String, String> confProperties2 = (Map<String, String>) typeConfig2.get(BlueprintResourceProvider.PROPERTIES_PROPERTY_ID); assertNotNull(confProperties2); assertEquals(1, confProperties2.size()); assertEquals("value2", confProperties2.get("key2")); Map<String, Map<String, Object>> configuration3 = configs.get(2); assertNotNull(configuration3); assertEquals(1, configuration3.size()); assertTrue(configuration3.containsKey("type3")); Map<String, Object> typeConfig3 = configuration3.get("type3"); assertNotNull(typeConfig3); assertEquals(2, typeConfig3.size()); assertTrue(typeConfig3.containsKey(BlueprintResourceProvider.PROPERTIES_PROPERTY_ID)); Map<String, String> confProperties3 = (Map<String, String>) typeConfig3.get(BlueprintResourceProvider.PROPERTIES_PROPERTY_ID); assertNotNull(confProperties3); assertEquals(3, confProperties3.size()); assertEquals("value3", confProperties3.get("key3")); assertEquals("value4", confProperties3.get("key4")); assertEquals("SECRET:type3:-1:test.password", confProperties3.get("test.password")); assertTrue(typeConfig3.containsKey(BlueprintResourceProvider.PROPERTIES_ATTRIBUTES_PROPERTY_ID)); Map<String, Map<String, String>> confAttributes3 = (Map<String, Map<String, String>>) typeConfig3.get(BlueprintResourceProvider.PROPERTIES_ATTRIBUTES_PROPERTY_ID); assertNotNull(confAttributes3); assertEquals(1, confAttributes3.size()); assertTrue(confAttributes3.containsKey("final")); Map<String, String> finalAttrs = confAttributes3.get("final"); assertEquals(2, finalAttrs.size()); assertEquals("attrValue1", finalAttrs.get("key3")); assertEquals("attrValue2", finalAttrs.get("key4")); }
List<Map<String, Map<String, Object>>> populateConfigurationList( Collection<? extends BlueprintConfiguration> configurations) throws NoSuchResourceException { List<Map<String, Map<String, Object>>> listConfigurations = new ArrayList<Map<String, Map<String, Object>>>(); for (BlueprintConfiguration config : configurations) { Map<String, Map<String, Object>> mapConfigurations = new HashMap<String, Map<String, Object>>(); Map<String, Object> configTypeDefinition = new HashMap<String, Object>(); String type = config.getType(); if(config instanceof BlueprintConfigEntity) { Map<String, String> properties = jsonSerializer.<Map<String, String>>fromJson( config.getConfigData(), Map.class); StackEntity stack = ((BlueprintConfigEntity)config).getBlueprintEntity().getStack(); StackInfo metaInfoStack; try { metaInfoStack = ambariMetaInfo.getStack(stack.getStackName(), stack.getStackVersion()); } catch (AmbariException e) { throw new NoSuchResourceException(e.getMessage()); } Map<org.apache.ambari.server.state.PropertyInfo.PropertyType, Set<String>> propertiesTypes = metaInfoStack.getConfigPropertiesTypes(type); SecretReference.replacePasswordsWithReferences(propertiesTypes, properties, type, -1l); configTypeDefinition.put(PROPERTIES_PROPERTY_ID, properties); } else { Map<String, Object> properties = jsonSerializer.<Map<String, Object>>fromJson( config.getConfigData(), Map.class); configTypeDefinition.put(PROPERTIES_PROPERTY_ID, properties); } Map<String, Map<String, String>> attributes = jsonSerializer.<Map<String, Map<String, String>>>fromJson( config.getConfigAttributes(), Map.class); if (attributes != null && !attributes.isEmpty()) { configTypeDefinition.put(PROPERTIES_ATTRIBUTES_PROPERTY_ID, attributes); } mapConfigurations.put(type, configTypeDefinition); listConfigurations.add(mapConfigurations); } return listConfigurations; }
BlueprintResourceProvider extends AbstractControllerResourceProvider { List<Map<String, Map<String, Object>>> populateConfigurationList( Collection<? extends BlueprintConfiguration> configurations) throws NoSuchResourceException { List<Map<String, Map<String, Object>>> listConfigurations = new ArrayList<Map<String, Map<String, Object>>>(); for (BlueprintConfiguration config : configurations) { Map<String, Map<String, Object>> mapConfigurations = new HashMap<String, Map<String, Object>>(); Map<String, Object> configTypeDefinition = new HashMap<String, Object>(); String type = config.getType(); if(config instanceof BlueprintConfigEntity) { Map<String, String> properties = jsonSerializer.<Map<String, String>>fromJson( config.getConfigData(), Map.class); StackEntity stack = ((BlueprintConfigEntity)config).getBlueprintEntity().getStack(); StackInfo metaInfoStack; try { metaInfoStack = ambariMetaInfo.getStack(stack.getStackName(), stack.getStackVersion()); } catch (AmbariException e) { throw new NoSuchResourceException(e.getMessage()); } Map<org.apache.ambari.server.state.PropertyInfo.PropertyType, Set<String>> propertiesTypes = metaInfoStack.getConfigPropertiesTypes(type); SecretReference.replacePasswordsWithReferences(propertiesTypes, properties, type, -1l); configTypeDefinition.put(PROPERTIES_PROPERTY_ID, properties); } else { Map<String, Object> properties = jsonSerializer.<Map<String, Object>>fromJson( config.getConfigData(), Map.class); configTypeDefinition.put(PROPERTIES_PROPERTY_ID, properties); } Map<String, Map<String, String>> attributes = jsonSerializer.<Map<String, Map<String, String>>>fromJson( config.getConfigAttributes(), Map.class); if (attributes != null && !attributes.isEmpty()) { configTypeDefinition.put(PROPERTIES_ATTRIBUTES_PROPERTY_ID, attributes); } mapConfigurations.put(type, configTypeDefinition); listConfigurations.add(mapConfigurations); } return listConfigurations; } }
BlueprintResourceProvider extends AbstractControllerResourceProvider { List<Map<String, Map<String, Object>>> populateConfigurationList( Collection<? extends BlueprintConfiguration> configurations) throws NoSuchResourceException { List<Map<String, Map<String, Object>>> listConfigurations = new ArrayList<Map<String, Map<String, Object>>>(); for (BlueprintConfiguration config : configurations) { Map<String, Map<String, Object>> mapConfigurations = new HashMap<String, Map<String, Object>>(); Map<String, Object> configTypeDefinition = new HashMap<String, Object>(); String type = config.getType(); if(config instanceof BlueprintConfigEntity) { Map<String, String> properties = jsonSerializer.<Map<String, String>>fromJson( config.getConfigData(), Map.class); StackEntity stack = ((BlueprintConfigEntity)config).getBlueprintEntity().getStack(); StackInfo metaInfoStack; try { metaInfoStack = ambariMetaInfo.getStack(stack.getStackName(), stack.getStackVersion()); } catch (AmbariException e) { throw new NoSuchResourceException(e.getMessage()); } Map<org.apache.ambari.server.state.PropertyInfo.PropertyType, Set<String>> propertiesTypes = metaInfoStack.getConfigPropertiesTypes(type); SecretReference.replacePasswordsWithReferences(propertiesTypes, properties, type, -1l); configTypeDefinition.put(PROPERTIES_PROPERTY_ID, properties); } else { Map<String, Object> properties = jsonSerializer.<Map<String, Object>>fromJson( config.getConfigData(), Map.class); configTypeDefinition.put(PROPERTIES_PROPERTY_ID, properties); } Map<String, Map<String, String>> attributes = jsonSerializer.<Map<String, Map<String, String>>>fromJson( config.getConfigAttributes(), Map.class); if (attributes != null && !attributes.isEmpty()) { configTypeDefinition.put(PROPERTIES_ATTRIBUTES_PROPERTY_ID, attributes); } mapConfigurations.put(type, configTypeDefinition); listConfigurations.add(mapConfigurations); } return listConfigurations; } BlueprintResourceProvider(Set<String> propertyIds,
                            Map<Resource.Type, String> keyPropertyIds,
                            AmbariManagementController controller); }
BlueprintResourceProvider extends AbstractControllerResourceProvider { List<Map<String, Map<String, Object>>> populateConfigurationList( Collection<? extends BlueprintConfiguration> configurations) throws NoSuchResourceException { List<Map<String, Map<String, Object>>> listConfigurations = new ArrayList<Map<String, Map<String, Object>>>(); for (BlueprintConfiguration config : configurations) { Map<String, Map<String, Object>> mapConfigurations = new HashMap<String, Map<String, Object>>(); Map<String, Object> configTypeDefinition = new HashMap<String, Object>(); String type = config.getType(); if(config instanceof BlueprintConfigEntity) { Map<String, String> properties = jsonSerializer.<Map<String, String>>fromJson( config.getConfigData(), Map.class); StackEntity stack = ((BlueprintConfigEntity)config).getBlueprintEntity().getStack(); StackInfo metaInfoStack; try { metaInfoStack = ambariMetaInfo.getStack(stack.getStackName(), stack.getStackVersion()); } catch (AmbariException e) { throw new NoSuchResourceException(e.getMessage()); } Map<org.apache.ambari.server.state.PropertyInfo.PropertyType, Set<String>> propertiesTypes = metaInfoStack.getConfigPropertiesTypes(type); SecretReference.replacePasswordsWithReferences(propertiesTypes, properties, type, -1l); configTypeDefinition.put(PROPERTIES_PROPERTY_ID, properties); } else { Map<String, Object> properties = jsonSerializer.<Map<String, Object>>fromJson( config.getConfigData(), Map.class); configTypeDefinition.put(PROPERTIES_PROPERTY_ID, properties); } Map<String, Map<String, String>> attributes = jsonSerializer.<Map<String, Map<String, String>>>fromJson( config.getConfigAttributes(), Map.class); if (attributes != null && !attributes.isEmpty()) { configTypeDefinition.put(PROPERTIES_ATTRIBUTES_PROPERTY_ID, attributes); } mapConfigurations.put(type, configTypeDefinition); listConfigurations.add(mapConfigurations); } return listConfigurations; } BlueprintResourceProvider(Set<String> propertyIds,
                            Map<Resource.Type, String> keyPropertyIds,
                            AmbariManagementController controller); static void init(BlueprintFactory factory, BlueprintDAO dao, SecurityConfigurationFactory
    securityFactory, Gson gson, AmbariMetaInfo metaInfo); @Override RequestStatus createResources(Request request); @Override //todo: continue to use dao/entity directly or use blueprint factory? Set<Resource> getResources(Request request, Predicate predicate); @Override RequestStatus updateResources(Request request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate); static List<Map<String, Object>> populateSettingList(
          Collection<? extends BlueprintSettingEntity> settings); }
BlueprintResourceProvider extends AbstractControllerResourceProvider { List<Map<String, Map<String, Object>>> populateConfigurationList( Collection<? extends BlueprintConfiguration> configurations) throws NoSuchResourceException { List<Map<String, Map<String, Object>>> listConfigurations = new ArrayList<Map<String, Map<String, Object>>>(); for (BlueprintConfiguration config : configurations) { Map<String, Map<String, Object>> mapConfigurations = new HashMap<String, Map<String, Object>>(); Map<String, Object> configTypeDefinition = new HashMap<String, Object>(); String type = config.getType(); if(config instanceof BlueprintConfigEntity) { Map<String, String> properties = jsonSerializer.<Map<String, String>>fromJson( config.getConfigData(), Map.class); StackEntity stack = ((BlueprintConfigEntity)config).getBlueprintEntity().getStack(); StackInfo metaInfoStack; try { metaInfoStack = ambariMetaInfo.getStack(stack.getStackName(), stack.getStackVersion()); } catch (AmbariException e) { throw new NoSuchResourceException(e.getMessage()); } Map<org.apache.ambari.server.state.PropertyInfo.PropertyType, Set<String>> propertiesTypes = metaInfoStack.getConfigPropertiesTypes(type); SecretReference.replacePasswordsWithReferences(propertiesTypes, properties, type, -1l); configTypeDefinition.put(PROPERTIES_PROPERTY_ID, properties); } else { Map<String, Object> properties = jsonSerializer.<Map<String, Object>>fromJson( config.getConfigData(), Map.class); configTypeDefinition.put(PROPERTIES_PROPERTY_ID, properties); } Map<String, Map<String, String>> attributes = jsonSerializer.<Map<String, Map<String, String>>>fromJson( config.getConfigAttributes(), Map.class); if (attributes != null && !attributes.isEmpty()) { configTypeDefinition.put(PROPERTIES_ATTRIBUTES_PROPERTY_ID, attributes); } mapConfigurations.put(type, configTypeDefinition); listConfigurations.add(mapConfigurations); } return listConfigurations; } BlueprintResourceProvider(Set<String> propertyIds,
                            Map<Resource.Type, String> keyPropertyIds,
                            AmbariManagementController controller); static void init(BlueprintFactory factory, BlueprintDAO dao, SecurityConfigurationFactory
    securityFactory, Gson gson, AmbariMetaInfo metaInfo); @Override RequestStatus createResources(Request request); @Override //todo: continue to use dao/entity directly or use blueprint factory? Set<Resource> getResources(Request request, Predicate predicate); @Override RequestStatus updateResources(Request request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate); static List<Map<String, Object>> populateSettingList(
          Collection<? extends BlueprintSettingEntity> settings); static final String BLUEPRINT_NAME_PROPERTY_ID; static final String STACK_NAME_PROPERTY_ID; static final String STACK_VERSION_PROPERTY_ID; static final String BLUEPRINT_SECURITY_PROPERTY_ID; static final String BLUEPRINTS_PROPERTY_ID; static final String HOST_GROUP_PROPERTY_ID; static final String HOST_GROUP_NAME_PROPERTY_ID; static final String HOST_GROUP_CARDINALITY_PROPERTY_ID; static final String COMPONENT_PROPERTY_ID; static final String COMPONENT_NAME_PROPERTY_ID; static final String COMPONENT_PROVISION_ACTION_PROPERTY_ID; static final String CONFIGURATION_PROPERTY_ID; static final String SETTING_PROPERTY_ID; static final String PROPERTIES_PROPERTY_ID; static final String PROPERTIES_ATTRIBUTES_PROPERTY_ID; static final String SCHEMA_IS_NOT_SUPPORTED_MESSAGE; static final String REQUEST_BODY_EMPTY_ERROR_MESSAGE; static final String CONFIGURATION_LIST_CHECK_ERROR_MESSAGE; static final String CONFIGURATION_MAP_CHECK_ERROR_MESSAGE; static final String CONFIGURATION_MAP_SIZE_CHECK_ERROR_MESSAGE; }