@Test public void testPopulateSettingList() 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); BlueprintSettingEntity settingEntity1 = new BlueprintSettingEntity(); settingEntity1.setSettingName("recovery_settings"); settingEntity1.setSettingData("[{\"recovery_enabled\":\"true\"}]"); settingEntity1.setBlueprintEntity(entity); BlueprintSettingEntity settingEntity2 = new BlueprintSettingEntity(); settingEntity2.setSettingName("service_settings"); settingEntity2.setSettingData("[{\"name\":\"HDFS\", \"recovery_enabled\":\"false\"}, " + "{\"name\":\"ZOOKEEPER\", \"recovery_enabled\":\"false\"}]"); settingEntity2.setBlueprintEntity(entity); BlueprintSettingEntity settingEntity3 = new BlueprintSettingEntity(); settingEntity3.setSettingName("component_settings"); settingEntity3.setSettingData("[{\"name\":\"METRICS_MONITOR\", \"recovery_enabled\":\"false\"}," + "{\"name\":\"KAFKA_CLIENT\", \"recovery_enabled\":\"false\"}]"); settingEntity3.setBlueprintEntity(entity); List<BlueprintSettingEntity> settingEntities = new ArrayList(); settingEntities.add(settingEntity1); settingEntities.add(settingEntity2); settingEntities.add(settingEntity3); List<Map<String, Object>> settings = provider.populateSettingList(settingEntities); assertNotNull(settings); assertEquals(settingEntities.size(), settings.size()); Map<String, Object> setting1 = settings.get(0); assertNotNull(setting1); assertEquals(1, setting1.size()); assertTrue(setting1.containsKey("recovery_settings")); List<Map<String, String>> setting1value = (List<Map<String, String>>) setting1.get("recovery_settings"); assertNotNull(setting1value); assertEquals(1, setting1value.size()); assertTrue(setting1value.get(0).containsKey("recovery_enabled")); assertEquals(setting1value.get(0).get("recovery_enabled"), "true"); Map<String, Object> setting2 = settings.get(1); assertNotNull(setting2); assertEquals(1, setting2.size()); assertTrue(setting2.containsKey("service_settings")); List<Map<String, String>> setting2value = (List<Map<String, String>>) setting2.get("service_settings"); assertNotNull(setting2value); assertEquals(2, setting2value.size()); assertTrue(setting2value.get(0).containsKey("name")); assertEquals(setting2value.get(0).get("name"), "HDFS"); assertTrue(setting2value.get(0).containsKey("recovery_enabled")); assertEquals(setting2value.get(0).get("recovery_enabled"), "false"); assertTrue(setting2value.get(1).containsKey("name")); assertEquals(setting2value.get(1).get("name"), "ZOOKEEPER"); assertTrue(setting2value.get(1).containsKey("recovery_enabled")); assertEquals(setting2value.get(1).get("recovery_enabled"), "false"); Map<String, Object> setting3 = settings.get(2); assertNotNull(setting3); assertEquals(1, setting3.size()); assertTrue(setting3.containsKey("component_settings")); List<Map<String, String>> setting3value = (List<Map<String, String>>) setting3.get("component_settings"); assertNotNull(setting3value); assertEquals(2, setting3value.size()); assertTrue(setting3value.get(0).containsKey("name")); assertEquals(setting3value.get(0).get("name"), "METRICS_MONITOR"); assertTrue(setting3value.get(0).containsKey("recovery_enabled")); assertEquals(setting3value.get(0).get("recovery_enabled"), "false"); assertTrue(setting3value.get(1).containsKey("name")); assertEquals(setting3value.get(1).get("name"), "KAFKA_CLIENT"); assertTrue(setting3value.get(1).containsKey("recovery_enabled")); assertEquals(setting3value.get(1).get("recovery_enabled"), "false"); }
public static List<Map<String, Object>> populateSettingList( Collection<? extends BlueprintSettingEntity> settings) throws NoSuchResourceException { List<Map<String, Object>> listSettings = new ArrayList<Map<String, Object>>(); if (settings != null) { for (BlueprintSettingEntity setting : settings) { List<Map<String, String>> propertiesList = jsonSerializer.<List<Map<String, String>>>fromJson( setting.getSettingData(), List.class); Map<String, Object> settingMap = new HashMap<>(); settingMap.put(setting.getSettingName(), propertiesList); listSettings.add(settingMap); } } return listSettings; }
BlueprintResourceProvider extends AbstractControllerResourceProvider { public static List<Map<String, Object>> populateSettingList( Collection<? extends BlueprintSettingEntity> settings) throws NoSuchResourceException { List<Map<String, Object>> listSettings = new ArrayList<Map<String, Object>>(); if (settings != null) { for (BlueprintSettingEntity setting : settings) { List<Map<String, String>> propertiesList = jsonSerializer.<List<Map<String, String>>>fromJson( setting.getSettingData(), List.class); Map<String, Object> settingMap = new HashMap<>(); settingMap.put(setting.getSettingName(), propertiesList); listSettings.add(settingMap); } } return listSettings; } }
BlueprintResourceProvider extends AbstractControllerResourceProvider { public static List<Map<String, Object>> populateSettingList( Collection<? extends BlueprintSettingEntity> settings) throws NoSuchResourceException { List<Map<String, Object>> listSettings = new ArrayList<Map<String, Object>>(); if (settings != null) { for (BlueprintSettingEntity setting : settings) { List<Map<String, String>> propertiesList = jsonSerializer.<List<Map<String, String>>>fromJson( setting.getSettingData(), List.class); Map<String, Object> settingMap = new HashMap<>(); settingMap.put(setting.getSettingName(), propertiesList); listSettings.add(settingMap); } } return listSettings; } BlueprintResourceProvider(Set<String> propertyIds,
                            Map<Resource.Type, String> keyPropertyIds,
                            AmbariManagementController controller); }
BlueprintResourceProvider extends AbstractControllerResourceProvider { public static List<Map<String, Object>> populateSettingList( Collection<? extends BlueprintSettingEntity> settings) throws NoSuchResourceException { List<Map<String, Object>> listSettings = new ArrayList<Map<String, Object>>(); if (settings != null) { for (BlueprintSettingEntity setting : settings) { List<Map<String, String>> propertiesList = jsonSerializer.<List<Map<String, String>>>fromJson( setting.getSettingData(), List.class); Map<String, Object> settingMap = new HashMap<>(); settingMap.put(setting.getSettingName(), propertiesList); listSettings.add(settingMap); } } return listSettings; } 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 { public static List<Map<String, Object>> populateSettingList( Collection<? extends BlueprintSettingEntity> settings) throws NoSuchResourceException { List<Map<String, Object>> listSettings = new ArrayList<Map<String, Object>>(); if (settings != null) { for (BlueprintSettingEntity setting : settings) { List<Map<String, String>> propertiesList = jsonSerializer.<List<Map<String, String>>>fromJson( setting.getSettingData(), List.class); Map<String, Object> settingMap = new HashMap<>(); settingMap.put(setting.getSettingName(), propertiesList); listSettings.add(settingMap); } } return listSettings; } 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; }