Search in sources :

Example 1 with ParameterMap

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);
}
Also used : ActivityDef(io.engineblock.activityimpl.ActivityDef) ParameterMap(io.engineblock.activityimpl.ParameterMap)

Example 2 with ParameterMap

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);
        }
    }
}
Also used : ParameterMap(io.engineblock.activityimpl.ParameterMap)

Example 3 with ParameterMap

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);
}
Also used : ParameterMap(io.engineblock.activityimpl.ParameterMap)

Example 4 with ParameterMap

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));
}
Also used : ParameterMap(io.engineblock.activityimpl.ParameterMap) Test(org.testng.annotations.Test)

Example 5 with ParameterMap

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);
}
Also used : ActivityDef(io.engineblock.activityimpl.ActivityDef) ParameterMap(io.engineblock.activityimpl.ParameterMap)

Aggregations

ParameterMap (io.engineblock.activityimpl.ParameterMap)7 ActivityDef (io.engineblock.activityimpl.ActivityDef)3 InvalidParameterException (java.security.InvalidParameterException)1 Test (org.testng.annotations.Test)1