Search in sources :

Example 1 with Activity

use of io.engineblock.activityapi.core.Activity in project engineblock by engineblock.

the class MetricsMapper method metricsDetail.

public static String metricsDetail(String activitySpec) {
    // StringBuilder metricsDetail = new StringBuilder();
    List<String> metricsDetails = new ArrayList<String>();
    ActivityDef activityDef = ActivityDef.parseActivityDef(activitySpec);
    logger.info("introspecting metric names for " + activitySpec);
    Optional<ActivityType> activityType = ActivityType.FINDER.get(activityDef.getActivityType());
    if (!activityType.isPresent()) {
        throw new RuntimeException("Activity type '" + activityDef.getActivityType() + "' does not exist in this runtime.");
    }
    Activity activity = activityType.get().getAssembledActivity(activityDef, new HashMap<>());
    MetricRegistryBindings metricRegistryBindings = new MetricRegistryBindings(ActivityMetrics.getMetricRegistry());
    activity.initActivity();
    activity.getInputDispenserDelegate().getInput(0);
    activity.getActionDispenserDelegate().getAction(0);
    activity.getMotorDispenserDelegate().getMotor(activityDef, 0);
    Map<String, Metric> metricMap = metricRegistryBindings.getMetrics();
    for (Map.Entry<String, Metric> metricEntry : metricMap.entrySet()) {
        String metricName = metricEntry.getKey();
        Metric metricValue = metricEntry.getValue();
        Map<String, String> getterSummary = getGetterSummary(metricValue);
        // details.put(metricName,getterSummary);
        List<String> methodDetails = getterSummary.entrySet().stream().map(es -> metricName + es.getKey() + "  " + es.getValue()).collect(Collectors.toList());
        methodDetails.sort(String::compareTo);
        String getterText = methodDetails.stream().collect(Collectors.joining("\n"));
        metricsDetails.add(metricName + "\n" + getterText);
    }
    return metricsDetails.stream().collect(Collectors.joining("\n"));
}
Also used : ActivityType(io.engineblock.activityapi.core.ActivityType) java.util(java.util) Logger(org.slf4j.Logger) Predicate(java.util.function.Predicate) LoggerFactory(org.slf4j.LoggerFactory) ActivityDef(io.engineblock.activityimpl.ActivityDef) Timer(java.util.Timer) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ActivityMetrics(io.engineblock.metrics.ActivityMetrics) Activity(io.engineblock.activityapi.core.Activity) com.codahale.metrics(com.codahale.metrics) MetricRegistryBindings(io.engineblock.metrics.MetricRegistryBindings) Method(java.lang.reflect.Method) ActivityType(io.engineblock.activityapi.core.ActivityType) Activity(io.engineblock.activityapi.core.Activity) ActivityDef(io.engineblock.activityimpl.ActivityDef) MetricRegistryBindings(io.engineblock.metrics.MetricRegistryBindings)

Example 2 with Activity

use of io.engineblock.activityapi.core.Activity in project engineblock by engineblock.

the class CoreServices method getOutputDispenser.

public static <A extends Activity> Optional<OutputDispenser> getOutputDispenser(A activity) {
    OutputDispenser outputDispenser = new SimpleConfig(activity, "output").getString("type").flatMap(OutputType.FINDER::get).map(mt -> mt.getOutputDispenser(activity)).orElse(null);
    if (outputDispenser == null) {
        return Optional.empty();
    }
    Optional<Predicate<ResultReadable>> outputFilterDispenser = getOutputFilter(activity);
    if (outputFilterDispenser.isPresent()) {
        outputDispenser = new FilteringOutputDispenser(outputDispenser, outputFilterDispenser.get());
    }
    return Optional.ofNullable(outputDispenser);
}
Also used : SimpleConfig(io.engineblock.util.SimpleConfig) InputType(io.engineblock.activityapi.input.InputType) Activity(io.engineblock.activityapi.core.Activity) ResultValueFilterType(io.engineblock.activityapi.cyclelog.filters.ResultValueFilterType) OutputType(io.engineblock.activityapi.output.OutputType) Predicate(java.util.function.Predicate) OutputDispenser(io.engineblock.activityapi.output.OutputDispenser) SimpleConfig(io.engineblock.util.SimpleConfig) Optional(java.util.Optional) ResultReadable(io.engineblock.activityapi.cyclelog.buffers.results.ResultReadable) ResultFilterDispenser(io.engineblock.activityapi.cyclelog.filters.ResultFilterDispenser) InputDispenser(io.engineblock.activityapi.input.InputDispenser) OutputDispenser(io.engineblock.activityapi.output.OutputDispenser) Predicate(java.util.function.Predicate)

Example 3 with Activity

use of io.engineblock.activityapi.core.Activity in project engineblock by engineblock.

the class CoreMotorTest method testBasicActivityMotor.

@Test
public void testBasicActivityMotor() {
    BlockingSegmentInput lockstepper = new BlockingSegmentInput();
    Activity activity = new SimpleActivity(ActivityDef.parseActivityDef("alias=foo"));
    Motor cm = new CoreMotor(activity, 5L, lockstepper);
    AtomicLong observableAction = new AtomicLong(-3L);
    cm.setAction(getTestConsumer(observableAction));
    cm.getSlotStateTracker().enterState(RunState.Starting);
    Thread t = new Thread(cm);
    t.setName("TestMotor");
    t.start();
    try {
        // allow action time to be waiting in monitor for test fixture
        Thread.sleep(1000);
    } catch (InterruptedException ignored) {
    }
    lockstepper.publishSegment(5L);
    boolean result = awaitCondition(atomicInteger -> (atomicInteger.get() == 5L), observableAction, 5000, 100);
    assertThat(observableAction.get()).isEqualTo(5L);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) BlockingSegmentInput(io.engineblock.activitycore.fortesting.BlockingSegmentInput) CoreMotor(io.engineblock.activityimpl.motor.CoreMotor) Motor(io.engineblock.activityapi.core.Motor) SimpleActivity(io.engineblock.activityimpl.SimpleActivity) SimpleActivity(io.engineblock.activityimpl.SimpleActivity) Activity(io.engineblock.activityapi.core.Activity) CoreMotor(io.engineblock.activityimpl.motor.CoreMotor) Test(org.testng.annotations.Test)

Aggregations

Activity (io.engineblock.activityapi.core.Activity)3 Predicate (java.util.function.Predicate)2 com.codahale.metrics (com.codahale.metrics)1 ActivityType (io.engineblock.activityapi.core.ActivityType)1 Motor (io.engineblock.activityapi.core.Motor)1 ResultReadable (io.engineblock.activityapi.cyclelog.buffers.results.ResultReadable)1 ResultFilterDispenser (io.engineblock.activityapi.cyclelog.filters.ResultFilterDispenser)1 ResultValueFilterType (io.engineblock.activityapi.cyclelog.filters.ResultValueFilterType)1 InputDispenser (io.engineblock.activityapi.input.InputDispenser)1 InputType (io.engineblock.activityapi.input.InputType)1 OutputDispenser (io.engineblock.activityapi.output.OutputDispenser)1 OutputType (io.engineblock.activityapi.output.OutputType)1 BlockingSegmentInput (io.engineblock.activitycore.fortesting.BlockingSegmentInput)1 ActivityDef (io.engineblock.activityimpl.ActivityDef)1 SimpleActivity (io.engineblock.activityimpl.SimpleActivity)1 CoreMotor (io.engineblock.activityimpl.motor.CoreMotor)1 ActivityMetrics (io.engineblock.metrics.ActivityMetrics)1 MetricRegistryBindings (io.engineblock.metrics.MetricRegistryBindings)1 SimpleConfig (io.engineblock.util.SimpleConfig)1 Method (java.lang.reflect.Method)1