Search in sources :

Example 1 with ActivityDef

use of io.engineblock.activityimpl.ActivityDef 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 ActivityDef

use of io.engineblock.activityimpl.ActivityDef in project engineblock by engineblock.

the class ActivityExecutorTest method testNewActivityExecutor.

@Test(enabled = true)
public void testNewActivityExecutor() {
    ActivityDef ad = ActivityDef.parseActivityDef("type=diag;alias=test;cycles=1000;");
    Optional<ActivityType> activityType = ActivityType.FINDER.get(ad.getActivityType());
    Input longSupplier = new TargetRateInput(ad);
    MotorDispenser cmf = getActivityMotorFactory(ad, motorActionDelay(999), longSupplier);
    Activity a = new SimpleActivity(ad);
    InputDispenser idisp = new CoreInputDispenser(a);
    ActionDispenser adisp = new CoreActionDispenser(a);
    OutputDispenser tdisp = CoreServices.getOutputDispenser(a).orElse(null);
    MotorDispenser mdisp = new CoreMotorDispenser(a, idisp, adisp, tdisp);
    a.setActionDispenserDelegate(adisp);
    a.setInputDispenserDelegate(idisp);
    a.setMotorDispenserDelegate(mdisp);
    ActivityExecutor ae = new ActivityExecutor(a);
    ad.setThreads(5);
    ae.startActivity();
    int[] speeds = new int[] { 1, 2000, 5, 2000, 2, 2000 };
    for (int offset = 0; offset < speeds.length; offset += 2) {
        int threadTarget = speeds[offset];
        int threadTime = speeds[offset + 1];
        logger.info("Setting thread level to " + threadTarget + " for " + threadTime + " seconds.");
        ad.setThreads(threadTarget);
        try {
            Thread.sleep(threadTime);
        } catch (InterruptedException ignored) {
        }
    }
    ad.setThreads(0);
}
Also used : TargetRateInput(io.engineblock.activityimpl.input.TargetRateInput) SimpleActivity(io.engineblock.activityimpl.SimpleActivity) CoreInputDispenser(io.engineblock.activityimpl.input.CoreInputDispenser) ActivityDef(io.engineblock.activityimpl.ActivityDef) CoreMotorDispenser(io.engineblock.activityimpl.motor.CoreMotorDispenser) CoreInputDispenser(io.engineblock.activityimpl.input.CoreInputDispenser) InputDispenser(io.engineblock.activityapi.input.InputDispenser) CoreActionDispenser(io.engineblock.activityimpl.action.CoreActionDispenser) TargetRateInput(io.engineblock.activityimpl.input.TargetRateInput) Input(io.engineblock.activityapi.input.Input) SimpleActivity(io.engineblock.activityimpl.SimpleActivity) CoreMotorDispenser(io.engineblock.activityimpl.motor.CoreMotorDispenser) CoreActionDispenser(io.engineblock.activityimpl.action.CoreActionDispenser) OutputDispenser(io.engineblock.activityapi.output.OutputDispenser) Test(org.testng.annotations.Test)

Example 3 with ActivityDef

use of io.engineblock.activityimpl.ActivityDef in project engineblock by engineblock.

the class ActivityExecutorTest method testDelayedStartSanity.

@Test
public void testDelayedStartSanity() {
    ActivityDef ad = ActivityDef.parseActivityDef("type=diag;alias=test;cycles=1000;initdelay=5000;");
    Optional<ActivityType> activityType = ActivityType.FINDER.get(ad.getActivityType());
    Activity a = new DelayedInitActivity(ad);
    InputDispenser idisp = new CoreInputDispenser(a);
    ActionDispenser adisp = new CoreActionDispenser(a);
    OutputDispenser tdisp = CoreServices.getOutputDispenser(a).orElse(null);
    MotorDispenser mdisp = new CoreMotorDispenser(a, idisp, adisp, tdisp);
    a.setActionDispenserDelegate(adisp);
    a.setOutputDispenserDelegate(tdisp);
    a.setInputDispenserDelegate(idisp);
    a.setMotorDispenserDelegate(mdisp);
    ActivityExecutor ae = new ActivityExecutor(a);
    ad.setThreads(1);
    ae.startActivity();
    ae.awaitCompletion(15000);
    assertThat(idisp.getInput(10).getInputSegment(3)).isNull();
}
Also used : SimpleActivity(io.engineblock.activityimpl.SimpleActivity) CoreInputDispenser(io.engineblock.activityimpl.input.CoreInputDispenser) ActivityDef(io.engineblock.activityimpl.ActivityDef) CoreMotorDispenser(io.engineblock.activityimpl.motor.CoreMotorDispenser) CoreInputDispenser(io.engineblock.activityimpl.input.CoreInputDispenser) InputDispenser(io.engineblock.activityapi.input.InputDispenser) CoreActionDispenser(io.engineblock.activityimpl.action.CoreActionDispenser) CoreActionDispenser(io.engineblock.activityimpl.action.CoreActionDispenser) CoreMotorDispenser(io.engineblock.activityimpl.motor.CoreMotorDispenser) OutputDispenser(io.engineblock.activityapi.output.OutputDispenser) Test(org.testng.annotations.Test)

Example 4 with ActivityDef

use of io.engineblock.activityimpl.ActivityDef 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 5 with ActivityDef

use of io.engineblock.activityimpl.ActivityDef in project engineblock by engineblock.

the class DiagActivityTypeTest method testDiagActivity.

@Test
public void testDiagActivity() {
    DiagActivityType da = new DiagActivityType();
    da.getName();
    ActivityDef ad = ActivityDef.parseActivityDef("type=diag;");
    DiagActivity a = da.getActivity(ad);
    a.initActivity();
    ActionDispenser actionDispenser = da.getActionDispenser(a);
    Action action = actionDispenser.getAction(1);
    action.runCycle(1L);
}
Also used : Action(io.engineblock.activityapi.core.Action) ActionDispenser(io.engineblock.activityapi.core.ActionDispenser) ActivityDef(io.engineblock.activityimpl.ActivityDef) Test(org.testng.annotations.Test)

Aggregations

ActivityDef (io.engineblock.activityimpl.ActivityDef)15 Test (org.testng.annotations.Test)5 ParameterMap (io.engineblock.activityimpl.ParameterMap)3 SimpleActivity (io.engineblock.activityimpl.SimpleActivity)3 CoreMotorDispenser (io.engineblock.activityimpl.motor.CoreMotorDispenser)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 Histogram (com.codahale.metrics.Histogram)2 Action (io.engineblock.activityapi.core.Action)2 ActionDispenser (io.engineblock.activityapi.core.ActionDispenser)2 InputDispenser (io.engineblock.activityapi.input.InputDispenser)2 OutputDispenser (io.engineblock.activityapi.output.OutputDispenser)2 CoreActionDispenser (io.engineblock.activityimpl.action.CoreActionDispenser)2 CoreInputDispenser (io.engineblock.activityimpl.input.CoreInputDispenser)2 com.codahale.metrics (com.codahale.metrics)1 Counter (com.codahale.metrics.Counter)1 Meter (com.codahale.metrics.Meter)1 Activity (io.engineblock.activityapi.core.Activity)1 ActivityType (io.engineblock.activityapi.core.ActivityType)1 Input (io.engineblock.activityapi.input.Input)1 TargetRateInput (io.engineblock.activityimpl.input.TargetRateInput)1