mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
make stdout adapter the default
This commit is contained in:
parent
a07adc5680
commit
16a52a0fb8
@ -16,27 +16,44 @@
|
|||||||
|
|
||||||
package io.nosqlbench.adapter.stdout;
|
package io.nosqlbench.adapter.stdout;
|
||||||
|
|
||||||
|
import io.nosqlbench.engine.api.activityconfig.yaml.OpTemplate;
|
||||||
import io.nosqlbench.engine.api.activityimpl.OpMapper;
|
import io.nosqlbench.engine.api.activityimpl.OpMapper;
|
||||||
import io.nosqlbench.engine.api.activityimpl.uniform.BaseDriverAdapter;
|
import io.nosqlbench.engine.api.activityimpl.uniform.BaseDriverAdapter;
|
||||||
import io.nosqlbench.engine.api.activityimpl.uniform.DriverAdapter;
|
import io.nosqlbench.engine.api.activityimpl.uniform.DriverAdapter;
|
||||||
import io.nosqlbench.engine.api.activityimpl.uniform.flowtypes.Op;
|
import io.nosqlbench.engine.api.activityimpl.uniform.DriverSpaceCache;
|
||||||
|
import io.nosqlbench.engine.api.templating.OpTemplateSupplier;
|
||||||
import io.nosqlbench.nb.annotations.Service;
|
import io.nosqlbench.nb.annotations.Service;
|
||||||
|
import io.nosqlbench.nb.api.config.standard.ConfigModel;
|
||||||
|
import io.nosqlbench.nb.api.config.standard.NBConfigModel;
|
||||||
import io.nosqlbench.nb.api.config.standard.NBConfiguration;
|
import io.nosqlbench.nb.api.config.standard.NBConfiguration;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.List;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.Optional;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
@Service(value= DriverAdapter.class, selector = "stdout")
|
@Service(value= DriverAdapter.class,selector = "stdout")
|
||||||
public class StdoutDriverAdapter extends BaseDriverAdapter<Op, Map<String,Object>> {
|
public class StdoutDriverAdapter extends BaseDriverAdapter<StdoutOp, StdoutSpace> implements OpTemplateSupplier, io.nosqlbench.engine.api.activityimpl.DefaultOpTemplateSupplier {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OpMapper<Op> getOpMapper() {
|
public OpMapper<StdoutOp> getOpMapper() {
|
||||||
return new StdoutOpMapper();
|
DriverSpaceCache<? extends StdoutSpace> ctxCache = getSpaceCache();
|
||||||
|
return new StdoutOpMapper(ctxCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Function<String, ? extends Map<String, Object>> getSpaceInitializer(NBConfiguration cfg) {
|
public Function<String, ? extends StdoutSpace> getSpaceInitializer(NBConfiguration cfg) {
|
||||||
return name -> new ConcurrentHashMap<>(cfg.getMap());
|
return (s) -> new StdoutSpace(cfg);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NBConfigModel getConfigModel() {
|
||||||
|
return ConfigModel.of(this.getClass())
|
||||||
|
.add(super.getConfigModel())
|
||||||
|
.add(StdoutSpace.getConfigModel());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<List<OpTemplate>> loadOpTemplates(NBConfiguration cfg) {
|
||||||
|
throw new RuntimeException("implement me");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,17 @@ import io.nosqlbench.engine.api.activityimpl.uniform.flowtypes.RunnableOp;
|
|||||||
|
|
||||||
public class StdoutOp implements RunnableOp {
|
public class StdoutOp implements RunnableOp {
|
||||||
|
|
||||||
|
private final StdoutSpace ctx;
|
||||||
|
private final String text;
|
||||||
|
|
||||||
|
public StdoutOp(StdoutSpace ctx, String text) {
|
||||||
|
this.ctx = ctx;
|
||||||
|
this.text = text;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
ctx.writeflush(text);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,15 +19,26 @@ package io.nosqlbench.adapter.stdout;
|
|||||||
import io.nosqlbench.engine.api.activityimpl.BaseOpDispenser;
|
import io.nosqlbench.engine.api.activityimpl.BaseOpDispenser;
|
||||||
import io.nosqlbench.engine.api.templating.ParsedOp;
|
import io.nosqlbench.engine.api.templating.ParsedOp;
|
||||||
|
|
||||||
public class StdoutOpDispenser extends BaseOpDispenser <StdoutOp> {
|
import java.util.function.LongFunction;
|
||||||
|
|
||||||
|
public class StdoutOpDispenser extends BaseOpDispenser<StdoutOp> {
|
||||||
|
|
||||||
public StdoutOpDispenser(ParsedOp op) {
|
private final LongFunction<StdoutSpace> ctxfunc;
|
||||||
super(op);
|
private final LongFunction<String> outFunction;
|
||||||
|
|
||||||
|
public StdoutOpDispenser(ParsedOp cmd, LongFunction<StdoutSpace> ctxfunc) {
|
||||||
|
super(cmd);
|
||||||
|
this.ctxfunc = ctxfunc;
|
||||||
|
LongFunction<Object> objectFunction = cmd.getAsRequiredFunction("stmt", Object.class);
|
||||||
|
LongFunction<String> stringfunc = l -> objectFunction.apply(l).toString();
|
||||||
|
cmd.enhance(stringfunc,"suffix",String.class,(a,b) -> a+b);
|
||||||
|
this.outFunction = stringfunc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StdoutOp apply(long value) {
|
public StdoutOp apply(long value) {
|
||||||
return null;
|
StdoutSpace ctx = ctxfunc.apply(value);
|
||||||
|
String output = outFunction.apply(value);
|
||||||
|
return new StdoutOp(ctx,output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,14 +18,24 @@ package io.nosqlbench.adapter.stdout;
|
|||||||
|
|
||||||
import io.nosqlbench.engine.api.activityimpl.OpDispenser;
|
import io.nosqlbench.engine.api.activityimpl.OpDispenser;
|
||||||
import io.nosqlbench.engine.api.activityimpl.OpMapper;
|
import io.nosqlbench.engine.api.activityimpl.OpMapper;
|
||||||
import io.nosqlbench.engine.api.activityimpl.uniform.flowtypes.Op;
|
import io.nosqlbench.engine.api.activityimpl.uniform.DriverSpaceCache;
|
||||||
import io.nosqlbench.engine.api.templating.ParsedOp;
|
import io.nosqlbench.engine.api.templating.ParsedOp;
|
||||||
|
|
||||||
public class StdoutOpMapper implements OpMapper<Op> {
|
import java.util.function.LongFunction;
|
||||||
|
|
||||||
|
public class StdoutOpMapper implements OpMapper<StdoutOp> {
|
||||||
|
|
||||||
|
private final DriverSpaceCache<? extends StdoutSpace> ctxcache;
|
||||||
|
|
||||||
|
public StdoutOpMapper(DriverSpaceCache<? extends StdoutSpace> ctxcache) {
|
||||||
|
this.ctxcache = ctxcache;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OpDispenser<? extends Op> apply(ParsedOp cmd) {
|
public OpDispenser<StdoutOp> apply(ParsedOp cmd) {
|
||||||
return new StdoutOpDispenser(cmd);
|
LongFunction<String> spacefunc = cmd.getAsFunctionOr("space", "default");
|
||||||
|
LongFunction<StdoutSpace> ctxfunc = (cycle) -> ctxcache.get(spacefunc.apply(cycle));
|
||||||
|
return new StdoutOpDispenser(cmd,ctxfunc);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,9 +14,12 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.nosqlbench.adapters.stdout;
|
package io.nosqlbench.adapter.stdout;
|
||||||
|
|
||||||
import io.nosqlbench.nb.api.config.standard.*;
|
import io.nosqlbench.nb.api.config.standard.ConfigModel;
|
||||||
|
import io.nosqlbench.nb.api.config.standard.NBConfigModel;
|
||||||
|
import io.nosqlbench.nb.api.config.standard.NBConfiguration;
|
||||||
|
import io.nosqlbench.nb.api.config.standard.Param;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
@ -32,9 +35,10 @@ public class StdoutSpace {
|
|||||||
this.writer = createPrintWriter(filename);
|
this.writer = createPrintWriter(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(String text) {
|
public void writeflush(String text) {
|
||||||
try {
|
try {
|
||||||
writer.write(text);
|
writer.write(text);
|
||||||
|
writer.flush();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@ -70,7 +74,8 @@ public class StdoutSpace {
|
|||||||
Param.optional("format")
|
Param.optional("format")
|
||||||
.setRegex("csv|readout|json|inlinejson|assignments|diag")
|
.setRegex("csv|readout|json|inlinejson|assignments|diag")
|
||||||
.setDescription("Which format to use.\n" +
|
.setDescription("Which format to use.\n" +
|
||||||
"If provided, the format will override any statement formats provided by the YAML")
|
"If provided, the format will override any statement formats provided by the YAML. " +
|
||||||
|
"If 'diag' is used, a diagnostic readout will be provided for binding constructions.")
|
||||||
)
|
)
|
||||||
.add(
|
.add(
|
||||||
Param.defaultTo("bindings","doc")
|
Param.defaultTo("bindings","doc")
|
@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.nosqlbench.adapters.stdout;
|
package io.nosqlbench.adapter.stdout;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
@ -20,11 +20,9 @@ import io.nosqlbench.engine.api.activityapi.core.Action;
|
|||||||
import io.nosqlbench.engine.api.activityapi.core.ActionDispenser;
|
import io.nosqlbench.engine.api.activityapi.core.ActionDispenser;
|
||||||
import io.nosqlbench.engine.api.activityapi.core.ActivityType;
|
import io.nosqlbench.engine.api.activityapi.core.ActivityType;
|
||||||
import io.nosqlbench.engine.api.activityimpl.ActivityDef;
|
import io.nosqlbench.engine.api.activityimpl.ActivityDef;
|
||||||
import io.nosqlbench.nb.annotations.Service;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@Service(value= ActivityType.class, selector="stdout-nb4")
|
|
||||||
public class StdoutActivityType implements ActivityType<StdoutActivity> {
|
public class StdoutActivityType implements ActivityType<StdoutActivity> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,56 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2022 nosqlbench
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.nosqlbench.adapters.stdout;
|
|
||||||
|
|
||||||
import io.nosqlbench.engine.api.activityconfig.yaml.OpTemplate;
|
|
||||||
import io.nosqlbench.engine.api.activityimpl.OpMapper;
|
|
||||||
import io.nosqlbench.engine.api.activityimpl.uniform.BaseDriverAdapter;
|
|
||||||
import io.nosqlbench.engine.api.activityimpl.uniform.DriverSpaceCache;
|
|
||||||
import io.nosqlbench.engine.api.templating.OpTemplateSupplier;
|
|
||||||
import io.nosqlbench.nb.api.config.standard.ConfigModel;
|
|
||||||
import io.nosqlbench.nb.api.config.standard.NBConfigModel;
|
|
||||||
import io.nosqlbench.nb.api.config.standard.NBConfiguration;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
public class StdoutDriverAdapter extends BaseDriverAdapter<StdoutOp, StdoutSpace> implements OpTemplateSupplier {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OpMapper<StdoutOp> getOpMapper() {
|
|
||||||
DriverSpaceCache<? extends StdoutSpace> ctxCache = getSpaceCache();
|
|
||||||
return new StdoutOpMapper(ctxCache);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Function<String, ? extends StdoutSpace> getSpaceInitializer(NBConfiguration cfg) {
|
|
||||||
return (s) -> new StdoutSpace(cfg);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NBConfigModel getConfigModel() {
|
|
||||||
return ConfigModel.of(this.getClass())
|
|
||||||
.add(super.getConfigModel())
|
|
||||||
.add(StdoutSpace.getConfigModel());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<List<OpTemplate>> loadOpTemplates(NBConfiguration cfg) {
|
|
||||||
throw new RuntimeException("implement me");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2022 nosqlbench
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.nosqlbench.adapters.stdout;
|
|
||||||
|
|
||||||
import io.nosqlbench.engine.api.activityimpl.BaseOpDispenser;
|
|
||||||
import io.nosqlbench.engine.api.templating.ParsedOp;
|
|
||||||
|
|
||||||
import java.util.function.LongFunction;
|
|
||||||
|
|
||||||
public class StdoutOpDispenser extends BaseOpDispenser<StdoutOp> {
|
|
||||||
|
|
||||||
private final LongFunction<StdoutSpace> ctxfunc;
|
|
||||||
private final LongFunction<String> outFunction;
|
|
||||||
|
|
||||||
public StdoutOpDispenser(ParsedOp cmd, LongFunction<StdoutSpace> ctxfunc) {
|
|
||||||
super(cmd);
|
|
||||||
this.ctxfunc = ctxfunc;
|
|
||||||
LongFunction<Object> objectFunction = cmd.getAsRequiredFunction("stmt", Object.class);
|
|
||||||
LongFunction<String> stringfunc = l -> objectFunction.apply(l).toString();
|
|
||||||
cmd.enhance(stringfunc,"suffix",String.class,(a,b) -> a+b);
|
|
||||||
this.outFunction = stringfunc;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public StdoutOp apply(long value) {
|
|
||||||
StdoutSpace ctx = ctxfunc.apply(value);
|
|
||||||
String output = outFunction.apply(value);
|
|
||||||
return new StdoutOp(ctx,output);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2022 nosqlbench
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.nosqlbench.adapters.stdout;
|
|
||||||
|
|
||||||
import io.nosqlbench.engine.api.activityimpl.OpDispenser;
|
|
||||||
import io.nosqlbench.engine.api.activityimpl.OpMapper;
|
|
||||||
import io.nosqlbench.engine.api.activityimpl.uniform.DriverSpaceCache;
|
|
||||||
import io.nosqlbench.engine.api.templating.ParsedOp;
|
|
||||||
|
|
||||||
import java.util.function.LongFunction;
|
|
||||||
|
|
||||||
public class StdoutOpMapper implements OpMapper<StdoutOp> {
|
|
||||||
|
|
||||||
private final DriverSpaceCache<? extends StdoutSpace> ctxcache;
|
|
||||||
|
|
||||||
public StdoutOpMapper(DriverSpaceCache<? extends StdoutSpace> ctxcache) {
|
|
||||||
this.ctxcache = ctxcache;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OpDispenser<StdoutOp> apply(ParsedOp cmd) {
|
|
||||||
LongFunction<String> spacefunc = cmd.getAsFunctionOr("space", "default");
|
|
||||||
LongFunction<StdoutSpace> ctxfunc = (cycle) -> ctxcache.get(spacefunc.apply(cycle));
|
|
||||||
return new StdoutOpDispenser(cmd,ctxfunc);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -18,11 +18,9 @@ package io.nosqlbench.engine.api.activityimpl.uniform;
|
|||||||
|
|
||||||
import io.nosqlbench.engine.api.activityapi.planning.OpSequence;
|
import io.nosqlbench.engine.api.activityapi.planning.OpSequence;
|
||||||
import io.nosqlbench.engine.api.activityconfig.StatementsLoader;
|
import io.nosqlbench.engine.api.activityconfig.StatementsLoader;
|
||||||
|
import io.nosqlbench.engine.api.activityconfig.yaml.OpTemplate;
|
||||||
import io.nosqlbench.engine.api.activityconfig.yaml.StmtsDocList;
|
import io.nosqlbench.engine.api.activityconfig.yaml.StmtsDocList;
|
||||||
import io.nosqlbench.engine.api.activityimpl.ActivityDef;
|
import io.nosqlbench.engine.api.activityimpl.*;
|
||||||
import io.nosqlbench.engine.api.activityimpl.OpDispenser;
|
|
||||||
import io.nosqlbench.engine.api.activityimpl.OpMapper;
|
|
||||||
import io.nosqlbench.engine.api.activityimpl.SimpleActivity;
|
|
||||||
import io.nosqlbench.engine.api.activityimpl.uniform.flowtypes.Op;
|
import io.nosqlbench.engine.api.activityimpl.uniform.flowtypes.Op;
|
||||||
import io.nosqlbench.nb.api.config.standard.*;
|
import io.nosqlbench.nb.api.config.standard.*;
|
||||||
import io.nosqlbench.nb.api.errors.OpConfigError;
|
import io.nosqlbench.nb.api.errors.OpConfigError;
|
||||||
@ -43,7 +41,7 @@ import java.util.function.Function;
|
|||||||
* @param <R> A type of runnable which wraps the operations for this type of driver.
|
* @param <R> A type of runnable which wraps the operations for this type of driver.
|
||||||
* @param <S> The context type for the activity, AKA the 'space' for a named driver instance and its associated object graph
|
* @param <S> The context type for the activity, AKA the 'space' for a named driver instance and its associated object graph
|
||||||
*/
|
*/
|
||||||
public class StandardActivity<R extends Op, S> extends SimpleActivity {
|
public class StandardActivity<R extends Op, S> extends SimpleActivity implements DefaultOpTemplateSupplier {
|
||||||
private final static Logger logger = LogManager.getLogger("ACTIVITY");
|
private final static Logger logger = LogManager.getLogger("ACTIVITY");
|
||||||
|
|
||||||
private final DriverAdapter<R, S> adapter;
|
private final DriverAdapter<R, S> adapter;
|
||||||
@ -121,4 +119,13 @@ public class StandardActivity<R extends Op, S> extends SimpleActivity {
|
|||||||
//
|
//
|
||||||
// ActivityDefObserver.apply(activityDef, adapter, sequence);
|
// ActivityDefObserver.apply(activityDef, adapter, sequence);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<OpTemplate> getDefaultTemplates(StmtsDocList optionalDocs) {
|
||||||
|
if (adapter instanceof DefaultOpTemplateSupplier s) {
|
||||||
|
return s.getDefaultTemplates(optionalDocs);
|
||||||
|
} else {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user