Search in sources :

Example 1 with ClusterClientModule

use of org.neo4j.cluster.client.ClusterClientModule in project neo4j by neo4j.

the class ClusterTopologyChangesIT method newClusterClient.

private ClusterClientModule newClusterClient(LifeSupport life, InstanceId id) {
    Config config = Config.embeddedDefaults(MapUtil.stringMap(ClusterSettings.initial_hosts.name(), cluster.getInitialHostsConfigString(), ClusterSettings.server_id.name(), String.valueOf(id.toIntegerIndex()), ClusterSettings.cluster_server.name(), "0.0.0.0:8888"));
    FormattedLogProvider logProvider = FormattedLogProvider.toOutputStream(System.out);
    SimpleLogService logService = new SimpleLogService(logProvider, logProvider);
    return new ClusterClientModule(life, new Dependencies(), new Monitors(), config, logService, new NotElectableElectionCredentialsProvider());
}
Also used : SimpleLogService(org.neo4j.kernel.impl.logging.SimpleLogService) Config(org.neo4j.kernel.configuration.Config) NotElectableElectionCredentialsProvider(org.neo4j.cluster.protocol.election.NotElectableElectionCredentialsProvider) Monitors(org.neo4j.kernel.monitoring.Monitors) Dependencies(org.neo4j.kernel.impl.util.Dependencies) ClusterClientModule(org.neo4j.cluster.client.ClusterClientModule) FormattedLogProvider(org.neo4j.logging.FormattedLogProvider)

Example 2 with ClusterClientModule

use of org.neo4j.cluster.client.ClusterClientModule in project neo4j by neo4j.

the class ClusterTopologyChangesIT method failedInstanceShouldReceiveCorrectCoordinatorIdUponRejoiningCluster.

@Test
public void failedInstanceShouldReceiveCorrectCoordinatorIdUponRejoiningCluster() throws Throwable {
    // Given
    HighlyAvailableGraphDatabase initialMaster = cluster.getMaster();
    // When
    cluster.shutdown(initialMaster);
    cluster.await(masterAvailable(initialMaster));
    cluster.await(masterSeesSlavesAsAvailable(1));
    // create node on new master to ensure that it has the greatest tx id
    createNodeOn(cluster.getMaster());
    cluster.sync();
    LifeSupport life = new LifeSupport();
    ClusterClientModule clusterClient = newClusterClient(life, new InstanceId(1));
    cleanup.add(life);
    final AtomicReference<InstanceId> coordinatorIdWhenReJoined = new AtomicReference<>();
    final CountDownLatch latch = new CountDownLatch(1);
    clusterClient.clusterClient.addClusterListener(new ClusterListener.Adapter() {

        @Override
        public void enteredCluster(ClusterConfiguration clusterConfiguration) {
            coordinatorIdWhenReJoined.set(clusterConfiguration.getElected(COORDINATOR));
            latch.countDown();
        }
    });
    life.start();
    // Then
    assertTrue(latch.await(20, SECONDS));
    assertEquals(new InstanceId(2), coordinatorIdWhenReJoined.get());
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) ClusterListener(org.neo4j.cluster.protocol.cluster.ClusterListener) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) AtomicReference(java.util.concurrent.atomic.AtomicReference) ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration) CountDownLatch(java.util.concurrent.CountDownLatch) ClusterClientModule(org.neo4j.cluster.client.ClusterClientModule) Test(org.junit.Test)

Example 3 with ClusterClientModule

use of org.neo4j.cluster.client.ClusterClientModule in project neo4j by neo4j.

the class ArbiterBootstrapper method start.

@SafeVarargs
@Override
public final int start(File homeDir, Optional<File> configFile, Pair<String, String>... configOverrides) {
    Config config = getConfig(configFile, configOverrides);
    try {
        DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
        life.add(new FileSystemLifecycleAdapter(fileSystem));
        life.add(new Neo4jJobScheduler());
        new ClusterClientModule(life, new Dependencies(), new Monitors(), config, logService(fileSystem, config), new NotElectableElectionCredentialsProvider());
    } catch (LifecycleException e) {
        @SuppressWarnings({ "ThrowableResultOfMethodCallIgnored", "unchecked" }) Throwable cause = peel(e, Predicates.<Throwable>instanceOf(LifecycleException.class));
        if (cause instanceof ChannelException) {
            System.err.println("ERROR: " + cause.getMessage() + (cause.getCause() != null ? ", caused by:" + cause.getCause().getMessage() : ""));
        } else {
            System.err.println("ERROR: Unknown error");
            throw e;
        }
    }
    addShutdownHook();
    life.start();
    return 0;
}
Also used : FileSystemLifecycleAdapter(org.neo4j.io.fs.FileSystemLifecycleAdapter) Neo4jJobScheduler(org.neo4j.kernel.impl.util.Neo4jJobScheduler) LifecycleException(org.neo4j.kernel.lifecycle.LifecycleException) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) Config(org.neo4j.kernel.configuration.Config) NotElectableElectionCredentialsProvider(org.neo4j.cluster.protocol.election.NotElectableElectionCredentialsProvider) Monitors(org.neo4j.kernel.monitoring.Monitors) Dependencies(org.neo4j.kernel.impl.util.Dependencies) ClusterClientModule(org.neo4j.cluster.client.ClusterClientModule) ChannelException(org.jboss.netty.channel.ChannelException)

Example 4 with ClusterClientModule

use of org.neo4j.cluster.client.ClusterClientModule in project neo4j by neo4j.

the class ArbiterBootstrapperIT method before.

@Before
public void before() throws Exception {
    directory = testDirectory.directory("temp");
    life = new LifeSupport();
    // So that the clients get started as they are added
    life.start();
    clients = new ClusterClient[2];
    for (int i = 1; i <= clients.length; i++) {
        Map<String, String> config = stringMap();
        config.put(cluster_server.name(), ":" + (5000 + i));
        config.put(server_id.name(), "" + i);
        config.put(initial_hosts.name(), ":5001");
        LifeSupport moduleLife = new LifeSupport();
        ClusterClientModule clusterClientModule = new ClusterClientModule(moduleLife, new Dependencies(), new Monitors(), Config.embeddedDefaults(config), NullLogService.getInstance(), new ServerIdElectionCredentialsProvider());
        ClusterClient client = clusterClientModule.clusterClient;
        CountDownLatch latch = new CountDownLatch(1);
        client.addClusterListener(new ClusterListener.Adapter() {

            @Override
            public void enteredCluster(ClusterConfiguration configuration) {
                latch.countDown();
                client.removeClusterListener(this);
            }
        });
        life.add(moduleLife);
        clients[i - 1] = client;
        assertTrue("Didn't join the cluster", latch.await(20, SECONDS));
    }
}
Also used : ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration) CountDownLatch(java.util.concurrent.CountDownLatch) Adapter(org.neo4j.cluster.protocol.cluster.ClusterListener.Adapter) ClusterClient(org.neo4j.cluster.client.ClusterClient) ClusterListener(org.neo4j.cluster.protocol.cluster.ClusterListener) Monitors(org.neo4j.kernel.monitoring.Monitors) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) ServerIdElectionCredentialsProvider(org.neo4j.cluster.protocol.election.ServerIdElectionCredentialsProvider) Dependencies(org.neo4j.kernel.impl.util.Dependencies) ClusterClientModule(org.neo4j.cluster.client.ClusterClientModule) Before(org.junit.Before)

Aggregations

ClusterClientModule (org.neo4j.cluster.client.ClusterClientModule)4 Dependencies (org.neo4j.kernel.impl.util.Dependencies)3 Monitors (org.neo4j.kernel.monitoring.Monitors)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 ClusterConfiguration (org.neo4j.cluster.protocol.cluster.ClusterConfiguration)2 ClusterListener (org.neo4j.cluster.protocol.cluster.ClusterListener)2 NotElectableElectionCredentialsProvider (org.neo4j.cluster.protocol.election.NotElectableElectionCredentialsProvider)2 Config (org.neo4j.kernel.configuration.Config)2 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 ChannelException (org.jboss.netty.channel.ChannelException)1 Before (org.junit.Before)1 Test (org.junit.Test)1 InstanceId (org.neo4j.cluster.InstanceId)1 ClusterClient (org.neo4j.cluster.client.ClusterClient)1 Adapter (org.neo4j.cluster.protocol.cluster.ClusterListener.Adapter)1 ServerIdElectionCredentialsProvider (org.neo4j.cluster.protocol.election.ServerIdElectionCredentialsProvider)1 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)1 FileSystemLifecycleAdapter (org.neo4j.io.fs.FileSystemLifecycleAdapter)1 SimpleLogService (org.neo4j.kernel.impl.logging.SimpleLogService)1