mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
remove deprecated Nashorn logic
This commit is contained in:
parent
cf5ae84abd
commit
b255d0d70f
@ -16,6 +16,7 @@
|
|||||||
package io.nosqlbench.engine.core.script;
|
package io.nosqlbench.engine.core.script;
|
||||||
|
|
||||||
import com.codahale.metrics.MetricRegistry;
|
import com.codahale.metrics.MetricRegistry;
|
||||||
|
import com.oracle.truffle.js.scriptengine.GraalJSEngineFactory;
|
||||||
import com.oracle.truffle.js.scriptengine.GraalJSScriptEngine;
|
import com.oracle.truffle.js.scriptengine.GraalJSScriptEngine;
|
||||||
import io.nosqlbench.engine.api.extensions.ScriptingPluginInfo;
|
import io.nosqlbench.engine.api.extensions.ScriptingPluginInfo;
|
||||||
import io.nosqlbench.engine.api.metrics.ActivityMetrics;
|
import io.nosqlbench.engine.api.metrics.ActivityMetrics;
|
||||||
@ -34,10 +35,7 @@ import io.nosqlbench.nb.api.metadata.ScenarioMetadataAware;
|
|||||||
import io.nosqlbench.nb.api.metadata.SystemId;
|
import io.nosqlbench.nb.api.metadata.SystemId;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.graalvm.polyglot.Context;
|
import org.graalvm.polyglot.*;
|
||||||
import org.graalvm.polyglot.EnvironmentAccess;
|
|
||||||
import org.graalvm.polyglot.HostAccess;
|
|
||||||
import org.graalvm.polyglot.PolyglotAccess;
|
|
||||||
|
|
||||||
import javax.script.Compilable;
|
import javax.script.Compilable;
|
||||||
import javax.script.CompiledScript;
|
import javax.script.CompiledScript;
|
||||||
@ -98,8 +96,7 @@ public class Scenario implements Callable<ScenarioResult> {
|
|||||||
private long endedAtMillis = -1L;
|
private long endedAtMillis = -1L;
|
||||||
|
|
||||||
public enum Engine {
|
public enum Engine {
|
||||||
Graalvm,
|
Graalvm
|
||||||
Nashorn
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Scenario(
|
public Scenario(
|
||||||
@ -175,62 +172,47 @@ public class Scenario implements Callable<ScenarioResult> {
|
|||||||
|
|
||||||
MetricRegistry metricRegistry = ActivityMetrics.getMetricRegistry();
|
MetricRegistry metricRegistry = ActivityMetrics.getMetricRegistry();
|
||||||
|
|
||||||
switch (engine) {
|
Context.Builder contextSettings = Context.newBuilder("js")
|
||||||
case Nashorn:
|
.allowHostAccess(HostAccess.ALL)
|
||||||
throw new RuntimeException("The nashorn engine has been deprecated in this version of NoSQLBench.");
|
.allowNativeAccess(true)
|
||||||
case Graalvm:
|
.allowCreateThread(true)
|
||||||
Context.Builder contextSettings = Context.newBuilder("js")
|
.allowIO(true)
|
||||||
.allowHostAccess(HostAccess.ALL)
|
.allowHostClassLookup(s -> true)
|
||||||
.allowNativeAccess(true)
|
.allowHostClassLoading(true)
|
||||||
.allowCreateThread(true)
|
.allowCreateProcess(true)
|
||||||
.allowIO(true)
|
.allowAllAccess(true)
|
||||||
.allowHostClassLookup(s -> true)
|
.allowEnvironmentAccess(EnvironmentAccess.INHERIT)
|
||||||
.allowHostClassLoading(true)
|
.allowPolyglotAccess(PolyglotAccess.ALL)
|
||||||
.allowCreateProcess(true)
|
.option("js.ecmascript-version", "2020")
|
||||||
.allowAllAccess(true)
|
.option("js.nashorn-compat", "true");
|
||||||
.allowEnvironmentAccess(EnvironmentAccess.INHERIT)
|
|
||||||
.allowPolyglotAccess(PolyglotAccess.ALL)
|
|
||||||
.option("js.ecmascript-version", "2020")
|
|
||||||
.option("js.nashorn-compat", "true");
|
|
||||||
|
|
||||||
// TODO: add in, out, err for this scenario
|
org.graalvm.polyglot.Engine.Builder engineBuilder = org.graalvm.polyglot.Engine.newBuilder();
|
||||||
this.scriptEngine = GraalJSScriptEngine.create(null, contextSettings);
|
engineBuilder.option("engine.WarnInterpreterOnly","false");
|
||||||
|
org.graalvm.polyglot.Engine polyglotEngine = engineBuilder.build();
|
||||||
|
|
||||||
// try {
|
// TODO: add in, out, err for this scenario
|
||||||
// this.scriptEngine.put("javaObj", new Object());
|
this.scriptEngine = GraalJSScriptEngine.create(polyglotEngine, contextSettings);
|
||||||
// this.scriptEngine.eval("(javaObj instanceof Java.type('java.lang.Object'));");
|
|
||||||
// } catch (ScriptException e) {
|
|
||||||
// throw new RuntimeException(e);
|
|
||||||
// }
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
scenarioController = new ScenarioController(this.scenarioName, minMaturity);
|
scenarioController = new ScenarioController(this.scenarioName, minMaturity);
|
||||||
if (!progressInterval.equals("disabled")) {
|
if (!progressInterval.equals("disabled")) {
|
||||||
activityProgressIndicator = new ActivityProgressIndicator(scenarioController, progressInterval);
|
activityProgressIndicator = new ActivityProgressIndicator(scenarioController, progressInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
scriptEnv = new ScenarioContext(scenarioController);
|
scriptEnv = new ScenarioContext(scenarioController);
|
||||||
scriptEngine.setContext(scriptEnv);
|
scriptEngine.setContext(scriptEnv);
|
||||||
|
|
||||||
scriptEngine.put("params", scenarioScriptParams);
|
scriptEngine.put("params", scenarioScriptParams);
|
||||||
|
|
||||||
if (engine == Engine.Graalvm) {
|
if (wantsGraaljsCompatMode) {
|
||||||
// https://github.com/graalvm/graaljs/blob/master/docs/user/JavaInterop.md
|
scriptEngine.put("scenario", scenarioController);
|
||||||
if (wantsGraaljsCompatMode) {
|
scriptEngine.put("metrics", new PolyglotMetricRegistryBindings(metricRegistry));
|
||||||
scriptEngine.put("scenario", scenarioController);
|
scriptEngine.put("activities", new NashornActivityBindings(scenarioController));
|
||||||
scriptEngine.put("metrics", new PolyglotMetricRegistryBindings(metricRegistry));
|
|
||||||
scriptEngine.put("activities", new NashornActivityBindings(scenarioController));
|
|
||||||
} else {
|
|
||||||
scriptEngine.put("scenario", new PolyglotScenarioController(scenarioController));
|
|
||||||
scriptEngine.put("metrics", new PolyglotMetricRegistryBindings(metricRegistry));
|
|
||||||
scriptEngine.put("activities", new NashornActivityBindings(scenarioController));
|
|
||||||
}
|
|
||||||
} else if (engine == Engine.Nashorn) {
|
|
||||||
throw new RuntimeException("The Nashorn engine has been deprecated in this version of NoSQLBench.");
|
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("Unsupported engine: " + engine);
|
scriptEngine.put("scenario", new PolyglotScenarioController(scenarioController));
|
||||||
|
scriptEngine.put("metrics", new PolyglotMetricRegistryBindings(metricRegistry));
|
||||||
|
scriptEngine.put("activities", new NashornActivityBindings(scenarioController));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ScriptingPluginInfo<?> extensionDescriptor : SandboxExtensionFinder.findAll()) {
|
for (ScriptingPluginInfo<?> extensionDescriptor : SandboxExtensionFinder.findAll()) {
|
||||||
@ -246,7 +228,7 @@ public class Scenario implements Callable<ScenarioResult> {
|
|||||||
metricRegistry,
|
metricRegistry,
|
||||||
scriptEnv
|
scriptEnv
|
||||||
);
|
);
|
||||||
ScenarioMetadataAware.apply(extensionObject,getScenarioMetadata());
|
ScenarioMetadataAware.apply(extensionObject, getScenarioMetadata());
|
||||||
logger.trace("Adding extension object: name=" + extensionDescriptor.getBaseVariableName() +
|
logger.trace("Adding extension object: name=" + extensionDescriptor.getBaseVariableName() +
|
||||||
" class=" + extensionObject.getClass().getSimpleName());
|
" class=" + extensionObject.getClass().getSimpleName());
|
||||||
scriptEngine.put(extensionDescriptor.getBaseVariableName(), extensionObject);
|
scriptEngine.put(extensionDescriptor.getBaseVariableName(), extensionObject);
|
||||||
@ -254,7 +236,7 @@ public class Scenario implements Callable<ScenarioResult> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private synchronized ScenarioMetadata getScenarioMetadata() {
|
private synchronized ScenarioMetadata getScenarioMetadata() {
|
||||||
if (this.scenarioMetadata==null) {
|
if (this.scenarioMetadata == null) {
|
||||||
this.scenarioMetadata = new ScenarioMetadata(
|
this.scenarioMetadata = new ScenarioMetadata(
|
||||||
this.startedAtMillis,
|
this.startedAtMillis,
|
||||||
this.scenarioName,
|
this.scenarioName,
|
||||||
|
Loading…
Reference in New Issue
Block a user