Skip to content

Commit

Permalink
Make launcher commands callable
Browse files Browse the repository at this point in the history
  • Loading branch information
wendigo authored and losipiuk committed Sep 14, 2020
1 parent a482e37 commit b140166
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
import io.airlift.bootstrap.Bootstrap;

import java.util.List;
import java.util.concurrent.Callable;

final class Commands
{
private Commands() {}

public static void runCommand(List<Module> modules, Class<? extends Runnable> commandExecution)
public static int runCommand(List<Module> modules, Class<? extends Callable<Integer>> commandExecution)
{
Bootstrap app = new Bootstrap(
ImmutableList.<Module>builder()
Expand All @@ -36,7 +37,12 @@ public static void runCommand(List<Module> modules, Class<? extends Runnable> co
.strictConfig()
.initialize();

injector.getInstance(commandExecution)
.run();
try {
return injector.getInstance(commandExecution)
.call();
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.prestosql.tests.product.launcher.env.EnvironmentFactory;
import io.prestosql.tests.product.launcher.env.EnvironmentModule;
import io.prestosql.tests.product.launcher.env.EnvironmentOptions;
import picocli.CommandLine.ExitCode;
import picocli.CommandLine.Option;

import javax.inject.Inject;
Expand All @@ -30,6 +31,7 @@
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.concurrent.Callable;

import static io.prestosql.tests.product.launcher.cli.Commands.runCommand;
import static java.util.Objects.requireNonNull;
Expand All @@ -40,7 +42,7 @@
description = "List environments",
usageHelpAutoWidth = true)
public final class EnvironmentList
implements Runnable
implements Callable<Integer>
{
@Option(names = {"-h", "--help"}, usageHelp = true, description = "Show this help message and exit")
public boolean usageHelpRequested;
Expand All @@ -53,9 +55,9 @@ public EnvironmentList(Extensions extensions)
}

@Override
public void run()
public Integer call()
{
runCommand(
return runCommand(
ImmutableList.<Module>builder()
.add(new LauncherModule())
.add(new EnvironmentModule(EnvironmentOptions.empty(), additionalEnvironments))
Expand All @@ -64,7 +66,7 @@ public void run()
}

public static class Execution
implements Runnable
implements Callable<Integer>
{
private final PrintStream out;
private final EnvironmentFactory factory;
Expand All @@ -85,13 +87,15 @@ public Execution(EnvironmentFactory factory, EnvironmentConfigFactory configFact
}

@Override
public void run()
public Integer call()
{
out.println("Available environments: ");
this.factory.list().forEach(out::println);

out.println("\nAvailable environment configs: ");
this.configFactory.listConfigs().forEach(out::println);

return ExitCode.OK;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@
import io.prestosql.tests.product.launcher.env.common.Standard;
import org.testcontainers.DockerClientFactory;
import picocli.CommandLine.Command;
import picocli.CommandLine.ExitCode;

import javax.inject.Inject;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Path;
import java.util.Optional;
import java.util.concurrent.Callable;

import static io.prestosql.tests.product.launcher.cli.Commands.runCommand;
import static io.prestosql.tests.product.launcher.env.EnvironmentContainers.COORDINATOR;
Expand All @@ -53,7 +55,7 @@
description = "Start an environment",
usageHelpAutoWidth = true)
public final class EnvironmentUp
implements Runnable
implements Callable<Integer>
{
private static final Logger log = Logger.get(EnvironmentUp.class);
private static final String LOGS_DIR = "logs/";
Expand All @@ -75,9 +77,9 @@ public EnvironmentUp(Extensions extensions)
}

@Override
public void run()
public Integer call()
{
runCommand(
return runCommand(
ImmutableList.<Module>builder()
.add(new LauncherModule())
.add(new EnvironmentModule(environmentOptions, additionalEnvironments))
Expand All @@ -104,7 +106,7 @@ public Module toModule()
}

public static class Execution
implements Runnable
implements Callable<Integer>
{
private final EnvironmentFactory environmentFactory;
private final boolean withoutPrestoMaster;
Expand All @@ -127,7 +129,7 @@ public Execution(EnvironmentFactory environmentFactory, EnvironmentConfig enviro
}

@Override
public void run()
public Integer call()
{
log.info("Pruning old environment(s)");
Environments.pruneEnvironment();
Expand All @@ -154,11 +156,13 @@ public void run()

if (background) {
killContainersReaperContainer();
return;
return ExitCode.OK;
}

environment.awaitContainersStopped();
log.info("Exiting, the containers will exit too");

return ExitCode.OK;
}

private void killContainersReaperContainer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,20 @@
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.nio.file.Paths;
import java.util.concurrent.Callable;

import static io.prestosql.tests.product.launcher.cli.Commands.runCommand;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;
import static picocli.CommandLine.ExitCode.OK;
import static picocli.CommandLine.Option;

@Command(
name = "describe",
description = "Describe tests suite",
usageHelpAutoWidth = true)
public class SuiteDescribe
implements Runnable
implements Callable<Integer>
{
private final Module additionalSuites;
private final Module additionalEnvironments;
Expand All @@ -69,9 +71,9 @@ public SuiteDescribe(Extensions extensions)
}

@Override
public void run()
public Integer call()
{
runCommand(
return runCommand(
ImmutableList.<Module>builder()
.add(new LauncherModule())
.add(new SuiteModule(additionalSuites))
Expand All @@ -98,7 +100,7 @@ public Module toModule()
}

public static class Execution
implements Runnable
implements Callable<Integer>
{
private final String suiteName;
private final File testJar;
Expand Down Expand Up @@ -131,7 +133,7 @@ public Execution(
}

@Override
public void run()
public Integer call()
{
Suite suite = suiteFactory.getSuite(suiteName);
EnvironmentConfig config = configFactory.getConfig(this.config);
Expand All @@ -142,6 +144,8 @@ public void run()
TestRun.TestRunOptions runOptions = createTestRunOptions(suiteName, testRun, config);
out.println(format("\npresto-product-tests-launcher/bin/run-launcher test run %s\n", OptionsPrinter.format(environmentOptions, runOptions)));
}

return OK;
}

private TestRun.TestRunOptions createTestRunOptions(String suiteName, SuiteTestRun suiteTestRun, EnvironmentConfig environmentConfig)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.prestosql.tests.product.launcher.suite.SuiteFactory;
import io.prestosql.tests.product.launcher.suite.SuiteModule;
import picocli.CommandLine.Command;
import picocli.CommandLine.ExitCode;
import picocli.CommandLine.Option;

import javax.inject.Inject;
Expand All @@ -33,6 +34,7 @@
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.concurrent.Callable;

import static io.prestosql.tests.product.launcher.cli.Commands.runCommand;
import static java.util.Objects.requireNonNull;
Expand All @@ -42,7 +44,7 @@
description = "List tests suite",
usageHelpAutoWidth = true)
public final class SuiteList
implements Runnable
implements Callable<Integer>
{
private final Module additionalEnvironments;
private final Module additionalSuites;
Expand All @@ -57,9 +59,9 @@ public SuiteList(Extensions extensions)
}

@Override
public void run()
public Integer call()
{
runCommand(
return runCommand(
ImmutableList.<Module>builder()
.add(new LauncherModule())
.add(new EnvironmentModule(EnvironmentOptions.empty(), additionalEnvironments))
Expand All @@ -69,7 +71,7 @@ public void run()
}

public static class Execution
implements Runnable
implements Callable<Integer>
{
private final PrintStream out;
private final EnvironmentConfigFactory configFactory;
Expand All @@ -90,13 +92,15 @@ public Execution(SuiteFactory suiteFactory, EnvironmentConfigFactory configFacto
}

@Override
public void run()
public Integer call()
{
out.println("Available suites: ");
this.suiteFactory.listSuites().forEach(out::println);

out.println("\nAvailable environment configs: ");
this.configFactory.listConfigs().forEach(out::println);

return ExitCode.OK;
}
}
}
Loading

0 comments on commit b140166

Please sign in to comment.