Merge branch 'cqlast'

This commit is contained in:
Jonathan Shook
2022-07-29 20:55:02 -05:00
91 changed files with 2116 additions and 1016 deletions

View File

@@ -83,11 +83,29 @@ public class NBConfiguration {
} else {
return value;
}
}
public String get(String name) {
return get(name, String.class);
/**
* Get a config value or object by name. This uses type inference (as a generic method)
* in addition to the internal model for type checking and ergonomic use. If you do not
* call this within an assignment or context where the Java compiler knows what type you
* are expecting, then use {@link #get(String, Class)} instead.
* @param name The name of the configuration parameter
* @param <T> The (inferred) generic type of the configuration value
* @return The value of type T, matching the config model type for the provided field name
*/
public <T> T get(String name) {
Param<T> param = (Param<T>)model.getNamedParams().get(name);
Object object = this.data.get(name);
if (param.type.isInstance(object)) {
return (T) object;
} else if (param.type.isAssignableFrom(object.getClass())) {
return param.type.cast(object);
} else if (NBTypeConverter.canConvert(object, param.type)) {
return NBTypeConverter.convert(object, param.type);
} else {
throw new NBConfigError("Unable to assign config value for field '" + name + "' of type '" + object.getClass().getCanonicalName() + "' to the required return type '" + param.type.getCanonicalName() + "' as specified in the config model for '" + model.getOf().getCanonicalName());
}
}
public <T> T get(String name, Class<? extends T> type) {

View File

@@ -16,6 +16,8 @@
package io.nosqlbench.api.docsapi.docexporter;
import io.nosqlbench.api.spi.BundledApp;
import io.nosqlbench.nb.annotations.Service;
import joptsimple.OptionParser;
import joptsimple.OptionSet;
import joptsimple.OptionSpec;
@@ -24,14 +26,19 @@ import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
public class BundledMarkdownExporter {
@Service(value=BundledApp.class,selector = "export-docs")
public class BundledMarkdownExporter implements BundledApp {
public static void main(String[] args) {
new BundledMarkdownExporter().appMain(args);
}
@Override
public int appMain(String[] args) {
final OptionParser parser = new OptionParser();
OptionSpec<String> zipfileSpec = parser.accepts("zipfile", "zip file to write to")
.withOptionalArg().ofType(String.class).defaultsTo("exported_docs.zip");
.withOptionalArg().ofType(String.class).defaultsTo("exported_docs.zip");
OptionSpec<?> helpSpec = parser.acceptsAll(List.of("help", "h", "?"), "Display help").forHelp();
OptionSet options = parser.parse(args);
@@ -46,6 +53,6 @@ public class BundledMarkdownExporter {
String zipfile = options.valueOf(zipfileSpec);
new BundledMarkdownZipExporter(new BundledFrontmatterInjector()).exportDocs(Path.of(zipfile));
return 0;
}
}

View File

@@ -16,6 +16,8 @@
package io.nosqlbench.api.labels;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -29,6 +31,7 @@ public interface Labeled {
}
return map;
}
default Map<String, String> getLabelsAnd(Map<String,String> extra) {
LinkedHashMap<String,String> map = new LinkedHashMap<>(getLabels());
map.putAll(extra);
@@ -51,4 +54,20 @@ public interface Labeled {
return labels;
}
}
default String linearized(Map<String,String> and) {
StringBuilder sb= new StringBuilder();
Map<String, String> allLabels = this.getLabelsAnd(and);
ArrayList<String> sortedLabels = new ArrayList<>(allLabels.keySet());
Collections.sort(sortedLabels);
for (String label : sortedLabels) {
sb.append(label).append(":").append(allLabels.get(label)).append((","));
}
sb.setLength(sb.length()-",".length());
return sb.toString();
}
default String linearized(String... and) {
return linearized(getLabelsAnd(and));
}
}

View File

@@ -19,6 +19,8 @@ package io.nosqlbench.api.markdown.exporter;
import io.nosqlbench.api.markdown.aggregator.MarkdownDocs;
import io.nosqlbench.api.markdown.types.DocScope;
import io.nosqlbench.api.markdown.types.MarkdownInfo;
import io.nosqlbench.api.spi.BundledApp;
import io.nosqlbench.nb.annotations.Service;
import joptsimple.*;
import java.nio.file.Path;
@@ -27,35 +29,15 @@ import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
public class MarkdownExporter implements Runnable {
@Service(value = BundledApp.class, selector = "markdown-exporter")
public class MarkdownExporter implements BundledApp, Runnable {
public static final String APP_NAME = "exporter";
private final Path basePath;
private final Set<DocScope> scopeSet;
public MarkdownExporter(Path basePath, Set<DocScope> scopeSet) {
this.basePath = basePath;
this.scopeSet = scopeSet;
}
private Path basePath;
private Set<DocScope> scopeSet;
public static void main(String[] args) {
final OptionParser parser = new OptionParser();
OptionSpec<String> basedir = parser.accepts("basedir", "base directory to write to")
.withRequiredArg().ofType(String.class).defaultsTo(".");
OptionSpec<String> docScopes = parser.accepts("scopes", "scopes of documentation to export")
.withRequiredArg().ofType(String.class).defaultsTo(DocScope.ANY.toString());
parser.acceptsAll(List.of("-h","--help","help"),"Display help").forHelp();
OptionSet options = parser.parse(args);
Path basePath = Path.of(basedir.value(options));
Set<DocScope> scopeSet = docScopes.values(options).stream().map(DocScope::valueOf).collect(Collectors.toSet());
new MarkdownExporter(basePath,scopeSet).run();
new MarkdownExporter().appMain(args);
}
@Override
@@ -65,4 +47,25 @@ public class MarkdownExporter implements Runnable {
}
@Override
public int appMain(String[] args) {
final OptionParser parser = new OptionParser();
OptionSpec<String> basedir = parser.accepts("basedir", "base directory to write to")
.withRequiredArg().ofType(String.class).defaultsTo(".");
OptionSpec<String> docScopes = parser.accepts("scopes", "scopes of documentation to export")
.withRequiredArg().ofType(String.class).defaultsTo(DocScope.ANY.toString());
parser.acceptsAll(List.of("-h", "--help", "help"), "Display help").forHelp();
OptionSet options = parser.parse(args);
Path basePath = Path.of(basedir.value(options));
Set<DocScope> scopeSet = docScopes.values(options).stream().map(DocScope::valueOf).collect(Collectors.toSet());
this.basePath = basePath;
this.scopeSet = scopeSet;
run();
return 0;
}
}

View File

@@ -0,0 +1,21 @@
/*
* Copyright (c) 2022 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.nosqlbench.api.spi;
public interface BundledApp {
int appMain(String[] args);
}