Skip to content

Commit

Permalink
Allow cluster process builder to be externally configured by providing
Browse files Browse the repository at this point in the history
properties you want to configure to builder during cluster construction
process
  • Loading branch information
MishaDemianenko committed May 8, 2018
1 parent 2e3780f commit a0eb0be
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
Expand Up @@ -22,11 +22,9 @@
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
Expand All @@ -35,7 +33,6 @@
import org.neo4j.causalclustering.core.CausalClusteringSettings; import org.neo4j.causalclustering.core.CausalClusteringSettings;
import org.neo4j.graphdb.factory.GraphDatabaseSettings; import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.harness.internal.EnterpriseInProcessServerBuilder; import org.neo4j.harness.internal.EnterpriseInProcessServerBuilder;
import org.neo4j.helpers.collection.Iterables;
import org.neo4j.kernel.configuration.BoltConnector; import org.neo4j.kernel.configuration.BoltConnector;
import org.neo4j.kernel.configuration.HttpConnector; import org.neo4j.kernel.configuration.HttpConnector;
import org.neo4j.kernel.configuration.Settings; import org.neo4j.kernel.configuration.Settings;
Expand Down Expand Up @@ -67,6 +64,7 @@ public static class Builder implements WithCores, WithReplicas, WithLogger, With
private Log log; private Log log;
private Path path; private Path path;
private PortPickingFactory portFactory = PortPickingFactory.DEFAULT; private PortPickingFactory portFactory = PortPickingFactory.DEFAULT;
private final Map<String, String> config = new HashMap<>();
private List<String> databases = new ArrayList<>( Collections.singletonList( "default" ) ); private List<String> databases = new ArrayList<>( Collections.singletonList( "default" ) );


public WithReplicas withCores( int n ) public WithReplicas withCores( int n )
Expand All @@ -87,6 +85,12 @@ public WithPath withLogger( LogProvider l )
return this; return this;
} }


public Builder withConfig( String settingName, String value )
{
config.put( settingName, value );
return this;
}

public Builder atPath( Path p ) public Builder atPath( Path p )
{ {
path = p; path = p;
Expand Down Expand Up @@ -233,24 +237,24 @@ static class CausalCluster
{ {
private final int nCores; private final int nCores;
private final int nReplicas; private final int nReplicas;
private final int nDatabases;
private final List<String> databaseNames; private final List<String> databaseNames;
private final Path clusterPath; private final Path clusterPath;
private final Log log; private final Log log;
private final PortPickingFactory portFactory; private final PortPickingFactory portFactory;
private final Map<String,String> config;


private List<ServerControls> coreControls = synchronizedList( new ArrayList<>() ); private List<ServerControls> coreControls = synchronizedList( new ArrayList<>() );
private List<ServerControls> replicaControls = synchronizedList( new ArrayList<>() ); private List<ServerControls> replicaControls = synchronizedList( new ArrayList<>() );


private CausalCluster( CausalClusterInProcessBuilder.Builder bldr ) private CausalCluster( CausalClusterInProcessBuilder.Builder builder )
{ {
this.nCores = bldr.numCoreHosts; this.nCores = builder.numCoreHosts;
this.nReplicas = bldr.numReadReplicas; this.nReplicas = builder.numReadReplicas;
this.clusterPath = bldr.path; this.clusterPath = builder.path;
this.log = bldr.log; this.log = builder.log;
this.portFactory = bldr.portFactory; this.portFactory = builder.portFactory;
this.nDatabases = bldr.databases.size(); this.databaseNames = builder.databases;
this.databaseNames = bldr.databases; this.config = builder.config;
} }


private Map<Integer,String> distributeHostsBetweenDatabases( int nHosts, List<String> databases ) private Map<Integer,String> distributeHostsBetweenDatabases( int nHosts, List<String> databases )
Expand Down Expand Up @@ -321,6 +325,8 @@ void boot() throws InterruptedException


builder.withConfig( OnlineBackupSettings.online_backup_enabled, Settings.FALSE ); builder.withConfig( OnlineBackupSettings.online_backup_enabled, Settings.FALSE );


config.forEach( builder::withConfig );

int finalCoreId = coreId; int finalCoreId = coreId;
Thread coreThread = new Thread( () -> Thread coreThread = new Thread( () ->
{ {
Expand Down Expand Up @@ -364,6 +370,9 @@ void boot() throws InterruptedException
builder.withConfig( ServerSettings.jmx_module_enabled.name(), Settings.FALSE ); builder.withConfig( ServerSettings.jmx_module_enabled.name(), Settings.FALSE );


builder.withConfig( OnlineBackupSettings.online_backup_enabled, Settings.FALSE ); builder.withConfig( OnlineBackupSettings.online_backup_enabled, Settings.FALSE );

config.forEach( builder::withConfig );

int finalReplicaId = replicaId; int finalReplicaId = replicaId;
Thread replicaThread = new Thread( () -> Thread replicaThread = new Thread( () ->
{ {
Expand Down
Expand Up @@ -19,15 +19,17 @@
*/ */
package org.neo4j.harness; package org.neo4j.harness;


import org.junit.ClassRule;
import org.junit.Test;

import java.nio.file.Path; import java.nio.file.Path;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;


import org.junit.ClassRule; import org.neo4j.kernel.configuration.Settings;
import org.junit.Test;

import org.neo4j.logging.NullLogProvider; import org.neo4j.logging.NullLogProvider;
import org.neo4j.ports.allocation.PortAuthority; import org.neo4j.ports.allocation.PortAuthority;
import org.neo4j.server.configuration.ServerSettings;
import org.neo4j.test.rule.TestDirectory; import org.neo4j.test.rule.TestDirectory;


public class CausalClusterInProcessRunnerIT public class CausalClusterInProcessRunnerIT
Expand Down Expand Up @@ -63,6 +65,7 @@ public int port( int offset, int id )
.withLogger( NullLogProvider.getInstance() ) .withLogger( NullLogProvider.getInstance() )
.atPath( clusterPath ) .atPath( clusterPath )
.withOptionalPortsStrategy( portPickingStrategy ) .withOptionalPortsStrategy( portPickingStrategy )
.withConfig( ServerSettings.script_enabled.name(), Settings.TRUE )
.build(); .build();


cluster.boot(); cluster.boot();
Expand Down
Expand Up @@ -43,10 +43,10 @@
public class EnterpriseInProcessServerBuilderIT public class EnterpriseInProcessServerBuilderIT
{ {
@Rule @Rule
public TestDirectory testDir = TestDirectory.testDirectory(); public final TestDirectory testDir = TestDirectory.testDirectory();


@Rule @Rule
public SuppressOutput suppressOutput = SuppressOutput.suppressAll(); public final SuppressOutput suppressOutput = SuppressOutput.suppressAll();


@Test @Test
public void shouldLaunchAServerInSpecifiedDirectory() public void shouldLaunchAServerInSpecifiedDirectory()
Expand Down
Expand Up @@ -42,7 +42,6 @@ public class EnterpriseNeo4jRuleTest
public Neo4jRule neo4j = new EnterpriseNeo4jRule() public Neo4jRule neo4j = new EnterpriseNeo4jRule()
.withConfig( LegacySslPolicyConfig.certificates_directory.name(), .withConfig( LegacySslPolicyConfig.certificates_directory.name(),
getRelativePath( getSharedTestTemporaryFolder(), LegacySslPolicyConfig.certificates_directory ) ) getRelativePath( getSharedTestTemporaryFolder(), LegacySslPolicyConfig.certificates_directory ) )
.withConfig( ServerSettings.script_enabled, Settings.TRUE )
.withExtension( "/test", MyEnterpriseUnmanagedExtension.class ) .withExtension( "/test", MyEnterpriseUnmanagedExtension.class )
.withConfig( OnlineBackupSettings.online_backup_enabled, Settings.FALSE ) .withConfig( OnlineBackupSettings.online_backup_enabled, Settings.FALSE )
.withConfig( ServerSettings.script_enabled, Settings.TRUE ); .withConfig( ServerSettings.script_enabled, Settings.TRUE );
Expand Down

0 comments on commit a0eb0be

Please sign in to comment.