/** * Generate new blockpoolID. * * @return new blockpoolID */ static String newBlockPoolID() throws UnknownHostException{ String ip; try { ip = DNS.getDefaultIP("default"); } catch (UnknownHostException e) { LOG.warn("Could not find ip address of \"default\" inteface."); throw e; } int rand = DFSUtil.getSecureRandom().nextInt(Integer.MAX_VALUE); return "BP-" + rand + "-"+ ip + "-" + Time.now(); }
static private String getUniqueRackPrefix() { String ip = "unknownIP"; try { ip = DNS.getDefaultIP("default"); } catch (UnknownHostException ignored) { System.out.println("Could not find ip address of \"default\" inteface."); } int rand = 0; try { rand = SecureRandom.getInstance("SHA1PRNG").nextInt(Integer.MAX_VALUE); } catch (NoSuchAlgorithmException e) { rand = (new Random()).nextInt(Integer.MAX_VALUE); } return "/Rack-" + rand + "-"+ ip + "-" + System.currentTimeMillis(); } }
public static String createNewStorageId(int port) { /* Return * "DS-randInt-ipaddr-currentTimeMillis" * It is considered extermely rare for all these numbers to match * on a different machine accidentally for the following * a) SecureRandom(INT_MAX) is pretty much random (1 in 2 billion), and * b) Good chance ip address would be different, and * c) Even on the same machine, Datanode is designed to use different ports. * d) Good chance that these are started at different times. * For a confict to occur all the 4 above have to match!. * The format of this string can be changed anytime in future without * affecting its functionality. */ String ip = "unknownIP"; try { ip = DNS.getDefaultIP("default"); } catch (UnknownHostException ignored) { LOG.warn("Could not find ip address of \"default\" inteface."); } int rand = 0; try { rand = SecureRandom.getInstance("SHA1PRNG").nextInt(Integer.MAX_VALUE); } catch (NoSuchAlgorithmException e) { LOG.warn("Could not use SecureRandom"); rand = R.nextInt(Integer.MAX_VALUE); } return "DS-" + rand + "-"+ ip + "-" + port + "-" + System.currentTimeMillis(); }
ip = DNS.getDefaultIP("default"); } catch (UnknownHostException ignored) { LOG.warn("Could not find ip address of \"default\" inteface.");
ip = DNS.getDefaultIP("default"); } catch (UnknownHostException ignored) { LOG.warn("Could not find ip address of \"default\" inteface.");
/** * Generate new blockpoolID. * * @return new blockpoolID */ static String newBlockPoolID() throws UnknownHostException{ String ip = "unknownIP"; try { ip = DNS.getDefaultIP("default"); } catch (UnknownHostException e) { LOG.warn("Could not find ip address of \"default\" inteface."); throw e; } int rand = DFSUtil.getSecureRandom().nextInt(Integer.MAX_VALUE); String bpid = "BP-" + rand + "-"+ ip + "-" + Time.now(); return bpid; }
/** * Generate new blockpoolID. * * @return new blockpoolID */ static String newBlockPoolID() throws UnknownHostException{ String ip = "unknownIP"; try { ip = DNS.getDefaultIP("default"); } catch (UnknownHostException e) { LOG.warn("Could not find ip address of \"default\" inteface."); throw e; } int rand = DFSUtil.getSecureRandom().nextInt(Integer.MAX_VALUE); String bpid = "BP-" + rand + "-"+ ip + "-" + Time.now(); return bpid; }
static private String getUniqueRackPrefix() { String ip = "unknownIP"; try { ip = DNS.getDefaultIP("default"); } catch (UnknownHostException ignored) { System.out.println("Could not find ip address of \"default\" inteface."); } int rand = DFSUtil.getSecureRandom().nextInt(Integer.MAX_VALUE); return "/Rack-" + rand + "-"+ ip + "-" + Time.now(); } }
/** * Test the "default" IP addresses is the local IP addr */ @Test public void testGetIPWithDefault() throws Exception { String[] ips = DNS.getIPs(DEFAULT); assertEquals("Should only return 1 default IP", 1, ips.length); assertEquals(getLocalIPAddr().getHostAddress(), ips[0].toString()); String ip = DNS.getDefaultIP(DEFAULT); assertEquals(ip, ips[0].toString()); }
/** * Test the "default" IP addresses is the local IP addr */ @Test public void testGetIPWithDefault() throws Exception { String[] ips = DNS.getIPs(DEFAULT); assertEquals("Should only return 1 default IP", 1, ips.length); assertEquals(getLocalIPAddr().getHostAddress(), ips[0].toString()); String ip = DNS.getDefaultIP(DEFAULT); assertEquals(ip, ips[0].toString()); }
/** * Test null interface name */ @Test public void testNullInterface() throws Exception { try { String host = DNS.getDefaultHost(null); fail("Expected a NullPointerException, got " + host); } catch (NullPointerException npe) { // Expected } try { String ip = DNS.getDefaultIP(null); fail("Expected a NullPointerException, got " + ip); } catch (NullPointerException npe) { // Expected } }
/** * Test null interface name */ @Test public void testNullInterface() throws Exception { try { String host = DNS.getDefaultHost(null); fail("Expected a NullPointerException, got " + host); } catch (NullPointerException npe) { // Expected } try { String ip = DNS.getDefaultIP(null); fail("Expected a NullPointerException, got " + ip); } catch (NullPointerException npe) { // Expected } }
void register() throws IOException { // get versions from the namenode nsInfo = nameNodeProto.versionRequest(); dnRegistration = new DatanodeRegistration( new DatanodeID(DNS.getDefaultIP("default"), DNS.getDefaultHost("default", "default"), DataNode.generateUuid(), getNodePort(dnIdx), DFSConfigKeys.DFS_DATANODE_HTTP_DEFAULT_PORT, DFSConfigKeys.DFS_DATANODE_HTTPS_DEFAULT_PORT, DFSConfigKeys.DFS_DATANODE_IPC_DEFAULT_PORT), new DataStorage(nsInfo), new ExportedBlockKeys(), VersionInfo.getVersion()); // register datanode dnRegistration = dataNodeProto.registerDatanode(dnRegistration); dnRegistration.setNamespaceInfo(nsInfo); //first block reports storage = new DatanodeStorage(DatanodeStorage.generateUuid()); final StorageBlockReport[] reports = { new StorageBlockReport(storage, BlockListAsLongs.EMPTY) }; dataNodeProto.blockReport(dnRegistration, bpid, reports, new BlockReportContext(1, 0, System.nanoTime())); }