Java Code Examples for org.apache.hadoop.hdfs.DistributedFileSystem#setSafeMode()
The following examples show how to use
org.apache.hadoop.hdfs.DistributedFileSystem#setSafeMode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestWithMiniClusterBase.java From NNAnalytics with Apache License 2.0 | 6 votes |
@Test //(timeout = 120000L) public void testRestartFetchNamespace() throws Exception { // Shutdown NNA. long currentTxid = nna.getLoader().getCurrentTxId(); nna.shutdown(); // Trigger file system updates. addFiles(100, 0L); DistributedFileSystem fileSystem = (DistributedFileSystem) FileSystem.get(CONF); fileSystem.setSafeMode(SafeModeAction.SAFEMODE_ENTER); fileSystem.saveNamespace(); fileSystem.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); nnaConf.set("nna.bootstrap.auto.fetch.namespace", "true"); nna.init(nnaConf, null, CONF); long restartedTxid = nna.getLoader().getCurrentTxId(); assertThat(restartedTxid, is(greaterThan(currentTxid + 99))); }
Example 2
Source File: FSUtils.java From hbase with Apache License 2.0 | 6 votes |
/** * We use reflection because {@link DistributedFileSystem#setSafeMode( * HdfsConstants.SafeModeAction action, boolean isChecked)} is not in hadoop 1.1 * * @param dfs * @return whether we're in safe mode * @throws IOException */ private static boolean isInSafeMode(DistributedFileSystem dfs) throws IOException { boolean inSafeMode = false; try { Method m = DistributedFileSystem.class.getMethod("setSafeMode", new Class<?> []{ org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction.class, boolean.class}); inSafeMode = (Boolean) m.invoke(dfs, org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction.SAFEMODE_GET, true); } catch (Exception e) { if (e instanceof IOException) throw (IOException) e; // Check whether dfs is on safemode. inSafeMode = dfs.setSafeMode( org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction.SAFEMODE_GET); } return inSafeMode; }
Example 3
Source File: TestFSImage.java From hadoop with Apache License 2.0 | 6 votes |
/** * Ensure that the digest written by the saver equals to the digest of the * file. */ @Test public void testDigest() throws IOException { Configuration conf = new Configuration(); MiniDFSCluster cluster = null; try { cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build(); DistributedFileSystem fs = cluster.getFileSystem(); fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); fs.saveNamespace(); fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); File currentDir = FSImageTestUtil.getNameNodeCurrentDirs(cluster, 0).get( 0); File fsimage = FSImageTestUtil.findNewestImageFile(currentDir .getAbsolutePath()); assertEquals(MD5FileUtils.readStoredMd5ForFile(fsimage), MD5FileUtils.computeMd5ForFile(fsimage)); } finally { if (cluster != null) { cluster.shutdown(); } } }
Example 4
Source File: TestSaveNamespace.java From big-c with Apache License 2.0 | 6 votes |
@Test (timeout=30000) public void testSaveNamespaceWithDanglingLease() throws Exception { MiniDFSCluster cluster = new MiniDFSCluster.Builder(new Configuration()) .numDataNodes(1).build(); cluster.waitActive(); DistributedFileSystem fs = cluster.getFileSystem(); try { cluster.getNamesystem().leaseManager.addLease("me", "/non-existent"); fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); cluster.getNameNodeRpc().saveNamespace(); fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); } finally { if (cluster != null) { cluster.shutdown(); } } }
Example 5
Source File: TestSaveNamespace.java From big-c with Apache License 2.0 | 6 votes |
/** * Test for save namespace should succeed when parent directory renamed with * open lease and destination directory exist. * This test is a regression for HDFS-2827 */ @Test public void testSaveNamespaceWithRenamedLease() throws Exception { MiniDFSCluster cluster = new MiniDFSCluster.Builder(new Configuration()) .numDataNodes(1).build(); cluster.waitActive(); DistributedFileSystem fs = (DistributedFileSystem) cluster.getFileSystem(); OutputStream out = null; try { fs.mkdirs(new Path("/test-target")); out = fs.create(new Path("/test-source/foo")); // don't close fs.rename(new Path("/test-source/"), new Path("/test-target/")); fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); cluster.getNameNodeRpc().saveNamespace(); fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); } finally { IOUtils.cleanup(LOG, out, fs); if (cluster != null) { cluster.shutdown(); } } }
Example 6
Source File: DFSAdmin.java From hadoop with Apache License 2.0 | 5 votes |
private boolean waitExitSafeMode(DistributedFileSystem dfs, boolean inSafeMode) throws IOException { while (inSafeMode) { try { Thread.sleep(5000); } catch (java.lang.InterruptedException e) { throw new IOException("Wait Interrupted"); } inSafeMode = dfs.setSafeMode(SafeModeAction.SAFEMODE_GET, false); } return inSafeMode; }
Example 7
Source File: TestFSImageWithAcl.java From hadoop with Apache License 2.0 | 5 votes |
/** * Restart the NameNode, optionally saving a new checkpoint. * * @param fs DistributedFileSystem used for saving namespace * @param persistNamespace boolean true to save a new checkpoint * @throws IOException if restart fails */ private void restart(DistributedFileSystem fs, boolean persistNamespace) throws IOException { if (persistNamespace) { fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); fs.saveNamespace(); fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); } cluster.restartNameNode(); cluster.waitActive(); }
Example 8
Source File: TestFSImageWithXAttr.java From hadoop with Apache License 2.0 | 5 votes |
/** * Restart the NameNode, optionally saving a new checkpoint. * * @param fs DistributedFileSystem used for saving namespace * @param persistNamespace boolean true to save a new checkpoint * @throws IOException if restart fails */ private void restart(DistributedFileSystem fs, boolean persistNamespace) throws IOException { if (persistNamespace) { fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); fs.saveNamespace(); fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); } cluster.restartNameNode(); cluster.waitActive(); }
Example 9
Source File: TestSafemodeBringsDownMaster.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testSafemodeBringsDownMaster() throws Exception { final TableName tableName = TableName.valueOf("testSafemodeBringsDownMaster"); final byte[][] splitKeys = new byte[][] { Bytes.toBytes("a"), Bytes.toBytes("b"), Bytes.toBytes("c") }; RegionInfo[] regions = MasterProcedureTestingUtility.createTable( getMasterProcedureExecutor(), tableName, splitKeys, "f1", "f2"); MiniDFSCluster dfsCluster = UTIL.getDFSCluster(); DistributedFileSystem dfs = (DistributedFileSystem) dfsCluster.getFileSystem(); dfs.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_ENTER); final long timeOut = 180000; long startTime = System.currentTimeMillis(); int index = -1; do { index = UTIL.getMiniHBaseCluster().getServerWithMeta(); } while (index == -1 && startTime + timeOut < System.currentTimeMillis()); if (index != -1){ UTIL.getMiniHBaseCluster().abortRegionServer(index); UTIL.getMiniHBaseCluster().waitOnRegionServer(index); } UTIL.waitFor(timeOut, new Waiter.Predicate<Exception>() { @Override public boolean evaluate() throws Exception { List<JVMClusterUtil.MasterThread> threads = UTIL.getMiniHBaseCluster().getLiveMasterThreads(); return threads == null || threads.isEmpty(); } }); dfs.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_LEAVE); }
Example 10
Source File: DFSAdmin.java From big-c with Apache License 2.0 | 5 votes |
private boolean waitExitSafeMode(DistributedFileSystem dfs, boolean inSafeMode) throws IOException { while (inSafeMode) { try { Thread.sleep(5000); } catch (java.lang.InterruptedException e) { throw new IOException("Wait Interrupted"); } inSafeMode = dfs.setSafeMode(SafeModeAction.SAFEMODE_GET, false); } return inSafeMode; }
Example 11
Source File: TestFSImageWithXAttr.java From big-c with Apache License 2.0 | 5 votes |
/** * Restart the NameNode, optionally saving a new checkpoint. * * @param fs DistributedFileSystem used for saving namespace * @param persistNamespace boolean true to save a new checkpoint * @throws IOException if restart fails */ private void restart(DistributedFileSystem fs, boolean persistNamespace) throws IOException { if (persistNamespace) { fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); fs.saveNamespace(); fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); } cluster.restartNameNode(); cluster.waitActive(); }
Example 12
Source File: TestFSImageWithAcl.java From big-c with Apache License 2.0 | 5 votes |
/** * Restart the NameNode, optionally saving a new checkpoint. * * @param fs DistributedFileSystem used for saving namespace * @param persistNamespace boolean true to save a new checkpoint * @throws IOException if restart fails */ private void restart(DistributedFileSystem fs, boolean persistNamespace) throws IOException { if (persistNamespace) { fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); fs.saveNamespace(); fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); } cluster.restartNameNode(); cluster.waitActive(); }
Example 13
Source File: TestFSImage.java From big-c with Apache License 2.0 | 4 votes |
/** * Ensure mtime and atime can be loaded from fsimage. */ @Test(timeout=60000) public void testLoadMtimeAtime() throws Exception { Configuration conf = new Configuration(); MiniDFSCluster cluster = null; try { cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1).build(); cluster.waitActive(); DistributedFileSystem hdfs = cluster.getFileSystem(); String userDir = hdfs.getHomeDirectory().toUri().getPath().toString(); Path file = new Path(userDir, "file"); Path dir = new Path(userDir, "/dir"); Path link = new Path(userDir, "/link"); hdfs.createNewFile(file); hdfs.mkdirs(dir); hdfs.createSymlink(file, link, false); long mtimeFile = hdfs.getFileStatus(file).getModificationTime(); long atimeFile = hdfs.getFileStatus(file).getAccessTime(); long mtimeDir = hdfs.getFileStatus(dir).getModificationTime(); long mtimeLink = hdfs.getFileLinkStatus(link).getModificationTime(); long atimeLink = hdfs.getFileLinkStatus(link).getAccessTime(); // save namespace and restart cluster hdfs.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_ENTER); hdfs.saveNamespace(); hdfs.setSafeMode(HdfsConstants.SafeModeAction.SAFEMODE_LEAVE); cluster.shutdown(); cluster = new MiniDFSCluster.Builder(conf).format(false) .numDataNodes(1).build(); cluster.waitActive(); hdfs = cluster.getFileSystem(); assertEquals(mtimeFile, hdfs.getFileStatus(file).getModificationTime()); assertEquals(atimeFile, hdfs.getFileStatus(file).getAccessTime()); assertEquals(mtimeDir, hdfs.getFileStatus(dir).getModificationTime()); assertEquals(mtimeLink, hdfs.getFileLinkStatus(link).getModificationTime()); assertEquals(atimeLink, hdfs.getFileLinkStatus(link).getAccessTime()); } finally { if (cluster != null) { cluster.shutdown(); } } }
Example 14
Source File: TestFSImage.java From big-c with Apache License 2.0 | 4 votes |
private void testPersistHelper(Configuration conf) throws IOException { MiniDFSCluster cluster = null; try { cluster = new MiniDFSCluster.Builder(conf).build(); cluster.waitActive(); FSNamesystem fsn = cluster.getNamesystem(); DistributedFileSystem fs = cluster.getFileSystem(); final Path dir = new Path("/abc/def"); final Path file1 = new Path(dir, "f1"); final Path file2 = new Path(dir, "f2"); // create an empty file f1 fs.create(file1).close(); // create an under-construction file f2 FSDataOutputStream out = fs.create(file2); out.writeBytes("hello"); ((DFSOutputStream) out.getWrappedStream()).hsync(EnumSet .of(SyncFlag.UPDATE_LENGTH)); // checkpoint fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); fs.saveNamespace(); fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); cluster.restartNameNode(); cluster.waitActive(); fs = cluster.getFileSystem(); assertTrue(fs.isDirectory(dir)); assertTrue(fs.exists(file1)); assertTrue(fs.exists(file2)); // check internals of file2 INodeFile file2Node = fsn.dir.getINode4Write(file2.toString()).asFile(); assertEquals("hello".length(), file2Node.computeFileSize()); assertTrue(file2Node.isUnderConstruction()); BlockInfoContiguous[] blks = file2Node.getBlocks(); assertEquals(1, blks.length); assertEquals(BlockUCState.UNDER_CONSTRUCTION, blks[0].getBlockUCState()); // check lease manager Lease lease = fsn.leaseManager.getLeaseByPath(file2.toString()); Assert.assertNotNull(lease); } finally { if (cluster != null) { cluster.shutdown(); } } }
Example 15
Source File: TestOfflineImageViewer.java From big-c with Apache License 2.0 | 4 votes |
@BeforeClass public static void createOriginalFSImage() throws IOException { MiniDFSCluster cluster = null; try { Configuration conf = new Configuration(); conf.setLong( DFSConfigKeys.DFS_NAMENODE_DELEGATION_TOKEN_MAX_LIFETIME_KEY, 10000); conf.setLong( DFSConfigKeys.DFS_NAMENODE_DELEGATION_TOKEN_RENEW_INTERVAL_KEY, 5000); conf.setBoolean( DFSConfigKeys.DFS_NAMENODE_DELEGATION_TOKEN_ALWAYS_USE_KEY, true); conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTH_TO_LOCAL, "RULE:[2:$1@$0](JobTracker@.*FOO.COM)s/@.*//" + "DEFAULT"); cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1).build(); cluster.waitActive(); DistributedFileSystem hdfs = cluster.getFileSystem(); // Create a reasonable namespace for (int i = 0; i < NUM_DIRS; i++) { Path dir = new Path("/dir" + i); hdfs.mkdirs(dir); writtenFiles.put(dir.toString(), pathToFileEntry(hdfs, dir.toString())); for (int j = 0; j < FILES_PER_DIR; j++) { Path file = new Path(dir, "file" + j); FSDataOutputStream o = hdfs.create(file); o.write(23); o.close(); writtenFiles.put(file.toString(), pathToFileEntry(hdfs, file.toString())); } } // Create an empty directory Path emptydir = new Path("/emptydir"); hdfs.mkdirs(emptydir); writtenFiles.put(emptydir.toString(), hdfs.getFileStatus(emptydir)); //Create a directory whose name should be escaped in XML Path invalidXMLDir = new Path("/dirContainingInvalidXMLChar\u0000here"); hdfs.mkdirs(invalidXMLDir); // Get delegation tokens so we log the delegation token op Token<?>[] delegationTokens = hdfs .addDelegationTokens(TEST_RENEWER, null); for (Token<?> t : delegationTokens) { LOG.debug("got token " + t); } final Path snapshot = new Path("/snapshot"); hdfs.mkdirs(snapshot); hdfs.allowSnapshot(snapshot); hdfs.mkdirs(new Path("/snapshot/1")); hdfs.delete(snapshot, true); // Set XAttrs so the fsimage contains XAttr ops final Path xattr = new Path("/xattr"); hdfs.mkdirs(xattr); hdfs.setXAttr(xattr, "user.a1", new byte[]{ 0x31, 0x32, 0x33 }); hdfs.setXAttr(xattr, "user.a2", new byte[]{ 0x37, 0x38, 0x39 }); // OIV should be able to handle empty value XAttrs hdfs.setXAttr(xattr, "user.a3", null); writtenFiles.put(xattr.toString(), hdfs.getFileStatus(xattr)); // Write results to the fsimage file hdfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER, false); hdfs.saveNamespace(); // Determine location of fsimage file originalFsimage = FSImageTestUtil.findLatestImageFile(FSImageTestUtil .getFSImage(cluster.getNameNode()).getStorage().getStorageDir(0)); if (originalFsimage == null) { throw new RuntimeException("Didn't generate or can't find fsimage"); } LOG.debug("original FS image file is " + originalFsimage); } finally { if (cluster != null) cluster.shutdown(); } }
Example 16
Source File: TestOfflineImageViewer.java From hadoop with Apache License 2.0 | 4 votes |
@BeforeClass public static void createOriginalFSImage() throws IOException { MiniDFSCluster cluster = null; try { Configuration conf = new Configuration(); conf.setLong( DFSConfigKeys.DFS_NAMENODE_DELEGATION_TOKEN_MAX_LIFETIME_KEY, 10000); conf.setLong( DFSConfigKeys.DFS_NAMENODE_DELEGATION_TOKEN_RENEW_INTERVAL_KEY, 5000); conf.setBoolean( DFSConfigKeys.DFS_NAMENODE_DELEGATION_TOKEN_ALWAYS_USE_KEY, true); conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTH_TO_LOCAL, "RULE:[2:$1@$0](JobTracker@.*FOO.COM)s/@.*//" + "DEFAULT"); cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1).build(); cluster.waitActive(); DistributedFileSystem hdfs = cluster.getFileSystem(); // Create a reasonable namespace for (int i = 0; i < NUM_DIRS; i++, dirCount++) { Path dir = new Path("/dir" + i); hdfs.mkdirs(dir); writtenFiles.put(dir.toString(), pathToFileEntry(hdfs, dir.toString())); for (int j = 0; j < FILES_PER_DIR; j++) { Path file = new Path(dir, "file" + j); FSDataOutputStream o = hdfs.create(file); o.write(23); o.close(); writtenFiles.put(file.toString(), pathToFileEntry(hdfs, file.toString())); } } // Create an empty directory Path emptydir = new Path("/emptydir"); hdfs.mkdirs(emptydir); dirCount++; writtenFiles.put(emptydir.toString(), hdfs.getFileStatus(emptydir)); //Create a directory whose name should be escaped in XML Path invalidXMLDir = new Path("/dirContainingInvalidXMLChar\u0000here"); hdfs.mkdirs(invalidXMLDir); dirCount++; // Get delegation tokens so we log the delegation token op Token<?>[] delegationTokens = hdfs .addDelegationTokens(TEST_RENEWER, null); for (Token<?> t : delegationTokens) { LOG.debug("got token " + t); } // Create INodeReference final Path src = new Path("/src"); hdfs.mkdirs(src); dirCount++; writtenFiles.put(src.toString(), hdfs.getFileStatus(src)); final Path orig = new Path("/src/orig"); hdfs.mkdirs(orig); hdfs.allowSnapshot(src); hdfs.createSnapshot(src, "snapshot"); final Path dst = new Path("/dst"); hdfs.rename(orig, dst); dirCount++; writtenFiles.put(dst.toString(), hdfs.getFileStatus(dst)); // Set XAttrs so the fsimage contains XAttr ops final Path xattr = new Path("/xattr"); hdfs.mkdirs(xattr); dirCount++; hdfs.setXAttr(xattr, "user.a1", new byte[]{ 0x31, 0x32, 0x33 }); hdfs.setXAttr(xattr, "user.a2", new byte[]{ 0x37, 0x38, 0x39 }); // OIV should be able to handle empty value XAttrs hdfs.setXAttr(xattr, "user.a3", null); writtenFiles.put(xattr.toString(), hdfs.getFileStatus(xattr)); // Write results to the fsimage file hdfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER, false); hdfs.saveNamespace(); // Determine location of fsimage file originalFsimage = FSImageTestUtil.findLatestImageFile(FSImageTestUtil .getFSImage(cluster.getNameNode()).getStorage().getStorageDir(0)); if (originalFsimage == null) { throw new RuntimeException("Didn't generate or can't find fsimage"); } LOG.debug("original FS image file is " + originalFsimage); } finally { if (cluster != null) cluster.shutdown(); } }
Example 17
Source File: DFSAdmin.java From RDFS with Apache License 2.0 | 4 votes |
/** * Safe mode maintenance command. * Usage: java DFSAdmin -safemode [enter | leave | get] * @param argv List of of command line parameters. * @param idx The index of the command that is being processed. * @exception IOException if the filesystem does not exist. */ public void setSafeMode(String[] argv, int idx) throws IOException { DistributedFileSystem dfs = getDFS(); if (dfs == null) { System.err.println("FileSystem is " + getFS().getUri()); return; } if (idx != argv.length - 1) { printUsage("-safemode"); return; } FSConstants.SafeModeAction action; Boolean waitExitSafe = false; if ("leave".equalsIgnoreCase(argv[idx])) { action = FSConstants.SafeModeAction.SAFEMODE_LEAVE; } else if ("enter".equalsIgnoreCase(argv[idx])) { action = FSConstants.SafeModeAction.SAFEMODE_ENTER; } else if ("get".equalsIgnoreCase(argv[idx])) { action = FSConstants.SafeModeAction.SAFEMODE_GET; } else if ("wait".equalsIgnoreCase(argv[idx])) { action = FSConstants.SafeModeAction.SAFEMODE_GET; waitExitSafe = true; } else { printUsage("-safemode"); return; } boolean inSafeMode = dfs.setSafeMode(action); // // If we are waiting for safemode to exit, then poll and // sleep till we are out of safemode. // if (waitExitSafe) { while (inSafeMode) { try { Thread.sleep(5000); } catch (java.lang.InterruptedException e) { throw new IOException("Wait Interrupted"); } inSafeMode = dfs.setSafeMode(action); } } System.out.println("Safe mode is " + (inSafeMode ? "ON" : "OFF")); }
Example 18
Source File: TestFSImage.java From hadoop with Apache License 2.0 | 4 votes |
private void testPersistHelper(Configuration conf) throws IOException { MiniDFSCluster cluster = null; try { cluster = new MiniDFSCluster.Builder(conf).build(); cluster.waitActive(); FSNamesystem fsn = cluster.getNamesystem(); DistributedFileSystem fs = cluster.getFileSystem(); final Path dir = new Path("/abc/def"); final Path file1 = new Path(dir, "f1"); final Path file2 = new Path(dir, "f2"); // create an empty file f1 fs.create(file1).close(); // create an under-construction file f2 FSDataOutputStream out = fs.create(file2); out.writeBytes("hello"); ((DFSOutputStream) out.getWrappedStream()).hsync(EnumSet .of(SyncFlag.UPDATE_LENGTH)); // checkpoint fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); fs.saveNamespace(); fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); cluster.restartNameNode(); cluster.waitActive(); fs = cluster.getFileSystem(); assertTrue(fs.isDirectory(dir)); assertTrue(fs.exists(file1)); assertTrue(fs.exists(file2)); // check internals of file2 INodeFile file2Node = fsn.dir.getINode4Write(file2.toString()).asFile(); assertEquals("hello".length(), file2Node.computeFileSize()); assertTrue(file2Node.isUnderConstruction()); BlockInfoContiguous[] blks = file2Node.getBlocks(); assertEquals(1, blks.length); assertEquals(BlockUCState.UNDER_CONSTRUCTION, blks[0].getBlockUCState()); // check lease manager Lease lease = fsn.leaseManager.getLeaseByPath(file2.toString()); Assert.assertNotNull(lease); } finally { if (cluster != null) { cluster.shutdown(); } } }
Example 19
Source File: DFSAdmin.java From hadoop-gpu with Apache License 2.0 | 4 votes |
/** * Safe mode maintenance command. * Usage: java DFSAdmin -safemode [enter | leave | get] * @param argv List of of command line parameters. * @param idx The index of the command that is being processed. * @exception IOException if the filesystem does not exist. */ public void setSafeMode(String[] argv, int idx) throws IOException { if (!(fs instanceof DistributedFileSystem)) { System.err.println("FileSystem is " + fs.getUri()); return; } if (idx != argv.length - 1) { printUsage("-safemode"); return; } FSConstants.SafeModeAction action; Boolean waitExitSafe = false; if ("leave".equalsIgnoreCase(argv[idx])) { action = FSConstants.SafeModeAction.SAFEMODE_LEAVE; } else if ("enter".equalsIgnoreCase(argv[idx])) { action = FSConstants.SafeModeAction.SAFEMODE_ENTER; } else if ("get".equalsIgnoreCase(argv[idx])) { action = FSConstants.SafeModeAction.SAFEMODE_GET; } else if ("wait".equalsIgnoreCase(argv[idx])) { action = FSConstants.SafeModeAction.SAFEMODE_GET; waitExitSafe = true; } else { printUsage("-safemode"); return; } DistributedFileSystem dfs = (DistributedFileSystem) fs; boolean inSafeMode = dfs.setSafeMode(action); // // If we are waiting for safemode to exit, then poll and // sleep till we are out of safemode. // if (waitExitSafe) { while (inSafeMode) { try { Thread.sleep(5000); } catch (java.lang.InterruptedException e) { throw new IOException("Wait Interrupted"); } inSafeMode = dfs.setSafeMode(action); } } System.out.println("Safe mode is " + (inSafeMode ? "ON" : "OFF")); }
Example 20
Source File: TestFSImageWithAcl.java From hadoop with Apache License 2.0 | 4 votes |
private void testAcl(boolean persistNamespace) throws IOException { Path p = new Path("/p"); DistributedFileSystem fs = cluster.getFileSystem(); fs.create(p).close(); fs.mkdirs(new Path("/23")); AclEntry e = new AclEntry.Builder().setName("foo") .setPermission(READ_EXECUTE).setScope(ACCESS).setType(USER).build(); fs.modifyAclEntries(p, Lists.newArrayList(e)); restart(fs, persistNamespace); AclStatus s = cluster.getNamesystem().getAclStatus(p.toString()); AclEntry[] returned = Lists.newArrayList(s.getEntries()).toArray( new AclEntry[0]); Assert.assertArrayEquals(new AclEntry[] { aclEntry(ACCESS, USER, "foo", READ_EXECUTE), aclEntry(ACCESS, GROUP, READ) }, returned); fs.removeAcl(p); if (persistNamespace) { fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); fs.saveNamespace(); fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); } cluster.restartNameNode(); cluster.waitActive(); s = cluster.getNamesystem().getAclStatus(p.toString()); returned = Lists.newArrayList(s.getEntries()).toArray(new AclEntry[0]); Assert.assertArrayEquals(new AclEntry[] { }, returned); fs.modifyAclEntries(p, Lists.newArrayList(e)); s = cluster.getNamesystem().getAclStatus(p.toString()); returned = Lists.newArrayList(s.getEntries()).toArray(new AclEntry[0]); Assert.assertArrayEquals(new AclEntry[] { aclEntry(ACCESS, USER, "foo", READ_EXECUTE), aclEntry(ACCESS, GROUP, READ) }, returned); }