mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-01-06 22:13:08 -06:00
make config model construction more uniform
This commit is contained in:
parent
ab24cc5aef
commit
284e86e64f
@ -5,11 +5,14 @@ import com.datastax.driver.core.DataType;
|
||||
import com.datastax.driver.core.TupleType;
|
||||
import com.datastax.driver.core.TupleValue;
|
||||
import io.nosqlbench.nb.api.config.standard.ConfigModel;
|
||||
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
|
||||
import io.nosqlbench.nb.api.config.standard.NBMapConfigurable;
|
||||
import io.nosqlbench.nb.api.config.standard.NBConfigModel;
|
||||
import io.nosqlbench.nb.api.config.standard.NBMapConfigurable;
|
||||
import io.nosqlbench.nb.api.config.standard.Param;
|
||||
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.LongFunction;
|
||||
import java.util.function.LongToIntFunction;
|
||||
import java.util.function.LongUnaryOperator;
|
||||
@ -21,14 +24,14 @@ import java.util.function.LongUnaryOperator;
|
||||
*
|
||||
* Functions are required for:
|
||||
* <LI>
|
||||
* <LI>map size {@code (LongToIntFunction)}</LI>
|
||||
* <LI>key {@code (LongFunction<Object>)}</LI>
|
||||
* <LI>tuple field 1 {@code (LongToIntFunction)}</LI>
|
||||
* <LI>tuple field 2 {@code {LongToIntFunction)}</LI>
|
||||
* <LI>map size {@code (LongToIntFunction)}</LI>
|
||||
* <LI>key {@code (LongFunction<Object>)}</LI>
|
||||
* <LI>tuple field 1 {@code (LongToIntFunction)}</LI>
|
||||
* <LI>tuple field 2 {@code {LongToIntFunction)}</LI>
|
||||
* </LI>
|
||||
*/
|
||||
@ThreadSafeMapper
|
||||
public class CustomFunc955 implements LongFunction<Map<?,?>>, NBMapConfigurable {
|
||||
public class CustomFunc955 implements LongFunction<Map<?, ?>>, NBMapConfigurable {
|
||||
|
||||
private final LongToIntFunction sizefunc;
|
||||
private final LongFunction<Object> keyfunc;
|
||||
@ -56,16 +59,16 @@ public class CustomFunc955 implements LongFunction<Map<?,?>>, NBMapConfigurable
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<?,?> apply(long value) {
|
||||
public Map<?, ?> apply(long value) {
|
||||
int size = sizefunc.applyAsInt(value);
|
||||
|
||||
HashMap<String, TupleValue> map = new HashMap<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
String key = keyfunc.apply(value+i).toString();
|
||||
int tuple1 = field1func.applyAsInt(value+i);
|
||||
long tuple2 = field2func.applyAsLong(value+i);
|
||||
String key = keyfunc.apply(value + i).toString();
|
||||
int tuple1 = field1func.applyAsInt(value + i);
|
||||
long tuple2 = field2func.applyAsLong(value + i);
|
||||
TupleValue tupleValue = tupleType.newValue(tuple1, tuple2);
|
||||
map.put(key,tupleValue);
|
||||
map.put(key, tupleValue);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
@ -81,7 +84,7 @@ public class CustomFunc955 implements LongFunction<Map<?,?>>, NBMapConfigurable
|
||||
@Override
|
||||
public NBConfigModel getConfigModel() {
|
||||
return ConfigModel.of(this.getClass())
|
||||
.optional("<cluster>", Cluster.class)
|
||||
.add(Param.optional("<cluster>", Cluster.class))
|
||||
.asReadOnly();
|
||||
}
|
||||
}
|
||||
|
@ -9,10 +9,7 @@ import io.nosqlbench.nb.api.SystemId;
|
||||
import io.nosqlbench.nb.api.annotations.Annotation;
|
||||
import io.nosqlbench.nb.api.annotations.Annotator;
|
||||
import io.nosqlbench.nb.api.config.params.ParamsParser;
|
||||
import io.nosqlbench.nb.api.config.standard.ConfigModel;
|
||||
import io.nosqlbench.nb.api.config.standard.NBConfigModel;
|
||||
import io.nosqlbench.nb.api.config.standard.NBConfigurable;
|
||||
import io.nosqlbench.nb.api.config.standard.NBConfiguration;
|
||||
import io.nosqlbench.nb.api.config.standard.*;
|
||||
import io.nosqlbench.nb.api.errors.BasicError;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@ -111,7 +108,7 @@ public class GrafanaMetricsAnnotator implements Annotator, NBConfigurable {
|
||||
public void applyConfig(NBConfiguration cfg) {
|
||||
|
||||
GrafanaClientConfig gc = new GrafanaClientConfig();
|
||||
gc.setBaseUri(cfg.param("baseurl", String.class));
|
||||
gc.setBaseUri(cfg.get("baseurl"));
|
||||
|
||||
cfg.getOptional("tags")
|
||||
.map(t -> ParamsParser.parse(t, false))
|
||||
@ -133,7 +130,7 @@ public class GrafanaMetricsAnnotator implements Annotator, NBConfigurable {
|
||||
Optional<String> optionalApikey = cfg.getOptional("apikey");
|
||||
|
||||
if (optionalApikeyfile.isPresent()) {
|
||||
keyfilePath=optionalApikeyfile.map(Path::of).orElseThrow();
|
||||
keyfilePath = optionalApikeyfile.map(Path::of).orElseThrow();
|
||||
} else if (optionalApikey.isPresent()) {
|
||||
gc.addHeaderSource(() -> Map.of("Authorization", "Bearer " + optionalApikey.get()));
|
||||
} else {
|
||||
@ -151,7 +148,7 @@ public class GrafanaMetricsAnnotator implements Annotator, NBConfigurable {
|
||||
}
|
||||
|
||||
private void setOnError(OnError onError) {
|
||||
this.onError=onError;
|
||||
this.onError = onError;
|
||||
}
|
||||
|
||||
private void setTags(Map<String, String> tags) {
|
||||
@ -161,22 +158,22 @@ public class GrafanaMetricsAnnotator implements Annotator, NBConfigurable {
|
||||
@Override
|
||||
public NBConfigModel getConfigModel() {
|
||||
return ConfigModel.of(this.getClass())
|
||||
.required("baseurl", String.class,
|
||||
"The base url of the grafana node, like http://localhost:3000/")
|
||||
.defaults("apikeyfile", "$NBSTATEDIR/grafana/grafana_apikey",
|
||||
"The file that contains the api key, supersedes apikey")
|
||||
.optional("apikey", String.class,
|
||||
"The api key to use, supersedes basic username and password")
|
||||
.optional("username", String.class,
|
||||
"The username to use for basic auth")
|
||||
.optional("password", String.class,
|
||||
"The password to use for basic auth")
|
||||
.defaults("tags", "source:nosqlbench",
|
||||
"The tags that identify the annotations, in k:v,... form")
|
||||
.defaults("onerror", "warn",
|
||||
"What to do when an error occurs while posting an annotation")
|
||||
.defaults("timeoutms", 5000,
|
||||
"connect and transport timeout for the HTTP client")
|
||||
.add(Param.required("baseurl", String.class)
|
||||
.setDescription("The base url of the grafana node, like http://localhost:3000/"))
|
||||
.add(Param.defaultTo("apikeyfile", "$NBSTATEDIR/grafana/grafana_apikey")
|
||||
.setDescription("The file that contains the api key, supersedes apikey"))
|
||||
.add(Param.optional("apikey", String.class)
|
||||
.setDescription("The api key to use, supersedes basic username and password"))
|
||||
.add(Param.optional("username", String.class)
|
||||
.setDescription("The username to use for basic auth"))
|
||||
.add(Param.optional("password", String.class)
|
||||
.setDescription("The password to use for basic auth"))
|
||||
.add(Param.defaultTo("tags", "source:nosqlbench")
|
||||
.setDescription("The tags that identify the annotations, in k:v,... form"))
|
||||
.add(Param.defaultTo("onerror", "warn")
|
||||
.setDescription("What to do when an error occurs while posting an annotation"))
|
||||
.add(Param.defaultTo("timeoutms", 5000)
|
||||
.setDescription("connect and transport timeout for the HTTP client"))
|
||||
.asReadOnly();
|
||||
}
|
||||
|
||||
|
@ -3,10 +3,7 @@ package io.nosqlbench.engine.core.metrics;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import io.nosqlbench.nb.api.annotations.Annotation;
|
||||
import io.nosqlbench.nb.api.annotations.Annotator;
|
||||
import io.nosqlbench.nb.api.config.standard.NBMapConfigurable;
|
||||
import io.nosqlbench.nb.api.config.standard.ConfigModel;
|
||||
import io.nosqlbench.nb.api.config.standard.NBConfigModel;
|
||||
import io.nosqlbench.nb.api.config.standard.NBConfiguration;
|
||||
import io.nosqlbench.nb.api.config.standard.*;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@ -35,16 +32,16 @@ public class LoggingAnnotator implements Annotator, NBMapConfigurable {
|
||||
public void applyConfig(Map<String, ?> providedConfig) {
|
||||
NBConfigModel configModel = getConfigModel();
|
||||
NBConfiguration cfg = configModel.apply(providedConfig);
|
||||
String levelName = cfg.param("level", String.class);
|
||||
String levelName = cfg.get("level");
|
||||
this.level = Level.valueOf(levelName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBConfigModel getConfigModel() {
|
||||
return ConfigModel.of(this.getClass())
|
||||
.defaults("level", "INFO",
|
||||
"The logging level to use for this annotator")
|
||||
.asReadOnly();
|
||||
.add(Param.defaultTo("level", "INFO")
|
||||
.setDescription("The logging level to use for this annotator"))
|
||||
.asReadOnly();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user