mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
specialize use of op,stmt,workload on CLI
This commit is contained in:
parent
353f4306e5
commit
612d7e4941
@ -17,6 +17,7 @@
|
||||
package io.nosqlbench.adapters.api.activityconfig;
|
||||
|
||||
import com.amazonaws.util.StringInputStream;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import io.nosqlbench.nb.api.nbio.Content;
|
||||
import io.nosqlbench.nb.api.nbio.NBIO;
|
||||
import io.nosqlbench.nb.api.errors.BasicError;
|
||||
@ -27,6 +28,8 @@ import io.nosqlbench.adapters.api.activityconfig.yaml.OpsDocList;
|
||||
import io.nosqlbench.adapters.api.templating.StrInterpolator;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.snakeyaml.engine.v2.api.Load;
|
||||
import org.snakeyaml.engine.v2.api.LoadSettings;
|
||||
import scala.Option;
|
||||
import sjsonnet.DefaultParseCache;
|
||||
import sjsonnet.SjsonnetMain;
|
||||
@ -146,4 +149,25 @@ public class OpsLoader {
|
||||
return stdoutOutput;
|
||||
}
|
||||
|
||||
// TODO These should not be exception based, use explicit pattern checks instead, or tap
|
||||
// into the parsers in a non-exception way
|
||||
public static boolean isJson(String workload) {
|
||||
try {
|
||||
new GsonBuilder().setPrettyPrinting().create().fromJson(workload, Map.class);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO These should not be exception based, use explicit pattern checks instead, or tap
|
||||
// into the parsers in a non-exception way
|
||||
public static boolean isYaml(String workload) {
|
||||
try {
|
||||
new Load(LoadSettings.builder().build()).loadFromString(workload);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ import java.util.*;
|
||||
|
||||
public class OpsOwner extends RawOpFields {
|
||||
|
||||
private final static List<String> opsFieldNames = List.of("op","ops","operation","statement","statements");
|
||||
private final static List<String> opsFieldNames = List.of("op","ops","operation","stmt","statement","statements");
|
||||
|
||||
private List<RawOpDef> rawOpDefs = new ArrayList<>();
|
||||
|
||||
|
@ -16,6 +16,8 @@
|
||||
|
||||
package io.nosqlbench.adapters.api.activityconfig.rawyaml;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import io.nosqlbench.nb.api.nbio.Content;
|
||||
import io.nosqlbench.nb.api.nbio.NBIO;
|
||||
import io.nosqlbench.nb.api.errors.BasicError;
|
||||
@ -36,6 +38,11 @@ public class RawOpsLoader {
|
||||
|
||||
private final ArrayList<Function<String,String>> transformers = new ArrayList<>();
|
||||
|
||||
private static LoadSettings loadSettings = LoadSettings.builder().build();
|
||||
private final Load yaml = new Load(loadSettings);
|
||||
private final Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
||||
|
||||
public RawOpsLoader(Function<String,String> transformer) {
|
||||
addTransformer(transformer);
|
||||
}
|
||||
@ -44,6 +51,15 @@ public class RawOpsLoader {
|
||||
addTransformer(new StrInterpolator());
|
||||
}
|
||||
|
||||
public boolean isJson(String workload) {
|
||||
try {
|
||||
Object canLoad = gson.fromJson(workload, Object.class);
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void addTransformer(Function<String, String> newTransformer) {
|
||||
Collections.addAll(this.transformers, newTransformer);
|
||||
}
|
||||
@ -79,8 +95,6 @@ public class RawOpsLoader {
|
||||
}
|
||||
|
||||
public RawOpsDocList parseYaml(String data) {
|
||||
LoadSettings loadSettings = LoadSettings.builder().build();
|
||||
Load yaml = new Load(loadSettings);
|
||||
Iterable<Object> objects = yaml.loadAllFromString(data);
|
||||
List<RawOpsDoc> newDocList = new ArrayList<>();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user