BlueprintResourceProvider extends AbstractControllerResourceProvider { void populateConfigurationEntity(Map<String, String> configuration, BlueprintConfiguration configEntity) { BlueprintConfigPopulationStrategy p = decidePopulationStrategy(configuration); p.applyConfiguration(configuration, configEntity); } 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; }
@Test public void testPopulateConfigurationEntity_oldSchema() throws Exception { Map<String, String> configuration = new HashMap<String, String>(); configuration.put("global/property1", "val1"); configuration.put("global/property2", "val2"); BlueprintConfiguration config = new BlueprintConfigEntity(); provider.populateConfigurationEntity(configuration, config); assertNotNull(config.getConfigData()); assertNotNull(config.getConfigAttributes()); Map<?, ?> configData = StageUtils.getGson().fromJson(config.getConfigData(), Map.class); Map<?, Map<?, ?>> configAttrs = StageUtils.getGson().fromJson(config.getConfigAttributes(), Map.class); assertNotNull(configData); assertNotNull(configAttrs); assertEquals(2, configData.size()); assertTrue(configData.containsKey("property1")); assertTrue(configData.containsKey("property2")); assertEquals("val1", configData.get("property1")); assertEquals("val2", configData.get("property2")); assertEquals(0, configAttrs.size()); }
@Test public void testPopulateConfigurationEntity_newSchema() throws Exception { Map<String, String> configuration = new HashMap<String, String>(); configuration.put("global/properties/property1", "val1"); configuration.put("global/properties/property2", "val2"); configuration.put("global/properties_attributes/final/property1", "true"); configuration.put("global/properties_attributes/final/property2", "false"); configuration.put("global/properties_attributes/deletable/property1", "true"); BlueprintConfiguration config = new BlueprintConfigEntity(); provider.populateConfigurationEntity(configuration, config); assertNotNull(config.getConfigData()); assertNotNull(config.getConfigAttributes()); Map<?, ?> configData = StageUtils.getGson().fromJson(config.getConfigData(), Map.class); Map<?, Map<?, ?>> configAttrs = StageUtils.getGson().fromJson(config.getConfigAttributes(), Map.class); assertNotNull(configData); assertNotNull(configAttrs); assertEquals(2, configData.size()); assertTrue(configData.containsKey("property1")); assertTrue(configData.containsKey("property2")); assertEquals("val1", configData.get("property1")); assertEquals("val2", configData.get("property2")); assertEquals(2, configAttrs.size()); assertTrue(configAttrs.containsKey("final")); assertTrue(configAttrs.containsKey("deletable")); Map<?, ?> finalAttrs = configAttrs.get("final"); assertNotNull(finalAttrs); assertEquals(2, finalAttrs.size()); assertTrue(finalAttrs.containsKey("property1")); assertTrue(finalAttrs.containsKey("property2")); assertEquals("true", finalAttrs.get("property1")); assertEquals("false", finalAttrs.get("property2")); Map<?, ?> deletableAttrs = configAttrs.get("deletable"); assertNotNull(deletableAttrs); assertEquals(1, deletableAttrs.size()); assertTrue(deletableAttrs.containsKey("property1")); assertEquals("true", deletableAttrs.get("property1")); }
@Test public void testPopulateConfigurationEntity_configIsNull() throws Exception { Map<String, String> configuration = null; BlueprintConfiguration config = new BlueprintConfigEntity(); provider.populateConfigurationEntity(configuration, config); assertNotNull(config.getConfigAttributes()); assertNotNull(config.getConfigData()); }
@Test public void testPopulateConfigurationEntity_configIsEmpty() throws Exception { Map<String, String> configuration = new HashMap<String, String>(); BlueprintConfiguration config = new BlueprintConfigEntity(); provider.populateConfigurationEntity(configuration, config); assertNotNull(config.getConfigAttributes()); assertNotNull(config.getConfigData()); }