Search in sources :

Example 16 with Node

use of com.predic8.membrane.core.interceptor.balancer.Node 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());
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Test(org.junit.Test)

Example 17 with Node

use of com.predic8.membrane.core.interceptor.balancer.Node 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());
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Test(org.junit.Test)

Example 18 with Node

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

the class LoadBalancingWithClusterManagerTest method startNode.

private DummyWebServiceInterceptor startNode(HttpRouter node, int port) throws Exception {
    DummyWebServiceInterceptor service1 = new DummyWebServiceInterceptor();
    node.addUserFeatureInterceptor(service1);
    node.getRuleManager().addProxyAndOpenPortIfNew(new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", port), "thomas-bayer.com", 80));
    node.init();
    return service1;
}
Also used : ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) DummyWebServiceInterceptor(com.predic8.membrane.core.services.DummyWebServiceInterceptor)

Example 19 with Node

use of com.predic8.membrane.core.interceptor.balancer.Node 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());
}
Also used : StringWriter(java.io.StringWriter) Node(com.predic8.membrane.core.interceptor.balancer.Node) URLParamUtil.createQueryString(com.predic8.membrane.core.util.URLParamUtil.createQueryString)

Aggregations

Exchange (com.predic8.membrane.core.exchange.Exchange)5 Node (com.predic8.membrane.core.interceptor.balancer.Node)5 ContainerNode (com.predic8.membrane.core.interceptor.xmlcontentfilter.SimpleXPathParser.ContainerNode)4 ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)4 MCElement (com.predic8.membrane.annot.MCElement)3 Test (org.junit.Test)3 Element (org.w3c.dom.Element)3 LoadBalancingInterceptor (com.predic8.membrane.core.interceptor.balancer.LoadBalancingInterceptor)2 Node (com.predic8.membrane.core.interceptor.xmlcontentfilter.SimpleXPathParser.Node)2 RoundBracketNode (com.predic8.membrane.core.interceptor.xmlcontentfilter.SimpleXPathParser.RoundBracketNode)2 SquareBracketNode (com.predic8.membrane.core.interceptor.xmlcontentfilter.SimpleXPathParser.SquareBracketNode)2 StringNode (com.predic8.membrane.core.interceptor.xmlcontentfilter.SimpleXPathParser.StringNode)2 UnparsedStringNode (com.predic8.membrane.core.interceptor.xmlcontentfilter.SimpleXPathParser.UnparsedStringNode)2 StringWriter (java.io.StringWriter)2 ArrayList (java.util.ArrayList)2 QName (javax.xml.namespace.QName)2 Node (org.w3c.dom.Node)2 NodeList (org.w3c.dom.NodeList)2 Router (com.predic8.membrane.core.Router)1 EtcdNodeInformation (com.predic8.membrane.core.cloud.etcd.EtcdNodeInformation)1