mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2024-12-25 08:11:06 -06:00
restore stdout adapters ability to synthesize example ops
This commit is contained in:
parent
7a3c3c583f
commit
f858ffa1d0
@ -16,23 +16,28 @@
|
||||
|
||||
package io.nosqlbench.adapter.stdout;
|
||||
|
||||
import io.nosqlbench.engine.api.activityconfig.yaml.OpData;
|
||||
import io.nosqlbench.engine.api.activityconfig.yaml.OpTemplate;
|
||||
import io.nosqlbench.engine.api.activityconfig.yaml.StmtsDocList;
|
||||
import io.nosqlbench.engine.api.activityimpl.OpMapper;
|
||||
import io.nosqlbench.engine.api.activityimpl.uniform.BaseDriverAdapter;
|
||||
import io.nosqlbench.engine.api.activityimpl.uniform.DriverAdapter;
|
||||
import io.nosqlbench.engine.api.activityimpl.uniform.DriverSpaceCache;
|
||||
import io.nosqlbench.engine.api.templating.OpTemplateSupplier;
|
||||
import io.nosqlbench.engine.api.activityimpl.uniform.decorators.SyntheticOpTemplateProvider;
|
||||
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 org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Service(value= DriverAdapter.class,selector = "stdout")
|
||||
public class StdoutDriverAdapter extends BaseDriverAdapter<StdoutOp, StdoutSpace> implements OpTemplateSupplier {
|
||||
public class StdoutDriverAdapter extends BaseDriverAdapter<StdoutOp, StdoutSpace> implements SyntheticOpTemplateProvider {
|
||||
private final static Logger logger = LogManager.getLogger(StdoutDriverAdapter.class);
|
||||
|
||||
@Override
|
||||
public OpMapper<StdoutOp> getOpMapper() {
|
||||
@ -53,7 +58,47 @@ public class StdoutDriverAdapter extends BaseDriverAdapter<StdoutOp, StdoutSpace
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<List<OpTemplate>> loadOpTemplates(NBConfiguration cfg) {
|
||||
throw new RuntimeException("implement me");
|
||||
public List<OpTemplate> getSyntheticOpTemplates(StmtsDocList stmtsDocList, Map<String,Object> cfg) {
|
||||
Set<String> activeBindingNames = new LinkedHashSet<>();
|
||||
|
||||
String bindings = Optional.ofNullable(cfg.get("bindings")).map(Object::toString).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;
|
||||
|
||||
OpData op = new OpData("synthetic", "synthetic", Map.of(), stmtsDocList.getDocBindings(), cfg,
|
||||
Map.of("stmt", genStatementTemplate(activeBindingNames, cfg)));
|
||||
|
||||
return List.of(op);
|
||||
}
|
||||
|
||||
private String genStatementTemplate(Set<String> keySet, Map<String,Object> cfg) {
|
||||
TemplateFormat format = Optional.ofNullable(cfg.get("format"))
|
||||
.map(Object::toString)
|
||||
.map(TemplateFormat::valueOf)
|
||||
.orElse(TemplateFormat.assignments);
|
||||
|
||||
boolean ensureNewline = Optional.ofNullable(cfg.get("newline"))
|
||||
.map(Object::toString)
|
||||
.map(Boolean::valueOf)
|
||||
.orElse(true);
|
||||
|
||||
String stmtTemplate = format.format(ensureNewline, new ArrayList<>(keySet));
|
||||
return stmtTemplate;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -55,7 +55,6 @@ import java.util.function.Function;
|
||||
*/
|
||||
public interface DriverAdapter<R extends Op, S> {
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* <H2>Op Mapping</H2>
|
||||
|
@ -35,10 +35,12 @@ import io.nosqlbench.engine.api.activityapi.ratelimits.RateSpec;
|
||||
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.activityimpl.uniform.decorators.SyntheticOpTemplateProvider;
|
||||
import io.nosqlbench.engine.api.activityimpl.uniform.flowtypes.Op;
|
||||
import io.nosqlbench.engine.api.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.engine.api.templating.CommandTemplate;
|
||||
import io.nosqlbench.engine.api.templating.ParsedOp;
|
||||
import io.nosqlbench.nb.api.config.standard.NBConfigModel;
|
||||
import io.nosqlbench.nb.api.config.standard.NBConfiguration;
|
||||
import io.nosqlbench.nb.api.errors.BasicError;
|
||||
import io.nosqlbench.nb.api.errors.OpConfigError;
|
||||
@ -503,6 +505,7 @@ public class SimpleActivity implements Activity, ProgressCapable {
|
||||
|
||||
StmtsDocList stmtsDocList = loadStmtsDocList();
|
||||
|
||||
|
||||
if (stmtsDocList == null) {
|
||||
throw new OpConfigError("No op templates found. You must provide either workload=... or op=...");
|
||||
}
|
||||
@ -514,12 +517,13 @@ public class SimpleActivity implements Activity, ProgressCapable {
|
||||
throw new BasicError("There were no active statements with tag filter '"
|
||||
+ tagfilter + "', since all " + beforeFiltering.size()+ " were filtered out.");
|
||||
}
|
||||
// else {
|
||||
// if (this instanceof DefaultOpTemplateSupplier s) {
|
||||
// stmts = s.getDefaultTemplates(stmtsDocList);
|
||||
// Objects.requireNonNull(stmts);
|
||||
// }
|
||||
// }
|
||||
else {
|
||||
if (this instanceof SyntheticOpTemplateProvider sotp) {
|
||||
|
||||
stmts = sotp.getSyntheticOpTemplates(stmtsDocList, getActivityDef().getParams());
|
||||
Objects.requireNonNull(stmts);
|
||||
}
|
||||
}
|
||||
if (stmts.size()==0) {
|
||||
throw new BasicError("There were no active statements with tag filter '" + tagfilter + "'");
|
||||
}
|
||||
|
@ -18,11 +18,13 @@ package io.nosqlbench.engine.api.activityimpl.uniform;
|
||||
|
||||
import io.nosqlbench.engine.api.activityapi.planning.OpSequence;
|
||||
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.activityimpl.ActivityDef;
|
||||
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.decorators.SyntheticOpTemplateProvider;
|
||||
import io.nosqlbench.engine.api.activityimpl.uniform.flowtypes.Op;
|
||||
import io.nosqlbench.nb.api.config.standard.*;
|
||||
import io.nosqlbench.nb.api.errors.OpConfigError;
|
||||
@ -43,7 +45,7 @@ import java.util.function.Function;
|
||||
* @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
|
||||
*/
|
||||
public class StandardActivity<R extends Op, S> extends SimpleActivity {
|
||||
public class StandardActivity<R extends Op, S> extends SimpleActivity implements SyntheticOpTemplateProvider {
|
||||
private final static Logger logger = LogManager.getLogger("ACTIVITY");
|
||||
|
||||
private final DriverAdapter<R, S> adapter;
|
||||
@ -118,16 +120,15 @@ public class StandardActivity<R extends Op, S> extends SimpleActivity {
|
||||
NBConfiguration cfg = cfgModel.matchConfig(activityDef.getParams());
|
||||
NBReconfigurable.applyMatching(cfg,List.of(configurable));
|
||||
}
|
||||
//
|
||||
// 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();
|
||||
// }
|
||||
// }
|
||||
@Override
|
||||
public List<OpTemplate> getSyntheticOpTemplates(StmtsDocList stmtsDocList, Map<String,Object> cfg) {
|
||||
if (adapter instanceof SyntheticOpTemplateProvider sotp) {
|
||||
return sotp.getSyntheticOpTemplates(stmtsDocList, cfg);
|
||||
} else {
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user