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;
}
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;
}
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;
}
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;
}
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());
}
Aggregations