support for --copy-workload

This commit is contained in:
Jonathan Shook 2020-04-06 03:04:46 -05:00
parent d887d3b8b4
commit cbcfa99ba8
2 changed files with 42 additions and 9 deletions

View File

@ -24,8 +24,12 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.stream.Collectors;
@ -69,7 +73,6 @@ public class NBCLI {
NBCLIOptions options = new NBCLIOptions(args);
ConsoleLogging.enableConsoleLogging(options.wantsConsoleLogLevel(), options.getConsoleLoggingPattern());
if (options.wantsBasicHelp()) {
System.out.println(loadHelpFile("basic.md"));
System.exit(0);
@ -90,11 +93,31 @@ public class NBCLI {
System.exit(0);
}
if (options.wantsWorkloads()) {
if (options.wantsScenariosList()) {
printWorkloads();
System.exit(0);
}
if (options.wantsToCopyWorkload()) {
String workloadToCopy = options.wantsToCopyWorkloadNamed();
logger.debug("user requests to copy out " + workloadToCopy);
Optional<Content<?>> tocopy = NBIO.classpath().prefix("activities").exact()
.name(workloadToCopy).extension("yaml").first();
Content<?> data = tocopy.orElseThrow(() -> new BasicError("Unable to find " + workloadToCopy + " in " +
"classpath to copy out"));
Path writeTo = Path.of(data.asPath().getFileName().toString());
if (Files.exists(writeTo)) {
throw new BasicError("A file named " + writeTo.toString() + " exists. Remove it first.");
}
try {
Files.writeString(writeTo,data.getCharBuffer(), StandardCharsets.UTF_8);
} catch (IOException e) {
throw new BasicError("Unable to write to " + writeTo.toString() + ": " + e.getMessage());
}
}
if (options.wantsInputTypes()) {
InputType.FINDER.getAll().stream().map(InputType::getName).forEach(System.out::println);
System.exit(0);
@ -243,7 +266,7 @@ public class NBCLI {
for (String scenario : scenarioList) {
if (scenario.equals("default")) {
scenario = scenario + " # same as running ./nb " + workloadName ;
scenario = scenario + "\n # same as running ./nb " + workloadName ;
}
System.out.println(" ./nb " + workloadName + " " + scenario);
}
@ -256,7 +279,6 @@ public class NBCLI {
.forEach(System.out::println);
}
}
}
private String loadHelpFile(String filename) {

View File

@ -26,12 +26,14 @@ public class NBCLIOptions {
private static final String METRICS = "--list-metrics";
private static final String DRIVER_TYPES = "--list-drivers";
private static final String ACTIVITY_TYPES = "--list-activity-types";
private static final String WORKLOADS = "--list-workloads";
private static final String LIST_WORKLOADS = "--list-workloads";
private static final String LIST_SCENARIOS = "--list-scenarios";
private static final String WANTS_INPUT_TYPES = "--list-input-types";
private static final String WANTS_OUTPUT_TYPES = "--list-output-types";
private static final String WANTS_VERSION_COORDS = "--version-coords";
private static final String WANTS_VERSION_SHORT = "--version";
private static final String SHOW_SCRIPT = "--show-script";
private static final String COPY_WORKLOAD = "--copy-workload";
// Execution
private static final String SCRIPT = "script";
@ -108,7 +110,8 @@ public class NBCLIOptions {
private Map<String, Level> logLevelsOverrides = new HashMap<>();
private boolean enableChart = false;
private boolean dockerMetrics = false;
private boolean wantsWorkloads = false;
private boolean wantsScenariosList = false;
private String wantsToCopyWorkload = null;
public NBCLIOptions(String[] args) {
parse(args);
@ -299,7 +302,7 @@ public class NBCLIOptions {
break;
case WORKLOADS:
arglist.removeFirst();
wantsWorkloads = true;
wantsToCopyWorkload = readWordOrThrow(arglist, "workload to copy");
break;
default:
Optional<InputStream> optionalScript =
@ -551,8 +554,16 @@ public class NBCLIOptions {
histoLoggerConfigs.add(String.format("%s:%s:%s", file, pattern, interval));
}
public boolean wantsWorkloads() {
return wantsWorkloads;
public boolean wantsScenariosList() {
return wantsScenariosList;
}
public boolean wantsToCopyWorkload() {
return wantsToCopyWorkload!=null;
}
public String wantsToCopyWorkloadNamed() {
return wantsToCopyWorkload;
}
public static enum CmdType {