use of com.google.common.net.HostAndPort in project torodb by torodb.
the class HeartbeatInfo method unmarshall.
public static HeartbeatInfo unmarshall(BsonDocument bson) throws TypesMismatchException, NoSuchKeyException, BadValueException {
BsonReaderTool.checkOnlyHasFields("ReplSetHeartbeatArgs", bson, CHECK_EMPTY_FIELD_NAME.getFieldName(), PROTOCOL_VERSION_FIELD_NAME.getFieldName(), CONFIG_VERSION_FIELD_NAME.getFieldName(), SENDER_ID_FIELD_NAME.getFieldName(), SET_NAME_FIELD_NAME.getFieldName(), SENDER_HOST_FIELD_NAME.getFieldName());
Boolean checkEmpty = null;
if (bson.containsKey(CHECK_EMPTY_FIELD_NAME.getFieldName())) {
checkEmpty = BsonReaderTool.getBoolean(bson, CHECK_EMPTY_FIELD_NAME);
}
long protocolVersion = BsonReaderTool.getLong(bson, PROTOCOL_VERSION_FIELD_NAME);
long configVersion = BsonReaderTool.getLong(bson, CONFIG_VERSION_FIELD_NAME);
Long senderId = null;
if (bson.containsKey(SENDER_ID_FIELD_NAME.getFieldName())) {
senderId = BsonReaderTool.getLong(bson, SENDER_ID_FIELD_NAME);
}
String setName = BsonReaderTool.getString(bson, SET_NAME_FIELD_NAME);
String senderHostString = BsonReaderTool.getString(bson, SENDER_HOST_FIELD_NAME, null);
HostAndPort senderHost = senderHostString != null ? BsonReaderTool.getHostAndPort(senderHostString) : null;
return new HeartbeatInfo(protocolVersion, configVersion, setName, senderHost, senderId, checkEmpty);
}
use of com.google.common.net.HostAndPort in project alluxio by Alluxio.
the class FileBlockInfo method toThrift.
/**
* @return thrift representation of the file block information
*/
protected alluxio.thrift.FileBlockInfo toThrift() {
List<alluxio.thrift.WorkerNetAddress> ufsLocations = new ArrayList<>();
for (String ufsLocation : mUfsLocations) {
HostAndPort address = HostAndPort.fromString(ufsLocation);
ufsLocations.add(new alluxio.thrift.WorkerNetAddress().setHost(address.getHostText()).setDataPort(address.getPortOrDefault(-1)));
}
return new alluxio.thrift.FileBlockInfo(mBlockInfo.toThrift(), mOffset, ufsLocations, mUfsLocations);
}
use of com.google.common.net.HostAndPort in project alluxio by Alluxio.
the class Performance method main.
/**
* Runs the performance test.
*
* Usage:
* {@code java -cp <ALLUXIO-VERSION> alluxio.examples.Performance <MasterIp> <FileNamePrefix>
* <WriteBlockSizeInBytes> <BlocksPerFile> <DebugMode:true/false> <Threads> <FilesPerThread>
* <TestCaseNumber> <BaseFileNumber>}
*
* @param args the arguments for this example
* @throws Exception if the example fails
*/
public static void main(String[] args) throws Exception {
if (args.length != 9) {
System.out.println("java -cp " + RuntimeConstants.ALLUXIO_JAR + " alluxio.examples.Performance " + "<MasterIp> <FileNamePrefix> <WriteBlockSizeInBytes> <BlocksPerFile> " + "<DebugMode:true/false> <Threads> <FilesPerThread> <TestCaseNumber> " + "<BaseFileNumber>\n" + "1: Files Write Test\n" + "2: Files Read Test\n" + "3: RamFile Write Test \n" + "4: RamFile Read Test \n" + "5: ByteBuffer Write Test \n" + "6: ByteBuffer Read Test \n");
System.exit(-1);
}
HostAndPort masterAddress = HostAndPort.fromString(args[0]);
sFileName = args[1];
sBlockSizeBytes = Integer.parseInt(args[2]);
sBlocksPerFile = Long.parseLong(args[3]);
sDebugMode = ("true".equals(args[4]));
sThreads = Integer.parseInt(args[5]);
sFiles = Integer.parseInt(args[6]) * sThreads;
final int testCase = Integer.parseInt(args[7]);
sBaseFileNumber = Integer.parseInt(args[8]);
sFileBytes = sBlocksPerFile * sBlockSizeBytes;
sFilesBytes = sFileBytes * sFiles;
long fileBufferBytes = Configuration.getBytes(PropertyKey.USER_FILE_BUFFER_BYTES);
sResultPrefix = String.format("Threads %d FilesPerThread %d TotalFiles %d " + "BLOCK_SIZE_KB %d BLOCKS_PER_FILE %d FILE_SIZE_MB %d " + "Alluxio_WRITE_BUFFER_SIZE_KB %d BaseFileNumber %d : ", sThreads, sFiles / sThreads, sFiles, sBlockSizeBytes / 1024, sBlocksPerFile, sFileBytes / Constants.MB, fileBufferBytes / 1024, sBaseFileNumber);
CommonUtils.warmUpLoop();
Configuration.set(PropertyKey.MASTER_HOSTNAME, masterAddress.getHostText());
Configuration.set(PropertyKey.MASTER_RPC_PORT, Integer.toString(masterAddress.getPort()));
if (testCase == 1) {
sResultPrefix = "AlluxioFilesWriteTest " + sResultPrefix;
LOG.info(sResultPrefix);
sFileSystem = FileSystem.Factory.get();
AlluxioTest(true);
} else if (testCase == 2 || testCase == 9) {
sResultPrefix = "AlluxioFilesReadTest " + sResultPrefix;
LOG.info(sResultPrefix);
sFileSystem = FileSystem.Factory.get();
sAlluxioStreamingRead = (9 == testCase);
AlluxioTest(false);
} else if (testCase == 3) {
sResultPrefix = "RamFile Write " + sResultPrefix;
LOG.info(sResultPrefix);
memoryCopyTest(true, false);
} else if (testCase == 4) {
sResultPrefix = "RamFile Read " + sResultPrefix;
LOG.info(sResultPrefix);
memoryCopyTest(false, false);
} else if (testCase == 5) {
sResultPrefix = "ByteBuffer Write Test " + sResultPrefix;
LOG.info(sResultPrefix);
memoryCopyTest(true, true);
} else if (testCase == 6) {
sResultPrefix = "ByteBuffer Read Test " + sResultPrefix;
LOG.info(sResultPrefix);
memoryCopyTest(false, true);
} else if (testCase == 7) {
sResultPrefix = "HdfsFilesWriteTest " + sResultPrefix;
LOG.info(sResultPrefix);
HdfsTest(true);
} else if (testCase == 8) {
sResultPrefix = "HdfsFilesReadTest " + sResultPrefix;
LOG.info(sResultPrefix);
HdfsTest(false);
} else {
throw new RuntimeException("No Test Case " + testCase);
}
for (int k = 0; k < RESULT_ARRAY_SIZE; k++) {
System.out.print(sResults[k] + " ");
}
System.out.println();
System.exit(0);
}
use of com.google.common.net.HostAndPort in project beam by apache.
the class SocketAddressFactory method createFrom.
/**
* Parse a {@link SocketAddress} from the given string.
*/
public static SocketAddress createFrom(String value) {
if (value.startsWith(UNIX_DOMAIN_SOCKET_PREFIX)) {
// Unix Domain Socket address.
// Create the underlying file for the Unix Domain Socket.
String filePath = value.substring(UNIX_DOMAIN_SOCKET_PREFIX.length());
File file = new File(filePath);
if (!file.isAbsolute()) {
throw new IllegalArgumentException("File path must be absolute: " + filePath);
}
try {
if (file.createNewFile()) {
// If this application created the file, delete it when the application exits.
file.deleteOnExit();
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
// Create the SocketAddress referencing the file.
return new DomainSocketAddress(file);
} else {
// Standard TCP/IP address.
HostAndPort hostAndPort = HostAndPort.fromString(value);
checkArgument(hostAndPort.hasPort(), "Address must be a unix:// path or be in the form host:port. Got: %s", value);
return new InetSocketAddress(hostAndPort.getHostText(), hostAndPort.getPort());
}
}
use of com.google.common.net.HostAndPort in project distributedlog by twitter.
the class DLZkServerSet method getZkAddresses.
private static Iterable<InetSocketAddress> getZkAddresses(URI uri) {
String zkServers = getZKServersFromDLUri(uri);
String[] zkServerList = StringUtils.split(zkServers, ',');
ImmutableList.Builder<InetSocketAddress> builder = ImmutableList.builder();
for (String zkServer : zkServerList) {
HostAndPort hostAndPort = HostAndPort.fromString(zkServer).withDefaultPort(2181);
builder.add(InetSocketAddress.createUnresolved(hostAndPort.getHostText(), hostAndPort.getPort()));
}
return builder.build();
}
Aggregations