use of io.engineblock.activityimpl.ParameterMap in project engineblock by engineblock.
the class ScenarioController method stop.
/**
* <p>Stop an activity, given an activity def map. The only part of the map that is important is the
* alias parameter. This method retains the map signature to provide convenience for scripting.</p>
*
* @param activityDefMap A map, containing at least the alias parameter
*/
public synchronized void stop(Map<String, String> activityDefMap) {
ActivityDef ad = new ActivityDef(new ParameterMap(activityDefMap));
stop(ad);
}
use of io.engineblock.activityimpl.ParameterMap in project engineblock by engineblock.
the class ScenarioController method apply.
/**
* Apply any parameter changes to a defined activity, or start a new one.
* This method is syntactical sugar for scripting. Each of the parameters in the map
* is checked against existing values, and per-field modifications
* are applied one at a time, only if the values have changed.
*
* @param appliedParams Map of new values.
*/
public synchronized void apply(Map<String, String> appliedParams) {
String alias = appliedParams.get("alias");
if (alias == null) {
throw new RuntimeException("alias must be provided");
}
ActivityExecutor executor = activityExecutors.get(alias);
if (executor == null) {
logger.info("started scenario from apply:" + alias);
start(appliedParams);
return;
}
ParameterMap previousMap = executor.getActivityDef().getParams();
for (String paramName : appliedParams.keySet()) {
String appliedVal = appliedParams.get(paramName);
Optional<String> prevVal = previousMap.getOptionalString(paramName);
if (!prevVal.isPresent() || !prevVal.get().equals(appliedVal)) {
logger.info("applying new value to activity '" + alias + "': '" + prevVal.get() + "' -> '" + appliedVal + "'");
previousMap.set(paramName, appliedVal);
}
}
}
use of io.engineblock.activityimpl.ParameterMap in project engineblock by engineblock.
the class StdoutActivity method onActivityDefUpdate.
@Override
public void onActivityDefUpdate(ActivityDef activityDef) {
super.onActivityDefUpdate(activityDef);
ParameterMap params = activityDef.getParams();
this.retry_delay = params.getOptionalInteger("retry_delay").orElse(1000);
this.retries = params.getOptionalInteger("retries").orElse(3);
}
use of io.engineblock.activityimpl.ParameterMap in project engineblock by engineblock.
the class ParameterMapTest method testGetOptional.
@Test
public void testGetOptional() {
ParameterMap abc = ParameterMap.parseOrException("a=1;b=2;c=3;");
Optional<Long> d = abc.getOptionalLong("d");
assertThat(d).isEmpty();
Optional<String> a = abc.getOptionalString("a");
assertThat(a).isEqualTo(Optional.of("1"));
Optional<Long> aLong = abc.getOptionalLong("a");
assertThat(aLong).isEqualTo(Optional.of(1L));
}
use of io.engineblock.activityimpl.ParameterMap in project engineblock by engineblock.
the class ScenarioController method start.
/**
* Start an activity, given a map which holds the activity definition for it. The activity will be known in
* the scenario by the alias parameter.
*
* @param activityDefMap A map containing the activity definition
*/
public synchronized void start(Map<String, String> activityDefMap) {
ActivityDef ad = new ActivityDef(new ParameterMap(activityDefMap));
start(ad);
}
Aggregations