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