change all references of context to container

This commit is contained in:
Jonathan Shook
2023-12-07 09:40:40 -06:00
parent 2f34a6e44d
commit e1f9545abd
100 changed files with 412 additions and 475 deletions

View File

@@ -108,7 +108,7 @@ public interface Activity extends Comparable<Activity>, ActivityDefObserver, Pro
/**
* Set the cycle rate limiter for this activity. This method should only
* be used in a non-concurrent context. Otherwise, the supplier version
* be used non-concurrently. Otherwise, the supplier version
* {@link #getCycleRateLimiter(Supplier)} should be used.
* @param rateLimiter The cycle {@link RateLimiter} for this activity
*/
@@ -133,7 +133,7 @@ public interface Activity extends Comparable<Activity>, ActivityDefObserver, Pro
/**
* Set the stride rate limiter for this activity. This method should only
* be used in a non-concurrent context. Otherwise, the supplier version
* be used non-concurrently. Otherwise, the supplier version
* {@link #getStrideRateLimiter(Supplier)}} should be used.
* @param rateLimiter The stride {@link RateLimiter} for this activity.
*/

View File

@@ -56,7 +56,7 @@ public interface AsyncAction<D> extends Action {
* be started (according to the configured concurrency limits),
* then it can signal such by returning true from this method.
*
* @param opc The op context that holds state for this operation
* @param opc The op ctx that holds state for this operation
* @return true, if the action is ready immediately for another operation
*/
boolean enqueue(TrackedOp<D> opc);

View File

@@ -20,7 +20,7 @@ import com.codahale.metrics.Histogram;
import com.codahale.metrics.Timer;
import io.nosqlbench.adapters.api.activityimpl.OpDispenser;
import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.*;
import io.nosqlbench.adapters.api.evalcontext.CycleFunction;
import io.nosqlbench.adapters.api.evalctx.CycleFunction;
import io.nosqlbench.nb.api.engine.activityimpl.ActivityDef;
import io.nosqlbench.nb.api.errors.ResultVerificationError;
import io.nosqlbench.engine.api.activityapi.core.ActivityDefObserver;

View File

@@ -204,8 +204,8 @@ public class NBCLIScenarioPreprocessor {
buildingCmd.put("alias", "alias=" + WORKLOAD_SCENARIO_STEP);
}
if (!buildingCmd.containsKey("context")) {
buildingCmd.put("context","context="+scenarioName);
if (!buildingCmd.containsKey("container")) {
buildingCmd.put("container","container="+scenarioName);
}
if (!buildingCmd.containsKey("step")) {
buildingCmd.put("step","step="+stepName);

View File

@@ -21,15 +21,15 @@ import org.graalvm.polyglot.*;
public class GraalJsEvaluator<T> implements ExprEvaluator<T> {
private final Class<T> resultType;
private Context context;
private Context ctx;
private Source script;
public GraalJsEvaluator(Class<T> resultType) {
this.resultType = resultType;
}
private Context getContext() {
if (context == null) {
private Context getCtx() {
if (ctx == null) {
Context.Builder contextSettings = Context.newBuilder("js")
.allowHostAccess(HostAccess.ALL)
.allowNativeAccess(true)
@@ -43,14 +43,14 @@ public class GraalJsEvaluator<T> implements ExprEvaluator<T> {
.allowPolyglotAccess(PolyglotAccess.ALL)
.option("js.ecmascript-version", "2020")
.option("js.nashorn-compat", "true");
context = contextSettings.build();
ctx = contextSettings.build();
}
return context;
return ctx;
}
@Override
public T eval() {
Value result = getContext().eval(this.script);
Value result = getCtx().eval(this.script);
T asType = result.as(resultType);
return asType;
}
@@ -63,7 +63,7 @@ public class GraalJsEvaluator<T> implements ExprEvaluator<T> {
@Override
public ExprEvaluator<T> put(String varName, Object var) {
getContext().getBindings("js").putMember(varName, var);
getCtx().getBindings("js").putMember(varName, var);
return this;
}
}

View File

@@ -16,13 +16,11 @@
package io.nosqlbench.engine.cmdstream;
import io.nosqlbench.engine.core.lifecycle.session.CmdParser;
import io.nosqlbench.nb.api.errors.BasicError;
import jakarta.validation.constraints.NotNull;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import java.security.InvalidParameterException;
import java.util.*;
/**
@@ -44,8 +42,8 @@ public class Cmd {
return targetContextName;
}
public Cmd forTargetContext(String contextName, String stepName) {
return new Cmd(cmdType, cmdArgs, contextName, stepName);
public Cmd forContainer(String containerName, String stepName) {
return new Cmd(cmdType, cmdArgs, containerName, stepName);
}

View File

@@ -32,7 +32,7 @@ public enum CmdType {
await(CmdParam.of("activity")),
waitMillis(CmdParam.of("ms", Long::parseLong)),
fragment(CmdParam.ofFreeform("fragment")),
context(CmdParam.of("name")),
container(CmdParam.of("name")),
indirect(CmdParam.of("indirect"));
private final CmdParam<?>[] positional;

View File

@@ -16,7 +16,7 @@
package io.nosqlbench.engine.core.lifecycle.activity;
import io.nosqlbench.engine.core.lifecycle.scenario.context.ContextActivitiesController;
import io.nosqlbench.engine.core.lifecycle.scenario.container.ContainerActivitiesController;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -24,9 +24,9 @@ public class ActivitiesExceptionHandler implements Thread.UncaughtExceptionHandl
private static final Logger logger = LogManager.getLogger(ActivitiesExceptionHandler.class);
private final ContextActivitiesController controller;
private final ContainerActivitiesController controller;
public ActivitiesExceptionHandler(ContextActivitiesController controller) {
public ActivitiesExceptionHandler(ContainerActivitiesController controller) {
this.controller = controller;
logger.debug(() -> "Activities exception handler starting up for executor '" + this.controller + "'");
}

View File

@@ -20,9 +20,9 @@ import io.nosqlbench.engine.api.activityapi.core.RunState;
import io.nosqlbench.engine.api.activityapi.core.progress.ProgressMeterDisplay;
import io.nosqlbench.engine.api.activityapi.core.progress.StateCapable;
import io.nosqlbench.engine.api.metrics.IndicatorMode;
import io.nosqlbench.engine.core.lifecycle.scenario.container.ContainerActivitiesController;
import io.nosqlbench.nb.api.engine.metrics.PeriodicRunnable;
import io.nosqlbench.nb.api.engine.util.Unit;
import io.nosqlbench.engine.core.lifecycle.scenario.context.ContextActivitiesController;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -35,14 +35,14 @@ public class ActivitiesProgressIndicator implements Runnable {
private final static Logger logger = LogManager.getLogger("PROGRESS");
private final String indicatorSpec;
private final ContextActivitiesController sc;
private final ContainerActivitiesController sc;
private PeriodicRunnable<ActivitiesProgressIndicator> runnable;
private IndicatorMode indicatorMode = IndicatorMode.console;
private final Set<String> seen = new HashSet<>();
private long intervalMillis = 1L;
public ActivitiesProgressIndicator(ContextActivitiesController sc, String indicatorSpec) {
public ActivitiesProgressIndicator(ContainerActivitiesController sc, String indicatorSpec) {
this.sc = sc;
this.indicatorSpec = indicatorSpec;
start();

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.nosqlbench.engine.core.lifecycle.scenario.context;
package io.nosqlbench.engine.core.lifecycle.scenario.container;
import io.nosqlbench.nb.api.engine.activityimpl.ActivityDef;
import org.graalvm.polyglot.Value;
@@ -28,11 +28,11 @@ import java.util.stream.Collectors;
*/
public class ActivityBindings implements Bindings, ProxyObject {
private final ContextActivitiesController scenario;
private final ContainerActivitiesController scenario;
private final Map<String, Bindings> elementMap = new HashMap<String, Bindings>();
public ActivityBindings(ContextActivitiesController contextActivitiesController) {
this.scenario = contextActivitiesController;
public ActivityBindings(ContainerActivitiesController containerActivitiesController) {
this.scenario = containerActivitiesController;
}
@Override
@@ -41,7 +41,7 @@ public class ActivityBindings implements Bindings, ProxyObject {
}
@Override
public void putAll(Map<? extends String, ? extends Object> toMerge) {
public void putAll(Map<? extends String, ?> toMerge) {
throw new RuntimeException("ScenarioBindings do not allow putAll(...)");
}

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.nosqlbench.engine.core.lifecycle.scenario.context;
package io.nosqlbench.engine.core.lifecycle.scenario.container;
import io.nosqlbench.nb.api.engine.activityimpl.ActivityDef;
import io.nosqlbench.nb.api.engine.activityimpl.ParameterMap;
@@ -40,9 +40,9 @@ import java.util.stream.Collectors;
* A ScenarioController provides a way to start Activities,
* modify them while running, and forceStopMotors, pause or restart them.
*/
public class ContextActivitiesController extends NBBaseComponent {
public class ContainerActivitiesController extends NBBaseComponent {
private static final Logger logger = LogManager.getLogger(ContextActivitiesController.class);
private static final Logger logger = LogManager.getLogger(ContainerActivitiesController.class);
private static final Logger scenariologger = LogManager.getLogger("SCENARIO");
private final ActivityLoader activityLoader;
@@ -51,7 +51,7 @@ public class ContextActivitiesController extends NBBaseComponent {
private final ExecutorService executorService;
public ContextActivitiesController(NBComponent parent) {
public ContainerActivitiesController(NBComponent parent) {
super(parent);
this.activityLoader = new ActivityLoader();
ActivitiesExceptionHandler exceptionHandler = new ActivitiesExceptionHandler(this);

View File

@@ -1,4 +1,4 @@
package io.nosqlbench.engine.core.lifecycle.scenario.context;
package io.nosqlbench.engine.core.lifecycle.scenario.container;
/*
* Copyright (c) 2022 nosqlbench
@@ -24,7 +24,7 @@ import java.io.PrintWriter;
import java.io.Reader;
import java.util.Map;
public interface ContextBuilderFacets {
public interface ContainerBuilderFacets {
public interface ALL extends
WantsName,
WantsController,
@@ -41,7 +41,7 @@ public interface ContextBuilderFacets {
}
public interface WantsController extends WantsStdin, WantsIoType {
public WantsStdin controller(ContextActivitiesController controller);
public WantsStdin controller(ContainerActivitiesController controller);
}
@@ -82,7 +82,7 @@ public interface ContextBuilderFacets {
}
public interface CanBuild {
NBBufferedCommandContext build(NBComponent forComponent);
NBBufferedContainer build(NBComponent forComponent);
}
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.nosqlbench.engine.core.lifecycle.scenario.context;
package io.nosqlbench.engine.core.lifecycle.scenario.container;
import java.io.CharArrayWriter;
import java.io.IOException;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.nosqlbench.engine.core.lifecycle.scenario.context;
package io.nosqlbench.engine.core.lifecycle.scenario.container;
import java.io.PrintWriter;
import java.io.Writer;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.nosqlbench.engine.core.lifecycle.scenario.context;
package io.nosqlbench.engine.core.lifecycle.scenario.container;
import org.jetbrains.annotations.NotNull;

View File

@@ -14,14 +14,13 @@
* limitations under the License.
*/
package io.nosqlbench.engine.core.lifecycle.scenario.context;
package io.nosqlbench.engine.core.lifecycle.scenario.container;
import org.jetbrains.annotations.NotNull;
import java.io.CharArrayWriter;
import java.io.IOException;
import java.io.Writer;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class InterjectingCharArrayWriter extends CharArrayWriter {

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.nosqlbench.engine.core.lifecycle.scenario.context;
package io.nosqlbench.engine.core.lifecycle.scenario.container;
import io.nosqlbench.engine.core.annotation.Annotators;
import io.nosqlbench.engine.core.lifecycle.activity.ActivitiesProgressIndicator;
@@ -38,12 +38,12 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
public class NBBufferedCommandContext extends NBBaseComponent implements NBCommandContext {
public class NBBufferedContainer extends NBBaseComponent implements NBContainer {
private final static Logger logger = LogManager.getLogger(NBBufferedCommandContext.class);
private final ContextActivitiesController controller;
private final static Logger logger = LogManager.getLogger(NBBufferedContainer.class);
private final ContainerActivitiesController controller;
private final ActivitiesProgressIndicator activitiesProgressIndicator;
private ContextShutdownHook contextShutdownHook;
private ContextShutdownHook containerShutdownHook;
private long startedAtMillis;
private Exception error;
private long endedAtMillis;
@@ -60,10 +60,10 @@ public class NBBufferedCommandContext extends NBBaseComponent implements NBComma
private DiagWriter stderrBuffer;
private DiagReader stdinBuffer;
public NBBufferedCommandContext(NBComponent parent, String name, IOType ioTypes) {
super(parent, NBLabels.forKV("context",name));
public NBBufferedContainer(NBComponent parent, String name, IOType ioTypes) {
super(parent, NBLabels.forKV("container",name));
this.iotype = ioTypes;
this.controller = new ContextActivitiesController(this);
this.controller = new ContainerActivitiesController(this);
switch (iotype) {
case traced:
@@ -83,9 +83,9 @@ public class NBBufferedCommandContext extends NBBaseComponent implements NBComma
break;
}
this.contextShutdownHook = new ContextShutdownHook(this);
this.containerShutdownHook = new ContextShutdownHook(this);
Runtime.getRuntime().addShutdownHook(this.contextShutdownHook);
Runtime.getRuntime().addShutdownHook(this.containerShutdownHook);
Annotators.recordAnnotation(
Annotation.newBuilder()
@@ -100,7 +100,7 @@ public class NBBufferedCommandContext extends NBBaseComponent implements NBComma
@Override
public ContextActivitiesController controller() {
public ContainerActivitiesController controller() {
return controller;
}
@@ -123,13 +123,13 @@ public class NBBufferedCommandContext extends NBBaseComponent implements NBComma
return this.stdoutBuffer.getTimedLog() + this.stderrBuffer.getTimedLog();
}
public NBCommandContext asFixtures() {
return (NBCommandContext) this;
public NBContainer asFixtures() {
return (NBContainer) this;
}
public static ContextBuilderFacets.WantsName builder() {
return new NBScenarioContextBuilder();
public static ContainerBuilderFacets.WantsName builder() {
return new NBScenarioContainerBuilder();
}
@Override
@@ -168,11 +168,11 @@ public class NBBufferedCommandContext extends NBBaseComponent implements NBComma
// ignore
// } else {
//
// RuntimeException error = new RuntimeException("Unrecognizable type to set context vars with:" + object.getClass().getCanonicalName());
// RuntimeException error = new RuntimeException("Unrecognizable type to set container vars with:" + object.getClass().getCanonicalName());
// logger.error(error);
//// throw new RuntimeException("Unrecognizable type to set context vars with:" + object.getClass().getCanonicalName());
//// throw new RuntimeException("Unrecognizable type to set container vars with:" + object.getClass().getCanonicalName());
} else {
logger.debug("no object was provided to set the context result");
logger.debug("no object was provided to set the container result");
}
return safeCmdResult;
@@ -180,7 +180,7 @@ public class NBBufferedCommandContext extends NBBaseComponent implements NBComma
@Override
public void doShutdown() {
NBCommandContext.super.doShutdown();
NBContainer.super.doShutdown();
}
@Override
@@ -190,11 +190,11 @@ public class NBBufferedCommandContext extends NBBaseComponent implements NBComma
@Override
public void beforeDetach() {
// TODO, shutdown hooks need to be moved to context
Runtime.getRuntime().removeShutdownHook(this.contextShutdownHook);
final var retiringScenarioShutdownHook = this.contextShutdownHook;
this.contextShutdownHook = null;
// TODO, shutdown hooks need to be moved to container
Runtime.getRuntime().removeShutdownHook(this.containerShutdownHook);
final var retiringScenarioShutdownHook = this.containerShutdownHook;
this.containerShutdownHook = null;
retiringScenarioShutdownHook.run();
this.logger.debug("removing context shutdown hook");
this.logger.debug("removing container shutdown hook");
}
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package io.nosqlbench.engine.core.lifecycle.scenario.context;
package io.nosqlbench.engine.core.lifecycle.scenario.container;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

View File

@@ -14,27 +14,25 @@
* limitations under the License.
*/
package io.nosqlbench.engine.core.lifecycle.scenario.context;
package io.nosqlbench.engine.core.lifecycle.scenario.container;
import io.nosqlbench.engine.core.lifecycle.scenario.execution.NBCommandResult;
import io.nosqlbench.engine.core.lifecycle.scenario.execution.NBInvokableCommand;
import io.nosqlbench.nb.api.components.NBComponent;
import os.CommandResult;
import java.io.PrintWriter;
import java.io.Reader;
import java.util.Map;
import java.util.function.BiFunction;
import java.util.function.Function;
public interface NBCommandContext extends NBComponent, BiFunction<NBInvokableCommand,NBCommandParams, NBCommandResult> {
public interface NBContainer extends NBComponent, BiFunction<NBInvokableCommand,NBCommandParams, NBCommandResult> {
// ScenarioPhaseParams params();
ContextActivitiesController controller();
ContainerActivitiesController controller();
PrintWriter out();
PrintWriter err();
Reader in();
public static ContextBuilderFacets.WantsName builder() {
return new NBScenarioContextBuilder();
public static ContainerBuilderFacets.WantsName builder() {
return new NBScenarioContainerBuilder();
}
default void doShutdown() {

View File

@@ -1,4 +1,4 @@
package io.nosqlbench.engine.core.lifecycle.scenario.context;
package io.nosqlbench.engine.core.lifecycle.scenario.container;
/*
* Copyright (c) 2022 nosqlbench
@@ -25,74 +25,74 @@ import java.io.PrintWriter;
import java.io.Reader;
import java.util.Map;
public class NBScenarioContextBuilder implements ContextBuilderFacets.ALL {
public class NBScenarioContainerBuilder implements ContainerBuilderFacets.ALL {
private Map<String,String> params = Map.of();
private ContextActivitiesController controller;
private ContainerActivitiesController controller;
private PrintWriter out = new PrintWriter(System.out);
private PrintWriter err = new PrintWriter(System.err);
private Reader in = new InputStreamReader(System.in);
private NBBufferedCommandContext.IOType iotype = NBBufferedCommandContext.IOType.traced;
private String contextName;
private NBBufferedContainer.IOType iotype = NBBufferedContainer.IOType.traced;
private String containerName;
public NBScenarioContextBuilder() {}
public NBBufferedCommandContext build(NBComponent contextParentComponent) {
return new NBBufferedCommandContext(contextParentComponent,contextName,iotype);
public NBScenarioContainerBuilder() {}
public NBBufferedContainer build(NBComponent contextParentComponent) {
return new NBBufferedContainer(contextParentComponent, containerName,iotype);
}
@Override
public NBScenarioContextBuilder controller(ContextActivitiesController controller) {
public NBScenarioContainerBuilder controller(ContainerActivitiesController controller) {
this.controller = controller;
return this;
}
@Override
public NBScenarioContextBuilder out(PrintWriter out) {
public NBScenarioContainerBuilder out(PrintWriter out) {
this.out = out;
return this;
}
@Override
public ContextBuilderFacets.WantsParams err(PrintWriter err) {
public ContainerBuilderFacets.WantsParams err(PrintWriter err) {
this.err = err;
return this;
}
@Override
public NBScenarioContextBuilder in(Reader in) {
public NBScenarioContainerBuilder in(Reader in) {
this.in = in;
return this;
}
@Override
public NBScenarioContextBuilder params(Map<String, String> params) {
public NBScenarioContainerBuilder params(Map<String, String> params) {
this.params=params;
return this;
}
@Override
public ContextBuilderFacets.WantsParams virtualIO() {
this.iotype= NBBufferedCommandContext.IOType.virtual;
public ContainerBuilderFacets.WantsParams virtualIO() {
this.iotype= NBBufferedContainer.IOType.virtual;
return this;
}
@Override
public ContextBuilderFacets.WantsParams connectedIO() {
this.iotype = NBBufferedCommandContext.IOType.connected;
public ContainerBuilderFacets.WantsParams connectedIO() {
this.iotype = NBBufferedContainer.IOType.connected;
return this;
}
@Override
public ContextBuilderFacets.WantsParams tracedIO() {
this.iotype= NBBufferedCommandContext.IOType.traced;
public ContainerBuilderFacets.WantsParams tracedIO() {
this.iotype= NBBufferedContainer.IOType.traced;
return this;
}
@Override
public ContextBuilderFacets.WantsController name(String contextName) {
this.contextName = contextName;
public ContainerBuilderFacets.WantsController name(String contextName) {
this.containerName = contextName;
return this;
}
}

View File

@@ -13,11 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.nosqlbench.engine.core.lifecycle.scenario.context;
import io.nosqlbench.engine.core.lifecycle.scenario.context.DiagReader;
import io.nosqlbench.engine.core.lifecycle.scenario.context.DiagWriter;
import io.nosqlbench.engine.core.lifecycle.scenario.context.InterjectingCharArrayWriter;
package io.nosqlbench.engine.core.lifecycle.scenario.container;
import javax.script.SimpleScriptContext;
import java.io.Reader;

View File

@@ -16,19 +16,19 @@
package io.nosqlbench.engine.core.lifecycle.scenario.execution;
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBCommandContext;
import io.nosqlbench.engine.core.lifecycle.scenario.container.NBContainer;
public class ContextShutdownHook extends Thread {
private final NBCommandContext context;
private final NBContainer container;
public ContextShutdownHook(NBCommandContext context) {
this.context = context;
public ContextShutdownHook(NBContainer container) {
this.container = container;
}
@Override
public void run() {
context.doShutdown();
container.doShutdown();
}
}

View File

@@ -16,16 +16,10 @@
package io.nosqlbench.engine.core.lifecycle.scenario.execution;
import io.nosqlbench.nb.api.annotations.Annotation;
import io.nosqlbench.nb.api.annotations.Layer;
import io.nosqlbench.nb.api.labels.NBLabels;
import io.nosqlbench.nb.api.components.NBComponent;
import io.nosqlbench.nb.api.components.NBComponentErrorHandler;
import io.nosqlbench.engine.core.annotation.Annotators;
import io.nosqlbench.engine.core.lifecycle.activity.ActivitiesProgressIndicator;
import io.nosqlbench.engine.core.lifecycle.scenario.context.ContextActivitiesController;
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBBufferedCommandContext;
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBCommandParams;
import io.nosqlbench.engine.core.lifecycle.scenario.container.ContainerActivitiesController;
import io.nosqlbench.engine.core.lifecycle.scenario.container.NBBufferedContainer;
import io.nosqlbench.engine.core.lifecycle.scenario.container.NBCommandParams;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -37,12 +31,12 @@ public abstract class NBBaseCommand extends NBInvokableCommand {
private final String targetScenario;
protected Logger logger = LogManager.getLogger("COMMAND");
public NBBaseCommand(NBBufferedCommandContext parentComponent, String stepName, String targetScenario) {
public NBBaseCommand(NBBufferedContainer parentComponent, String stepName, String targetScenario) {
super(parentComponent, NBLabels.forKV("step", stepName));
this.targetScenario = targetScenario;
}
public NBBaseCommand(NBBufferedCommandContext parentComponent, String commandLabel) {
public NBBaseCommand(NBBufferedContainer parentComponent, String commandLabel) {
this(parentComponent, commandLabel, "_testing_");
}
@@ -55,7 +49,7 @@ public abstract class NBBaseCommand extends NBInvokableCommand {
}
@Override
public final Object apply(NBBufferedCommandContext sctx, NBCommandParams params) {
public final Object apply(NBBufferedContainer sctx, NBCommandParams params) {
return invoke(params, sctx.out(), sctx.err(), sctx.in(), sctx.controller());
}
@@ -69,7 +63,7 @@ public abstract class NBBaseCommand extends NBInvokableCommand {
PrintWriter stdout,
PrintWriter stderr,
Reader stdin,
ContextActivitiesController controller
ContainerActivitiesController controller
);

View File

@@ -16,7 +16,7 @@
package io.nosqlbench.engine.core.lifecycle.scenario.execution;
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBBufferedCommandContext;
import io.nosqlbench.engine.core.lifecycle.scenario.container.NBBufferedContainer;
import io.nosqlbench.nb.api.components.NBComponent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -37,7 +37,7 @@ public abstract class NBCommandInfo {
public NBInvokableCommand create(NBComponent parent, String cmdName, String ctxName) {
Constructor<? extends NBInvokableCommand> cmdCtor;
try {
cmdCtor = getType().getConstructor(NBBufferedCommandContext.class, String.class, String.class);
cmdCtor = getType().getConstructor(NBBufferedContainer.class, String.class, String.class);
return cmdCtor.newInstance(parent, cmdName, ctxName);
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException e) {
throw new RuntimeException("Unable to instantiate command via ctor(parent,name,ctx): " + e,e);

View File

@@ -17,7 +17,7 @@
package io.nosqlbench.engine.core.lifecycle.scenario.execution;
import io.nosqlbench.engine.core.lifecycle.ExecutionResult;
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBBufferedCommandContext;
import io.nosqlbench.engine.core.lifecycle.scenario.container.NBBufferedContainer;
import java.util.function.Supplier;
@@ -25,11 +25,11 @@ public class NBCommandResult implements Supplier<ExecutionResult> {
private final long startedAt;
private final long endedAt;
private final Exception exception;
private final NBBufferedCommandContext fixtures;
private final NBBufferedContainer fixtures;
private Object resultObject;
public NBCommandResult(NBBufferedCommandContext fixtures, long start, long end, Exception exception) {
public NBCommandResult(NBBufferedContainer fixtures, long start, long end, Exception exception) {
this.fixtures = fixtures;
this.startedAt=start;
this.endedAt=end;

View File

@@ -16,35 +16,33 @@
package io.nosqlbench.engine.core.lifecycle.scenario.execution;
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBBufferedCommandContext;
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBCommandParams;
import io.nosqlbench.engine.core.lifecycle.scenario.container.NBBufferedContainer;
import io.nosqlbench.engine.core.lifecycle.scenario.container.NBCommandParams;
import io.nosqlbench.nb.api.components.NBBaseComponent;
import io.nosqlbench.nb.api.components.NBComponent;
import io.nosqlbench.nb.api.labels.NBLabels;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Objects;
import java.util.function.BiFunction;
public abstract class NBInvokableCommand extends NBBaseComponent implements BiFunction<NBBufferedCommandContext, NBCommandParams, Object> {
public abstract class NBInvokableCommand extends NBBaseComponent implements BiFunction<NBBufferedContainer, NBCommandParams, Object> {
private static final Logger logger = LogManager.getLogger(NBInvokableCommand.class);
public NBInvokableCommand(NBBufferedCommandContext parentComponent, NBLabels componentSpecificLabelsOnly) {
public NBInvokableCommand(NBBufferedContainer parentComponent, NBLabels componentSpecificLabelsOnly) {
super(parentComponent, componentSpecificLabelsOnly);
}
@Override
public abstract Object apply(NBBufferedCommandContext nbBufferedCommandContext, NBCommandParams nbCommandParams);
public abstract Object apply(NBBufferedContainer nbBufferedContainer, NBCommandParams nbCommandParams);
public NBCommandResult invokeSafe(NBBufferedCommandContext context, NBCommandParams params) {
public NBCommandResult invokeSafe(NBBufferedContainer container, NBCommandParams params) {
Object resultObject = null;
Exception exception = null;
long startAt = System.currentTimeMillis();
NBCommandResult result = null;
try {
logger.debug("invoking command: " + this);
resultObject=apply(context, params);
resultObject=apply(container, params);
logger.debug("cmd produced: " + (resultObject==null ? "NULL" : resultObject.toString()));
} catch (Exception e) {
exception = e;
@@ -52,7 +50,7 @@ public abstract class NBInvokableCommand extends NBBaseComponent implements BiFu
exception.printStackTrace(System.out);
} finally {
long endAt = System.currentTimeMillis();
result = new NBCommandResult(context, startAt, endAt, exception);
result = new NBCommandResult(container, startAt, endAt, exception);
if (resultObject!=null) {
result.setResultObject(resultObject);
}

View File

@@ -16,19 +16,17 @@
package io.nosqlbench.engine.core.lifecycle.scenario.script;
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBCommandContext;
import javax.script.SimpleScriptContext;
import java.io.Reader;
import java.io.Writer;
public class BufferedScriptContext extends SimpleScriptContext {
public class BufferedScriptCtx extends SimpleScriptContext {
Reader reader;
Writer writer;
Writer errorWriter;
public BufferedScriptContext(Writer writer, Writer errorWriter,Reader reader) {
public BufferedScriptCtx(Writer writer, Writer errorWriter, Reader reader) {
this.writer = writer;
this.errorWriter = errorWriter;
this.reader = reader;

View File

@@ -18,12 +18,12 @@ package io.nosqlbench.engine.core.lifecycle.scenario.script;
import com.oracle.truffle.js.scriptengine.GraalJSScriptEngine;
import io.nosqlbench.engine.cmdstream.BasicScriptBuffer;
import io.nosqlbench.engine.cmdstream.Cmd;
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBBufferedCommandContext;
import io.nosqlbench.engine.core.lifecycle.scenario.container.ContainerActivitiesController;
import io.nosqlbench.engine.core.lifecycle.scenario.container.NBBufferedContainer;
import io.nosqlbench.engine.core.lifecycle.scenario.execution.NBBaseCommand;
import io.nosqlbench.engine.core.lifecycle.ExecutionMetricsResult;
import io.nosqlbench.engine.core.lifecycle.activity.ActivitiesProgressIndicator;
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBCommandParams;
import io.nosqlbench.engine.core.lifecycle.scenario.context.ContextActivitiesController;
import io.nosqlbench.engine.core.lifecycle.scenario.container.NBCommandParams;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Engine.Builder;
import org.graalvm.polyglot.EnvironmentAccess;
@@ -43,7 +43,7 @@ public class NBScriptedCommand extends NBBaseCommand {
private Exception error;
private ExecutionMetricsResult result;
private BufferedScriptContext context;
private BufferedScriptCtx ctx;
private GraalJSScriptEngine _engine;
public Optional<ExecutionMetricsResult> getResultIfComplete() {
@@ -77,7 +77,7 @@ public class NBScriptedCommand extends NBBaseCommand {
}
public NBScriptedCommand(
NBBufferedCommandContext parentComponent,
NBBufferedContainer parentComponent,
String phaseName,
String targetScenario
) {
@@ -87,7 +87,7 @@ public class NBScriptedCommand extends NBBaseCommand {
this.buffer = new BasicScriptBuffer();
}
public static NBScriptedCommand ofScripted(String name, Map<String, String> params, NBBufferedCommandContext parent, Invocation invocation) {
public static NBScriptedCommand ofScripted(String name, Map<String, String> params, NBBufferedContainer parent, Invocation invocation) {
return new NBScriptedCommand(parent, name, "default");
}
public NBScriptedCommand add(Cmd... cmds) {
@@ -118,10 +118,10 @@ public class NBScriptedCommand extends NBBaseCommand {
// return this;
// }
private BufferedScriptContext initializeScriptContext(PrintWriter stdout, PrintWriter stderr, Reader stdin, ContextActivitiesController controller) {
BufferedScriptContext ctx = new BufferedScriptContext(stdout, stderr, stdin);
private BufferedScriptCtx initializeScriptContext(PrintWriter stdout, PrintWriter stderr, Reader stdin, ContainerActivitiesController controller) {
BufferedScriptCtx ctx = new BufferedScriptCtx(stdout, stderr, stdin);
ctx.getBindings(ScriptContext.ENGINE_SCOPE).put("this", this);
ctx.getBindings(ScriptContext.ENGINE_SCOPE).put("context", context);
ctx.getBindings(ScriptContext.ENGINE_SCOPE).put("container", this.ctx);
ctx.getBindings(ScriptContext.ENGINE_SCOPE).put("controller", controller);
ctx.getBindings(ScriptContext.ENGINE_SCOPE).put("stdout", stdout);
ctx.getBindings(ScriptContext.ENGINE_SCOPE).put("stderr", stderr);
@@ -155,13 +155,13 @@ public class NBScriptedCommand extends NBBaseCommand {
}
@Override
public Object invoke(NBCommandParams params, PrintWriter stdout, PrintWriter stderr, Reader stdin, ContextActivitiesController controller) {
public Object invoke(NBCommandParams params, PrintWriter stdout, PrintWriter stderr, Reader stdin, ContainerActivitiesController controller) {
try {
this.logger.debug("Initializing scripting engine for {}.", phaseName);
GraalJSScriptEngine engine = this.initializeScriptingEngine();
this.context = this.initializeScriptContext(stdout, stderr, stdin, controller);
this.ctx = this.initializeScriptContext(stdout, stderr, stdin, controller);
this.logger.debug("Running control script for {}.", phaseName);
engine.setContext(context);
engine.setContext(ctx);
engine.getContext().getBindings(ScriptContext.ENGINE_SCOPE).put("params", params);
Object resultObject = null;

View File

@@ -15,12 +15,12 @@
*/
package io.nosqlbench.engine.core.lifecycle.scenario.script;
import io.nosqlbench.engine.core.lifecycle.scenario.context.ScriptEnvBuffer;
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBCommandContext;
import io.nosqlbench.engine.core.lifecycle.scenario.container.ScriptEnvBuffer;
import io.nosqlbench.engine.core.lifecycle.scenario.container.NBContainer;
public class ScenarioScriptShell extends ScriptEnvBuffer {
public ScenarioScriptShell(NBCommandContext fixtures) {
public ScenarioScriptShell(NBContainer fixtures) {
}
@Override

View File

@@ -16,8 +16,8 @@
package io.nosqlbench.engine.core.lifecycle.scenario.script.bindings;
import io.nosqlbench.engine.core.lifecycle.scenario.container.ContainerActivitiesController;
import io.nosqlbench.nb.api.engine.activityimpl.ActivityDef;
import io.nosqlbench.engine.core.lifecycle.scenario.context.ContextActivitiesController;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.graalvm.polyglot.Value;
@@ -29,9 +29,9 @@ public class PolyglotScenarioController {
private static final Logger logger = LogManager.getLogger("SCENARIO/POLYGLOT");
private final ContextActivitiesController controller;
private final ContainerActivitiesController controller;
public PolyglotScenarioController(ContextActivitiesController inner) {
public PolyglotScenarioController(ContainerActivitiesController inner) {
this.controller = inner;
}

View File

@@ -19,8 +19,7 @@ package io.nosqlbench.engine.core.lifecycle.session;
import io.nosqlbench.engine.cmdstream.Cmd;
import io.nosqlbench.engine.cmdstream.CmdArg;
import io.nosqlbench.engine.cmdstream.CmdParam;
import io.nosqlbench.engine.cmdstream.CmdType;
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBBufferedCommandContext;
import io.nosqlbench.engine.core.lifecycle.scenario.container.NBBufferedContainer;
import io.nosqlbench.engine.core.lifecycle.scenario.execution.NBInvokableCommand;
import io.nosqlbench.engine.core.lifecycle.scenario.script.NBScriptedCommand;
import io.nosqlbench.nb.annotations.Service;
@@ -29,14 +28,13 @@ import io.nosqlbench.nb.api.nbio.NBIO;
import java.nio.file.Path;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@Service(value = NBInvokableResolver.class, selector = "autojs")
public class NBAutoScriptResolver implements NBInvokableResolver {
@Override
public NBInvokableCommand resolve(Cmd cmd, NBBufferedCommandContext parent, String phaseName) {
public NBInvokableCommand resolve(Cmd cmd, NBBufferedContainer parent, String phaseName) {
Optional<Content<?>> scriptfile = NBIO.local()
.searchPrefixes("scripts/auto")

View File

@@ -17,9 +17,9 @@
package io.nosqlbench.engine.core.lifecycle.session;
import io.nosqlbench.engine.cmdstream.*;
import io.nosqlbench.engine.core.lifecycle.scenario.container.NBBufferedContainer;
import io.nosqlbench.engine.core.lifecycle.scenario.execution.NBInvokableCommand;
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBBufferedCommandContext;
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBCommandParams;
import io.nosqlbench.engine.core.lifecycle.scenario.container.NBCommandParams;
import io.nosqlbench.nb.api.errors.BasicError;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -31,10 +31,10 @@ public class NBCommandAssembly {
private final static Logger logger = LogManager.getLogger(NBCommandAssembly.class);
public static record CommandInvocation(NBInvokableCommand command, NBCommandParams params, String contextName) {
public static record CommandInvocation(NBInvokableCommand command, NBCommandParams params, String containerName) {
}
public static List<CommandInvocation> assemble(List<Cmd> cmds, Function<String, NBBufferedCommandContext> ctxprovider) {
public static List<CommandInvocation> assemble(List<Cmd> cmds, Function<String, NBBufferedContainer> ctxprovider) {
List<Cmd> mappedCmds = tagCommandsWithContext(cmds);
List<CommandInvocation> invocations = prepareMappedPhases(mappedCmds, ctxprovider);
return invocations;
@@ -42,27 +42,27 @@ public class NBCommandAssembly {
private static List<Cmd> tagCommandsWithContext(List<Cmd> cmds) {
LinkedList<Cmd> tagged = new LinkedList<>();
String contextName = Cmd.DEFAULT_TARGET_CONTEXT;
String containerName = Cmd.DEFAULT_TARGET_CONTEXT;
for (Cmd cmd : cmds) {
if (cmd.getArgs().containsKey("context")) {
String ctx = cmd.getArgs().remove("context").getValue();
if (cmd.getArgs().containsKey("container")) {
String ctx = cmd.getArgs().remove("container").getValue();
String step = cmd.getArgs().containsKey("step") ? cmd.getArgs().remove("step").getValue() : "no-step";
tagged.add(cmd.forTargetContext(ctx, step));
} else if (cmd.getCmdType() == CmdType.context) {
contextName = cmd.getArgValue("context_name");
if (contextName.equals(Cmd.DEFAULT_TARGET_CONTEXT)) {
tagged.add(cmd.forContainer(ctx, step));
} else if (cmd.getCmdType() == CmdType.container) {
containerName = cmd.getArgValue("container");
if (containerName.equals(Cmd.DEFAULT_TARGET_CONTEXT)) {
logger.warn("You are explicitly setting the scenario name to " + Cmd.DEFAULT_TARGET_CONTEXT + "'. This is likely an error. " +
"This is the default scenario name, and if you are using different scenario names you should pick something that is different and specific.");
}
} else {
tagged.add(cmd.forTargetContext(contextName, null));
tagged.add(cmd.forContainer(containerName, null));
}
}
return new ArrayList<>(tagged);
}
private static List<CommandInvocation> prepareMappedPhases(List<Cmd> mappedCmds, Function<String, NBBufferedCommandContext> ctxProvider) {
private static List<CommandInvocation> prepareMappedPhases(List<Cmd> mappedCmds, Function<String, NBBufferedContainer> ctxProvider) {
List<CommandInvocation> parameterizedInvocations = new ArrayList<>();
NBCoreInvokableResolver core_resolver = new NBCoreInvokableResolver();
String basename = "phase_";
@@ -72,7 +72,7 @@ public class NBCommandAssembly {
String phaseName = basename + count;
NBCommandParams params = switch (cmd.getCmdType()) {
case indirect, java, context -> NBCommandParams.of(cmd.getArgMap());
case indirect, java, container -> NBCommandParams.of(cmd.getArgMap());
default -> NBCommandParams.of(Map.of());
};
@@ -81,8 +81,8 @@ public class NBCommandAssembly {
if (command==null) {
throw new BasicError("Found zero commands for spec;" + cmd);
}
String contextName = cmd.getTargetContext();
parameterizedInvocations.add(new CommandInvocation(command, params, contextName));
String containerName = cmd.getTargetContext();
parameterizedInvocations.add(new CommandInvocation(command, params, containerName));
}
return parameterizedInvocations;
}

View File

@@ -16,9 +16,9 @@
package io.nosqlbench.engine.core.lifecycle.session;
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBBufferedCommandContext;
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBCommandContext;
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBCommandParams;
import io.nosqlbench.engine.core.lifecycle.scenario.container.NBBufferedContainer;
import io.nosqlbench.engine.core.lifecycle.scenario.container.NBContainer;
import io.nosqlbench.engine.core.lifecycle.scenario.container.NBCommandParams;
import io.nosqlbench.engine.core.lifecycle.scenario.execution.NBCommandResult;
import io.nosqlbench.engine.core.lifecycle.scenario.execution.NBInvokableCommand;
import io.nosqlbench.nb.api.config.standard.TestComponent;
@@ -26,7 +26,6 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Map;
import java.util.Objects;
public class NBCommandInvoker {
private final static Logger logger = LogManager.getLogger(NBCommandInvoker.class);
@@ -35,15 +34,15 @@ public class NBCommandInvoker {
return invoke(createContext(),command,params);
}
public static NBCommandResult invoke(NBBufferedCommandContext context, NBInvokableCommand command) {
return invoke(context, command, NBCommandParams.of(Map.of()));
public static NBCommandResult invoke(NBBufferedContainer container, NBInvokableCommand command) {
return invoke(container, command, NBCommandParams.of(Map.of()));
}
private static NBBufferedCommandContext createContext() {
return NBCommandContext.builder().name("testing").build(TestComponent.EMPTY_COMPONENT);
private static NBBufferedContainer createContext() {
return NBContainer.builder().name("testing").build(TestComponent.EMPTY_COMPONENT);
}
public static NBCommandResult invoke(NBBufferedCommandContext context, NBInvokableCommand command, NBCommandParams params) {
return command.invokeSafe(context,params);
public static NBCommandResult invoke(NBBufferedContainer container, NBInvokableCommand command, NBCommandParams params) {
return command.invokeSafe(container,params);
}
}

View File

@@ -17,11 +17,9 @@
package io.nosqlbench.engine.core.lifecycle.session;
import io.nosqlbench.engine.cmdstream.Cmd;
import io.nosqlbench.engine.cmdstream.CmdType;
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBBufferedCommandContext;
import io.nosqlbench.engine.core.lifecycle.scenario.container.NBBufferedContainer;
import io.nosqlbench.engine.core.lifecycle.scenario.execution.NBInvokableCommand;
import io.nosqlbench.nb.annotations.Service;
import io.nosqlbench.nb.api.components.NBComponent;
import java.util.*;
@@ -35,7 +33,7 @@ public class NBCoreInvokableResolver implements NBInvokableResolver {
private SequencedMap<String,NBInvokableResolver> resolvers = new LinkedHashMap<>();
@Override
public NBInvokableCommand resolve(Cmd cmd, NBBufferedCommandContext parent, String phaseName) {
public NBInvokableCommand resolve(Cmd cmd, NBBufferedContainer parent, String phaseName) {
for (NBInvokableResolver resolver : getResolvers().values()) {
NBInvokableCommand loadedCommand = resolver.resolve(cmd, parent, phaseName);
if (loadedCommand!=null) {

View File

@@ -17,12 +17,10 @@
package io.nosqlbench.engine.core.lifecycle.session;
import io.nosqlbench.engine.cmdstream.Cmd;
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBBufferedCommandContext;
import io.nosqlbench.engine.core.lifecycle.scenario.container.NBBufferedContainer;
import io.nosqlbench.engine.core.lifecycle.scenario.execution.NBInvokableCommand;
import java.util.List;
public interface NBInvokableResolver {
NBInvokableCommand resolve(Cmd cmd, NBBufferedCommandContext parent, String phaseName);
NBInvokableCommand resolve(Cmd cmd, NBBufferedContainer parent, String phaseName);
}

View File

@@ -16,19 +16,16 @@
package io.nosqlbench.engine.core.lifecycle.session;
import io.nosqlbench.engine.cmdstream.BasicScriptBuffer;
import io.nosqlbench.engine.cmdstream.Cmd;
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBBufferedCommandContext;
import io.nosqlbench.engine.core.lifecycle.scenario.container.NBBufferedContainer;
import io.nosqlbench.engine.core.lifecycle.scenario.execution.NBInvokableCommand;
import io.nosqlbench.engine.core.lifecycle.scenario.script.NBScriptedCommand;
import io.nosqlbench.nb.annotations.Service;
import java.util.List;
@Service(value = NBInvokableResolver.class, selector = "js")
public class NBScriptCommandResolver implements NBInvokableResolver {
@Override
public NBInvokableCommand resolve(Cmd cmd, NBBufferedCommandContext parent, String phaseName) {
public NBInvokableCommand resolve(Cmd cmd, NBBufferedContainer parent, String phaseName) {
return switch (cmd.getCmdType()) {
case run, await, forceStop, stop, start, waitMillis, fragment, script->
new NBScriptedCommand(parent, phaseName, cmd.getTargetContext()).add(cmd);

View File

@@ -26,8 +26,8 @@ import io.nosqlbench.nb.api.components.decorators.NBTokenWords;
import io.nosqlbench.engine.cmdstream.Cmd;
import io.nosqlbench.engine.core.clientload.*;
import io.nosqlbench.engine.core.lifecycle.ExecutionResult;
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBBufferedCommandContext;
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBCommandContext;
import io.nosqlbench.engine.core.lifecycle.scenario.container.NBBufferedContainer;
import io.nosqlbench.engine.core.lifecycle.scenario.container.NBContainer;
import io.nosqlbench.engine.core.lifecycle.scenario.execution.NBCommandResult;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -47,7 +47,7 @@ public class NBSession extends NBBaseComponent implements Function<List<Cmd>, Ex
private final String sessionName;
private final ClientSystemMetricChecker clientMetricChecker;
private final Map<String, NBBufferedCommandContext> contexts = new ConcurrentHashMap<>();
private final Map<String, NBBufferedContainer> containers = new ConcurrentHashMap<>();
public enum STATUS {
OK,
@@ -55,10 +55,10 @@ public class NBSession extends NBBaseComponent implements Function<List<Cmd>, Ex
ERROR
}
private NBBufferedCommandContext getContext(String name) {
return contexts.computeIfAbsent(
private NBBufferedContainer getContext(String name) {
return containers.computeIfAbsent(
name,
n -> NBCommandContext.builder().name(n).build(this)
n -> NBContainer.builder().name(n).build(this)
);
}
@@ -99,19 +99,19 @@ public class NBSession extends NBBaseComponent implements Function<List<Cmd>, Ex
*/
public ExecutionResult apply(List<Cmd> cmds) {
// TODO: add context closing command
// TODO: inject context closing commands after the last command referencing each context
// TODO: add container closing command
// TODO: inject container closing commands after the last command referencing each container
List<NBCommandAssembly.CommandInvocation> invocationCalls = NBCommandAssembly.assemble(cmds, this::getContext);
ResultCollector collector = new ResultCollector();
try (ResultContext results = new ResultContext(collector).ok()) {
for (NBCommandAssembly.CommandInvocation invocation : invocationCalls) {
try {
String targetContext = invocation.contextName();
NBBufferedCommandContext context = getContext(targetContext);
NBCommandResult cmdResult = context.apply(invocation.command(), invocation.params());
String targetContext = invocation.containerName();
NBBufferedContainer container = getContext(targetContext);
NBCommandResult cmdResult = container.apply(invocation.command(), invocation.params());
results.apply(cmdResult);
} catch (Exception e) {
String msg = "While running command '" + invocation.command() + "' in context '" + invocation.contextName() + "', an error occurred: " + e.toString();
String msg = "While running command '" + invocation.command() + "' in container '" + invocation.containerName() + "', an error occurred: " + e.toString();
logger.error(msg);
results.error(e);
break;
@@ -119,9 +119,9 @@ public class NBSession extends NBBaseComponent implements Function<List<Cmd>, Ex
}
}
for (String ctxName : contexts.keySet()) {
NBBufferedCommandContext ctx = contexts.get(ctxName);
logger.debug("awaiting end of activities in context '" + ctxName + "':" +
for (String containerName : containers.keySet()) {
NBBufferedContainer ctx = containers.get(containerName);
logger.debug("awaiting end of activities in container '" + containerName + "':" +
ctx.controller().getActivityDefs().stream().map(ActivityDef::getAlias).toList());
ctx.controller().shutdown();
ctx.controller().awaitCompletion(Long.MAX_VALUE);

View File

@@ -55,7 +55,7 @@ public class ResultContext implements AutoCloseable {
if (this.status==null) {
this.status= ExecutionResult.Status.ERROR;
if (this.error!=null) {
this.error=new RuntimeException("early execution result with no asserted status. Call setStatus on your result context or end with `return ctx.ok() or ctx.error(...)`");
this.error=new RuntimeException("early execution result with no asserted status. Call setStatus on your result object or end with `return ctx.ok() or ctx.error(...)`");
}
}
receiver.accept(this);

View File

@@ -20,12 +20,9 @@ import io.nosqlbench.engine.cmdstream.Cmd;
import io.nosqlbench.engine.cmdstream.CmdArg;
import io.nosqlbench.engine.cmdstream.CmdParam;
import io.nosqlbench.engine.core.lifecycle.session.NBCommandInvoker;
import io.nosqlbench.engine.core.lifecycle.session.NBSession;
import io.nosqlbench.nb.api.config.standard.TestComponent;
import io.nosqlbench.nb.api.components.NBComponent;
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBBufferedCommandContext;
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBCommandContext;
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBCommandParams;
import io.nosqlbench.engine.core.lifecycle.scenario.container.NBBufferedContainer;
import io.nosqlbench.engine.core.lifecycle.scenario.container.NBContainer;
import io.nosqlbench.engine.core.lifecycle.scenario.execution.NBCommandResult;
import io.nosqlbench.engine.core.lifecycle.scenario.script.NBScriptedCommand;
import org.apache.logging.log4j.LogManager;
@@ -41,7 +38,7 @@ public class NBBaseCommandTest {
@Test
public void shouldLoadScriptText() {
NBBufferedCommandContext ctx = NBCommandContext.builder().name("testing").build(NBComponent.EMPTY_COMPONENT);
NBBufferedContainer ctx = NBContainer.builder().name("testing").build(NBComponent.EMPTY_COMPONENT);
NBScriptedCommand cmd = NBScriptedCommand.ofScripted("testing", Map.of(),ctx, NBScriptedCommand.Invocation.EXECUTE_SCRIPT);
cmd.add(new Cmd("fragment",Map.of(
"fragment",new CmdArg(new CmdParam("fragment",s->s,false),"=","print('loaded script environment...');")

View File

@@ -17,7 +17,7 @@
package io.nosqlbench.engine.core.script;
import io.nosqlbench.nb.api.errors.BasicError;
import io.nosqlbench.engine.core.lifecycle.scenario.context.NBCommandParams;
import io.nosqlbench.engine.core.lifecycle.scenario.container.NBCommandParams;
import org.junit.jupiter.api.Test;
import java.util.HashMap;