Search in sources :

Example 21 with DistributionGroupConfiguration

use of org.bboxdb.storage.entity.DistributionGroupConfiguration in project bboxdb by jnidzwetzki.

the class BenchmarkFileInsertPerformance method prepare.

@Override
protected void prepare() throws Exception {
    super.prepare();
    // Remove old data
    final EmptyResultFuture deleteResult = bboxdbClient.deleteDistributionGroup(DISTRIBUTION_GROUP);
    deleteResult.waitForAll();
    // Create a new distribution group
    final DistributionGroupConfiguration config = DistributionGroupConfigurationBuilder.create(2).withReplicationFactor(replicationFactor).build();
    final EmptyResultFuture createResult = bboxdbClient.createDistributionGroup(DISTRIBUTION_GROUP, config);
    createResult.waitForAll();
}
Also used : DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture)

Example 22 with DistributionGroupConfiguration

use of org.bboxdb.storage.entity.DistributionGroupConfiguration in project bboxdb by jnidzwetzki.

the class BBoxDBClientExample method main.

/**
 * Connect to the BBoxDB Server at localhost and insert some tuples
 *
 * @param args
 * @throws ExecutionException
 * @throws InterruptedException
 * @throws BBoxDBException
 */
public static void main(String[] args) throws InterruptedException, ExecutionException, BBoxDBException {
    // A 2 dimensional table (member of distribution group 'mygroup3') with the name 'testdata'
    final int dimensions = 2;
    final String distributionGroup = "mygroup3";
    final String mytable = distributionGroup + "_testdata";
    // The name of the cluster
    final String clustername = "mycluster";
    // The zookeeper connect points
    final List<String> connectPoints = Arrays.asList("localhost:2181");
    // Connect to the server
    final BBoxDB bboxdbClient = new BBoxDBCluster(connectPoints, clustername);
    bboxdbClient.connect();
    // Check the connection state
    if (!bboxdbClient.isConnected()) {
        System.out.println("Error while connecting to the BBoxDB cluster");
        System.exit(-1);
    }
    // Clean the old content of the distribution group
    final EmptyResultFuture deleteGroupResult = bboxdbClient.deleteDistributionGroup(distributionGroup);
    deleteGroupResult.waitForAll();
    if (deleteGroupResult.isFailed()) {
        System.err.println("Unable to delete distribution group: " + distributionGroup);
        System.err.println(deleteGroupResult.getAllMessages());
        System.exit(-1);
    }
    // Create a new distribution group
    final DistributionGroupConfiguration configuration = DistributionGroupConfigurationBuilder.create(dimensions).withReplicationFactor((short) 3).build();
    final EmptyResultFuture createGroupResult = bboxdbClient.createDistributionGroup(distributionGroup, configuration);
    createGroupResult.waitForAll();
    if (createGroupResult.isFailed()) {
        System.err.println("Unable to create distribution group: " + distributionGroup);
        System.err.println(createGroupResult.getAllMessages());
        System.exit(-1);
    }
    // Create the table
    final TupleStoreConfiguration tableConfig = TupleStoreConfigurationBuilder.create().allowDuplicates(false).build();
    final EmptyResultFuture createTableResult = bboxdbClient.createTable(mytable, tableConfig);
    createTableResult.waitForAll();
    if (createTableResult.isFailed()) {
        System.err.println("Unable to create table group: " + mytable);
        System.err.println(createTableResult.getAllMessages());
        System.exit(-1);
    }
    // Insert two new tuples
    final Tuple tuple1 = new Tuple("key1", new BoundingBox(0d, 5d, 0d, 1d), "mydata1".getBytes());
    final EmptyResultFuture insertResult1 = bboxdbClient.insertTuple(mytable, tuple1);
    final Tuple tuple2 = new Tuple("key2", new BoundingBox(-1d, 2d, -1d, 2d), "mydata2".getBytes());
    final EmptyResultFuture insertResult2 = bboxdbClient.insertTuple(mytable, tuple2);
    // Wait for the insert operations to complete
    insertResult1.waitForAll();
    insertResult2.waitForAll();
    if (insertResult1.isFailed()) {
        System.err.println("Unable to insert tuple: " + insertResult1.getAllMessages());
        System.exit(-1);
    }
    if (insertResult2.isFailed()) {
        System.err.println("Unable to insert tuple: " + insertResult2.getAllMessages());
        System.exit(-1);
    }
    // Query by key
    final TupleListFuture resultFuture1 = bboxdbClient.queryKey(mytable, "key");
    // We got a future object, the search is performed asynchronous
    // Wait for the result
    resultFuture1.waitForAll();
    if (resultFuture1.isFailed()) {
        System.err.println("NetworkOperationFuture is failed: " + resultFuture1.getAllMessages());
        System.exit(-1);
    }
    // Output all tuples
    for (final Tuple tuple : resultFuture1) {
        System.out.println(tuple);
    }
    // Query by bounding box
    final TupleListFuture resultFuture2 = bboxdbClient.queryBoundingBox(mytable, new BoundingBox(-0.5d, 1d, -0.5d, 1d));
    // Again, we got a future object, the search is performed asynchronous
    resultFuture2.waitForAll();
    if (resultFuture2.isFailed()) {
        System.err.println("NetworkOperationFuture is failed: " + resultFuture2.getAllMessages());
        System.exit(-1);
    }
    // Output all tuples
    for (final Tuple tuple : resultFuture2) {
        System.out.println("Tuple: " + tuple);
    }
    bboxdbClient.disconnect();
}
Also used : BBoxDB(org.bboxdb.network.client.BBoxDB) TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) BoundingBox(org.bboxdb.commons.math.BoundingBox) TupleListFuture(org.bboxdb.network.client.future.TupleListFuture) BBoxDBCluster(org.bboxdb.network.client.BBoxDBCluster) DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration) Tuple(org.bboxdb.storage.entity.Tuple) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture)

Example 23 with DistributionGroupConfiguration

use of org.bboxdb.storage.entity.DistributionGroupConfiguration in project bboxdb by jnidzwetzki.

the class CreateDistributionGroupRequest method decodeTuple.

/**
 * Decode the encoded package into a object
 *
 * @param encodedPackage
 * @return
 * @throws PackageEncodeException
 */
public static CreateDistributionGroupRequest decodeTuple(final ByteBuffer encodedPackage) throws PackageEncodeException {
    final short sequenceNumber = NetworkPackageDecoder.getRequestIDFromRequestPackage(encodedPackage);
    final boolean decodeResult = NetworkPackageDecoder.validateRequestPackageHeader(encodedPackage, NetworkConst.REQUEST_TYPE_CREATE_DISTRIBUTION_GROUP);
    if (decodeResult == false) {
        throw new PackageEncodeException("Unable to decode package");
    }
    final int dimensions = encodedPackage.getInt();
    final short replicationFactor = encodedPackage.getShort();
    final short groupLength = encodedPackage.getShort();
    final short placementLength = encodedPackage.getShort();
    final short spacePartitionerLength = encodedPackage.getShort();
    final int placementConfigLength = encodedPackage.getInt();
    final int spacePartitionerConfigLength = encodedPackage.getInt();
    final int maximumRegionSize = encodedPackage.getInt();
    final int minimumRegionSize = encodedPackage.getInt();
    // Distribution group
    final byte[] groupBytes = new byte[groupLength];
    encodedPackage.get(groupBytes, 0, groupBytes.length);
    final String distributionGroup = new String(groupBytes);
    // Placement strategy
    final byte[] placementBytes = new byte[placementLength];
    encodedPackage.get(placementBytes, 0, placementBytes.length);
    final String placemeneStrategy = new String(placementBytes);
    // Placement config length
    final byte[] placementConfigBytes = new byte[placementConfigLength];
    encodedPackage.get(placementConfigBytes, 0, placementConfigBytes.length);
    final String placementConfig = new String(placementConfigBytes);
    // Space partitioner
    final byte[] spacePartitionerBytes = new byte[spacePartitionerLength];
    encodedPackage.get(spacePartitionerBytes, 0, spacePartitionerBytes.length);
    final String spacePartitioner = new String(spacePartitionerBytes);
    // Space partitioner configuration
    final byte[] spacePartitionerConfigBytes = new byte[spacePartitionerConfigLength];
    encodedPackage.get(spacePartitionerConfigBytes, 0, spacePartitionerConfigBytes.length);
    final String spacePartitionerConfig = new String(spacePartitionerConfigBytes);
    if (encodedPackage.remaining() != 0) {
        throw new PackageEncodeException("Some bytes are left after decoding: " + encodedPackage.remaining());
    }
    final DistributionGroupConfiguration configuration = DistributionGroupConfigurationBuilder.create(dimensions).withPlacementStrategy(placemeneStrategy, placementConfig).withSpacePartitioner(spacePartitioner, spacePartitionerConfig).withMaximumRegionSize(maximumRegionSize).withMinimumRegionSize(minimumRegionSize).withReplicationFactor(replicationFactor).build();
    return new CreateDistributionGroupRequest(sequenceNumber, distributionGroup, configuration);
}
Also used : PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration)

Example 24 with DistributionGroupConfiguration

use of org.bboxdb.storage.entity.DistributionGroupConfiguration in project bboxdb by jnidzwetzki.

the class TestNetworkCommunication method testCreateDistributionGroupTwoTimes.

/**
 * Test create a distribution group two times
 * @throws BBoxDBException
 * @throws InterruptedException
 */
@Test(timeout = 60000)
public void testCreateDistributionGroupTwoTimes() throws BBoxDBException, InterruptedException {
    final BBoxDBConnection bboxdbConnection = connectToServer();
    final BBoxDBClient bboxDBClient = bboxdbConnection.getBboxDBClient();
    // Create distribution group
    final DistributionGroupConfiguration configuration = DistributionGroupConfigurationBuilder.create(2).withReplicationFactor((short) 1).build();
    final EmptyResultFuture resultCreate = bboxDBClient.createDistributionGroup(DISTRIBUTION_GROUP, configuration);
    // Prevent retries
    resultCreate.setRetryPolicy(FutureRetryPolicy.RETRY_POLICY_NONE);
    resultCreate.waitForAll();
    Assert.assertTrue(resultCreate.isFailed());
    Assert.assertEquals(ErrorMessages.ERROR_DGROUP_EXISTS, resultCreate.getMessage(0));
    Assert.assertTrue(bboxdbConnection.getConnectionState().isInRunningState());
    disconnect(bboxDBClient);
}
Also used : BBoxDBClient(org.bboxdb.network.client.BBoxDBClient) DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration) BBoxDBConnection(org.bboxdb.network.client.BBoxDBConnection) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture) Test(org.junit.Test)

Example 25 with DistributionGroupConfiguration

use of org.bboxdb.storage.entity.DistributionGroupConfiguration in project bboxdb by jnidzwetzki.

the class TestSampling method before.

@Before
public void before() throws ZookeeperException, BBoxDBException, StorageManagerException {
    final DistributionGroupConfiguration configuration = DistributionGroupConfigurationBuilder.create(2).withPlacementStrategy("org.bboxdb.distribution.placement.DummyResourcePlacementStrategy", "").build();
    storageRegistry.deleteAllTablesInDistributionGroup(TEST_GROUP);
    distributionGroupZookeeperAdapter.deleteDistributionGroup(TEST_GROUP);
    distributionGroupZookeeperAdapter.createDistributionGroup(TEST_GROUP, configuration);
}
Also used : DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration) Before(org.junit.Before)

Aggregations

DistributionGroupConfiguration (org.bboxdb.storage.entity.DistributionGroupConfiguration)43 Test (org.junit.Test)12 EmptyResultFuture (org.bboxdb.network.client.future.EmptyResultFuture)9 Before (org.junit.Before)7 ZookeeperNotFoundException (org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException)4 BeforeClass (org.junit.BeforeClass)4 BoundingBox (org.bboxdb.commons.math.BoundingBox)3 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)3 ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)3 BBoxDBException (org.bboxdb.misc.BBoxDBException)3 Tuple (org.bboxdb.storage.entity.Tuple)3 DistributionGroupAdapter (org.bboxdb.distribution.zookeeper.DistributionGroupAdapter)2 ZookeeperClient (org.bboxdb.distribution.zookeeper.ZookeeperClient)2 TupleStoreConfiguration (org.bboxdb.storage.entity.TupleStoreConfiguration)2 Cursor (java.awt.Cursor)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 HashSet (java.util.HashSet)1 Random (java.util.Random)1 InputParseException (org.bboxdb.commons.InputParseException)1