Search in sources :

Example 21 with XAttr

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

the class XAttrHelper method getFirstXAttrValue.

/**
   * Get value of first xattr from <code>XAttr</code> list
   */
public static byte[] getFirstXAttrValue(List<XAttr> xAttrs) {
    byte[] value = null;
    XAttr xAttr = getFirstXAttr(xAttrs);
    if (xAttr != null) {
        value = xAttr.getValue();
        if (value == null) {
            // xattr exists, but no value.
            value = new byte[0];
        }
    }
    return value;
}
Also used : XAttr(org.apache.hadoop.fs.XAttr)

Example 22 with XAttr

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

the class XAttrHelper method buildXAttrMap.

/**
   * Build xattr map from <code>XAttr</code> list, the key is
   * xattr name with prefix, and value is xattr value.
   */
public static Map<String, byte[]> buildXAttrMap(List<XAttr> xAttrs) {
    if (xAttrs == null) {
        return null;
    }
    Map<String, byte[]> xAttrMap = Maps.newHashMap();
    for (XAttr xAttr : xAttrs) {
        String name = getPrefixedName(xAttr);
        byte[] value = xAttr.getValue();
        if (value == null) {
            value = new byte[0];
        }
        xAttrMap.put(name, value);
    }
    return xAttrMap;
}
Also used : XAttr(org.apache.hadoop.fs.XAttr)

Example 23 with XAttr

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

the class PBHelperClient 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)

Example 24 with XAttr

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

the class PBHelperClient 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) Builder(org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.LocatedBlockProto.Builder) DatanodeInfoBuilder(org.apache.hadoop.hdfs.protocol.DatanodeInfo.DatanodeInfoBuilder) XAttr(org.apache.hadoop.fs.XAttr)

Example 25 with XAttr

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

the class FSDirAttrOp method setDirStoragePolicy.

private static void setDirStoragePolicy(FSDirectory fsd, INodesInPath iip, byte policyId) throws IOException {
    INode inode = FSDirectory.resolveLastINode(iip);
    List<XAttr> existingXAttrs = XAttrStorage.readINodeXAttrs(inode);
    XAttr xAttr = BlockStoragePolicySuite.buildXAttr(policyId);
    List<XAttr> newXAttrs = null;
    if (policyId == HdfsConstants.BLOCK_STORAGE_POLICY_ID_UNSPECIFIED) {
        List<XAttr> toRemove = Lists.newArrayList();
        toRemove.add(xAttr);
        List<XAttr> removed = Lists.newArrayList();
        newXAttrs = FSDirXAttrOp.filterINodeXAttrs(existingXAttrs, toRemove, removed);
    } else {
        newXAttrs = FSDirXAttrOp.setINodeXAttrs(fsd, existingXAttrs, Arrays.asList(xAttr), EnumSet.of(XAttrSetFlag.CREATE, XAttrSetFlag.REPLACE));
    }
    XAttrStorage.updateINodeXAttrs(inode, newXAttrs, iip.getLatestSnapshotId());
}
Also used : 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