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);
}
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;
}
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);
}
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;
}
}
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();
}
Aggregations