Package com.netflix.loadbalancer

Examples of com.netflix.loadbalancer.Server


        }
        Collection<Server> servers = transform(nodes, new Function<ServiceNode, Server>() {
            @Nullable
            @Override
            public Server apply(@Nullable ServiceNode node) {
                return new Server(node.getAddress(), node.getServicePort());
            }
        });

        return newArrayList(servers);
    }
View Full Code Here


  public AbstractLoadBalancer lb() {
    return lb;
  }

  @Override public Request apply(RequestTemplate input) {
    Server currentServer = lb.chooseServer(null);
    String url = format("%s://%s", scheme, currentServer.getHostPort());
    input.insert(0, url);
    try {
      return input.request();
    } finally {
      lb.getLoadBalancerStats().incrementNumRequests(currentServer);
View Full Code Here

        List<Server> serverList = new ArrayList<Server>();
        for (String serverStr : listString.split(",")) {
            String[] parts = serverStr.split(":");
            if (parts.length != 2)
                throw new IllegalArgumentException("Invalid server (must be in host:port format): " + serverStr);
            serverList.add(new Server(parts[0], Integer.parseInt(parts[1])));
        }
        return serverList;
    }
View Full Code Here

    protected List<Server> pollForServers() {
        try {
            List<Server> activeNodeList = getNodeList();
            int activeNodeCount = activeNodeList.size();
            Server server = null;
            List<String> hosts = null;
            String path = "/?endpoint";

            // we want to try a different node on failure until we try every active node (HttpClient will auto-retry
            // 500s and some IOEs), but we don't want to start with the same node each time.
            for (int i = 0; i < activeNodeCount; i++) {
                try {
                    // get next server in the list (trying to distribute this call among active nodes)
                    // note: the extra modulus logic is there just in case requestCounter wraps around to a negative value
                    server = activeNodeList.get((requestCounter++ % activeNodeCount + activeNodeCount) % activeNodeCount);

                    HttpGet request = new HttpGet(protocol + "://" + server + path);
                    logger.debug("endpoint query attempt #" + (i + 1) + ": trying " + server);

                    // format date
                    String rfcDate;
                    synchronized (rfc822DateFormat) {
                        rfcDate = rfc822DateFormat.format(new Date());
                    }

                    // generate signature
                    String canonicalString = "GET\n\n\n" + rfcDate + "\n" + path;
                    String signature = getSignature(canonicalString, secret);

                    // add date and auth headers
                    request.addHeader("Date", rfcDate);
                    request.addHeader("Authorization", "AWS " + user + ":" + signature);

                    // send request
                    HttpResponse response = httpClient.execute(request);
                    if (response.getStatusLine().getStatusCode() > 299) {
                        EntityUtils.consumeQuietly(response.getEntity());
                        throw new RuntimeException("received error response: " + response.getStatusLine());
                    }

                    logger.debug("received success response: " + response.getStatusLine());
                    hosts = parseResponse(response);
                    break;
                } catch (Exception e) {
                    logger.warn("error polling for endpoints on " + server, e);
                }
            }

            if (hosts == null)
                throw new RuntimeException("Exhausted all nodes; no response available");

            List<Server> updatedNodeList = new ArrayList<Server>();
            for (String host : hosts) {
                updatedNodeList.add(new Server(host, port));
            }
            setNodeList(updatedNodeList);
        } catch (Exception e) {
            logger.warn("Unable to poll for servers", e);
        }
View Full Code Here

    protected Server[] toServers(List<URI> uris) {
        List<Server> servers = new ArrayList<Server>();
        for (URI uri : uris) {
            int port = uri.getPort();
            if (port == -1) port = (uri.getScheme().equalsIgnoreCase("https") ? 443 : 80);
            servers.add(new Server(uri.getHost(), port));
        }
        return servers.toArray(new Server[servers.size()]);
    }
View Full Code Here

            });
        }
        executors.shutdown();
        waitLatch.await();

        Server downServer = new Server("localhost", servers.get(0).getPort());
        downServer.setAlive(true);

        ConnectionPool.SuroConnection downConnection = new ConnectionPool.SuroConnection(
                downServer,
                injector.getInstance(ClientConfig.class),
                true);
View Full Code Here

        createInjector();

        ILoadBalancer lb = mock(ILoadBalancer.class);
        List<Server> servers = new LinkedList<Server>();
        for (SuroServer4Test suroServer4Test : this.servers) {
            servers.add(new Server("localhost", suroServer4Test.getPort()));
        }
        when(lb.getServerList(true)).thenReturn(servers);

        ConnectionPool pool = new ConnectionPool(injector.getInstance(ClientConfig.class), lb);
        assertTrue(pool.getPoolSize() >= 1);
View Full Code Here

        createInjector();

        ILoadBalancer lb = mock(ILoadBalancer.class);
        List<Server> servers = new LinkedList<Server>();
        for (SuroServer4Test suroServer4Test : this.servers) {
            servers.add(new Server("localhost", suroServer4Test.getPort()));
        }
        when(lb.getServerList(true)).thenReturn(servers);

        ConnectionPool pool = new ConnectionPool(injector.getInstance(ClientConfig.class), lb);
        assertEquals(pool.getPoolSize(), 3);
View Full Code Here

        createInjector();

        final ILoadBalancer lb = mock(ILoadBalancer.class);
        List<Server> servers = new LinkedList<Server>();
        for (SuroServer4Test suroServer4Test : this.servers) {
            servers.add(new Server("localhost", suroServer4Test.getPort()));
        }
        when(lb.getServerList(true)).thenReturn(servers);

        final AtomicBoolean passed = new AtomicBoolean(false);
        Thread t = new Thread(new Runnable() {
View Full Code Here

    @Test
    public void pingTest() throws Exception {
        final SuroServer4Test server4Test = new SuroServer4Test();
        server4Test.start();
        SuroPing ping = new SuroPing();
        Server server = new Server("localhost", server4Test.getPort());
        assertEquals(true, ping.isAlive(server));
        server4Test.shutdown();
    }
View Full Code Here

TOP

Related Classes of com.netflix.loadbalancer.Server

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.