Search in sources :

Example 21 with HostAndPort

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);
}
Also used : HostAndPort(com.google.common.net.HostAndPort)

Example 22 with HostAndPort

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);
}
Also used : HostAndPort(com.google.common.net.HostAndPort) ArrayList(java.util.ArrayList)

Example 23 with HostAndPort

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);
}
Also used : HostAndPort(com.google.common.net.HostAndPort)

Example 24 with HostAndPort

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());
    }
}
Also used : HostAndPort(com.google.common.net.HostAndPort) InetSocketAddress(java.net.InetSocketAddress) DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) IOException(java.io.IOException) File(java.io.File)

Example 25 with HostAndPort

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();
}
Also used : HostAndPort(com.google.common.net.HostAndPort) ImmutableList(com.google.common.collect.ImmutableList) InetSocketAddress(java.net.InetSocketAddress)

Aggregations

HostAndPort (com.google.common.net.HostAndPort)45 IOException (java.io.IOException)8 Test (org.junit.Test)7 InetSocketAddress (java.net.InetSocketAddress)5 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 Request (com.metamx.http.client.Request)3 SequenceInputStreamResponseHandler (com.metamx.http.client.response.SequenceInputStreamResponseHandler)3 SystemException (com.torodb.core.exceptions.SystemException)3 JCommander (com.beust.jcommander.JCommander)2 Console (com.beust.jcommander.internal.Console)2 OpTime (com.eightkdata.mongowp.OpTime)2 UnreachableMongoServerException (com.eightkdata.mongowp.client.core.UnreachableMongoServerException)2 MongoException (com.eightkdata.mongowp.exceptions.MongoException)2 Charsets (com.google.common.base.Charsets)2 Throwables (com.google.common.base.Throwables)2 Service (com.google.common.util.concurrent.Service)2 CreationException (com.google.inject.CreationException)2 NoSyncSourceFoundException (com.torodb.mongodb.repl.exceptions.NoSyncSourceFoundException)2 BackendPasswordConfig (com.torodb.packaging.config.model.backend.BackendPasswordConfig)2