BlueprintResourceProvider extends AbstractControllerResourceProvider { BlueprintConfigPopulationStrategy decidePopulationStrategy(Map<String, String> configuration) { if (configuration != null && !configuration.isEmpty()) { String keyEntry = configuration.keySet().iterator().next(); String[] keyNameTokens = keyEntry.split("/"); int levels = keyNameTokens.length; String propertiesType = keyNameTokens[1]; if (levels == 2) { return new BlueprintConfigPopulationStrategyV1(); } else if ((levels == 3 && PROPERTIES_PROPERTY_ID.equals(propertiesType)) || (levels == 4 && PROPERTIES_ATTRIBUTES_PROPERTY_ID.equals(propertiesType))) { return new BlueprintConfigPopulationStrategyV2(); } else { throw new IllegalArgumentException(SCHEMA_IS_NOT_SUPPORTED_MESSAGE); } } else { return new BlueprintConfigPopulationStrategyV2(); } } 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 testDecidePopulationStrategy_configIsEmpty() throws Exception { Map<String, String> configMap = new HashMap<String, String>(); BlueprintConfigPopulationStrategy provisioner = provider.decidePopulationStrategy(configMap); assertNotNull(provisioner); assertTrue(provisioner instanceof BlueprintConfigPopulationStrategyV2); }
@Test public void testDecidePopulationStrategy_configIsNull() throws Exception { Map<String, String> configMap = null; BlueprintConfigPopulationStrategy provisioner = provider.decidePopulationStrategy(configMap); assertNotNull(provisioner); assertTrue(provisioner instanceof BlueprintConfigPopulationStrategyV2); }
@Test public void testDecidePopulationStrategy_withOldSchema() throws Exception { Map<String, String> configMap = new HashMap<String, String>(); configMap.put("global/hive_database", "db"); BlueprintConfigPopulationStrategy provisioner = provider.decidePopulationStrategy(configMap); assertNotNull(provisioner); assertTrue(provisioner instanceof BlueprintConfigPopulationStrategyV1); }
@Test public void testDecidePopulationStrategy_withNewSchema_attributes() throws Exception { Map<String, String> configMap = new HashMap<String, String>(); configMap.put("global/properties_attributes/final/foo_contact", "true"); BlueprintConfigPopulationStrategy provisioner = provider.decidePopulationStrategy(configMap); assertNotNull(provisioner); assertTrue(provisioner instanceof BlueprintConfigPopulationStrategyV2); }
@Test public void testDecidePopulationStrategy_withNewSchema_properties() throws Exception { Map<String, String> configMap = new HashMap<String, String>(); configMap.put("global/properties/foo_contact", "foo@ffl.dsfds"); BlueprintConfigPopulationStrategy provisioner = provider.decidePopulationStrategy(configMap); assertNotNull(provisioner); assertTrue(provisioner instanceof BlueprintConfigPopulationStrategyV2); }
@Test public void testDecidePopulationStrategy_unsupportedSchema() throws Exception { Map<String, String> configMap = new HashMap<String, String>(); configMap.put("global/properties/lot/foo_contact", "foo@ffl.dsfds"); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage(BlueprintResourceProvider.SCHEMA_IS_NOT_SUPPORTED_MESSAGE); provider.decidePopulationStrategy(configMap); }