/** replaces the attributes underneath the rootAttribute parameter with the given value; * see {@link #addLaunchAttributesMap(EntitySpec, Map)} for richer functionality */ public static void setLaunchAttribute(EntityInternal entity, String rootAttribute, Object value) { entity.config().set(ChefConfig.CHEF_LAUNCH_ATTRIBUTES.subKey(rootAttribute), value); }
public static void addToLaunchRunList(EntityInternal entity, String ...recipes) { for (String recipe: recipes) entity.config().set(ChefConfig.CHEF_LAUNCH_RUN_LIST, SetModifications.addItem(recipe)); }
/** replaces the attributes underneath the rootAttribute parameter with the given value; * see {@link #addLaunchAttributesMap(EntitySpec, Map)} for richer functionality */ public static void setLaunchAttribute(EntityInternal entity, String rootAttribute, Object value) { entity.config().set(ChefConfig.CHEF_LAUNCH_ATTRIBUTES.subKey(rootAttribute), value); }
@Override public void refreshInheritedConfigOfChildren() { for (Entity it : getChildren()) { ((EntityInternal)it).config().refreshInheritedConfig(); } }
/** Logs a warning if an entity has a value for a config key. */ public static void warnOnIgnoringConfig(Entity entity, ConfigKey<?> key) { if (((EntityInternal)entity).config().getRaw(key).isPresentAndNonNull()) log.warn("Ignoring "+key+" set on "+entity+" ("+entity.getConfig(key)+")"); }
@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 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")); }
private void checkReferences(final Entity entity, Map<ConfigKey<Entity>, Entity> keyToEntity) throws Exception { for (final ConfigKey<Entity> key : keyToEntity.keySet()) { try { Assert.assertEquals(getResolvedConfigInTask(entity, key).get(), keyToEntity.get(key), "For entity " + entity.toString() + ":"); } catch (Throwable t) { Exceptions.propagateIfFatal(t); Assert.fail("Wrong value for "+entity+":"+key+", "+((EntityInternal)entity).config().getLocalRaw(key)+": "+t, t); } } }
@Test public void testConfigBagContainsMatchesForFlagName() throws Exception { // Prefers flag-name, over config-key's name EntityInternal entity = mgmt.getEntityManager().createEntity(EntitySpec.create(MyEntity.class) .configure("myconfigflagname", "myval")); assertEquals(entity.config().getBag().getAllConfigAsConfigKeyMap(), ImmutableMap.of(MyEntity.MY_CONFIG_WITH_FLAGNAME, "myval")); assertEquals(entity.config().getBag().getAllConfig(), ImmutableMap.of("myentity.myconfigwithflagname", "myval")); assertEquals(entity.config().getLocalBag().getAllConfig(), ImmutableMap.of("myentity.myconfigwithflagname", "myval")); }
@Test public void testConfigBagContainsUnmatched() throws Exception { EntityInternal entity = mgmt.getEntityManager().createEntity(EntitySpec.create(MyEntity.class) .configure("notThere", "notThereVal")); assertEquals(entity.config().getBag().getAllConfigAsConfigKeyMap(), ImmutableMap.of(ConfigKeys.newConfigKey(Object.class, "notThere"), "notThereVal")); assertEquals(entity.config().getBag().getAllConfig(), ImmutableMap.of("notThere", "notThereVal")); assertEquals(entity.config().getLocalBag().getAllConfig(), ImmutableMap.of("notThere", "notThereVal")); }
@Test public void testChildCanOverrideConfigUsingFlagName() throws Exception { EntityInternal entity = mgmt.getEntityManager().createEntity(EntitySpec.create(MyEntity.class) .configure(MyChildEntity.MY_CHILD_CONFIG_WITH_FLAGNAME, "myval")); assertEquals(entity.config().getBag().getAllConfigAsConfigKeyMap(), ImmutableMap.of(MyChildEntity.MY_CHILD_CONFIG_WITH_FLAGNAME, "myval")); EntityInternal child = mgmt.getEntityManager().createEntity(EntitySpec.create(MyChildEntity.class) .parent(entity) .configure("mychildconfigflagname", "overrideMyval")); assertEquals(child.config().getBag().getAllConfigAsConfigKeyMap(), ImmutableMap.of(MyChildEntity.MY_CHILD_CONFIG_WITH_FLAGNAME, "overrideMyval")); assertEquals(child.config().getBag().getAllConfig(), ImmutableMap.of("mychildentity.myconfigwithflagname", "overrideMyval")); assertEquals(child.config().getLocalBag().getAllConfig(), ImmutableMap.of("mychildentity.myconfigwithflagname", "overrideMyval")); }
@Test public void testChildInheritsFromParent() throws Exception { EntityInternal entity = mgmt.getEntityManager().createEntity(EntitySpec.create(MyEntity.class) .configure("myentity.myconfig", "myval1")); EntityInternal child = mgmt.getEntityManager().createEntity(EntitySpec.create(MyChildEntity.class) .parent(entity)); assertEquals(child.config().getBag().getAllConfigAsConfigKeyMap(), ImmutableMap.of(MyEntity.MY_CONFIG, "myval1")); assertEquals(child.config().getBag().getAllConfig(), ImmutableMap.of("myentity.myconfig", "myval1")); assertEquals(child.config().getLocalBag().getAllConfig(), ImmutableMap.of()); }
@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 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 testUsingDeprecatedName() throws Exception { EntityInternal entity = app.addChild(EntitySpec.create(MyBaseEntity.class) .configure("oldSuperKey1", "myval")); EntityInternal entity2 = app.addChild(EntitySpec.create(MyBaseEntity.class) .configure("oldSuperKey1b", "myval")); assertEquals(entity.config().get(MyBaseEntity.SUPER_KEY_1), "myval"); assertEquals(entity2.config().get(MyBaseEntity.SUPER_KEY_1), "myval"); }
protected void failOnStep(ConfigKey<Boolean> latch) { if (((EntityInternal)entity).config().getRaw(latch).isPresent()) { DynamicTasks.queue("Failing task", new Runnable() { @Override public void run() { throw new IllegalStateException("forced fail"); } }); } }
@Test public void testPrefersNonDeprecatedName() throws Exception { EntityInternal entity = app.addChild(EntitySpec.create(MyBaseEntity.class) .configure("superKey1", "myval") .configure("oldSuperKey1", "mywrongval")); assertEquals(entity.config().get(MyBaseEntity.SUPER_KEY_1), "myval"); }
protected void checkTemplates(EntityInternal ent) { Map<String, Object> substitutions = MutableMap.copyOf(ent.config().get(SoftwareProcess.TEMPLATE_SUBSTITUTIONS)).asUnmodifiable(); String out0 = TemplateProcessor.processTemplateContents("hello "+"${field}", substitutions); Assert.assertEquals(out0, "hello val"); String out1 = TemplateProcessor.processTemplateContents("hello "+"${config['template.substitutions']['field']}", ent, substitutions); Assert.assertEquals(out1, "hello val"); }
@Test(enabled=false) public void testPrefersFlagNameOverConfigKeyName() throws Exception { EntityInternal entity = mgmt.getEntityManager().createEntity(EntitySpec.create(MyEntity.class) .configure("myconfigflagname", "myval") .configure("myentity.myconfigwithflagname", "shouldIgnoreAndPreferFlagName")); assertEquals(entity.config().getBag().getAllConfigAsConfigKeyMap(), ImmutableMap.of(MyEntity.MY_CONFIG_WITH_FLAGNAME, "myval")); }
@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"); }