Search in sources :

Example 6 with HostAndPort

use of com.google.common.net.HostAndPort in project legacy-jclouds-examples by jclouds.

the class CloudServersPublish method awaitSsh.

private void awaitSsh(String ip) throws TimeoutException {
    SocketOpen socketOpen = compute.getContext().utils().injector().getInstance(SocketOpen.class);
    Predicate<HostAndPort> socketTester = retry(socketOpen, 300, 5, 5, SECONDS);
    socketTester.apply(HostAndPort.fromParts(ip, 22));
}
Also used : SocketOpen(org.jclouds.predicates.SocketOpen) HostAndPort(com.google.common.net.HostAndPort)

Example 7 with HostAndPort

use of com.google.common.net.HostAndPort in project legacy-jclouds-examples by jclouds.

the class MainApp method main.

public static void main(String[] args) {
    if (args.length < PARAMETERS)
        throw new IllegalArgumentException(INVALID_SYNTAX);
    String provider = args[0];
    String identity = args[1];
    String credential = args[2];
    String groupName = args[3];
    Action action = Action.valueOf(args[4].toUpperCase());
    // note that you can check if a provider is present ahead of time
    checkArgument(contains(allKeys, provider), "provider %s not in supported list: %s", provider, allKeys);
    MinecraftController controller = initController(provider, identity, credential, groupName);
    System.out.printf(">> initialized controller %s%n", controller);
    try {
        switch(action) {
            case ADD:
                System.out.printf(">> adding a server to group %s%n", groupName);
                HostAndPort server = controller.add();
                System.out.printf("<< server %s%n", server);
                break;
            case LIST:
                System.out.printf(">> listing servers in group %s%n", groupName);
                Iterable<HostAndPort> servers = controller.list();
                System.out.printf("<< servers %s%n", servers);
                break;
            case TAIL:
                System.out.printf(">> tailing all servers in group %s%n", groupName);
                Map<HostAndPort, String> output = controller.tail();
                System.out.printf("<< output %s%n", output);
                break;
            case PIDS:
                System.out.printf(">> getting pids of all servers in group %s%n", groupName);
                Map<HostAndPort, String> pids = controller.pids();
                System.out.printf("<< pids %s%n", pids);
                break;
            case DESTROY:
                System.out.printf(">> destroying group %s%n", groupName);
                Iterable<HostAndPort> destroyed = controller.destroy();
                System.out.printf("<< destroyed servers %s%n", destroyed);
                break;
        }
    } catch (RuntimeException e) {
        error = 1;
        e.printStackTrace();
    } finally {
        controller.close();
        System.exit(error);
    }
}
Also used : HostAndPort(com.google.common.net.HostAndPort)

Example 8 with HostAndPort

use of com.google.common.net.HostAndPort in project PayFile by mikehearn.

the class ConnectServerController method initialize.

// Called by FXMLLoader
public void initialize() {
    server.textProperty().addListener((observableValue, prev, current) -> connectBtn.setDisable(current.trim().isEmpty()));
    defaultTitle = titleLabel.getText();
    // Restore the server used last time, minus the port part if it was the default.
    HostAndPort lastServer = Settings.getLastServer();
    if (lastServer != null)
        server.setText(lastServer.getPort() == PayFileClient.PORT ? lastServer.getHostText() : lastServer.toString());
}
Also used : HostAndPort(com.google.common.net.HostAndPort)

Example 9 with HostAndPort

use of com.google.common.net.HostAndPort in project PayFile by mikehearn.

the class ConnectServerController method maybeSettleLastServer.

/**
     * Possibly reconnect to the last paid server and ask it to give us back the money. Note that after 24 hours this
     * channel will expire anyway, so if the server is gone, it's not the end of the world, we'll still get the money
     * back. The returned future completes immediately if nothing needs to be done.
     */
private CompletableFuture<Void> maybeSettleLastServer(HostAndPort newServerName) {
    final HostAndPort lastPaidServer = Settings.getLastPaidServer();
    // If we didn't have a payment channel, or we did but it's with the same server we're connecting to, ignore.
    if (lastPaidServer == null || newServerName.equals(lastPaidServer))
        return CompletableFuture.completedFuture(null);
    BigInteger amountInLastServer = PayFileClient.getBalanceForServer(lastPaidServer.getHostText(), lastPaidServer.getPort(), Main.bitcoin.wallet());
    // If the last server we paid was already settled, ignore.
    if (amountInLastServer.compareTo(BigInteger.ZERO) == 0)
        return CompletableFuture.completedFuture(null);
    // Otherwise we have some money locked up with the last server. Ask for it back.
    final CompletableFuture<Void> future = new CompletableFuture<>();
    titleLabel.setText(String.format("Contacting %s to request early settlement ...", lastPaidServer));
    log.info("Connecting to {}", lastPaidServer);
    Main.connect(lastPaidServer, REFUND_CONNECT_TIMEOUT_MSEC).whenCompleteAsync((client, ex) -> {
        if (ex == null) {
            log.info("Connected. Requesting early settlement.");
            titleLabel.setText("Requesting early settlement ...");
            client.settlePaymentChannel().whenCompleteAsync((v, settleEx) -> {
                if (settleEx == null) {
                    log.info("Settled. Proceeding ...");
                    client.disconnect();
                    future.complete(null);
                } else {
                    crashAlert(settleEx);
                }
            }, Platform::runLater);
        } else {
            log.error("Failed to connect", ex);
            titleLabel.setText(defaultTitle);
            informUserTheyMustWait(lastPaidServer);
        }
    }, Platform::runLater);
    return future;
}
Also used : HostAndPort(com.google.common.net.HostAndPort) CompletableFuture(java.util.concurrent.CompletableFuture) Platform(javafx.application.Platform) BigInteger(java.math.BigInteger)

Example 10 with HostAndPort

use of com.google.common.net.HostAndPort in project zipkin by openzipkin.

the class DefaultSessionFactory method parseContactPoints.

static List<InetSocketAddress> parseContactPoints(Cassandra3Storage cassandra) {
    List<InetSocketAddress> result = new LinkedList<>();
    for (String contactPoint : cassandra.contactPoints.split(",")) {
        HostAndPort parsed = HostAndPort.fromString(contactPoint);
        result.add(new InetSocketAddress(parsed.getHostText(), parsed.getPortOrDefault(9042)));
    }
    return result;
}
Also used : HostAndPort(com.google.common.net.HostAndPort) InetSocketAddress(java.net.InetSocketAddress) LinkedList(java.util.LinkedList)

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