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

Simplify Configuration #3035

Merged
merged 7 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -3,6 +3,7 @@
*/
package io.deephaven.configuration;

import io.deephaven.internal.log.Bootstrap;
import io.deephaven.io.logger.Logger;
import io.deephaven.internal.log.LoggerFactory;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -52,7 +53,7 @@ protected Configuration() {
}
// The quiet property is available because things like shell scripts may be parsing our System.out and they
// don't want to have to deal with these log messages
if (System.getProperty(QUIET_PROPERTY) == null) {
if (!isQuiet()) {
log.info().append("Configuration: configuration file is ").append(configurationFile).endl();
}
}
Expand Down Expand Up @@ -311,4 +312,8 @@ private static void writeLine(StringBuilder out, String sKey, String sLeftValue,
out.append(sKey).append(", \"").append(sLeftValue).append("\", \"").append(sRightValue).append("\", \"")
.append(sRightValue2).append("\"\n");
}

static boolean isQuiet() {
return Bootstrap.isQuiet() || System.getProperty(QUIET_PROPERTY) != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
import org.apache.commons.lang3.StringEscapeUtils;
import org.jetbrains.annotations.NotNull;

import static io.deephaven.configuration.Configuration.QUIET_PROPERTY;

/**
* Class for reading in a customized properties file, applying only the locally-relevant properties and keeping track of
* which properties may not be further modified. Maintains the ordering of the properties from the input file.
Expand Down Expand Up @@ -647,7 +645,7 @@ private String stringScope() {
*
*/
public synchronized void load(String fileName) throws IOException, ConfigurationException {
if (System.getProperty(QUIET_PROPERTY) == null) {
if (!Configuration.isQuiet()) {
log.info("Loading " + fileName);
}
thisFile = fileName;
Expand Down
16 changes: 10 additions & 6 deletions log-factory/src/main/java/io/deephaven/internal/log/Bootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
*/
package io.deephaven.internal.log;

class Bootstrap {
private static boolean isEnabled() {
return Boolean.parseBoolean(
System.getProperty("io.deephaven.internal.log.Bootstrap.enabled", "true"));
public final class Bootstrap {

public static boolean isQuiet() {
return Boolean.getBoolean("deephaven.quiet");
}

public static void log(Class<?> source, String message) {
if (isEnabled()) {
System.out.printf("# %s: %s%n", source.getName(), message);
printf("# %s: %s%n", source.getName(), message);
}

public static void printf(String format, Object ... args) {
if (!isQuiet()) {
System.out.printf(format, args);
rcaudy marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.deephaven.configuration.Configuration;
import io.deephaven.engine.util.ScriptSession;
import io.deephaven.integrations.python.PyLogOutputStream;
import io.deephaven.internal.log.Bootstrap;
import io.deephaven.io.log.LogLevel;
import io.deephaven.io.logger.LogBuffer;
import io.deephaven.io.logger.LogBufferOutputStream;
Expand Down Expand Up @@ -105,7 +106,7 @@ public void start() throws Exception {

final ScriptSession scriptSession = this.scriptSession.get();
checkGlobals(scriptSession, null);
System.out.println("Server started on port " + server.server().getPort());
Bootstrap.printf("Server started on port %d%n", server.server().getPort());

// We need to open the systemic execution context to permanently install the contexts for this thread.
scriptSession.getExecutionContext().open();
Expand Down
4 changes: 4 additions & 0 deletions server/jetty-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ if (hasProperty('gcApplication')) {
extraJvmArgs += ['-Dio.deephaven.app.GcApplication.enabled=true']
}

if (hasProperty('quiet')) {
extraJvmArgs += ['-Ddeephaven.quiet=true']
}

tasks.withType(JavaExec).configureEach {
// This appends to the existing jvm args, so that java-open-nio still takes effect
jvmArgs extraJvmArgs
Expand Down
4 changes: 4 additions & 0 deletions server/netty-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ if (hasProperty('gcApplication')) {
extraJvmArgs += ['-Dio.deephaven.app.GcApplication.enabled=true']
}

if (hasProperty('quiet')) {
extraJvmArgs += ['-Ddeephaven.quiet=true']
}

tasks.withType(JavaExec).configureEach {
// This appends to the existing jvm args, so that java-open-nio still takes effect
jvmArgs extraJvmArgs
Expand Down
9 changes: 5 additions & 4 deletions server/src/main/java/io/deephaven/server/runner/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.deephaven.configuration.ConfigDir;
import io.deephaven.configuration.Configuration;
import io.deephaven.configuration.DataDir;
import io.deephaven.internal.log.Bootstrap;
import io.deephaven.internal.log.LoggerFactory;
import io.deephaven.io.logger.LogBufferGlobal;
import io.deephaven.io.logger.LogBufferInterceptor;
Expand Down Expand Up @@ -52,11 +53,11 @@ private static void bootstrapSystemProperties(String[] args) throws IOException
bootstrapFromFile(Path.of(args[0]));
return;
}
System.out.println("# No argument, skipping bootstrapping");
Bootstrap.printf("# No argument, skipping bootstrapping%n");
}

private static void bootstrapFromFile(Path configFile) throws IOException {
System.out.printf("# Bootstrapping from file '%s'%n", configFile);
Bootstrap.printf("# Bootstrapping from file '%s'%n", configFile);
try (final Reader reader = Files.newBufferedReader(configFile, StandardCharsets.UTF_8)) {
rcaudy marked this conversation as resolved.
Show resolved Hide resolved
System.getProperties().load(reader);
}
Expand All @@ -76,7 +77,7 @@ private static void bootstrapProjectDirectories() throws IOException {
Files.createDirectories(cacheDir);
Files.createDirectories(dataDir);

System.out.printf("%s=%s%n%s=%s%n%s=%s%n",
Bootstrap.printf("%s=%s%n%s=%s%n%s=%s%n",
CacheDir.PROPERTY,
cacheDir,
ConfigDir.PROPERTY,
Expand All @@ -95,7 +96,7 @@ private static void bootstrapProjectDirectories() throws IOException {
*/
@NotNull
public static Configuration init(String[] args, Class<?> mainClass) throws IOException {
System.out.printf("# Starting %s%n", mainClass.getName());
Bootstrap.printf("# Starting %s%n", mainClass.getName());

// No classes should be loaded before we bootstrap additional system properties
bootstrapSystemProperties(args);
Expand Down