Search in sources :

Example 26 with SerialisationException

use of uk.gov.gchq.gaffer.exception.SerialisationException in project Gaffer by gchq.

the class DoublesUnionSerialiserTest method testSerialiser.

private void testSerialiser(final DoublesUnion union) {
    final double quantile1 = union.getResult().getQuantile(0.5D);
    final byte[] unionSerialised;
    try {
        unionSerialised = SERIALISER.serialise(union);
    } catch (final SerialisationException exception) {
        fail("A SerialisationException occurred");
        return;
    }
    final DoublesUnion unionDeserialised;
    try {
        unionDeserialised = SERIALISER.deserialise(unionSerialised);
    } catch (final SerialisationException exception) {
        fail("A SerialisationException occurred");
        return;
    }
    assertEquals(quantile1, unionDeserialised.getResult().getQuantile(0.5D), DELTA);
}
Also used : DoublesUnion(com.yahoo.sketches.quantiles.DoublesUnion) SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException)

Example 27 with SerialisationException

use of uk.gov.gchq.gaffer.exception.SerialisationException in project Gaffer by gchq.

the class ProxyStore method handleResponse.

protected <OUTPUT> OUTPUT handleResponse(final Response response, final TypeReference<OUTPUT> outputTypeReference) throws StoreException {
    final String outputJson = response.hasEntity() ? response.readEntity(String.class) : null;
    if (200 != response.getStatus() && 204 != response.getStatus()) {
        LOGGER.warn("Gaffer bad status " + response.getStatus());
        LOGGER.warn("Detail: " + outputJson);
        throw new StoreException("Delegate Gaffer store returned status: " + response.getStatus() + ". Response content was: " + outputJson);
    }
    OUTPUT output = null;
    if (null != outputJson) {
        try {
            output = deserialise(outputJson, outputTypeReference);
        } catch (final SerialisationException e) {
            throw new StoreException(e.getMessage(), e);
        }
    }
    return output;
}
Also used : SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) StoreException(uk.gov.gchq.gaffer.store.StoreException)

Example 28 with SerialisationException

use of uk.gov.gchq.gaffer.exception.SerialisationException in project Gaffer by gchq.

the class AbstractCoreKeyAccumuloElementConverter method getPropertiesFromColumnVisibility.

@Override
public Properties getPropertiesFromColumnVisibility(final String group, final byte[] columnVisibility) throws AccumuloElementConversionException {
    final Properties properties = new Properties();
    final SchemaElementDefinition elementDefinition = schema.getElement(group);
    if (null == elementDefinition) {
        throw new AccumuloElementConversionException("No SchemaElementDefinition found for group " + group + ", is this group in your schema or do your table iterators need updating?");
    }
    if (null != schema.getVisibilityProperty()) {
        final TypeDefinition propertyDef = elementDefinition.getPropertyTypeDef(schema.getVisibilityProperty());
        if (null != propertyDef) {
            final Serialisation serialiser = propertyDef.getSerialiser();
            try {
                if (columnVisibility == null || columnVisibility.length == 0) {
                    final Object value = serialiser.deserialiseEmptyBytes();
                    if (value != null) {
                        properties.put(schema.getVisibilityProperty(), value);
                    }
                } else {
                    properties.put(schema.getVisibilityProperty(), serialiser.deserialise(columnVisibility));
                }
            } catch (final SerialisationException e) {
                throw new AccumuloElementConversionException(e.getMessage(), e);
            }
        }
    }
    return properties;
}
Also used : SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) Serialisation(uk.gov.gchq.gaffer.serialisation.Serialisation) Properties(uk.gov.gchq.gaffer.data.element.Properties) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition) AccumuloElementConversionException(uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition)

Example 29 with SerialisationException

use of uk.gov.gchq.gaffer.exception.SerialisationException in project Gaffer by gchq.

the class ByteEntityRangeFactory method getRange.

@Override
protected <T extends GetElementsOperation<?, ?>> List<Range> getRange(final Object vertex, final T operation, final IncludeEdgeType includeEdgesParam) throws RangeFactoryException {
    final IncludeIncomingOutgoingType inOutType = operation.getIncludeIncomingOutGoing();
    final IncludeEdgeType includeEdges;
    final boolean includeEntities;
    if (SeedMatchingType.EQUAL.equals(operation.getSeedMatching())) {
        includeEdges = IncludeEdgeType.NONE;
        includeEntities = true;
    } else {
        includeEdges = includeEdgesParam;
        includeEntities = operation.isIncludeEntities();
    }
    byte[] serialisedVertex;
    try {
        serialisedVertex = ByteArrayEscapeUtils.escape(schema.getVertexSerialiser().serialise(vertex));
    } catch (final SerialisationException e) {
        throw new RangeFactoryException("Failed to serialise identifier", e);
    }
    if (!includeEntities && includeEdges == IncludeEdgeType.NONE) {
        throw new IllegalArgumentException("Need to include either Entities or Edges or both when getting Range");
    }
    if (includeEdges == IncludeEdgeType.NONE) {
        // return only entities
        return Collections.singletonList(new Range(getEntityKey(serialisedVertex, false), true, getEntityKey(serialisedVertex, true), true));
    } else {
        if (includeEntities) {
            if (includeEdges == IncludeEdgeType.DIRECTED) {
                // return onlyDirectedEdges and entities
                if (inOutType == IncludeIncomingOutgoingType.INCOMING) {
                    return Arrays.asList(new Range(getEntityKey(serialisedVertex, false), true, getEntityKey(serialisedVertex, true), true), new Range(getDirectedEdgeKeyDestinationFirst(serialisedVertex, false), true, getDirectedEdgeKeyDestinationFirst(serialisedVertex, true), true));
                } else if (inOutType == IncludeIncomingOutgoingType.OUTGOING) {
                    return Collections.singletonList(new Range(getEntityKey(serialisedVertex, false), true, getDirectedEdgeKeySourceFirst(serialisedVertex, true), true));
                } else {
                    return Collections.singletonList(new Range(getEntityKey(serialisedVertex, false), false, getDirectedEdgeKeyDestinationFirst(serialisedVertex, true), false));
                }
            } else if (includeEdges == IncludeEdgeType.UNDIRECTED) {
                // Entity only range and undirected only range
                return Arrays.asList(new Range(getUnDirectedEdgeKey(serialisedVertex, false), true, getUnDirectedEdgeKey(serialisedVertex, true), true), new Range(getEntityKey(serialisedVertex, false), true, getEntityKey(serialisedVertex, true), true));
            } else {
                // Return everything
                if (inOutType == IncludeIncomingOutgoingType.INCOMING) {
                    return Arrays.asList(new Range(getEntityKey(serialisedVertex, false), true, getEntityKey(serialisedVertex, true), true), new Range(getDirectedEdgeKeyDestinationFirst(serialisedVertex, false), true, getUnDirectedEdgeKey(serialisedVertex, true), true));
                } else if (inOutType == IncludeIncomingOutgoingType.OUTGOING) {
                    return Arrays.asList(new Range(getEntityKey(serialisedVertex, false), true, getDirectedEdgeKeySourceFirst(serialisedVertex, true), true), new Range(getUnDirectedEdgeKey(serialisedVertex, false), true, getUnDirectedEdgeKey(serialisedVertex, true), true));
                } else {
                    return Collections.singletonList(new Range(getEntityKey(serialisedVertex, false), true, getUnDirectedEdgeKey(serialisedVertex, true), true));
                }
            }
        } else if (includeEdges == IncludeEdgeType.DIRECTED) {
            if (inOutType == IncludeIncomingOutgoingType.INCOMING) {
                return Collections.singletonList(new Range(getDirectedEdgeKeyDestinationFirst(serialisedVertex, false), true, getDirectedEdgeKeyDestinationFirst(serialisedVertex, true), true));
            } else if (inOutType == IncludeIncomingOutgoingType.OUTGOING) {
                return Collections.singletonList(new Range(getDirectedEdgeKeySourceFirst(serialisedVertex, false), true, getDirectedEdgeKeySourceFirst(serialisedVertex, true), true));
            } else {
                return Collections.singletonList(new Range(getDirectedEdgeKeySourceFirst(serialisedVertex, false), true, getDirectedEdgeKeyDestinationFirst(serialisedVertex, true), true));
            }
        } else if (includeEdges == IncludeEdgeType.UNDIRECTED) {
            return Collections.singletonList(new Range(getUnDirectedEdgeKey(serialisedVertex, false), true, getUnDirectedEdgeKey(serialisedVertex, true), true));
        } else {
            // return all edges
            if (inOutType == IncludeIncomingOutgoingType.INCOMING) {
                return Collections.singletonList(new Range(getDirectedEdgeKeyDestinationFirst(serialisedVertex, false), true, getUnDirectedEdgeKey(serialisedVertex, true), true));
            } else if (inOutType == IncludeIncomingOutgoingType.OUTGOING) {
                return Arrays.asList(new Range(getDirectedEdgeKeySourceFirst(serialisedVertex, false), true, getDirectedEdgeKeySourceFirst(serialisedVertex, true), true), new Range(getUnDirectedEdgeKey(serialisedVertex, false), true, getUnDirectedEdgeKey(serialisedVertex, true), true));
            } else {
                final Pair<Key> keys = getAllEdgeOnlyKeys(serialisedVertex);
                return Collections.singletonList(new Range(keys.getFirst(), false, keys.getSecond(), false));
            }
        }
    }
}
Also used : IncludeEdgeType(uk.gov.gchq.gaffer.operation.GetOperation.IncludeEdgeType) SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) IncludeIncomingOutgoingType(uk.gov.gchq.gaffer.operation.GetOperation.IncludeIncomingOutgoingType) Range(org.apache.accumulo.core.data.Range) RangeFactoryException(uk.gov.gchq.gaffer.accumulostore.key.exception.RangeFactoryException) Pair(uk.gov.gchq.gaffer.accumulostore.utils.Pair)

Example 30 with SerialisationException

use of uk.gov.gchq.gaffer.exception.SerialisationException in project Gaffer by gchq.

the class ClassicRangeFactory method getKeyFromEdgeSeed.

@Override
protected <T extends GetElementsOperation<?, ?>> Key getKeyFromEdgeSeed(final EdgeSeed seed, final T operation, final boolean endKey) throws RangeFactoryException {
    final byte directionFlag1 = seed.isDirected() ? (operation.getIncludeIncomingOutGoing() == IncludeIncomingOutgoingType.INCOMING ? ClassicBytePositions.INCORRECT_WAY_DIRECTED_EDGE : ClassicBytePositions.CORRECT_WAY_DIRECTED_EDGE) : ClassicBytePositions.UNDIRECTED_EDGE;
    final Serialisation vertexSerialiser = schema.getVertexSerialiser();
    // Serialise source and destination to byte arrays, escaping if
    // necessary
    byte[] source;
    try {
        source = ByteArrayEscapeUtils.escape(vertexSerialiser.serialise(seed.getSource()));
    } catch (final SerialisationException e) {
        throw new RangeFactoryException("Failed to serialise Edge Source", e);
    }
    byte[] destination;
    try {
        destination = ByteArrayEscapeUtils.escape(vertexSerialiser.serialise(seed.getDestination()));
    } catch (final SerialisationException e) {
        throw new RangeFactoryException("Failed to serialise Edge Destination", e);
    }
    // Length of row key is the length of the source
    // plus the length of the destination
    // plus one for the delimiter in between the source and destination
    // plus one for the delimiter in between the destination and the direction flag
    // plus one for the direction flag at the end.
    byte[] key;
    if (endKey) {
        key = new byte[source.length + destination.length + 4];
        key[key.length - 3] = ByteArrayEscapeUtils.DELIMITER;
        key[key.length - 2] = directionFlag1;
        key[key.length - 1] = ByteArrayEscapeUtils.DELIMITER_PLUS_ONE;
    } else {
        key = new byte[source.length + destination.length + 3];
        key[key.length - 2] = ByteArrayEscapeUtils.DELIMITER;
        key[key.length - 1] = directionFlag1;
    }
    // Create first key: source DELIMITER destination DELIMITER (CORRECT_WAY_DIRECTED_EDGE or UNDIRECTED_EDGE)
    // Here if we desire an EdgeID we and the user has asked for incoming
    // edges only for related items, we put the destination first so we find the flipped edge's key,
    // this key will pass the filter iterators check for incoming edges, but
    // the result will be flipped back to the correct edge on the client end conversion
    // Simply put when looking up an EDGE ID that ID counts as both incoming
    // and outgoing so we use the reversed key when looking up incoming.
    byte[] firstValue;
    byte[] secondValue;
    if (operation.getIncludeIncomingOutGoing() == IncludeIncomingOutgoingType.INCOMING) {
        firstValue = destination;
        secondValue = source;
    } else {
        firstValue = source;
        secondValue = destination;
    }
    System.arraycopy(firstValue, 0, key, 0, firstValue.length);
    key[firstValue.length] = ByteArrayEscapeUtils.DELIMITER;
    System.arraycopy(secondValue, 0, key, firstValue.length + 1, secondValue.length);
    return new Key(key, AccumuloStoreConstants.EMPTY_BYTES, AccumuloStoreConstants.EMPTY_BYTES, AccumuloStoreConstants.EMPTY_BYTES, Long.MAX_VALUE);
}
Also used : SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) Serialisation(uk.gov.gchq.gaffer.serialisation.Serialisation) Key(org.apache.accumulo.core.data.Key) RangeFactoryException(uk.gov.gchq.gaffer.accumulostore.key.exception.RangeFactoryException)

Aggregations

SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)39 IOException (java.io.IOException)12 UnsupportedEncodingException (java.io.UnsupportedEncodingException)9 AccumuloElementConversionException (uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 RangeFactoryException (uk.gov.gchq.gaffer.accumulostore.key.exception.RangeFactoryException)4 SchemaElementDefinition (uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Properties (uk.gov.gchq.gaffer.data.element.Properties)3 Serialisation (uk.gov.gchq.gaffer.serialisation.Serialisation)3 StoreException (uk.gov.gchq.gaffer.store.StoreException)3 TypeDefinition (uk.gov.gchq.gaffer.store.schema.TypeDefinition)3 HyperLogLogPlus (com.clearspring.analytics.stream.cardinality.HyperLogLogPlus)2 DataInputStream (java.io.DataInputStream)2 DataOutputStream (java.io.DataOutputStream)2 Entry (java.util.Map.Entry)2 Key (org.apache.accumulo.core.data.Key)2 Test (org.junit.Test)2 RoaringBitmap (org.roaringbitmap.RoaringBitmap)2 Entity (uk.gov.gchq.gaffer.data.element.Entity)2