HDFS-9057. allow/disallow snapshots via webhdfs (Contributed by Brahma Reddy Battula)
(cherry picked from commit6d2332ae37
) (cherry picked from commit4b21b47f56
)
This commit is contained in:
parent
879caf688b
commit
7dc22dbe0c
|
@ -1227,6 +1227,12 @@ public class WebHdfsFileSystem extends FileSystem
|
||||||
new FsPathRunner(op, p, new AclPermissionParam(aclSpec)).run();
|
new FsPathRunner(op, p, new AclPermissionParam(aclSpec)).run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void allowSnapshot(final Path p) throws IOException {
|
||||||
|
statistics.incrementWriteOps(1);
|
||||||
|
final HttpOpParam.Op op = PutOpParam.Op.ALLOWSNAPSHOT;
|
||||||
|
new FsPathRunner(op, p).run();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Path createSnapshot(final Path path, final String snapshotName)
|
public Path createSnapshot(final Path path, final String snapshotName)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
@ -1242,6 +1248,12 @@ public class WebHdfsFileSystem extends FileSystem
|
||||||
}.run();
|
}.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void disallowSnapshot(final Path p) throws IOException {
|
||||||
|
statistics.incrementWriteOps(1);
|
||||||
|
final HttpOpParam.Op op = PutOpParam.Op.DISALLOWSNAPSHOT;
|
||||||
|
new FsPathRunner(op, p).run();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteSnapshot(final Path path, final String snapshotName)
|
public void deleteSnapshot(final Path path, final String snapshotName)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
|
|
@ -46,6 +46,8 @@ public class PutOpParam extends HttpOpParam<PutOpParam.Op> {
|
||||||
SETXATTR(false, HttpURLConnection.HTTP_OK),
|
SETXATTR(false, HttpURLConnection.HTTP_OK),
|
||||||
REMOVEXATTR(false, HttpURLConnection.HTTP_OK),
|
REMOVEXATTR(false, HttpURLConnection.HTTP_OK),
|
||||||
|
|
||||||
|
ALLOWSNAPSHOT(false, HttpURLConnection.HTTP_OK),
|
||||||
|
DISALLOWSNAPSHOT(false, HttpURLConnection.HTTP_OK),
|
||||||
CREATESNAPSHOT(false, HttpURLConnection.HTTP_OK),
|
CREATESNAPSHOT(false, HttpURLConnection.HTTP_OK),
|
||||||
RENAMESNAPSHOT(false, HttpURLConnection.HTTP_OK),
|
RENAMESNAPSHOT(false, HttpURLConnection.HTTP_OK),
|
||||||
|
|
||||||
|
|
|
@ -633,6 +633,10 @@ public class NamenodeWebHdfsMethods {
|
||||||
np.removeXAttr(fullpath, XAttrHelper.buildXAttr(xattrName.getXAttrName()));
|
np.removeXAttr(fullpath, XAttrHelper.buildXAttr(xattrName.getXAttrName()));
|
||||||
return Response.ok().type(MediaType.APPLICATION_OCTET_STREAM).build();
|
return Response.ok().type(MediaType.APPLICATION_OCTET_STREAM).build();
|
||||||
}
|
}
|
||||||
|
case ALLOWSNAPSHOT: {
|
||||||
|
np.allowSnapshot(fullpath);
|
||||||
|
return Response.ok().type(MediaType.APPLICATION_OCTET_STREAM).build();
|
||||||
|
}
|
||||||
case CREATESNAPSHOT: {
|
case CREATESNAPSHOT: {
|
||||||
String snapshotPath = np.createSnapshot(fullpath, snapshotName.getValue());
|
String snapshotPath = np.createSnapshot(fullpath, snapshotName.getValue());
|
||||||
final String js = JsonUtil.toJsonString(
|
final String js = JsonUtil.toJsonString(
|
||||||
|
@ -644,6 +648,10 @@ public class NamenodeWebHdfsMethods {
|
||||||
snapshotName.getValue());
|
snapshotName.getValue());
|
||||||
return Response.ok().type(MediaType.APPLICATION_OCTET_STREAM).build();
|
return Response.ok().type(MediaType.APPLICATION_OCTET_STREAM).build();
|
||||||
}
|
}
|
||||||
|
case DISALLOWSNAPSHOT: {
|
||||||
|
np.disallowSnapshot(fullpath);
|
||||||
|
return Response.ok().type(MediaType.APPLICATION_OCTET_STREAM).build();
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
throw new UnsupportedOperationException(op + " is not supported");
|
throw new UnsupportedOperationException(op + " is not supported");
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,6 +61,7 @@ import org.apache.hadoop.hdfs.MiniDFSCluster;
|
||||||
import org.apache.hadoop.hdfs.TestDFSClientRetries;
|
import org.apache.hadoop.hdfs.TestDFSClientRetries;
|
||||||
import org.apache.hadoop.hdfs.TestFileCreation;
|
import org.apache.hadoop.hdfs.TestFileCreation;
|
||||||
import org.apache.hadoop.hdfs.client.HdfsClientConfigKeys;
|
import org.apache.hadoop.hdfs.client.HdfsClientConfigKeys;
|
||||||
|
import org.apache.hadoop.hdfs.protocol.SnapshottableDirectoryStatus;
|
||||||
import org.apache.hadoop.hdfs.server.namenode.NameNode;
|
import org.apache.hadoop.hdfs.server.namenode.NameNode;
|
||||||
import org.apache.hadoop.hdfs.server.namenode.snapshot.SnapshotTestHelper;
|
import org.apache.hadoop.hdfs.server.namenode.snapshot.SnapshotTestHelper;
|
||||||
import org.apache.hadoop.hdfs.server.namenode.web.resources.NamenodeWebHdfsMethods;
|
import org.apache.hadoop.hdfs.server.namenode.web.resources.NamenodeWebHdfsMethods;
|
||||||
|
@ -375,6 +376,60 @@ public class TestWebHDFS {
|
||||||
false));
|
false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test allow and disallow snapshot through WebHdfs. Verifying webhdfs with
|
||||||
|
* Distributed filesystem methods.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testWebHdfsAllowandDisallowSnapshots() throws Exception {
|
||||||
|
MiniDFSCluster cluster = null;
|
||||||
|
final Configuration conf = WebHdfsTestUtil.createConf();
|
||||||
|
try {
|
||||||
|
cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build();
|
||||||
|
cluster.waitActive();
|
||||||
|
final DistributedFileSystem dfs = cluster.getFileSystem();
|
||||||
|
final WebHdfsFileSystem webHdfs = WebHdfsTestUtil
|
||||||
|
.getWebHdfsFileSystem(conf, WebHdfsConstants.WEBHDFS_SCHEME);
|
||||||
|
|
||||||
|
final Path bar = new Path("/bar");
|
||||||
|
dfs.mkdirs(bar);
|
||||||
|
|
||||||
|
// allow snapshots on /bar using webhdfs
|
||||||
|
webHdfs.allowSnapshot(bar);
|
||||||
|
webHdfs.createSnapshot(bar, "s1");
|
||||||
|
final Path s1path = SnapshotTestHelper.getSnapshotRoot(bar, "s1");
|
||||||
|
Assert.assertTrue(webHdfs.exists(s1path));
|
||||||
|
SnapshottableDirectoryStatus[] snapshottableDirs =
|
||||||
|
dfs.getSnapshottableDirListing();
|
||||||
|
assertEquals(1, snapshottableDirs.length);
|
||||||
|
assertEquals(bar, snapshottableDirs[0].getFullPath());
|
||||||
|
dfs.deleteSnapshot(bar, "s1");
|
||||||
|
dfs.disallowSnapshot(bar);
|
||||||
|
snapshottableDirs = dfs.getSnapshottableDirListing();
|
||||||
|
assertNull(snapshottableDirs);
|
||||||
|
|
||||||
|
// disallow snapshots on /bar using webhdfs
|
||||||
|
dfs.allowSnapshot(bar);
|
||||||
|
snapshottableDirs = dfs.getSnapshottableDirListing();
|
||||||
|
assertEquals(1, snapshottableDirs.length);
|
||||||
|
assertEquals(bar, snapshottableDirs[0].getFullPath());
|
||||||
|
webHdfs.disallowSnapshot(bar);
|
||||||
|
snapshottableDirs = dfs.getSnapshottableDirListing();
|
||||||
|
assertNull(snapshottableDirs);
|
||||||
|
try {
|
||||||
|
webHdfs.createSnapshot(bar);
|
||||||
|
fail("Cannot create snapshot on a non-snapshottable directory");
|
||||||
|
} catch (Exception e) {
|
||||||
|
GenericTestUtils.assertExceptionContains(
|
||||||
|
"Directory is not a snapshottable directory", e);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (cluster != null) {
|
||||||
|
cluster.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test snapshot creation through WebHdfs
|
* Test snapshot creation through WebHdfs
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue