Search in sources :

Example 1 with Balancer

use of com.predic8.membrane.core.interceptor.balancer.Balancer 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 2 with Balancer

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

the class LoadBalancingInterceptorTest method setUp.

@Before
public void setUp() throws Exception {
    service1 = new HttpRouter();
    mockInterceptor1 = new DummyWebServiceInterceptor();
    ServiceProxy sp1 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 2000), "thomas-bayer.com", 80);
    sp1.getInterceptors().add(new AbstractInterceptor() {

        @Override
        public Outcome handleResponse(Exchange exc) throws Exception {
            exc.getResponse().getHeader().add("Connection", "close");
            return Outcome.CONTINUE;
        }
    });
    sp1.getInterceptors().add(mockInterceptor1);
    service1.getRuleManager().addProxyAndOpenPortIfNew(sp1);
    service1.init();
    service2 = new HttpRouter();
    mockInterceptor2 = new DummyWebServiceInterceptor();
    ServiceProxy sp2 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 3000), "thomas-bayer.com", 80);
    sp2.getInterceptors().add(new AbstractInterceptor() {

        @Override
        public Outcome handleResponse(Exchange exc) throws Exception {
            exc.getResponse().getHeader().add("Connection", "close");
            return Outcome.CONTINUE;
        }
    });
    sp2.getInterceptors().add(mockInterceptor2);
    service2.getRuleManager().addProxyAndOpenPortIfNew(sp2);
    service2.init();
    balancer = new HttpRouter();
    ServiceProxy sp3 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 7000), "thomas-bayer.com", 80);
    balancingInterceptor = new LoadBalancingInterceptor();
    balancingInterceptor.setName("Default");
    sp3.getInterceptors().add(balancingInterceptor);
    balancer.getRuleManager().addProxyAndOpenPortIfNew(sp3);
    enableFailOverOn5XX(balancer);
    balancer.init();
    BalancerUtil.lookupBalancer(balancer, "Default").up("Default", "localhost", 2000);
    BalancerUtil.lookupBalancer(balancer, "Default").up("Default", "localhost", 3000);
    roundRobinStrategy = new RoundRobinStrategy();
    byThreadStrategy = new ByThreadStrategy();
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) LoadBalancingInterceptor(com.predic8.membrane.core.interceptor.balancer.LoadBalancingInterceptor) ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) ByThreadStrategy(com.predic8.membrane.core.interceptor.balancer.ByThreadStrategy) Outcome(com.predic8.membrane.core.interceptor.Outcome) AbstractInterceptor(com.predic8.membrane.core.interceptor.AbstractInterceptor) HttpRouter(com.predic8.membrane.core.HttpRouter) RoundRobinStrategy(com.predic8.membrane.core.interceptor.balancer.RoundRobinStrategy) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) DummyWebServiceInterceptor(com.predic8.membrane.core.services.DummyWebServiceInterceptor) Before(org.junit.Before)

Example 3 with Balancer

use of com.predic8.membrane.core.interceptor.balancer.Balancer 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 4 with Balancer

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

the class AdminPageBuilder method createBalancersTable.

protected void createBalancersTable() throws UnsupportedEncodingException {
    table().attr("cellpadding", "0", "cellspacing", "0", "border", "0", "class", "display balancersTable");
    thead();
    tr();
    createThs("Name", "Failover", "Health");
    end();
    end();
    tbody();
    for (LoadBalancingInterceptor loadBalancingInterceptor : BalancerUtil.collectBalancers(router)) {
        tr();
        td();
        createLink(loadBalancingInterceptor.getName(), "clusters", null, createQueryString("balancer", loadBalancingInterceptor.getName()));
        end();
        createTds(loadBalancingInterceptor.isFailOver() ? "yes" : "no", getFormatedHealth(loadBalancingInterceptor.getName()));
        end();
    }
    end();
    end();
}
Also used : LoadBalancingInterceptor(com.predic8.membrane.core.interceptor.balancer.LoadBalancingInterceptor)

Example 5 with Balancer

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

the class MultipleLoadBalancersTest method setUp.

@Before
public void setUp() throws Exception {
    service1 = new MockService(2001);
    service2 = new MockService(2002);
    service11 = new MockService(2011);
    service12 = new MockService(2012);
    balancer = new HttpRouter();
    balancingInterceptor1 = createBalancingInterceptor(7000, "Default");
    balancingInterceptor2 = createBalancingInterceptor(7001, "Balancer2");
    BalancerUtil.lookupBalancer(balancer, "Default").up("Default", "localhost", service1.port);
    BalancerUtil.lookupBalancer(balancer, "Default").up("Default", "localhost", service2.port);
    BalancerUtil.lookupBalancer(balancer, "Balancer2").up("Default", "localhost", service11.port);
    BalancerUtil.lookupBalancer(balancer, "Balancer2").up("Default", "localhost", service12.port);
    roundRobinStrategy1 = new RoundRobinStrategy();
    roundRobinStrategy2 = new RoundRobinStrategy();
}
Also used : HttpRouter(com.predic8.membrane.core.HttpRouter) RoundRobinStrategy(com.predic8.membrane.core.interceptor.balancer.RoundRobinStrategy) Before(org.junit.Before)

Aggregations

LoadBalancingInterceptor (com.predic8.membrane.core.interceptor.balancer.LoadBalancingInterceptor)3 HttpRouter (com.predic8.membrane.core.HttpRouter)2 Cluster (com.predic8.membrane.core.interceptor.balancer.Cluster)2 Node (com.predic8.membrane.core.interceptor.balancer.Node)2 RoundRobinStrategy (com.predic8.membrane.core.interceptor.balancer.RoundRobinStrategy)2 Before (org.junit.Before)2 Exchange (com.predic8.membrane.core.exchange.Exchange)1 AbstractInterceptor (com.predic8.membrane.core.interceptor.AbstractInterceptor)1 Interceptor (com.predic8.membrane.core.interceptor.Interceptor)1 Outcome (com.predic8.membrane.core.interceptor.Outcome)1 AccessControlInterceptor (com.predic8.membrane.core.interceptor.acl.AccessControlInterceptor)1 Balancer (com.predic8.membrane.core.interceptor.balancer.Balancer)1 ByThreadStrategy (com.predic8.membrane.core.interceptor.balancer.ByThreadStrategy)1 ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)1 ServiceProxyKey (com.predic8.membrane.core.rules.ServiceProxyKey)1 DummyWebServiceInterceptor (com.predic8.membrane.core.services.DummyWebServiceInterceptor)1 URLParamUtil.createQueryString (com.predic8.membrane.core.util.URLParamUtil.createQueryString)1 Process2 (com.predic8.membrane.examples.Process2)1 File (java.io.File)1 StringWriter (java.io.StringWriter)1