Search in sources :

Example 1 with SequencePlanner

use of io.nosqlbench.engine.api.activityapi.planning.SequencePlanner 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)

Example 2 with SequencePlanner

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

the class KafkaProducerActivity method initOpSequencer.

private OpSequence<KafkaStatement> initOpSequencer() {
    SequencerType sequencerType = SequencerType.valueOf(getParams().getOptionalString("seq").orElse("bucket"));
    SequencePlanner<KafkaStatement> sequencer = new SequencePlanner<>(sequencerType);
    String tagFilter = activityDef.getParams().getOptionalString("tags").orElse("");
    StmtsDocList stmtsDocList = StatementsLoader.loadPath(logger, yamlLoc, activityDef.getParams(), "activities");
    List<OpTemplate> statements = stmtsDocList.getStmts(tagFilter);
    String format = getParams().getOptionalString("format").orElse(null);
    if (statements.size() > 0) {
        for (OpTemplate statement : statements) {
            sequencer.addOp(new KafkaStatement(statement, servers, clientId, schemaRegistryUrl), statement.getParamOrDefault("ratio", 1));
        }
    } else {
        logger.error("Unable to create a Kafka statement if you have no active statements.");
    }
    return sequencer.resolve();
}
Also used : OpTemplate(io.nosqlbench.engine.api.activityconfig.yaml.OpTemplate) SequencePlanner(io.nosqlbench.engine.api.activityapi.planning.SequencePlanner) StmtsDocList(io.nosqlbench.engine.api.activityconfig.yaml.StmtsDocList) SequencerType(io.nosqlbench.engine.api.activityapi.planning.SequencerType)

Example 3 with SequencePlanner

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

the class MongoActivity method initOpSequencer.

OpSequence<ReadyMongoStatement> initOpSequencer() {
    SequencerType sequencerType = SequencerType.valueOf(activityDef.getParams().getOptionalString("seq").orElse("bucket"));
    SequencePlanner<ReadyMongoStatement> sequencer = new SequencePlanner<>(sequencerType);
    StmtsDocList stmtsDocList = StatementsLoader.loadPath(logger, yamlLoc, activityDef.getParams(), "activities");
    String tagfilter = activityDef.getParams().getOptionalString("tags").orElse("");
    TagFilter tagFilter = new TagFilter(tagfilter);
    stmtsDocList.getStmts().stream().map(tagFilter::matchesTaggedResult).forEach(r -> logger.info(r.getLog()));
    List<OpTemplate> stmts = stmtsDocList.getStmts(tagfilter);
    if (stmts.isEmpty()) {
        logger.error("No statements found for this activity");
    } else {
        for (OpTemplate stmt : stmts) {
            ParsedTemplate parsed = stmt.getParsed().orElseThrow();
            String statement = parsed.getPositionalStatement(Function.identity());
            Objects.requireNonNull(statement);
            sequencer.addOp(new ReadyMongoStatement(stmt), stmt.getParamOrDefault("ratio", 1));
        }
    }
    return sequencer.resolve();
}
Also used : OpTemplate(io.nosqlbench.engine.api.activityconfig.yaml.OpTemplate) TagFilter(io.nosqlbench.engine.api.util.TagFilter) SequencePlanner(io.nosqlbench.engine.api.activityapi.planning.SequencePlanner) StmtsDocList(io.nosqlbench.engine.api.activityconfig.yaml.StmtsDocList) ConnectionString(com.mongodb.ConnectionString) SequencerType(io.nosqlbench.engine.api.activityapi.planning.SequencerType) ParsedTemplate(io.nosqlbench.virtdata.core.templates.ParsedTemplate)

Example 4 with SequencePlanner

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

the class SimpleActivity method createOpSequence.

/**
 * Given a function that can create an op of type <O> from an OpTemplate, generate
 * an indexed sequence of ready to call operations.
 *
 * This method uses the following conventions to derive the sequence:
 *
 * <OL>
 * <LI>If an 'op', 'stmt', or 'statement' parameter is provided, then it's value is
 * taken as the only provided statement.</LI>
 * <LI>If a 'yaml, or 'workload' parameter is provided, then the statements in that file
 * are taken with their ratios </LI>
 * <LI>Any provided tags filter is used to select only the statements which have matching
 * tags. If no tags are provided, then all the found statements are included.</LI>
 * <LI>The ratios and the 'seq' parameter are used to build a sequence of the ready operations,
 * where the sequence length is the sum of the ratios.</LI>
 * </OL>
 *
 * @param opinit A function to map an OpTemplate to the executable operation form required by
 *               the native driver for this activity.
 * @param <O>    A holder for an executable operation for the native driver used by this activity.
 * @return The sequence of operations as determined by filtering and ratios
 */
@Deprecated(forRemoval = true)
protected <O> OpSequence<OpDispenser<? extends O>> createOpSequence(Function<OpTemplate, OpDispenser<? extends O>> opinit) {
    String tagfilter = activityDef.getParams().getOptionalString("tags").orElse("");
    // StrInterpolator interp = new StrInterpolator(activityDef);
    SequencerType sequencerType = getParams().getOptionalString("seq").map(SequencerType::valueOf).orElse(SequencerType.bucket);
    SequencePlanner<OpDispenser<? extends O>> planner = new SequencePlanner<>(sequencerType);
    StmtsDocList stmtsDocList = null;
    String workloadSource = "unspecified";
    Optional<String> stmt = activityDef.getParams().getOptionalString("op", "stmt", "statement");
    Optional<String> op_yaml_loc = activityDef.getParams().getOptionalString("yaml", "workload");
    if (stmt.isPresent()) {
        stmtsDocList = StatementsLoader.loadStmt(logger, stmt.get(), activityDef.getParams());
        workloadSource = "commandline:" + stmt.get();
    } else if (op_yaml_loc.isPresent()) {
        stmtsDocList = StatementsLoader.loadPath(logger, op_yaml_loc.get(), activityDef.getParams(), "activities");
        workloadSource = "yaml:" + op_yaml_loc.get();
    }
    List<OpTemplate> stmts = stmtsDocList.getStmts(tagfilter);
    List<Long> ratios = new ArrayList<>(stmts.size());
    for (int i = 0; i < stmts.size(); i++) {
        OpTemplate opTemplate = stmts.get(i);
        long ratio = opTemplate.removeParamOrDefault("ratio", 1);
        ratios.add(ratio);
    }
    if (stmts.size() == 0) {
        throw new BasicError("There were no active statements with tag filter '" + tagfilter + "'");
    }
    try {
        for (int i = 0; i < stmts.size(); i++) {
            long ratio = ratios.get(i);
            OpTemplate optemplate = stmts.get(i);
            OpDispenser<? extends O> driverSpecificReadyOp = opinit.apply(optemplate);
            planner.addOp(driverSpecificReadyOp, ratio);
        }
    } catch (Exception e) {
        throw new OpConfigError(e.getMessage(), workloadSource, e);
    }
    return planner.resolve();
}
Also used : OpConfigError(io.nosqlbench.nb.api.errors.OpConfigError) SequencerType(io.nosqlbench.engine.api.activityapi.planning.SequencerType) OpTemplate(io.nosqlbench.engine.api.activityconfig.yaml.OpTemplate) SequencePlanner(io.nosqlbench.engine.api.activityapi.planning.SequencePlanner) StmtsDocList(io.nosqlbench.engine.api.activityconfig.yaml.StmtsDocList) BasicError(io.nosqlbench.nb.api.errors.BasicError)

Aggregations

SequencePlanner (io.nosqlbench.engine.api.activityapi.planning.SequencePlanner)4 SequencerType (io.nosqlbench.engine.api.activityapi.planning.SequencerType)4 OpTemplate (io.nosqlbench.engine.api.activityconfig.yaml.OpTemplate)4 StmtsDocList (io.nosqlbench.engine.api.activityconfig.yaml.StmtsDocList)4 ParsedTemplate (io.nosqlbench.virtdata.core.templates.ParsedTemplate)2 Histogram (com.codahale.metrics.Histogram)1 Timer (com.codahale.metrics.Timer)1 ConnectionString (com.mongodb.ConnectionString)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 StatementsLoader (io.nosqlbench.engine.api.activityconfig.StatementsLoader)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 TagFilter (io.nosqlbench.engine.api.util.TagFilter)1 BasicError (io.nosqlbench.nb.api.errors.BasicError)1 OpConfigError (io.nosqlbench.nb.api.errors.OpConfigError)1