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 @@ -5,6 +5,7 @@

import io.deephaven.base.StringUtils;
import io.deephaven.configuration.Configuration;
import io.deephaven.configuration.DataDir;
import io.deephaven.engine.context.ExecutionContext;
import io.deephaven.engine.table.ColumnDefinition;
import io.deephaven.engine.table.Table;
Expand All @@ -17,6 +18,7 @@
import io.deephaven.benchmarking.impl.TableBackedBenchmarkTableBuilder;
import org.openjdk.jmh.infra.BenchmarkParams;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -257,8 +259,8 @@ public static String buildParameterString(BenchmarkParams params) {
return StringUtils.joinStrings(params.getParamsKeys().stream().map(params::getParam), ";");
}

public static String getLogPath() {
return Configuration.getInstance().getWorkspacePath();
public static Path dataDir() {
return DataDir.get();
}

public static final String DETAIL_LOG_PREFIX = "Details.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collection;
import org.openjdk.jmh.infra.BenchmarkParams;
Expand Down Expand Up @@ -52,7 +51,7 @@ public static void main(String[] args) throws IOException {
.build());
final Collection<RunResult> run = runner.run();
recordResults(run);
CsvResultWriter.recordResults(run, new File(BenchmarkTools.getLogPath() + File.separator + "Benchmark"));
CsvResultWriter.recordResults(run, BenchmarkTools.dataDir().resolve("Benchmark").toFile());
} catch (Throwable t) {
t.printStackTrace();
System.exit(1);
Expand Down Expand Up @@ -97,14 +96,14 @@ private static void recordResults(Collection<RunResult> results) {
final Table result = topLevel.naturalJoin(mergedDetails, "Benchmark,Mode,Run,Iteration,Params");

final Path outputPath =
Paths.get(BenchmarkTools.getLogPath()).resolve("Benchmark" + ParquetTableWriter.PARQUET_FILE_EXTENSION);
BenchmarkTools.dataDir().resolve("Benchmark" + ParquetTableWriter.PARQUET_FILE_EXTENSION);

ParquetTools.writeTable(result, outputPath.toFile(), result.getDefinition());
}

private static Table getMergedDetails() {
final File[] files = FileUtils.missingSafeListFiles(
new File(BenchmarkTools.getLogPath()),
BenchmarkTools.dataDir().toFile(),
file -> file.getName().startsWith(BenchmarkTools.DETAIL_LOG_PREFIX));
Arrays.sort(files, Utils.getModifiedTimeComparator(false));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;

public class TableBenchmarkState {
Expand All @@ -43,7 +42,7 @@ public void init() {
}

public void logOutput() throws IOException {
final Path outputPath = Paths.get(BenchmarkTools.getLogPath())
final Path outputPath = BenchmarkTools.dataDir()
.resolve(BenchmarkTools.getDetailOutputPath(benchmarkName) + ParquetTableWriter.PARQUET_FILE_EXTENSION);

final Table output = outputBuilder.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending
*/
package io.deephaven.configuration;

import java.nio.file.Path;

/**
* The cache directory is a directory that the application may use for storing data with "cache-like" semantics.
* Cache-like data is data that may be preserved across restarts, but the application logic should not make the
* assumptions that the data will be available.
*/
public final class CacheDir {
public static final String PROPERTY = "deephaven.cacheDir";
private static final String JAVA_IO_TMPDIR = "java.io.tmpdir";

/**
* Return the system property value for {@value CacheDir#PROPERTY} if it is present.
*
* <p>
* Otherwise, return "%s/deephaven/cache", parameterized from the value of the system property
* {@value JAVA_IO_TMPDIR}.
*
* @return the cache dir
*/
public static Path get() {
rcaudy marked this conversation as resolved.
Show resolved Hide resolved
final String explicitCacheDir = System.getProperty(PROPERTY);
return explicitCacheDir != null ? Path.of(explicitCacheDir)
: Path.of(System.getProperty(JAVA_IO_TMPDIR), "deephaven", "cache");
}

/**
* Gets the cache directory if the system property {@value #PROPERTY} is present, otherwise sets the system property
* {@value #PROPERTY} to {@code defaultValue} and returns {@code defaultValue}.
*
* @param defaultValue the value to set if none is present
* @return the cache directory
*/
public static Path getOrSet(String defaultValue) {
final String existing = System.getProperty(PROPERTY);
if (existing != null) {
return Path.of(existing);
}
System.setProperty(PROPERTY, defaultValue);
return Path.of(defaultValue);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending
*/
package io.deephaven.configuration;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;

public final class ConfigDir {
public static final String PROPERTY = "deephaven.configDir";
static final String ROOT_FILE_PROP = "Configuration.rootFile";
private static final String DEFAULT_CONFIG_FILE_NAME = "deephaven.prop";
rcaudy marked this conversation as resolved.
Show resolved Hide resolved
private static final String DEFAULT_CONFIGURATION_FILE = "dh-defaults.prop";

/**
* Gets the config directory by the system property {@value #PROPERTY} if present.
*
* @return the config directory
*/
public static Optional<Path> get() {
return Optional.ofNullable(System.getProperty(ConfigDir.PROPERTY)).map(Path::of);
}

/**
* Gets the config directory if the system property {@value #PROPERTY} is present, otherwise sets the system
* property {@value #PROPERTY} to {@code defaultValue} and returns {@code defaultValue}.
*
* @param defaultValue the value to set if none is present
* @return the config directory
*/
public static Path getOrSet(String defaultValue) {
final String existing = System.getProperty(PROPERTY);
if (existing != null) {
return Path.of(existing);
}
System.setProperty(PROPERTY, defaultValue);
return Path.of(defaultValue);
}

/**
* Gets the configuration file, first by the system property {@value #ROOT_FILE_PROP} if set; otherwise the filename
* {@value #DEFAULT_CONFIG_FILE_NAME} in {@link #get() the config directory} if the file exists; and otherwise
* returns {@value #DEFAULT_CONFIGURATION_FILE}.
*
* @return the configuration file
*/
public static String configurationFile() {
return Optional
.ofNullable(System.getProperty(ROOT_FILE_PROP))
.or(ConfigDir::configDirectoryFileIfExists)
.orElse(DEFAULT_CONFIGURATION_FILE);
}

private static Optional<String> configDirectoryFileIfExists() {
return get()
.map(ConfigDir::defaultFileName)
.filter(Files::exists)
.map(Path::toString);
}

private static Path defaultFileName(Path p) {
return p.resolve(DEFAULT_CONFIG_FILE_NAME);
}
}
Loading