/** * @deprecated since 0.10.0; use {@link #getFilteredLocationProperties(String, String, Map, Map)} */ @Deprecated protected Map<String, Object> getFilteredLocationProperties(String provider, String namedLocation, Map<String, ?> globalProperties) { return new LocationPropertiesFromBrooklynProperties().getLocationProperties(getPrefix(), namedLocation, globalProperties); }
@Test public void testExtractProviderProperties() throws Exception { String provider = "myprovider"; String namedLocation = null; Map<String, String> properties = Maps.newLinkedHashMap(); // prefer those in "named" over everything else properties.put("brooklyn.location.myprovider.privateKeyFile", "privateKeyFile-inProviderSpecific"); properties.put("brooklyn.location.privateKeyFile", "privateKeyFile-inLocationGeneric"); // prefer location-generic if nothing else properties.put("brooklyn.location.publicKeyFile", "publicKeyFile-inLocationGeneric"); Map<String, Object> conf = parser.getLocationProperties(provider, namedLocation, properties); assertEquals(conf.get("privateKeyFile"), "privateKeyFile-inProviderSpecific"); assertEquals(conf.get("publicKeyFile"), "publicKeyFile-inLocationGeneric"); }
@Test public void testConvertsDeprecatedFormats() throws Exception { String provider = "myprovider"; String namedLocation = "mynamed"; Map<String, String> properties = Maps.newLinkedHashMap(); properties.put("brooklyn.location.named.mynamed", "myprovider"); // prefer those in "named" over everything else properties.put("brooklyn.location.named.mynamed.private-key-file", "privateKeyFile-inNamed"); properties.put("brooklyn.location.myprovider.public-key-file", "publicKeyFile-inProviderSpecific"); properties.put("brooklyn.location.private-key-data", "privateKeyData-inGeneric"); Map<String, Object> conf = parser.getLocationProperties(provider, namedLocation, properties); assertEquals(conf.get("privateKeyFile"), "privateKeyFile-inNamed"); assertEquals(conf.get("publicKeyFile"), "publicKeyFile-inProviderSpecific"); assertEquals(conf.get("privateKeyData"), "privateKeyData-inGeneric"); }
@Test public void testThrowsIfProviderDoesNotMatchNamed() throws Exception { String provider = "myprovider"; String namedLocation = "mynamed"; Map<String, String> properties = Maps.newLinkedHashMap(); properties.put("brooklyn.location.named.mynamed", "completelydifferent"); try { Map<String, Object> conf = parser.getLocationProperties(provider, namedLocation, properties); } catch (IllegalStateException e) { if (!e.toString().contains("Conflicting configuration")) throw e; } } }
@Test public void testExtractNamedLocationProperties() throws Exception { String provider = "myprovider"; String namedLocation = "mynamed"; Map<String, String> properties = Maps.newLinkedHashMap(); properties.put("brooklyn.location.named.mynamed", "myprovider"); // prefer those in "named" over everything else properties.put("brooklyn.location.named.mynamed.privateKeyFile", "privateKeyFile-inNamed"); properties.put("brooklyn.location.myprovider.privateKeyFile", "privateKeyFile-inProviderSpecific"); properties.put("brooklyn.location.privateKeyFile", "privateKeyFile-inGeneric"); // prefer those in provider-specific over generic properties.put("brooklyn.location.myprovider.publicKeyFile", "publicKeyFile-inProviderSpecific"); properties.put("brooklyn.location.publicKeyFile", "publicKeyFile-inGeneric"); // prefer location-generic if nothing else properties.put("brooklyn.location.privateKeyData", "privateKeyData-inGeneric"); Map<String, Object> conf = parser.getLocationProperties(provider, namedLocation, properties); assertEquals(conf.get("privateKeyFile"), "privateKeyFile-inNamed"); assertEquals(conf.get("publicKeyFile"), "publicKeyFile-inProviderSpecific"); assertEquals(conf.get("privateKeyData"), "privateKeyData-inGeneric"); }
@Override protected Map<String, Object> getFilteredLocationProperties(String provider, String namedLocation, Map<String, ?> prioritisedProperties, Map<String, ?> globalProperties) { Map<String, Object> dockerConf = new LocationPropertiesFromBrooklynProperties().getLocationProperties(getPrefix(), namedLocation, globalProperties); Object providerInConf = dockerConf.get("provider"); if (providerInConf != null && !provider.equals(providerInConf)) { throw new IllegalArgumentException(provider + " location configured with provider '" + providerInConf + "', but must be blank or '" + provider + "'"); } String providerOrApi = "docker"; String regionName = (String) prioritisedProperties.get("region"); Map<String, Object> jcloudsConf = new JcloudsPropertiesFromBrooklynProperties().getJcloudsProperties(providerOrApi, regionName, namedLocation, globalProperties); return MutableMap.<String, Object>builder() .putAll(jcloudsConf) .putAll(dockerConf) .put("provider", providerOrApi) .build(); } }
Map<String, Object> filteredProperties = new LocationPropertiesFromBrooklynProperties().getLocationProperties(null, namedLocation, globalProperties); ConfigBag flags = ConfigBag.newInstance(locationFlags).putIfAbsent(filteredProperties); flags.remove(LocationInternal.NAMED_SPEC_NAME);
Map<String, Object> filteredProperties = new LocationPropertiesFromBrooklynProperties().getLocationProperties(null, namedLocation, (Map)globalProperties); MutableMap<Object, Object> flags = MutableMap.<Object, Object>builder() .putAll(filteredProperties)