Search in sources :

Example 61 with DeserializationException

use of org.apache.hadoop.hbase.exceptions.DeserializationException in project hbase by apache.

the class PermissionStorage method readUserPermission.

public static ListMultimap<String, UserPermission> readUserPermission(byte[] data, Configuration conf) throws DeserializationException {
    if (ProtobufUtil.isPBMagicPrefix(data)) {
        int pblen = ProtobufUtil.lengthOfPBMagic();
        try {
            AccessControlProtos.UsersAndPermissions.Builder builder = AccessControlProtos.UsersAndPermissions.newBuilder();
            ProtobufUtil.mergeFrom(builder, data, pblen, data.length - pblen);
            return AccessControlUtil.toUserPermission(builder.build());
        } catch (IOException e) {
            throw new DeserializationException(e);
        }
    } else {
        // TODO: We have to re-write non-PB data as PB encoded. Otherwise we will carry old Writables
        // forever (here and a couple of other places).
        ListMultimap<String, UserPermission> userPermission = ArrayListMultimap.create();
        try {
            DataInput in = new DataInputStream(new ByteArrayInputStream(data));
            int length = in.readInt();
            for (int i = 0; i < length; i++) {
                String user = Text.readString(in);
                List<Permission> perms = readWritableUserPermission(in, conf);
                for (Permission p : perms) {
                    userPermission.put(user, new UserPermission(user, p));
                }
            }
        } catch (IOException | ClassNotFoundException e) {
            throw new DeserializationException(e);
        }
        return userPermission;
    }
}
Also used : IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException) DataInput(java.io.DataInput) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 62 with DeserializationException

use of org.apache.hadoop.hbase.exceptions.DeserializationException in project hbase by apache.

the class PermissionStorage method readPermissions.

public static ListMultimap<String, Permission> readPermissions(byte[] data, Configuration conf) throws DeserializationException {
    if (ProtobufUtil.isPBMagicPrefix(data)) {
        int pblen = ProtobufUtil.lengthOfPBMagic();
        try {
            AccessControlProtos.UsersAndPermissions.Builder builder = AccessControlProtos.UsersAndPermissions.newBuilder();
            ProtobufUtil.mergeFrom(builder, data, pblen, data.length - pblen);
            return AccessControlUtil.toPermission(builder.build());
        } catch (IOException e) {
            throw new DeserializationException(e);
        }
    } else {
        // TODO: We have to re-write non-PB data as PB encoded. Otherwise we will carry old Writables
        // forever (here and a couple of other places).
        ListMultimap<String, Permission> perms = ArrayListMultimap.create();
        try {
            DataInput in = new DataInputStream(new ByteArrayInputStream(data));
            int length = in.readInt();
            for (int i = 0; i < length; i++) {
                String user = Text.readString(in);
                perms.putAll(user, readWritableUserPermission(in, conf));
            }
        } catch (IOException | ClassNotFoundException e) {
            throw new DeserializationException(e);
        }
        return perms;
    }
}
Also used : IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException) DataInput(java.io.DataInput) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 63 with DeserializationException

use of org.apache.hadoop.hbase.exceptions.DeserializationException in project hbase by apache.

the class RegexStringComparator method parseFrom.

/**
 * @param pbBytes A pb serialized {@link RegexStringComparator} instance
 * @return An instance of {@link RegexStringComparator} made from <code>bytes</code>
 * @throws DeserializationException
 * @see #toByteArray
 */
public static RegexStringComparator parseFrom(final byte[] pbBytes) throws DeserializationException {
    ComparatorProtos.RegexStringComparator proto;
    try {
        proto = ComparatorProtos.RegexStringComparator.parseFrom(pbBytes);
    } catch (InvalidProtocolBufferException e) {
        throw new DeserializationException(e);
    }
    RegexStringComparator comparator;
    if (proto.hasEngine()) {
        EngineType engine = EngineType.valueOf(proto.getEngine());
        comparator = new RegexStringComparator(proto.getPattern(), proto.getPatternFlags(), engine);
    } else {
        comparator = new RegexStringComparator(proto.getPattern(), proto.getPatternFlags());
    }
    String charset = proto.getCharset();
    if (charset.length() > 0) {
        try {
            comparator.getEngine().setCharset(charset);
        } catch (IllegalCharsetNameException e) {
            LOG.error("invalid charset", e);
        }
    }
    return comparator;
}
Also used : IllegalCharsetNameException(java.nio.charset.IllegalCharsetNameException) ComparatorProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.ComparatorProtos) InvalidProtocolBufferException(org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException)

Example 64 with DeserializationException

use of org.apache.hadoop.hbase.exceptions.DeserializationException in project hbase by apache.

the class RowFilter method parseFrom.

/**
 * @param pbBytes A pb serialized {@link RowFilter} instance
 * @return An instance of {@link RowFilter} made from <code>bytes</code>
 * @throws DeserializationException
 * @see #toByteArray
 */
public static RowFilter parseFrom(final byte[] pbBytes) throws DeserializationException {
    FilterProtos.RowFilter proto;
    try {
        proto = FilterProtos.RowFilter.parseFrom(pbBytes);
    } catch (InvalidProtocolBufferException e) {
        throw new DeserializationException(e);
    }
    final CompareOperator valueCompareOp = CompareOperator.valueOf(proto.getCompareFilter().getCompareOp().name());
    ByteArrayComparable valueComparator = null;
    try {
        if (proto.getCompareFilter().hasComparator()) {
            valueComparator = ProtobufUtil.toComparator(proto.getCompareFilter().getComparator());
        }
    } catch (IOException ioe) {
        throw new DeserializationException(ioe);
    }
    return new RowFilter(valueCompareOp, valueComparator);
}
Also used : CompareOperator(org.apache.hadoop.hbase.CompareOperator) InvalidProtocolBufferException(org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException) FilterProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.FilterProtos) IOException(java.io.IOException) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException)

Example 65 with DeserializationException

use of org.apache.hadoop.hbase.exceptions.DeserializationException in project hbase by apache.

the class SingleColumnValueExcludeFilter method parseFrom.

/**
 * @param pbBytes A pb serialized {@link SingleColumnValueExcludeFilter} instance
 * @return An instance of {@link SingleColumnValueExcludeFilter} made from <code>bytes</code>
 * @throws DeserializationException
 * @see #toByteArray
 */
public static SingleColumnValueExcludeFilter parseFrom(final byte[] pbBytes) throws DeserializationException {
    FilterProtos.SingleColumnValueExcludeFilter proto;
    try {
        proto = FilterProtos.SingleColumnValueExcludeFilter.parseFrom(pbBytes);
    } catch (InvalidProtocolBufferException e) {
        throw new DeserializationException(e);
    }
    FilterProtos.SingleColumnValueFilter parentProto = proto.getSingleColumnValueFilter();
    final CompareOperator compareOp = CompareOperator.valueOf(parentProto.getCompareOp().name());
    final ByteArrayComparable comparator;
    try {
        comparator = ProtobufUtil.toComparator(parentProto.getComparator());
    } catch (IOException ioe) {
        throw new DeserializationException(ioe);
    }
    return new SingleColumnValueExcludeFilter(parentProto.hasColumnFamily() ? parentProto.getColumnFamily().toByteArray() : null, parentProto.hasColumnQualifier() ? parentProto.getColumnQualifier().toByteArray() : null, compareOp, comparator, parentProto.getFilterIfMissing(), parentProto.getLatestVersionOnly());
}
Also used : CompareOperator(org.apache.hadoop.hbase.CompareOperator) InvalidProtocolBufferException(org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException) FilterProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.FilterProtos) IOException(java.io.IOException) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException)

Aggregations

DeserializationException (org.apache.hadoop.hbase.exceptions.DeserializationException)83 IOException (java.io.IOException)57 InvalidProtocolBufferException (org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException)15 FilterProtos (org.apache.hadoop.hbase.shaded.protobuf.generated.FilterProtos)13 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)12 KeeperException (org.apache.zookeeper.KeeperException)12 ArrayList (java.util.ArrayList)11 ServerName (org.apache.hadoop.hbase.ServerName)9 Cell (org.apache.hadoop.hbase.Cell)8 CompareOperator (org.apache.hadoop.hbase.CompareOperator)8 InterruptedIOException (java.io.InterruptedIOException)7 CellVisibility (org.apache.hadoop.hbase.security.visibility.CellVisibility)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 Tag (org.apache.hadoop.hbase.Tag)6 HBaseProtos (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos)6 Map (java.util.Map)5 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)5 TableName (org.apache.hadoop.hbase.TableName)5 FilterList (org.apache.hadoop.hbase.filter.FilterList)5 List (java.util.List)4