/** * Adds an effector with an explicit body to this entity. */ @Beta public <T> void addEffector(Effector<T> effector, EffectorTaskFactory<T> body) { addEffector(new EffectorAndBody<T>(effector, body)); }
/** * Adds an effector with an explicit body to this entity. */ @Beta public <T> void addEffector(Effector<T> effector, EffectorBody<T> body) { addEffector(effector, new EffectorBodyTaskFactory<T>(body)); }
@Override public void apply(EntityLocal entity) { ((EntityInternal)entity).getMutableEntityType().addEffector(effector); }
@Override public void init() { super.init(); getMutableEntityType().addEffector(DeployBlueprintEffectorBody.DEPLOY_BLUEPRINT); getMutableEntityType().addEffector(ShutdownEffectorBody.SHUTDOWN); getMutableEntityType().addEffector(StopNodeButLeaveAppsEffectorBody.STOP_NODE_BUT_LEAVE_APPS); getMutableEntityType().addEffector(StopNodeAndKillAppsEffectorBody.STOP_NODE_AND_KILL_APPS); getMutableEntityType().addEffector(SetHighAvailabilityPriorityEffectorBody.SET_HIGH_AVAILABILITY_PRIORITY); getMutableEntityType().addEffector(SetHighAvailabilityModeEffectorBody.SET_HIGH_AVAILABILITY_MODE); getMutableEntityType().addEffector(BrooklynNodeUpgradeEffectorBody.UPGRADE); }
@Override public void init() { super.init(); getMutableEntityType().addEffector(EXECUTE_SCRIPT, new EffectorBody<String>() { @Override public String call(ConfigBag parameters) { return executeScript((String)parameters.getStringKey("commands")); } }); getMutableEntityType().addEffector(MySqlNodeEffectors.EXPORT_DUMP); getMutableEntityType().addEffector(MySqlNodeEffectors.IMPORT_DUMP); getMutableEntityType().addEffector(MySqlNodeEffectors.CHANGE_PASSWORD); }
@Override public void init() { super.init(); getMutableEntityType().addEffector(EXECUTE_SCRIPT, new EffectorBody<String>() { @Override public String call(ConfigBag parameters) { return executeScript((String) parameters.getStringKey("commands")); } }); }
/** Attaches lifecycle effectors (start, restart, stop) to the given entity post-creation. */ public void attachLifecycleEffectors(Entity entity) { ((EntityInternal) entity).getMutableEntityType().addEffector(newStartEffector()); ((EntityInternal) entity).getMutableEntityType().addEffector(newRestartEffector()); ((EntityInternal) entity).getMutableEntityType().addEffector(newStopEffector()); }
@Override public void init() { super.init(); getMutableEntityType().addEffector(EXECUTE_SCRIPT, new EffectorBody<String>() { @Override public String call(ConfigBag parameters) { return executeScript((String)parameters.getStringKey("commands")); } }); }
private void populateEffectors() { HttpToolResponse result = http().get("/effectors"); Collection<?> cfgEffectors = new Gson().fromJson(result.getContentAsString(), Collection.class); Collection<Effector<String>> remoteEntityEffectors = RemoteEffectorBuilder.of(cfgEffectors); EntityDynamicType mutableEntityType = getMutableEntityType(); for (Effector<String> eff : remoteEntityEffectors) { //remote already started if ("start".equals(eff.getName())) continue; mutableEntityType.addEffector(eff); } }
@Override public void apply(EntityLocal entity) { ((EntityInternal) entity).getMutableEntityType().addEffector(EffectorTaskTest.DOUBLE_1); } }));
@Override public void apply(EntityLocal entity) { ((EntityInternal)entity).getMutableEntityType().addEffector(EffectorTaskTest.DOUBLE_1); }});
@Override public void init() { super.init(); getLifecycleEffectorTasks().attachLifecycleEffectors(this); if (Boolean.TRUE.equals(getConfig(ADD_OPEN_INBOUND_PORTS_EFFECTOR))) { getMutableEntityType().addEffector(NetworkingEffectors.OPEN_INBOUND_PORTS_IN_SECURITY_GROUP_EFFECTOR); } }
@Test public void testRestoresEffectorStaticClass() throws Exception { origApp.getMutableEntityType().addEffector(SayHiBody.EFFECTOR); checkEffectorWithRebind(); }
@Override public void init() { super.init(); getMutableEntityType().addEffector(DeployBlueprintEffectorBody.DEPLOY_BLUEPRINT); }
@Override public void init() { super.init(); getMutableEntityType().addEffector(SetHighAvailabilityPriorityEffectorBody.SET_HIGH_AVAILABILITY_PRIORITY); getMutableEntityType().addEffector(SetHighAvailabilityModeEffectorBody.SET_HIGH_AVAILABILITY_MODE); sensors().set(HA_PRIORITY, 0); }
@Test public void testEffectorBodyAddedImplicitlyButBodylessSignatureInvoked() throws Exception { EntityInternal doubler = app.createAndManageChild(EntitySpec.create(TestEntity.class)); // add it doubler.getMutableEntityType().addEffector(DOUBLE_1); // invoke it, but using something with equivalent name (and signature -- though only name is used currently) // ensures that the call picks up the body by looking in the actual entity Assert.assertEquals(doubler.invoke(DOUBLE_BODYLESS, MutableMap.of("numberToDouble", 3)).get(), (Integer)6); }
private void execRelease(final JcloudsLocation loc, final JcloudsSshMachineLocation machine) throws Exception { EffectorBody<Void> effectorBody = new EffectorBody<Void>() { @Override public Void call(ConfigBag parameters) { loc.releasePortForwarding(machine); return null; } }; Effector<Void> effector = new EffectorAndBody<Void>("myeffector", Void.class, ImmutableList.<ParameterType<?>>of(), "", new EffectorBodyTaskFactory<Void>(effectorBody)); EntityInternal entity = (EntityInternal) app.createAndManageChild(EntitySpec.create(BasicEntity.class)); entity.getMutableEntityType().addEffector(effector); entity.invoke(effector, ImmutableMap.<String, Object>of()).get(); } }
@Override public void apply(EntityLocal entity) { Maybe<Effector<?>> effectorMaybe = entity.getEntityType().getEffectorByName(effector.getName()); if (!effectorMaybe.isAbsentOrNull()) { Effector<?> original = Effectors.effector(effectorMaybe.get()).name(ORIGINAL_PREFIX + effector.getName()).build(); ((EntityInternal) entity).getMutableEntityType().addEffector(original); } super.apply(entity); }
@Test(enabled=false) public void testRestoresEffectorAnonymousClass() throws Exception { origApp.getMutableEntityType().addEffector(Effectors.effector(String.class, "say_hi") .parameter(SayHiBody.NAME_KEY) .description("says hello") .impl(new EffectorBody<String>() { @Override public String call(ConfigBag parameters) { return "hello "+parameters.get(SayHiBody.NAME_KEY); } }).build()); checkEffectorWithRebind(); }
@Override public void init() { super.init(); getMutableEntityType().addEffector(new EffectorAndBody<Void>(SoftwareProcess.RESTART, new MethodEffector<Void>(SubSoftwareProcess.class, "customRestart").getBody())); }