本文整理了Java中org.apache.brooklyn.api.entity.Entity.invoke()
方法的一些代码示例,展示了Entity.invoke()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Entity.invoke()
方法的具体详情如下:
包路径:org.apache.brooklyn.api.entity.Entity
类名称:Entity
方法名:invoke
[英]Invokes the given effector, with the given parameters to that effector.
[中]使用该效应器的给定参数调用给定效应器。
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@Override
public String addRegion(String location) {
Preconditions.checkNotNull(location, "location");
Location l = getManagementContext().getLocationRegistry().getLocationManaged(location);
addLocations(Arrays.asList(l));
Entity e = addCluster(l);
((EntityInternal)e).addLocations(Arrays.asList(l));
if (e instanceof Startable) {
Task<?> task = e.invoke(Startable.START, ImmutableMap.of("locations", ImmutableList.of(l)));
task.getUnchecked();
}
return e.getId();
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
private Object invokeEffectorNamed(Entity target, String effectorName, ConfigBag params) {
LOG.debug("{} forwarding effector invocation on {} to entity={}, effector={}, parameters={}",
new Object[]{this, entity(), target, effectorName, params});
Effector<?> effector = EffectorUtils.findEffectorDeclared(target, effectorName).get();
return target.invoke(effector, params.getAllConfig()).getUnchecked();
}
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
/** the composed effector should allow us to inspect its children */
@Test
public void testComposedEffector() throws Exception {
Entity txp1 = app.createAndManageChild(EntitySpec.create(Entity.class, Txp1Entity.class));
Task<Integer> e = txp1.invoke(TWO_X_PLUS_ONE, MutableMap.of("numberToStartWith", 3));
Assert.assertTrue(e instanceof DynamicSequentialTask);
Assert.assertEquals(e.get(), (Integer)7);
Assert.assertEquals( Iterables.size( ((HasTaskChildren)e).getChildren() ), 1);
Task<?> child = ((HasTaskChildren)e).getChildren().iterator().next();
Assert.assertEquals( Iterables.size( ((HasTaskChildren)child).getChildren() ), 1);
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@Test
public void testEffectorWithoutBodyFails() throws Exception {
Entity doubler = app.createAndManageChild(EntitySpec.create(TestEntity.class));
boolean failed = false;
try {
doubler.invoke(DOUBLE_BODYLESS, MutableMap.of("numberToDouble", 3));
} catch (Exception e) {
failed = true;
}
if (!failed) Assert.fail("doubling should have failed because it had no body");
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
/** the composed effector should allow us to inspect its children */
@Test
public void testComposedEffectorBasic() throws Exception {
Entity txp1 = app.createAndManageChild(EntitySpec.create(Entity.class, Txp1Entity.class));
Task<Integer> e = txp1.invoke(TWO_X_PLUS_ONE_BASIC, MutableMap.of("numberToStartWith", 3));
Assert.assertTrue(e instanceof DynamicSequentialTask);
Assert.assertEquals(e.get(), (Integer)7);
Assert.assertEquals( Iterables.size( ((HasTaskChildren)e).getChildren() ), 2);
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-software-webapp
@Test
public void testTestJavaWebAppEntityStarts() throws Exception {
Entity test = app.createAndManageChild(EntitySpec.create(TestJavaWebAppEntity.class));
test.invoke(Startable.START, ImmutableMap.of("locations", ImmutableList.of(loc))).get();
EntityAsserts.assertAttributeEqualsEventually(test, Attributes.SERVICE_UP, true);
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@Test
// also assert it works when the effector is defined on an entity
public void testSimpleEffectorOnEntity() throws Exception {
Entity doubler = app.createAndManageChild(EntitySpec.create(Entity.class, DoublingEntity.class));
Assert.assertEquals(doubler.invoke(DOUBLE_1, MutableMap.of("numberToDouble", 3)).get(), (Integer)6);
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
public static String doEffectorCallBrooklyn(Entity me) {
return me.invoke(Effectors.effector(String.class, "sayHI").buildAbstract(), ImmutableMap.of("name", "brooklyn")).getUnchecked();
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@Test
// also assert it works when the entity is defined on an entity
public void testOverriddenEffectorOnEntity() throws Exception {
Entity doubler = app.createAndManageChild(EntitySpec.create(Entity.class, BadDoublingEntity.class));
Assert.assertEquals(doubler.invoke(DoublingEntity.DOUBLE, MutableMap.of("numberToDouble", 3, "numberToStartWith", 3)).get(), (Integer)7);
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@Test
public void testEffectorWithBodyWorksEvenIfNotOnEntity() throws Exception {
Entity doubler = app.createAndManageChild(EntitySpec.create(TestEntity.class));
Assert.assertEquals(doubler.invoke(DOUBLE_1, MutableMap.of("numberToDouble", 3)).get(), (Integer)6);
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-camp
@Override
protected JcloudsMachineLocation obtainMachine(JcloudsLocation jcloudsLoc, Map<?,?> props) throws Exception {
final MachineEntity entity = (MachineEntity) Iterables.getOnlyElement(origApp.getChildren());
origApp.invoke(Startable.START, ImmutableMap.<String, Object>of()).get();
// Execute ssh (with RecordingSshTool), and confirm was given resolved password
entity.execCommand("mycmd");
Map<?, ?> constructorProps = RecordingSshTool.getLastConstructorProps();
ExecCmd execCmd = RecordingSshTool.getLastExecCmd();
assertEquals(constructorProps.get("password"), "myYamlPassword", "constructorProps: "+constructorProps+"; execProps: "+execCmd.props);
return Machines.findUniqueMachineLocation(entity.getLocations(), JcloudsMachineLocation.class).get();
}
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@Test
// also assert it works when an abstract effector name is passed in to the entity
public void testSimpleEffectorNameMatching() throws Exception {
Entity doubler = app.createAndManageChild(EntitySpec.create(Entity.class, DoublingEntity.class));
Assert.assertEquals(doubler.invoke(Effectors.effector(Integer.class, "double").buildAbstract(), MutableMap.of("numberToDouble", 3)).get(), (Integer)6);
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-camp
@Test
public void testThrowsIfTargetDoesNotResolve() throws Exception {
final String effectorName = "proxy-effector";
Entity app = createAndStartApplication(
"location: localhost",
"services:",
"- type: " + BasicEntity.class.getName(),
" brooklyn.initializers:",
" - type: org.apache.brooklyn.core.effector.ProxyEffector",
" brooklyn.config:",
" name: " + effectorName,
" targetEntity: $brooklyn:entity(\"skhbfskdbf\")",
" targetEffector: identityEffector"
);
waitForApplicationTasks(app);
Entity basicEntity = app.getChildren().iterator().next();
Effector<?> effector = basicEntity.getEntityType().getEffectorByName(effectorName).get();
try {
basicEntity.invoke(effector, ImmutableMap.<String, Object>of()).get();
Asserts.shouldHaveFailedPreviously("expected exception when invoking effector that does not exist");
} catch (Exception e) {
Asserts.expectedFailure(e);
}
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-camp
@Override
protected JcloudsLocation newJcloudsLocation(ComputeServiceRegistry computeServiceRegistry) throws Exception {
ByonComputeServiceStaticRef.setInstance(computeServiceRegistry);
String yaml = Joiner.on("\n").join(
"location:",
" "+LOCATION_CATALOG_ID+":",
" identity: $brooklyn:external(\"creds\", \"test-identity\")",
" credential: $brooklyn:external(\"creds\", \"test-credential\")",
"services:\n"+
"- type: org.apache.brooklyn.entity.stock.BasicApplication");
EntitySpec<?> spec =
mgmt().getTypeRegistry().createSpecFromPlan(CampTypePlanTransformer.FORMAT, yaml, RegisteredTypeLoadingContexts.spec(Application.class), EntitySpec.class);
final Entity app = mgmt().getEntityManager().createEntity(spec);
app.invoke(Startable.START, ImmutableMap.<String, Object>of()).get();
JcloudsLocation result = (JcloudsLocation) Iterables.getOnlyElement(app.getLocations());
assertEquals(result.getIdentity(), "myidentity");
assertEquals(result.getCredential(), "mycredential");
return result;
}
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-camp
@Test
public void testCatalogBomLoadsFileInBundle() throws Exception {
bm.setDefaultClassForLoading(getClass());
File jf = bm.createJarFromClasspathDir("osgi/catalog-bundle-1");
// add a file in the bundle
String customText = "Sample data "+Identifiers.makeRandomId(4);
jf = bm.copyAdding(jf, MutableMap.of(
new ZipEntry("sample.txt"), (InputStream) new ByteArrayInputStream(customText.getBytes())));
installBundle(jf);
String yaml = Strings.lines("name: simple-app-yaml",
"services:",
"- type: " + "basic1",
" brooklyn.initializers:",
" - type: "+GetFileContentsEffector.class.getName());
Entity app = createAndStartApplication(yaml);
Entity basic1 = Iterables.getOnlyElement( app.getChildren() );
// check the file put in the bundle gets loaded without needing to do anything special
String contents = basic1.invoke(GetFileContentsEffector.GET_FILE_CONTENTS, MutableMap.of(GetFileContentsEffector.FILENAME.getName(), "classpath://sample.txt")).get();
Asserts.assertEquals(contents, customText);
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-camp
protected Entity createAndStartApplication(String input, Map<String,?> startParameters) throws Exception {
EntitySpec<?> spec =
mgmt().getTypeRegistry().createSpecFromPlan(CampTypePlanTransformer.FORMAT, input, RegisteredTypeLoadingContexts.spec(Application.class), EntitySpec.class);
final Entity app = mgmt().getEntityManager().createEntity(spec);
getLogger().info("Test created app, and will now start " + app);
// start the app (happens automatically if we use camp to instantiate, but not if we use crate spec approach)
app.invoke(Startable.START, startParameters).get();
return app;
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-camp
protected Entity createAndStartApplicationAsync(String yaml, Map<String,?> startParameters) throws Exception {
EntitySpec<?> spec =
mgmt().getTypeRegistry().createSpecFromPlan(CampTypePlanTransformer.FORMAT, yaml, RegisteredTypeLoadingContexts.spec(Application.class), EntitySpec.class);
final Entity app = brooklynMgmt.getEntityManager().createEntity(spec);
// start the app (happens automatically if we use camp to instantiate, but not if we use create spec approach).
// Note calling .get() on task, so this is non-blocking.
app.invoke(Startable.START, startParameters);
return app;
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-camp
protected Entity createAndStartApplication(String input, Map<String,?> startParameters) throws Exception {
EntitySpec<?> spec =
mgmt().getTypeRegistry().createSpecFromPlan(CampTypePlanTransformer.FORMAT, input, RegisteredTypeLoadingContexts.spec(Application.class), EntitySpec.class);
final Entity app = brooklynMgmt.getEntityManager().createEntity(spec);
// start the app (happens automatically if we use camp to instantiate, but not if we use crate spec approach)
app.invoke(Startable.START, startParameters).get();
return app;
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-camp
@Test
public void testRebindsClusterWithEntitySpecWrappingOsgi() throws Exception {
RegisteredType ci = installWrappedMoreEntity();
EntitySpec<DynamicCluster> clusterSpec = EntitySpec.create(DynamicCluster.class)
.configure(DynamicCluster.INITIAL_SIZE, 1)
.configure(DynamicCluster.MEMBER_SPEC, origManagementContext.getTypeRegistry().createSpec(ci, null, EntitySpec.class));
final Entity app = mgmt().getEntityManager().createEntity(EntitySpec.create(BasicApplication.class).child(clusterSpec));
app.invoke(Startable.START, MutableMap.of()).get();
rebind();
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-camp
@Test
public void testClusterWithEntitySpecFromOsgi() throws Exception {
TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), BROOKLYN_TEST_OSGI_ENTITIES_PATH);
TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), BROOKLYN_TEST_MORE_ENTITIES_V2_PATH);
// install dependencies
((ManagementContextInternal)mgmt()).getOsgiManager().get().install(
new ResourceUtils(getClass()).getResourceFromUrl(BROOKLYN_TEST_OSGI_ENTITIES_URL) ).checkNoError();
((ManagementContextInternal)mgmt()).getOsgiManager().get().install(
new ResourceUtils(getClass()).getResourceFromUrl(BROOKLYN_TEST_MORE_ENTITIES_V2_URL) ).get();
RegisteredType ci = Preconditions.checkNotNull( mgmt().getTypeRegistry().get(BROOKLYN_TEST_MORE_ENTITIES_MORE_ENTITY) );
EntitySpec<DynamicCluster> clusterSpec = EntitySpec.create(DynamicCluster.class)
.configure(DynamicCluster.INITIAL_SIZE, 1)
.configure(DynamicCluster.MEMBER_SPEC, origManagementContext.getTypeRegistry().createSpec(ci, null, EntitySpec.class));
final Entity app = mgmt().getEntityManager().createEntity(EntitySpec.create(BasicApplication.class).child(clusterSpec));
app.invoke(Startable.START, MutableMap.of()).get();
rebind();
}
内容来源于网络,如有侵权,请联系作者删除!