Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starting Zilla with the CLI improvement #1042

Merged
merged 4 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -749,9 +749,10 @@ private void generateLauncher() throws IOException
"if [ -n \"$ZILLA_INCUBATOR_ENABLED\" ]; then",
"JAVA_OPTIONS=\"$JAVA_OPTIONS -Dzilla.incubator.enabled=$ZILLA_INCUBATOR_ENABLED\"",
"fi",
"cd \"${0%/*}\"",
"ZILLA_DIRECTORY=\"${0%/*}\"",
"JAVA_OPTIONS=\"$JAVA_OPTIONS -Dzilla.directory=$ZILLA_DIRECTORY\"",
String.format(String.join(" ", Arrays.asList(
"exec %s/bin/java",
"exec $ZILLA_DIRECTORY/%s/bin/java",
"--add-opens java.base/sun.nio.ch=org.agrona.core",
"$JAVA_OPTIONS",
"-m io.aklivity.zilla.runtime.command/io.aklivity.zilla.runtime.command.internal.ZillaMain \"$@\"")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static io.aklivity.zilla.runtime.engine.EngineConfiguration.ENGINE_DIRECTORY;
import static io.aklivity.zilla.runtime.engine.EngineConfiguration.ENGINE_VERBOSE;
import static io.aklivity.zilla.runtime.engine.EngineConfiguration.ENGINE_WORKERS;
import static io.aklivity.zilla.runtime.engine.EngineConfiguration.ZILLA_DIRECTORY_PROPERTY;
import static java.lang.Runtime.getRuntime;
import static org.agrona.LangUtil.rethrowUnchecked;

Expand All @@ -45,14 +46,15 @@
@Command(name = "start", description = "Start engine")
public final class ZillaStartCommand extends ZillaCommand
{
private static final String OPTION_PROPERTIES_PATH_DEFAULT = ".zilla/zilla.properties";
private static final String ZILLA_DIRECTORY = System.getProperty(ZILLA_DIRECTORY_PROPERTY, ".");
private static final String OPTION_PROPERTIES_PATH_DEFAULT = String.format("%s/.zilla/zilla.properties", ZILLA_DIRECTORY);
private static final String ZILLA_ENGINE_PATH_DEFAULT = String.format("%s/.zilla/engine", ZILLA_DIRECTORY);

private final CountDownLatch stop = new CountDownLatch(1);
private final CountDownLatch stopped = new CountDownLatch(1);

@Option(name = {"-c", "--config"},
description = "Configuration location",
hidden = true)
description = "Configuration location")
public URI configURI;

@Option(name = {"-v", "--verbose"},
Expand All @@ -64,26 +66,23 @@ public final class ZillaStartCommand extends ZillaCommand
public int workers = -1;

@Option(name = {"-P", "--property"},
description = "Property name=value",
hidden = true)
description = "Property name=value")
public List<String> properties;

@Option(name = {"-p", "--properties"},
description = "Path to properties",
hidden = true)
description = "Path to properties")
public String propertiesPath;

@Option(name = "-e",
description = "Show exception traces",
hidden = true)
@Option(name = {"-e", "--exception-traces"},
description = "Show exception traces")
public boolean exceptions;

@Override
public void run()
{
Runtime runtime = getRuntime();
Properties props = new Properties();
props.setProperty(ENGINE_DIRECTORY.name(), ".zilla/engine");
props.setProperty(ENGINE_DIRECTORY.name(), ZILLA_ENGINE_PATH_DEFAULT);

Path path = Paths.get(propertiesPath != null ? propertiesPath : OPTION_PROPERTIES_PATH_DEFAULT);
if (Files.exists(path) || propertiesPath != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
public class EngineConfiguration extends Configuration
{
public static final String ZILLA_NAME_PROPERTY = "zilla.name";
public static final String ZILLA_DIRECTORY_PROPERTY = "zilla.directory";

public static final boolean DEBUG_BUDGETS = Boolean.getBoolean("zilla.engine.debug.budgets");

Expand Down Expand Up @@ -82,7 +83,7 @@ public class EngineConfiguration extends Configuration
ENGINE_CONFIG_URL = config.property(URL.class, "config.url", EngineConfiguration::configURL, "file:zilla.yaml");
ENGINE_CONFIG_POLL_INTERVAL_SECONDS = config.property("config.poll.interval.seconds", 60);
ENGINE_NAME = config.property("name", EngineConfiguration::defaultName);
ENGINE_DIRECTORY = config.property("directory", ".");
ENGINE_DIRECTORY = config.property("directory", EngineConfiguration::defaultDirectory);
ENGINE_CACHE_DIRECTORY = config.property(Path.class, "cache.directory", EngineConfiguration::cacheDirectory, "cache");
ENGINE_HOST_RESOLVER = config.property(HostResolver.class, "host.resolver",
EngineConfiguration::decodeHostResolver, EngineConfiguration::defaultHostResolver);
Expand Down Expand Up @@ -319,7 +320,12 @@ private static URL configURL(
URL configURL = null;
try
{
configURL = URI.create(url).toURL();
URI uri = URI.create(url);
if (uri.getScheme() == null)
{
uri = URI.create(String.format("file:%s", url));
}
configURL = uri.toURL();
}
catch (MalformedURLException ex)
{
Expand Down Expand Up @@ -348,6 +354,12 @@ private static String defaultName(
return System.getProperty(ZILLA_NAME_PROPERTY, "zilla");
}

private static String defaultDirectory(
Configuration config)
{
return System.getProperty(ZILLA_DIRECTORY_PROPERTY, ".");
}

private static HostResolver decodeHostResolver(
Configuration config,
String value)
Expand Down