Search in sources :

Example 1 with BBoxDBCluster

use of org.bboxdb.network.client.BBoxDBCluster in project bboxdb by jnidzwetzki.

the class TestBBoxDBCluster method testSendDisconnectPackage.

/**
 * Integration test for the disconnect package
 * @throws InterruptedException
 */
@Test(timeout = 60000)
public void testSendDisconnectPackage() throws InterruptedException {
    System.out.println("=== Running cluster testSendDisconnectPackage");
    final BBoxDBCluster bboxdbClient = connectToServer();
    Assert.assertTrue(bboxdbClient.isConnected());
    bboxdbClient.disconnect();
    Assert.assertFalse(bboxdbClient.isConnected());
    System.out.println("=== End cluster testSendDisconnectPackage");
    disconnect(bboxdbClient);
}
Also used : BBoxDBCluster(org.bboxdb.network.client.BBoxDBCluster) Test(org.junit.Test)

Example 2 with BBoxDBCluster

use of org.bboxdb.network.client.BBoxDBCluster in project bboxdb by jnidzwetzki.

the class TestBBoxDBCluster method connectToServer.

/**
 * Build a new connection to the bboxdb server
 *
 * @return
 * @throws InterruptedException
 */
protected BBoxDBCluster connectToServer() throws InterruptedException {
    final String clusterName = BBoxDBConfigurationManager.getConfiguration().getClustername();
    final BBoxDBCluster bboxdbCluster = new BBoxDBCluster(CLUSTER_CONTACT_POINT, clusterName);
    final boolean result = bboxdbCluster.connect();
    Assert.assertTrue(result);
    Thread.sleep(50);
    Assert.assertTrue(bboxdbCluster.isConnected());
    return bboxdbCluster;
}
Also used : BBoxDBCluster(org.bboxdb.network.client.BBoxDBCluster)

Example 3 with BBoxDBCluster

use of org.bboxdb.network.client.BBoxDBCluster in project bboxdb by jnidzwetzki.

the class DistributedSelftest method main.

public static void main(final String[] args) throws InterruptedException, ExecutionException, BBoxDBException {
    if (args.length < 2) {
        logger.error("Usage: DistributedSelftest <Cluster-Name> <Cluster-Endpoint1> <Cluster-EndpointN>");
        System.exit(-1);
    }
    logger.info("Running selftest......");
    final String clustername = args[0];
    final Collection<String> endpoints = new ArrayList<String>();
    for (int i = 1; i < args.length; i++) {
        endpoints.add(args[i]);
    }
    final BBoxDBCluster bboxdbCluster = new BBoxDBCluster(endpoints, clustername);
    bboxdbCluster.connect();
    if (!bboxdbCluster.isConnected()) {
        logger.error("Connection could not be established");
        System.exit(-1);
    }
    logger.info("Connected to cluster: " + clustername);
    logger.info("With endpoint(s): " + endpoints);
    recreateDistributionGroup(bboxdbCluster);
    executeSelftest(bboxdbCluster);
}
Also used : ArrayList(java.util.ArrayList) BBoxDBCluster(org.bboxdb.network.client.BBoxDBCluster)

Example 4 with BBoxDBCluster

use of org.bboxdb.network.client.BBoxDBCluster in project bboxdb by jnidzwetzki.

the class CLI method run.

public void run() {
    // Default Zookeeper values
    String zookeeperHost = "localhost:2181";
    String zookeeperClustername = "mycluster";
    if (line.hasOption(CLIParameter.ZOOKEEPER_HOST)) {
        zookeeperHost = line.getOptionValue(CLIParameter.ZOOKEEPER_HOST);
    }
    if (line.hasOption(CLIParameter.ZOOKEEPER_CLUSTER_NAME)) {
        zookeeperClustername = line.getOptionValue(CLIParameter.ZOOKEEPER_CLUSTER_NAME);
    }
    // Connect to zookeeper and BBoxDB
    System.out.print("Connecting to BBoxDB cluster...");
    System.out.flush();
    bboxDbConnection = new BBoxDBCluster(zookeeperHost, zookeeperClustername);
    if (!bboxDbConnection.connect()) {
        System.err.println("\n\n");
        System.err.println("Error: Unable to connect to the BBoxDB cluster.");
        System.err.format("Error: Did you specified the correct Zookeeper host (-%s=%s) " + "and cluster (-%s=%s)?%n", CLIParameter.ZOOKEEPER_HOST, zookeeperHost, CLIParameter.ZOOKEEPER_CLUSTER_NAME, zookeeperClustername);
        System.exit(-1);
    }
    System.out.println(" [Established]");
    if (line.hasOption(CLIParameter.VERBOSE)) {
        org.apache.log4j.Logger logger4j = org.apache.log4j.Logger.getRootLogger();
        logger4j.setLevel(org.apache.log4j.Level.toLevel("DEBUG"));
    }
    final String action = line.getOptionValue(CLIParameter.ACTION);
    switch(action) {
        case CLIAction.CREATE_DGROUP:
            actionCreateDgroup(line);
            break;
        case CLIAction.DELETE_DGROUP:
            actionDeleteDgroup(line);
            break;
        case CLIAction.SHOW_DGROUP:
            actionShowDgroup(line);
            break;
        case CLIAction.CREATE_TABLE:
            actionCreateTable(line);
            break;
        case CLIAction.DELETE_TABLE:
            actionDeleteTable(line);
            break;
        case CLIAction.SHOW_INSTANCES:
            actionShowInstances(line);
            break;
        case CLIAction.IMPORT:
            actionImportData(line);
            break;
        case CLIAction.QUERY:
            actionExecuteQuery(line);
            break;
        case CLIAction.JOIN:
            actionExecuteJoin(line);
            break;
        case CLIAction.CONTINUOUS_QUERY:
            actionExecuteContinuousQuery(line);
            break;
        case CLIAction.INSERT:
            actionInsertTuple(line);
            break;
        case CLIAction.DELETE:
            actionDeleteTuple(line);
            break;
        default:
            break;
    }
}
Also used : BBoxDBCluster(org.bboxdb.network.client.BBoxDBCluster)

Example 5 with BBoxDBCluster

use of org.bboxdb.network.client.BBoxDBCluster 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)

Aggregations

BBoxDBCluster (org.bboxdb.network.client.BBoxDBCluster)8 BoundingBox (org.bboxdb.commons.math.BoundingBox)2 BBoxDB (org.bboxdb.network.client.BBoxDB)2 ArrayList (java.util.ArrayList)1 EmptyResultFuture (org.bboxdb.network.client.future.EmptyResultFuture)1 TupleListFuture (org.bboxdb.network.client.future.TupleListFuture)1 DistributionGroupConfiguration (org.bboxdb.storage.entity.DistributionGroupConfiguration)1 Tuple (org.bboxdb.storage.entity.Tuple)1 TupleStoreConfiguration (org.bboxdb.storage.entity.TupleStoreConfiguration)1 Test (org.junit.Test)1