mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
re-homing some packages for API sanity
This commit is contained in:
parent
347006239a
commit
367334fa6e
@ -2,7 +2,6 @@ package io.nosqlbench.engine.api.activityconfig.yaml;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import io.nosqlbench.engine.api.activityconfig.ParsedStmtOp;
|
||||
import io.nosqlbench.engine.api.util.Tagged;
|
||||
import io.nosqlbench.nb.api.config.params.Element;
|
||||
import io.nosqlbench.nb.api.config.params.NBParams;
|
||||
@ -253,7 +252,7 @@ public abstract class OpTemplate implements Tagged {
|
||||
* Parse the statement for anchors and return a richer view of the StmtDef which
|
||||
* is simpler to use for most statement configuration needs.
|
||||
*
|
||||
* @return a new {@link ParsedStmtOp}
|
||||
* @return an optional {@link ParsedTemplate}
|
||||
*/
|
||||
public Optional<ParsedTemplate> getParsed(Function<String,String>... rewriters) {
|
||||
Optional<String> os = getStmt();
|
||||
@ -315,6 +314,6 @@ public abstract class OpTemplate implements Tagged {
|
||||
}
|
||||
|
||||
public Element getParamReader() {
|
||||
return NBParams.one(getParams());
|
||||
return NBParams.one(getName(),getParams());
|
||||
}
|
||||
}
|
@ -1,7 +1,10 @@
|
||||
package io.nosqlbench.engine.api.activityimpl.uniform;
|
||||
|
||||
import io.nosqlbench.engine.api.activityimpl.ActivityDef;
|
||||
import io.nosqlbench.engine.api.activityimpl.uniform.fieldmappers.FieldDestructuringMapper;
|
||||
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.NBMapConfigurable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -11,10 +14,10 @@ import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class BaseDriverAdapter<R extends Runnable,S>
|
||||
implements DriverAdapter<R,S>, ActivityDefAware {
|
||||
implements DriverAdapter<R,S>, NBMapConfigurable {
|
||||
|
||||
private final DriverSpaceCache<? extends S> spaceCache;
|
||||
private ActivityDef activityDef;
|
||||
private NBConfiguration NBCfgReader;
|
||||
|
||||
protected BaseDriverAdapter() {
|
||||
this.spaceCache = new DriverSpaceCache<>(getSpaceInitializer());
|
||||
@ -79,16 +82,26 @@ public abstract class BaseDriverAdapter<R extends Runnable,S>
|
||||
}
|
||||
|
||||
@Override
|
||||
public DriverSpaceCache<? extends S> getSpaceCache() {
|
||||
public final DriverSpaceCache<? extends S> getSpaceCache() {
|
||||
return spaceCache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActivityDef(ActivityDef activiytDef) {
|
||||
this.activityDef = activiytDef;
|
||||
public final void applyConfig(Map<String, ?> providedConfig) {
|
||||
NBConfiguration config = getConfigModel().apply(providedConfig);
|
||||
}
|
||||
|
||||
public ActivityDef getActivityDef() {
|
||||
return activityDef;
|
||||
/**
|
||||
* In order to be provided with config information, it is required
|
||||
* that the driver adapter specify the valid configuration options,
|
||||
* their types, and so on.
|
||||
*/
|
||||
@Override
|
||||
public NBConfigModel getConfigModel() {
|
||||
return ConfigModel.of(this.getClass());
|
||||
}
|
||||
|
||||
public NBConfiguration getConfigReader() {
|
||||
return NBCfgReader;
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package io.nosqlbench.engine.api.activityimpl.uniform;
|
||||
|
||||
import io.nosqlbench.engine.api.activityapi.core.ActivityType;
|
||||
import io.nosqlbench.engine.api.activityimpl.OpDispenser;
|
||||
import io.nosqlbench.engine.api.activityimpl.OpMapper;
|
||||
import io.nosqlbench.engine.api.templating.ParsedCommand;
|
||||
@ -10,7 +9,7 @@ import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* <P>The DriverAdapter interface is expected to be the replacement
|
||||
* for the current {@link ActivityType}. This interface takes a simpler
|
||||
* for ActivityTypes. This interface takes a simpler
|
||||
* approach. Specifically, all of the core logic which was being pasted into each
|
||||
* driver type is centralized, and only the necessary interfaces
|
||||
* needed for construction new operations and shared context are exposed.
|
@ -15,7 +15,7 @@
|
||||
|
||||
package io.nosqlbench.engine.api.activityimpl;
|
||||
|
||||
import io.nosqlbench.nb.api.config.ParamsParser;
|
||||
import io.nosqlbench.nb.api.config.params.ParamsParser;
|
||||
import io.nosqlbench.engine.api.util.Unit;
|
||||
|
||||
import org.graalvm.polyglot.Value;
|
||||
@ -261,13 +261,6 @@ public class ParameterMap extends ConcurrentHashMap<String,Object> implements Bi
|
||||
return new ParameterMap(parsedMap);
|
||||
}
|
||||
|
||||
// static Optional<ParameterMap> parseOptionalParams(Optional<String> optionalEncodedParams) {
|
||||
// if (optionalEncodedParams.isPresent()) {
|
||||
// return parseParams(optionalEncodedParams.get());
|
||||
// }
|
||||
// return Optional.empty();
|
||||
// }
|
||||
|
||||
public static Optional<ParameterMap> parseParams(String encodedParams) {
|
||||
try {
|
||||
return Optional.ofNullable(parseOrException(encodedParams));
|
||||
@ -306,45 +299,6 @@ public class ParameterMap extends ConcurrentHashMap<String,Object> implements Bi
|
||||
return removed!=null;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Parse positional parameters, each suffixed with the ';' terminator.
|
||||
// * This form simply allows for the initial parameter names to be elided, so long as they
|
||||
// * are sure to match up with a well-known order. This method cleans up the input, injecting
|
||||
// * the field names as necessary, and then calls the normal parsing logic.
|
||||
// *
|
||||
// * @param encodedParams parameter string
|
||||
// * @param defaultFieldNames the well-known field ordering
|
||||
// * @return a new ParameterMap, if parsing was successful
|
||||
// */
|
||||
// public static ParameterMap parsePositional(String encodedParams, String[] defaultFieldNames) {
|
||||
//
|
||||
// String[] splitAtSemi = encodedParams.split(";");
|
||||
//
|
||||
// for (int wordidx = 0; wordidx < splitAtSemi.length; wordidx++) {
|
||||
//
|
||||
// if (!splitAtSemi[wordidx].contains("=")) {
|
||||
//
|
||||
// if (wordidx > (defaultFieldNames.length - 1)) {
|
||||
// throw new RuntimeException("positional param (without var=val; format) ran out of "
|
||||
// + "positional field names:"
|
||||
// + " names:" + Arrays.toString(defaultFieldNames)
|
||||
// + ", values: " + Arrays.toString(splitAtSemi)
|
||||
// + ", original: " + encodedParams
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// splitAtSemi[wordidx] = defaultFieldNames[wordidx] + "=" + splitAtSemi[wordidx] + ";";
|
||||
// }
|
||||
// if (!splitAtSemi[wordidx].endsWith(";")) {
|
||||
// splitAtSemi[wordidx] = splitAtSemi[wordidx] + ";";
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// String allArgs = Arrays.asList(splitAtSemi).stream().collect(Collectors.joining());
|
||||
// ParameterMap parameterMap = ParameterMap.parseOrException(allArgs);
|
||||
// return parameterMap;
|
||||
// }
|
||||
|
||||
public interface Listener {
|
||||
void handleParameterMapUpdate(ParameterMap parameterMap);
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package io.nosqlbench.nb.api.config;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface ConfigAware {
|
||||
void applyConfig(Map<String, ?> providedConfig);
|
||||
|
||||
ConfigModel getConfigModel();
|
||||
}
|
@ -15,7 +15,7 @@
|
||||
* /
|
||||
*/
|
||||
|
||||
package io.nosqlbench.nb.api.config;
|
||||
package io.nosqlbench.nb.api.config.params;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
@ -1,4 +1,4 @@
|
||||
package io.nosqlbench.nb.api.config;
|
||||
package io.nosqlbench.nb.api.config.params;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -49,8 +49,8 @@ public class Synonyms {
|
||||
}
|
||||
|
||||
public static String canonicalize(String arg, Logger logger) {
|
||||
return canonicalize(arg, PARAM_SYNONYMS, (d, p) -> logger.warn(
|
||||
"The param name '" + p + "' is preferred. The use of '" + d + "' may be deprecated in the future."
|
||||
return canonicalize(arg, PARAM_SYNONYMS, (d, p) -> logger.debug(
|
||||
"rewrote synonym to canonical term (" + d +" => " + p +")"
|
||||
));
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package io.nosqlbench.nb.api.config;
|
||||
package io.nosqlbench.nb.api.config.standard;
|
||||
|
||||
import io.nosqlbench.nb.api.errors.BasicError;
|
||||
|
@ -1,6 +1,7 @@
|
||||
package io.nosqlbench.nb.api.config;
|
||||
package io.nosqlbench.nb.api.config.standard;
|
||||
|
||||
import com.google.gson.*;
|
||||
import io.nosqlbench.nb.api.config.params.ParamsParser;
|
||||
import io.nosqlbench.nb.api.content.NBIO;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
@ -0,0 +1,175 @@
|
||||
package io.nosqlbench.nb.api.config.standard;
|
||||
|
||||
import io.nosqlbench.nb.api.errors.BasicError;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ConfigModel implements NBConfigModel {
|
||||
|
||||
private final LinkedHashMap<String, Param<?>> elements = new LinkedHashMap<>();
|
||||
private Param<?> lastAdded = null;
|
||||
private final Class<?> ofType;
|
||||
|
||||
private ConfigModel(Class<?> ofType, Param<?>... params) {
|
||||
this.ofType = ofType;
|
||||
for (Param<?> param : params) {
|
||||
this.elements.put(param.getName(), param);
|
||||
}
|
||||
}
|
||||
|
||||
public static ConfigModel of(Class<?> ofType, Param<?>... params) {
|
||||
return new ConfigModel(ofType, params);
|
||||
}
|
||||
|
||||
public ConfigModel optional(String name, Class<?> clazz) {
|
||||
add(new Param<>(name, clazz, "", false, null));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ConfigModel optional(String name, Class<?> clazz, String description) {
|
||||
add(new Param<>(name, clazz, description, false, null));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ConfigModel required(String name, Class<?> clazz, String description) {
|
||||
add(new Param<>(name, clazz, description, true, null));
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T> ConfigModel add(Param<T> param) {
|
||||
this.elements.put(param.name, param);
|
||||
lastAdded = null;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ConfigModel required(String name, Class<?> clazz) {
|
||||
add(new Param<>(name, clazz, "", true, null));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ConfigModel defaults(String name, Object defaultValue) {
|
||||
add(new Param<>(name, defaultValue.getClass(), "", true, defaultValue));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ConfigModel defaults(String name, Object defaultValue, String description) {
|
||||
add(new Param<>(name, defaultValue.getClass(), description, true, defaultValue));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ConfigModel describedAs(String descriptionOfLastElement) {
|
||||
lastAdded.setDescription(descriptionOfLastElement);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public NBConfigModel asReadOnly() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Param<?>> getElements() {
|
||||
return Collections.unmodifiableMap(elements);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getOf() {
|
||||
return ofType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void assertValidConfig(Map<String, ?> config) {
|
||||
for (String configkey : config.keySet()) {
|
||||
Param<?> element = this.elements.get(configkey);
|
||||
if (element == null) {
|
||||
StringBuilder paramhelp = new StringBuilder(
|
||||
"Unknown config parameter in config model '" + configkey + "' " +
|
||||
"while configuring " + getOf().getSimpleName()
|
||||
+ ", possible parameter names are " + this.elements.keySet() + "."
|
||||
);
|
||||
|
||||
ConfigSuggestions.getForParam(this, configkey)
|
||||
.ifPresent(suggestion -> paramhelp.append(" ").append(suggestion));
|
||||
|
||||
throw new BasicError(paramhelp.toString());
|
||||
}
|
||||
Object value = config.get(configkey);
|
||||
Object testValue = convertValueTo(ofType.getSimpleName(), configkey, value, element.getType());
|
||||
}
|
||||
for (Param<?> element : elements.values()) {
|
||||
if (element.isRequired() && element.getDefaultValue() == null) {
|
||||
if (!config.containsKey(element.getName())) {
|
||||
throw new RuntimeException("A required config element named '" + element.getName() +
|
||||
"' and type '" + element.getType().getSimpleName() + "' was not found\n" +
|
||||
"for configuring a " + getOf().getSimpleName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Object convertValueTo(String configName, String paramName, Object value, Class<?> type) {
|
||||
try {
|
||||
if (type.isAssignableFrom(value.getClass())) {
|
||||
return type.cast(value);
|
||||
} else if (Number.class.isAssignableFrom(type)
|
||||
&& Number.class.isAssignableFrom(value.getClass())) {
|
||||
Number number = (Number) value;
|
||||
if (type.equals(Float.class)) {
|
||||
return number.floatValue();
|
||||
} else if (type.equals(Integer.class)) {
|
||||
return number.intValue();
|
||||
} else if (type.equals(Double.class)) {
|
||||
return number.doubleValue();
|
||||
} else if (type.equals(Long.class)) {
|
||||
return number.longValue();
|
||||
} else if (type.equals(Byte.class)) {
|
||||
return number.byteValue();
|
||||
} else if (type.equals(Short.class)) {
|
||||
return number.shortValue();
|
||||
} else {
|
||||
throw new RuntimeException("Number type " + type.getSimpleName() + " could " +
|
||||
" not be converted from " + value.getClass().getSimpleName());
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
throw new RuntimeException(
|
||||
"While configuring " + paramName + " for " + configName + ", " +
|
||||
"Unable to convert " + value.getClass() + " to " +
|
||||
type.getCanonicalName()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBConfiguration apply(Map<String, ?> config) {
|
||||
assertValidConfig(config);
|
||||
LinkedHashMap<String, Object> validConfig = new LinkedHashMap<>();
|
||||
|
||||
elements.forEach((k, v) -> {
|
||||
String name = v.getName();
|
||||
Class<?> type = v.getType();
|
||||
Object cval = config.get(name);
|
||||
if (cval == null && v.isRequired()) {
|
||||
cval = v.getDefaultValue();
|
||||
}
|
||||
if (cval != null) {
|
||||
cval = convertValueTo(ofType.getSimpleName(), k, cval, type);
|
||||
validConfig.put(name, cval);
|
||||
}
|
||||
});
|
||||
|
||||
return new NBConfiguration(this.asReadOnly(), validConfig);
|
||||
}
|
||||
|
||||
public ConfigModel validIfRegex(String s) {
|
||||
Pattern regex = Pattern.compile(s);
|
||||
lastAdded.setRegex(regex);
|
||||
return this;
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package io.nosqlbench.nb.api.config.standard;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface NBMapConfigurable extends NBCanValidateConfig {
|
||||
void applyConfig(Map<String, ?> providedConfig);
|
||||
}
|
@ -2,9 +2,7 @@ package io.nosqlbench.nb.api.config;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class MutableConfigModelTest {
|
||||
public class ConfigModelTest {
|
||||
|
||||
@Test
|
||||
void optional() {
|
||||
@ -49,4 +47,4 @@ public class MutableConfigModelTest {
|
||||
@Test
|
||||
void apply() {
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package io.nosqlbench.nb.api.config;
|
||||
|
||||
import io.nosqlbench.nb.api.config.params.Synonyms;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
Loading…
Reference in New Issue
Block a user