Search in sources :

Example 1 with OpSequence

use of io.nosqlbench.engine.api.activityapi.planning.OpSequence in project nosqlbench by nosqlbench.

the class StdoutActivity method initOpSequencer.

private OpSequence<StringBindings> initOpSequencer() {
    // List<StringBindingsTemplate> stringBindingsTemplates = new ArrayList<>();
    SequencerType sequencerType = SequencerType.valueOf(getParams().getOptionalString("seq").orElse("bucket"));
    SequencePlanner<StringBindings> sequencer = new SequencePlanner<>(sequencerType);
    String tagfilter = activityDef.getParams().getOptionalString("tags").orElse("");
    List<OpTemplate> stmts = stmtsDocList.getStmts(tagfilter);
    String format = getParams().getOptionalString("format").orElse(null);
    if ((stmts.size() == 0 && stmtsDocList.getDocBindings().size() > 0) || format != null) {
        if (format != null && format.startsWith("diag")) {
            logger.info("Creating diagnostic log for resolver construction...");
            BindingsTemplate bt = new BindingsTemplate();
            stmtsDocList.getDocBindings().forEach(bt::addFieldBinding);
            String diagnostics = bt.getDiagnostics();
            getConsoleOut().println(diagnostics);
            getConsoleOut().flush();
            System.exit(2);
        } else {
            logger.info("Creating stdout statement template from bindings, since none is otherwise defined.");
            Set<String> activeBindingNames = new LinkedHashSet<>();
            String bindings = getActivityDef().getParams().getOptionalString("bindings").orElse("doc");
            activeBindingNames.addAll(stmtsDocList.getDocBindings().keySet());
            Pattern bindingsFilter = Pattern.compile(bindings.equalsIgnoreCase("doc") ? ".*" : bindings);
            Set<String> filteredBindingNames = new LinkedHashSet<>();
            activeBindingNames.stream().filter(n -> {
                if (bindingsFilter.matcher(n).matches()) {
                    logger.trace("bindings filter kept binding '" + n + "'");
                    return true;
                } else {
                    logger.trace("bindings filter removed binding '" + n + "'");
                    return false;
                }
            }).forEach(filteredBindingNames::add);
            activeBindingNames = filteredBindingNames;
            String generatedStmt = genStatementTemplate(activeBindingNames);
            BindingsTemplate bt = new BindingsTemplate();
            stmtsDocList.getDocBindings().forEach(bt::addFieldBinding);
            StringBindings sb = new StringBindings(generatedStmt, bt.getMap());
            sequencer.addOp(sb, 1L);
        }
    } else if (stmts.size() > 0) {
        for (OpTemplate stmt : stmts) {
            ParsedTemplate parsed = stmt.getParsed().orElseThrow();
            BindingsTemplate bt = new BindingsTemplate(parsed.getBindPoints());
            String statement = parsed.getPositionalStatement(Function.identity());
            Objects.requireNonNull(statement);
            if (!statement.endsWith("\n") && getParams().getOptionalBoolean("newline").orElse(true)) {
                statement = statement + "\n";
            }
            StringBindingsTemplate sbt = new StringBindingsTemplate(stmt.getStmt().orElseThrow(), bt);
            StringBindings sb = sbt.resolve();
            sequencer.addOp(sb, stmt.getParamOrDefault("ratio", 1));
        }
    } else {
        logger.error("Unable to create a stdout statement if you have no active statements or bindings configured.");
    }
    OpSequence<StringBindings> opSequence = sequencer.resolve();
    return opSequence;
}
Also used : Histogram(com.codahale.metrics.Histogram) OpSequence(io.nosqlbench.engine.api.activityapi.planning.OpSequence) StringBindings(io.nosqlbench.virtdata.core.templates.StringBindings) java.util(java.util) ParsedTemplate(io.nosqlbench.virtdata.core.templates.ParsedTemplate) ActivityDef(io.nosqlbench.engine.api.activityimpl.ActivityDef) SimpleActivity(io.nosqlbench.engine.api.activityimpl.SimpleActivity) Function(java.util.function.Function) ExceptionMeterMetrics(io.nosqlbench.engine.api.metrics.ExceptionMeterMetrics) ActivityDefObserver(io.nosqlbench.engine.api.activityapi.core.ActivityDefObserver) StmtsDocList(io.nosqlbench.engine.api.activityconfig.yaml.StmtsDocList) StatementsLoader(io.nosqlbench.engine.api.activityconfig.StatementsLoader) OpTemplate(io.nosqlbench.engine.api.activityconfig.yaml.OpTemplate) SequencePlanner(io.nosqlbench.engine.api.activityapi.planning.SequencePlanner) PrintWriter(java.io.PrintWriter) TemplateFormat(io.nosqlbench.adapters.stdout.TemplateFormat) BindingsTemplate(io.nosqlbench.virtdata.core.bindings.BindingsTemplate) FileNotFoundException(java.io.FileNotFoundException) ActivityMetrics(io.nosqlbench.engine.api.metrics.ActivityMetrics) SequencerType(io.nosqlbench.engine.api.activityapi.planning.SequencerType) Logger(org.apache.logging.log4j.Logger) ParameterMap(io.nosqlbench.engine.api.activityimpl.ParameterMap) Writer(java.io.Writer) Timer(com.codahale.metrics.Timer) StringBindingsTemplate(io.nosqlbench.virtdata.core.templates.StringBindingsTemplate) Pattern(java.util.regex.Pattern) LogManager(org.apache.logging.log4j.LogManager) Pattern(java.util.regex.Pattern) StringBindingsTemplate(io.nosqlbench.virtdata.core.templates.StringBindingsTemplate) SequencerType(io.nosqlbench.engine.api.activityapi.planning.SequencerType) StringBindings(io.nosqlbench.virtdata.core.templates.StringBindings) OpTemplate(io.nosqlbench.engine.api.activityconfig.yaml.OpTemplate) SequencePlanner(io.nosqlbench.engine.api.activityapi.planning.SequencePlanner) ParsedTemplate(io.nosqlbench.virtdata.core.templates.ParsedTemplate) BindingsTemplate(io.nosqlbench.virtdata.core.bindings.BindingsTemplate) StringBindingsTemplate(io.nosqlbench.virtdata.core.templates.StringBindingsTemplate)

Aggregations

Histogram (com.codahale.metrics.Histogram)1 Timer (com.codahale.metrics.Timer)1 TemplateFormat (io.nosqlbench.adapters.stdout.TemplateFormat)1 ActivityDefObserver (io.nosqlbench.engine.api.activityapi.core.ActivityDefObserver)1 OpSequence (io.nosqlbench.engine.api.activityapi.planning.OpSequence)1 SequencePlanner (io.nosqlbench.engine.api.activityapi.planning.SequencePlanner)1 SequencerType (io.nosqlbench.engine.api.activityapi.planning.SequencerType)1 StatementsLoader (io.nosqlbench.engine.api.activityconfig.StatementsLoader)1 OpTemplate (io.nosqlbench.engine.api.activityconfig.yaml.OpTemplate)1 StmtsDocList (io.nosqlbench.engine.api.activityconfig.yaml.StmtsDocList)1 ActivityDef (io.nosqlbench.engine.api.activityimpl.ActivityDef)1 ParameterMap (io.nosqlbench.engine.api.activityimpl.ParameterMap)1 SimpleActivity (io.nosqlbench.engine.api.activityimpl.SimpleActivity)1 ActivityMetrics (io.nosqlbench.engine.api.metrics.ActivityMetrics)1 ExceptionMeterMetrics (io.nosqlbench.engine.api.metrics.ExceptionMeterMetrics)1 BindingsTemplate (io.nosqlbench.virtdata.core.bindings.BindingsTemplate)1 ParsedTemplate (io.nosqlbench.virtdata.core.templates.ParsedTemplate)1 StringBindings (io.nosqlbench.virtdata.core.templates.StringBindings)1 StringBindingsTemplate (io.nosqlbench.virtdata.core.templates.StringBindingsTemplate)1 FileNotFoundException (java.io.FileNotFoundException)1