Search in sources :

Example 1 with OpConfigError

use of io.nosqlbench.nb.api.errors.OpConfigError in project nosqlbench by nosqlbench.

the class ParsedTemplateMap method applyTemplateFields.

// For now, we only allow bind points to reference bindings, not other op template
// fields. This seems like the saner and less confusing approach, so implementing
// op field references should be left until it is requested if at all
private void applyTemplateFields(Map<String, Object> map, Map<String, String> bindings) {
    this.specmap = map;
    this.bindings = bindings;
    map.forEach((k, v) -> {
        if (v instanceof CharSequence) {
            ParsedTemplate pt = ParsedTemplate.of(((CharSequence) v).toString(), bindings);
            this.captures.add(pt.getCaptures());
            switch(pt.getType()) {
                case literal:
                    statics.put(k, ((CharSequence) v).toString());
                    protomap.put(k, ((CharSequence) v).toString());
                    break;
                case bindref:
                    String spec = pt.asBinding().orElseThrow().getBindspec();
                    if (spec == null) {
                        throw new OpConfigError("Empty binding spec for '" + k + "'");
                    }
                    Optional<DataMapper<Object>> mapper = VirtData.getOptionalMapper(spec);
                    dynamics.put(k, mapper.orElseThrow());
                    protomap.put(k, null);
                    break;
                case concat:
                    StringBindings sb = new StringBindings(pt);
                    dynamics.put(k, sb);
                    protomap.put(k, null);
                    break;
            }
        } else if (v instanceof Map) {
            ((Map) v).keySet().forEach(smk -> {
                if (!CharSequence.class.isAssignableFrom(smk.getClass())) {
                    throw new OpConfigError("Only string keys are allowed in submaps.");
                }
            });
            Map<String, Object> submap = (Map<String, Object>) v;
            ParsedTemplateMap subtpl = new ParsedTemplateMap(submap, bindings, cfgsources);
            if (subtpl.isStatic()) {
                statics.put(k, submap);
                protomap.put(k, submap);
            } else {
                dynamics.put(k, subtpl);
                protomap.put(k, null);
            }
        } else if (v instanceof List) {
            List<Object> sublist = (List<Object>) v;
            ParsedTemplateList subtpl = new ParsedTemplateList(sublist, bindings, cfgsources);
            if (subtpl.isStatic()) {
                statics.put(k, sublist);
                protomap.put(k, sublist);
            } else {
                dynamics.put(k, subtpl);
                protomap.put(k, null);
            }
        } else {
            // Eventually, nested and mixed static dynamic structure could be supported, but
            // it would be complex to implement and also not that efficient, so let's just copy
            // structure for now
            statics.put(k, v);
            protomap.put(k, v);
        }
    });
}
Also used : ListBinder(io.nosqlbench.engine.api.templating.binders.ListBinder) StringBindings(io.nosqlbench.virtdata.core.templates.StringBindings) java.util(java.util) ParsedTemplate(io.nosqlbench.virtdata.core.templates.ParsedTemplate) LongFunction(java.util.function.LongFunction) ArrayBinder(io.nosqlbench.engine.api.templating.binders.ArrayBinder) CapturePoint(io.nosqlbench.virtdata.core.templates.CapturePoint) BindPoint(io.nosqlbench.virtdata.core.templates.BindPoint) Function(java.util.function.Function) BasicError(io.nosqlbench.nb.api.errors.BasicError) NBConfigError(io.nosqlbench.nb.api.config.standard.NBConfigError) NBTypeConverter(io.nosqlbench.nb.api.config.standard.NBTypeConverter) DynamicFieldReader(io.nosqlbench.nb.api.config.fieldreaders.DynamicFieldReader) OpConfigError(io.nosqlbench.nb.api.errors.OpConfigError) OrderedMapBinder(io.nosqlbench.engine.api.templating.binders.OrderedMapBinder) Logger(org.apache.logging.log4j.Logger) StaticFieldReader(io.nosqlbench.nb.api.config.fieldreaders.StaticFieldReader) VirtData(io.nosqlbench.virtdata.core.bindings.VirtData) DataMapper(io.nosqlbench.virtdata.core.bindings.DataMapper) LogManager(org.apache.logging.log4j.LogManager) OpConfigError(io.nosqlbench.nb.api.errors.OpConfigError) DataMapper(io.nosqlbench.virtdata.core.bindings.DataMapper) StringBindings(io.nosqlbench.virtdata.core.templates.StringBindings) ParsedTemplate(io.nosqlbench.virtdata.core.templates.ParsedTemplate)

Example 2 with OpConfigError

use of io.nosqlbench.nb.api.errors.OpConfigError in project nosqlbench by nosqlbench.

the class Templatizer method make.

public static Result make(Map<String, String> bindings, Object v, String name, List<Map<String, Object>> cfgsources) {
    Result result = new Result();
    result.setName(name);
    if (v instanceof CharSequence) {
        ParsedTemplate pt = ParsedTemplate.of(((CharSequence) v).toString(), bindings);
        result.addCaptures(pt.getCaptures());
        result.setType(pt.getType());
        switch(pt.getType()) {
            case literal:
                result.setValue(((CharSequence) v).toString());
                break;
            case bindref:
                String spec = pt.asBinding().orElseThrow().getBindspec();
                if (spec == null) {
                    throw new OpConfigError("Empty binding spec for '" + (name != null ? name : "anonymous binding") + "'");
                }
                Optional<DataMapper<Object>> mapper = VirtData.getOptionalMapper(spec);
                result.setFunction(mapper.orElseThrow());
                break;
            case concat:
                StringBindings sb = new StringBindings(pt);
                result.setFunction(sb);
                break;
        }
    } else if (v instanceof Map) {
        ((Map) v).keySet().forEach(smk -> {
            if (!CharSequence.class.isAssignableFrom(smk.getClass())) {
                throw new OpConfigError("Only string keys are allowed in submaps.");
            }
        });
        Map<String, Object> submap = (Map<String, Object>) v;
        ParsedTemplateMap subtpl = new ParsedTemplateMap(submap, bindings, cfgsources);
        if (subtpl.isStatic()) {
            result.setValue(submap);
        } else {
            result.setFunction(subtpl);
        }
    } else if (v instanceof List) {
        List<Object> sublist = (List<Object>) v;
        ParsedTemplateList subtpl = new ParsedTemplateList(sublist, bindings, cfgsources);
        if (subtpl.isStatic()) {
            result.setValue(sublist);
        } else {
            result.setFunction(subtpl);
        }
    } else {
        result.setValue(v);
    // Eventually, nested and mixed static dynamic structure could be supported, but
    // it would be complex to implement and also not that efficient, so let's just copy
    // structure for now
    }
    return result;
}
Also used : OpConfigError(io.nosqlbench.nb.api.errors.OpConfigError) StringBindings(io.nosqlbench.virtdata.core.templates.StringBindings) List(java.util.List) ParsedTemplate(io.nosqlbench.virtdata.core.templates.ParsedTemplate) LongFunction(java.util.function.LongFunction) Map(java.util.Map) CapturePoint(io.nosqlbench.virtdata.core.templates.CapturePoint) Optional(java.util.Optional) VirtData(io.nosqlbench.virtdata.core.bindings.VirtData) DataMapper(io.nosqlbench.virtdata.core.bindings.DataMapper) ArrayList(java.util.ArrayList) OpConfigError(io.nosqlbench.nb.api.errors.OpConfigError) DataMapper(io.nosqlbench.virtdata.core.bindings.DataMapper) StringBindings(io.nosqlbench.virtdata.core.templates.StringBindings) List(java.util.List) ArrayList(java.util.ArrayList) ParsedTemplate(io.nosqlbench.virtdata.core.templates.ParsedTemplate) Map(java.util.Map)

Example 3 with OpConfigError

use of io.nosqlbench.nb.api.errors.OpConfigError in project nosqlbench by nosqlbench.

the class Cqld4FluentGraphOpMapper method apply.

@Override
public OpDispenser<? extends Op> apply(ParsedOp cmd) {
    GraphTraversalSource g = DseGraph.g;
    ParsedTemplate fluent = cmd.getAsTemplate(target.field).orElseThrow();
    String scriptBodyWithRawVarRefs = fluent.getPositionalStatement();
    CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
    if (cmd.isDynamic("imports")) {
        throw new OpConfigError("You may only define imports as a static list. Dynamic values are not allowed.");
    }
    List imports = cmd.getOptionalStaticValue("imports", List.class).orElse(List.of("org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__"));
    String[] verifiedClasses = expandClassNames(imports);
    ImportCustomizer importer = new ImportCustomizer();
    importer.addImports(verifiedClasses);
    compilerConfiguration.addCompilationCustomizers(importer);
    Supplier<Script> supplier = () -> {
        groovy.lang.Binding groovyBindings = new Binding(new LinkedHashMap<String, Object>(Map.of("g", g)));
        GroovyShell gshell = new GroovyShell(groovyBindings, compilerConfiguration);
        return gshell.parse(scriptBodyWithRawVarRefs);
    };
    LongFunction<? extends String> graphnameFunc = cmd.getAsRequiredFunction("graphname");
    Bindings virtdataBindings = new BindingsTemplate(fluent.getBindPoints()).resolveBindings();
    return new Cqld4FluentGraphOpDispenser(cmd, graphnameFunc, sessionFunc, virtdataBindings, supplier);
}
Also used : Binding(groovy.lang.Binding) Script(groovy.lang.Script) OpConfigError(io.nosqlbench.nb.api.errors.OpConfigError) Bindings(io.nosqlbench.virtdata.core.bindings.Bindings) GroovyShell(groovy.lang.GroovyShell) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Cqld4FluentGraphOpDispenser(io.nosqlbench.adapter.cqld4.opdispensers.Cqld4FluentGraphOpDispenser) CompilerConfiguration(org.codehaus.groovy.control.CompilerConfiguration) ImportCustomizer(org.codehaus.groovy.control.customizers.ImportCustomizer) ParsedTemplate(io.nosqlbench.virtdata.core.templates.ParsedTemplate) BindingsTemplate(io.nosqlbench.virtdata.core.bindings.BindingsTemplate)

Example 4 with OpConfigError

use of io.nosqlbench.nb.api.errors.OpConfigError in project nosqlbench by nosqlbench.

the class DynamoDBSpace method createClient.

private AmazonDynamoDB createClient(NBConfiguration cfg) {
    AmazonDynamoDBClientBuilder builder = AmazonDynamoDBClientBuilder.standard();
    Optional<String> region = cfg.getOptional("region");
    Optional<String> endpoint = cfg.getOptional("endpoint");
    Optional<String> signing_region = cfg.getOptional("signing_region");
    if (region.isPresent() && (endpoint.isPresent() || signing_region.isPresent())) {
        throw new OpConfigError("If you specify region, endpoint and signing_region options are not allowed");
    }
    if (region.isPresent()) {
        builder.withRegion(region.get());
    } else if (endpoint.isPresent() && signing_region.isPresent()) {
        AwsClientBuilder.EndpointConfiguration endpointConfiguration = new AwsClientBuilder.EndpointConfiguration(endpoint.get(), signing_region.get());
        builder = builder.withEndpointConfiguration(endpointConfiguration);
    } else {
        throw new OpConfigError("Either region or endpoint and signing_region options are required.");
    }
    ClientConfiguration ccfg = new ClientConfiguration();
    cfg.getOptional("client_socket_timeout").map(Integer::parseInt).ifPresent(ccfg::withSocketTimeout);
    cfg.getOptional("client_execution_timeout").map(Integer::parseInt).ifPresent(ccfg::withClientExecutionTimeout);
    cfg.getOptional("client_max_connections").map(Integer::parseInt).ifPresent(ccfg::withMaxConnections);
    cfg.getOptional("client_max_error_retry").map(Integer::parseInt).ifPresent(ccfg::withMaxErrorRetry);
    cfg.getOptional("client_user_agent_prefix").ifPresent(ccfg::withUserAgentPrefix);
    cfg.getOptional("client_consecutive_retries_before_throttling").map(Integer::parseInt).ifPresent(ccfg::withMaxConsecutiveRetriesBeforeThrottling);
    cfg.getOptional("client_gzip").map(Boolean::parseBoolean).ifPresent(ccfg::withGzip);
    cfg.getOptional("client_tcp_keepalive").map(Boolean::parseBoolean).ifPresent(ccfg::withTcpKeepAlive);
    cfg.getOptional("client_disable_socket_proxy").map(Boolean::parseBoolean).ifPresent(ccfg::withDisableSocketProxy);
    // ccfg.withHeader();
    // ccfg.withProtocol()
    // ccfg.withRetryMode();
    // ccfg.withRetryPolicy();
    ccfg.withSocketBufferSizeHints(cfg.getOptional("client_so_send_size_hint").map(Integer::parseInt).orElse(0), cfg.getOptional("client_so_recv_size_hint").map(Integer::parseInt).orElse(0));
    builder.setClientConfiguration(ccfg);
    return builder.build();
}
Also used : AmazonDynamoDBClientBuilder(com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder) OpConfigError(io.nosqlbench.nb.api.errors.OpConfigError) AwsClientBuilder(com.amazonaws.client.builder.AwsClientBuilder) ClientConfiguration(com.amazonaws.ClientConfiguration)

Example 5 with OpConfigError

use of io.nosqlbench.nb.api.errors.OpConfigError in project nosqlbench by nosqlbench.

the class ParsedTemplateMap method getOptionalTargetEnum.

public <E extends Enum<E>, V> Optional<TypeAndTarget<E, V>> getOptionalTargetEnum(Class<E> enumclass, String typeFieldName, String valueFieldName, Class<V> valueClass) {
    if (isStatic(typeFieldName)) {
        String enumValue = statics.get(typeFieldName).toString();
        E verifiedEnumValue;
        try {
            verifiedEnumValue = Enum.valueOf(enumclass, enumValue);
        } catch (IllegalArgumentException iae) {
            throw new OpConfigError("type designator field '" + typeFieldName + "' had value of '" + enumValue + ", but this failed to match " + "any of known types in " + EnumSet.allOf(enumclass));
        }
        if (isDefined(valueFieldName)) {
            if (isStatic(typeFieldName)) {
                return Optional.of(new TypeAndTarget<E, V>(verifiedEnumValue, typeFieldName, l -> NBTypeConverter.convert(statics.get(valueFieldName), valueClass)));
            } else if (isDynamic(valueFieldName)) {
                return Optional.of(new TypeAndTarget<E, V>(verifiedEnumValue, typeFieldName, getAsRequiredFunction(valueFieldName, valueClass)));
            }
        }
    } else if (isDynamic(typeFieldName)) {
        throw new OpConfigError("The op template field '" + typeFieldName + "' must be a static value. You can not vary it by cycle.");
    }
    return Optional.empty();
}
Also used : ListBinder(io.nosqlbench.engine.api.templating.binders.ListBinder) StringBindings(io.nosqlbench.virtdata.core.templates.StringBindings) java.util(java.util) ParsedTemplate(io.nosqlbench.virtdata.core.templates.ParsedTemplate) LongFunction(java.util.function.LongFunction) ArrayBinder(io.nosqlbench.engine.api.templating.binders.ArrayBinder) CapturePoint(io.nosqlbench.virtdata.core.templates.CapturePoint) BindPoint(io.nosqlbench.virtdata.core.templates.BindPoint) Function(java.util.function.Function) BasicError(io.nosqlbench.nb.api.errors.BasicError) NBConfigError(io.nosqlbench.nb.api.config.standard.NBConfigError) NBTypeConverter(io.nosqlbench.nb.api.config.standard.NBTypeConverter) DynamicFieldReader(io.nosqlbench.nb.api.config.fieldreaders.DynamicFieldReader) OpConfigError(io.nosqlbench.nb.api.errors.OpConfigError) OrderedMapBinder(io.nosqlbench.engine.api.templating.binders.OrderedMapBinder) Logger(org.apache.logging.log4j.Logger) StaticFieldReader(io.nosqlbench.nb.api.config.fieldreaders.StaticFieldReader) VirtData(io.nosqlbench.virtdata.core.bindings.VirtData) DataMapper(io.nosqlbench.virtdata.core.bindings.DataMapper) LogManager(org.apache.logging.log4j.LogManager) OpConfigError(io.nosqlbench.nb.api.errors.OpConfigError)

Aggregations

OpConfigError (io.nosqlbench.nb.api.errors.OpConfigError)9 BasicError (io.nosqlbench.nb.api.errors.BasicError)4 ParsedTemplate (io.nosqlbench.virtdata.core.templates.ParsedTemplate)4 DataMapper (io.nosqlbench.virtdata.core.bindings.DataMapper)3 VirtData (io.nosqlbench.virtdata.core.bindings.VirtData)3 CapturePoint (io.nosqlbench.virtdata.core.templates.CapturePoint)3 StringBindings (io.nosqlbench.virtdata.core.templates.StringBindings)3 LongFunction (java.util.function.LongFunction)3 ArrayBinder (io.nosqlbench.engine.api.templating.binders.ArrayBinder)2 ListBinder (io.nosqlbench.engine.api.templating.binders.ListBinder)2 OrderedMapBinder (io.nosqlbench.engine.api.templating.binders.OrderedMapBinder)2 DynamicFieldReader (io.nosqlbench.nb.api.config.fieldreaders.DynamicFieldReader)2 StaticFieldReader (io.nosqlbench.nb.api.config.fieldreaders.StaticFieldReader)2 NBConfigError (io.nosqlbench.nb.api.config.standard.NBConfigError)2 NBTypeConverter (io.nosqlbench.nb.api.config.standard.NBTypeConverter)2 BindPoint (io.nosqlbench.virtdata.core.templates.BindPoint)2 java.util (java.util)2 Function (java.util.function.Function)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2