Search in sources :

Example 6 with BBoxDBInstanceManager

use of org.bboxdb.distribution.membership.BBoxDBInstanceManager in project bboxdb by jnidzwetzki.

the class TestDistributedInstanceManager method testRegisterUnregister2.

/**
 * test unregister
 */
@Test(timeout = 60000)
public void testRegisterUnregister2() throws InterruptedException {
    final BBoxDBInstance instance = new BBoxDBInstance("node1:5050");
    final ZookeeperClient zookeeperClient = getNewZookeeperClient(instance);
    BBoxDBInstanceManager.getInstance().startMembershipObserver(zookeeperClient);
    Assert.assertTrue(zookeeperClient.isConnected());
    Thread.sleep(1000);
    final BBoxDBInstanceManager distributedInstanceManager = BBoxDBInstanceManager.getInstance();
    Assert.assertFalse(distributedInstanceManager.getInstances().isEmpty());
    Assert.assertEquals(1, distributedInstanceManager.getInstances().size());
    Assert.assertEquals(instance.getInetSocketAddress(), distributedInstanceManager.getInstances().get(0).getInetSocketAddress());
    zookeeperClient.shutdown();
    Assert.assertTrue(distributedInstanceManager.getInstances().isEmpty());
    final BBoxDBInstance instance2 = new BBoxDBInstance("node1:5050");
    final ZookeeperClient zookeeperClient2 = getNewZookeeperClient(instance2);
    BBoxDBInstanceManager.getInstance().startMembershipObserver(zookeeperClient2);
    Assert.assertTrue(zookeeperClient2.isConnected());
    Thread.sleep(1000);
    Assert.assertFalse(distributedInstanceManager.getInstances().isEmpty());
    Assert.assertEquals(1, distributedInstanceManager.getInstances().size());
    Assert.assertEquals(instance.getInetSocketAddress(), distributedInstanceManager.getInstances().get(0).getInetSocketAddress());
    zookeeperClient2.shutdown();
}
Also used : ZookeeperClient(org.bboxdb.distribution.zookeeper.ZookeeperClient) BBoxDBInstanceManager(org.bboxdb.distribution.membership.BBoxDBInstanceManager) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) Test(org.junit.Test)

Example 7 with BBoxDBInstanceManager

use of org.bboxdb.distribution.membership.BBoxDBInstanceManager in project bboxdb by jnidzwetzki.

the class SpacePartitionerHelper method allocateSystemsToRegion.

/**
 * Allocate the required amount of systems to the given region
 *
 * @param region
 * @param zookeeperClient
 * @throws ZookeeperException
 * @throws ResourceAllocationException
 * @throws ZookeeperNotFoundException
 */
public static void allocateSystemsToRegion(final String regionPath, final String distributionGroupName, final Collection<BBoxDBInstance> blacklist, final ZookeeperClient zookeeperClient) throws ZookeeperException, ResourceAllocationException, ZookeeperNotFoundException {
    final DistributionGroupConfiguration config = DistributionGroupConfigurationCache.getInstance().getDistributionGroupConfiguration(distributionGroupName);
    final short replicationFactor = config.getReplicationFactor();
    final BBoxDBInstanceManager distributedInstanceManager = BBoxDBInstanceManager.getInstance();
    final List<BBoxDBInstance> availableSystems = distributedInstanceManager.getInstances();
    final String placementStrategy = config.getPlacementStrategy();
    final ResourcePlacementStrategy resourcePlacementStrategy = ResourcePlacementStrategyFactory.getInstance(placementStrategy);
    if (resourcePlacementStrategy == null) {
        throw new ResourceAllocationException("Unable to instanciate the ressource " + "placement strategy");
    }
    // The blacklist, to prevent duplicate allocations
    final Set<BBoxDBInstance> allocationSystems = new HashSet<>();
    final Set<BBoxDBInstance> blacklistedSystems = new HashSet<>();
    blacklistedSystems.addAll(blacklist);
    for (short i = 0; i < replicationFactor; i++) {
        final BBoxDBInstance instance = resourcePlacementStrategy.getInstancesForNewRessource(availableSystems, blacklistedSystems);
        allocationSystems.add(instance);
        blacklistedSystems.add(instance);
    }
    logger.info("Allocated new ressource to {} with blacklist {}", allocationSystems, blacklist);
    zookeeperClient.getDistributionRegionAdapter().allocateSystemsToRegion(regionPath, allocationSystems);
}
Also used : BBoxDBInstanceManager(org.bboxdb.distribution.membership.BBoxDBInstanceManager) DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) ResourceAllocationException(org.bboxdb.distribution.placement.ResourceAllocationException) ResourcePlacementStrategy(org.bboxdb.distribution.placement.ResourcePlacementStrategy) HashSet(java.util.HashSet)

Example 8 with BBoxDBInstanceManager

use of org.bboxdb.distribution.membership.BBoxDBInstanceManager 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 9 with BBoxDBInstanceManager

use of org.bboxdb.distribution.membership.BBoxDBInstanceManager 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 10 with BBoxDBInstanceManager

use of org.bboxdb.distribution.membership.BBoxDBInstanceManager 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

BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)11 BBoxDBInstanceManager (org.bboxdb.distribution.membership.BBoxDBInstanceManager)11 ZookeeperClient (org.bboxdb.distribution.zookeeper.ZookeeperClient)9 Test (org.junit.Test)9 ZookeeperBBoxDBInstanceAdapter (org.bboxdb.distribution.membership.ZookeeperBBoxDBInstanceAdapter)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 DistributedInstanceEvent (org.bboxdb.distribution.membership.DistributedInstanceEvent)3 HashSet (java.util.HashSet)1 ResourceAllocationException (org.bboxdb.distribution.placement.ResourceAllocationException)1 ResourcePlacementStrategy (org.bboxdb.distribution.placement.ResourcePlacementStrategy)1 DistributionGroupConfiguration (org.bboxdb.storage.entity.DistributionGroupConfiguration)1