本文整理了Java中org.apache.hadoop.hbase.net.Address.toString()
方法的一些代码示例,展示了Address.toString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Address.toString()
方法的具体详情如下:
包路径:org.apache.hadoop.hbase.net.Address
类名称:Address
方法名:toString
[英]If hostname is a.b.c and the port is 123, return a:123 instead of a.b.c:123.
[中]如果主机名是a.b.c,端口是123,则返回a:123而不是a.b.c:123。
代码示例来源:origin: apache/hbase
/**
* @return Hostname and port formatted as described at
* {@link Addressing#createHostAndPortStr(String, int)}
* @deprecated Since 2.0. Use {@link #getAddress()} instead.
*/
@Deprecated
public String getHostAndPort() {
return this.address.toString();
}
代码示例来源:origin: apache/hbase
/**
* If hostname is a.b.c and the port is 123, return a:123 instead of a.b.c:123.
* @return if host looks like it is resolved -- not an IP -- then strip the domain portion
* otherwise returns same as {@link #toString()}}
*/
public String toStringWithoutDomain() {
String hostname = getHostname();
String [] parts = hostname.split("\\.");
if (parts.length > 1) {
for (String part: parts) {
if (!StringUtils.isNumeric(part)) {
return Address.fromParts(parts[0], getPort()).toString();
}
}
}
return toString();
}
代码示例来源:origin: apache/hbase
/**
* Parses hostname:port from WAL file path
* @param p path to WAL file
* @return hostname:port
*/
public static String parseHostNameFromLogFile(Path p) {
try {
if (AbstractFSWALProvider.isArchivedLogFile(p)) {
return BackupUtils.parseHostFromOldLog(p);
} else {
ServerName sname = AbstractFSWALProvider.getServerNameFromWALDirectoryName(p);
if (sname != null) {
return sname.getAddress().toString();
} else {
LOG.error("Skip log file (can't parse): " + p);
return null;
}
}
} catch (Exception e) {
LOG.error("Skip log file (can't parse): " + p, e);
return null;
}
}
代码示例来源:origin: apache/hbase
if (serversToIndex.get(sn.getAddress().toString()) == null) {
serversToIndex.put(sn.getHostAndPort(), numServers++);
代码示例来源:origin: apache/hbase
@Test
public void testClearNotProcessedDeadServer() throws Exception {
LOG.info("testClearNotProcessedDeadServer");
NUM_DEAD_SERVERS = cluster.getClusterMetrics().getDeadServerNames().size();
RSGroupInfo appInfo = addGroup("deadServerGroup", 1);
ServerName targetServer = getServerName(appInfo.getServers().iterator().next());
try {
// stopping may cause an exception
// due to the connection loss
admin.stopRegionServer(targetServer.getAddress().toString());
NUM_DEAD_SERVERS++;
} catch (Exception e) {
}
TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {
@Override
public boolean evaluate() throws Exception {
return cluster.getClusterMetrics().getDeadServerNames().size() == NUM_DEAD_SERVERS;
}
});
List<ServerName> notClearedServers = admin.clearDeadServers(Lists.newArrayList(targetServer));
assertEquals(1, notClearedServers.size());
}
代码示例来源:origin: apache/hbase
/**
* UT for HBASE-21746
*/
@Test
public void testLoadMetaRegion() throws Exception {
HRegionServer rsWithMeta = TEST_UTIL.getMiniHBaseCluster().getRegionServerThreads().stream()
.map(t -> t.getRegionServer())
.filter(rs -> rs.getRegions(TableName.META_TABLE_NAME).size() > 0).findFirst().get();
int onlineRegions = rsWithMeta.getNumberOfOnlineRegions();
String rsName = rsWithMeta.getServerName().getAddress().toString();
try (RegionMover rm =
new RegionMoverBuilder(rsName, TEST_UTIL.getConfiguration()).ack(true).build()) {
LOG.info("Unloading " + rsWithMeta.getServerName());
rm.unload();
assertEquals(0, rsWithMeta.getNumberOfOnlineRegions());
LOG.info("Loading " + rsWithMeta.getServerName());
rm.load();
assertEquals(onlineRegions, rsWithMeta.getNumberOfOnlineRegions());
}
}
代码示例来源:origin: apache/hbase
public static Put addLocation(Put p, ServerName sn, long openSeqNum, int replicaId)
throws IOException {
CellBuilder builder = CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY);
return p.add(builder.clear()
.setRow(p.getRow())
.setFamily(getCatalogFamily())
.setQualifier(getServerColumn(replicaId))
.setTimestamp(p.getTimestamp())
.setType(Cell.Type.Put)
.setValue(Bytes.toBytes(sn.getAddress().toString()))
.build())
.add(builder.clear()
.setRow(p.getRow())
.setFamily(getCatalogFamily())
.setQualifier(getStartCodeColumn(replicaId))
.setTimestamp(p.getTimestamp())
.setType(Cell.Type.Put)
.setValue(Bytes.toBytes(sn.getStartcode()))
.build())
.add(builder.clear()
.setRow(p.getRow())
.setFamily(getCatalogFamily())
.setQualifier(getSeqNumColumn(replicaId))
.setTimestamp(p.getTimestamp())
.setType(Type.Put)
.setValue(Bytes.toBytes(openSeqNum))
.build());
}
代码示例来源:origin: apache/hbase
/**
* UT for HBASE-21746
*/
@Test
public void testTargetServerDeadWhenLoading() throws Exception {
HRegionServer rs = TEST_UTIL.getMiniHBaseCluster().getRegionServer(0);
String rsName = rs.getServerName().getAddress().toString();
Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
// wait 5 seconds at most
conf.setInt(RegionMover.SERVERSTART_WAIT_MAX_KEY, 5);
String filename =
new Path(TEST_UTIL.getDataTestDir(), "testTargetServerDeadWhenLoading").toString();
// unload the region server
try (RegionMover rm =
new RegionMoverBuilder(rsName, conf).filename(filename).ack(true).build()) {
LOG.info("Unloading " + rs.getServerName());
rm.unload();
assertEquals(0, rs.getNumberOfOnlineRegions());
}
String inexistRsName = "whatever:123";
try (RegionMover rm =
new RegionMoverBuilder(inexistRsName, conf).filename(filename).ack(true).build()) {
// load the regions to an inexist region server, which should fail and return false
LOG.info("Loading to an inexist region server {}", inexistRsName);
assertFalse(rm.load());
}
}
}
代码示例来源:origin: apache/hbase
admin.stopRegionServer(targetServer.getAddress().toString());
NUM_DEAD_SERVERS++;
} catch (Exception e) {
代码示例来源:origin: apache/hbase
admin.stopRegionServer(targetServer.getAddress().toString());
NUM_DEAD_SERVERS++;
} catch (Exception e) {
代码示例来源:origin: apache/hbase
MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
HRegionServer regionServer = cluster.getRegionServer(0);
String rsName = regionServer.getServerName().getAddress().toString();
int numRegions = regionServer.getNumberOfOnlineRegions();
RegionMoverBuilder rmBuilder =
代码示例来源:origin: apache/hbase
admin.stopRegionServer(targetServer.getAddress().toString());
} catch (Exception e) {
代码示例来源:origin: apache/hbase
@Test
public void testWithAck() throws Exception {
MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
HRegionServer regionServer = cluster.getRegionServer(0);
String rsName = regionServer.getServerName().getAddress().toString();
int numRegions = regionServer.getNumberOfOnlineRegions();
RegionMoverBuilder rmBuilder =
new RegionMoverBuilder(rsName, TEST_UTIL.getConfiguration()).ack(true).maxthreads(8);
try (RegionMover rm = rmBuilder.build()) {
LOG.info("Unloading " + regionServer.getServerName());
rm.unload();
assertEquals(0, regionServer.getNumberOfOnlineRegions());
LOG.info("Successfully Unloaded\nNow Loading");
rm.load();
assertEquals(numRegions, regionServer.getNumberOfOnlineRegions());
// Repeat the same load. It should be very fast because all regions are already moved.
rm.load();
}
}
代码示例来源:origin: apache/hbase
/**
* Call this restart method only after running MockMasterServices#start()
* The RSs can be differentiated by the port number, see
* ServerName in MockMasterServices#start() method above.
* Restart of region server will have new startcode in server name
*
* @param serverName Server name to be restarted
*/
public void restartRegionServer(ServerName serverName) throws IOException {
List<ServerName> onlineServers = serverManager.getOnlineServersList();
long startCode = -1;
for (ServerName s : onlineServers) {
if (s.getAddress().equals(serverName.getAddress())) {
startCode = s.getStartcode() + 1;
break;
}
}
if (startCode == -1) {
return;
}
ServerName sn = ServerName.valueOf(serverName.getAddress().toString(), startCode);
serverManager.regionServerReport(sn, ServerMetricsBuilder.of(sn));
}
代码示例来源:origin: apache/hbase
@Test
public void testParseOfBytes() {
final String snStr = "www.EXAMPLE.org,1234,5678";
ServerName sn = ServerName.valueOf(snStr);
byte[] versionedBytes = sn.getVersionedBytes();
ServerName parsedSn = ServerName.parseVersionedServerName(versionedBytes);
assertEquals(sn.toString(), parsedSn.toString());
assertEquals(sn.getHostnameLowerCase(), parsedSn.getHostnameLowerCase());
assertEquals(sn.getPort(), parsedSn.getPort());
assertEquals(sn.getStartcode(), parsedSn.getStartcode());
final String hostnamePortStr = sn.getAddress().toString();
byte[] bytes = Bytes.toBytes(hostnamePortStr);
parsedSn = ServerName.parseVersionedServerName(bytes);
assertEquals(sn.getHostnameLowerCase(), parsedSn.getHostnameLowerCase());
assertEquals(sn.getPort(), parsedSn.getPort());
assertEquals(ServerName.NON_STARTCODE, parsedSn.getStartcode());
}
代码示例来源:origin: com.aliyun.hbase/alihbase-common
/**
* @return Hostname and port formatted as described at
* {@link Addressing#createHostAndPortStr(String, int)}
* @deprecated Since 2.0. Use {@link #getAddress()} instead.
*/
@Deprecated
public String getHostAndPort() {
return this.address.toString();
}
代码示例来源:origin: org.apache.hbase/hbase-common
/**
* @return Hostname and port formatted as described at
* {@link Addressing#createHostAndPortStr(String, int)}
* @deprecated Since 2.0. Use {@link #getAddress()} instead.
*/
@Deprecated
public String getHostAndPort() {
return this.address.toString();
}
代码示例来源:origin: org.apache.hbase/hbase-client
public static Put addLocation(Put p, ServerName sn, long openSeqNum, int replicaId)
throws IOException {
CellBuilder builder = CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY);
return p.add(builder.clear()
.setRow(p.getRow())
.setFamily(getCatalogFamily())
.setQualifier(getServerColumn(replicaId))
.setTimestamp(p.getTimestamp())
.setType(Cell.Type.Put)
.setValue(Bytes.toBytes(sn.getAddress().toString()))
.build())
.add(builder.clear()
.setRow(p.getRow())
.setFamily(getCatalogFamily())
.setQualifier(getStartCodeColumn(replicaId))
.setTimestamp(p.getTimestamp())
.setType(Cell.Type.Put)
.setValue(Bytes.toBytes(sn.getStartcode()))
.build())
.add(builder.clear()
.setRow(p.getRow())
.setFamily(getCatalogFamily())
.setQualifier(getSeqNumColumn(replicaId))
.setTimestamp(p.getTimestamp())
.setType(Type.Put)
.setValue(Bytes.toBytes(openSeqNum))
.build());
}
代码示例来源:origin: org.apache.hbase/hbase-common
/**
* If hostname is a.b.c and the port is 123, return a:123 instead of a.b.c:123.
* @return if host looks like it is resolved -- not an IP -- then strip the domain portion
* otherwise returns same as {@link #toString()}}
*/
public String toStringWithoutDomain() {
String hostname = getHostname();
String [] parts = hostname.split("\\.");
if (parts.length > 1) {
for (String part: parts) {
if (!StringUtils.isNumeric(part)) {
return Address.fromParts(parts[0], getPort()).toString();
}
}
}
return toString();
}
代码示例来源:origin: org.apache.hbase/hbase-server
@Test
public void testParseOfBytes() {
final String snStr = "www.EXAMPLE.org,1234,5678";
ServerName sn = ServerName.valueOf(snStr);
byte[] versionedBytes = sn.getVersionedBytes();
ServerName parsedSn = ServerName.parseVersionedServerName(versionedBytes);
assertEquals(sn.toString(), parsedSn.toString());
assertEquals(sn.getHostnameLowerCase(), parsedSn.getHostnameLowerCase());
assertEquals(sn.getPort(), parsedSn.getPort());
assertEquals(sn.getStartcode(), parsedSn.getStartcode());
final String hostnamePortStr = sn.getAddress().toString();
byte[] bytes = Bytes.toBytes(hostnamePortStr);
parsedSn = ServerName.parseVersionedServerName(bytes);
assertEquals(sn.getHostnameLowerCase(), parsedSn.getHostnameLowerCase());
assertEquals(sn.getPort(), parsedSn.getPort());
assertEquals(ServerName.NON_STARTCODE, parsedSn.getStartcode());
}
内容来源于网络,如有侵权,请联系作者删除!