List of usage examples for java.net InetSocketAddress getHostName
public final String getHostName()
From source file:org.apache.accumulo.server.gc.SimpleGarbageCollector.java
private void getZooLock(InetSocketAddress addr) throws KeeperException, InterruptedException { String address = addr.getHostName() + ":" + addr.getPort(); String path = ZooUtil.getRoot(HdfsZooInstance.getInstance()) + Constants.ZGC_LOCK; LockWatcher lockWatcher = new LockWatcher() { public void lostLock(LockLossReason reason) { Halt.halt("GC lock in zookeeper lost (reason = " + reason + "), exiting!"); }//from w w w. j av a 2 s. c o m }; while (true) { lock = new ZooLock(path); if (lock.tryLock(lockWatcher, new ServerServices(address, Service.GC_CLIENT).toString().getBytes())) { break; } UtilWaitThread.sleep(1000); } }
From source file:org.apache.james.protocols.smtp.AbstractStartTlsSMTPServerTest.java
@Test public void testStartTLSWithJavamail() throws Exception { InetSocketAddress address = new InetSocketAddress("127.0.0.1", TestUtils.getFreePort()); ProtocolServer server = null;/*from w w w .j ava2 s . com*/ try { TestMessageHook hook = new TestMessageHook(); server = createServer(createProtocol(hook), address, Encryption.createStartTls(BogusSslContextFactory.getServerContext())); server.bind(); Properties mailProps = new Properties(); mailProps.put("mail.smtp.from", "test@localhost"); mailProps.put("mail.smtp.host", address.getHostName()); mailProps.put("mail.smtp.port", address.getPort()); mailProps.put("mail.smtp.socketFactory.class", BogusSSLSocketFactory.class.getName()); mailProps.put("mail.smtp.socketFactory.fallback", "false"); mailProps.put("mail.smtp.starttls.enable", "true"); Session mailSession = Session.getDefaultInstance(mailProps); MimeMessage message = new MimeMessage(mailSession); message.setFrom(new InternetAddress("test@localhost")); String[] emails = { "valid@localhost" }; Address rcpts[] = new Address[emails.length]; for (int i = 0; i < emails.length; i++) { rcpts[i] = new InternetAddress(emails[i].trim().toLowerCase()); } message.setRecipients(Message.RecipientType.TO, rcpts); message.setSubject("Testmail", "UTF-8"); message.setText("Test....."); SMTPTransport transport = (SMTPTransport) mailSession.getTransport("smtps"); transport.connect(new Socket(address.getHostName(), address.getPort())); transport.sendMessage(message, rcpts); assertEquals(1, hook.getQueued().size()); } finally { if (server != null) { server.unbind(); } } }
From source file:org.apache.hadoop.mapreduce.v2.app.rm.RMCommunicator.java
protected void register() { //Register/* w w w. j a va2 s . c o m*/ InetSocketAddress serviceAddr = null; if (clientService != null) { serviceAddr = clientService.getBindAddress(); } try { RegisterApplicationMasterRequest request = recordFactory .newRecordInstance(RegisterApplicationMasterRequest.class); if (serviceAddr != null) { request.setHost(serviceAddr.getHostName()); request.setRpcPort(serviceAddr.getPort()); request.setTrackingUrl(MRWebAppUtil.getAMWebappScheme(getConfig()) + serviceAddr.getHostName() + ":" + clientService.getHttpPort()); } RegisterApplicationMasterResponse response = scheduler.registerApplicationMaster(request); isApplicationMasterRegistered = true; maxContainerCapability = response.getMaximumResourceCapability(); this.context.getClusterInfo().setMaxContainerCapability(maxContainerCapability); if (UserGroupInformation.isSecurityEnabled()) { setClientToAMToken(response.getClientToAMTokenMasterKey()); } this.applicationACLs = response.getApplicationACLs(); LOG.info("maxContainerCapability: " + maxContainerCapability); String queue = response.getQueue(); LOG.info("queue: " + queue); job.setQueueName(queue); this.schedulerResourceTypes.addAll(response.getSchedulerResourceTypes()); } catch (Exception are) { LOG.error("Exception while registering", are); throw new YarnRuntimeException(are); } }
From source file:org.apache.hadoop.hdfs.server.namenode.SecondaryNameNode.java
/** * Initialize SecondaryNameNode.//from w w w.j a va 2 s.c om */ private void initialize(final Configuration conf) throws IOException { final InetSocketAddress infoSocAddr = getHttpAddress(conf); infoBindAddress = infoSocAddr.getHostName(); if (UserGroupInformation.isSecurityEnabled()) { SecurityUtil.login(conf, DFSConfigKeys.DFS_SECONDARY_NAMENODE_KEYTAB_FILE_KEY, DFSConfigKeys.DFS_SECONDARY_NAMENODE_USER_NAME_KEY, infoBindAddress); } // initiate Java VM metrics JvmMetricsSource.create("SecondaryNameNode", conf.get("session.id")); // Create connection to the namenode. shouldRun = true; nameNodeAddr = NameNode.getServiceAddress(conf, true); this.conf = conf; this.namenode = (NamenodeProtocol) RPC.waitForProxy(NamenodeProtocol.class, NamenodeProtocol.versionID, nameNodeAddr, conf); // initialize checkpoint directories fsName = getInfoServer(); checkpointDirs = FSImage.getCheckpointDirs(conf, "/tmp/hadoop/dfs/namesecondary"); checkpointEditsDirs = FSImage.getCheckpointEditsDirs(conf, "/tmp/hadoop/dfs/namesecondary"); checkpointImage = new CheckpointStorage(); checkpointImage.recoverCreate(checkpointDirs, checkpointEditsDirs); // Initialize other scheduling parameters from the configuration checkpointPeriod = conf.getLong("fs.checkpoint.period", 3600); checkpointSize = conf.getLong("fs.checkpoint.size", 4194304); // initialize the webserver for uploading files. // Kerberized SSL servers must be run from the host principal... UserGroupInformation httpUGI = UserGroupInformation.loginUserFromKeytabAndReturnUGI( SecurityUtil.getServerPrincipal( conf.get(DFSConfigKeys.DFS_SECONDARY_NAMENODE_KRB_HTTPS_USER_NAME_KEY), infoBindAddress), conf.get(DFSConfigKeys.DFS_SECONDARY_NAMENODE_KEYTAB_FILE_KEY)); try { infoServer = httpUGI.doAs(new PrivilegedExceptionAction<HttpServer>() { @Override public HttpServer run() throws IOException, InterruptedException { LOG.info("Starting web server as: " + UserGroupInformation.getCurrentUser().getUserName()); int tmpInfoPort = infoSocAddr.getPort(); infoServer = new HttpServer("secondary", infoBindAddress, tmpInfoPort, tmpInfoPort == 0, conf, SecurityUtil.getAdminAcls(conf, DFSConfigKeys.DFS_ADMIN)); if (UserGroupInformation.isSecurityEnabled()) { System.setProperty("https.cipherSuites", Krb5AndCertsSslSocketConnector.KRB5_CIPHER_SUITES.get(0)); InetSocketAddress secInfoSocAddr = NetUtils.createSocketAddr(infoBindAddress + ":" + conf.get("dfs.secondary.https.port", infoBindAddress + ":" + 0)); imagePort = secInfoSocAddr.getPort(); infoServer.addSslListener(secInfoSocAddr, conf, false, true); } infoServer.setAttribute("name.system.image", checkpointImage); infoServer.setAttribute(JspHelper.CURRENT_CONF, conf); infoServer.addInternalServlet("getimage", "/getimage", GetImageServlet.class, true); infoServer.start(); return infoServer; } }); } catch (InterruptedException e) { throw new RuntimeException(e); } LOG.info("Web server init done"); // The web-server port can be ephemeral... ensure we have the correct info infoPort = infoServer.getPort(); if (!UserGroupInformation.isSecurityEnabled()) imagePort = infoPort; conf.set("dfs.secondary.http.address", infoBindAddress + ":" + infoPort); LOG.info("Secondary Web-server up at: " + infoBindAddress + ":" + infoPort); LOG.info("Secondary image servlet up at: " + infoBindAddress + ":" + imagePort); LOG.warn("Checkpoint Period :" + checkpointPeriod + " secs " + "(" + checkpointPeriod / 60 + " min)"); LOG.warn("Log Size Trigger :" + checkpointSize + " bytes " + "(" + checkpointSize / 1024 + " KB)"); }
From source file:org.apache.tajo.master.TajoMaster.java
private void initWebServer() throws Exception { if (!systemConf.getBoolVar(ConfVars.$TEST_MODE)) { InetSocketAddress address = systemConf.getSocketAddrVar(ConfVars.TAJO_MASTER_INFO_ADDRESS); webServer = StaticHttpServer.getInstance(this, "admin", address.getHostName(), address.getPort(), true, null, context.getConf(), null); webServer.addServlet("queryServlet", "/query_exec", QueryExecutorServlet.class); webServer.start();/*from www .j ava 2s. c o m*/ } }
From source file:com.tesora.dve.mysqlapi.repl.MyReplicationSlaveService.java
@Override public boolean denyServiceStart(ExternalServiceContext ctxt) throws PEException { String serviceAddress = stripPort( GroupManager.getCoordinationServices().getExternalServiceRegisteredAddress(ctxt.getServiceName())); InetSocketAddress isa = GroupManager.getCoordinationServices().getMemberAddress(); InetAddress ia = isa.getAddress(); String ourAddress = null;//from w ww . j a v a 2 s. co m if (ia == null) { ourAddress = stripPort(isa.getHostName()); } else { ourAddress = stripPort(ia.getHostAddress()); } if (!StringUtils.equals(serviceAddress, ourAddress)) { // someone else has started replication slave so don't allow start if (logger.isDebugEnabled()) { logger.debug("Service '" + ctxt.getServiceName() + "' is already registered at '" + serviceAddress + "'"); } return true; } return false; }
From source file:org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWebAppFilter.java
@Inject public RMWebAppFilter(Injector injector, Configuration conf) { super(injector); this.injector = injector; InetSocketAddress sock = YarnConfiguration.useHttps(conf) ? conf.getSocketAddr(YarnConfiguration.RM_WEBAPP_HTTPS_ADDRESS, YarnConfiguration.DEFAULT_RM_WEBAPP_HTTPS_ADDRESS, YarnConfiguration.DEFAULT_RM_WEBAPP_HTTPS_PORT) : conf.getSocketAddr(YarnConfiguration.RM_WEBAPP_ADDRESS, YarnConfiguration.DEFAULT_RM_WEBAPP_ADDRESS, YarnConfiguration.DEFAULT_RM_WEBAPP_PORT); path = sock.getHostName() + ":" + Integer.toString(sock.getPort()); path = YarnConfiguration.useHttps(conf) ? "https://" + path : "http://" + path; ahsEnabled = conf.getBoolean(YarnConfiguration.APPLICATION_HISTORY_ENABLED, YarnConfiguration.DEFAULT_APPLICATION_HISTORY_ENABLED); ahsPageURLPrefix = pjoin(/* www . j a v a 2s . co m*/ WebAppUtils.getHttpSchemePrefix(conf) + WebAppUtils.getAHSWebAppURLWithoutScheme(conf), "applicationhistory"); }
From source file:org.apache.hama.bsp.TestBSPTaskFaults.java
@Override protected void setUp() throws Exception { super.setUp(); conf = new HamaConfiguration(); conf.setInt(Constants.GROOM_PING_PERIOD, 200); conf.setClass("bsp.work.class", FaulTestBSP.class, BSP.class); conf.setClass(SyncServiceFactory.SYNC_PEER_CLASS, LocalBSPRunner.LocalSyncClient.class, SyncClient.class); int port = BSPNetUtils.getFreePort(4321 + incrementTestNumber()); try {//from w w w .ja va2 s . c om InetSocketAddress inetAddress = new InetSocketAddress(port); groom = new MinimalGroomServer(conf); workerServer = RPC.getServer(groom, inetAddress.getHostName(), inetAddress.getPort(), conf); workerServer.start(); LOG.info("Started RPC server"); conf.setInt("bsp.groom.rpc.port", inetAddress.getPort()); umbilical = (BSPPeerProtocol) RPC.getProxy(BSPPeerProtocol.class, HamaRPCProtocolVersion.versionID, inetAddress, conf); LOG.info("Started the proxy connections"); this.testBSPTaskService = Executors.newScheduledThreadPool(1); } catch (BindException be) { LOG.info(be); } }
From source file:org.apache.hadoop.mapred.StatusHttpServer.java
/** * Configure an ssl listener on the server. * @param addr address to listen on/* ww w .j a v a2 s.c o m*/ * @param keystore location of the keystore * @param storPass password for the keystore * @param keyPass password for the key */ public void addSslListener(InetSocketAddress addr, String keystore, String storPass, String keyPass) throws IOException { if (sslListener != null || webServer.isStarted()) { throw new IOException("Failed to add ssl listener"); } sslListener = new SslListener(); sslListener.setHost(addr.getHostName()); sslListener.setPort(addr.getPort()); sslListener.setKeystore(keystore); sslListener.setPassword(storPass); sslListener.setKeyPassword(keyPass); webServer.addListener(sslListener); }
From source file:org.apache.hadoop.hdfs.server.namenode.SnapshotNode.java
/** * Initialize SnapshotNode//from w w w.j a v a 2 s .c om * @throws IOException */ private void init() throws IOException { ssDir = conf.get("fs.snapshot.dir", "/.SNAPSHOT"); tempDir = conf.get("fs.snapshot.tempdir", "/tmp/snapshot"); fileServer = getImageServer(); dfs = FileSystem.get(conf); Path ssPath = new Path(ssDir); if (!dfs.exists(ssPath)) { dfs.mkdirs(ssPath); } maxLeaseUpdateThreads = conf.getInt("fs.snapshot.leaseupdatethreads", 100); // Waiting room purge thread purgeThread = new Daemon((new WaitingRoom(conf)).getPurger()); purgeThread.start(); // Get namenode rpc connection nameNodeAddr = NameNode.getAddress(conf); namenode = (NamenodeProtocol) RPC.waitForProxy(NamenodeProtocol.class, NamenodeProtocol.versionID, nameNodeAddr, conf); // Snapshot RPC Server InetSocketAddress socAddr = SnapshotNode.getAddress(conf); int handlerCount = conf.getInt("fs.snapshot.handler.count", 10); server = RPC.getServer(this, socAddr.getHostName(), socAddr.getPort(), handlerCount, false, conf); // The rpc-server port can be ephemeral... ensure we have the correct info serverAddress = server.getListenerAddress(); LOG.info("SnapshotNode up at: " + serverAddress); server.start(); // start rpc server }