public Builder withLeaderHostAndPort(String host, int port) { this.leaderHostAndPort = HostAndPort.fromParts(host, port); return this; }
public StaticHiveCluster(List<URI> metastoreUris, String metastoreUsername, HiveMetastoreClientFactory clientFactory) { requireNonNull(metastoreUris, "metastoreUris is null"); checkArgument(!metastoreUris.isEmpty(), "metastoreUris must specify at least one URI"); this.addresses = metastoreUris.stream() .map(StaticHiveCluster::checkMetastoreUri) .map(uri -> HostAndPort.fromParts(uri.getHost(), uri.getPort())) .collect(toList()); this.metastoreUsername = metastoreUsername; this.clientFactory = requireNonNull(clientFactory, "clientFactory is null"); }
public String getHostAndTlsPort() { if (enableTlsPort) { return HostAndPort.fromParts(host, tlsPort).toString(); } return null; }
public static HostAndPortWithScheme fromParts(String scheme, String host, int port) { return new HostAndPortWithScheme(scheme, HostAndPort.fromParts(host, port)); }
public HostAndPort getHttpsAddress() { URI httpsUri = server.getHttpServerInfo().getHttpsUri(); return HostAndPort.fromParts(httpsUri.getHost(), httpsUri.getPort()); }
public HostAndPort getAddress() { return HostAndPort.fromParts(getBaseUrl().getHost(), getBaseUrl().getPort()); }
public void setLeader(int leaderId, String leaderHost, int leaderPort) { this.leader = new KafkaLeader(leaderId, HostAndPort.fromParts(leaderHost, leaderPort)); }
public TestingHiveCluster(HiveClientConfig config, String host, int port) { this.config = requireNonNull(config, "config is null"); this.address = HostAndPort.fromParts(requireNonNull(host, "host is null"), port); }
/** * Retrieves the host and port from the specified URI. * * @param uriString URI to retrieve the host and port from * @return the host and port from the URI as a String * @throws URISyntaxException if the specified URI is invalid or cannot be parsed */ public static String getHostAndPortFromUri(String uriString) throws URISyntaxException { URI uri = new URI(uriString); if (uri.getPort() == -1) { return uri.getHost(); } else { return HostAndPort.fromParts(uri.getHost(), uri.getPort()).toString(); } }
/** * Returns host and port together as something that can be used as part of a URI. */ public String getHostAndPort() { if (enablePlaintextPort) { if (plaintextPort < 0) { return HostAndPort.fromString(host).toString(); } else { return HostAndPort.fromParts(host, plaintextPort).toString(); } } return null; }
for (Broker replica : metadata.replicas()) { replicaBrokers.add( HostAndPort.fromParts(replica.host(), replica.port()) );
public void testFromParts() { HostAndPort hp = HostAndPort.fromParts("gmail.com", 81); assertEquals("gmail.com", hp.getHost()); assertTrue(hp.hasPort()); assertEquals(81, hp.getPort()); try { HostAndPort.fromParts("gmail.com:80", 81); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { } try { HostAndPort.fromParts("gmail.com", -1); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { } }
public void testSerialization() { SerializableTester.reserializeAndAssert(HostAndPort.fromParts("host", 80)); SerializableTester.reserializeAndAssert(HostAndPort.fromString("host")); SerializableTester.reserializeAndAssert(HostAndPort.fromString("host:80")); SerializableTester.reserializeAndAssert(HostAndPort.fromString("[::1]:104")); SerializableTester.reserializeAndAssert(HostAndPort.fromParts("1::2", 103)); } }
public static FileBlockInfo createRandom() { FileBlockInfo result = new FileBlockInfo(); Random random = new Random(); BlockInfo blockInfo = BlockInfoTest.createRandom(); long offset = random.nextLong(); List<String> ufsLocations = new ArrayList<>(); long numUfsLocations = random.nextInt(10); for (int i = 0; i < numUfsLocations; i++) { ufsLocations.add(HostAndPort.fromParts(CommonUtils.randomAlphaNumString(random.nextInt(10)), random.nextInt(Constants.MAX_PORT)).toString()); } result.setBlockInfo(blockInfo); result.setOffset(offset); result.setUfsLocations(ufsLocations); return result; } }
@Test public void testDiscoverNodesInTier() { EasyMock.reset(lookupNodeDiscovery); EasyMock.expect(lookupNodeDiscovery.getNodesInTier("tier")) .andReturn( ImmutableSet.of( HostAndPortWithScheme.fromParts("http", "h1", 8080), HostAndPortWithScheme.fromParts("http", "h2", 8080) ) ) .once(); EasyMock.replay(lookupNodeDiscovery); final LookupCoordinatorManager manager = new LookupCoordinatorManager( druidNodeDiscoveryProvider, configManager, lookupCoordinatorManagerConfig, EasyMock.createMock(LookupCoordinatorManager.LookupsCommunicator.class), lookupNodeDiscovery ); manager.start(); Assert.assertEquals( ImmutableSet.of( HostAndPort.fromParts("h1", 8080), HostAndPort.fromParts("h2", 8080) ), ImmutableSet.copyOf(manager.discoverNodesInTier("tier"))); EasyMock.verify(lookupNodeDiscovery); }
public void testHashCodeAndEquals() { HostAndPort hpNoPort1 = HostAndPort.fromString("foo::123"); HostAndPort hpNoPort2 = HostAndPort.fromString("foo::123"); HostAndPort hpNoPort3 = HostAndPort.fromString("[foo::123]"); HostAndPort hpNoPort4 = HostAndPort.fromHost("[foo::123]"); HostAndPort hpNoPort5 = HostAndPort.fromHost("foo::123"); HostAndPort hpWithPort1 = HostAndPort.fromParts("[foo::123]", 80); HostAndPort hpWithPort2 = HostAndPort.fromParts("foo::123", 80); HostAndPort hpWithPort3 = HostAndPort.fromString("[foo::123]:80"); new EqualsTester() .addEqualityGroup(hpNoPort1, hpNoPort2, hpNoPort3, hpNoPort4, hpNoPort5) .addEqualityGroup(hpWithPort1, hpWithPort2, hpWithPort3) .testEquals(); }
@Test public void testGetLookupStatusDetailedTrue() { final LookupCoordinatorResource lookupCoordinatorResource = new LookupCoordinatorResource( EasyMock.createStrictMock(LookupCoordinatorManager.class), mapper, mapper ); HostAndPort newNode = HostAndPort.fromParts("localhost", 4352); Assert.assertEquals( new LookupCoordinatorResource.LookupStatus(false, ImmutableList.of(newNode)), lookupCoordinatorResource.getLookupStatus( LOOKUP_NAME, SINGLE_LOOKUP, ImmutableList.of(LOOKUP_NODE, newNode), NODES_LOOKUP_STATE, true ) ); }
@Test public void testGetLookupStatusDetailedFalse() { final LookupCoordinatorResource lookupCoordinatorResource = new LookupCoordinatorResource( EasyMock.createStrictMock(LookupCoordinatorManager.class), mapper, mapper ); HostAndPort newNode = HostAndPort.fromParts("localhost", 4352); Assert.assertEquals( new LookupCoordinatorResource.LookupStatus(false, null), lookupCoordinatorResource.getLookupStatus( LOOKUP_NAME, SINGLE_LOOKUP, ImmutableList.of(LOOKUP_NODE, newNode), NODES_LOOKUP_STATE, false ) ); }
/** * Converts a proto type to a wire type. * * @param fileBlockPInfo the proto type to convert * @return the converted wire type */ public static FileBlockInfo fromProto(alluxio.grpc.FileBlockInfo fileBlockPInfo) { return new FileBlockInfo().setBlockInfo(fromProto(fileBlockPInfo.getBlockInfo())) .setOffset(fileBlockPInfo.getOffset()).setUfsLocations( fileBlockPInfo.getUfsLocationsCount() > 0 ? fileBlockPInfo.getUfsStringLocationsList() : map(addr -> HostAndPort.fromParts(addr.getHost(), addr.getDataPort()).toString(), fileBlockPInfo.getUfsLocationsList())); }
public void testToString() { // With ports. assertEquals("foo:101", "" + HostAndPort.fromString("foo:101")); assertEquals(":102", HostAndPort.fromString(":102").toString()); assertEquals("[1::2]:103", HostAndPort.fromParts("1::2", 103).toString()); assertEquals("[::1]:104", HostAndPort.fromString("[::1]:104").toString()); // Without ports. assertEquals("foo", "" + HostAndPort.fromString("foo")); assertEquals("", HostAndPort.fromString("").toString()); assertEquals("[1::2]", HostAndPort.fromString("1::2").toString()); assertEquals("[::1]", HostAndPort.fromString("[::1]").toString()); // Garbage in, garbage out. assertEquals("[::]]:107", HostAndPort.fromParts("::]", 107).toString()); assertEquals("[[:]]:108", HostAndPort.fromString("[[:]]:108").toString()); }