Search in sources :

Example 6 with Cluster

use of com.predic8.membrane.core.interceptor.balancer.Cluster in project service-proxy by membrane.

the class AdminPageBuilder method getFormatedHealth.

private String getFormatedHealth(String balancerName) {
    Balancer balancer = BalancerUtil.lookupBalancer(router, balancerName);
    int available = 0, all = 0;
    for (Cluster c : balancer.getClusters()) {
        all += balancer.getAllNodesByCluster(c.getName()).size();
        available += balancer.getAvailableNodesByCluster(c.getName()).size();
    }
    return String.format("%d up/ %d down", available, all - available);
}
Also used : Balancer(com.predic8.membrane.core.interceptor.balancer.Balancer) Cluster(com.predic8.membrane.core.interceptor.balancer.Cluster)

Example 7 with Cluster

use of com.predic8.membrane.core.interceptor.balancer.Cluster in project service-proxy by membrane.

the class NodeOnlineCheckerTest method testPutNodesBackOnline.

@Test
public void testPutNodesBackOnline() throws InterruptedException {
    Node node = new Node("http://www.predic8.de", 80);
    Exchange exc = new Exchange(null);
    exc.getDestinations().add(0, "http://www.predic8.de:80");
    exc.setNodeStatusCode(0, 500);
    LoadBalancingInterceptor lbi = new LoadBalancingInterceptor();
    Cluster cl = lbi.getClusterManager().getClusters().get(0);
    cl.nodeUp(node);
    assertEquals(Node.Status.UP, cl.getNode(node).getStatus());
    NodeOnlineChecker noc = new NodeOnlineChecker();
    lbi.setNodeOnlineChecker(noc);
    final int limit = 10;
    noc.setNodeCounterLimit5XX(limit);
    noc.setRetryTimeInSeconds(1);
    assertEquals(Node.Status.UP, cl.getNode(node).getStatus());
    for (int i = 0; i < limit + 1; i++) {
        noc.handle(exc);
    }
    assertEquals(Node.Status.DOWN, cl.getNode(node).getStatus());
    noc.putNodesBackUp();
    assertEquals(Node.Status.DOWN, cl.getNode(node).getStatus());
    Thread.sleep(noc.getRetryTimeInSeconds() * 1000);
    noc.putNodesBackUp();
    assertEquals(Node.Status.UP, cl.getNode(node).getStatus());
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Test(org.junit.Test)

Example 8 with Cluster

use of com.predic8.membrane.core.interceptor.balancer.Cluster in project service-proxy by membrane.

the class NodeOnlineCheckerTest method testExchangeWithBadStatuscode.

@Test
public void testExchangeWithBadStatuscode() {
    Node node = new Node("http://www.predic8.de", 80);
    Exchange exc = new Exchange(null);
    exc.getDestinations().add(0, "http://www.predic8.de:80");
    exc.setNodeStatusCode(0, 500);
    LoadBalancingInterceptor lbi = new LoadBalancingInterceptor();
    Cluster cl = lbi.getClusterManager().getClusters().get(0);
    cl.nodeUp(node);
    assertEquals(Node.Status.UP, cl.getNode(node).getStatus());
    NodeOnlineChecker noc = new NodeOnlineChecker();
    lbi.setNodeOnlineChecker(noc);
    final int limit = 10;
    noc.setNodeCounterLimit5XX(limit);
    for (int i = 0; i < limit; i++) {
        noc.handle(exc);
    }
    assertEquals(Node.Status.UP, cl.getNode(node).getStatus());
    exc.setNodeStatusCode(0, 400);
    noc.handle(exc);
    assertEquals(Node.Status.UP, cl.getNode(node).getStatus());
    exc.setNodeStatusCode(0, 500);
    for (int i = 0; i < limit + 1; i++) {
        noc.handle(exc);
    }
    assertEquals(Node.Status.DOWN, cl.getNode(node).getStatus());
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Test(org.junit.Test)

Example 9 with Cluster

use of com.predic8.membrane.core.interceptor.balancer.Cluster in project service-proxy by membrane.

the class DynamicAdminPageInterceptor method handleNodeShowRequest.

@Mapping("/admin/node/show/?(\\?.*)?")
public Response handleNodeShowRequest(final Map<String, String> params, String relativeRootPath) throws Exception {
    StringWriter writer = new StringWriter();
    return respond(new AdminPageBuilder(writer, router, relativeRootPath, params, readOnly) {

        @Override
        protected int getSelectedTab() {
            return TAB_ID_LOAD_BALANCING;
        }

        @Override
        protected void createTabContent() throws Exception {
            String balancer = getBalancerParam(params);
            h2().text("Node " + params.get("host") + ":" + params.get("port") + " (" + "Cluster " + params.get("cluster") + " of Balancer " + balancer + ")").end();
            h3().text("Status Codes").end();
            Node n = BalancerUtil.lookupBalancer(router, balancer).getNode(params.get("cluster"), params.get("host"), Integer.parseInt(params.get("port")));
            createStatusCodesTable(n.getStatisticsByStatusCodes());
            p().text("Total requests: " + n.getCounter()).end();
            p().text("Current threads: " + n.getThreads()).end();
            p().text("Requests without responses: " + n.getLost()).end();
            span().classAttr("mb-button");
            createLink("Reset Counter", "node", "reset", createQueryString("balancer", balancer, "cluster", params.get("cluster"), "host", n.getHost(), "port", "" + n.getPort()));
            end();
            span().classAttr("mb-button");
            createLink("Show Sessions", "node", "sessions", createQueryString("balancer", balancer, "cluster", params.get("cluster"), "host", n.getHost(), "port", "" + n.getPort()));
            end();
        }
    }.createPage());
}
Also used : StringWriter(java.io.StringWriter) Node(com.predic8.membrane.core.interceptor.balancer.Node) URLParamUtil.createQueryString(com.predic8.membrane.core.util.URLParamUtil.createQueryString)

Example 10 with Cluster

use of com.predic8.membrane.core.interceptor.balancer.Cluster in project service-proxy by membrane.

the class LoadBalancerBasic1Test method test.

@Test
public void test() throws IOException, InterruptedException {
    File base = getExampleDir("loadbalancer-basic-1");
    AssertUtils.replaceInFile(new File(base, "proxies.xml"), "8080", "3023");
    Process2 sl = new Process2.Builder().in(base).script("service-proxy").waitForMembrane().start();
    try {
        assertEquals(1, LoadBalancerUtil.getRespondingNode("http://localhost:4000/"));
        assertEquals(2, LoadBalancerUtil.getRespondingNode("http://localhost:4001/"));
        assertEquals(3, LoadBalancerUtil.getRespondingNode("http://localhost:4002/"));
        addLBNodeViaHTML("http://localhost:9000/admin/", "localhost", 4000);
        addLBNodeViaHTML("http://localhost:9000/admin/", "localhost", 4001);
        Thread.sleep(1000);
        assertEquals(1, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
        assertEquals(2, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
        assertEquals(1, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
        assertEquals(2, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
        getAndAssert(204, "http://localhost:9010/clustermanager/up?host=localhost&port=4002");
        AssertUtils.assertContains("localhost:4002", getAndAssert200("http://localhost:9000/admin/clusters/show?cluster=Default"));
        assertEquals(3, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
        assertEquals(1, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
        assertEquals(2, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
        assertEquals(3, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
    } finally {
        sl.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) File(java.io.File) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 Exchange (com.predic8.membrane.core.exchange.Exchange)3 Node (com.predic8.membrane.core.interceptor.balancer.Node)3 Process2 (com.predic8.membrane.examples.Process2)3 File (java.io.File)3 Cluster (com.predic8.membrane.core.interceptor.balancer.Cluster)2 StringWriter (java.io.StringWriter)2 Balancer (com.predic8.membrane.core.interceptor.balancer.Balancer)1 URLParamUtil.createQueryString (com.predic8.membrane.core.util.URLParamUtil.createQueryString)1 URISyntaxException (java.net.URISyntaxException)1 FileUtils.writeStringToFile (org.apache.commons.io.FileUtils.writeStringToFile)1