Search in sources :

Example 51 with Node

use of org.mobicents.tools.heartbeat.api.Node in project load-balancer by RestComm.

the class CustomHeartbeatTest method testCustomHeartbeat.

@Test
public void testCustomHeartbeat() throws Exception {
    EventListener failureEventListener = new EventListener() {

        @Override
        public void uasAfterResponse(int statusCode, AppServer source) {
        }

        @Override
        public void uasAfterRequestReceived(String method, AppServer source) {
        // TODO Auto-generated method stub
        }

        @Override
        public void uacAfterRequestSent(String method, AppServer source) {
        // TODO Auto-generated method stub
        }

        @Override
        public void uacAfterResponse(int statusCode, AppServer source) {
            if (statusCode == 180) {
                ringingAppServer = source;
            } else {
                okAppServer = source;
            }
        }
    };
    for (AppServer as : servers) as.setEventListener(failureEventListener);
    shootist.callerSendsBye = true;
    String fromName = "sender";
    String fromHost = "sip-servlets.com";
    SipURI fromAddress = servers[0].protocolObjects.addressFactory.createSipURI(fromName, fromHost);
    String toUser = "replaces";
    String toHost = "sip-servlets.com";
    SipURI toAddress = servers[0].protocolObjects.addressFactory.createSipURI(toUser, toHost);
    SipURI ruri = servers[0].protocolObjects.addressFactory.createSipURI("usera", "127.0.0.1:5033");
    ruri.setLrParam();
    SipURI route = servers[0].protocolObjects.addressFactory.createSipURI("lbaddress_InternalPort", "127.0.0.1:5065");
    route.setParameter("node_host", "127.0.0.1");
    route.setParameter("node_port", "4060");
    route.setLrParam();
    shootist.start();
    // servers[0].sipListener.sendSipRequest("INVITE", fromAddress, toAddress, null, null, false);
    // servers[0].sendHeartbeat = false;
    // servers[1].sendHeartbeat = false;
    servers[0].sipListener.sendSipRequest("OPTIONS", fromAddress, toAddress, "tcpPort=1\nudpPort=2\nhostname=sipHeartbeat\nip=127.0.0.1", route, false, new String[] { "Mobicents-Heartbeat" }, new String[] { "1" }, ruri);
    Thread.sleep(4000);
    servers[0].sipListener.sendSipRequest("OPTIONS", fromAddress, toAddress, "tcpPort=1\nudpPort=2\nhostname=sipHeartbeat\nip=127.0.0.1", route, false, new String[] { "Mobicents-Heartbeat" }, new String[] { "1" }, ruri);
    Thread.sleep(4000);
    servers[0].sipListener.sendSipRequest("OPTIONS", fromAddress, toAddress, "tcpPort=1\nudpPort=2\nhostname=sipHeartbeat\nip=127.0.0.1", route, false, new String[] { "Mobicents-Heartbeat" }, new String[] { "1" }, ruri);
    Thread.sleep(4000);
    servers[0].sipListener.sendSipRequest("OPTIONS", fromAddress, toAddress, "tcpPort=1\nudpPort=2\nhostname=sipHeartbeat\nip=127.0.0.1", route, false, new String[] { "Mobicents-Heartbeat" }, new String[] { "1" }, ruri);
    Thread.sleep(4000);
    servers[0].sipListener.sendSipRequest("OPTIONS", fromAddress, toAddress, "tcpPort=1\nudpPort=2\nhostname=sipHeartbeat\nip=127.0.0.1", route, false, new String[] { "Mobicents-Heartbeat" }, new String[] { "1" }, ruri);
    List<Node> list = balancer.getNodes();
    Node node = list.get(0);
    assertEquals(node.getHostName(), "sipHeartbeat");
    assertEquals(1, list.size());
}
Also used : AppServer(org.mobicents.tools.sip.balancer.AppServer) Node(org.mobicents.tools.heartbeat.api.Node) EventListener(org.mobicents.tools.sip.balancer.EventListener) SipURI(javax.sip.address.SipURI) Test(org.junit.Test)

Example 52 with Node

use of org.mobicents.tools.heartbeat.api.Node in project load-balancer by RestComm.

the class Helper method getNode.

public static Node getNode() {
    Node node = new Node("TestNodeHeartbeat", "127.0.0.1");
    Map<String, String> map = new HashMap<>();
    map.put("httpPort", "8080");
    map.put("sslPort", "8081");
    map.put("udpPort", "5060");
    map.put("tcpPort", "5060");
    map.put("tlsPort", "5061");
    map.put("wsPort", "5062");
    map.put("wssPort", "5063");
    map.put("sessionId", "" + System.currentTimeMillis());
    map.put("Restcomm-Instance-Id", "q1w2e3r4t5y6");
    map.put("version", "0");
    map.put("heartbeatPort", "2222");
    node.getProperties().putAll(map);
    return node;
}
Also used : HashMap(java.util.HashMap) Node(org.mobicents.tools.heartbeat.api.Node)

Example 53 with Node

use of org.mobicents.tools.heartbeat.api.Node in project load-balancer by RestComm.

the class SipBalancerShutdownHook method getNodeList.

public String[] getNodeList() {
    List<Node> nodes = getNodes();
    String[] nodeList = new String[nodes.size()];
    int i = 0;
    for (Node node : nodes) {
        nodeList[i] = node.toString();
        i++;
    }
    return nodeList;
}
Also used : Node(org.mobicents.tools.heartbeat.api.Node)

Example 54 with Node

use of org.mobicents.tools.heartbeat.api.Node in project load-balancer by RestComm.

the class CallIDAffinityBalancerAlgorithm method selectNewNode.

protected Node selectNewNode(Node node, String callId, Boolean isIpV6) {
    if (logger.isDebugEnabled()) {
        logger.debug("The assigned node has died. This is the dead node: " + node);
    }
    if (groupedFailover) {
        // This will occur very rarely because we re-assign all calls from the dead node in
        // a single operation
        Node oldNode = node;
        node = leastBusyTargetNode(oldNode);
        if (node == null)
            return null;
        groupedFailover(oldNode, node);
    } else {
        // Boolean isIpV6=LbUtils.isValidInet6Address(node.getIp());
        if (lbConfig.getSipConfiguration().getTrafficRampupCyclePeriod() != null && lbConfig.getSipConfiguration().getMaxWeightIndex() != null)
            node = getNextRampUpNode(isIpV6);
        else
            node = nextAvailableNode(isIpV6);
        if (node == null) {
            if (logger.isDebugEnabled()) {
                logger.debug("no nodes available return null");
            }
            return null;
        }
        callIdMap.put(callId, node);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("So, we must select new node: " + node);
    }
    return node;
}
Also used : Node(org.mobicents.tools.heartbeat.api.Node)

Example 55 with Node

use of org.mobicents.tools.heartbeat.api.Node in project load-balancer by RestComm.

the class CallIDAffinityBalancerAlgorithm method jvmRouteSwitchover.

@Override
public void jvmRouteSwitchover(String fromJvmRoute, String toJvmRoute) {
    try {
        Node oldNode = getBalancerContext().jvmRouteToSipNode.get(fromJvmRoute);
        Node newNode = getBalancerContext().jvmRouteToSipNode.get(toJvmRoute);
        if (oldNode != null && newNode != null) {
            int updatedRoutes = 0;
            for (String key : callIdMap.keySet()) {
                Node n = callIdMap.get(key);
                if (n.equals(oldNode)) {
                    callIdMap.replace(key, newNode);
                    updatedRoutes++;
                }
            }
            if (logger.isInfoEnabled()) {
                logger.info("Switchover occured where fromJvmRoute=" + fromJvmRoute + " and toJvmRoute=" + toJvmRoute + " with " + updatedRoutes + " updated routes.");
            }
        } else {
            if (logger.isInfoEnabled()) {
                logger.info("Switchover failed where fromJvmRoute=" + fromJvmRoute + " and toJvmRoute=" + toJvmRoute);
            }
        }
    } catch (Throwable t) {
        if (logger.isInfoEnabled()) {
            logger.info("Switchover failed where fromJvmRoute=" + fromJvmRoute + " and toJvmRoute=" + toJvmRoute);
            logger.info("This is not a fatal failure, logging the reason for the failure ", t);
        }
    }
}
Also used : Node(org.mobicents.tools.heartbeat.api.Node) ListeningPoint(javax.sip.ListeningPoint)

Aggregations

Node (org.mobicents.tools.heartbeat.api.Node)70 ListeningPoint (javax.sip.ListeningPoint)19 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 Via (gov.nist.javax.sip.header.Via)7 HashMap (java.util.HashMap)7 SIPHeader (gov.nist.javax.sip.header.SIPHeader)6 ParseException (java.text.ParseException)6 ArrayList (java.util.ArrayList)6 ViaHeader (javax.sip.header.ViaHeader)6 RouteHeader (javax.sip.header.RouteHeader)5 SIPResponse (gov.nist.javax.sip.message.SIPResponse)4 UnknownHostException (java.net.UnknownHostException)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 InvalidArgumentException (javax.sip.InvalidArgumentException)4 SipException (javax.sip.SipException)4 SipURI (javax.sip.address.SipURI)4 RecordRouteHeader (javax.sip.header.RecordRouteHeader)4 ToHeader (javax.sip.header.ToHeader)4 Response (javax.sip.message.Response)4 Test (org.junit.Test)4