use canonical canonical NB naming

This commit is contained in:
Jonathan Shook 2021-02-04 17:47:18 -06:00
parent 9526208af8
commit 808a69ace7
6 changed files with 21 additions and 26 deletions

View File

@ -1,6 +1,6 @@
package io.nosqlbench.engine.cli;
import io.nosqlbench.nb.api.Environment;
import io.nosqlbench.nb.api.NBEnvironment;
import io.nosqlbench.nb.api.errors.BasicError;
import joptsimple.internal.Strings;
import org.apache.logging.log4j.Logger;
@ -254,7 +254,7 @@ public class NBCLIArgsFile {
List<String> interpolated = loaded.stream()
.map(p -> {
String q = Environment.INSTANCE.interpolate(p).orElse(p);
String q = NBEnvironment.INSTANCE.interpolate(p).orElse(p);
if (!q.equals(p)) {
if (logger != null) {
logger.info("argsfile: '" + argsPath.toString() + "': loaded option '" + p + "' as '" + q + "'");
@ -388,7 +388,7 @@ public class NBCLIArgsFile {
Path selected = null;
String[] possibles = argspath.split(":");
for (String possible : possibles) {
Optional<String> expanded = Environment.INSTANCE.interpolate(possible);
Optional<String> expanded = NBEnvironment.INSTANCE.interpolate(possible);
if (expanded.isPresent()) {
Path possiblePath = Path.of(expanded.get());
if (Files.exists(possiblePath)) {
@ -400,8 +400,8 @@ public class NBCLIArgsFile {
if (selected == null) {
String defaultFirst = possibles[0];
defaultFirst = Environment.INSTANCE.interpolate(defaultFirst)
.orElseThrow(() -> new RuntimeException("Invalid default argsfile: '" + possibles[0] + "'"));
defaultFirst = NBEnvironment.INSTANCE.interpolate(defaultFirst)
.orElseThrow(() -> new RuntimeException("Invalid default argsfile: '" + possibles[0] + "'"));
selected = Path.of(defaultFirst);
}

View File

@ -3,7 +3,7 @@ package io.nosqlbench.engine.cli;
import io.nosqlbench.engine.api.metrics.IndicatorMode;
import io.nosqlbench.engine.api.util.Unit;
import io.nosqlbench.engine.core.script.Scenario;
import io.nosqlbench.nb.api.Environment;
import io.nosqlbench.nb.api.NBEnvironment;
import io.nosqlbench.nb.api.errors.BasicError;
import io.nosqlbench.nb.api.logging.NBLogLevel;
@ -370,7 +370,7 @@ public class NBCLIOptions {
return this.statepath;
}
List<String> paths = Environment.INSTANCE.interpolate(":", statedirs);
List<String> paths = NBEnvironment.INSTANCE.interpolate(":", statedirs);
Path selected = null;
for (String pathName : paths) {
@ -399,7 +399,7 @@ public class NBCLIOptions {
}
}
Environment.INSTANCE.put(NBSTATEDIR, selected.toString());
NBEnvironment.INSTANCE.put(NBSTATEDIR, selected.toString());
return selected;
}

View File

@ -4,7 +4,7 @@ import io.nosqlbench.engine.clients.grafana.GrafanaClient;
import io.nosqlbench.engine.clients.grafana.GrafanaClientConfig;
import io.nosqlbench.engine.clients.grafana.transfer.GAnnotation;
import io.nosqlbench.nb.annotations.Service;
import io.nosqlbench.nb.api.Environment;
import io.nosqlbench.nb.api.NBEnvironment;
import io.nosqlbench.nb.api.OnError;
import io.nosqlbench.nb.api.SystemId;
import io.nosqlbench.nb.api.annotations.Annotation;
@ -138,8 +138,8 @@ public class GrafanaMetricsAnnotator implements Annotator, ConfigAware {
} else if (cfg.containsKey("apikey")) {
gc.addHeaderSource(() -> Map.of("Authorization", "Bearer " + cfg.param("apikey", String.class)));
} else {
Optional<String> apikeyLocation = Environment.INSTANCE
.interpolate(cfg.paramEnv("apikeyfile", String.class));
Optional<String> apikeyLocation = NBEnvironment.INSTANCE
.interpolate(cfg.paramEnv("apikeyfile", String.class));
keyfilePath = apikeyLocation.map(Path::of).orElseThrow();
}

View File

@ -2,7 +2,6 @@ package io.nosqlbench.nb.api;
import io.nosqlbench.nb.api.errors.BasicError;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import java.util.*;
import java.util.regex.Matcher;
@ -35,14 +34,14 @@ import java.util.regex.Pattern;
* The first location to return a non-null value is used. Null values are considered
* invalid in this API, except when provided as a default value.
*/
public class Environment {
public class NBEnvironment {
private Logger logger;
// package private for testing
Environment() {
NBEnvironment() {
}
public final static Environment INSTANCE = new Environment();
public final static NBEnvironment INSTANCE = new NBEnvironment();
private final LinkedHashMap<String, String> references = new LinkedHashMap<>();
@ -54,7 +53,7 @@ public class Environment {
"LOGNAME", "user.name" // *n*x
);
public Environment resetRefs() {
public NBEnvironment resetRefs() {
this.references.clear();
return this;
}
@ -124,11 +123,7 @@ public class Environment {
}
value = System.getenv(name);
if (value != null) {
return value;
}
return null;
return value;
}
/**

View File

@ -1,6 +1,6 @@
package io.nosqlbench.nb.api.config;
import io.nosqlbench.nb.api.Environment;
import io.nosqlbench.nb.api.NBEnvironment;
import java.util.LinkedHashMap;
import java.util.Optional;
@ -16,7 +16,7 @@ public class ConfigReader extends LinkedHashMap<String, Object> {
public <T> T paramEnv(String name, Class<? extends T> vclass) {
T param = param(name, vclass);
if (param instanceof String) {
Optional<String> interpolated = Environment.INSTANCE.interpolate(param.toString());
Optional<String> interpolated = NBEnvironment.INSTANCE.interpolate(param.toString());
if (interpolated.isEmpty()) {
throw new RuntimeException("Unable to interpolate env and sys props in '" + param + "'");
}

View File

@ -4,15 +4,15 @@ import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class EnvironmentTest {
public class NBEnvironmentTest {
@Test
public void testInterpolation() {
Environment env = new Environment();
NBEnvironment env = new NBEnvironment();
String home1 = env.interpolate("home is '$HOME'").orElse(null);
assertThat(home1).matches(".+");
String home2 = env.interpolate("home is '${home}'").orElse(null);
assertThat(home1).matches(".+");
}
}
}