Search in sources :

Example 1 with Protocol

use of com.arangodb.Protocol in project YCSB by brianfrankcooper.

the class ArangoDBClient method init.

/**
 * Initialize any state for this DB. Called once per DB instance; there is
 * one DB instance per client thread.
 *
 * Actually, one client process will share one DB instance here.(Coincide to
 * mongoDB driver)
 */
@Override
public void init() throws DBException {
    synchronized (ArangoDBClient.class) {
        Properties props = getProperties();
        collectionName = props.getProperty("table", "usertable");
        // Set the DB address
        String ip = props.getProperty("arangodb.ip", "localhost");
        String portStr = props.getProperty("arangodb.port", "8529");
        int port = Integer.parseInt(portStr);
        // Set network protocol
        String protocolStr = props.getProperty("arangodb.protocol", "VST");
        Protocol protocol = Protocol.valueOf(protocolStr);
        // If clear db before run
        String dropDBBeforeRunStr = props.getProperty("arangodb.dropDBBeforeRun", "false");
        dropDBBeforeRun = Boolean.parseBoolean(dropDBBeforeRunStr);
        // Set the sync mode
        String waitForSyncStr = props.getProperty("arangodb.waitForSync", "false");
        waitForSync = Boolean.parseBoolean(waitForSyncStr);
        // Set if transaction for update
        String transactionUpdateStr = props.getProperty("arangodb.transactionUpdate", "false");
        transactionUpdate = Boolean.parseBoolean(transactionUpdateStr);
        // Init ArangoDB connection
        try {
            arangoDB = new ArangoDB.Builder().host(ip).port(port).useProtocol(protocol).build();
        } catch (Exception e) {
            logger.error("Failed to initialize ArangoDB", e);
            System.exit(-1);
        }
        if (INIT_COUNT.getAndIncrement() == 0) {
            // Init the database
            if (dropDBBeforeRun) {
                // Try delete first
                try {
                    arangoDB.db(databaseName).drop();
                } catch (ArangoDBException e) {
                    logger.info("Fail to delete DB: {}", databaseName);
                }
            }
            try {
                arangoDB.createDatabase(databaseName);
                logger.info("Database created: " + databaseName);
            } catch (ArangoDBException e) {
                logger.error("Failed to create database: {} with ex: {}", databaseName, e.toString());
            }
            try {
                arangoDB.db(databaseName).createCollection(collectionName);
                logger.info("Collection created: " + collectionName);
            } catch (ArangoDBException e) {
                logger.error("Failed to create collection: {} with ex: {}", collectionName, e.toString());
            }
            logger.info("ArangoDB client connection created to {}:{}", ip, port);
            // Log the configuration
            logger.info("Arango Configuration: dropDBBeforeRun: {}; address: {}:{}; databaseName: {};" + " waitForSync: {}; transactionUpdate: {};", dropDBBeforeRun, ip, port, databaseName, waitForSync, transactionUpdate);
        }
    }
}
Also used : ArangoDB(com.arangodb.ArangoDB) Properties(java.util.Properties) Protocol(com.arangodb.Protocol) ArangoDBException(com.arangodb.ArangoDBException) IOException(java.io.IOException) DBException(site.ycsb.DBException) ArangoDBException(com.arangodb.ArangoDBException)

Aggregations

ArangoDB (com.arangodb.ArangoDB)1 ArangoDBException (com.arangodb.ArangoDBException)1 Protocol (com.arangodb.Protocol)1 IOException (java.io.IOException)1 Properties (java.util.Properties)1 DBException (site.ycsb.DBException)1