本文整理了Java中org.apache.brooklyn.core.entity.Entities.invokeEffector()
方法的一些代码示例,展示了Entities.invokeEffector()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Entities.invokeEffector()
方法的具体详情如下:
包路径:org.apache.brooklyn.core.entity.Entities
类名称:Entities
方法名:invokeEffector
[英]Invokes in parallel if multiple, but otherwise invokes the item directly.
[中]如果有多个,则并行调用,否则直接调用该项。
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
/** Invokes in parallel if multiple, but otherwise invokes the item directly. */
public static Task<?> invokeEffector(Entity callingEntity, Iterable<? extends Entity> entitiesToCall,
final Effector<?> effector) {
return invokeEffector(callingEntity, entitiesToCall, effector, Collections.<String,Object>emptyMap());
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
/** Invokes in parallel if multiple, but otherwise invokes the item directly. */
public static Task<?> invokeEffector(Entity callingEntity, Iterable<? extends Entity> entitiesToCall,
final Effector<?> effector, final Map<String,?> parameters) {
if (Iterables.size(entitiesToCall)==1)
return invokeEffector(callingEntity, entitiesToCall.iterator().next(), effector, parameters);
else
return invokeEffectorList(callingEntity, entitiesToCall, effector, parameters);
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
public static <T> Task<T> invokeEffector(Entity callingEntity, Entity entityToCall,
final Effector<T> effector) {
return invokeEffector(callingEntity, entityToCall, effector, Collections.<String,Object>emptyMap());
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@SuppressWarnings("unchecked")
public static <T> Task<T> invokeEffectorWithArgs(Entity callingEntity, Entity entityToCall,
final Effector<T> effector, Object ...args) {
return invokeEffector(callingEntity, entityToCall, effector,
EffectorUtils.prepareArgsForEffectorAsMapFromArray(effector, args));
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-rest-resources
public Task<?> start(Application app, List<? extends Location> locations) {
return Entities.invokeEffector(app, app, Startable.START,
MutableMap.of("locations", locations));
}
代码示例来源:origin: io.brooklyn.clocker/brooklyn-clocker-docker
public static final void stop(Entity caller, Entity target, Duration timeout) {
if (target != null && Entities.isManaged(target)) {
boolean stopped = Entities.invokeEffector(caller, target, Startable.STOP)
.blockUntilEnded(timeout);
if (!stopped) {
LOG.debug("{} may not have stopped. Proceeding to stop {} anyway", target, caller);
}
}
}
代码示例来源:origin: io.brooklyn.clocker/brooklyn-clocker-docker
@Override
public void stop() {
Entities.invokeEffector(getEntity(), getOwnerEntity(), Startable.STOP);
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
public static <T extends Application> CreationResult<T,Void> start(T app) {
Task<Void> task = Entities.invokeEffector(app, app, Startable.START,
// locations already set in the entities themselves;
// TODO make it so that this arg does not have to be supplied to START !
MutableMap.of("locations", MutableList.of()));
return CreationResult.of(app, task);
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-software-base
@Test(groups="Integration")
public void testSshDateEffector1() {
Task<String> call = Entities.invokeEffector(app, app, GET_REMOTE_DATE_1);
log.info("ssh date 1 gives: "+call.getUnchecked());
Assert.assertTrue(call.getUnchecked().indexOf("201") > 0);
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
/** convenience for starting an entity, esp a new Startable instance which has been created dynamically
* (after the application is started) */
public static void start(Entity e, Collection<? extends Location> locations) {
if (!isManaged(e) && !manage(e)) {
log.warn("Using deprecated discouraged mechanism to start management -- Entities.start(Application, Locations) -- caller should create and use the preferred management context");
startManagement(e);
}
if (e instanceof Startable) Entities.invokeEffector(e, e, Startable.START,
MutableMap.of("locations", locations)).getUnchecked();
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-software-base
@Test(groups="Integration")
public void testSshDateEffector2() {
Task<String> call = Entities.invokeEffector(app, app, GET_REMOTE_DATE_2);
log.info("ssh date 2 gives: "+call.getUnchecked());
Assert.assertTrue(call.getUnchecked().indexOf("201") == 0);
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-software-database
@Override
public String executeScript(String commands) {
return Entities.invokeEffector(this, this, EXECUTE_SCRIPT,
ConfigBag.newInstance().configure(ExecuteScriptEffectorBody.SCRIPT, commands).getAllConfig()).getUnchecked();
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@Override
public void resetPasswordOnChildren(String newPassword, Integer secretPin) throws Exception {
for (TestEntityWithEffectors child : Iterables.filter(getChildren(), TestEntityWithEffectors.class)) {
Entities.invokeEffector(this, child, RESET_PASSWORD, ImmutableMap.of("newPassword", newPassword, "secretPin", secretPin)).get();
child.resetPassword(newPassword, secretPin);
}
}
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@Override
public void run() {
Task<?> task = Entities.invokeEffector(app, entities, TestEntity.MY_EFFECTOR);
try {
task.get();
} catch (Exception e) {
throw Exceptions.propagate(e);
}
}}));
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@Override
public void removeRegion(String id) {
Entity entity = getManagementContext().getEntityManager().getEntity(id);
Preconditions.checkNotNull(entity, "No entity found for %s", id);
Preconditions.checkArgument(this.equals(entity.getParent()), "Wrong parent (%s) for %s", entity.getParent(), entity);
Collection<Location> childLocations = entity.getLocations();
if (entity instanceof Startable) {
try {
Entities.invokeEffector(this, entity, Startable.STOP).get();
} catch (Exception e) {
Exceptions.propagateIfFatal(e);
log.warn("Error stopping "+entity+" ("+e+"); proceeding to remove it anyway");
log.debug("Error stopping "+entity+" ("+e+"); proceeding to remove it anyway", e);
}
}
removeChild(entity);
removeLocations(childLocations);
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-software-base
@Test(groups="Integration")
public void testBadExitCodeCaughtAndStdErrAvailable() {
final ProcessTaskWrapper<?>[] sshTasks = new ProcessTaskWrapper[1];
Task<Void> call = Entities.invokeEffector(app, app, Effectors.effector(Void.class, "badExitCode")
.impl(new SshEffectorBody<Void>() {
@Override
public Void call(ConfigBag parameters) {
sshTasks[0] = queue( ssh(COMMAND_THAT_DOES_NOT_EXIST).requiringExitCodeZero() );
return null;
}
}).build() );
call.blockUntilEnded();
Assert.assertTrue(call.isError());
log.info("stderr gives: "+new String(sshTasks[0].getStderr()));
Assert.assertTrue(new String(sshTasks[0].getStderr()).indexOf(COMMAND_THAT_DOES_NOT_EXIST) >= 0);
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-software-messaging
@Override
public void start(Collection<? extends Location> locations) {
if (isLegacyConstruction()) {
// TODO should no longer be needed?
init();
}
locations = MutableList.copyOf(Locations.getLocationsCheckingAncestors(locations, this));
Iterables.getOnlyElement(locations); // Assert just one
// set it; here we don't allow changing locations
addLocations(locations);
List<Entity> childrenToStart = MutableList.<Entity>of(getCluster());
// Set the KafkaZookeeper entity as child of cluster, if it does not already have a parent
if (getZooKeeper().getParent() == null) {
addChild(getZooKeeper());
} // And only start zookeeper if we are parent
if (Objects.equal(this, getZooKeeper().getParent())) childrenToStart.add(getZooKeeper());
Entities.invokeEffector(this, childrenToStart, Startable.START, ImmutableMap.of("locations", locations)).getUnchecked();
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@Override
public void stop() {
ServiceStateLogic.setExpectedState(this, Lifecycle.STOPPING);
try {
Iterable<Entity> stoppableChildren = Iterables.filter(getChildren(), Predicates.instanceOf(Startable.class));
Task<?> invoke = Entities.invokeEffector(this, stoppableChildren, Startable.STOP);
if (invoke != null) invoke.get();
ServiceStateLogic.setExpectedState(this, Lifecycle.STOPPED);
sensors().set(SERVICE_UP, false);
} catch (Exception e) {
ServiceStateLogic.setExpectedState(this, Lifecycle.ON_FIRE);
throw Exceptions.propagate(e);
}
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@Test
public void testInvokeEffectorDirectlyIncludesException() throws Exception {
try {
entity.myEffector();
} catch (Exception e) {
assertExceptionContainsIsEntitledStack(e);
}
try {
Entities.invokeEffector(app, entity, TestEntity.MY_EFFECTOR).get();
} catch (Exception e) {
assertExceptionContainsIsEntitledStack(e);
}
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-software-base
@Override
public StubContainerLocation obtain(Map<?, ?> flags) throws NoMachinesAvailableException {
Entity callerContext = (Entity) flags.get(LocationConfigKeys.CALLER_CONTEXT.getName());
if (callerContext == null) callerContext = getOwner();
DynamicCluster cluster = dockerHost.getDockerContainerCluster();
Entity added = cluster.addNode(machine, flags);
if (added == null) {
throw new NoMachinesAvailableException(String.format("Failed to create container at %s", dockerHost));
} else {
Entities.invokeEffector(callerContext, added, Startable.START, MutableMap.of("locations", ImmutableList.of(machine))).getUnchecked();
}
StubContainer container = (StubContainer) added;
return container.getDynamicLocation();
}
内容来源于网络,如有侵权,请联系作者删除!