Skip to content

Commit

Permalink
Use deep resolving task for policy effector args
Browse files Browse the repository at this point in the history
  • Loading branch information
grkvlt committed Apr 11, 2017
1 parent 098e03e commit 9413b4b
Showing 1 changed file with 7 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@
import java.util.Calendar;
import java.util.Date;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

import org.apache.brooklyn.api.effector.Effector;
import org.apache.brooklyn.api.entity.EntityLocal;
import org.apache.brooklyn.api.mgmt.Task;
import org.apache.brooklyn.config.ConfigKey;
import org.apache.brooklyn.core.config.ConfigKeys;
import org.apache.brooklyn.core.entity.EntityInitializers;
Expand All @@ -50,7 +48,6 @@
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.google.common.reflect.TypeToken;

@Beta
Expand Down Expand Up @@ -146,22 +143,14 @@ protected Duration getWaitUntil(String time) {
public void run() {
synchronized (mutex) {
try {
final ConfigBag bag = ResolvingConfigBag.newInstanceExtending(getManagementContext(), config().getBag());
final Map<String, Object> args = EntityInitializers.resolve(bag, EFFECTOR_ARGUMENTS);
ConfigBag bag = ResolvingConfigBag.newInstanceExtending(getManagementContext(), config().getBag());
Map<String, Object> args = EntityInitializers.resolve(bag, EFFECTOR_ARGUMENTS);
LOG.debug("{}: Resolving arguments for {}: {}", new Object[] { this, effector.getName(), Iterables.toString(args.keySet()) });
bag.putAll(args);
Task<Map<String, Object>> resolve = Tasks.create("resolveArguments", new Callable<Map<String, Object>>() {
@Override
public Map<String, Object> call() {
Map<String, Object> resolved = Maps.newLinkedHashMap();
for (String key : args.keySet()) {
resolved.put(key, bag.getStringKey(key));
}
return resolved;
}
});
getManagementContext().getExecutionContext(entity).submit(resolve);
Map<String, Object> resolved = resolve.getUnchecked();
Map<String, Object> resolved = (Map) Tasks.resolving(args, Object.class)
.deep(true)
.context(entity)
.get();

LOG.debug("{}: Invoking effector on {}, {}({})", new Object[] { this, entity, effector.getName(), resolved });
Object result = entity.invoke(effector, resolved).getUnchecked();
LOG.debug("{}: Effector {} returned {}", new Object[] { this, effector.getName(), result });
Expand Down

0 comments on commit 9413b4b

Please sign in to comment.