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