/** */ public static void main(String argv[]) throws Exception { if (DFSUtil.parseHelpArgument(argv, NameNode.USAGE, System.out, true)) { System.exit(0); } try { StringUtils.startupShutdownMessage(NameNode.class, argv, LOG); NameNode namenode = createNameNode(argv, null); if (namenode != null) { namenode.join(); } } catch (Throwable e) { LOG.error("Failed to start namenode.", e); terminate(1, e); } }
NNThroughputBenchmark(Configuration conf) throws IOException, LoginException { config = conf; // We do not need many handlers, since each thread simulates a handler // by calling name-node methods directly config.setInt("dfs.namenode.handler.count", 1); // set exclude file config.set("dfs.hosts.exclude", "${hadoop.tmp.dir}/dfs/hosts/exclude"); File excludeFile = new File(config.get("dfs.hosts.exclude", "exclude")); if(! excludeFile.exists()) { if(!excludeFile.getParentFile().mkdirs()) throw new IOException("NNThroughputBenchmark: cannot mkdir " + excludeFile); } new FileOutputStream(excludeFile).close(); // Start the NameNode String[] argv = new String[] {}; nameNode = NameNode.createNameNode(argv, config); }
/** * Check whether the namenode can be started. */ private boolean canStartNameNode(Configuration conf) throws IOException { NameNode nn2 = null; try { nn2 = NameNode.createNameNode(new String[]{}, conf); } catch(IOException e) { if (e instanceof java.net.BindException) return false; throw e; } finally { stopNameNode(nn2); } return true; }
NameNode startNameNode( Configuration conf, String imageDirs, String editsDirs, StartupOption start) throws IOException { conf.set(DFSConfigKeys.FS_DEFAULT_NAME_KEY, "hdfs://localhost:0"); conf.set(DFSConfigKeys.DFS_NAMENODE_HTTP_ADDRESS_KEY, "0.0.0.0:0"); conf.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY, imageDirs); conf.set(DFSConfigKeys.DFS_NAMENODE_EDITS_DIR_KEY, editsDirs); String[] args = new String[]{start.getName()}; NameNode nn = NameNode.createNameNode(args, conf); Assert.assertTrue(nn.isInSafeMode()); return nn; }
NameNode startNameNode( Configuration conf, String imageDirs, String editsDirs, StartupOption start) throws IOException { conf.set(DFSConfigKeys.FS_DEFAULT_NAME_KEY, "hdfs://localhost:0"); conf.set(DFSConfigKeys.DFS_NAMENODE_HTTP_ADDRESS_KEY, "0.0.0.0:0"); conf.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY, imageDirs); conf.set(DFSConfigKeys.DFS_NAMENODE_EDITS_DIR_KEY, editsDirs); String[] args = new String[]{start.getName()}; NameNode nn = NameNode.createNameNode(args, conf); assertTrue(nn.isInSafeMode()); return nn; }
@Override protected NameNode doCreate(Dictionary properties) throws Exception { Configuration conf = new Configuration(); for (Enumeration e = properties.keys(); e.hasMoreElements();) { Object key = e.nextElement(); Object val = properties.get(key); conf.set( key.toString(), val.toString() ); } boolean exists = false; for (File file : FSNamesystem.getNamespaceDirs(conf)) { exists |= file.exists(); } if (!exists) { NameNode.format(conf); } NameNode nameNode = NameNode.createNameNode(null, conf); return nameNode; }
BackupNode startBackupNode(Configuration conf, StartupOption t, int i) throws IOException { Configuration c = new HdfsConfiguration(conf); String dirs = getBackupNodeDir(t, i); c.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY, dirs); c.set(DFSConfigKeys.DFS_NAMENODE_EDITS_DIR_KEY, "${dfs.name.dir}"); return (BackupNode)NameNode.createNameNode(new String[]{t.getName()}, c); }
/** */ public static void main(String argv[]) throws Exception { try { StringUtils.startupShutdownMessage(NameNode.class, argv, LOG); NameNode namenode = createNameNode(argv, null); if (namenode != null) namenode.join(); } catch (Throwable e) { LOG.error(StringUtils.stringifyException(e)); System.exit(-1); } }
/** */ public static void main(String argv[]) throws Exception { try { StringUtils.startupShutdownMessage(NameNode.class, argv, LOG); NameNode namenode = createNameNode(argv, null); if (namenode != null) namenode.join(); } catch (Throwable e) { LOG.error(StringUtils.stringifyException(e)); System.exit(-1); } } }
public void start() { log.info("Starting NameNode..."); try { try { nameNode = NameNode.createNameNode(null, HadoopUtils.toConfiguration(startupProperties)); } catch (InconsistentFSStateException e) { log.info("HDFS is in inconsistent state. Reformatting..."); formatStorage(); nameNode = NameNode.createNameNode(null, HadoopUtils.toConfiguration(startupProperties)); } nameNode.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); } catch (IOException e) { throw new TechnicalException(e); } log.info("NameNode started."); }
/** */ public static void main(String argv[]) throws Exception { if (DFSUtil.parseHelpArgument(argv, NameNode.USAGE, System.out, true)) { System.exit(0); } try { StringUtils.startupShutdownMessage(NameNode.class, argv, LOG); NameNode namenode = createNameNode(argv, null); if (namenode != null) { namenode.join(); } } catch (Throwable e) { LOG.error("Failed to start namenode.", e); terminate(1, e); } }
/** * Check whether the namenode can be started. */ private boolean canStartNameNode(Configuration conf) throws IOException { NameNode nn2 = null; try { nn2 = NameNode.createNameNode(new String[]{}, conf); } catch(IOException e) { if (e instanceof java.net.BindException) return false; throw e; } finally { stopNameNode(nn2); } return true; }
/** */ public static void main(String argv[]) throws Exception { if (DFSUtil.parseHelpArgument(argv, NameNode.USAGE, System.out, true)) { System.exit(0); } try { StringUtils.startupShutdownMessage(NameNode.class, argv, LOG); NameNode namenode = createNameNode(argv, null); if (namenode != null) { namenode.join(); } } catch (Throwable e) { LOG.error("Failed to start namenode.", e); terminate(1, e); } }
/** * Start the namenode. */ public NameNode startNameNode(boolean withService) throws IOException { hdfsDir = new File(TEST_DATA_DIR, "dfs"); if ( hdfsDir.exists() && !FileUtil.fullyDelete(hdfsDir) ) { throw new IOException("Could not delete hdfs directory '" + hdfsDir + "'"); } config = new HdfsConfiguration(); config.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY, fileAsURI(new File(hdfsDir, "name1")).toString()); FileSystem.setDefaultUri(config, "hdfs://" + THIS_HOST); if (withService) { NameNode.setServiceAddress(config, THIS_HOST); } config.set(DFSConfigKeys.DFS_NAMENODE_HTTP_ADDRESS_KEY, THIS_HOST); DFSTestUtil.formatNameNode(config); String[] args = new String[] {}; // NameNode will modify config with the ports it bound to return NameNode.createNameNode(args, config); }
/** * Test namenode format with -format option when an empty name directory * exists. Format should succeed. * * @throws IOException */ @Test public void testFormatWithEmptyDir() throws IOException { if (!hdfsDir.mkdirs()) { fail("Failed to create dir " + hdfsDir.getPath()); } String[] argv = { "-format" }; try { NameNode.createNameNode(argv, config); fail("createNameNode() did not call System.exit()"); } catch (ExitException e) { assertEquals("Format should have succeeded", 0, e.status); } String cid = getClusterId(config); assertTrue("Didn't get new ClusterId", (cid != null && !cid.equals(""))); }
/** * Test namenode format with -force -nonInteractive -force option. Format * should succeed. * * @throws IOException */ @Test public void testFormatWithNonInteractiveAndForce() throws IOException { if (!hdfsDir.mkdirs()) { fail("Failed to create dir " + hdfsDir.getPath()); } String[] argv = { "-format", "-nonInteractive", "-force" }; try { NameNode.createNameNode(argv, config); fail("createNameNode() did not call System.exit()"); } catch (ExitException e) { assertEquals("Format should have succeeded", 0, e.status); } String cid = getClusterId(config); assertTrue("Didn't get new ClusterId", (cid != null && !cid.equals(""))); }
/** * Test namenode format with -format option. Format should succeed. * * @throws IOException */ @Test public void testFormat() throws IOException { String[] argv = { "-format" }; try { NameNode.createNameNode(argv, config); fail("createNameNode() did not call System.exit()"); } catch (ExitException e) { assertEquals("Format should have succeeded", 0, e.status); } String cid = getClusterId(config); assertTrue("Didn't get new ClusterId", (cid != null && !cid.equals(""))); }
/** * Test namenode format with -format -force -clusterid option when name * directory exists. Format should succeed. * * @throws IOException */ @Test public void testFormatWithForceAndClusterId() throws IOException { if (!hdfsDir.mkdirs()) { fail("Failed to create dir " + hdfsDir.getPath()); } String myId = "testFormatWithForceAndClusterId"; String[] argv = { "-format", "-force", "-clusterid", myId }; try { NameNode.createNameNode(argv, config); fail("createNameNode() did not call System.exit()"); } catch (ExitException e) { assertEquals("Format should have succeeded", 0, e.status); } String cId = getClusterId(config); assertEquals("ClusterIds do not match", myId, cId); }
/** * Test namenode format with -format -nonInteractive options when name * directory does not exist. Format should succeed. * * @throws IOException */ @Test public void testFormatWithNonInteractiveNameDirDoesNotExit() throws IOException { String[] argv = { "-format", "-nonInteractive" }; try { NameNode.createNameNode(argv, config); fail("createNameNode() did not call System.exit()"); } catch (ExitException e) { assertEquals("Format should have succeeded", 0, e.status); } String cid = getClusterId(config); assertTrue("Didn't get new ClusterId", (cid != null && !cid.equals(""))); }
BackupNode startBackupNode(Configuration conf, StartupOption startupOpt, int idx) throws IOException { Configuration c = new HdfsConfiguration(conf); String dirs = getBackupNodeDir(startupOpt, idx); c.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY, dirs); c.set(DFSConfigKeys.DFS_NAMENODE_EDITS_DIR_KEY, "${" + DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY + "}"); c.set(DFSConfigKeys.DFS_NAMENODE_BACKUP_ADDRESS_KEY, "127.0.0.1:0"); c.set(DFSConfigKeys.DFS_NAMENODE_BACKUP_HTTP_ADDRESS_KEY, "127.0.0.1:0"); BackupNode bn = (BackupNode)NameNode.createNameNode( new String[]{startupOpt.getName()}, c); assertTrue(bn.getRole() + " must be in SafeMode.", bn.isInSafeMode()); assertTrue(bn.getRole() + " must be in StandbyState", bn.getNamesystem().getHAState() .equalsIgnoreCase(HAServiceState.STANDBY.name())); return bn; }