@Test public void testCreateAttributesResources() throws Exception { AmbariManagementController managementController = createMock(AmbariManagementController.class); RequestStatusResponse response = createNiceMock(RequestStatusResponse.class); managementController.createConfiguration(AbstractResourceProviderTest.Matcher.getConfigurationRequest( "Cluster100", "type", "tag", new HashMap<String, String>(){ { put("a", "b"); } }, new HashMap<String, Map<String,String>>(){ { put("final", new HashMap<String, String>(){ { put("a", "true"); } }); } })); expectLastCall().andReturn(null); replay(managementController, response); ConfigurationResourceProvider provider = new ConfigurationResourceProvider( managementController); Set<Map<String, Object>> propertySet = new LinkedHashSet<Map<String, Object>>(); Map<String, Object> properties = new LinkedHashMap<String, Object>(); properties.put(ConfigurationResourceProvider.CONFIGURATION_CLUSTER_NAME_PROPERTY_ID, "Cluster100"); properties.put(ConfigurationResourceProvider.CONFIGURATION_CONFIG_TAG_PROPERTY_ID, "tag"); properties.put(ConfigurationResourceProvider.CONFIGURATION_CONFIG_TYPE_PROPERTY_ID, "type"); properties.put("properties/a", "b"); properties.put("properties_attributes/final/a", "true"); propertySet.add(properties); Request request = PropertyHelper.getCreateRequest(propertySet, null); provider.createResources(request); verify(managementController, response); }
@Override public RequestStatus createResources(Request request) throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException { for (Map<String, Object> map : request.getProperties()) { String cluster = (String) map.get(CONFIGURATION_CLUSTER_NAME_PROPERTY_ID); String type = (String) map.get(CONFIGURATION_CONFIG_TYPE_PROPERTY_ID); String tag = (String) map.get(CONFIGURATION_CONFIG_TAG_PROPERTY_ID); Map<String, String> configMap = new HashMap<String, String>(); Map<String, Map<String, String>> configAttributesMap = null; for (Entry<String, Object> entry : map.entrySet()) { String propertyCategory = PropertyHelper.getPropertyCategory(entry.getKey()); if (propertyCategory != null && propertyCategory.equals("properties") && null != entry.getValue()) { configMap.put(PropertyHelper.getPropertyName(entry.getKey()), entry.getValue().toString()); } if (propertyCategory != null && PROPERTIES_ATTRIBUTES_PATTERN.matcher(propertyCategory).matches() && null != entry.getValue()) { if (null == configAttributesMap) { configAttributesMap = new HashMap<String, Map<String,String>>(); } String attributeName = propertyCategory.substring(propertyCategory.lastIndexOf('/') + 1); Map<String, String> attributesMap = configAttributesMap.get(attributeName); if (attributesMap == null) { attributesMap = new HashMap<String, String>(); configAttributesMap.put(attributeName, attributesMap); } attributesMap.put(PropertyHelper.getPropertyName(entry.getKey()), entry.getValue().toString()); } } final ConfigurationRequest configRequest = new ConfigurationRequest(cluster, type, tag, configMap, configAttributesMap); createResources(new Command<Void>() { @Override public Void invoke() throws AmbariException, AuthorizationException { getManagementController().createConfiguration(configRequest); return null; } }); } return getRequestStatus(null); }
ConfigurationResourceProvider extends
    AbstractControllerResourceProvider { @Override public RequestStatus createResources(Request request) throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException { for (Map<String, Object> map : request.getProperties()) { String cluster = (String) map.get(CONFIGURATION_CLUSTER_NAME_PROPERTY_ID); String type = (String) map.get(CONFIGURATION_CONFIG_TYPE_PROPERTY_ID); String tag = (String) map.get(CONFIGURATION_CONFIG_TAG_PROPERTY_ID); Map<String, String> configMap = new HashMap<String, String>(); Map<String, Map<String, String>> configAttributesMap = null; for (Entry<String, Object> entry : map.entrySet()) { String propertyCategory = PropertyHelper.getPropertyCategory(entry.getKey()); if (propertyCategory != null && propertyCategory.equals("properties") && null != entry.getValue()) { configMap.put(PropertyHelper.getPropertyName(entry.getKey()), entry.getValue().toString()); } if (propertyCategory != null && PROPERTIES_ATTRIBUTES_PATTERN.matcher(propertyCategory).matches() && null != entry.getValue()) { if (null == configAttributesMap) { configAttributesMap = new HashMap<String, Map<String,String>>(); } String attributeName = propertyCategory.substring(propertyCategory.lastIndexOf('/') + 1); Map<String, String> attributesMap = configAttributesMap.get(attributeName); if (attributesMap == null) { attributesMap = new HashMap<String, String>(); configAttributesMap.put(attributeName, attributesMap); } attributesMap.put(PropertyHelper.getPropertyName(entry.getKey()), entry.getValue().toString()); } } final ConfigurationRequest configRequest = new ConfigurationRequest(cluster, type, tag, configMap, configAttributesMap); createResources(new Command<Void>() { @Override public Void invoke() throws AmbariException, AuthorizationException { getManagementController().createConfiguration(configRequest); return null; } }); } return getRequestStatus(null); } }
ConfigurationResourceProvider extends
    AbstractControllerResourceProvider { @Override public RequestStatus createResources(Request request) throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException { for (Map<String, Object> map : request.getProperties()) { String cluster = (String) map.get(CONFIGURATION_CLUSTER_NAME_PROPERTY_ID); String type = (String) map.get(CONFIGURATION_CONFIG_TYPE_PROPERTY_ID); String tag = (String) map.get(CONFIGURATION_CONFIG_TAG_PROPERTY_ID); Map<String, String> configMap = new HashMap<String, String>(); Map<String, Map<String, String>> configAttributesMap = null; for (Entry<String, Object> entry : map.entrySet()) { String propertyCategory = PropertyHelper.getPropertyCategory(entry.getKey()); if (propertyCategory != null && propertyCategory.equals("properties") && null != entry.getValue()) { configMap.put(PropertyHelper.getPropertyName(entry.getKey()), entry.getValue().toString()); } if (propertyCategory != null && PROPERTIES_ATTRIBUTES_PATTERN.matcher(propertyCategory).matches() && null != entry.getValue()) { if (null == configAttributesMap) { configAttributesMap = new HashMap<String, Map<String,String>>(); } String attributeName = propertyCategory.substring(propertyCategory.lastIndexOf('/') + 1); Map<String, String> attributesMap = configAttributesMap.get(attributeName); if (attributesMap == null) { attributesMap = new HashMap<String, String>(); configAttributesMap.put(attributeName, attributesMap); } attributesMap.put(PropertyHelper.getPropertyName(entry.getKey()), entry.getValue().toString()); } } final ConfigurationRequest configRequest = new ConfigurationRequest(cluster, type, tag, configMap, configAttributesMap); createResources(new Command<Void>() { @Override public Void invoke() throws AmbariException, AuthorizationException { getManagementController().createConfiguration(configRequest); return null; } }); } return getRequestStatus(null); } ConfigurationResourceProvider(AmbariManagementController managementController); }
ConfigurationResourceProvider extends
    AbstractControllerResourceProvider { @Override public RequestStatus createResources(Request request) throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException { for (Map<String, Object> map : request.getProperties()) { String cluster = (String) map.get(CONFIGURATION_CLUSTER_NAME_PROPERTY_ID); String type = (String) map.get(CONFIGURATION_CONFIG_TYPE_PROPERTY_ID); String tag = (String) map.get(CONFIGURATION_CONFIG_TAG_PROPERTY_ID); Map<String, String> configMap = new HashMap<String, String>(); Map<String, Map<String, String>> configAttributesMap = null; for (Entry<String, Object> entry : map.entrySet()) { String propertyCategory = PropertyHelper.getPropertyCategory(entry.getKey()); if (propertyCategory != null && propertyCategory.equals("properties") && null != entry.getValue()) { configMap.put(PropertyHelper.getPropertyName(entry.getKey()), entry.getValue().toString()); } if (propertyCategory != null && PROPERTIES_ATTRIBUTES_PATTERN.matcher(propertyCategory).matches() && null != entry.getValue()) { if (null == configAttributesMap) { configAttributesMap = new HashMap<String, Map<String,String>>(); } String attributeName = propertyCategory.substring(propertyCategory.lastIndexOf('/') + 1); Map<String, String> attributesMap = configAttributesMap.get(attributeName); if (attributesMap == null) { attributesMap = new HashMap<String, String>(); configAttributesMap.put(attributeName, attributesMap); } attributesMap.put(PropertyHelper.getPropertyName(entry.getKey()), entry.getValue().toString()); } } final ConfigurationRequest configRequest = new ConfigurationRequest(cluster, type, tag, configMap, configAttributesMap); createResources(new Command<Void>() { @Override public Void invoke() throws AmbariException, AuthorizationException { getManagementController().createConfiguration(configRequest); return null; } }); } return getRequestStatus(null); } ConfigurationResourceProvider(AmbariManagementController managementController); @Override RequestStatus createResources(Request request); @Override Set<Resource> getResourcesAuthorized(Request request, Predicate predicate); @Override RequestStatus updateResources(Request request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate); @Override Set<String> checkPropertyIds(Set<String> propertyIds); }
ConfigurationResourceProvider extends
    AbstractControllerResourceProvider { @Override public RequestStatus createResources(Request request) throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException { for (Map<String, Object> map : request.getProperties()) { String cluster = (String) map.get(CONFIGURATION_CLUSTER_NAME_PROPERTY_ID); String type = (String) map.get(CONFIGURATION_CONFIG_TYPE_PROPERTY_ID); String tag = (String) map.get(CONFIGURATION_CONFIG_TAG_PROPERTY_ID); Map<String, String> configMap = new HashMap<String, String>(); Map<String, Map<String, String>> configAttributesMap = null; for (Entry<String, Object> entry : map.entrySet()) { String propertyCategory = PropertyHelper.getPropertyCategory(entry.getKey()); if (propertyCategory != null && propertyCategory.equals("properties") && null != entry.getValue()) { configMap.put(PropertyHelper.getPropertyName(entry.getKey()), entry.getValue().toString()); } if (propertyCategory != null && PROPERTIES_ATTRIBUTES_PATTERN.matcher(propertyCategory).matches() && null != entry.getValue()) { if (null == configAttributesMap) { configAttributesMap = new HashMap<String, Map<String,String>>(); } String attributeName = propertyCategory.substring(propertyCategory.lastIndexOf('/') + 1); Map<String, String> attributesMap = configAttributesMap.get(attributeName); if (attributesMap == null) { attributesMap = new HashMap<String, String>(); configAttributesMap.put(attributeName, attributesMap); } attributesMap.put(PropertyHelper.getPropertyName(entry.getKey()), entry.getValue().toString()); } } final ConfigurationRequest configRequest = new ConfigurationRequest(cluster, type, tag, configMap, configAttributesMap); createResources(new Command<Void>() { @Override public Void invoke() throws AmbariException, AuthorizationException { getManagementController().createConfiguration(configRequest); return null; } }); } return getRequestStatus(null); } ConfigurationResourceProvider(AmbariManagementController managementController); @Override RequestStatus createResources(Request request); @Override Set<Resource> getResourcesAuthorized(Request request, Predicate predicate); @Override RequestStatus updateResources(Request request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate); @Override Set<String> checkPropertyIds(Set<String> propertyIds); static final String CONFIGURATION_CONFIG_TYPE_PROPERTY_ID; static final String CONFIGURATION_CONFIG_TAG_PROPERTY_ID; static final String CONFIGURATION_CONFIG_VERSION_PROPERTY_ID; }