Search in sources :

Example 1 with LoadBalancingInterceptor

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

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

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

the class EtcdBasedConfigurator method setUpClusterNode.

private void setUpClusterNode(EtcdNodeInformation node) {
    log.info("Creating " + node);
    ServiceProxy sp = runningServiceProxyForModule.get(node.getModule());
    LoadBalancingInterceptor lbi = (LoadBalancingInterceptor) sp.getInterceptors().get(0);
    lbi.getClusterManager().getClusters().get(0).nodeUp(new Node(node.getTargetHost(), Integer.parseInt(node.getTargetPort())));
    runningNodesForModule.get(node.getModule()).add(node);
}
Also used : LoadBalancingInterceptor(com.predic8.membrane.core.interceptor.balancer.LoadBalancingInterceptor) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) Node(com.predic8.membrane.core.interceptor.balancer.Node)

Example 4 with LoadBalancingInterceptor

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

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

the class EtcdBasedConfigurator method shutdownRunningClusterNode.

private void shutdownRunningClusterNode(EtcdNodeInformation node) {
    log.info("Destroying " + node);
    ServiceProxy sp = runningServiceProxyForModule.get(node.getModule());
    LoadBalancingInterceptor lbi = (LoadBalancingInterceptor) sp.getInterceptors().get(0);
    lbi.getClusterManager().removeNode(Balancer.DEFAULT_NAME, baseUrl, port);
    runningNodesForModule.get(node.getModule()).remove(node);
}
Also used : LoadBalancingInterceptor(com.predic8.membrane.core.interceptor.balancer.LoadBalancingInterceptor) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy)

Aggregations

ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)8 LoadBalancingInterceptor (com.predic8.membrane.core.interceptor.balancer.LoadBalancingInterceptor)7 ServiceProxyKey (com.predic8.membrane.core.rules.ServiceProxyKey)6 Exchange (com.predic8.membrane.core.exchange.Exchange)4 HttpRouter (com.predic8.membrane.core.HttpRouter)3 Test (org.junit.Test)3 URISyntaxException (java.net.URISyntaxException)2 Before (org.junit.Before)2 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 ByThreadStrategy (com.predic8.membrane.core.interceptor.balancer.ByThreadStrategy)1 Node (com.predic8.membrane.core.interceptor.balancer.Node)1 RoundRobinStrategy (com.predic8.membrane.core.interceptor.balancer.RoundRobinStrategy)1 Rule (com.predic8.membrane.core.rules.Rule)1 DummyWebServiceInterceptor (com.predic8.membrane.core.services.DummyWebServiceInterceptor)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 BeansException (org.springframework.beans.BeansException)1