Search in sources :

Example 6 with EncryptionZone

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);
}
Also used : Path(org.apache.hadoop.fs.Path) EncryptionZone(org.apache.hadoop.hdfs.protocol.EncryptionZone) Test(org.junit.Test)

Example 7 with EncryptionZone

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);
}
Also used : Path(org.apache.hadoop.fs.Path) EncryptionZone(org.apache.hadoop.hdfs.protocol.EncryptionZone) FileSystem(org.apache.hadoop.fs.FileSystem) IOException(java.io.IOException)

Example 8 with EncryptionZone

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);
    }
}
Also used : EncryptionZone(org.apache.hadoop.hdfs.protocol.EncryptionZone) ServiceException(com.google.protobuf.ServiceException) ListEncryptionZonesRequestProto(org.apache.hadoop.hdfs.protocol.proto.EncryptionZonesProtos.ListEncryptionZonesRequestProto) BatchedListEntries(org.apache.hadoop.fs.BatchedRemoteIterator.BatchedListEntries) EncryptionZoneProto(org.apache.hadoop.hdfs.protocol.proto.EncryptionZonesProtos.EncryptionZoneProto)

Example 9 with EncryptionZone

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);
}
Also used : Path(org.apache.hadoop.fs.Path) EncryptionZone(org.apache.hadoop.hdfs.protocol.EncryptionZone) FileAlreadyExistsException(org.apache.hadoop.fs.FileAlreadyExistsException) FileStatus(org.apache.hadoop.fs.FileStatus) FileNotFoundException(java.io.FileNotFoundException) HadoopIllegalArgumentException(org.apache.hadoop.HadoopIllegalArgumentException)

Example 10 with EncryptionZone

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);
}
Also used : EncryptionZone(org.apache.hadoop.hdfs.protocol.EncryptionZone) BatchedListEntries(org.apache.hadoop.fs.BatchedRemoteIterator.BatchedListEntries)

Aggregations

EncryptionZone (org.apache.hadoop.hdfs.protocol.EncryptionZone)15 IOException (java.io.IOException)5 Path (org.apache.hadoop.fs.Path)5 ServiceException (com.google.protobuf.ServiceException)3 HdfsFileStatus (org.apache.hadoop.hdfs.protocol.HdfsFileStatus)3 FileNotFoundException (java.io.FileNotFoundException)2 CipherSuite (org.apache.hadoop.crypto.CipherSuite)2 CryptoProtocolVersion (org.apache.hadoop.crypto.CryptoProtocolVersion)2 BatchedListEntries (org.apache.hadoop.fs.BatchedRemoteIterator.BatchedListEntries)2 FileStatus (org.apache.hadoop.fs.FileStatus)2 Test (org.junit.Test)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 ArrayList (java.util.ArrayList)1 HadoopIllegalArgumentException (org.apache.hadoop.HadoopIllegalArgumentException)1 FileAlreadyExistsException (org.apache.hadoop.fs.FileAlreadyExistsException)1 FileEncryptionInfo (org.apache.hadoop.fs.FileEncryptionInfo)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 LocatedFileStatus (org.apache.hadoop.fs.LocatedFileStatus)1 XAttr (org.apache.hadoop.fs.XAttr)1 HdfsLocatedFileStatus (org.apache.hadoop.hdfs.protocol.HdfsLocatedFileStatus)1