grpc partial work

This commit is contained in:
Jonathan Shook 2021-05-13 12:57:09 -05:00
parent 12987713d0
commit 31873af0fd
16 changed files with 226 additions and 11 deletions

View File

@ -0,0 +1,24 @@
package io.nosqlbench.driver.cqld4.opdispensers;
import com.datastax.oss.driver.api.core.CqlSession;
import io.nosqlbench.driver.cqld4.Cqld4Op;
import io.nosqlbench.engine.api.activityconfig.yaml.OpTemplate;
import io.nosqlbench.engine.api.activityimpl.OpDispenser;
import io.nosqlbench.engine.api.templating.CommandTemplate;
import java.util.function.Function;
public class Cqld4BatchStatementDispenser implements Function<OpTemplate, OpDispenser<Cqld4Op>> {
private final CqlSession session;
private final CommandTemplate cmd;
public Cqld4BatchStatementDispenser(CqlSession session, CommandTemplate cmd) {
this.session = session;
this.cmd = cmd;
}
@Override
public OpDispenser<Cqld4Op> apply(OpTemplate opTemplate) {
return null;
}
}

41
driver-grpc/pom.xml Normal file
View File

@ -0,0 +1,41 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>mvn-defaults</artifactId>
<groupId>io.nosqlbench</groupId>
<version>4.15.45-SNAPSHOT</version>
<relativePath>../mvn-defaults</relativePath>
</parent>
<artifactId>driver-grpc</artifactId>
<packaging>jar</packaging>
<name>${project.artifactId}</name>
<description>
A gRPC nosqlbench ActivityType (AT) driver module
</description>
<dependencies>
<dependency>
<groupId>io.nosqlbench</groupId>
<artifactId>engine-api</artifactId>
<version>4.15.45-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.nosqlbench</groupId>
<artifactId>drivers-api</artifactId>
<version>4.15.45-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf-nano</artifactId>
<version>1.18.0</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,46 @@
package io.nosqlbench.driver.grpc;
import com.codahale.metrics.Timer;
import io.nosqlbench.engine.api.activityapi.planning.OpSequence;
import io.nosqlbench.engine.api.activityimpl.OpDispenser;
import io.nosqlbench.engine.api.activityimpl.uniform.StandardAction;
public class GrpcAction extends StandardAction {
private final int slot;
private final GrpcActivity activity;
private OpSequence<OpDispenser<GrpcOp>> sequencer;
public GrpcAction(int slot, GrpcActivity activity, OpSequence opsource) {
super(activity, opsource);
this.slot = slot;
this.activity = activity;
}
@Override
public void init() {
this.sequencer = activity.getSequencer();
}
@Override
public int runCycle(long cycle) {
GrpcOp op = null;
try (Timer.Context ctx = activity.getInstrumentation().getOrCreateBindTimer().time()) {
// Get the template instance from the sequence
OpDispenser<GrpcOp> opDispenser = sequencer.apply(cycle);
// Get an executable op from the template instance
op = opDispenser.apply(cycle);
}
int tries = activity.getMaxTries();
op.run();
return 0;
}
}

View File

@ -0,0 +1,4 @@
package io.nosqlbench.driver.grpc;
public interface GrpcOp extends Runnable {
}

View File

@ -0,0 +1,19 @@
package io.nosqlbench.driver.grpc;
import io.nosqlbench.driver.grpc.optypes.NullGrpcOp;
import io.nosqlbench.engine.api.activityconfig.yaml.OpTemplate;
import io.nosqlbench.engine.api.activityimpl.OpDispenser;
public class GrpcOpMapper implements OpDispenser<GrpcOp> {
private final OpTemplate opTemplate;
public GrpcOpMapper(OpTemplate opTemplate) {
this.opTemplate = opTemplate;
}
@Override
public GrpcOp apply(long value) {
return new NullGrpcOp();
}
}

View File

@ -0,0 +1,9 @@
package io.nosqlbench.driver.grpc.optypes;
import io.nosqlbench.driver.grpc.GrpcOp;
public class NullGrpcOp implements GrpcOp {
@Override
public void run() {
}
}

View File

@ -4,6 +4,7 @@ import java.net.http.HttpRequest;
import java.util.regex.Pattern;
public class HttpOp {
public final Pattern ok_status;
public final Pattern ok_body;
public final HttpRequest request;

View File

@ -10,7 +10,7 @@ import javax.management.remote.JMXConnector;
/**
* All JMX Operations should built on this base type.
*/
public abstract class JmxOp {
public abstract class JmxOp implements Runnable {
protected final static Logger logger = LogManager.getLogger(JmxOp.class);
@ -43,4 +43,8 @@ public abstract class JmxOp {
}
public abstract void execute();
public void run() {
execute();
}
}

View File

@ -44,7 +44,6 @@ public class MongoActivity extends SimpleActivity implements ActivityDefObserver
private MongoClient client;
private MongoDatabase mongoDatabase;
private boolean showQuery;
private int maxTries;
private OpSequence<ReadyMongoStatement> opSequence;
@ -84,9 +83,6 @@ public class MongoActivity extends SimpleActivity implements ActivityDefObserver
mongoDatabase = client.getDatabase(databaseName);
showQuery = activityDef.getParams().getOptionalBoolean("showquery")
.orElse(false);
maxTries = activityDef.getParams().getOptionalInteger("maxtries")
.orElse(10);
bindTimer = ActivityMetrics.timer(activityDef, "bind");
resultTimer = ActivityMetrics.timer(activityDef, "result");
resultSuccessTimer = ActivityMetrics.timer(activityDef, "result-success");
@ -155,7 +151,4 @@ public class MongoActivity extends SimpleActivity implements ActivityDefObserver
return showQuery;
}
protected int getMaxTries() {
return maxTries;
}
}

View File

@ -3,11 +3,10 @@ package io.nosqlbench.driver.pulsar.ops;
import io.nosqlbench.driver.pulsar.PulsarSpace;
import io.nosqlbench.engine.api.templating.CommandTemplate;
import java.util.Set;
import java.util.function.LongFunction;
/**
* This maps a set of specifier functions to a pulsar operation. The pulsar operation contains
* This maps a set of specifier functions to a pulsar operation. The result contains
* enough state to define a pulsar operation such that it can be executed, measured, and possibly
* retried if needed.
*

View File

@ -210,4 +210,6 @@ public interface Activity extends Comparable<Activity>, ActivityDefObserver, Pro
default Function<Throwable,String> getErrorNameMapper() {
return t -> t.getClass().getSimpleName();
}
int getMaxTries();
}

View File

@ -0,0 +1,20 @@
package io.nosqlbench.engine.api.activityimpl;
public class DiagRunnableOp implements Runnable {
public final String message;
public DiagRunnableOp(String message) {
this.message = message;
}
@Override
public void run() {
}
@Override
public String toString() {
return message;
}
}

View File

@ -0,0 +1,24 @@
package io.nosqlbench.engine.api.activityimpl;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import io.nosqlbench.engine.api.templating.CommandTemplate;
import java.util.Map;
public class DiagRunnableOpDispenser<O extends Runnable> implements OpDispenser<Runnable> {
private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
private final CommandTemplate cmdTpl;
public DiagRunnableOpDispenser(CommandTemplate commandTemplate) {
this.cmdTpl = commandTemplate;
}
@Override
public Runnable apply(long value) {
Map<String, String> command = cmdTpl.getCommand(value);
String body = gson.toJson(command);
return new DiagRunnableOp(body);
}
}

View File

@ -0,0 +1,16 @@
package io.nosqlbench.engine.api.activityimpl;
import io.nosqlbench.engine.api.activityconfig.yaml.OpTemplate;
import io.nosqlbench.engine.api.templating.CommandTemplate;
import java.util.function.Function;
public class DiagRunnableOpMapper implements Function<OpTemplate, OpDispenser<Runnable>> {
@Override
public OpDispenser<Runnable> apply(OpTemplate opTemplate) {
CommandTemplate commandTemplate = new CommandTemplate(opTemplate);
return new DiagRunnableOpDispenser(commandTemplate);
}
}

View File

@ -4,7 +4,6 @@ import com.codahale.metrics.Timer;
import io.nosqlbench.engine.api.activityapi.core.*;
import io.nosqlbench.engine.api.activityapi.cyclelog.filters.IntPredicateDispenser;
import io.nosqlbench.engine.api.activityapi.errorhandling.ErrorMetrics;
import io.nosqlbench.engine.api.activityapi.errorhandling.modular.ErrorHandler;
import io.nosqlbench.engine.api.activityapi.errorhandling.modular.NBErrorHandler;
import io.nosqlbench.engine.api.activityapi.input.Input;
import io.nosqlbench.engine.api.activityapi.input.InputDispenser;
@ -449,6 +448,7 @@ public class SimpleActivity implements Activity, ProgressCapable {
* @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<O>> createOpSequence(Function<OpTemplate, OpDispenser<O>> opinit) {
String tagfilter = activityDef.getParams().getOptionalString("tags").orElse("");
StrInterpolator interp = new StrInterpolator(activityDef);
@ -500,6 +500,17 @@ public class SimpleActivity implements Activity, ProgressCapable {
}
}
/**
* Activities with retryable operations (when specified with the retry error handler for some
* types of error), should allow the user to specify how many retries are allowed before
* giving up on the operation.
* @return The number of allowable retries
*/
@Override
public int getMaxTries() {
return getActivityDef().getParams().getOptionalInteger("maxtries").orElse(10);
}
}

View File

@ -50,6 +50,8 @@
<module>driver-jdbc</module>
<module>driver-cockroachdb</module>
<module>driver-pulsar</module>
<module>driver-grpc</module>
<module>driver-direct</module>
<!-- VIRTDATA MODULES -->