public int getMappedPort(int portNumber) { Map<Integer, String> mapping = config().get(SshMachineLocation.TCP_PORT_MAPPINGS); for (Map.Entry<Integer, String> entry : mapping.entrySet()) { int containerPort = HostAndPort.fromString(entry.getValue()).getPort(); if (containerPort == portNumber) { return entry.getKey(); } } return -1; }
@Test public void testSetConfigPrefersNonDeprecated() throws Exception { Map<?,?> remaining = ConfigUtilsInternal.setAllConfigKeys( ImmutableMap.of("key1", "myval", "oldKey1", "myOldVal1", "oldKey1b", "myOldVal1b"), ImmutableList.of(key1), app); assertEquals(app.config().get(key1), "myval"); // Should remove deprecated value as well (and warn about it) assertEquals(remaining, ImmutableMap.of()); }
@Override public void setEntity(EntityLocal entity) { super.setEntity(entity); effector = getEffector(); if (Boolean.TRUE.equals(config().get(RUNNING))) { running.set(true); resubmitOnResume(); } AttributeSensor<Boolean> sensor = config().get(START_SENSOR); subscriptions().subscribe(ImmutableMap.of("notifyOfInitialValue", true), entity, sensor, this); }
@Override public StubContainer getOwner() { return (StubContainer) config().get(OWNER); }
public String getField1() { return config().get(REPLACEMENT_FOR_FIELD_1); } }
@Test public void testUsingDeprecatedName() throws Exception { MyApp entity = app().addChild(EntitySpec.create(MyApp.class) .configure("oldKey1", "myval")); assertEquals(entity.config().get(MyApp.KEY_1), "myval"); rebind(); Entity newEntity = mgmt().getEntityManager().getEntity(entity.getId()); assertEquals(newEntity.config().get(MyApp.KEY_1), "myval"); // Expect the persisted state of the entity to have used the non-deprecated name. String allLines = getPersistanceFileContents(BrooklynObjectType.ENTITY, newEntity.getId()); assertFalse(allLines.contains("oldKey1"), "contains 'oldKey1', allLines="+allLines); assertTrue(allLines.contains("key1"), "contains 'key1', allLines="+allLines); }
@Override public <T> T getConfig(ConfigKey<T> key) { return config().get(key); }
@Test public void testResolvesListAndMapProperties() throws Exception { brooklynProperties.put("brooklyn.location.jclouds.softlayer.prop1", "[ a, b ]"); brooklynProperties.put("brooklyn.location.jclouds.softlayer.prop2", "{ a: 1, b: 2 }"); brooklynProperties.put("brooklyn.location.named.foo", "jclouds:softlayer:ams01"); JcloudsLocation l = resolve("named:foo"); assertJcloudsEquals(l, "softlayer", "ams01"); assertEquals(l.config().get(new SetConfigKey<String>(String.class, "prop1")), MutableSet.of("a", "b")); assertEquals(l.config().get(new MapConfigKey<String>(String.class, "prop2")), MutableMap.of("a", 1, "b", 2)); }
@Test public void testMergesKeyFromRuntimeParentWithOwnDeprecated() throws Exception { EntityInternal entity = app.addChild(EntitySpec.create(TestEntity.class) .configure("confMapDeepMerge", ImmutableMap.of("mykey", "myval"))); EntityInternal child = entity.addChild(EntitySpec.create(MyEntity.class) .configure("oldConfMapDeepMerge", ImmutableMap.of("mykey2", "myval2"))); assertEquals(child.config().get(MyEntity.CONF_MAP_DEEP_MERGE), ImmutableMap.of("mykey", "myval", "mykey2", "myval2")); }
@Test public void testMergesDeprecatedKeyFromRuntimeParentWithOwn() throws Exception { EntityInternal entity = app.addChild(EntitySpec.create(TestEntity.class) .configure("oldConfMapDeepMerge", ImmutableMap.of("mykey", "myval"))); EntityInternal child = entity.addChild(EntitySpec.create(MyEntity.class) .configure("confMapDeepMerge", ImmutableMap.of("mykey2", "myval2"))); assertEquals(child.config().get(MyEntity.CONF_MAP_DEEP_MERGE), ImmutableMap.of("mykey", "myval", "mykey2", "myval2")); }
@Test public void testSetAndGetDynamicConfigUsingDeprecatedName() throws Exception { // Using BasicEntity, which doesn't know about KEY_1 EntityInternal entity = (EntityInternal) app.addChild(EntitySpec.create(BasicEntity.class)); // Set using deprecated name entity.config().putAll(ImmutableMap.of("oldKey1", "myval3")); assertEquals(entity.config().get(KEY_1), "myval3"); // Set using pseudo-generated strongly typed key with deprecated name entity.config().set(ConfigKeys.newConfigKey(Object.class, "oldKey1"), "myval4"); assertEquals(entity.config().get(KEY_1), "myval4"); }
@Test public void testInheritsDeprecatedKeyFromRuntimeParent() throws Exception { EntityInternal entity = app.addChild(EntitySpec.create(TestEntity.class) .configure("oldSuperKey1", "myval")); EntityInternal child = entity.addChild(EntitySpec.create(MyBaseEntity.class)); assertEquals(child.config().get(MyBaseEntity.SUPER_KEY_1), "myval"); }
@Override public void rebind() { super.rebind(); dockerHost = (DockerHost) config().get(OWNER); machine = config().get(MACHINE); portForwarder = config().get(PORT_FORWARDER); jcloudsLocation = config().get(JCLOUDS_LOCATION); if (dockerHost != null && getConfig(LOCATION_NAME) != null) { register(); } addReloadListener(); }
@Override public void setEntity(EntityLocal entity) { super.setEntity(entity); Object target = config().get(SUSPEND_TARGET); Preconditions.checkNotNull(target, "Suspend target required"); Preconditions.checkNotNull(getTargetPolicy(), "Can't find target policy set in " + SUSPEND_TARGET.getName() + ": " + target); subscribe(); uniqueTag = JavaClassNames.simpleClassName(getClass())+":"+getConfig(SUSPEND_SENSOR).getName()+":"+getConfig(RESUME_SENSOR).getName(); }
@Test public void testUsingDeprecatedName() throws Exception { EntityInternal entity = app.addChild(EntitySpec.create(MyEntity.class) .configure("oldConfMapDeepMerge", ImmutableMap.of("mykey", "myval"))); assertEquals(entity.config().get(MyEntity.CONF_MAP_DEEP_MERGE), ImmutableMap.of("mykey", "myval")); }
protected PortForwardManager getPortForwardManager() { PortForwardManager portForwardManager = config().get(PORT_FORWARD_MANAGER); if (portForwardManager == null) { portForwardManager = (PortForwardManager) getManagementContext().getLocationRegistry().getLocationManaged(PortForwardManagerLocationResolver.PFM_GLOBAL_SPEC); } return portForwardManager; } }
@Test public void testGetConfigMapWithSubKeys() throws Exception { TestEntity entity = mgmt.getEntityManager().createEntity(EntitySpec.create(TestEntity.class) .configure(TestEntity.CONF_MAP_THING.subKey("mysub"), "myval")); assertEquals(entity.config().get(TestEntity.CONF_MAP_THING), ImmutableMap.of("mysub", "myval")); assertEquals(entity.config().getNonBlocking(TestEntity.CONF_MAP_THING).get(), ImmutableMap.of("mysub", "myval")); assertEquals(entity.config().get(TestEntity.CONF_MAP_THING.subKey("mysub")), "myval"); assertEquals(entity.config().getNonBlocking(TestEntity.CONF_MAP_THING.subKey("mysub")).get(), "myval"); }
@Test public void testUsingDeprecatedNameInLocation() throws Exception { MyLocation loc = mgmt.getLocationManager().createLocation(LocationSpec.create(MyLocation.class) .configure("oldKey1", "myval")); assertEquals(loc.config().get(MyLocation.KEY_1), "myval"); }
protected MachineLocation getMachine() { Supplier<MachineLocation> supplier = config().get(MACHINE); if (supplier != null) { return supplier.get(); } else { return Locations.findUniqueMachineLocation(entity.getLocations()).get(); } }