use of io.engineblock.activityapi.core.ActivityType 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.ActivityType in project engineblock by engineblock.
the class ScenarioController method getActivityExecutor.
private ActivityExecutor getActivityExecutor(ActivityDef activityDef, boolean createIfMissing) {
synchronized (activityExecutors) {
ActivityExecutor executor = activityExecutors.get(activityDef.getAlias());
if (executor == null && createIfMissing) {
String activityTypeName = activityDef.getParams().getOptionalString("type").orElse("diag");
ActivityType activityType = ActivityType.FINDER.getOrThrow(activityTypeName);
executor = new ActivityExecutor(activityType.getAssembledActivity(activityDef, getActivityMap()));
activityExecutors.put(activityDef.getAlias(), executor);
}
return executor;
}
}
Aggregations