List of usage examples for com.google.common.net InetAddresses toAddrString
public static String toAddrString(InetAddress ip)
From source file:org.apache.hadoop.hdfs.qjournal.client.IPCLoggerChannel.java
@Override public String toString() { return InetAddresses.toAddrString(addr.getAddress()) + ':' + addr.getPort(); }
From source file:org.opendaylight.openflowplugin.legacy.sal.compatibility.MDFlowMapping.java
public static Address toInetAddress(final InetAddress address) { if (address instanceof Inet4Address) { return new Ipv4Builder().setIpv4Address(new Ipv4Prefix(InetAddresses.toAddrString(address) + "/32")) .build();//from ww w . j av a 2 s . co m } if (address instanceof Inet6Address) { return new Ipv6Builder().setIpv6Address(new Ipv6Prefix(InetAddresses.toAddrString(address) + "/128")) .build(); } throw new IllegalArgumentException(String.format("Unhandled address class %s", address.getClass())); }
From source file:org.opendaylight.controller.sal.compatibility.MDFlowMapping.java
public static Address toInetAddress(final InetAddress address) { if (address instanceof Inet4Address) { return new Ipv4Builder().setIpv4Address(new Ipv4Prefix(InetAddresses.toAddrString(address))).build(); }/*from w w w . j a v a2 s . c om*/ if (address instanceof Inet6Address) { return new Ipv6Builder().setIpv6Address(new Ipv6Prefix(InetAddresses.toAddrString(address))).build(); } throw new IllegalArgumentException(String.format("Unhandled address class %s", address.getClass())); }
From source file:com.gemini.provision.network.openstack.NetworkProviderOpenStackImpl.java
@Override public ProvisioningProviderResponseType createSubnet(GeminiTenant tenant, GeminiEnvironment env, GeminiNetwork parent, GeminiSubnet newSubnet) { //authenticate the session with the OpenStack installation OSClient os = OSFactory.builder().endpoint(env.getEndPoint()) .credentials(env.getAdminUserName(), env.getAdminPassword()).tenantName(tenant.getName()) .authenticate();//from w ww. j av a 2 s .c om if (os == null) { Logger.error("Failed to authenticate Tenant: {}", ToStringBuilder.reflectionToString(tenant, ToStringStyle.MULTI_LINE_STYLE)); return null; } //check to see if the parenet network exists Network osParent; try { osParent = os.networking().network().list().stream() .filter(osn -> osn.getName().equals(parent.getName())).findFirst().get(); parent.setCloudID(osParent.getId()); //just in case... } catch (NoSuchElementException ex) { Logger.error( "Failed to create subnet - parent network does not exist. Tenant: {} Environment: {} network: {} subnet: {}", tenant.getName(), env.getName(), parent.getName(), newSubnet.getName()); return ProvisioningProviderResponseType.CLOUD_NO_PARENT; } //check to see if this subnet exists if (os.networking().subnet().list().stream().anyMatch(n -> n.getName().equals(newSubnet.getName()))) { Logger.error( "Failed to create subnet - already exists. Tenant: {} Environment: {} network: {} subnet: {}", tenant.getName(), env.getName(), parent.getName(), newSubnet.getName()); return ProvisioningProviderResponseType.OBJECT_EXISTS; } //create the subnet Subnet subnet; try { subnet = os.networking().subnet().create(Builders.subnet().tenantId(tenant.getTenantID()) .gateway(InetAddresses.toAddrString(newSubnet.getGateway())) .enableDHCP(newSubnet.isEnableDHCP()) .ipVersion( newSubnet.getNetworkType() == IPAddressType.IPv6 ? IPVersionType.V6 : IPVersionType.V4) .name(newSubnet.getName()).networkId(parent.getCloudID()).cidr(newSubnet.getCidr()).build()); } catch (ClientResponseException ex) { Logger.error( "Cloud exception: failed to create subnet. status code {} tenant: {} env: {} parent network: {} subnet {} ", ex.getStatusCode(), tenant.getName(), env.getName(), parent.getName(), newSubnet.getName()); return ProvisioningProviderResponseType.CLOUD_EXCEPTION; } //add the list of subnets (this will be an update the subnet just created) List<GeminiSubnetAllocationPool> pools = newSubnet.getAllocationPools(); pools.stream().forEach(p -> { if (os.networking().subnet().update(subnet.toBuilder() .addPool(p.getStart().getHostAddress(), p.getEnd().getHostAddress()).build()) == null) { Logger.error( "Failed to create subnet allocation pool, Tenant: {} Environment: {} Parent Network: {} Subnet: {} Allocation Pool {} {}", tenant.getName(), env.getName(), parent.getName(), newSubnet.getName(), p.getStart().getHostAddress(), p.getEnd().getHostAddress()); } }); //copy the id to the domain object newSubnet.setCloudID(subnet.getId()); Logger.debug("Successfully added network - tenant: {} env: {} parent network: {} subnet {} ", tenant.getName(), env.getName(), parent.getName(), newSubnet.getName()); return ProvisioningProviderResponseType.SUCCESS; }
From source file:google.registry.rdap.RdapJsonFormatter.java
/** * Creates a JSON object for a {@link HostResource}. * * @param hostResource the host resource object from which the JSON object should be created * @param isTopLevel if true, the top-level boilerplate will be added * @param linkBase the URL base to be used when creating links * @param whoisServer the fully-qualified domain name of the WHOIS server to be listed in the * port43 field; if null, port43 is not added to the object * @param now the as-date//from w w w. j a v a 2 s. co m * @param outputDataType whether to generate full or summary data */ ImmutableMap<String, Object> makeRdapJsonForHost(HostResource hostResource, boolean isTopLevel, @Nullable String linkBase, @Nullable String whoisServer, DateTime now, OutputDataType outputDataType) { ImmutableMap.Builder<String, Object> jsonBuilder = new ImmutableMap.Builder<>(); jsonBuilder.put("objectClassName", "nameserver"); jsonBuilder.put("handle", hostResource.getRepoId()); jsonBuilder.put("ldhName", hostResource.getFullyQualifiedHostName()); // Only include the unicodeName field if there are unicode characters. if (hasUnicodeComponents(hostResource.getFullyQualifiedHostName())) { jsonBuilder.put("unicodeName", Idn.toUnicode(hostResource.getFullyQualifiedHostName())); } jsonBuilder.put("status", makeStatusValueList(hostResource.getStatusValues())); jsonBuilder.put("links", ImmutableList.of(makeLink("nameserver", hostResource.getFullyQualifiedHostName(), linkBase))); List<ImmutableMap<String, Object>> remarks; // If we are outputting all data (not just summary data), also add events taken from the history // entries. If we are outputting summary data, instead add a remark indicating that fact. if (outputDataType == OutputDataType.SUMMARY) { remarks = ImmutableList.of(RdapIcannStandardInformation.SUMMARY_DATA_REMARK); } else { remarks = ImmutableList.of(); ImmutableList<Object> events = makeEvents(hostResource, now); if (!events.isEmpty()) { jsonBuilder.put("events", events); } } ImmutableSet<InetAddress> inetAddresses = hostResource.getInetAddresses(); if (!inetAddresses.isEmpty()) { ImmutableList.Builder<String> v4AddressesBuilder = new ImmutableList.Builder<>(); ImmutableList.Builder<String> v6AddressesBuilder = new ImmutableList.Builder<>(); for (InetAddress inetAddress : inetAddresses) { if (inetAddress instanceof Inet4Address) { v4AddressesBuilder.add(InetAddresses.toAddrString(inetAddress)); } else if (inetAddress instanceof Inet6Address) { v6AddressesBuilder.add(InetAddresses.toAddrString(inetAddress)); } } ImmutableMap.Builder<String, ImmutableList<String>> ipAddressesBuilder = new ImmutableMap.Builder<>(); ImmutableList<String> v4Addresses = v4AddressesBuilder.build(); if (!v4Addresses.isEmpty()) { ipAddressesBuilder.put("v4", Ordering.natural().immutableSortedCopy(v4Addresses)); } ImmutableList<String> v6Addresses = v6AddressesBuilder.build(); if (!v6Addresses.isEmpty()) { ipAddressesBuilder.put("v6", Ordering.natural().immutableSortedCopy(v6Addresses)); } ImmutableMap<String, ImmutableList<String>> ipAddresses = ipAddressesBuilder.build(); if (!ipAddresses.isEmpty()) { jsonBuilder.put("ipAddresses", ipAddressesBuilder.build()); } } if (whoisServer != null) { jsonBuilder.put("port43", whoisServer); } if (isTopLevel) { addTopLevelEntries(jsonBuilder, BoilerplateType.NAMESERVER, remarks, ImmutableList.<ImmutableMap<String, Object>>of(), linkBase); } else if (!remarks.isEmpty()) { jsonBuilder.put(REMARKS, remarks); } return jsonBuilder.build(); }
From source file:com.gemini.provision.network.openstack.NetworkProviderOpenStackImpl.java
@Override public ProvisioningProviderResponseType updateSubnet(GeminiTenant tenant, GeminiEnvironment env, GeminiSubnet subnet) {/*from ww w. j ava 2s .c o m*/ //authenticate the session with the OpenStack installation OSClient os = OSFactory.builder().endpoint(env.getEndPoint()) .credentials(env.getAdminUserName(), env.getAdminPassword()).tenantName(tenant.getName()) .authenticate(); if (os == null) { Logger.error("Failed to authenticate Tenant: {}", ToStringBuilder.reflectionToString(tenant, ToStringStyle.MULTI_LINE_STYLE)); return null; } // Get a subnet by ID Subnet s = os.networking().subnet().get(subnet.getCloudID()); if (s == null) { Logger.error("Failed to update subnet - doesn't exist. Tenant: {} Environment: {} Sbunet: {}", tenant.getName(), env.getName(), ToStringBuilder.reflectionToString(subnet, ToStringStyle.MULTI_LINE_STYLE)); return ProvisioningProviderResponseType.OBJECT_NOT_FOUND; } //update the subnet Subnet updatedSubnet; try { updatedSubnet = os.networking().subnet().update(s.toBuilder().tenantId(tenant.getTenantID()) .cidr(subnet.getCidr()).name(subnet.getName()) .gateway(InetAddresses.toAddrString(subnet.getGateway())) .networkId(subnet.getParent().getCloudID()).enableDHCP(subnet.isEnableDHCP()) .ipVersion(subnet.getNetworkType() == IPAddressType.IPv6 ? IPVersionType.V6 : IPVersionType.V4) .build()); } catch (ClientResponseException ex) { Logger.error("Cloud exception: status code {}", ex.getStatusCode()); return ProvisioningProviderResponseType.CLOUD_EXCEPTION; } //TODO: Need to get detailed error codes for the call above. Research the StatusCode class if (updatedSubnet == null) { Logger.error( "Failed to update subnet, Cloud provider failure. Tenant: {} Environment: {} Parent Network: {} Subnet: {} ", tenant.getName(), env.getName(), subnet.getParent().getName(), subnet.getName()); return ProvisioningProviderResponseType.CLOUD_FAILURE; } //add the list of subnets (this will be an update the subnet just created) List<GeminiSubnetAllocationPool> pools = subnet.getAllocationPools(); pools.stream().forEach(p -> { if (os.networking().subnet().update(updatedSubnet.toBuilder() .addPool(p.getStart().getHostAddress(), p.getEnd().getHostAddress()).build()) == null) { Logger.error( "Failed to create subnet allocation pool, Tenant: {} Environment: {} Parent Network: {} Subnet: {} Allocation Pool {} {}", tenant.getName(), env.getName(), subnet.getParent().getName(), subnet.getName(), p.getStart().getHostAddress(), p.getEnd().getHostAddress()); } }); Logger.debug("Successfully updated the subnet. Tenant: {} Environment: {} Parent Network: {} Subnet: {}", tenant.getName(), env.getName(), subnet.getParent().getName(), subnet.getName()); return ProvisioningProviderResponseType.SUCCESS; }
From source file:org.elassandra.cluster.InternalCassandraClusterService.java
private static Object toJsonValue(Object o) { if (o instanceof UUID) return o.toString(); if (o instanceof Date) return ((Date) o).getTime(); if (o instanceof ByteBuffer) { // encode byte[] as Base64 encoded string ByteBuffer bb = ByteBufferUtil.clone((ByteBuffer) o); CharBuffer encoded = CharBuffer.allocate(4 * (bb.capacity() + 2) / 3); Base64.encode(bb, encoded);/*from w w w . j ava2s . c om*/ encoded.position(0); return encoded.toString(); } if (o instanceof InetAddress) return InetAddresses.toAddrString((InetAddress) o); return o; }
From source file:org.dcache.ftp.door.Help.java
protected void replyDelayedPassive(CommandRequest request, DelayedPassiveReply format, InetSocketAddress socketAddress) { InetAddress address = socketAddress.getAddress(); Protocol protocol = Protocol.fromAddress(address); switch (format) { case NONE://from ww w . j a v a 2 s . co m break; case PASV: checkArgument(protocol == Protocol.IPV4, "PASV required IPv4 data channel."); int port = socketAddress.getPort(); byte[] host = address.getAddress(); reply(request, String.format("127 PORT (%d,%d,%d,%d,%d,%d)", (host[0] & 0377), (host[1] & 0377), (host[2] & 0377), (host[3] & 0377), (port / 256), (port % 256))); break; case EPSV: reply(request, String.format("129 Entering Extended Passive Mode (|%d|%s|%d|)", protocol.getCode(), InetAddresses.toAddrString(address), socketAddress.getPort())); break; } }