Java Code Examples for org.apache.brooklyn.api.entity.Entity#getConfig()
The following examples show how to use
org.apache.brooklyn.api.entity.Entity#getConfig() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ObjectsYamlTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testBrooklynObjectWithFactoryMethodWithArgCoercion() throws Exception { Entity testEntity = setupAndCheckTestEntityInBasicYamlWith( " brooklyn.config:", " test.confObject:", " $brooklyn:object:", " type: " + Time.class.getName(), " factoryMethod.name: makeDateString", " factoryMethod.args:", " - 1000", " - yyyy-MM-dd'T'HH:mm:ss", " - UTC"); String val = (String) testEntity.getConfig(TestEntity.CONF_OBJECT); assertEquals(val, "1970-01-01T00:00:01"); }
Example 2
Source File: ObjectsYamlTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testBrooklynObjectWithParameterisedConstructor() throws Exception { Entity testEntity = setupAndCheckTestEntityInBasicYamlWith( " brooklyn.config:", " test.confObject:", " $brooklyn:object:", " type: "+ObjectsYamlTest.class.getName()+"$TestObject", " constructor.args:", " - frog", " - 7", " - $brooklyn:object:", " type: org.apache.brooklyn.camp.brooklyn.SimpleTestPojo" ); Object testObject = testEntity.getConfig(TestEntity.CONF_OBJECT); Assert.assertTrue(testObject instanceof TestObject, "Expected a TestObject: "+testObject); Assert.assertTrue(managementContextInjected.get()); Assert.assertEquals(((TestObject) testObject).getNumber(), Integer.valueOf(7)); Assert.assertEquals(((TestObject) testObject).getString(), "frog"); Object testObjectObject = ((TestObject) testObject).getObject(); Assert.assertTrue(testObjectObject instanceof SimpleTestPojo, "Expected a SimpleTestPojo: "+testObjectObject); }
Example 3
Source File: ObjectsYamlTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testFactorArgsAsDeferredSuppliers() throws Exception { Entity testEntity = setupAndCheckTestEntityInBasicYamlWith( " brooklyn.config:", " mystring: myval", " myint: 123", " mydouble: 1.4", " test.confObject:", " $brooklyn:object:", " type: "+ObjectsYamlTest.class.getName()+"$TestObject", " factoryMethod.name: newTestObject", " factoryMethod.args:", " - $brooklyn:config(\"mystring\")", " - $brooklyn:config(\"myint\")", " - myThirdParam"); TestObject testObject = (TestObject) testEntity.getConfig(TestEntity.CONF_OBJECT); assertEquals(testObject.getNumber(), Integer.valueOf(124)); // factory method adds one assertEquals(testObject.getString(), "myval-suffix"); assertEquals(testObject.getObject(), "myThirdParam"); }
Example 4
Source File: ObjectsYamlTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testConstructorArgsAsDeferredSuppliers() throws Exception { Entity testEntity = setupAndCheckTestEntityInBasicYamlWith( " brooklyn.config:", " mystring: myval", " myint: 123", " mydouble: 1.4", " test.confObject:", " $brooklyn:object:", " type: "+ObjectsYamlTest.class.getName()+"$TestObject", " constructor.args:", " - $brooklyn:config(\"mystring\")", " - $brooklyn:config(\"myint\")", " - myThirdParam"); TestObject testObject = (TestObject) testEntity.getConfig(TestEntity.CONF_OBJECT); assertEquals(testObject.getNumber(), Integer.valueOf(123)); assertEquals(testObject.getString(), "myval"); assertEquals(testObject.getObject(), "myThirdParam"); }
Example 5
Source File: ObjectsYamlTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test public void testBrooklynObjectWithFactoryMethodNoArgs() throws Exception { Entity testEntity = setupAndCheckTestEntityInBasicYamlWith( " brooklyn.config:", " test.confObject:", " $brooklyn:object:", " type: "+ObjectsYamlTest.class.getName()+"$TestObject", " factoryMethod.name: newTestObjectWithNoArgs"); TestObject testObject = (TestObject) testEntity.getConfig(TestEntity.CONF_OBJECT); assertEquals(testObject.getString(), "myDefaultFirst"); assertEquals(testObject.getNumber(), Integer.valueOf(1)); assertEquals(testObject.getObject(), "myDefaultThird"); }
Example 6
Source File: DownloadSubstituters.java From brooklyn-server with Apache License 2.0 | 5 votes |
public static Map<String,Object> getBasicEntitySubstitutions(EntityDriver driver) { Entity entity = driver.getEntity(); String type = entity.getEntityType().getName(); String simpleType = type.substring(type.lastIndexOf(".")+1); String version = entity.getConfig(BrooklynConfigKeys.SUGGESTED_VERSION); return MutableMap.<String,Object>builder() .put("entity", entity) .put("driver", driver) .put("type", type) .put("simpletype", simpleType) .putIfNotNull("version", version) .build(); }
Example 7
Source File: CloudFoundryYamlLiveTest.java From SeaCloudsPlatform with Apache License 2.0 | 5 votes |
private Entity findChildEntitySpecByPlanId(Application app, String planId) { for (Entity child : app.getChildren()) { String childPlanId = child.getConfig(BrooklynCampConstants.PLAN_ID); if ((childPlanId != null) && (childPlanId.equals(planId))) { return child; } } return null; }
Example 8
Source File: ConfigNestedYamlTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
protected Entity checkEntity(Entity ent, boolean expectDotSyntaxToWork) throws Exception { String dotSyntax = ent.getConfig( ConfigKeys.newStringConfigKey("template.substitutions.field") ); Assert.assertEquals(dotSyntax, expectDotSyntaxToWork ? "val" : null, "wrong value for dot syntax: "+dotSyntax); // observed in some situations we get the dot syntax instead! // Assert.assertEquals(dotSyntax, "val", "wrong value for dot syntax: "+dotSyntax); // might be okay if the above does happen (though I can't get it reproduced); // however the following must _always_ work // strongly typed Map<?,?> map1 = ent.getConfig(SoftwareProcess.TEMPLATE_SUBSTITUTIONS); Assert.assertNotNull(map1, "Nothing found for 'template.substitutions'"); Assert.assertTrue(map1.containsKey("field"), "missing 'field' in "+map1); Assert.assertEquals(map1.get("field"), "val", "wrong value for 'field' in "+map1); // because SoftwareProcess declares TEMPLATE_SUBSTITUTIONS it rewrites where map entries are put // (to use dot syntax) so if the entity is a software process (ie expectDotSyntaxToWork) // neither "anonymous key" lookup nor template processing deep-map works, // unless we switch from the query key to own key when we do the key value lookup // (we should probably be doing that any way however!) // (those two tests deliberately fail in this commit, fixed in following commit) // anonymous key Map<?,?> map2 = ent.getConfig(ConfigKeys.newConfigKey(Map.class, "template.substitutions")); Assert.assertNotNull(map2, "Nothing found for 'template.substitutions'"); Assert.assertTrue(map2.containsKey("field"), "missing 'field' in "+map2); Assert.assertEquals(map2.get("field"), "val", "wrong value for 'field' in "+map2); checkTemplates((EntityInternal) ent); return ent; }
Example 9
Source File: SameServerDriverLifecycleEffectorTasks.java From brooklyn-server with Apache License 2.0 | 5 votes |
private void addRequiredOpenPortsRecursively(Entity entity, Set<Integer> ports) { ports.addAll(entity.getConfig(SameServerEntity.REQUIRED_OPEN_LOGIN_PORTS)); Boolean portsAutoInfer = entity.getConfig(SameServerEntity.INBOUND_PORTS_AUTO_INFER); String portsRegex = entity.getConfig(SameServerEntity.INBOUND_PORTS_CONFIG_REGEX); ports.addAll(InboundPortsUtils.getRequiredOpenPorts(entity, portsAutoInfer, portsRegex)); LOG.debug("getRequiredOpenPorts detected default {} for {}", ports, entity); for (Entity child : entity.getChildren()) { addRequiredOpenPortsRecursively(child, ports); } }
Example 10
Source File: EntitiesYamlTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test public void testUndeclaredExplicitFlagsIgnored() throws Exception { Entity testEntity = setupAndCheckTestEntityInBasicYamlWith( " brooklyn.flags:", " test.dynamic.confName: Foo Bar"); String dynamicConfNameValue = testEntity.getConfig(ConfigKeys.newStringConfigKey("test.dynamic.confName")); Assert.assertNull(dynamicConfNameValue); }
Example 11
Source File: TargetableTestComponentImpl.java From brooklyn-server with Apache License 2.0 | 5 votes |
/** * Find the target entity in the given execution context. * * @see {@link #resolveTarget()}. */ public static Entity resolveTarget(ExecutionContext executionContext, Entity entity) { Entity target = entity.getConfig(TARGET_ENTITY); if (null == target) { target = getTargetById(executionContext, entity); } return target; }
Example 12
Source File: TestFrameworkAssertions.java From brooklyn-server with Apache License 2.0 | 5 votes |
protected static List<Map<String, Object>> getAsListOfMaps(Entity entity, ConfigKey<Object> key) { Object config = entity.getConfig(key); Maybe<Map<String, Object>> maybeMap = TypeCoercions.tryCoerce(config, new TypeToken<Map<String, Object>>() {}); if (maybeMap.isPresent()) { return Collections.singletonList(maybeMap.get()); } Maybe<List<Map<String, Object>>> maybeList = TypeCoercions.tryCoerce(config, new TypeToken<List<Map<String, Object>>>() {}); if (maybeList.isPresent()) { return maybeList.get(); } throw new FatalConfigurationRuntimeException(key.getDescription() + " is not a map or list of maps"); }
Example 13
Source File: SeaCloudsMonitoringInitializationPolicies.java From SeaCloudsPlatform with Apache License 2.0 | 4 votes |
private String getCampPlanId(Entity child) { return child.getConfig(BrooklynCampConstants.PLAN_ID); }
Example 14
Source File: MiscClassesRebindTest.java From brooklyn-server with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") protected <T> T getTestKeyFromEntityMemento(String label, String entityId, Class<T> type) throws Exception { Entity e = loadEntityMemento(label, entityId); return (T) e.getConfig(TEST_KEY); }
Example 15
Source File: EntityFunctions.java From brooklyn-server with Apache License 2.0 | 4 votes |
@Override public T apply(Entity input) { return (input == null) ? null : input.getConfig(key); }
Example 16
Source File: KnifeTaskFactory.java From brooklyn-library with Apache License 2.0 | 4 votes |
protected <T> T entityConfig(ConfigKey<T> key) { Entity entity = entity(); if (entity!=null) return entity.getConfig(key); return null; }
Example 17
Source File: BrooklynNodeUpgradeEffectorBody.java From brooklyn-server with Apache License 2.0 | 4 votes |
private String dryRunUpdate(ConfigBag parameters) { // TODO require entity() node state master or hot standby AND require persistence enabled, or a new 'force_attempt_upgrade' parameter to be applied // TODO could have a 'skip_dry_run_upgrade' parameter // TODO could support 'dry_run_only' parameter, with optional resumption tasks (eg new dynamic effector) // 1 add new brooklyn version entity as child (so uses same machine), with same config apart from things in parameters final Entity dryRunChild = entity().addChild(createDryRunSpec() .displayName("Upgraded Version Dry-Run Node") // install dir and label are recomputed because they are not inherited, and download_url will normally be different .configure(parameters.getAllConfig())); //force this to start as hot-standby // TODO alternatively could use REST API as in BrooklynClusterUpgradeEffectorBody // TODO Want better way to append to the config (so can do it all in the spec) String launchParameters = dryRunChild.getConfig(BrooklynNode.EXTRA_LAUNCH_PARAMETERS); if (Strings.isBlank(launchParameters)) launchParameters = ""; else launchParameters += " "; launchParameters += "--highAvailability "+HighAvailabilityMode.HOT_STANDBY; ((EntityInternal)dryRunChild).config().set(BrooklynNode.EXTRA_LAUNCH_PARAMETERS, launchParameters); final String dryRunNodeUid = dryRunChild.getId(); ((EntityInternal)dryRunChild).setDisplayName("Dry-Run Upgraded Brooklyn Node ("+dryRunNodeUid+")"); DynamicTasks.queue(Effectors.invocation(dryRunChild, BrooklynNode.START, ConfigBag.EMPTY)); // 2 confirm hot standby status DynamicTasks.queue(EntityTasks.requiringAttributeEventually(dryRunChild, BrooklynNode.MANAGEMENT_NODE_STATE, Predicates.equalTo(ManagementNodeState.HOT_STANDBY), Duration.FIVE_MINUTES)); // 3 stop new version DynamicTasks.queue(Tasks.builder().displayName("shutdown transient node") .add(Effectors.invocation(dryRunChild, BrooklynNode.STOP_NODE_BUT_LEAVE_APPS, ImmutableMap.of(StopSoftwareParameters.STOP_MACHINE_MODE, StopMode.NEVER))) .build()); DynamicTasks.queue(Tasks.<Void>builder().displayName("remove transient node").body( new Runnable() { @Override public void run() { Entities.unmanage(dryRunChild); } } ).build()); return dryRunChild.getId(); }
Example 18
Source File: CouchbaseNodeSshDriver.java From brooklyn-library with Apache License 2.0 | 4 votes |
@Override public void addReplicationRule(Entity toCluster, String fromBucket, String toBucket) { DynamicTasks.queue(DependentConfiguration.attributeWhenReady(toCluster, Attributes.SERVICE_UP)).getUnchecked(); String destName = CouchbaseClusterImpl.getClusterName(toCluster); log.info("Setting up XDCR for " + fromBucket + " from " + CouchbaseClusterImpl.getClusterName(getEntity()) + " (via " + getEntity() + ") " + "to " + destName + " (" + toCluster + ")"); Entity destPrimaryNode = toCluster.getAttribute(CouchbaseCluster.COUCHBASE_PRIMARY_NODE); String destHostname = destPrimaryNode.getAttribute(Attributes.HOSTNAME); String destUsername = toCluster.getConfig(CouchbaseNode.COUCHBASE_ADMIN_USERNAME); String destPassword = toCluster.getConfig(CouchbaseNode.COUCHBASE_ADMIN_PASSWORD); // on the REST API there is mention of a 'type' 'continuous' but i don't see other refs to this // PROTOCOL Select REST protocol or memcached for replication. xmem indicates memcached while capi indicates REST protocol. // looks like xmem is the default; leave off for now // String replMode = "xmem"; DynamicTasks.queue(TaskTags.markInessential(SshEffectorTasks.ssh( couchbaseCli("xdcr-setup") + getCouchbaseHostnameAndCredentials() + " --create" + " --xdcr-cluster-name=" + BashStringEscapes.wrapBash(destName) + " --xdcr-hostname=" + BashStringEscapes.wrapBash(destHostname) + " --xdcr-username=" + BashStringEscapes.wrapBash(destUsername) + " --xdcr-password=" + BashStringEscapes.wrapBash(destPassword) ).summary("create xdcr destination " + destName).newTask())); // would be nice to auto-create bucket, but we'll need to know the parameters; the port in particular is tedious // ((CouchbaseNode)destPrimaryNode).bucketCreate(toBucket, "couchbase", null, 0, 0); DynamicTasks.queue(SshEffectorTasks.ssh( couchbaseCli("xdcr-replicate") + getCouchbaseHostnameAndCredentials() + " --create" + " --xdcr-cluster-name=" + BashStringEscapes.wrapBash(destName) + " --xdcr-from-bucket=" + BashStringEscapes.wrapBash(fromBucket) + " --xdcr-to-bucket=" + BashStringEscapes.wrapBash(toBucket) // + " --xdcr-replication-mode="+replMode ).summary("configure replication for " + fromBucket + " to " + destName + ":" + toBucket).newTask()); }
Example 19
Source File: CouchbaseClusterImpl.java From brooklyn-library with Apache License 2.0 | 4 votes |
/** finds the cluster name specified for a node or a cluster, * using {@link CouchbaseCluster#CLUSTER_NAME} or falling back to the cluster (or node) ID. */ public static String getClusterName(Entity node) { String name = node.getConfig(CLUSTER_NAME); if (!Strings.isBlank(name)) return Strings.makeValidFilename(name); return getClusterOrNode(node).getId(); }
Example 20
Source File: SeaCloudsMonitoringInitializationPolicies.java From SeaCloudsPlatform with Apache License 2.0 | 4 votes |
private String getToscaPlanId(Entity child) { return child.getConfig(TOSCA_ID); }