Example usage for java.net InetAddress getCanonicalHostName

List of usage examples for java.net InetAddress getCanonicalHostName

Introduction

In this page you can find the example usage for java.net InetAddress getCanonicalHostName.

Prototype

public String getCanonicalHostName() 

Source Link

Document

Gets the fully qualified domain name for this IP address.

Usage

From source file:org.mule.test.firewall.FirewallTestCase.java

protected String addressToString(InetAddress address) {
    return address.getHostName() + "/" + address.getCanonicalHostName() + "/" + address.getHostAddress();
}

From source file:org.apache.kylin.job.cube.CubingJob.java

@Override
protected Pair<String, String> formatNotifications(ExecutableState state) {
    final Output output = jobService.getOutput(getId());
    String logMsg;// w  ww .jav  a2 s.co  m
    switch (output.getState()) {
    case ERROR:
        logMsg = output.getVerboseMsg();
        break;
    case DISCARDED:
        logMsg = "";
        break;
    case SUCCEED:
        logMsg = "";
        break;
    default:
        return null;
    }
    String content = ExecutableConstants.NOTIFY_EMAIL_TEMPLATE;
    content = content.replaceAll("\\$\\{job_name\\}", getName());
    content = content.replaceAll("\\$\\{result\\}", state.toString());
    content = content.replaceAll("\\$\\{cube_name\\}", getCubeName());
    content = content.replaceAll("\\$\\{start_time\\}", new Date(getStartTime()).toString());
    content = content.replaceAll("\\$\\{duration\\}", getDuration() / 60000 + "mins");
    content = content.replaceAll("\\$\\{mr_waiting\\}", getMapReduceWaitTime() / 60000 + "mins");
    content = content.replaceAll("\\$\\{last_update_time\\}", new Date(getLastModified()).toString());
    content = content.replaceAll("\\$\\{submitter\\}", getSubmitter());
    content = content.replaceAll("\\$\\{error_log\\}", logMsg);

    try {
        InetAddress inetAddress = InetAddress.getLocalHost();
        content = content.replaceAll("\\$\\{job_engine\\}", inetAddress.getCanonicalHostName());
    } catch (UnknownHostException e) {
        logger.warn(e.getLocalizedMessage(), e);
    }

    String title = "[" + state.toString() + "] - [Kylin Cube Build Job]-" + getCubeName();
    return Pair.of(title, content);
}

From source file:org.mule.module.management.mbean.MuleService.java

public MuleService(MuleContext muleContext) {
    this.muleContext = muleContext;
    String patch = System.getProperty("sun.os.patch.level", null);
    jdk = System.getProperty("java.version") + " (" + System.getProperty("java.vm.info") + ")";
    os = System.getProperty("os.name");
    if (patch != null && !"unknown".equalsIgnoreCase(patch)) {
        os += " - " + patch;
    }/*from  ww w.  ja va  2  s  .co  m*/
    os += " (" + System.getProperty("os.version") + ", " + System.getProperty("os.arch") + ")";

    buildNumber = MuleManifest.getBuildNumber();
    buildDate = MuleManifest.getBuildDate();
    try {
        InetAddress iad = InetAddress.getLocalHost();
        host = iad.getCanonicalHostName();
        ip = iad.getHostAddress();
    } catch (UnknownHostException e) {
        // ignore
    }
}

From source file:org.mule.test.firewall.FirewallTestCase.java

protected String name(InetAddress address, boolean canonical) {
    if (canonical) {
        return address.getCanonicalHostName();
    } else {//from   www  .  j av a 2 s .c o  m
        return address.getHostName();
    }
}

From source file:org.mule.test.firewall.FirewallTestCase.java

@Test
public void testCanonicalHost() throws Exception {
    InetAddress aLocalAddress = InetAddress.getLocalHost();
    assertNotSame("No extrernal name", LOCALHOST, aLocalAddress.getCanonicalHostName());
    consistentAddress(aLocalAddress.getCanonicalHostName(), true);
}

From source file:com.chicm.cmraft.core.ClusterMemberManager.java

private void initLocalAddresses() {
    try {//from  ww  w.j a  va2 s.  c  om
        Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
        while (interfaces.hasMoreElements()) {
            NetworkInterface inet = (NetworkInterface) interfaces.nextElement();
            Enumeration<InetAddress> addrs = inet.getInetAddresses();
            while (addrs.hasMoreElements()) {
                InetAddress addr = (InetAddress) addrs.nextElement();
                LOG.debug("local address:" + addr.getHostAddress());
                LOG.debug("local address:" + addr.getHostName());
                if (!addr.getHostAddress().isEmpty()) {
                    localAddresses.add(addr.getHostAddress());
                }
                if (!addr.getHostName().isEmpty()) {
                    localAddresses.add(addr.getHostName());
                }
            }
        }

        InetAddress inetAddress = InetAddress.getLocalHost();
        localAddresses.add(inetAddress.getHostAddress());
        localAddresses.add(inetAddress.getCanonicalHostName());
        localAddresses.add(inetAddress.getHostName());

        inetAddress = InetAddress.getLoopbackAddress();
        localAddresses.add(inetAddress.getHostAddress());
        localAddresses.add(inetAddress.getCanonicalHostName());
        localAddresses.add(inetAddress.getHostName());
    } catch (SocketException | UnknownHostException e) {
        LOG.error("", e);
    }
}

From source file:org.sipfoundry.preflight.NTP.java

public ResultCode validate(int timeout, NetworkResources networkResources, JournalService journalService,
        InetAddress bindAddress) {
    ResultCode results = NONE;//from   w  w w  . j a v  a  2  s. c om

    if (networkResources.ntpServers == null) {
        journalService.println("No NTP servers provided, skipping test.");
        results = NTP_SERVERS_MISSING;
    } else {
        journalService.println("Starting NTP servers test.");
        NTPUDPClient client = new NTPUDPClient();
        client.setDefaultTimeout(timeout * 1000);
        try {
            client.open(bindPort, bindAddress);

            for (InetAddress ntpServer : networkResources.ntpServers) {
                journalService.println("NTP test for server: " + ntpServer.getCanonicalHostName());
                try {
                    TimeInfo info = client.getTime(ntpServer);
                    journalService.println(new String(processResponse(info)));
                } catch (IOException e) {
                    client.close();
                    if (e.getClass() == java.net.SocketTimeoutException.class) {
                        journalService.println("  NTP request timed out.");
                        results = NTP_SERVER_FAILURE;
                    } else {
                        journalService.println("  NTP request error: " + e.getMessage());
                        results = NTP_TEST_FAILURE;
                    }
                }
            }
        } catch (SocketException e) {
            journalService.println("Unable to create NTP client: " + e.getMessage());
            results = NTP_TEST_FAILURE;
        }
    }

    journalService.println("");
    return results;
}

From source file:org.apache.qpid.server.security.access.firewall.HostnameFirewallRule.java

/**
 * @param remote//  www  .jav a 2s.com
 *            the InetAddress to look up
 * @return the hostname, null if not found, takes longer than
 *         {@value #DNS_LOOKUP} to find or otherwise fails
 */
private String getHostname(final InetAddress remote) throws AccessControlFirewallException {
    FutureTask<String> lookup = new FutureTask<String>(new Callable<String>() {
        public String call() {
            return remote.getCanonicalHostName();
        }
    });
    DNS_LOOKUP.execute(lookup);

    try {
        return lookup.get(DNS_TIMEOUT, TimeUnit.MILLISECONDS);
    } catch (Exception e) {
        _logger.warn("Unable to look up hostname from address " + remote, e);
        return null;
    } finally {
        lookup.cancel(true);
    }
}

From source file:org.hyperic.plugin.vrealize.automation.DiscoveryVRAManagerServer.java

private Resource getCommonModel(ServerResource server, String vraApplicationEndPointFqdn,
        String vraManagerDatabaseServerFqdn) {

    ObjectFactory factory = new ObjectFactory();

    Resource vraApplication = factory.createApplicationResource(TYPE_VRA_APPLICATION,
            vraApplicationEndPointFqdn);
    vraApplication.addProperty(factory.createProperty(KEY_APPLICATION_NAME, vraApplicationEndPointFqdn));

    Resource vraManagerServersGroup = factory.createLogicalResource(TYPE_VRA_MANAGER_SERVER_TAG,
            vraApplicationEndPointFqdn);

    Resource vraManagerServer = factory.createResource(!CREATE_IF_NOT_EXIST, server.getType(), server.getName(),
            ResourceTier.SERVER);//from w  ww. ja v a2  s  .c o m

    Resource vraDatabasesGroup = factory.createLogicalResource(TYPE_VRA_DATABASES_GROUP,
            vraApplicationEndPointFqdn);

    vraDatabasesGroup.addRelations(factory.createRelation(vraApplication, RelationType.PARENT));

    // If database server resides on this machine then skip it to avoid cyclic reference
    Resource databaseServerHost = factory.createResource(!CREATE_IF_NOT_EXIST, VraConstants.TYPE_WINDOWS,
            vraManagerDatabaseServerFqdn, ResourceTier.PLATFORM);
    databaseServerHost.addRelations(factory.createRelation(vraDatabasesGroup, RelationType.PARENT));

    InetAddress addr = null;
    String hostname = null;
    try {
        addr = InetAddress.getLocalHost();
        hostname = addr.getCanonicalHostName();
    } catch (UnknownHostException e) {
        log.error(e.getMessage(), e);
        hostname = getFqdn("localhost");
        log.debug(String.format("[getCommonModel] hostname is: '%s'", hostname));
    }

    if (!VRAUtils.areFqdnsEquivalent(hostname, vraManagerDatabaseServerFqdn)) {
        vraManagerServer.addRelations(factory.createRelation(databaseServerHost,
                VRAUtils.getDataBaseRalationType(vraManagerDatabaseServerFqdn)));
    } else {
        log.debug(String.format("not mapping DB server because '%s' is equivalent to '%s", hostname,
                vraManagerDatabaseServerFqdn));
    }

    vraManagerServer.addRelations(factory.createRelation(vraManagerServersGroup, RelationType.PARENT));

    vraManagerServersGroup.addRelations(factory.createRelation(vraApplication, RelationType.PARENT));

    return vraManagerServer;
}

From source file:org.apache.lens.client.SpnegoClientFilter.java

private String getCanonicalHostname(String hostname) {
    String canonicalHostname = hostname;
    try {/*from w ww.  j a v  a 2 s  . c o m*/
        InetAddress in = InetAddress.getByName(hostname);
        canonicalHostname = in.getCanonicalHostName();
        log.debug("resolved hostname=" + hostname + " to canonicalHostname=" + canonicalHostname);
    } catch (Exception e) {
        log.warn("unable to resolve canonical hostname", e);
    }
    return canonicalHostname;
}