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"));
}
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);
}
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);
}
Aggregations