private void deleteCorruptedFile(String path) { try { namenode.getRpcServer().delete(path, true); LOG.info("Fsck: deleted corrupt file " + path); } catch (Exception e) { LOG.error("Fsck: error deleting corrupted file " + path, e); internalError = true; } }
final LocatedBlocks locations = np.getBlockLocations(path, offset, 1); final int count = locations.locatedBlockCount(); if (count > 0) {
/** A utility method for creating credentials. */ public static Credentials createCredentials(final NameNode namenode, final UserGroupInformation ugi, final String renewer) throws IOException { final Token<DelegationTokenIdentifier> token = namenode.getRpcServer( ).getDelegationToken(new Text(renewer)); if (token == null) { return null; } final InetSocketAddress addr = namenode.getNameNodeAddress(); SecurityUtil.setTokenService(token, addr); final Credentials c = new Credentials(); c.addToken(new Text(ugi.getShortUserName()), token); return c; }
private void checkDir(String path, Result replRes, Result ecRes) throws IOException { if (snapshottableDirs != null && snapshottableDirs.contains(path)) { String snapshotPath = (path.endsWith(Path.SEPARATOR) ? path : path + Path.SEPARATOR) + HdfsConstants.DOT_SNAPSHOT_DIR; HdfsFileStatus snapshotFileInfo = namenode.getRpcServer().getFileInfo( snapshotPath); check(snapshotPath, snapshotFileInfo, replRes, ecRes); } byte[] lastReturnedName = HdfsFileStatus.EMPTY_NAME; DirectoryListing thisListing; if (showFiles) { out.println(path + " <dir>"); } totalDirs++; do { assert lastReturnedName != null; thisListing = namenode.getRpcServer().getListing( path, lastReturnedName, false); if (thisListing == null) { return; } HdfsFileStatus[] files = thisListing.getPartialListing(); for (int i = 0; i < files.length; i++) { check(path, files[i], replRes, ecRes); } lastReturnedName = thisListing.getLastName(); } while (thisListing.hasMore()); }
namenode.getRpcServer().getSnapshottableDirListing(); if (snapshotDirs != null) { for (SnapshottableDirectoryStatus dir : snapshotDirs) { final HdfsFileStatus file = namenode.getRpcServer().getFileInfo(path); if (file != null) {
final boolean b = np.mkdirs(fullpath, permission.getFsPermission(), true); final String js = JsonUtil.toJsonString("boolean", b); return Response.ok(js).type(MediaType.APPLICATION_JSON).build(); np.createSymlink(destination.getValue(), fullpath, PermissionParam.getDefaultFsPermission(), createParent.getValue()); return Response.ok().type(MediaType.APPLICATION_OCTET_STREAM).build(); final boolean b = np.rename(fullpath, destination.getValue()); final String js = JsonUtil.toJsonString("boolean", b); return Response.ok(js).type(MediaType.APPLICATION_JSON).build(); } else { np.rename2(fullpath, destination.getValue(), s.toArray(new Options.Rename[s.size()])); return Response.ok().type(MediaType.APPLICATION_OCTET_STREAM).build(); final boolean b = np.setReplication(fullpath, replication.getValue(conf)); final String js = JsonUtil.toJsonString("boolean", b); return Response.ok(js).type(MediaType.APPLICATION_JSON).build(); np.setOwner(fullpath, owner.getValue(), group.getValue()); return Response.ok().type(MediaType.APPLICATION_OCTET_STREAM).build(); np.setPermission(fullpath, permission.getFsPermission()); return Response.ok().type(MediaType.APPLICATION_OCTET_STREAM).build(); np.setTimes(fullpath, modificationTime.getValue(), accessTime.getValue()); return Response.ok().type(MediaType.APPLICATION_OCTET_STREAM).build();
String dir = "/testNamenodeRetryCache/testCreateSnapshot/src"; resetCall(); nnRpc.mkdirs(dir, perm, true); nnRpc.allowSnapshot(dir); String name = nnRpc.createSnapshot(dir, "snap1"); Assert.assertEquals(name, nnRpc.createSnapshot(dir, "snap1")); Assert.assertEquals(name, nnRpc.createSnapshot(dir, "snap1")); Assert.assertEquals(name, nnRpc.createSnapshot(dir, "snap1")); nnRpc.createSnapshot(dir, "snap1"); Assert.fail("testSnapshotMethods expected exception is not thrown"); } catch (IOException e) { nnRpc.renameSnapshot(dir, "snap1", "snap2"); nnRpc.renameSnapshot(dir, "snap1", "snap2"); nnRpc.renameSnapshot(dir, "snap1", "snap2"); nnRpc.renameSnapshot(dir, "snap1", "snap2"); Assert.fail("testSnapshotMethods expected exception is not thrown"); } catch (IOException e) { nnRpc.deleteSnapshot(dir, "snap2"); nnRpc.deleteSnapshot(dir, "snap2"); nnRpc.deleteSnapshot(dir, "snap2"); nnRpc.deleteSnapshot(dir, "snap2"); Assert.fail("testSnapshotMethods expected exception is not thrown"); } catch (IOException e) {
final HdfsFileStatus status = np.getFileInfo(path); if (status == null) { throw new FileNotFoundException("File " + path + " not found."); final LocatedBlocks locations = np.getBlockLocations(path, offset, 1); final int count = locations.locatedBlockCount(); if (count > 0) {
.getDelegationToken(new Text(renewer)); cluster.transitionToActive(1); nn2.getRpcServer().renewDelegationToken(token); nn2.getRpcServer().cancelDelegationToken(token); token = nn2.getRpcServer().getDelegationToken(new Text(renewer)); Assert.assertTrue(token != null); } finally {
@Override public void run() { thr = Thread.currentThread(); FsPermission p = new FsPermission((short)0777); int i = 0; while (!stopped) { try { String dirname = "/thr-" + thr.getId() + "-dir-" + i; nn.mkdirs(dirname, p, true); nn.delete(dirname, true); } catch (SafeModeException sme) { // This is OK - the tests will bring NN in and out of safemode } catch (Throwable e) { LOG.warn("Got error in transaction thread", e); caught.compareAndSet(null, e); break; } i++; } }
boolean hdfsPathExists(String path) throws AccessControlException, UnresolvedLinkException, IOException { try { HdfsFileStatus hfs = namenode.getRpcServer().getFileInfo(path); return (hfs != null); } catch (FileNotFoundException e) { return false; } }
nn1.getRpcServer().setReplication(TEST_FILE, (short) 2); while (BlockManagerTestUtil.getComputedDatanodeWork( nn1.getNamesystem().getBlockManager()) > 0) { cluster.triggerBlockReports(); nn1.getRpcServer().setReplication(TEST_FILE, (short) 1); nn2.getRpcServer().getFileInfo(TEST_FILE).getReplication());
nnRpc.setReplication("/filestatus0", (short) 4); nnRpc.delete("/filestatus0", true); nnRpc.delete("/filestatus1", true); nnRpc.metaSave("metasaveAfterDelete.out.txt");
fs.mkdirs(baseDir); fs.exists(baseDir); long baseDirFileId = nnRpc.getFileInfo(baseDir.toString()).getFileId(); nnRpc.getPreferredBlockSize(testFileInodePath.toString())); LocatedBlocks l1 = nnRpc.getBlockLocations(testFileInodePath.toString(), 0, Long.MAX_VALUE); LocatedBlocks l2 = nnRpc.getBlockLocations(testFileRegularPath.toString(), 0, Long.MAX_VALUE); checkEquals(l1, l2);
/** * Test for rename2 */ @Test public void testRename2() throws Exception { String src = "/testNamenodeRetryCache/testRename2/src"; String target = "/testNamenodeRetryCache/testRename2/target"; resetCall(); nnRpc.mkdirs(src, perm, true); // Retried renames succeed newCall(); nnRpc.rename2(src, target, Rename.NONE); nnRpc.rename2(src, target, Rename.NONE); nnRpc.rename2(src, target, Rename.NONE); // A non-retried request fails newCall(); try { nnRpc.rename2(src, target, Rename.NONE); Assert.fail("testRename 2 expected exception is not thrown"); } catch (IOException e) { // expected } }
return; if (!namenode.getRpcServer().mkdirs( target, file.getPermission(), true)) { throw new IOException("failed to create directory " + target);
private static DirectoryListing getDirectoryListing(final NamenodeProtocols np, final String p, byte[] startAfter) throws IOException { final DirectoryListing listing = np.getListing(p, startAfter, false); if (listing == null) { // the directory does not exist throw new FileNotFoundException("File " + p + " does not exist."); } return listing; }
/** * Test for rename1 */ @SuppressWarnings("deprecation") @Test public void testRename1() throws Exception { String src = "/testNamenodeRetryCache/testRename1/src"; String target = "/testNamenodeRetryCache/testRename1/target"; resetCall(); nnRpc.mkdirs(src, perm, true); // Retried renames succeed newCall(); Assert.assertTrue(nnRpc.rename(src, target)); Assert.assertTrue(nnRpc.rename(src, target)); Assert.assertTrue(nnRpc.rename(src, target)); // A non-retried request fails newCall(); Assert.assertFalse(nnRpc.rename(src, target)); }
private void checkNameSpace(Configuration conf) throws IOException { NameNode namenode = new NameNode(conf); NamenodeProtocols nnRpc = namenode.getRpcServer(); assertTrue(nnRpc.getFileInfo("/test").isDir()); nnRpc.setSafeMode(SafeModeAction.SAFEMODE_ENTER, false); nnRpc.saveNamespace(); namenode.stop(); namenode.join(); }
nn1.getRpcServer().setReplication(TEST_FILE, (short) 1); nn1.getRpcServer().rollEditLog(); nn2.getRpcServer().getFileInfo(TEST_FILE).getReplication());