List of usage examples for java.net InetAddress getHostName
public String getHostName()
From source file:org.openqa.selenium.server.htmlrunner.DatabaseTestResults.java
public void write() throws IOException { // insert Database TestSuiteName String setname = "";// TODO - implement suite.getName()? String runId = productName.toUpperCase() + timestamp; String bTcDesc = System.getProperty("database.tc_desc", "false"); String username = System.getProperty("gitak.username", System.getProperty("user.name")); String hostname = System.getProperty("gitak.hostname"); if (hostname == null) { try {//from www. ja v a2 s.c om InetAddress addr = InetAddress.getLocalHost(); hostname = addr.getHostName(); } catch (UnknownHostException e) { e.printStackTrace(); } } if (this.getDbReportOption()) { this.connectDatabase(); String sqlstmt = "INSERT INTO tsi_tests_run(RUN_ID, HOSTNAME, PLATFORM, USER_NAME, " + "START_TIME, END_TIME, PRODUCT_NAME, PRODUCT_VERSION, PRODUCT_BUILD, CATEGORY, STATUS, " + "NUM_TC_STARTED, NUM_TC_PASSED, NUM_TC_FAILED, NUM_TC_MANUAL, NUM_TC_UNCERTAIN, LOG_URL, " + "NOTE, T_TESTS_VERSION) VALUES(" + "'" + runId + "', '" + hostname + "', '" + runtimePlatform + "', '" + username + "', " + //"to_date('" + formatDateTime(runTime) + "', 'yyyy/mm/dd-hh24:mi:ss'), " + " SYSDATE," + // "to_date('" + formatDateTime(null) + "', 'yyyy/mm/dd-hh24:mi:ss'), " + " SYSDATE," + " '" + productName + // PDMS predefine product acronym "', '" + productVersion + // Version id like 3.5.1.7 "', '" + productBuild + // Top level label, use full version id like 3.5.1V7 "', '" + dbCategory + // -Ddatabase.category=ui for PDMS UI test category "', 'COMPLETED', " + numTestTotal + ", " + numTestPasses + ", " + numTestFailures + ", 0, 0, '" + logUrl + "', null, '" + this.seleniumVersion + "' )"; qaSqlExecute(sqlstmt); if (testPassed.size() > 0) { String[] split = splitTestString(testPassed.get(0), "::"); setname = split[0]; } else if (testFailed.size() > 0) { String[] split = splitTestString(testFailed.get(0), "::"); setname = split[0]; } if (setname.length() > 27) { setname = setname.substring(0, 27); // set_name column size = 30 } log.info("Test Suite = " + setname); String sqlset = "INSERT INTO tsi_tests_set(RUN_ID, SEQ_NO, SET_NAME, OWNER," + "START_TIME, END_TIME, NUM_TC_STARTED, NUM_TC_PASSED, NUM_TC_FAILED, NUM_TC_MANUAL, NUM_TC_UNCERTAIN, LOG_URL, NOTE) " + " VALUES('" + runId + "', null, '" + setname + "', '" + username + "', " + //"to_date('" + formatDateTime(runTime) + "', 'yyyy/mm/dd-hh24:mi:ss'), " + " SYSDATE, SYSDATE, 0, 0, 0, 0, 0, null, null)"; qaSqlExecute(sqlset); for (String aTestFailed : testFailed) { String tfail = aTestFailed.replace("\u00a0", " "); // parse failed test string and insert to Database String[] values = splitTestString(tfail, "\\|"); if (values.length > 0) { String[] names = splitTestString(values[0], "::"); String testSet = names[0]; String testCase = names[1]; if (bTcDesc.equals("true") && names.length > 2) { String testDesc = names[2]; log.info("Test Desc -->" + testDesc); String descStmt = this.createSqlTestCaseDescription(testSet, testCase, testDesc); qaSqlExecute(descStmt); } qaSqlExecute(this.createSqlTestCaseStatement(runId, testSet, testCase, false, tfail)); } } for (String aTestPassed : testPassed) { String tpass = aTestPassed.replace("\u00a0", " "); String[] names = splitTestString(tpass, "::"); String testSet = names[0]; String testCase = names[1]; if (bTcDesc.equals("true") && names.length > 2) { String testDesc = names[2]; log.info("Test Desc -->" + testDesc); String descStmt = this.createSqlTestCaseDescription(testSet, testCase, testDesc); qaSqlExecute(descStmt); } String stmt = this.createSqlTestCaseStatement(runId, testSet, testCase, true, null); qaSqlExecute(stmt); } // Update runtime with actual elapsed time from posted result runTime.setTime(runTime.getTime() + this.getTotalTime()); // Updating test set/suite to close String updateSet = "update tsi_tests_set set seq_no=0, owner=''{0}'', end_time=to_date(''{1}'',''yyyy/mm/dd-hh24:mi:ss'')," + " num_tc_passed={2}, num_tc_failed={3} where run_id=''{4}'' and set_name=''{5}''"; // update ? log_url='' Object[] setVal = { username, formatDateTime(runTime), numTestPasses, numTestFailures, runId, setname }; qaSqlExecute(MessageFormat.format(updateSet, setVal)); // Updating test run to close String updateRun = "update tsi_tests_run set end_time=to_date(''{0}'',''yyyy/mm/dd-hh24:mi:ss''), status=''COMPLETED''," + " NUM_TC_PASSED={1}, NUM_TC_FAILED={2} where run_id = ''{3}''"; Object[] runVal = { formatDateTime(runTime), numTestPasses, numTestFailures, runId }; qaSqlExecute(MessageFormat.format(updateRun, runVal)); closeDatabase(); } // if this.getDbReportOption }
From source file:net.cit.tetrad.dao.management.impl.MainDaoImpl.java
private String getServerName() { String hostname = ""; try {/*w w w.j a v a2s. c om*/ InetAddress addr = InetAddress.getLocalHost(); // Get hostname hostname = addr.getHostName(); log.info("no error hostname:" + hostname); } catch (UnknownHostException e) { log.error(e, e); try { // Get hostname by textual representation of IP address InetAddress addr = InetAddress.getByName("127.0.0.1"); // /[127.0.0.1 is always localhost -dmw]/ // Get the host name from the address hostname = addr.getHostName(); // Get canonical host name String hostnameCanonical = addr.getCanonicalHostName(); log.info("hostname:" + hostname + " || hostnameCanonical:" + hostnameCanonical); } catch (UnknownHostException e2) { // handle exception log.error(e2, e2); } } return hostname; }
From source file:org.springframework.cloud.commons.util.InetUtils.java
public HostInfo convertAddress(final InetAddress address) { HostInfo hostInfo = new HostInfo(); Future<String> result = executorService.submit(new Callable<String>() { @Override/* w ww. j a va 2 s . c o m*/ public String call() throws Exception { return address.getHostName(); } }); String hostname; try { hostname = result.get(this.properties.getTimeoutSeconds(), TimeUnit.SECONDS); } catch (Exception e) { log.info("Cannot determine local hostname"); hostname = "localhost"; } hostInfo.setHostname(hostname); hostInfo.setIpAddress(address.getHostAddress()); return hostInfo; }
From source file:org.apereo.portal.PortalInfoProviderImpl.java
protected String getLocalHostName() { this.logger.info("Attempting to resolve serverName using InetAddress.getLocalHost()"); final InetAddress localhost; try {// ww w .ja v a2s. c o m localhost = InetAddress.getLocalHost(); } catch (UnknownHostException e) { logger.warn("Failed to find InetAddress for InetAddress.getLocalHost()", e); return null; } return localhost.getHostName(); }
From source file:org.dcm4chee.xds2.src.tool.pnrsnd.PnRSnd.java
private void send(PnRRequest pnrReq) throws MalformedURLException, MetadataConfigurationException { configTLS();/* w w w .ja va2s. c om*/ configTimeout(); URL xdsRepositoryURL = new URL(props.getProperty("URL")); RegistryResponseType rsp = client.sendProvideAndRegister(pnrReq, xdsRepositoryURL); InetAddress addr = AuditLogger.localHost(); String localhost = addr == null ? "localhost" : addr.getHostName();//DNS! XDSAudit.logSourceExport(pnrReq.getSubmissionSetUID(), pnrReq.getPatientID(), XDSConstants.WS_ADDRESSING_ANONYMOUS, AuditLogger.processID(), localhost, xdsRepositoryURL.toExternalForm(), xdsRepositoryURL.getHost(), XDSConstants.XDS_B_STATUS_SUCCESS.equals(rsp.getStatus())); log.info("Response:" + rsp.getStatus()); RegistryErrorList errors = rsp.getRegistryErrorList(); if (errors != null) { List<RegistryError> errList = errors.getRegistryError(); RegistryError err; for (int i = 0, len = errList.size(); i < len;) { err = errList.get(i); log.info("Error " + (++i) + ":"); log.info(" ErrorCode :" + err.getErrorCode()); log.info(" CodeContext:" + err.getCodeContext()); log.info(" Severity :" + err.getSeverity()); log.info(" Value :" + err.getValue()); log.info(" Location :" + err.getLocation()); } } }
From source file:org.hyperic.hq.plugin.rabbitmq.detect.RabbitServerDetector.java
/** * Create the server name/*ww w . j av a2 s .c om*/ * @param args * @return rabbit@host */ private String getServerName(String[] args) { String name = null; for (int n = 0; n < args.length; n++) { if (args[n].equalsIgnoreCase(DetectorConstants.SNAME)) { name = args[n + 1]; } } if ((name != null) && (!name.contains("@"))) { try { InetAddress addr = InetAddress.getLocalHost(); String hostname = addr.getHostName(); String old_name = name; name += "@" + hostname; name = name.substring(0, name.indexOf(".")); logger.debug(DetectorConstants.SNAME + "=" + old_name + " -> " + name); } catch (UnknownHostException ex) { name = null; logger.debug(ex.getMessage(), ex); } } return name; }
From source file:org.apache.hadoop.realtime.JobSubmitter.java
/** * Internal method for submitting jobs to the system. * //from w w w . j a v a2 s .c o m * <p>The job submission process involves: * <ol> * <li> * Checking the input and output specifications of the job. * </li> * <li> * Serializing the job description file for the job. * </li> * <li> * Setup the requisite accounting information for the * DistributedCache of the job, if necessary. * </li> * <li> * Copying the job's jar and configuration to the dragon system * directory on the distributed file-system. * </li> * <li> * Submitting the job to the {@link DragonJobService} and optionally * monitoring it's status. * </li> * </ol></p> * @param job the configuration to submit * @param cluster the handle to the Cluster * @throws ClassNotFoundException * @throws InterruptedException * @throws IOException */ boolean submitJobInternal(DragonJob job, Cluster cluster) throws ClassNotFoundException, InterruptedException, IOException { Path jobStagingArea = JobSubmissionFiles.getStagingDir(cluster, job.getConfiguration()); Configuration conf = job.getConfiguration(); InetAddress ip = InetAddress.getLocalHost(); if (ip != null) { submitHostAddress = ip.getHostAddress(); submitHostName = ip.getHostName(); conf.set(DragonJobConfig.JOB_SUBMITHOST, submitHostName); conf.set(DragonJobConfig.JOB_SUBMITHOSTADDR, submitHostAddress); } JobId jobId = client.getNewJobId(); job.setJobId(jobId); Path submitJobDir = new Path(jobStagingArea, jobId.toString()); try { conf.set("hadoop.http.filter.initializers", "org.apache.hadoop.yarn.server.webproxy.amfilter.AmFilterInitializer"); conf.set(DragonJobConfig.JOB_SUBMIT_DIR, submitJobDir.toString()); if (LOG.isDebugEnabled()) { LOG.debug("Configuring job " + jobId + " with " + submitJobDir + " as the submit dir"); } // get delegation token for the dir TokenCache.obtainTokensForNamenodes(job.getCredentials(), new Path[] { submitJobDir }, conf); populateTokenCache(conf, job.getCredentials()); copyAndConfigureFiles(job, submitJobDir); Path submitJobFile = JobSubmissionFiles.getJobConfPath(submitJobDir); Path submitJobDescFile = JobSubmissionFiles.getJobDescriptionFile(submitJobDir); // write "queue admins of the queue to which job is being submitted" // to job file. String queue = conf.get(DragonJobConfig.QUEUE_NAME, DragonJobConfig.DEFAULT_QUEUE_NAME); AccessControlList acl = client.getQueueAdmins(queue); conf.set(toFullPropertyName(queue, QueueACL.ADMINISTER_JOBS.getAclName()), acl.getAclString()); // removing jobtoken referrals before copying the jobconf to HDFS // as the tasks don't need this setting, actually they may break // because of it if present as the referral will point to a // different job. TokenCache.cleanUpTokenReferral(conf); // Write job file to submit dir writeConf(conf, submitJobFile); // Write the serialized job description dag to submit dir writeJobDescription(job.getJobGraph(), submitJobDescFile); // // Now, actually submit the job (using the submit name) // printTokens(jobId, job.getCredentials()); return client.submitJob(jobId, submitJobDir.toString(), job.getCredentials()); } finally { // if (status == null) { // LOG.info("Cleaning up the staging area " + submitJobDir); // if (jtFs != null && submitJobDir != null) // jtFs.delete(submitJobDir, true); // // } } }
From source file:edu.vt.middleware.gator.log4j.SocketServer.java
/** * Gets the logging event handler for the given client. * /* www. ja v a 2 s. c om*/ * @param hostNameOrIp Host name or IP address of client. * * @return Logging event handler for given client or null if no handler is * found for given client. */ public LoggingEventHandler getLoggingEventHandler(final String hostNameOrIp) { for (InetAddress address : eventHandlerMap.keySet()) { if (address.getHostName().equals(hostNameOrIp) || address.getHostAddress().equals(hostNameOrIp)) { return eventHandlerMap.get(address); } } return null; }
From source file:org.apache.james.transport.mailets.DSNBounce.java
private String getHostname() { try {//from w w w . j a va 2 s . c o m InetAddress hostAddress = InetAddress.getLocalHost(); return hostAddress.getHostName(); } catch (Exception e) { return "[address unknown]"; } }
From source file:org.apache.synapse.ServerConfigurationInformation.java
private void initServerHostAndIP() { try {//from w ww . j a v a 2 s . c o m InetAddress addr = InetAddress.getLocalHost(); if (addr != null) { // Get IP Address ipAddress = addr.getHostAddress(); if (ipAddress != null) { } // Get hostName hostName = addr.getHostName(); if (hostName == null) { hostName = ipAddress; } } } catch (UnknownHostException e) { log.warn("Unable to get the hostName or IP address of the server", e); } }