Search in sources :

Example 41 with BBoxDBException

use of org.bboxdb.misc.BBoxDBException in project bboxdb by jnidzwetzki.

the class CLI method actionCreateTable.

/**
 * Create a new table
 * @param line
 */
protected void actionCreateTable(final CommandLine line) {
    if (!line.hasOption(CLIParameter.TABLE)) {
        System.err.println("Create table should be performed, but no table was specified");
        printHelpAndExit();
    }
    final TupleStoreConfigurationBuilder ssTableConfigurationBuilder = TupleStoreConfigurationBuilder.create();
    // Duplicates
    if (line.hasOption(CLIParameter.DUPLICATES)) {
        final String allowDuplicates = line.getOptionValue(CLIParameter.DUPLICATES);
        final boolean duplicatesAllowed = MathUtil.tryParseBooleanOrExit(allowDuplicates, () -> "Unable to parse the bolean value for duplicates: " + allowDuplicates);
        ssTableConfigurationBuilder.allowDuplicates(duplicatesAllowed);
    }
    // TTL
    if (line.hasOption(CLIParameter.TTL)) {
        final String ttlString = line.getOptionValue(CLIParameter.TTL);
        final int ttl = MathUtil.tryParseIntOrExit(ttlString, () -> "Unable to parse the region size: " + ttlString);
        ssTableConfigurationBuilder.withTTL(ttl, TimeUnit.MILLISECONDS);
    }
    // Versions
    if (line.hasOption(CLIParameter.VERSIONS)) {
        final String versionString = line.getOptionValue(CLIParameter.VERSIONS);
        final int versions = MathUtil.tryParseIntOrExit(versionString, () -> "Unable to parse the region size: " + versionString);
        ssTableConfigurationBuilder.withVersions(versions);
    }
    // Spatial index reader
    if (line.hasOption(CLIParameter.SPATIAL_INDEX_READER)) {
        final String spatialIndexReader = line.getOptionValue(CLIParameter.SPATIAL_INDEX_READER);
        ssTableConfigurationBuilder.withSpatialIndexReader(spatialIndexReader);
    }
    // Spatial index writer
    if (line.hasOption(CLIParameter.SPATIAL_INDEX_WRITER)) {
        final String spatialIndexWriter = line.getOptionValue(CLIParameter.SPATIAL_INDEX_WRITER);
        ssTableConfigurationBuilder.withSpatialIndexWriter(spatialIndexWriter);
    }
    final TupleStoreConfiguration configuration = ssTableConfigurationBuilder.build();
    try {
        final String table = line.getOptionValue(CLIParameter.TABLE);
        final EmptyResultFuture resultFuture = bboxDbConnection.createTable(table, configuration);
        resultFuture.waitForAll();
        if (resultFuture.isFailed()) {
            System.err.println("Unable to create table: " + resultFuture.getAllMessages());
            System.exit(-1);
        }
    } catch (BBoxDBException e) {
        System.err.println("Got an exception while creating table: " + e);
        System.exit(-1);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        return;
    }
}
Also used : TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) TupleStoreConfigurationBuilder(org.bboxdb.storage.entity.TupleStoreConfigurationBuilder) BBoxDBException(org.bboxdb.misc.BBoxDBException) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture)

Example 42 with BBoxDBException

use of org.bboxdb.misc.BBoxDBException in project bboxdb by jnidzwetzki.

the class CLI method actionExecuteJoin.

/**
 * Execute the given query
 * @param line
 */
protected void actionExecuteJoin(final CommandLine line) {
    if (!line.hasOption(CLIParameter.TABLE)) {
        System.err.println("Query should be performed, but no table was specified");
        printHelpAndExit();
    }
    if (!line.hasOption(CLIParameter.BOUNDING_BOX)) {
        System.err.println("Bounding box is not given");
        System.exit(-1);
    }
    try {
        final String tables = line.getOptionValue(CLIParameter.TABLE);
        final List<String> tableList = Arrays.asList(tables.split(":"));
        System.out.println("Executing join query...");
        final BoundingBox boundingBox = getBoundingBoxFromArgs(line);
        final JoinedTupleListFuture resultFuture = bboxDbConnection.queryJoin(tableList, boundingBox);
        if (resultFuture == null) {
            System.err.println("Unable to get query");
            System.exit(-1);
        }
        resultFuture.waitForAll();
        if (resultFuture.isFailed()) {
            System.err.println("Unable to execute query: " + resultFuture.getAllMessages());
            System.exit(-1);
        }
        for (final JoinedTuple tuple : resultFuture) {
            printJoinedTuple(tuple);
        }
        System.out.println("Join done");
    } catch (BBoxDBException e) {
        System.err.println("Got an exception while performing query: " + e);
        System.exit(-1);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        return;
    }
}
Also used : JoinedTupleListFuture(org.bboxdb.network.client.future.JoinedTupleListFuture) BoundingBox(org.bboxdb.commons.math.BoundingBox) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) BBoxDBException(org.bboxdb.misc.BBoxDBException)

Example 43 with BBoxDBException

use of org.bboxdb.misc.BBoxDBException in project bboxdb by jnidzwetzki.

the class CLI method actionImportData.

/**
 * Import data
 * @param line
 */
protected void actionImportData(final CommandLine line) {
    final List<String> requiredArgs = Arrays.asList(CLIParameter.FILE, CLIParameter.FORMAT, CLIParameter.TABLE);
    checkRequiredArgs(requiredArgs);
    final String filename = line.getOptionValue(CLIParameter.FILE);
    final String format = line.getOptionValue(CLIParameter.FORMAT);
    final String table = line.getOptionValue(CLIParameter.TABLE);
    System.out.println("Importing file: " + filename);
    final TupleFileReader tupleFile = new TupleFileReader(filename, format);
    tupleFile.addTupleListener(t -> {
        if (t == null) {
            logger.error("Unable to parse line: " + tupleFile.getLastReadLine());
            return;
        }
        if (tupleFile.getProcessedLines() % 1000 == 0) {
            System.out.format("Read %d lines%n", tupleFile.getProcessedLines());
        }
        try {
            final EmptyResultFuture result = bboxDbConnection.insertTuple(table, t);
            pendingFutures.put(result);
        } catch (BBoxDBException e) {
            logger.error("Got exception while inserting tuple", e);
        }
    });
    try {
        tupleFile.processFile();
        pendingFutures.waitForCompletion();
        System.out.format("Successfully imported %d lines%n", tupleFile.getProcessedLines());
    } catch (IOException e) {
        logger.error("Got IO Exception while reading data", e);
        System.exit(-1);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        return;
    }
}
Also used : TupleFileReader(org.bboxdb.tools.TupleFileReader) IOException(java.io.IOException) BBoxDBException(org.bboxdb.misc.BBoxDBException) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture)

Example 44 with BBoxDBException

use of org.bboxdb.misc.BBoxDBException in project bboxdb by jnidzwetzki.

the class CLI method actionExecuteQuery.

/**
 * Execute the given query
 * @param line
 */
protected void actionExecuteQuery(final CommandLine line) {
    if (!line.hasOption(CLIParameter.TABLE)) {
        System.err.println("Query should be performed, but no table was specified");
        printHelpAndExit();
    }
    try {
        final TupleListFuture resultFuture = buildQueryFuture(line);
        if (resultFuture == null) {
            System.err.println("Unable to get query");
            System.exit(-1);
        }
        resultFuture.waitForAll();
        if (resultFuture.isFailed()) {
            System.err.println("Unable to execute query: " + resultFuture.getAllMessages());
            System.exit(-1);
        }
        for (final Tuple tuple : resultFuture) {
            printTuple(tuple);
        }
        System.out.println("Query done");
    } catch (BBoxDBException e) {
        System.err.println("Got an exception while performing query: " + e);
        System.exit(-1);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        return;
    }
}
Also used : TupleListFuture(org.bboxdb.network.client.future.TupleListFuture) JoinedTupleListFuture(org.bboxdb.network.client.future.JoinedTupleListFuture) BBoxDBException(org.bboxdb.misc.BBoxDBException) Tuple(org.bboxdb.storage.entity.Tuple) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple)

Example 45 with BBoxDBException

use of org.bboxdb.misc.BBoxDBException in project bboxdb by jnidzwetzki.

the class CLI method actionExecuteContinuousQuery.

/**
 * Execute a continuous bounding box query
 * @param line
 */
protected void actionExecuteContinuousQuery(final CommandLine line) {
    if (!line.hasOption(CLIParameter.TABLE)) {
        System.err.println("Query should be performed, but no table was specified");
        printHelpAndExit();
    }
    try {
        System.out.println("Executing continuous bounding box query...");
        final String table = line.getOptionValue(CLIParameter.TABLE);
        if (!line.hasOption(CLIParameter.BOUNDING_BOX)) {
            System.err.println("Bounding box is not given");
            System.exit(-1);
        }
        final BoundingBox boundingBox = getBoundingBoxFromArgs(line);
        final TupleListFuture resultFuture = bboxDbConnection.queryBoundingBoxContinuous(table, boundingBox);
        if (resultFuture == null) {
            System.err.println("Unable to get query");
            System.exit(-1);
        }
        resultFuture.waitForAll();
        if (resultFuture.isFailed()) {
            System.err.println("Unable to execute query: " + resultFuture.getAllMessages());
            System.exit(-1);
        }
        for (final Tuple tuple : resultFuture) {
            printTuple(tuple);
        }
        System.out.println("Query done");
    } catch (BBoxDBException e) {
        System.err.println("Got an exception while performing query: " + e);
        System.exit(-1);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        return;
    }
}
Also used : BoundingBox(org.bboxdb.commons.math.BoundingBox) TupleListFuture(org.bboxdb.network.client.future.TupleListFuture) JoinedTupleListFuture(org.bboxdb.network.client.future.JoinedTupleListFuture) BBoxDBException(org.bboxdb.misc.BBoxDBException) Tuple(org.bboxdb.storage.entity.Tuple) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple)

Aggregations

BBoxDBException (org.bboxdb.misc.BBoxDBException)64 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)24 ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)22 BoundingBox (org.bboxdb.commons.math.BoundingBox)17 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)14 SpacePartitioner (org.bboxdb.distribution.partitioner.SpacePartitioner)13 ArrayList (java.util.ArrayList)12 ZookeeperNotFoundException (org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException)12 StorageManagerException (org.bboxdb.storage.StorageManagerException)12 List (java.util.List)11 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)11 EmptyResultFuture (org.bboxdb.network.client.future.EmptyResultFuture)10 Tuple (org.bboxdb.storage.entity.Tuple)9 ResourceAllocationException (org.bboxdb.distribution.placement.ResourceAllocationException)7 RoutingHop (org.bboxdb.network.routing.RoutingHop)7 JoinedTupleListFuture (org.bboxdb.network.client.future.JoinedTupleListFuture)6 RoutingHeader (org.bboxdb.network.routing.RoutingHeader)6 RejectedException (org.bboxdb.commons.RejectedException)5 DistributionRegionIdMapper (org.bboxdb.distribution.region.DistributionRegionIdMapper)5 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)5