diff --git a/community/server/src/main/java/org/neo4j/server/ServerCommandLineArgs.java b/community/server/src/main/java/org/neo4j/server/ServerCommandLineArgs.java index c1c2cc42bb31d..ae03bbe30fac7 100644 --- a/community/server/src/main/java/org/neo4j/server/ServerCommandLineArgs.java +++ b/community/server/src/main/java/org/neo4j/server/ServerCommandLineArgs.java @@ -25,7 +25,7 @@ import org.neo4j.helpers.Args; import org.neo4j.helpers.collection.Pair; import org.neo4j.kernel.impl.util.Converters; -import org.neo4j.server.configuration.ServerSettings; +import org.neo4j.server.configuration.ConfigLoader; import static org.neo4j.helpers.collection.Pair.pair; @@ -41,21 +41,20 @@ */ public class ServerCommandLineArgs { - static final String CONFIG_KEY_ALT_1 = "config"; - static final String CONFIG_KEY_ALT_2 = "C"; - private final File configFile; + private static final String CONFIG_DIR_ARG = "config-dir"; + private final Args args; private final Pair[] configOverrides; - private ServerCommandLineArgs( File configFile, Pair[] configOverrides ) + private ServerCommandLineArgs( Args args, Pair[] configOverrides ) { - this.configFile = configFile; + this.args = args; this.configOverrides = configOverrides; } public static ServerCommandLineArgs parse( String[] argv ) { Args args = Args.parse( argv ); - return new ServerCommandLineArgs( detemineConfigFile( args ), parseConfigOverrides( args ) ); + return new ServerCommandLineArgs( args, parseConfigOverrides( args ) ); } public Pair[] configOverrides() @@ -65,13 +64,11 @@ public Pair[] configOverrides() public File configFile() { - return configFile; - } - - private static File detemineConfigFile( Args arguments ) - { - return new File( arguments.get( CONFIG_KEY_ALT_2, - arguments.get( CONFIG_KEY_ALT_1, ServerSettings.SERVER_CONFIG_FILE ) ) ); + if ( !args.has( CONFIG_DIR_ARG ) ) + { + return null; + } + return new File( new File( args.get( CONFIG_DIR_ARG ) ), ConfigLoader.DEFAULT_CONFIG_FILE_NAME ); } private static Pair[] parseConfigOverrides( Args arguments ) diff --git a/community/server/src/main/java/org/neo4j/server/configuration/ConfigLoader.java b/community/server/src/main/java/org/neo4j/server/configuration/ConfigLoader.java index 3bba679430654..c8480ab1d9a0d 100644 --- a/community/server/src/main/java/org/neo4j/server/configuration/ConfigLoader.java +++ b/community/server/src/main/java/org/neo4j/server/configuration/ConfigLoader.java @@ -36,6 +36,8 @@ public class ConfigLoader { + public static final String DEFAULT_CONFIG_FILE_NAME = "neo4j.conf"; + private final SettingsClasses settingsClasses; public ConfigLoader( SettingsClasses settingsClasses ) diff --git a/community/server/src/test/java/org/neo4j/server/BaseBootstrapperTest.java b/community/server/src/test/java/org/neo4j/server/BaseBootstrapperTest.java index 3b867d85c271d..e3508d5211c7b 100644 --- a/community/server/src/test/java/org/neo4j/server/BaseBootstrapperTest.java +++ b/community/server/src/test/java/org/neo4j/server/BaseBootstrapperTest.java @@ -31,6 +31,7 @@ import org.junit.rules.TemporaryFolder; import org.neo4j.graphdb.config.Setting; +import org.neo4j.server.configuration.ConfigLoader; import org.neo4j.test.server.ExclusiveServerTestBase; import static org.hamcrest.Matchers.equalTo; @@ -98,7 +99,7 @@ public void shouldStartStopNeoServerWithoutAnyConfigFiles() throws IOException public void canSpecifyConfigFile() throws Throwable { // Given - File configFile = tempDir.newFile( "neo4j.config" ); + File configFile = tempDir.newFile( ConfigLoader.DEFAULT_CONFIG_FILE_NAME ); Map properties = stringMap( forced_kernel_id.name(), "ourcustomvalue" ); properties.putAll( ServerTestUtils.getDefaultRelativeProperties() ); @@ -107,7 +108,7 @@ public void canSpecifyConfigFile() throws Throwable store( properties, configFile ); // When - ServerBootstrapper.start( bootstrapper, "-C", configFile.getAbsolutePath() ); + ServerBootstrapper.start( bootstrapper, "--config-dir", configFile.getParentFile().getAbsolutePath() ); // Then assertThat( bootstrapper.getServer().getConfig().get( forced_kernel_id ), equalTo( "ourcustomvalue" ) ); @@ -117,7 +118,7 @@ public void canSpecifyConfigFile() throws Throwable public void canOverrideConfigValues() throws Throwable { // Given - File configFile = tempDir.newFile( "neo4j.config" ); + File configFile = tempDir.newFile( ConfigLoader.DEFAULT_CONFIG_FILE_NAME); Map properties = stringMap( forced_kernel_id.name(), "thisshouldnotshowup" ); properties.putAll( ServerTestUtils.getDefaultRelativeProperties() ); @@ -127,7 +128,7 @@ public void canOverrideConfigValues() throws Throwable // When ServerBootstrapper.start( bootstrapper, - "-C", configFile.getAbsolutePath(), + "--config-dir", configFile.getParentFile().getAbsolutePath(), "-c", configOption( forced_kernel_id, "mycustomvalue" ) ); // Then diff --git a/community/server/src/test/java/org/neo4j/server/ServerCommandLineArgsTest.java b/community/server/src/test/java/org/neo4j/server/ServerCommandLineArgsTest.java index fd3affb6ddec4..0ae005fc060df 100644 --- a/community/server/src/test/java/org/neo4j/server/ServerCommandLineArgsTest.java +++ b/community/server/src/test/java/org/neo4j/server/ServerCommandLineArgsTest.java @@ -24,6 +24,7 @@ import org.junit.Test; import org.neo4j.helpers.collection.Pair; +import org.neo4j.server.configuration.ConfigLoader; import static org.junit.Assert.assertEquals; @@ -35,21 +36,15 @@ public class ServerCommandLineArgsTest @Test public void shouldPickUpSpecifiedConfigFile() throws Exception { - shouldPickUpSpecifiedConfigFile( ServerCommandLineArgs.CONFIG_KEY_ALT_1 ); - shouldPickUpSpecifiedConfigFile( ServerCommandLineArgs.CONFIG_KEY_ALT_2 ); + File expectedFile = new File( "some-dir/" + ConfigLoader.DEFAULT_CONFIG_FILE_NAME ); + assertEquals( expectedFile, parse( "--config-dir", "some-dir" ).configFile() ); + assertEquals( expectedFile, parse( "--config-dir=some-dir" ).configFile() ); } - public void shouldPickUpSpecifiedConfigFile( String key ) + @Test + public void shouldReturnNullIfConfigDirIsNotSpecified() { - // GIVEN - String customConfigFile = "MyConfigFile"; - String[] args = array( "--" + key, customConfigFile ); - - // WHEN - ServerCommandLineArgs parsed = ServerCommandLineArgs.parse( args ); - - // THEN - assertEquals( new File( customConfigFile ), parsed.configFile() ); + assertEquals( null, parse().configFile() ); } @Test @@ -94,10 +89,15 @@ public void shouldPickUpMultipleOverriddenConfigurationParameters() throws Excep // THEN assertEquals( asSet( - Pair.of( "my_first_option", "first" ), - Pair.of( "myoptionenabled", Boolean.TRUE.toString() ), - Pair.of( "my_second_option", "second" ) ), + Pair.of( "my_first_option", "first" ), + Pair.of( "myoptionenabled", Boolean.TRUE.toString() ), + Pair.of( "my_second_option", "second" ) ), asSet( parsed.configOverrides() ) ); } + + private ServerCommandLineArgs parse( String... args ) + { + return ServerCommandLineArgs.parse( args ); + } } diff --git a/enterprise/server-enterprise/src/main/java/org/neo4j/server/enterprise/ArbiterEntryPoint.java b/enterprise/server-enterprise/src/main/java/org/neo4j/server/enterprise/ArbiterEntryPoint.java index f7ee4d40e1787..b0efc9f5ee6b6 100644 --- a/enterprise/server-enterprise/src/main/java/org/neo4j/server/enterprise/ArbiterEntryPoint.java +++ b/enterprise/server-enterprise/src/main/java/org/neo4j/server/enterprise/ArbiterEntryPoint.java @@ -19,21 +19,21 @@ */ package org.neo4j.server.enterprise; -import java.io.File; import java.io.IOException; import org.neo4j.server.BlockingBootstrapper; import org.neo4j.server.Bootstrapper; import org.neo4j.server.ServerBootstrapper; -import org.neo4j.server.configuration.ServerSettings; +import org.neo4j.server.ServerCommandLineArgs; public class ArbiterEntryPoint { private static Bootstrapper bootstrapper; - public static void main( String[] args ) throws IOException + public static void main( String[] argv ) throws IOException { - int status = new ArbiterBootstrapper().start( getConfigFile() ); + ServerCommandLineArgs args = ServerCommandLineArgs.parse( argv ); + int status = new ArbiterBootstrapper().start( args.configFile() ); if ( status != 0 ) { System.exit( status ); @@ -53,21 +53,4 @@ public static void stop( @SuppressWarnings("UnusedParameters") String[] args ) bootstrapper.stop(); } } - - static File getConfigFile() - { - String configPath = System.getProperty( ServerSettings.SERVER_CONFIG_FILE_KEY ); - if ( configPath == null ) - { - throw new RuntimeException( "System property " + ServerSettings.SERVER_CONFIG_FILE_KEY + - " must be provided" ); - } - - File configFile = new File( configPath ); - if ( !configFile.exists() ) - { - throw new IllegalArgumentException( configFile + " doesn't exist" ); - } - return configFile; - } } diff --git a/enterprise/server-enterprise/src/test/java/org/neo4j/server/enterprise/ArbiterBootstrapperTestProxy.java b/enterprise/server-enterprise/src/test/java/org/neo4j/server/enterprise/ArbiterBootstrapperTestProxy.java index b9b6b0f723a0d..7eb6618f8a4f2 100644 --- a/enterprise/server-enterprise/src/test/java/org/neo4j/server/enterprise/ArbiterBootstrapperTestProxy.java +++ b/enterprise/server-enterprise/src/test/java/org/neo4j/server/enterprise/ArbiterBootstrapperTestProxy.java @@ -21,19 +21,23 @@ import java.io.IOException; +import org.neo4j.server.ServerCommandLineArgs; + public class ArbiterBootstrapperTestProxy { public static final String START_SIGNAL = "starting"; - public static void main( String[] args ) throws IOException + public static void main( String[] argv ) throws IOException { + ServerCommandLineArgs args = ServerCommandLineArgs.parse( argv ); + // This sysout will be intercepted by the parent process and will trigger // a start of a timeout. The whole reason for this class to be here is to // split awaiting for the process to start and actually awaiting the cluster client to start. System.out.println( START_SIGNAL ); try ( ArbiterBootstrapper arbiter = new ArbiterBootstrapper() ) { - arbiter.start( ArbiterEntryPoint.getConfigFile() ); + arbiter.start( args.configFile() ); System.in.read(); } }