Search in sources :

Example 1 with Activity

use of io.nosqlbench.engine.api.activityapi.core.Activity in project nosqlbench by nosqlbench.

the class MetricsMapper method metricsDetail.

public static String metricsDetail(String activitySpec) {
    // StringBuilder metricsDetail = new StringBuilder();
    List<String> metricsDetails = new ArrayList<>();
    ActivityDef activityDef = ActivityDef.parseActivityDef(activitySpec);
    logger.info("introspecting metric names for " + activitySpec);
    Optional<ActivityType> activityType = new ActivityTypeLoader().load(activityDef);
    if (!activityType.isPresent()) {
        throw new RuntimeException("Activity type '" + activityDef.getActivityType() + "' does not exist in this runtime.");
    }
    Activity activity = activityType.get().getAssembledActivity(activityDef, new HashMap<>());
    PolyglotMetricRegistryBindings nashornMetricRegistryBindings = new PolyglotMetricRegistryBindings(ActivityMetrics.getMetricRegistry());
    activity.initActivity();
    activity.getInputDispenserDelegate().getInput(0);
    activity.getActionDispenserDelegate().getAction(0);
    activity.getMotorDispenserDelegate().getMotor(activityDef, 0);
    Map<String, Metric> metricMap = nashornMetricRegistryBindings.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 : java.util(java.util) ActivityDef(io.nosqlbench.engine.api.activityimpl.ActivityDef) Predicate(java.util.function.Predicate) Timer(java.util.Timer) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ActivityMetrics(io.nosqlbench.engine.api.metrics.ActivityMetrics) ActivityTypeLoader(io.nosqlbench.engine.core.lifecycle.ActivityTypeLoader) Logger(org.apache.logging.log4j.Logger) com.codahale.metrics(com.codahale.metrics) Activity(io.nosqlbench.engine.api.activityapi.core.Activity) PolyglotMetricRegistryBindings(io.nosqlbench.engine.core.metrics.PolyglotMetricRegistryBindings) LogManager(org.apache.logging.log4j.LogManager) Method(java.lang.reflect.Method) ActivityType(io.nosqlbench.engine.api.activityapi.core.ActivityType) ActivityType(io.nosqlbench.engine.api.activityapi.core.ActivityType) Activity(io.nosqlbench.engine.api.activityapi.core.Activity) ActivityDef(io.nosqlbench.engine.api.activityimpl.ActivityDef) PolyglotMetricRegistryBindings(io.nosqlbench.engine.core.metrics.PolyglotMetricRegistryBindings) ActivityTypeLoader(io.nosqlbench.engine.core.lifecycle.ActivityTypeLoader)

Example 2 with Activity

use of io.nosqlbench.engine.api.activityapi.core.Activity in project nosqlbench by nosqlbench.

the class ScenarioController method stop.

/**
 * Stop an activity, given the name by which it is known already in the scenario. This causes the
 * activity to stop all threads, but keeps the thread objects handy for starting again. This can be useful
 * for certain testing scenarios in which you want to stop some workloads and start others based on other conditions.
 *
 * Alternately, you can provide one or more aliases in the same command, and all matching names will be stopped.
 *
 * @param spec The name of the activity that is already known to the scenario
 */
public synchronized void stop(String spec) {
    logger.debug("request->STOP '" + spec + "'");
    List<String> aliases = Arrays.asList(spec.split("[,; ]"));
    List<String> matched = aliases.stream().map(String::trim).filter(s -> !s.isEmpty()).flatMap(aspec -> getMatchingAliases(aspec).stream()).collect(Collectors.toList());
    for (String alias : matched) {
        ActivityDef adef = aliasToDef(alias);
        scenariologger.debug("STOP " + adef.getAlias());
        stop(adef);
    }
}
Also used : java.util(java.util) ActivityDef(io.nosqlbench.engine.api.activityimpl.ActivityDef) Maturity(io.nosqlbench.nb.annotations.Maturity) RunState(io.nosqlbench.engine.api.activityapi.core.RunState) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Annotation(io.nosqlbench.nb.api.annotations.Annotation) Collectors(java.util.stream.Collectors) ActivityMetrics(io.nosqlbench.engine.api.metrics.ActivityMetrics) BasicError(io.nosqlbench.nb.api.errors.BasicError) Logger(org.apache.logging.log4j.Logger) InvalidParameterException(java.security.InvalidParameterException) ProgressAndStateMeter(io.nosqlbench.engine.api.activityimpl.ProgressAndStateMeter) ParameterMap(io.nosqlbench.engine.api.activityimpl.ParameterMap) Annotators(io.nosqlbench.engine.core.annotation.Annotators) Pattern(java.util.regex.Pattern) Activity(io.nosqlbench.engine.api.activityapi.core.Activity) LogManager(org.apache.logging.log4j.LogManager) ActivityType(io.nosqlbench.engine.api.activityapi.core.ActivityType) Layer(io.nosqlbench.nb.api.annotations.Layer) ActivityDef(io.nosqlbench.engine.api.activityimpl.ActivityDef)

Example 3 with Activity

use of io.nosqlbench.engine.api.activityapi.core.Activity in project nosqlbench by nosqlbench.

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.nosqlbench.engine.api.util.SimpleConfig) OutputType(io.nosqlbench.engine.api.activityapi.output.OutputType) InputDispenser(io.nosqlbench.engine.api.activityapi.input.InputDispenser) OutputDispenser(io.nosqlbench.engine.api.activityapi.output.OutputDispenser) Predicate(java.util.function.Predicate) Optional(java.util.Optional) ResultValueFilterType(io.nosqlbench.engine.api.activityapi.cyclelog.filters.ResultValueFilterType) InputType(io.nosqlbench.engine.api.activityapi.input.InputType) Activity(io.nosqlbench.engine.api.activityapi.core.Activity) ResultFilterDispenser(io.nosqlbench.engine.api.activityapi.cyclelog.filters.ResultFilterDispenser) SimpleConfig(io.nosqlbench.engine.api.util.SimpleConfig) ResultReadable(io.nosqlbench.engine.api.activityapi.cyclelog.buffers.results.ResultReadable) OutputDispenser(io.nosqlbench.engine.api.activityapi.output.OutputDispenser) Predicate(java.util.function.Predicate)

Aggregations

Activity (io.nosqlbench.engine.api.activityapi.core.Activity)3 ActivityType (io.nosqlbench.engine.api.activityapi.core.ActivityType)2 ActivityDef (io.nosqlbench.engine.api.activityimpl.ActivityDef)2 ActivityMetrics (io.nosqlbench.engine.api.metrics.ActivityMetrics)2 java.util (java.util)2 Predicate (java.util.function.Predicate)2 Collectors (java.util.stream.Collectors)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 com.codahale.metrics (com.codahale.metrics)1 RunState (io.nosqlbench.engine.api.activityapi.core.RunState)1 ResultReadable (io.nosqlbench.engine.api.activityapi.cyclelog.buffers.results.ResultReadable)1 ResultFilterDispenser (io.nosqlbench.engine.api.activityapi.cyclelog.filters.ResultFilterDispenser)1 ResultValueFilterType (io.nosqlbench.engine.api.activityapi.cyclelog.filters.ResultValueFilterType)1 InputDispenser (io.nosqlbench.engine.api.activityapi.input.InputDispenser)1 InputType (io.nosqlbench.engine.api.activityapi.input.InputType)1 OutputDispenser (io.nosqlbench.engine.api.activityapi.output.OutputDispenser)1 OutputType (io.nosqlbench.engine.api.activityapi.output.OutputType)1 ParameterMap (io.nosqlbench.engine.api.activityimpl.ParameterMap)1 ProgressAndStateMeter (io.nosqlbench.engine.api.activityimpl.ProgressAndStateMeter)1