Search in sources :

Example 16 with ZookeeperClient

use of org.bboxdb.distribution.zookeeper.ZookeeperClient in project bboxdb by jnidzwetzki.

the class ConnectDialog method getConnectAction.

/**
 * Get the connect action
 * @return
 */
/**
 * Get the connect action
 * @return
 */
protected Action getConnectAction() {
    final AbstractAction connectAction = new AbstractAction() {

        /**
         */
        private static final long serialVersionUID = 2908534701228350424L;

        @Override
        public void actionPerformed(ActionEvent e) {
            final String guiHosts = hosts.getText();
            if (guiHosts == null) {
                return;
            }
            final String[] hostList = guiHosts.split(",");
            final List<String> zookeeperHosts = Arrays.asList(hostList);
            final String cluster = clustername.getText();
            final ZookeeperClient zookeeperClient = new ZookeeperClient(zookeeperHosts, cluster);
            zookeeperClient.init();
            ZookeeperClientFactory.setDefaultZookeeperClient(zookeeperClient);
            showMainDialog(zookeeperClient);
            BBoxDBInstanceManager.getInstance().startMembershipObserver(zookeeperClient);
            mainframe.dispose();
        }

        /**
         * Show the main dialog
         *
         * @param distributionGroup
         * @param zookeeperClient
         */
        protected void showMainDialog(final ZookeeperClient zookeeperClient) {
            final GuiModel guiModel = new GuiModel(zookeeperClient);
            final BBoxDBGui bboxDBGUI = new BBoxDBGui(guiModel);
            guiModel.setBBoxDBGui(bboxDBGUI);
            bboxDBGUI.run();
        }
    };
    return connectAction;
}
Also used : ZookeeperClient(org.bboxdb.distribution.zookeeper.ZookeeperClient) ActionEvent(java.awt.event.ActionEvent) AbstractAction(javax.swing.AbstractAction)

Example 17 with ZookeeperClient

use of org.bboxdb.distribution.zookeeper.ZookeeperClient in project bboxdb by jnidzwetzki.

the class TestNetworkCommunication method testSendDeletePackage.

/**
 * Send a delete package to the server
 * @throws InterruptedException
 * @throws ExecutionException
 * @throws ZookeeperException
 * @throws BBoxDBException
 */
@Test(timeout = 60000)
public void testSendDeletePackage() throws InterruptedException, ExecutionException, ZookeeperException, BBoxDBException {
    System.out.println("=== Running sendDeletePackage");
    final BBoxDBConnection bboxdbConnection = connectToServer();
    final BBoxDBClient bboxDBClient = bboxdbConnection.getBboxDBClient();
    final String tableName = DISTRIBUTION_GROUP + "_relation3";
    final TupleStoreName tupleStoreName = new TupleStoreName(tableName);
    final ZookeeperClient zookeeperClient = ZookeeperClientFactory.getZookeeperClient();
    final TupleStoreAdapter tupleStoreAdapter = zookeeperClient.getTupleStoreAdapter();
    Assert.assertFalse(tupleStoreAdapter.isTableKnown(tupleStoreName));
    // Create table
    final TupleStoreConfiguration configuration = TupleStoreConfigurationBuilder.create().build();
    final EmptyResultFuture createFuture = bboxDBClient.createTable(tableName, configuration);
    createFuture.waitForAll();
    Assert.assertTrue(createFuture.isDone());
    Assert.assertFalse(createFuture.isFailed());
    Assert.assertTrue(tupleStoreAdapter.isTableKnown(tupleStoreName));
    // Delete table
    final EmptyResultFuture deleteResult1 = bboxDBClient.deleteTable(tableName);
    deleteResult1.waitForAll();
    Assert.assertTrue(deleteResult1.isDone());
    Assert.assertFalse(deleteResult1.isFailed());
    Assert.assertTrue(bboxdbConnection.getConnectionState().isInRunningState());
    Assert.assertFalse(tupleStoreAdapter.isTableKnown(tupleStoreName));
    // Second call
    final EmptyResultFuture deleteResult2 = bboxDBClient.deleteTable(tableName);
    deleteResult2.waitForAll();
    Assert.assertTrue(deleteResult2.isDone());
    Assert.assertFalse(deleteResult2.isFailed());
    Assert.assertTrue(bboxdbConnection.getConnectionState().isInRunningState());
    Assert.assertFalse(tupleStoreAdapter.isTableKnown(tupleStoreName));
    // Disconnect
    disconnect(bboxDBClient);
    Assert.assertFalse(bboxDBClient.isConnected());
    System.out.println("=== End sendDeletePackage");
}
Also used : ZookeeperClient(org.bboxdb.distribution.zookeeper.ZookeeperClient) BBoxDBClient(org.bboxdb.network.client.BBoxDBClient) TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) TupleStoreAdapter(org.bboxdb.distribution.zookeeper.TupleStoreAdapter) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) BBoxDBConnection(org.bboxdb.network.client.BBoxDBConnection) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture) Test(org.junit.Test)

Example 18 with ZookeeperClient

use of org.bboxdb.distribution.zookeeper.ZookeeperClient in project bboxdb by jnidzwetzki.

the class TestDistributedInstanceManager method testAddEvent.

/**
 * Test add event generation
 * @throws InterruptedException
 * @throws ZookeeperException
 */
@Test(timeout = 30000)
public void testAddEvent() throws InterruptedException {
    final BBoxDBInstanceManager distributedInstanceManager = BBoxDBInstanceManager.getInstance();
    final BBoxDBInstance instance1 = new BBoxDBInstance("node4:5050");
    final BBoxDBInstance instance2 = new BBoxDBInstance("node5:5050");
    final ZookeeperClient zookeeperClient1 = getNewZookeeperClient(instance1);
    BBoxDBInstanceManager.getInstance().startMembershipObserver(zookeeperClient1);
    Thread.sleep(5000);
    final CountDownLatch changedLatch = new CountDownLatch(1);
    distributedInstanceManager.registerListener(new BiConsumer<DistributedInstanceEvent, BBoxDBInstance>() {

        @Override
        public void accept(final DistributedInstanceEvent event, final BBoxDBInstance instance) {
            if (event == DistributedInstanceEvent.ADD) {
                if (instance.socketAddressEquals(instance2)) {
                    changedLatch.countDown();
                }
            } else {
                // Unexpected event
                System.out.println("Got unexpeceted event: " + event);
                Assert.assertTrue(false);
            }
        }
    });
    final ZookeeperClient zookeeperClient2 = getNewZookeeperClient(instance2);
    changedLatch.await();
    distributedInstanceManager.removeAllListener();
    zookeeperClient1.shutdown();
    zookeeperClient2.shutdown();
}
Also used : ZookeeperClient(org.bboxdb.distribution.zookeeper.ZookeeperClient) BBoxDBInstanceManager(org.bboxdb.distribution.membership.BBoxDBInstanceManager) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) DistributedInstanceEvent(org.bboxdb.distribution.membership.DistributedInstanceEvent) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 19 with ZookeeperClient

use of org.bboxdb.distribution.zookeeper.ZookeeperClient in project bboxdb by jnidzwetzki.

the class TestDistributedInstanceManager method testChangedEventOnDeletion.

/**
 * Test delete event generation
 * @throws InterruptedException
 * @throws ZookeeperException
 */
@Test(timeout = 30000)
public void testChangedEventOnDeletion() throws InterruptedException, ZookeeperException {
    final BBoxDBInstanceManager distributedInstanceManager = BBoxDBInstanceManager.getInstance();
    final BBoxDBInstance instance1 = new BBoxDBInstance("node6:5050");
    final BBoxDBInstance instance2 = new BBoxDBInstance("node7:5050");
    final ZookeeperClient zookeeperClient1 = getNewZookeeperClient(instance1);
    final ZookeeperBBoxDBInstanceAdapter zookeeperBBoxDBInstanceAdapter1 = new ZookeeperBBoxDBInstanceAdapter(zookeeperClient1);
    BBoxDBInstanceManager.getInstance().startMembershipObserver(zookeeperClient1);
    final ZookeeperClient zookeeperClient2 = getNewZookeeperClient(instance2);
    final ZookeeperBBoxDBInstanceAdapter zookeeperBBoxDBInstanceAdapter2 = new ZookeeperBBoxDBInstanceAdapter(zookeeperClient2);
    zookeeperBBoxDBInstanceAdapter1.updateStateData(instance1, BBoxDBInstanceState.READY);
    zookeeperBBoxDBInstanceAdapter2.updateStateData(instance2, BBoxDBInstanceState.READY);
    Thread.sleep(5000);
    final CountDownLatch changedLatch = new CountDownLatch(1);
    distributedInstanceManager.registerListener(new BiConsumer<DistributedInstanceEvent, BBoxDBInstance>() {

        @Override
        public void accept(final DistributedInstanceEvent event, final BBoxDBInstance instance) {
            if (event == DistributedInstanceEvent.CHANGED) {
                if (instance.socketAddressEquals(instance2)) {
                    changedLatch.countDown();
                }
            } else {
                System.out.println("Got unexpeced event: " + event);
                // Unexpected event
                Assert.assertTrue(false);
            }
        }
    });
    zookeeperClient2.shutdown();
    changedLatch.await();
    distributedInstanceManager.removeAllListener();
    zookeeperClient1.shutdown();
}
Also used : ZookeeperClient(org.bboxdb.distribution.zookeeper.ZookeeperClient) BBoxDBInstanceManager(org.bboxdb.distribution.membership.BBoxDBInstanceManager) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) ZookeeperBBoxDBInstanceAdapter(org.bboxdb.distribution.membership.ZookeeperBBoxDBInstanceAdapter) DistributedInstanceEvent(org.bboxdb.distribution.membership.DistributedInstanceEvent) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 20 with ZookeeperClient

use of org.bboxdb.distribution.zookeeper.ZookeeperClient in project bboxdb by jnidzwetzki.

the class TestDistributedInstanceManager method testRegisterInstance3.

/**
 * One instance is known and changes
 * @throws ZookeeperException
 */
@Test(timeout = 60000)
public void testRegisterInstance3() throws InterruptedException, ZookeeperException {
    final BBoxDBInstance instance = new BBoxDBInstance("node1:5050");
    final ZookeeperClient zookeeperClient = getNewZookeeperClient(instance);
    BBoxDBInstanceManager.getInstance().startMembershipObserver(zookeeperClient);
    Assert.assertTrue(zookeeperClient.isConnected());
    Thread.sleep(1000);
    final ZookeeperBBoxDBInstanceAdapter zookeeperBBoxDBInstanceAdapter = new ZookeeperBBoxDBInstanceAdapter(zookeeperClient);
    final BBoxDBInstanceManager distributedInstanceManager = BBoxDBInstanceManager.getInstance();
    Assert.assertTrue(BBoxDBInstanceState.FAILED == distributedInstanceManager.getInstances().get(0).getState());
    zookeeperBBoxDBInstanceAdapter.updateStateData(instance, BBoxDBInstanceState.OUTDATED);
    Thread.sleep(2000);
    System.out.println(distributedInstanceManager.getInstances());
    Assert.assertTrue(BBoxDBInstanceState.OUTDATED == distributedInstanceManager.getInstances().get(0).getState());
    zookeeperBBoxDBInstanceAdapter.updateStateData(instance, BBoxDBInstanceState.READY);
    Thread.sleep(1000);
    Assert.assertTrue(BBoxDBInstanceState.READY == distributedInstanceManager.getInstances().get(0).getState());
    zookeeperClient.shutdown();
}
Also used : ZookeeperClient(org.bboxdb.distribution.zookeeper.ZookeeperClient) BBoxDBInstanceManager(org.bboxdb.distribution.membership.BBoxDBInstanceManager) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) ZookeeperBBoxDBInstanceAdapter(org.bboxdb.distribution.membership.ZookeeperBBoxDBInstanceAdapter) Test(org.junit.Test)

Aggregations

ZookeeperClient (org.bboxdb.distribution.zookeeper.ZookeeperClient)24 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)13 Test (org.junit.Test)12 BBoxDBInstanceManager (org.bboxdb.distribution.membership.BBoxDBInstanceManager)9 ZookeeperBBoxDBInstanceAdapter (org.bboxdb.distribution.membership.ZookeeperBBoxDBInstanceAdapter)6 CountDownLatch (java.util.concurrent.CountDownLatch)3 DistributedInstanceEvent (org.bboxdb.distribution.membership.DistributedInstanceEvent)3 DistributionGroupAdapter (org.bboxdb.distribution.zookeeper.DistributionGroupAdapter)3 ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)3 BBoxDBConfiguration (org.bboxdb.misc.BBoxDBConfiguration)2 DistributionGroupConfiguration (org.bboxdb.storage.entity.DistributionGroupConfiguration)2 ActionEvent (java.awt.event.ActionEvent)1 File (java.io.File)1 AbstractAction (javax.swing.AbstractAction)1 InputParseException (org.bboxdb.commons.InputParseException)1 SpacePartitioner (org.bboxdb.distribution.partitioner.SpacePartitioner)1 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)1 TupleStoreAdapter (org.bboxdb.distribution.zookeeper.TupleStoreAdapter)1 ZookeeperInstanceRegisterer (org.bboxdb.distribution.zookeeper.ZookeeperInstanceRegisterer)1 ZookeeperNotFoundException (org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException)1