Search in sources :

Example 16 with XAttr

use of org.apache.hadoop.fs.XAttr in project hadoop by apache.

the class TestFSDirectory method testINodeXAttrsLimit.

@Test
public void testINodeXAttrsLimit() throws Exception {
    List<XAttr> existingXAttrs = Lists.newArrayListWithCapacity(2);
    XAttr xAttr1 = (new XAttr.Builder()).setNameSpace(XAttr.NameSpace.USER).setName("a1").setValue(new byte[] { 0x31, 0x32, 0x33 }).build();
    XAttr xAttr2 = (new XAttr.Builder()).setNameSpace(XAttr.NameSpace.USER).setName("a2").setValue(new byte[] { 0x31, 0x31, 0x31 }).build();
    existingXAttrs.add(xAttr1);
    existingXAttrs.add(xAttr2);
    // Adding system and raw namespace xAttrs aren't affected by inode
    // xAttrs limit.
    XAttr newSystemXAttr = (new XAttr.Builder()).setNameSpace(XAttr.NameSpace.SYSTEM).setName("a3").setValue(new byte[] { 0x33, 0x33, 0x33 }).build();
    XAttr newRawXAttr = (new XAttr.Builder()).setNameSpace(XAttr.NameSpace.RAW).setName("a3").setValue(new byte[] { 0x33, 0x33, 0x33 }).build();
    List<XAttr> newXAttrs = Lists.newArrayListWithCapacity(2);
    newXAttrs.add(newSystemXAttr);
    newXAttrs.add(newRawXAttr);
    List<XAttr> xAttrs = FSDirXAttrOp.setINodeXAttrs(fsdir, existingXAttrs, newXAttrs, EnumSet.of(XAttrSetFlag.CREATE, XAttrSetFlag.REPLACE));
    assertEquals(xAttrs.size(), 4);
    // Adding a trusted namespace xAttr, is affected by inode xAttrs limit.
    XAttr newXAttr1 = (new XAttr.Builder()).setNameSpace(XAttr.NameSpace.TRUSTED).setName("a4").setValue(new byte[] { 0x34, 0x34, 0x34 }).build();
    newXAttrs.set(0, newXAttr1);
    try {
        FSDirXAttrOp.setINodeXAttrs(fsdir, existingXAttrs, newXAttrs, EnumSet.of(XAttrSetFlag.CREATE, XAttrSetFlag.REPLACE));
        fail("Setting user visible xattr on inode should fail if " + "reaching limit.");
    } catch (IOException e) {
        GenericTestUtils.assertExceptionContains("Cannot add additional XAttr " + "to inode, would exceed limit", e);
    }
}
Also used : IOException(java.io.IOException) XAttr(org.apache.hadoop.fs.XAttr) Test(org.junit.Test)

Example 17 with XAttr

use of org.apache.hadoop.fs.XAttr in project hadoop by apache.

the class XAttrHelper method buildXAttr.

/**
   * Build <code>XAttr</code> from name with prefix and value.
   * Name can not be null. Value can be null. The name and prefix
   * are validated.
   * Both name and namespace are case sensitive.
   */
public static XAttr buildXAttr(String name, byte[] value) {
    Preconditions.checkNotNull(name, "XAttr name cannot be null.");
    final int prefixIndex = name.indexOf(".");
    if (prefixIndex < 3) {
        // Prefix length is at least 3.
        throw new HadoopIllegalArgumentException("An XAttr name must be " + "prefixed with user/trusted/security/system/raw, followed by a '.'");
    } else if (prefixIndex == name.length() - 1) {
        throw new HadoopIllegalArgumentException("XAttr name cannot be empty.");
    }
    NameSpace ns;
    final String prefix = name.substring(0, prefixIndex);
    if (StringUtils.equalsIgnoreCase(prefix, NameSpace.USER.toString())) {
        ns = NameSpace.USER;
    } else if (StringUtils.equalsIgnoreCase(prefix, NameSpace.TRUSTED.toString())) {
        ns = NameSpace.TRUSTED;
    } else if (StringUtils.equalsIgnoreCase(prefix, NameSpace.SYSTEM.toString())) {
        ns = NameSpace.SYSTEM;
    } else if (StringUtils.equalsIgnoreCase(prefix, NameSpace.SECURITY.toString())) {
        ns = NameSpace.SECURITY;
    } else if (StringUtils.equalsIgnoreCase(prefix, NameSpace.RAW.toString())) {
        ns = NameSpace.RAW;
    } else {
        throw new HadoopIllegalArgumentException("An XAttr name must be " + "prefixed with user/trusted/security/system/raw, followed by a '.'");
    }
    return (new XAttr.Builder()).setNameSpace(ns).setName(name.substring(prefixIndex + 1)).setValue(value).build();
}
Also used : HadoopIllegalArgumentException(org.apache.hadoop.HadoopIllegalArgumentException) NameSpace(org.apache.hadoop.fs.XAttr.NameSpace) XAttr(org.apache.hadoop.fs.XAttr)

Example 18 with XAttr

use of org.apache.hadoop.fs.XAttr in project hadoop by apache.

the class XAttrHelper method buildXAttrAsList.

/**
   * Build xattr name with prefix as <code>XAttr</code> list.
   */
public static List<XAttr> buildXAttrAsList(String name) {
    XAttr xAttr = buildXAttr(name);
    List<XAttr> xAttrs = Lists.newArrayListWithCapacity(1);
    xAttrs.add(xAttr);
    return xAttrs;
}
Also used : XAttr(org.apache.hadoop.fs.XAttr)

Example 19 with XAttr

use of org.apache.hadoop.fs.XAttr in project SSM by Intel-bigdata.

the class EventBatchSerializer method convertXAttrs.

public static List<XAttr> convertXAttrs(List<XAttrProto> xAttrSpec) {
    ArrayList<XAttr> xAttrs = Lists.newArrayListWithCapacity(xAttrSpec.size());
    for (XAttrProto a : xAttrSpec) {
        XAttr.Builder builder = new XAttr.Builder();
        builder.setNameSpace(convert(a.getNamespace()));
        if (a.hasName()) {
            builder.setName(a.getName());
        }
        if (a.hasValue()) {
            builder.setValue(a.getValue().toByteArray());
        }
        xAttrs.add(builder.build());
    }
    return xAttrs;
}
Also used : XAttrProto(org.apache.hadoop.hdfs.protocol.proto.XAttrProtos.XAttrProto) XAttr(org.apache.hadoop.fs.XAttr)

Example 20 with XAttr

use of org.apache.hadoop.fs.XAttr in project SSM by Intel-bigdata.

the class EventBatchSerializer method convertXAttrProto.

public static List<XAttrProto> convertXAttrProto(List<XAttr> xAttrSpec) {
    if (xAttrSpec == null) {
        return Lists.newArrayListWithCapacity(0);
    }
    ArrayList<XAttrProto> xAttrs = Lists.newArrayListWithCapacity(xAttrSpec.size());
    for (XAttr a : xAttrSpec) {
        XAttrProto.Builder builder = XAttrProto.newBuilder();
        builder.setNamespace(convert(a.getNameSpace()));
        if (a.getName() != null) {
            builder.setName(a.getName());
        }
        if (a.getValue() != null) {
            builder.setValue(getByteString(a.getValue()));
        }
        xAttrs.add(builder.build());
    }
    return xAttrs;
}
Also used : XAttrProto(org.apache.hadoop.hdfs.protocol.proto.XAttrProtos.XAttrProto) XAttr(org.apache.hadoop.fs.XAttr)

Aggregations

XAttr (org.apache.hadoop.fs.XAttr)43 IOException (java.io.IOException)13 Test (org.junit.Test)7 HdfsProtos (org.apache.hadoop.hdfs.protocol.proto.HdfsProtos)5 FileNotFoundException (java.io.FileNotFoundException)4 XAttrProto (org.apache.hadoop.hdfs.protocol.proto.XAttrProtos.XAttrProto)4 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ArrayList (java.util.ArrayList)2 HadoopIllegalArgumentException (org.apache.hadoop.HadoopIllegalArgumentException)2 CipherSuite (org.apache.hadoop.crypto.CipherSuite)2 CryptoProtocolVersion (org.apache.hadoop.crypto.CryptoProtocolVersion)2 AccessControlException (org.apache.hadoop.security.AccessControlException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableList (com.google.common.collect.ImmutableList)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1