use of org.apache.hadoop.hdfs.protocol.EncryptionZone in project hadoop by apache.
the class TestEncryptionZones method testGetEncryptionZoneOnANonExistentPaths.
@Test
public void testGetEncryptionZoneOnANonExistentPaths() throws Exception {
final Path ezPath = new Path("/ez");
fs.mkdirs(ezPath);
dfsAdmin.createEncryptionZone(ezPath, TEST_KEY, NO_TRASH);
Path zoneFile = new Path(ezPath, "file");
EncryptionZone ez = fs.getEZForPath(zoneFile);
assertNotNull("Expected EZ for non-existent path in EZ", ez);
ez = dfsAdmin.getEncryptionZoneForPath(zoneFile);
assertNotNull("Expected EZ for non-existent path in EZ", ez);
ez = dfsAdmin.getEncryptionZoneForPath(new Path("/does/not/exist"));
assertNull("Expected null for non-existent path not in EZ", ez);
}
use of org.apache.hadoop.hdfs.protocol.EncryptionZone in project hadoop by apache.
the class DistributedFileSystem method getEZForPath.
/* HDFS only */
public EncryptionZone getEZForPath(final Path path) throws IOException {
Preconditions.checkNotNull(path);
Path absF = fixRelativePart(path);
return new FileSystemLinkResolver<EncryptionZone>() {
@Override
public EncryptionZone doCall(final Path p) throws IOException {
return dfs.getEZForPath(getPathName(p));
}
@Override
public EncryptionZone next(final FileSystem fs, final Path p) throws IOException {
if (fs instanceof DistributedFileSystem) {
DistributedFileSystem myDfs = (DistributedFileSystem) fs;
return myDfs.getEZForPath(p);
} else {
throw new UnsupportedOperationException("Cannot call getEZForPath" + " on a symlink to a non-DistributedFileSystem: " + path + " -> " + p);
}
}
}.resolve(this, absF);
}
use of org.apache.hadoop.hdfs.protocol.EncryptionZone in project hadoop by apache.
the class ClientNamenodeProtocolTranslatorPB method listEncryptionZones.
@Override
public BatchedEntries<EncryptionZone> listEncryptionZones(long id) throws IOException {
final ListEncryptionZonesRequestProto req = ListEncryptionZonesRequestProto.newBuilder().setId(id).build();
try {
EncryptionZonesProtos.ListEncryptionZonesResponseProto response = rpcProxy.listEncryptionZones(null, req);
List<EncryptionZone> elements = Lists.newArrayListWithCapacity(response.getZonesCount());
for (EncryptionZoneProto p : response.getZonesList()) {
elements.add(PBHelperClient.convert(p));
}
return new BatchedListEntries<>(elements, response.getHasMore());
} catch (ServiceException e) {
throw ProtobufHelper.getRemoteException(e);
}
}
use of org.apache.hadoop.hdfs.protocol.EncryptionZone in project hadoop by apache.
the class HdfsAdmin method provisionEZTrash.
private void provisionEZTrash(Path path) throws IOException {
// make sure the path is an EZ
EncryptionZone ez = dfs.getEZForPath(path);
if (ez == null) {
throw new IllegalArgumentException(path + " is not an encryption zone.");
}
String ezPath = ez.getPath();
if (!path.toString().equals(ezPath)) {
throw new IllegalArgumentException(path + " is not the root of an " + "encryption zone. Do you mean " + ez.getPath() + "?");
}
// check if the trash directory exists
Path trashPath = new Path(ez.getPath(), FileSystem.TRASH_PREFIX);
try {
FileStatus trashFileStatus = dfs.getFileStatus(trashPath);
String errMessage = "Will not provision new trash directory for " + "encryption zone " + ez.getPath() + ". Path already exists.";
if (!trashFileStatus.isDirectory()) {
errMessage += "\r\n" + "Warning: " + trashPath.toString() + " is not a directory";
}
if (!trashFileStatus.getPermission().equals(TRASH_PERMISSION)) {
errMessage += "\r\n" + "Warning: the permission of " + trashPath.toString() + " is not " + TRASH_PERMISSION;
}
throw new FileAlreadyExistsException(errMessage);
} catch (FileNotFoundException ignored) {
// no trash path
}
// Update the permission bits
dfs.mkdir(trashPath, TRASH_PERMISSION);
dfs.setPermission(trashPath, TRASH_PERMISSION);
}
use of org.apache.hadoop.hdfs.protocol.EncryptionZone in project hadoop by apache.
the class EncryptionZoneManager method listEncryptionZones.
/**
* Cursor-based listing of encryption zones.
* <p/>
* Called while holding the FSDirectory lock.
*/
BatchedListEntries<EncryptionZone> listEncryptionZones(long prevId) throws IOException {
assert dir.hasReadLock();
if (!hasCreatedEncryptionZone()) {
return new BatchedListEntries<EncryptionZone>(Lists.newArrayList(), false);
}
NavigableMap<Long, EncryptionZoneInt> tailMap = encryptionZones.tailMap(prevId, false);
final int numResponses = Math.min(maxListEncryptionZonesResponses, tailMap.size());
final List<EncryptionZone> zones = Lists.newArrayListWithExpectedSize(numResponses);
int count = 0;
for (EncryptionZoneInt ezi : tailMap.values()) {
/*
Skip EZs that are only present in snapshots. Re-resolve the path to
see if the path's current inode ID matches EZ map's INode ID.
INode#getFullPathName simply calls getParent recursively, so will return
the INode's parents at the time it was snapshotted. It will not
contain a reference INode.
*/
final String pathName = getFullPathName(ezi);
INode inode = dir.getInode(ezi.getINodeId());
INode lastINode = null;
if (inode.getParent() != null || inode.isRoot()) {
INodesInPath iip = dir.getINodesInPath(pathName, DirOp.READ_LINK);
lastINode = iip.getLastINode();
}
if (lastINode == null || lastINode.getId() != ezi.getINodeId()) {
continue;
}
// Add the EZ to the result list
zones.add(new EncryptionZone(ezi.getINodeId(), pathName, ezi.getSuite(), ezi.getVersion(), ezi.getKeyName()));
count++;
if (count >= numResponses) {
break;
}
}
final boolean hasMore = (numResponses < tailMap.size());
return new BatchedListEntries<EncryptionZone>(zones, hasMore);
}
Aggregations