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());
}
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();
}
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);
}
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();
}
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);
}
Aggregations