Refine search
@Override public InetAddress toInetAddress(String hostOrAddress) throws UnknownHostException { if (InetAddresses.isInetAddress(hostOrAddress)) { return InetAddresses.forString(hostOrAddress); } return InetAddress.getByName(hostOrAddress); }
@Override public Object getObjectValue(ConnectorSession session, Block block, int position) { if (block.isNull(position)) { return null; } try { return InetAddresses.toAddrString(InetAddress.getByAddress(block.getSlice(position, 0, getFixedSize()).getBytes())); } catch (UnknownHostException e) { throw new IllegalArgumentException(); } }
public void testToUriStringIPv4() { String ipStr = "1.2.3.4"; InetAddress ip = InetAddresses.forString(ipStr); assertEquals("1.2.3.4", InetAddresses.toUriString(ip)); }
/** * Returns the IPv4 address embedded in an IPv4 compatible address. * * @param ip {@link Inet6Address} to be examined for an embedded IPv4 address * @return {@link Inet4Address} of the embedded IPv4 address * @throws IllegalArgumentException if the argument is not a valid IPv4 compatible address */ public static Inet4Address getCompatIPv4Address(Inet6Address ip) { checkArgument( isCompatIPv4Address(ip), "Address '%s' is not IPv4-compatible.", toAddrString(ip)); return getInet4Address(Arrays.copyOfRange(ip.getAddress(), 12, 16)); }
/** * Returns the IPv4 address embedded in an ISATAP address. * * @param ip {@link Inet6Address} to be examined for embedded IPv4 in ISATAP address * @return {@link Inet4Address} of embedded IPv4 in an ISATAP address * @throws IllegalArgumentException if the argument is not a valid IPv6 ISATAP address */ public static Inet4Address getIsatapIPv4Address(Inet6Address ip) { checkArgument(isIsatapAddress(ip), "Address '%s' is not an ISATAP address.", toAddrString(ip)); return getInet4Address(Arrays.copyOfRange(ip.getAddress(), 12, 16)); }
/** * Returns the IPv4 address embedded in a 6to4 address. * * @param ip {@link Inet6Address} to be examined for embedded IPv4 in 6to4 address * @return {@link Inet4Address} of embedded IPv4 in 6to4 address * @throws IllegalArgumentException if the argument is not a valid IPv6 6to4 address */ public static Inet4Address get6to4IPv4Address(Inet6Address ip) { checkArgument(is6to4Address(ip), "Address '%s' is not a 6to4 address.", toAddrString(ip)); return getInet4Address(Arrays.copyOfRange(ip.getAddress(), 2, 6)); }
@Test public void testFqdnDiscovery() throws UnknownHostException { NodeInfo nodeInfo = new NodeInfo(ENVIRONMENT, POOL, "nodeInfo", null, null, null, null, null, null, FQDN); assertNotNull(nodeInfo.getInternalAddress()); assertEquals(nodeInfo.getBindIp(), InetAddresses.forString("0.0.0.0")); assertEquals(nodeInfo.getExternalAddress(), InetAddress.getLocalHost().getCanonicalHostName()); }
@Test public void testBasicNodeInfo() { long testStartTime = System.currentTimeMillis(); String nodeId = "nodeId"; String location = "location"; String binarySpec = "binary"; String configSpec = "config"; InetAddress internalIp = InetAddresses.forString("10.0.0.22"); InetAddress bindIp = InetAddresses.forString("10.0.0.33"); String externalAddress = "external"; NodeInfo nodeInfo = new NodeInfo(ENVIRONMENT, POOL, nodeId, internalIp, bindIp, externalAddress, location, binarySpec, configSpec); Assert.assertEquals(nodeInfo.getEnvironment(), ENVIRONMENT); Assert.assertEquals(nodeInfo.getPool(), POOL); Assert.assertEquals(nodeInfo.getNodeId(), nodeId); Assert.assertEquals(nodeInfo.getLocation(), location); Assert.assertEquals(nodeInfo.getBinarySpec(), binarySpec); Assert.assertEquals(nodeInfo.getConfigSpec(), configSpec); Assert.assertNotNull(nodeInfo.getInstanceId()); Assertions.assertNotEquals(nodeInfo.getNodeId(), nodeInfo.getInstanceId()); Assert.assertEquals(nodeInfo.getInternalIp(), internalIp); Assert.assertEquals(nodeInfo.getExternalAddress(), externalAddress); Assert.assertEquals(nodeInfo.getBindIp(), bindIp); Assertions.assertGreaterThanOrEqual(nodeInfo.getStartTime(), testStartTime); // make sure toString doesn't throw an exception Assert.assertNotNull(nodeInfo.toString()); }
private String findPublicHostname() { try { return InetAddress.getLocalHost().getHostName().toLowerCase(); } catch (UnknownHostException e) { // Java 7u5 and later on MacOS sometimes throws this unless the local hostname is in DNS // or hosts file. The exception message is the hostname followed by a colon and an error message. final Matcher matcher = HOST_EXCEPTION_MESSAGE_PATTERN.matcher(e.getMessage()); if (matcher.matches()) { return matcher.group(1).toLowerCase(); } return InetAddresses.toUriString(internalIp); } } }
public static void localBoundIP(String localBoundIP) { System.setProperty(MOCKSERVER_LOCAL_BOUND_IP, InetAddresses.forString(localBoundIP).getHostAddress()); }
@Test public void testDefaultAddresses() { NodeInfo nodeInfo = new NodeInfo(ENVIRONMENT, POOL, "nodeInfo", InetAddresses.forString("10.0.0.22"), null, null, null, null, null); Assert.assertEquals(nodeInfo.getExternalAddress(), "10.0.0.22"); Assert.assertEquals(nodeInfo.getBindIp(), InetAddresses.forString("0.0.0.0")); }
private static String findInternalAddress(AddressSource addressSource) { switch (addressSource) { case IP: return InetAddresses.toAddrString(findInternalIp()); case HOSTNAME: return getLocalHost().getHostName(); case FQDN: return getLocalHost().getCanonicalHostName(); default: throw new IllegalArgumentException(); } }
@Test public void testCreateNodeWithGroupEncodedIntoNameThenStoreCredentials() { String group = "foo"; String name = "node" + new Random().nextInt(); Template template = templateBuilder.build(); // test passing custom options template.getOptions().as(SoftLayerTemplateOptions.class).domainName("me.org"); guest = adapter.createNodeWithGroupEncodedIntoName(group, name, template); assertEquals(guest.getNode().getHostname(), name); assertEquals(guest.getNodeId(), guest.getNode().getId() + ""); assertEquals(guest.getNode().getDomain(), template.getOptions().as(SoftLayerTemplateOptions.class) .getDomainName()); assert InetAddresses.isInetAddress(guest.getNode().getPrimaryBackendIpAddress()) : guest; doConnectViaSsh(guest.getNode(), prioritizeCredentialsFromTemplate.apply(template, guest.getCredentials())); }
assertTrue(InetAddresses.isMappedIPv4Address(mappedStr)); InetAddress mapped = InetAddresses.forString(mappedStr); assertThat(mapped).isNotInstanceOf(Inet6Address.class); assertEquals(InetAddress.getByName("192.168.0.1"), mapped); assertTrue(InetAddresses.isMappedIPv4Address(mappedStr)); mapped = InetAddresses.forString(mappedStr); assertThat(mapped).isNotInstanceOf(Inet6Address.class); assertEquals(InetAddress.getByName("192.168.0.1"), mapped); assertTrue(InetAddresses.isMappedIPv4Address(mappedStr)); mapped = InetAddresses.forString(mappedStr); assertThat(mapped).isNotInstanceOf(Inet6Address.class); assertEquals(InetAddress.getByName("1.2.3.4"), mapped); assertTrue(InetAddresses.isMappedIPv4Address(mappedStr)); mapped = InetAddresses.forString(mappedStr); assertThat(mapped).isNotInstanceOf(Inet6Address.class); assertEquals(InetAddress.getByName("1.2.3.4"), mapped); assertFalse(InetAddresses.isMappedIPv4Address("::")); assertFalse(InetAddresses.isMappedIPv4Address("::ffff")); assertFalse(InetAddresses.isMappedIPv4Address("::ffff:0")); assertFalse(InetAddresses.isMappedIPv4Address("::fffe:0:0")); assertFalse(InetAddresses.isMappedIPv4Address("::1:ffff:0:0")); assertFalse(InetAddresses.isMappedIPv4Address("foo")); assertFalse(InetAddresses.isMappedIPv4Address("192.0.2.1"));
@ValidatorMethod @SuppressWarnings("unused") public void validateHttpBindAddress() throws ValidationException { try { final String host = getHttpBindAddress().getHost(); if (!InetAddresses.isInetAddress(host)) { final InetAddress inetAddress = InetAddress.getByName(host); } } catch (IllegalArgumentException | UnknownHostException e) { throw new ValidationException(e); } }
@Test public void testAddressDiscovery() { NodeInfo nodeInfo = new NodeInfo(ENVIRONMENT, POOL, "nodeInfo", null, null, null, null, null, null); Assert.assertNotNull(nodeInfo.getInternalIp()); Assert.assertEquals(nodeInfo.getBindIp(), InetAddresses.forString("0.0.0.0")); Assert.assertEquals(nodeInfo.getExternalAddress(), InetAddresses.toAddrString(nodeInfo.getInternalIp())); }
protected static String getLocalPoolName(String poolName) { if (BLADE_ID == null) { try { BLADE_ID = InetAddresses.coerceToInteger(InetAddress.getLocalHost()); } catch (UnknownHostException e) { LOGGER.error("ResourceManager - Exception - {}", e); } } return poolName + "." + BLADE_ID; }
public static String toString(InetAddress a) { String name = a.getHostName(); if (InetAddresses.isInetAddress(name)) { return InetAddresses.toAddrString(a); } else { return name + "/" + InetAddresses.toUriString(a); } }
private static void insertTestData(CassandraSession session, SchemaTableName table, Date date, int rowsCount) { for (Integer rowNumber = 1; rowNumber <= rowsCount; rowNumber++) { Insert insert = QueryBuilder.insertInto(table.getSchemaName(), table.getTableName()) .value("key", "key " + rowNumber.toString()) .value("typeuuid", UUID.fromString(String.format("00000000-0000-0000-0000-%012d", rowNumber))) .value("typeinteger", rowNumber) .value("typelong", rowNumber.longValue() + 1000) .value("typebytes", ByteBuffer.wrap(Ints.toByteArray(rowNumber)).asReadOnlyBuffer()) .value("typetimestamp", date) .value("typeansi", "ansi " + rowNumber) .value("typeboolean", rowNumber % 2 == 0) .value("typedecimal", new BigDecimal(Math.pow(2, rowNumber))) .value("typedouble", Math.pow(4, rowNumber)) .value("typefloat", (float) Math.pow(8, rowNumber)) .value("typeinet", InetAddresses.forString("127.0.0.1")) .value("typevarchar", "varchar " + rowNumber) .value("typevarint", BigInteger.TEN.pow(rowNumber)) .value("typetimeuuid", UUID.fromString(String.format("d2177dd0-eaa2-11de-a572-001b779c76e%d", rowNumber))) .value("typelist", ImmutableList.of("list-value-1" + rowNumber, "list-value-2" + rowNumber)) .value("typemap", ImmutableMap.of(rowNumber, rowNumber + 1L, rowNumber + 2, rowNumber + 3L)) .value("typeset", ImmutableSet.of(false, true)); session.execute(insert); } assertEquals(session.execute("SELECT COUNT(*) FROM " + table).all().get(0).getLong(0), rowsCount); } }
private static void assertAddressToLong(String address, long ip) { Inet4Address addr = (Inet4Address) InetAddresses.forString(address); assertEquals(Inet4Network.addressToLong(addr), ip); }