Search in sources :

Example 31 with PackageEncodeException

use of org.bboxdb.network.packages.PackageEncodeException in project bboxdb by jnidzwetzki.

the class TestCompressionRatio method handleCompressedData.

/**
 * Handle compressed packages
 * @param tableName
 * @param buffer
 * @return
 * @throws PackageEncodeException
 * @throws IOException
 */
protected long handleCompressedData(final TupleStoreName tableName, final List<Tuple> buffer) {
    final RoutingHeader routingHeader = new RoutingHeader(false);
    final List<NetworkRequestPackage> packages = buffer.stream().map(t -> new InsertTupleRequest((short) 4, routingHeader, tableName, t)).collect(Collectors.toList());
    final CompressionEnvelopeRequest compressionEnvelopeRequest = new CompressionEnvelopeRequest(NetworkConst.COMPRESSION_TYPE_GZIP, packages);
    buffer.clear();
    return packageToBytes(compressionEnvelopeRequest);
}
Also used : Arrays(java.util.Arrays) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) Logger(org.slf4j.Logger) ByteArrayOutputStream(java.io.ByteArrayOutputStream) NetworkConst(org.bboxdb.network.NetworkConst) InsertTupleRequest(org.bboxdb.network.packages.request.InsertTupleRequest) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) Tuple(org.bboxdb.storage.entity.Tuple) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Objects(java.util.Objects) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) List(java.util.List) TupleFileReader(org.bboxdb.tools.TupleFileReader) CompressionEnvelopeRequest(org.bboxdb.network.packages.request.CompressionEnvelopeRequest) NetworkRequestPackage(org.bboxdb.network.packages.NetworkRequestPackage) CompressionEnvelopeRequest(org.bboxdb.network.packages.request.CompressionEnvelopeRequest) NetworkRequestPackage(org.bboxdb.network.packages.NetworkRequestPackage) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) InsertTupleRequest(org.bboxdb.network.packages.request.InsertTupleRequest)

Example 32 with PackageEncodeException

use of org.bboxdb.network.packages.PackageEncodeException in project bboxdb by jnidzwetzki.

the class DeleteTableHandler method handleRequest.

@Override
public /**
 * Handle the delete table call
 */
boolean handleRequest(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
    try {
        final DeleteTableRequest deletePackage = DeleteTableRequest.decodeTuple(encodedPackage);
        final TupleStoreName requestTable = deletePackage.getTable();
        logger.info("Got delete call for table: {}", requestTable);
        // Delete zookeeper configuration
        final TupleStoreAdapter tupleStoreAdapter = ZookeeperClientFactory.getZookeeperClient().getTupleStoreAdapter();
        tupleStoreAdapter.deleteTable(requestTable);
        // Clear cached data
        TupleStoreConfigurationCache.getInstance().clear();
        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;
}
Also used : DeleteTableRequest(org.bboxdb.network.packages.request.DeleteTableRequest) SuccessResponse(org.bboxdb.network.packages.response.SuccessResponse) TupleStoreAdapter(org.bboxdb.distribution.zookeeper.TupleStoreAdapter) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) IOException(java.io.IOException) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse)

Example 33 with PackageEncodeException

use of org.bboxdb.network.packages.PackageEncodeException in project bboxdb by jnidzwetzki.

the class NetworkHelper method uncompressBytes.

/**
 * Uncompress the data in the byte array
 * @param compressionType
 * @param compressedBytes
 * @return
 * @throws PackageEncodeException
 */
public static byte[] uncompressBytes(final byte compressionType, final byte[] compressedBytes) throws PackageEncodeException {
    try {
        final ByteArrayInputStream bais = new ByteArrayInputStream(compressedBytes);
        final GZIPInputStream inputStream = new GZIPInputStream(bais);
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final byte[] buffer = new byte[10240];
        for (int length = 0; (length = inputStream.read(buffer)) > 0; ) {
            baos.write(buffer, 0, length);
        }
        inputStream.close();
        baos.close();
        return baos.toByteArray();
    } catch (IOException e) {
        throw new PackageEncodeException(e);
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 34 with PackageEncodeException

use of org.bboxdb.network.packages.PackageEncodeException in project bboxdb by jnidzwetzki.

the class BBoxDBConnection method testPackageSend.

/**
 * Recalculate the routing header and handle the exceptions
 * @param requestPackage
 * @param future
 * @return
 */
private boolean testPackageSend(final NetworkRequestPackage requestPackage, final NetworkOperationFuture future) {
    try {
        // Check if package needs to be send
        final RoutingHeader routingHeader = requestPackage.getRoutingHeader();
        if (routingHeader.isRoutedPackage()) {
            if (routingHeader.getHopCount() == 0) {
                future.setMessage("No distribution regions in next hop, not sending to server");
                future.fireCompleteEvent();
                return false;
            }
        }
    } catch (PackageEncodeException e) {
        final String message = "Got a exception during package encoding";
        logger.error(message);
        future.setMessage(message);
        future.setFailedState();
        future.fireCompleteEvent();
        return false;
    }
    return true;
}
Also used : PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) RoutingHeader(org.bboxdb.network.routing.RoutingHeader)

Example 35 with PackageEncodeException

use of org.bboxdb.network.packages.PackageEncodeException in project bboxdb by jnidzwetzki.

the class CreateDistributionGroupRequest method decodeTuple.

/**
 * Decode the encoded package into a object
 *
 * @param encodedPackage
 * @return
 * @throws PackageEncodeException
 */
public static CreateDistributionGroupRequest decodeTuple(final ByteBuffer encodedPackage) throws PackageEncodeException {
    final short sequenceNumber = NetworkPackageDecoder.getRequestIDFromRequestPackage(encodedPackage);
    final boolean decodeResult = NetworkPackageDecoder.validateRequestPackageHeader(encodedPackage, NetworkConst.REQUEST_TYPE_CREATE_DISTRIBUTION_GROUP);
    if (decodeResult == false) {
        throw new PackageEncodeException("Unable to decode package");
    }
    final int dimensions = encodedPackage.getInt();
    final short replicationFactor = encodedPackage.getShort();
    final short groupLength = encodedPackage.getShort();
    final short placementLength = encodedPackage.getShort();
    final short spacePartitionerLength = encodedPackage.getShort();
    final int placementConfigLength = encodedPackage.getInt();
    final int spacePartitionerConfigLength = encodedPackage.getInt();
    final int maximumRegionSize = encodedPackage.getInt();
    final int minimumRegionSize = encodedPackage.getInt();
    // Distribution group
    final byte[] groupBytes = new byte[groupLength];
    encodedPackage.get(groupBytes, 0, groupBytes.length);
    final String distributionGroup = new String(groupBytes);
    // Placement strategy
    final byte[] placementBytes = new byte[placementLength];
    encodedPackage.get(placementBytes, 0, placementBytes.length);
    final String placemeneStrategy = new String(placementBytes);
    // Placement config length
    final byte[] placementConfigBytes = new byte[placementConfigLength];
    encodedPackage.get(placementConfigBytes, 0, placementConfigBytes.length);
    final String placementConfig = new String(placementConfigBytes);
    // Space partitioner
    final byte[] spacePartitionerBytes = new byte[spacePartitionerLength];
    encodedPackage.get(spacePartitionerBytes, 0, spacePartitionerBytes.length);
    final String spacePartitioner = new String(spacePartitionerBytes);
    // Space partitioner configuration
    final byte[] spacePartitionerConfigBytes = new byte[spacePartitionerConfigLength];
    encodedPackage.get(spacePartitionerConfigBytes, 0, spacePartitionerConfigBytes.length);
    final String spacePartitionerConfig = new String(spacePartitionerConfigBytes);
    if (encodedPackage.remaining() != 0) {
        throw new PackageEncodeException("Some bytes are left after decoding: " + encodedPackage.remaining());
    }
    final DistributionGroupConfiguration configuration = DistributionGroupConfigurationBuilder.create(dimensions).withPlacementStrategy(placemeneStrategy, placementConfig).withSpacePartitioner(spacePartitioner, spacePartitionerConfig).withMaximumRegionSize(maximumRegionSize).withMinimumRegionSize(minimumRegionSize).withReplicationFactor(replicationFactor).build();
    return new CreateDistributionGroupRequest(sequenceNumber, distributionGroup, configuration);
}
Also used : PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration)

Aggregations

PackageEncodeException (org.bboxdb.network.packages.PackageEncodeException)68 IOException (java.io.IOException)31 ByteBuffer (java.nio.ByteBuffer)21 ErrorResponse (org.bboxdb.network.packages.response.ErrorResponse)16 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)14 RoutingHeader (org.bboxdb.network.routing.RoutingHeader)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 ArrayList (java.util.ArrayList)9 BoundingBox (org.bboxdb.commons.math.BoundingBox)9 List (java.util.List)8 SuccessResponse (org.bboxdb.network.packages.response.SuccessResponse)6 Tuple (org.bboxdb.storage.entity.Tuple)6 StreamClientQuery (org.bboxdb.network.server.StreamClientQuery)5 OperatorTreeBuilder (org.bboxdb.storage.queryprocessor.OperatorTreeBuilder)5 NetworkRequestPackage (org.bboxdb.network.packages.NetworkRequestPackage)4 Operator (org.bboxdb.storage.queryprocessor.operator.Operator)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ExceptionSafeRunnable (org.bboxdb.commons.concurrent.ExceptionSafeRunnable)3 CompressionEnvelopeRequest (org.bboxdb.network.packages.request.CompressionEnvelopeRequest)3 ClientQuery (org.bboxdb.network.server.ClientQuery)3