@Test public void testCalculateConfigurations() throws Exception { Map<Resource.Type, String> keyPropertyIds = Collections.emptyMap(); Set<String> propertyIds = Collections.emptySet(); AmbariManagementController ambariManagementController = mock(AmbariManagementController.class); RecommendationResourceProvider provider = new RecommendationResourceProvider(propertyIds, keyPropertyIds, ambariManagementController); Request request = mock(Request.class); Set<Map<String, Object>> propertiesSet = new HashSet<Map<String, Object>>(); Map<String, Object> propertiesMap = new HashMap<String, Object>(); propertiesMap.put(CONFIGURATIONS_PROPERTY_ID + "site/properties/string_prop", "string"); List<Object> array = new ArrayList<Object>(); array.add("array1"); array.add("array2"); propertiesMap.put(CONFIGURATIONS_PROPERTY_ID + "site/properties/array_prop", array); propertiesSet.add(propertiesMap); doReturn(propertiesSet).when(request).getProperties(); Map<String, Map<String, Map<String, String>>> calculatedConfigurations = provider.calculateConfigurations(request); assertNotNull(calculatedConfigurations); assertEquals(1, calculatedConfigurations.size()); Map<String, Map<String, String>> site = calculatedConfigurations.get("site"); assertNotNull(site); assertEquals(1, site.size()); Map<String, String> properties = site.get("properties"); assertNotNull(properties); assertEquals(2, properties.size()); assertEquals("string", properties.get("string_prop")); assertEquals("[array1, array2]", properties.get("array_prop")); }
protected Map<String, Map<String, Map<String, String>>> calculateConfigurations(Request request) { Map<String, Map<String, Map<String, String>>> configurations = new HashMap<String, Map<String, Map<String, String>>>(); Map<String, Object> properties = request.getProperties().iterator().next(); for (String property : properties.keySet()) { if (property.startsWith(CONFIGURATIONS_PROPERTY_ID)) { try { String propertyEnd = property.substring(CONFIGURATIONS_PROPERTY_ID.length()); String[] propertyPath = propertyEnd.split("/"); String siteName = propertyPath[0]; String propertiesProperty = propertyPath[1]; String propertyName = propertyPath[2]; Map<String, Map<String, String>> siteMap = configurations.get(siteName); if (siteMap == null) { siteMap = new HashMap<String, Map<String, String>>(); configurations.put(siteName, siteMap); } Map<String, String> propertiesMap = siteMap.get(propertiesProperty); if (propertiesMap == null) { propertiesMap = new HashMap<String, String>(); siteMap.put(propertiesProperty, propertiesMap); } Object propVal = properties.get(property); if (propVal != null) propertiesMap.put(propertyName, propVal.toString()); else LOG.info(String.format("No value specified for configuration property, name = %s ", property)); } catch (Exception e) { LOG.debug(String.format("Error handling configuration property, name = %s", property), e); } } } return configurations; }
StackAdvisorResourceProvider extends ReadOnlyResourceProvider { protected Map<String, Map<String, Map<String, String>>> calculateConfigurations(Request request) { Map<String, Map<String, Map<String, String>>> configurations = new HashMap<String, Map<String, Map<String, String>>>(); Map<String, Object> properties = request.getProperties().iterator().next(); for (String property : properties.keySet()) { if (property.startsWith(CONFIGURATIONS_PROPERTY_ID)) { try { String propertyEnd = property.substring(CONFIGURATIONS_PROPERTY_ID.length()); String[] propertyPath = propertyEnd.split("/"); String siteName = propertyPath[0]; String propertiesProperty = propertyPath[1]; String propertyName = propertyPath[2]; Map<String, Map<String, String>> siteMap = configurations.get(siteName); if (siteMap == null) { siteMap = new HashMap<String, Map<String, String>>(); configurations.put(siteName, siteMap); } Map<String, String> propertiesMap = siteMap.get(propertiesProperty); if (propertiesMap == null) { propertiesMap = new HashMap<String, String>(); siteMap.put(propertiesProperty, propertiesMap); } Object propVal = properties.get(property); if (propVal != null) propertiesMap.put(propertyName, propVal.toString()); else LOG.info(String.format("No value specified for configuration property, name = %s ", property)); } catch (Exception e) { LOG.debug(String.format("Error handling configuration property, name = %s", property), e); } } } return configurations; } }
StackAdvisorResourceProvider extends ReadOnlyResourceProvider { protected Map<String, Map<String, Map<String, String>>> calculateConfigurations(Request request) { Map<String, Map<String, Map<String, String>>> configurations = new HashMap<String, Map<String, Map<String, String>>>(); Map<String, Object> properties = request.getProperties().iterator().next(); for (String property : properties.keySet()) { if (property.startsWith(CONFIGURATIONS_PROPERTY_ID)) { try { String propertyEnd = property.substring(CONFIGURATIONS_PROPERTY_ID.length()); String[] propertyPath = propertyEnd.split("/"); String siteName = propertyPath[0]; String propertiesProperty = propertyPath[1]; String propertyName = propertyPath[2]; Map<String, Map<String, String>> siteMap = configurations.get(siteName); if (siteMap == null) { siteMap = new HashMap<String, Map<String, String>>(); configurations.put(siteName, siteMap); } Map<String, String> propertiesMap = siteMap.get(propertiesProperty); if (propertiesMap == null) { propertiesMap = new HashMap<String, String>(); siteMap.put(propertiesProperty, propertiesMap); } Object propVal = properties.get(property); if (propVal != null) propertiesMap.put(propertyName, propVal.toString()); else LOG.info(String.format("No value specified for configuration property, name = %s ", property)); } catch (Exception e) { LOG.debug(String.format("Error handling configuration property, name = %s", property), e); } } } return configurations; } protected  StackAdvisorResourceProvider(Set<String> propertyIds, Map<Type, String> keyPropertyIds,
      AmbariManagementController managementController); }
StackAdvisorResourceProvider extends ReadOnlyResourceProvider { protected Map<String, Map<String, Map<String, String>>> calculateConfigurations(Request request) { Map<String, Map<String, Map<String, String>>> configurations = new HashMap<String, Map<String, Map<String, String>>>(); Map<String, Object> properties = request.getProperties().iterator().next(); for (String property : properties.keySet()) { if (property.startsWith(CONFIGURATIONS_PROPERTY_ID)) { try { String propertyEnd = property.substring(CONFIGURATIONS_PROPERTY_ID.length()); String[] propertyPath = propertyEnd.split("/"); String siteName = propertyPath[0]; String propertiesProperty = propertyPath[1]; String propertyName = propertyPath[2]; Map<String, Map<String, String>> siteMap = configurations.get(siteName); if (siteMap == null) { siteMap = new HashMap<String, Map<String, String>>(); configurations.put(siteName, siteMap); } Map<String, String> propertiesMap = siteMap.get(propertiesProperty); if (propertiesMap == null) { propertiesMap = new HashMap<String, String>(); siteMap.put(propertiesProperty, propertiesMap); } Object propVal = properties.get(property); if (propVal != null) propertiesMap.put(propertyName, propVal.toString()); else LOG.info(String.format("No value specified for configuration property, name = %s ", property)); } catch (Exception e) { LOG.debug(String.format("Error handling configuration property, name = %s", property), e); } } } return configurations; } protected  StackAdvisorResourceProvider(Set<String> propertyIds, Map<Type, String> keyPropertyIds,
      AmbariManagementController managementController); @Inject static void init(StackAdvisorHelper instance); }
StackAdvisorResourceProvider extends ReadOnlyResourceProvider { protected Map<String, Map<String, Map<String, String>>> calculateConfigurations(Request request) { Map<String, Map<String, Map<String, String>>> configurations = new HashMap<String, Map<String, Map<String, String>>>(); Map<String, Object> properties = request.getProperties().iterator().next(); for (String property : properties.keySet()) { if (property.startsWith(CONFIGURATIONS_PROPERTY_ID)) { try { String propertyEnd = property.substring(CONFIGURATIONS_PROPERTY_ID.length()); String[] propertyPath = propertyEnd.split("/"); String siteName = propertyPath[0]; String propertiesProperty = propertyPath[1]; String propertyName = propertyPath[2]; Map<String, Map<String, String>> siteMap = configurations.get(siteName); if (siteMap == null) { siteMap = new HashMap<String, Map<String, String>>(); configurations.put(siteName, siteMap); } Map<String, String> propertiesMap = siteMap.get(propertiesProperty); if (propertiesMap == null) { propertiesMap = new HashMap<String, String>(); siteMap.put(propertiesProperty, propertiesMap); } Object propVal = properties.get(property); if (propVal != null) propertiesMap.put(propertyName, propVal.toString()); else LOG.info(String.format("No value specified for configuration property, name = %s ", property)); } catch (Exception e) { LOG.debug(String.format("Error handling configuration property, name = %s", property), e); } } } return configurations; } protected  StackAdvisorResourceProvider(Set<String> propertyIds, Map<Type, String> keyPropertyIds,
      AmbariManagementController managementController); @Inject static void init(StackAdvisorHelper instance);  }