mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
improve error for driver adapter not found
This commit is contained in:
parent
a6df79c322
commit
a05dbc834a
@ -26,6 +26,7 @@ import io.nosqlbench.engine.core.annotation.Annotators;
|
|||||||
import io.nosqlbench.nb.annotations.Maturity;
|
import io.nosqlbench.nb.annotations.Maturity;
|
||||||
import io.nosqlbench.nb.api.annotations.Annotation;
|
import io.nosqlbench.nb.api.annotations.Annotation;
|
||||||
import io.nosqlbench.nb.api.annotations.Layer;
|
import io.nosqlbench.nb.api.annotations.Layer;
|
||||||
|
import io.nosqlbench.nb.api.config.standard.ConfigSuggestions;
|
||||||
import io.nosqlbench.nb.api.errors.BasicError;
|
import io.nosqlbench.nb.api.errors.BasicError;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
@ -323,7 +324,12 @@ public class ScenarioController {
|
|||||||
.setMaturity(this.minMaturity)
|
.setMaturity(this.minMaturity)
|
||||||
.load(activityDef)
|
.load(activityDef)
|
||||||
.orElseThrow(
|
.orElseThrow(
|
||||||
() -> new RuntimeException("Driver for '" + activityDef + "' was not found.")
|
() -> new RuntimeException("Driver for '" + activityDef + "' was not found." +
|
||||||
|
"\nYou can use --list-drivers to see what drivers are supported in this runtime." +
|
||||||
|
ConfigSuggestions.suggestAlternates(
|
||||||
|
new ActivityTypeLoader().getAllSelectors(),activityDef.getActivityType(),4)
|
||||||
|
.orElse("")
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
executor = new ActivityExecutor(
|
executor = new ActivityExecutor(
|
||||||
|
@ -24,25 +24,51 @@ import java.util.stream.Collectors;
|
|||||||
public class ConfigSuggestions {
|
public class ConfigSuggestions {
|
||||||
|
|
||||||
public static Optional<String> getForParam(ConfigModel model, String param) {
|
public static Optional<String> getForParam(ConfigModel model, String param) {
|
||||||
return suggestAlternateCase(model,param)
|
return suggestAlternateCase(model, param)
|
||||||
.or(() -> suggestAlternates(model,param,4));
|
.or(() -> suggestAlternates(model, param, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Optional<String> suggestAlternateCase(ConfigModel model, String param) {
|
private static Optional<String> suggestAlternateCase(ConfigModel model, String param) {
|
||||||
for (String cname : model.getNamedParams().keySet()) {
|
for (String cname : model.getNamedParams().keySet()) {
|
||||||
if (cname.equalsIgnoreCase(param)) {
|
if (cname.equalsIgnoreCase(param)) {
|
||||||
return Optional.of("Did you mean '" + cname + "'?");
|
return Optional.of(" Did you mean '" + cname + "'?");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Optional<String> suggestAlternates(ConfigModel model, String param, int maxDistance) {
|
public static Optional<String> suggestAlternates(Set<String> candidates, String provided, int maxDistance) {
|
||||||
|
Set<String>[] sorted = new Set[maxDistance+1];
|
||||||
|
for (int i = 0; i < sorted.length; i++) {
|
||||||
|
sorted[i]=new HashSet<String>();
|
||||||
|
}
|
||||||
|
for (String candidate : candidates) {
|
||||||
|
int distance = LevenshteinDistance.getDefaultInstance().apply(provided, candidate);
|
||||||
|
if (distance<=maxDistance) {
|
||||||
|
sorted[distance].add(candidate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (Set<String> set : sorted) {
|
||||||
|
if (set.size()>1) {
|
||||||
|
return Optional.of(" Did you mean one of '" + String.join("','", set) + "' ?");
|
||||||
|
} else if (set.size()==1) {
|
||||||
|
return Optional.of(" Did you mean '" + set.stream().findFirst().get() + "' ?");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Optional<String> suggestAlternates(
|
||||||
|
ConfigModel model,
|
||||||
|
String param,
|
||||||
|
int maxDistance
|
||||||
|
) {
|
||||||
Map<Integer, Set<String>> suggestions = new HashMap<>();
|
Map<Integer, Set<String>> suggestions = new HashMap<>();
|
||||||
|
|
||||||
for (String candidate : model.getNamedParams().keySet()) {
|
for (String candidate : model.getNamedParams().keySet()) {
|
||||||
try {
|
try {
|
||||||
Integer distance = LevenshteinDistance.getDefaultInstance().apply(param, candidate);
|
Integer distance = LevenshteinDistance.getDefaultInstance().apply(param, candidate);
|
||||||
if (distance>maxDistance) {
|
if (distance > maxDistance) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Set<String> strings = suggestions.computeIfAbsent(distance, d -> new HashSet<>());
|
Set<String> strings = suggestions.computeIfAbsent(distance, d -> new HashSet<>());
|
||||||
@ -55,12 +81,12 @@ public class ConfigSuggestions {
|
|||||||
ArrayList<Integer> params = new ArrayList<>(suggestions.keySet());
|
ArrayList<Integer> params = new ArrayList<>(suggestions.keySet());
|
||||||
Collections.sort(params);
|
Collections.sort(params);
|
||||||
List<Set<String>> orderedSets = params.stream().map(suggestions::get).collect(Collectors.toList());
|
List<Set<String>> orderedSets = params.stream().map(suggestions::get).collect(Collectors.toList());
|
||||||
if (orderedSets.size()==0) {
|
if (orderedSets.size() == 0) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
} else if (orderedSets.get(0).size()==1) {
|
} else if (orderedSets.get(0).size() == 1) {
|
||||||
return Optional.of("Did you mean '" + orderedSets.get(0).stream().findFirst().get() +"'?");
|
return Optional.of(" Did you mean '" + orderedSets.get(0).stream().findFirst().get() + "'?");
|
||||||
} else {
|
} else {
|
||||||
return Optional.of("Did you mean one of " + orderedSets.get(0).toString() + "?\n");
|
return Optional.of(" Did you mean one of " + orderedSets.get(0).toString() + "?\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user