use of org.bboxdb.distribution.zookeeper.TupleStoreAdapter 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");
}
use of org.bboxdb.distribution.zookeeper.TupleStoreAdapter in project bboxdb by jnidzwetzki.
the class CreateTableHandler method handleRequest.
@Override
public /**
* Handle the create table call
*/
boolean handleRequest(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
try {
final CreateTableRequest createPackage = CreateTableRequest.decodeTuple(encodedPackage);
final TupleStoreName requestTable = createPackage.getTable();
logger.info("Got create call for table: {}", requestTable.getFullname());
final TupleStoreAdapter tupleStoreAdapter = ZookeeperClientFactory.getZookeeperClient().getTupleStoreAdapter();
if (tupleStoreAdapter.isTableKnown(requestTable)) {
logger.warn("Table name is already known {}", requestTable.getFullname());
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_TABLE_EXISTS);
clientConnectionHandler.writeResultPackage(responsePackage);
} else {
tupleStoreAdapter.writeTuplestoreConfiguration(requestTable, createPackage.getTupleStoreConfiguration());
clientConnectionHandler.writeResultPackage(new SuccessResponse(packageSequence));
}
} catch (Exception e) {
logger.warn("Error while delete tuple", e);
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION);
clientConnectionHandler.writeResultPackage(responsePackage);
}
return true;
}
use of org.bboxdb.distribution.zookeeper.TupleStoreAdapter in project bboxdb by jnidzwetzki.
the class InsertTupleHandler method createMissingTables.
/**
* Create all missing tables
*/
protected void createMissingTables(final TupleStoreName requestTable, final TupleStoreManagerRegistry storageRegistry, final Collection<TupleStoreName> localTables) throws StorageManagerException {
try {
final TupleStoreAdapter tupleStoreAdapter = ZookeeperClientFactory.getZookeeperClient().getTupleStoreAdapter();
if (!tupleStoreAdapter.isTableKnown(requestTable)) {
throw new StorageManagerException("Table: " + requestTable.getFullname() + " is unkown");
}
final TupleStoreConfiguration config = tupleStoreAdapter.readTuplestoreConfiguration(requestTable);
for (final TupleStoreName tupleStoreName : localTables) {
final boolean alreadyKnown = storageRegistry.isStorageManagerKnown(tupleStoreName);
if (!alreadyKnown) {
storageRegistry.createTableIfNotExist(tupleStoreName, config);
}
}
} catch (ZookeeperException e) {
throw new StorageManagerException(e);
}
}
use of org.bboxdb.distribution.zookeeper.TupleStoreAdapter in project bboxdb by jnidzwetzki.
the class TupleStoreConfigurationCache method getDuplicateResolverForTupleStore.
public synchronized DuplicateResolver<Tuple> getDuplicateResolverForTupleStore(final String tupleStorename) {
if (!cache.containsKey(tupleStorename)) {
try {
final TupleStoreAdapter tupleStoreAdapter = ZookeeperClientFactory.getZookeeperClient().getTupleStoreAdapter();
final TupleStoreName tupleStoreNameObject = new TupleStoreName(tupleStorename);
if (!tupleStoreAdapter.isTableKnown(tupleStoreNameObject)) {
logger.error("Table {} is not known, using do nothing duplicate resolver", tupleStorename);
return new DoNothingDuplicateResolver();
}
final TupleStoreConfiguration tupleStoreConfiguration = tupleStoreAdapter.readTuplestoreConfiguration(tupleStoreNameObject);
final DuplicateResolver<Tuple> resolver = TupleDuplicateResolverFactory.build(tupleStoreConfiguration);
cache.put(tupleStorename, resolver);
} catch (ZookeeperException e) {
logger.error("Exception while reading zookeeper data", e);
return new DoNothingDuplicateResolver();
}
}
final DuplicateResolver<Tuple> duplicateResolver = cache.get(tupleStorename);
return duplicateResolver;
}
Aggregations