Search in sources :

Example 1 with Cluster

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

the class NodeOnlineCheckerTest method testExchangeWithException.

@Test
public void testExchangeWithException() {
    Node node = new Node("http://www.predic8.de", 80);
    Exchange exc = new Exchange(null);
    exc.getDestinations().add(0, "http://www.predic8.de:80");
    exc.setNodeException(0, new Exception());
    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);
    noc.handle(exc);
    assertEquals(Node.Status.DOWN, cl.getNode(node).getStatus());
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) URISyntaxException(java.net.URISyntaxException) Test(org.junit.Test)

Example 2 with Cluster

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

the class LoadBalancerMultiple4Test method test.

@Test
public void test() throws IOException, InterruptedException {
    File base = getExampleDir("loadbalancer-multiple-4");
    AssertUtils.replaceInFile(new File(base, "proxies.xml"), "8080", "3023");
    AssertUtils.replaceInFile(new File(base, "proxies.xml"), "8081", "3024");
    Process2 sl = new Process2.Builder().in(base).script("service-proxy").waitForMembrane().start();
    try {
        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"));
        assertEquals(3, LoadBalancerUtil.getRespondingNode("http://localhost:3024/service"));
        assertEquals(4, LoadBalancerUtil.getRespondingNode("http://localhost:3024/service"));
        assertEquals(3, LoadBalancerUtil.getRespondingNode("http://localhost:3024/service"));
        assertEquals(4, LoadBalancerUtil.getRespondingNode("http://localhost:3024/service"));
        String status = getAndAssert200("http://localhost:9000/admin/clusters/show?balancer=balancer1&cluster=Default");
        assertNodeStatus(status, "localhost", 4000, "UP");
        assertNodeStatus(status, "localhost", 4001, "UP");
        getAndAssert(204, "http://localhost:9010/clustermanager/down?balancer=balancer1&host=localhost&port=4001");
        Thread.sleep(1000);
        status = getAndAssert200("http://localhost:9000/admin/clusters/show?balancer=balancer1&cluster=Default");
        assertNodeStatus(status, "localhost", 4000, "UP");
        assertNodeStatus(status, "localhost", 4001, "DOWN");
        assertEquals(1, LoadBalancerUtil.getRespondingNode("http://localhost:3023/service"));
        assertEquals(1, 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)

Example 3 with Cluster

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

the class DynamicAdminPageInterceptor method handleNodeSessionsRequest.

@Mapping("/admin/node/sessions/?(\\?.*)?")
public Response handleNodeSessionsRequest(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 {
            h2().text("Node " + params.get("host") + ":" + params.get("port")).end();
            h3().text("Sessions").end();
            createSessionsTable(BalancerUtil.lookupBalancer(router, getBalancerParam(params)).getSessionsByNode(params.get("cluster"), new Node(params.get("host"), Integer.parseInt(params.get("port")))));
        }
    }.createPage());
}
Also used : StringWriter(java.io.StringWriter) Node(com.predic8.membrane.core.interceptor.balancer.Node)

Example 4 with Cluster

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

the class AdminPageBuilder method createNodesTable.

protected void createNodesTable(String balancerName) throws Exception {
    table().attr("cellpadding", "0", "cellspacing", "0", "border", "0", "class", "display nodesTable");
    thead();
    tr();
    createThs("Node", "Status", "Count", "Errors", "Time since last up", "Sessions", "Current Threads", "Action");
    end();
    end();
    tbody();
    for (Node n : BalancerUtil.lookupBalancer(router, balancerName).getAllNodesByCluster(params.get("cluster"))) {
        tr();
        td();
        createLink("" + n.getHost() + ":" + n.getPort(), "node", "show", createQueryString("balancer", balancerName, "cluster", params.get("cluster"), "host", n.getHost(), "port", "" + n.getPort()));
        end();
        createTds(getStatusString(n), "" + n.getCounter(), String.format("%1$.2f%%", n.getErrors() * 100), formatDurationHMS(System.currentTimeMillis() - n.getLastUpTime()), "" + BalancerUtil.lookupBalancer(router, balancerName).getSessionsByNode(params.get("cluster"), n).size(), "" + n.getThreads());
        td();
        createIcon("ui-icon-eject", "node", "takeout", "takeout", createQuery4Node(n));
        createIcon("ui-icon-circle-arrow-n", "node", "up", "up", createQuery4Node(n));
        createIcon("ui-icon-circle-arrow-s", "node", "down", "down", createQuery4Node(n));
        if (!readOnly)
            createIcon("ui-icon-trash", "node", "delete", "delete", createQuery4Node(n));
        end();
        end();
    }
    end();
    end();
    script().raw("$(document).ready(function() { $('.nodesTable').dataTable({'bJQueryUI': true, \"bPaginate\": false}); } );").end();
}
Also used : Node(com.predic8.membrane.core.interceptor.balancer.Node)

Example 5 with Cluster

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

the class AdminPageBuilder method createClustersTable.

protected void createClustersTable(String balancerName) throws UnsupportedEncodingException {
    table().attr("cellpadding", "0", "cellspacing", "0", "border", "0", "class", "display clustersTable");
    thead();
    tr();
    createThs("Name", "#Nodes", "Health");
    end();
    end();
    tbody();
    for (Cluster c : BalancerUtil.lookupBalancer(router, balancerName).getClusters()) {
        tr();
        td();
        createLink(!c.getName().isEmpty() ? c.getName() : "<unnamed>", "clusters", "show", createQueryString("balancer", balancerName, "cluster", c.getName()));
        end();
        createTds(String.valueOf(BalancerUtil.lookupBalancer(router, balancerName).getAllNodesByCluster(c.getName()).size()), getFormatedHealth(balancerName, c.getName()));
        end();
    }
    end();
    end();
}
Also used : Cluster(com.predic8.membrane.core.interceptor.balancer.Cluster)

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