Skip to content

Commit

Permalink
Use command line argument instead of system property to specify config
Browse files Browse the repository at this point in the history
  • Loading branch information
benbc committed Mar 22, 2016
1 parent 3972c9d commit 81740f8
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 89 deletions.
9 changes: 3 additions & 6 deletions community/server/pom.xml
Expand Up @@ -352,12 +352,9 @@
<configuration> <configuration>
<mainClass>${neo4j-server.mainClass}</mainClass> <mainClass>${neo4j-server.mainClass}</mainClass>
<classpathScope>test</classpathScope> <classpathScope>test</classpathScope>
<systemProperties> <arguments>
<systemProperty> <argument>--config-dir=${basedir}/neo4j-home/conf</argument>
<key>org.neo4j.config.file</key> </arguments>
<value>${basedir}/neo4j-home/conf/neo4j.conf</value>
</systemProperty>
</systemProperties>
</configuration> </configuration>
</plugin> </plugin>


Expand Down
Expand Up @@ -41,9 +41,6 @@


import static java.lang.String.format; import static java.lang.String.format;


import static org.neo4j.server.configuration.ServerSettings.SERVER_CONFIG_FILE;
import static org.neo4j.server.configuration.ServerSettings.SERVER_CONFIG_FILE_KEY;

public abstract class ServerBootstrapper implements Bootstrapper public abstract class ServerBootstrapper implements Bootstrapper
{ {
public static final int OK = 0; public static final int OK = 0;
Expand Down Expand Up @@ -154,8 +151,7 @@ private static LogProvider setupLogging()


private Config createConfig( Log log, File file, Pair<String, String>[] configOverrides ) throws IOException private Config createConfig( Log log, File file, Pair<String, String>[] configOverrides ) throws IOException
{ {
File standardConfigFile = new File( System.getProperty( SERVER_CONFIG_FILE_KEY, SERVER_CONFIG_FILE ) ); return new ConfigLoader( this::settingsClasses ).loadConfig( file, log, configOverrides );
return new ConfigLoader( this::settingsClasses ).loadConfig( file, standardConfigFile, log, configOverrides );
} }


private void addShutdownHook() private void addShutdownHook()
Expand Down
Expand Up @@ -41,7 +41,7 @@
*/ */
public class ServerCommandLineArgs public class ServerCommandLineArgs
{ {
private static final String CONFIG_DIR_ARG = "config-dir"; public static final String CONFIG_DIR_ARG = "config-dir";
private final Args args; private final Args args;
private final Pair<String, String>[] configOverrides; private final Pair<String, String>[] configOverrides;


Expand Down
Expand Up @@ -50,28 +50,26 @@ public ConfigLoader( List<Class<?>> settingsClasses )
this( settings -> settingsClasses ); this( settings -> settingsClasses );
} }


public Config loadConfig( File configFile, File legacyConfigFile, Log log, Pair<String, String>... configOverrides ) public Config loadConfig( File configFile, Log log, Pair<String, String>... configOverrides )
{ {
if ( log == null ) if ( log == null )
{ {
throw new IllegalArgumentException( "log cannot be null " ); throw new IllegalArgumentException( "log cannot be null " );
} }


HashMap<String, String> settings = calculateSettings( configFile, legacyConfigFile, log, configOverrides ); HashMap<String, String> settings = calculateSettings( configFile, log, configOverrides );
Config config = new Config( settings, settingsClasses.calculate( settings ) ); Config config = new Config( settings, settingsClasses.calculate( settings ) );
config.setLogger( log ); config.setLogger( log );
return config; return config;
} }


private HashMap<String, String> calculateSettings( File configFile, File legacyConfigFile, Log log, private HashMap<String, String> calculateSettings( File config, Log log, Pair<String, String>[] configOverrides )
Pair<String, String>[] configOverrides )
{ {
HashMap<String, String> settings = new HashMap<>(); HashMap<String, String> settings = new HashMap<>();
if ( configFile != null && configFile.exists() ) if ( config != null && config.exists() )
{ {
settings.putAll( loadFromFile( log, configFile ) ); settings.putAll( loadFromFile( log, config ) );
} }
settings.putAll( loadFromFile( log, legacyConfigFile ) );
settings.putAll( toMap( configOverrides ) ); settings.putAll( toMap( configOverrides ) );
overrideEmbeddedDefaults( settings ); overrideEmbeddedDefaults( settings );
return settings; return settings;
Expand Down
Expand Up @@ -58,16 +58,6 @@
@Description("Settings used by the server configuration") @Description("Settings used by the server configuration")
public interface ServerSettings public interface ServerSettings
{ {
/**
* Key for the configuration file system property.
*/
String SERVER_CONFIG_FILE_KEY = "org.neo4j.config.file";

/**
* Default path for the configuration file. The path should always be get/set using System.property.
*/
String SERVER_CONFIG_FILE = "conf/neo4j.conf";

@Description("Maximum request header size") @Description("Maximum request header size")
@Internal @Internal
Setting<Integer> maximum_request_header_size = Setting<Integer> maximum_request_header_size =
Expand Down
Expand Up @@ -62,7 +62,7 @@ public void shouldProvideAConfiguration() throws IOException
.build(); .build();


// when // when
Config config = configLoader.loadConfig( null, configFile, log ); Config config = configLoader.loadConfig( configFile, log );


// then // then
assertNotNull( config ); assertNotNull( config );
Expand All @@ -77,7 +77,7 @@ public void shouldUseSpecifiedConfigFile() throws Exception
.build(); .build();


// when // when
Config testConf = configLoader.loadConfig( null, configFile, log ); Config testConf = configLoader.loadConfig( configFile, log );


// then // then
final String EXPECTED_VALUE = "bar"; final String EXPECTED_VALUE = "bar";
Expand All @@ -94,7 +94,7 @@ public void shouldAcceptDuplicateKeysWithSameValue() throws IOException
.build(); .build();


// when // when
Config testConf = configLoader.loadConfig( null, configFile, log ); Config testConf = configLoader.loadConfig( configFile, log );


// then // then
assertNotNull( testConf ); assertNotNull( testConf );
Expand All @@ -119,7 +119,7 @@ public void shouldFindThirdPartyJaxRsPackages() throws IOException
} }


// when // when
Config config = configLoader.loadConfig( null, file, log ); Config config = configLoader.loadConfig( file, log );


// then // then
List<ThirdPartyJaxRsPackage> thirdpartyJaxRsPackages = config.get( ServerSettings.third_party_packages ); List<ThirdPartyJaxRsPackage> thirdpartyJaxRsPackages = config.get( ServerSettings.third_party_packages );
Expand All @@ -138,7 +138,7 @@ public void shouldRetainRegistrationOrderOfThirdPartyJaxRsPackages() throws IOEx
.build(); .build();


// when // when
Config config = configLoader.loadConfig( null, configFile, log ); Config config = configLoader.loadConfig( configFile, log );


// then // then
List<ThirdPartyJaxRsPackage> thirdpartyJaxRsPackages = config.get( ServerSettings.third_party_packages ); List<ThirdPartyJaxRsPackage> thirdpartyJaxRsPackages = config.get( ServerSettings.third_party_packages );
Expand All @@ -157,7 +157,7 @@ public void shouldWorkFineWhenSpecifiedConfigFileDoesNotExist()
File nonExistentConfigFile = new File( "/tmp/" + System.currentTimeMillis() ); File nonExistentConfigFile = new File( "/tmp/" + System.currentTimeMillis() );


// When // When
Config config = configLoader.loadConfig( null, nonExistentConfigFile, log ); Config config = configLoader.loadConfig( nonExistentConfigFile, log );


// Then // Then
assertNotNull( config ); assertNotNull( config );
Expand Down
Expand Up @@ -103,7 +103,7 @@ public CommunityNeoServer build() throws IOException
final File configFile = buildBefore(); final File configFile = buildBefore();


Log log = logProvider.getLog( getClass() ); Log log = logProvider.getLog( getClass() );
Config config = new ConfigLoader( CommunityBootstrapper.settingsClasses ).loadConfig( null, configFile, log ); Config config = new ConfigLoader( CommunityBootstrapper.settingsClasses ).loadConfig( configFile, log );
return build( configFile, config, GraphDatabaseDependencies.newDependencies().userLogProvider( logProvider ) return build( configFile, config, GraphDatabaseDependencies.newDependencies().userLogProvider( logProvider )
.monitors( new Monitors() ) ); .monitors( new Monitors() ) );
} }
Expand Down
9 changes: 3 additions & 6 deletions enterprise/server-enterprise/pom.xml
Expand Up @@ -195,12 +195,9 @@
<configuration> <configuration>
<mainClass>${neo4j-server.mainClass}</mainClass> <mainClass>${neo4j-server.mainClass}</mainClass>
<classpathScope>test</classpathScope> <classpathScope>test</classpathScope>
<systemProperties> <arguments>
<systemProperty> <argument>--config-dir=${basedir}/neo4j-home/conf</argument>
<key>org.neo4j.config.file</key> </arguments>
<value>${basedir}/neo4j-home/conf/neo4j.conf</value>
</systemProperty>
</systemProperties>
</configuration> </configuration>
</plugin> </plugin>


Expand Down
Expand Up @@ -52,7 +52,8 @@
import org.neo4j.kernel.impl.util.Dependencies; import org.neo4j.kernel.impl.util.Dependencies;
import org.neo4j.kernel.lifecycle.LifeSupport; import org.neo4j.kernel.lifecycle.LifeSupport;
import org.neo4j.kernel.monitoring.Monitors; import org.neo4j.kernel.monitoring.Monitors;
import org.neo4j.server.configuration.ServerSettings; import org.neo4j.server.ServerCommandLineArgs;
import org.neo4j.server.configuration.ConfigLoader;
import org.neo4j.server.enterprise.functional.DumpPortListenerOnNettyBindFailure; import org.neo4j.server.enterprise.functional.DumpPortListenerOnNettyBindFailure;
import org.neo4j.test.InputStreamAwaiter; import org.neo4j.test.InputStreamAwaiter;
import org.neo4j.test.ProcessStreamHandler; import org.neo4j.test.ProcessStreamHandler;
Expand Down Expand Up @@ -177,23 +178,23 @@ public void after() throws Exception
life.shutdown(); life.shutdown();
} }


private File configFile( Map<String, String> config ) throws IOException private File writeConfig( Map<String, String> config ) throws IOException
{ {
File configFile = new File( directory, "config-file" ); File configFile = new File( directory, ConfigLoader.DEFAULT_CONFIG_FILE_NAME );
store( config, configFile ); store( config, configFile );
return configFile; return directory;
} }


private void startAndAssertJoined( Integer expectedAssignedPort, Map<String, String> config ) throws Exception private void startAndAssertJoined( Integer expectedAssignedPort, Map<String, String> config ) throws Exception
{ {
Map<String, String> localCopy = new HashMap<>( config ); Map<String, String> localCopy = new HashMap<>( config );
localCopy.put( GraphDatabaseSettings.auth_store.name(), Files.createTempFile( "auth", "" ).toString() ); localCopy.put( GraphDatabaseSettings.auth_store.name(), Files.createTempFile( "auth", "" ).toString() );
File configFile = configFile( localCopy ); File configDir = writeConfig( localCopy );
CountDownLatch latch = new CountDownLatch( 1 ); CountDownLatch latch = new CountDownLatch( 1 );
AtomicInteger port = new AtomicInteger(); AtomicInteger port = new AtomicInteger();
clients[0].addClusterListener( joinAwaitingListener( latch, port ) ); clients[0].addClusterListener( joinAwaitingListener( latch, port ) );


boolean arbiterStarted = startArbiter( configFile, latch ); boolean arbiterStarted = startArbiter( configDir, latch );
if ( expectedAssignedPort == null ) if ( expectedAssignedPort == null )
{ {
assertFalse( format( "Should not be able to start arbiter given config file:%s", config ), arbiterStarted ); assertFalse( format( "Should not be able to start arbiter given config file:%s", config ), arbiterStarted );
Expand All @@ -219,13 +220,13 @@ public void joinedCluster( InstanceId member, URI memberUri )
}; };
} }


private boolean startArbiter( File configFile, CountDownLatch latch ) throws Exception private boolean startArbiter( File configDir, CountDownLatch latch ) throws Exception
{ {
Process process = null; Process process = null;
ProcessStreamHandler handler = null; ProcessStreamHandler handler = null;
try try
{ {
process = startArbiterProcess( configFile ); process = startArbiterProcess( configDir );
new InputStreamAwaiter( process.getInputStream() ).awaitLine( START_SIGNAL, 20, SECONDS ); new InputStreamAwaiter( process.getInputStream() ).awaitLine( START_SIGNAL, 20, SECONDS );
handler = new ProcessStreamHandler( process, false, "", IGNORE_FAILURES ); handler = new ProcessStreamHandler( process, false, "", IGNORE_FAILURES );
handler.launch(); handler.launch();
Expand Down Expand Up @@ -258,14 +259,14 @@ private boolean startArbiter( File configFile, CountDownLatch latch ) throws Exc
} }
} }


private Process startArbiterProcess( File configFile ) throws Exception private Process startArbiterProcess( File configDir ) throws Exception
{ {
List<String> args = new ArrayList<>( asList( "java", "-cp", getProperty( "java.class.path" ) ) ); List<String> args = new ArrayList<>( asList( "java", "-cp", getProperty( "java.class.path" ) ) );
if ( configFile != null ) args.add( ArbiterBootstrapperTestProxy.class.getName() );
if ( configDir != null )
{ {
args.add( "-D" + ServerSettings.SERVER_CONFIG_FILE_KEY + "=" + configFile.getAbsolutePath() ); args.add( format( "--%s=%s", ServerCommandLineArgs.CONFIG_DIR_ARG, configDir ) );
} }
args.add( ArbiterBootstrapperTestProxy.class.getName() );
return getRuntime().exec( args.toArray( new String[args.size()] ) ); return getRuntime().exec( args.toArray( new String[args.size()] ) );
} }


Expand Down
Expand Up @@ -58,7 +58,7 @@ public void shouldBeAbleToRestartServer() throws Exception
String dataDirectory1 = baseDir.directory( "data1" ).getAbsolutePath(); String dataDirectory1 = baseDir.directory( "data1" ).getAbsolutePath();
String dataDirectory2 = baseDir.directory( "data2" ).getAbsolutePath(); String dataDirectory2 = baseDir.directory( "data2" ).getAbsolutePath();


Config config = new ConfigLoader( CommunityBootstrapper.settingsClasses ).loadConfig( null, Config config = new ConfigLoader( CommunityBootstrapper.settingsClasses ).loadConfig(
EnterpriseServerBuilder EnterpriseServerBuilder
.server() .server()
.withDefaultDatabaseTuning() .withDefaultDatabaseTuning()
Expand Down
Expand Up @@ -67,10 +67,9 @@
import org.neo4j.kernel.lifecycle.LifecycleException; import org.neo4j.kernel.lifecycle.LifecycleException;
import org.neo4j.register.Register.DoubleLongRegister; import org.neo4j.register.Register.DoubleLongRegister;
import org.neo4j.register.Registers; import org.neo4j.register.Registers;
import org.neo4j.server.ServerBootstrapper;
import org.neo4j.server.CommunityBootstrapper; import org.neo4j.server.CommunityBootstrapper;
import org.neo4j.server.ServerBootstrapper;
import org.neo4j.server.ServerTestUtils; import org.neo4j.server.ServerTestUtils;
import org.neo4j.server.configuration.ServerSettings;
import org.neo4j.test.SuppressOutput; import org.neo4j.test.SuppressOutput;
import org.neo4j.test.TargetDirectory; import org.neo4j.test.TargetDirectory;
import org.neo4j.test.TestGraphDatabaseFactory; import org.neo4j.test.TestGraphDatabaseFactory;
Expand Down Expand Up @@ -209,23 +208,16 @@ public void serverDatabaseShouldStartOnOlderStoreWhenUpgradeIsEnabled() throws T
props.store( writer, "" ); props.store( writer, "" );
} }


ServerBootstrapper bootstrapper = new CommunityBootstrapper();
try try
{ {
ServerBootstrapper bootstrapper = new CommunityBootstrapper(); bootstrapper.start( configFile );
try assertTrue( bootstrapper.isRunning() );
{ checkInstance( store, bootstrapper.getServer().getDatabase().getGraph() );
bootstrapper.start( configFile );
assertTrue( bootstrapper.isRunning() );
checkInstance( store, bootstrapper.getServer().getDatabase().getGraph() );
}
finally
{
bootstrapper.stop();
}
} }
finally finally
{ {
System.clearProperty( ServerSettings.SERVER_CONFIG_FILE_KEY ); bootstrapper.stop();
} }


assertConsistentStore( storeDir ); assertConsistentStore( storeDir );
Expand Down
Expand Up @@ -29,8 +29,7 @@ CLASSPATH=`find $NEO4J_HOME -name '*.jar' | xargs echo | tr ' ' ':'`


java -cp "${CLASSPATH}" \ java -cp "${CLASSPATH}" \
-Dfile.encoding=UTF-8 \ -Dfile.encoding=UTF-8 \
-Dorg.neo4j.config.file=conf/neo4j.conf \ #{neo4j.mainClass} --config-dir=conf > /var/log/neo4j/neo4j.log 2>&1 &
#{neo4j.mainClass} > /var/log/neo4j/neo4j.log 2>&1 &


echo $! > $PID_FILE echo $! > $PID_FILE


Expand Up @@ -54,12 +54,7 @@ public DesktopConfigurator( Installation installation, File databaseDirectory )
public void refresh() public void refresh()
{ {
config = new ConfigLoader( CommunityBootstrapper.settingsClasses).loadConfig( config = new ConfigLoader( CommunityBootstrapper.settingsClasses).loadConfig(
/** Future single file, neo4j.conf or similar */
null,

/** Server config file */
installation.getConfigurationsFile(), installation.getConfigurationsFile(),

FormattedLog.toOutputStream( System.out ), FormattedLog.toOutputStream( System.out ),


/** Desktop-specific config overrides */ /** Desktop-specific config overrides */
Expand Down
Expand Up @@ -163,7 +163,6 @@ Function Get-Java
$ClassPath="$($Neo4jServer.Home)/lib/*;$($Neo4jServer.Home)/plugins/*" $ClassPath="$($Neo4jServer.Home)/lib/*;$($Neo4jServer.Home)/plugins/*"
$ShellArgs = @("-cp `"$($ClassPath)`""` $ShellArgs = @("-cp `"$($ClassPath)`""`
,'-server' ` ,'-server' `
,'-Dorg.neo4j.config.file=conf/neo4j.conf' `
,'-Dlog4j.configuration=file:conf/log4j.properties' ` ,'-Dlog4j.configuration=file:conf/log4j.properties' `
,'-Dneo4j.ext.udc.source=zip-powershell' ` ,'-Dneo4j.ext.udc.source=zip-powershell' `
,'-Dorg.neo4j.cluster.logdirectory=data/log' ` ,'-Dorg.neo4j.cluster.logdirectory=data/log' `
Expand Down
@@ -1,9 +1,3 @@
#********************************************************************
# Property file references
#********************************************************************

dbms.jvm.additional=-Dorg.neo4j.config.file=conf/neo4j.conf

#******************************************************************** #********************************************************************
# JVM Parameters # JVM Parameters
#******************************************************************** #********************************************************************
Expand Down
@@ -1,9 +1,3 @@
#********************************************************************
# Property file references
#********************************************************************

dbms.jvm.additional=-Dorg.neo4j.config.file=conf/neo4j.conf

#******************************************************************** #********************************************************************
# JVM Parameters # JVM Parameters
#******************************************************************** #********************************************************************
Expand Down

0 comments on commit 81740f8

Please sign in to comment.