Added BobyqaOptimizer and CsvOutputWriter as builders and removed them from plugins

This commit is contained in:
Mark Wolters
2023-10-05 11:11:55 -04:00
committed by Jonathan Shook
parent 3bc5115b17
commit dc06437d6e
15 changed files with 65 additions and 224 deletions

View File

@@ -1,43 +0,0 @@
/*
* Copyright (c) 2023 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.engine.extensions.conversions;
import io.nosqlbench.api.config.LabeledScenarioContext;
import io.nosqlbench.api.extensions.ScriptingExtensionPluginInfo;
import io.nosqlbench.components.NBComponent;
import io.nosqlbench.nb.annotations.Service;
import org.apache.logging.log4j.Logger;
import java.util.List;
@Service(value = ScriptingExtensionPluginInfo.class,selector = "convert")
public class ConversionUtilsPluginInfo implements ScriptingExtensionPluginInfo<ConverterUtils> {
@Override
public String getDescription() {
return "Utilities to convert between common basic data types";
}
@Override
public ConverterUtils getExtensionObject(Logger logger, NBComponent baseComponent) {
return new ConverterUtils();
}
@Override
public List<Class<?>> autoImportStaticMethodClasses() {
return List.of(ConverterUtils.class);
}
}

View File

@@ -1,37 +0,0 @@
/*
* Copyright (c) 2022-2023 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.engine.extensions.csvoutput;
import io.nosqlbench.api.config.LabeledScenarioContext;
import io.nosqlbench.api.extensions.ScriptingExtensionPluginInfo;
import io.nosqlbench.components.NBComponent;
import io.nosqlbench.nb.annotations.Service;
import org.apache.logging.log4j.Logger;
@Service(value = ScriptingExtensionPluginInfo.class,selector = "csvoutput")
public class CsvOutputPluginData implements ScriptingExtensionPluginInfo<CsvOutputPluginInstance> {
@Override
public String getDescription() {
return "Write CSV output to a named file";
}
@Override
public CsvOutputPluginInstance getExtensionObject(final Logger logger, final NBComponent baseComponent) {
return new CsvOutputPluginInstance();
}
}

View File

@@ -1,24 +0,0 @@
/*
* 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.engine.extensions.csvoutput;
public class CsvOutputPluginInstance {
public CsvOutputPluginWriter open(String filename, String... headers) {
return new CsvOutputPluginWriter(filename, headers);
}
}

View File

@@ -1,13 +0,0 @@
csvoutput extension
===================
This extension makes it easy to start writing CSV data to a file,
using a defined set of headers.
### Examples
Open a writer and write a row:
var out=csvoutput.open('output.csv','time','value');
out.write({'time':23,'value':23});

View File

@@ -1,40 +0,0 @@
/*
* 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.engine.extensions.optimizers;
import io.nosqlbench.components.NBBaseComponent;
import io.nosqlbench.components.NBComponent;
import org.apache.logging.log4j.Logger;
import javax.script.ScriptContext;
public class BobyqaOptimizerPlugin {
private final Logger logger;
private final NBComponent baseComponent;
public BobyqaOptimizerPlugin(Logger logger, NBComponent baseComponent) {
this.logger = logger;
this.baseComponent = baseComponent;
}
public BobyqaOptimizerInstance init() {
return new BobyqaOptimizerInstance(logger,baseComponent);
}
}

View File

@@ -1,39 +0,0 @@
/*
* Copyright (c) 2022-2023 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.engine.extensions.optimizers;
import io.nosqlbench.api.config.LabeledScenarioContext;
import io.nosqlbench.api.extensions.ScriptingExtensionPluginInfo;
import io.nosqlbench.components.NBBaseComponent;
import io.nosqlbench.components.NBComponent;
import io.nosqlbench.nb.annotations.Service;
import org.apache.logging.log4j.Logger;
@Service(value = ScriptingExtensionPluginInfo.class, selector = "optimos")
public class BobyqaOptimizerPluginData implements ScriptingExtensionPluginInfo<BobyqaOptimizerPlugin> {
@Override
public String getDescription() {
return "Allows use of the BOBYQA optimizer in scripts.";
}
@Override
public BobyqaOptimizerPlugin getExtensionObject(final Logger logger, final NBComponent baseComponent) {
return new BobyqaOptimizerPlugin(logger, baseComponent);
}
}

View File

@@ -16,6 +16,8 @@
package io.nosqlbench.engine.extensions.csvoutput; package io.nosqlbench.engine.extensions.csvoutput;
import io.nosqlbench.api.csvoutput.CsvOutputPluginWriter;
import io.nosqlbench.components.NBBaseComponent;
import org.assertj.core.util.Files; import org.assertj.core.util.Files;
import org.graalvm.polyglot.Value; import org.graalvm.polyglot.Value;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@@ -30,7 +32,7 @@ public class CsvOutputPluginWriterTest {
File tmpfile = Files.newTemporaryFile(); File tmpfile = Files.newTemporaryFile();
tmpfile.deleteOnExit(); tmpfile.deleteOnExit();
System.out.println("tmpfile="+ tmpfile.getPath()); System.out.println("tmpfile="+ tmpfile.getPath());
CsvOutputPluginWriter out = new CsvOutputPluginWriter(tmpfile.getPath(), "one", "two"); CsvOutputPluginWriter out = new CsvOutputPluginWriter(new NBBaseComponent(null), tmpfile.getPath(), "one", "two");
out.write(Value.asValue(Map.of("one","one_","two","two_"))); out.write(Value.asValue(Map.of("one","one_","two","two_")));
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2022 nosqlbench * Copyright (c) 2022-2023 nosqlbench
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -12,10 +12,13 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*
*/ */
package io.nosqlbench.engine.extensions.csvoutput; package io.nosqlbench.api.csvoutput;
import io.nosqlbench.components.NBBaseComponent;
import io.nosqlbench.components.NBComponent;
import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter; import org.apache.commons.csv.CSVPrinter;
import org.graalvm.polyglot.Value; import org.graalvm.polyglot.Value;
@@ -27,14 +30,15 @@ import java.nio.file.Path;
import java.nio.file.attribute.PosixFilePermissions; import java.nio.file.attribute.PosixFilePermissions;
import java.util.*; import java.util.*;
public class CsvOutputPluginWriter { public class CsvOutputPluginWriter extends NBBaseComponent {
private final CSVPrinter printer; private final CSVPrinter printer;
private final FileWriter filewriter; private final FileWriter filewriter;
private final LinkedHashSet<String> headerKeys; private final LinkedHashSet<String> headerKeys;
private final String filename; private final String filename;
public CsvOutputPluginWriter(String filename, String... headers) { public CsvOutputPluginWriter(NBComponent component, String filename, String... headers) {
super(component);
try { try {
this.filename = filename; this.filename = filename;
Path filepath = Path.of(filename); Path filepath = Path.of(filename);

View File

@@ -12,9 +12,10 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*
*/ */
package io.nosqlbench.engine.extensions.conversions; package io.nosqlbench.api.engine.conversions;
public class ConverterUtils { public class ConverterUtils {
public static int[] toIntArray(String[] strings) { public static int[] toIntArray(String[] strings) {

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2022 nosqlbench * Copyright (c) 2022-2023 nosqlbench
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -12,9 +12,10 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*
*/ */
package io.nosqlbench.engine.extensions.optimizers; package io.nosqlbench.api.engine.optimizers;
import io.nosqlbench.components.NBBaseComponent; import io.nosqlbench.components.NBBaseComponent;
import io.nosqlbench.components.NBComponent; import io.nosqlbench.components.NBComponent;
@@ -23,16 +24,16 @@ import org.apache.commons.math3.optim.*;
import org.apache.commons.math3.optim.nonlinear.scalar.GoalType; import org.apache.commons.math3.optim.nonlinear.scalar.GoalType;
import org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction; import org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction;
import org.apache.commons.math3.optim.nonlinear.scalar.noderiv.BOBYQAOptimizer; import org.apache.commons.math3.optim.nonlinear.scalar.noderiv.BOBYQAOptimizer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import javax.script.ScriptContext;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.function.Function; import java.util.function.Function;
public class BobyqaOptimizerInstance { public class BobyqaOptimizerInstance extends NBBaseComponent {
private final Logger logger; private static final Logger logger = LogManager.getLogger(BobyqaOptimizerInstance.class);
private final NBComponent baseComponent; private final NBComponent baseComponent;
private int interpolations = 0; private int interpolations = 0;
@@ -49,8 +50,8 @@ public class BobyqaOptimizerInstance {
private MVLogger mvLogger; private MVLogger mvLogger;
private double guessSlew = 0.25d; private double guessSlew = 0.25d;
public BobyqaOptimizerInstance(Logger logger, NBComponent baseComponent) { public BobyqaOptimizerInstance(NBComponent baseComponent) {
this.logger = logger; super(baseComponent);
this.baseComponent = baseComponent; this.baseComponent = baseComponent;
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2022 nosqlbench * Copyright (c) 2022-2023 nosqlbench
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -12,9 +12,10 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*
*/ */
package io.nosqlbench.engine.extensions.optimizers; package io.nosqlbench.api.engine.optimizers;
import org.apache.commons.math3.analysis.MultivariateFunction; import org.apache.commons.math3.analysis.MultivariateFunction;

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2022 nosqlbench * Copyright (c) 2022-2023 nosqlbench
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -12,9 +12,10 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*
*/ */
package io.nosqlbench.engine.extensions.optimizers; package io.nosqlbench.api.engine.optimizers;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2022 nosqlbench * Copyright (c) 2022-2023 nosqlbench
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -12,9 +12,10 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*
*/ */
package io.nosqlbench.engine.extensions.optimizers; package io.nosqlbench.api.engine.optimizers;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2022 nosqlbench * Copyright (c) 2022-2023 nosqlbench
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -12,9 +12,10 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*
*/ */
package io.nosqlbench.engine.extensions.optimizers; package io.nosqlbench.api.engine.optimizers;
import org.apache.commons.math3.analysis.MultivariateFunction; import org.apache.commons.math3.analysis.MultivariateFunction;
import org.graalvm.polyglot.proxy.ProxyObject; import org.graalvm.polyglot.proxy.ProxyObject;

View File

@@ -16,6 +16,7 @@
package io.nosqlbench.components; package io.nosqlbench.components;
import io.nosqlbench.api.csvoutput.CsvOutputPluginWriter;
import com.codahale.metrics.Meter; import com.codahale.metrics.Meter;
import io.nosqlbench.api.engine.metrics.DeltaHdrHistogramReservoir; import io.nosqlbench.api.engine.metrics.DeltaHdrHistogramReservoir;
import io.nosqlbench.api.engine.metrics.DoubleSummaryGauge; import io.nosqlbench.api.engine.metrics.DoubleSummaryGauge;
@@ -27,6 +28,7 @@ import io.nosqlbench.api.engine.metrics.reporters.CsvReporter;
import io.nosqlbench.api.engine.metrics.instruments.*; import io.nosqlbench.api.engine.metrics.instruments.*;
import io.nosqlbench.api.engine.metrics.reporters.MetricInstanceFilter; import io.nosqlbench.api.engine.metrics.reporters.MetricInstanceFilter;
import io.nosqlbench.api.engine.metrics.reporters.PromPushReporterComponent; import io.nosqlbench.api.engine.metrics.reporters.PromPushReporterComponent;
import io.nosqlbench.api.engine.optimizers.BobyqaOptimizerInstance;
import io.nosqlbench.api.labels.NBLabels; import io.nosqlbench.api.labels.NBLabels;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@@ -124,33 +126,56 @@ public class NBBuilders {
// return new ExamplePlugin(component); // return new ExamplePlugin(component);
// } // }
public static class csvReporterBuilder { public BobyqaOptimizerInstance bobyqaOptimizer(final NBComponent component) {
return new BobyqaOptimizerInstance(component);
}
public static class CsvOutputWriterBuilder {
//CsvOutputPluginWriter(NBComponent component, String filename, String... headers) {
private final NBComponent component;
private final String filename;
private String[] headers;
public CsvOutputWriterBuilder(NBComponent component, String filename) {
this.component = component;
this.filename = filename;
}
public CsvOutputWriterBuilder headers(String... headers) {
this.headers = headers;
return this;
}
public CsvOutputPluginWriter build() {
return new CsvOutputPluginWriter(component, filename, headers);
}
}
public static class CsvReporterBuilder {
private final NBComponent component; private final NBComponent component;
private Path reportTo = Path.of("metrics.csv"); private Path reportTo = Path.of("metrics.csv");
private int interval = 1; private int interval = 1;
private MetricInstanceFilter filter = new MetricInstanceFilter(); private MetricInstanceFilter filter = new MetricInstanceFilter();
private NBLabels labels = null; private NBLabels labels = null;
public csvReporterBuilder(NBComponent component) { public CsvReporterBuilder(NBComponent component) {
this.component = component; this.component = component;
} }
public csvReporterBuilder labels(NBLabels labels) { public CsvReporterBuilder labels(NBLabels labels) {
this.labels = labels; this.labels = labels;
return this; return this;
} }
public csvReporterBuilder path(Path reportTo) { public CsvReporterBuilder path(Path reportTo) {
this.reportTo = reportTo; this.reportTo = reportTo;
return this; return this;
} }
public csvReporterBuilder path(String reportTo) { public CsvReporterBuilder path(String reportTo) {
this.reportTo = Path.of(reportTo); this.reportTo = Path.of(reportTo);
return this; return this;
} }
public csvReporterBuilder interval(int interval) { public CsvReporterBuilder interval(int interval) {
this.interval = interval; this.interval = interval;
return this; return this;
} }
public csvReporterBuilder filter(MetricInstanceFilter filter) { public CsvReporterBuilder filter(MetricInstanceFilter filter) {
this.filter = filter; this.filter = filter;
return this; return this;
} }