use of com.predic8.membrane.core.interceptor.balancer.Cluster in project service-proxy by membrane.
the class AdminPageBuilder method getFormatedHealth.
private String getFormatedHealth(String balancerName) {
Balancer balancer = BalancerUtil.lookupBalancer(router, balancerName);
int available = 0, all = 0;
for (Cluster c : balancer.getClusters()) {
all += balancer.getAllNodesByCluster(c.getName()).size();
available += balancer.getAvailableNodesByCluster(c.getName()).size();
}
return String.format("%d up/ %d down", available, all - available);
}
use of com.predic8.membrane.core.interceptor.balancer.Cluster in project service-proxy by membrane.
the class NodeOnlineCheckerTest method testPutNodesBackOnline.
@Test
public void testPutNodesBackOnline() throws InterruptedException {
Node node = new Node("http://www.predic8.de", 80);
Exchange exc = new Exchange(null);
exc.getDestinations().add(0, "http://www.predic8.de:80");
exc.setNodeStatusCode(0, 500);
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);
final int limit = 10;
noc.setNodeCounterLimit5XX(limit);
noc.setRetryTimeInSeconds(1);
assertEquals(Node.Status.UP, cl.getNode(node).getStatus());
for (int i = 0; i < limit + 1; i++) {
noc.handle(exc);
}
assertEquals(Node.Status.DOWN, cl.getNode(node).getStatus());
noc.putNodesBackUp();
assertEquals(Node.Status.DOWN, cl.getNode(node).getStatus());
Thread.sleep(noc.getRetryTimeInSeconds() * 1000);
noc.putNodesBackUp();
assertEquals(Node.Status.UP, cl.getNode(node).getStatus());
}
use of com.predic8.membrane.core.interceptor.balancer.Cluster in project service-proxy by membrane.
the class NodeOnlineCheckerTest method testExchangeWithBadStatuscode.
@Test
public void testExchangeWithBadStatuscode() {
Node node = new Node("http://www.predic8.de", 80);
Exchange exc = new Exchange(null);
exc.getDestinations().add(0, "http://www.predic8.de:80");
exc.setNodeStatusCode(0, 500);
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);
final int limit = 10;
noc.setNodeCounterLimit5XX(limit);
for (int i = 0; i < limit; i++) {
noc.handle(exc);
}
assertEquals(Node.Status.UP, cl.getNode(node).getStatus());
exc.setNodeStatusCode(0, 400);
noc.handle(exc);
assertEquals(Node.Status.UP, cl.getNode(node).getStatus());
exc.setNodeStatusCode(0, 500);
for (int i = 0; i < limit + 1; i++) {
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 DynamicAdminPageInterceptor method handleNodeShowRequest.
@Mapping("/admin/node/show/?(\\?.*)?")
public Response handleNodeShowRequest(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 {
String balancer = getBalancerParam(params);
h2().text("Node " + params.get("host") + ":" + params.get("port") + " (" + "Cluster " + params.get("cluster") + " of Balancer " + balancer + ")").end();
h3().text("Status Codes").end();
Node n = BalancerUtil.lookupBalancer(router, balancer).getNode(params.get("cluster"), params.get("host"), Integer.parseInt(params.get("port")));
createStatusCodesTable(n.getStatisticsByStatusCodes());
p().text("Total requests: " + n.getCounter()).end();
p().text("Current threads: " + n.getThreads()).end();
p().text("Requests without responses: " + n.getLost()).end();
span().classAttr("mb-button");
createLink("Reset Counter", "node", "reset", createQueryString("balancer", balancer, "cluster", params.get("cluster"), "host", n.getHost(), "port", "" + n.getPort()));
end();
span().classAttr("mb-button");
createLink("Show Sessions", "node", "sessions", createQueryString("balancer", balancer, "cluster", params.get("cluster"), "host", n.getHost(), "port", "" + n.getPort()));
end();
}
}.createPage());
}
use of com.predic8.membrane.core.interceptor.balancer.Cluster in project service-proxy by membrane.
the class LoadBalancerBasic1Test method test.
@Test
public void test() throws IOException, InterruptedException {
File base = getExampleDir("loadbalancer-basic-1");
AssertUtils.replaceInFile(new File(base, "proxies.xml"), "8080", "3023");
Process2 sl = new Process2.Builder().in(base).script("service-proxy").waitForMembrane().start();
try {
assertEquals(1, LoadBalancerUtil.getRespondingNode("http://localhost:4000/"));
assertEquals(2, LoadBalancerUtil.getRespondingNode("http://localhost:4001/"));
assertEquals(3, LoadBalancerUtil.getRespondingNode("http://localhost:4002/"));
addLBNodeViaHTML("http://localhost:9000/admin/", "localhost", 4000);
addLBNodeViaHTML("http://localhost:9000/admin/", "localhost", 4001);
Thread.sleep(1000);
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"));
getAndAssert(204, "http://localhost:9010/clustermanager/up?host=localhost&port=4002");
AssertUtils.assertContains("localhost:4002", getAndAssert200("http://localhost:9000/admin/clusters/show?cluster=Default"));
assertEquals(3, 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:3023/service"));
} finally {
sl.killScript();
}
}
Aggregations