Search in sources :

Example 16 with Node

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

the class UserBasedAlgorithm method selectNewNode.

protected Node selectNewNode(Node node, String user, 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;
        }
        userToMap.put(user, 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 17 with Node

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

the class UserBasedAlgorithm 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 : userToMap.keySet()) {
                Node n = userToMap.get(key);
                if (n.equals(oldNode)) {
                    userToMap.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)

Example 18 with Node

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

the class UserBasedAlgorithm method leastBusyTargetNode.

protected synchronized Node leastBusyTargetNode(Node deadNode) {
    HashMap<Node, Integer> nodeUtilization = new HashMap<Node, Integer>();
    for (Node node : userToMap.values()) {
        Integer n = nodeUtilization.get(node);
        if (n == null) {
            nodeUtilization.put(node, 0);
        } else {
            nodeUtilization.put(node, n + 1);
        }
    }
    int minUtil = Integer.MAX_VALUE;
    Node minUtilNode = null;
    for (Node node : nodeUtilization.keySet()) {
        Integer util = nodeUtilization.get(node);
        if (!node.equals(deadNode) && (util < minUtil)) {
            minUtil = util;
            minUtilNode = node;
        }
    }
    logger.info("Least busy node selected " + minUtilNode + " with " + minUtil + " calls");
    return minUtilNode;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Node(org.mobicents.tools.heartbeat.api.Node) ListeningPoint(javax.sip.ListeningPoint)

Example 19 with Node

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

the class UserBasedAlgorithm method groupedFailover.

public synchronized void groupedFailover(Node oldNode, Node newNode) {
    try {
        if (oldNode != null && newNode != null) {
            int updatedRoutes = 0;
            for (String key : userToMap.keySet()) {
                Node n = userToMap.get(key);
                if (n.equals(oldNode)) {
                    userToMap.replace(key, newNode);
                    updatedRoutes++;
                }
            }
            if (logger.isInfoEnabled()) {
                logger.info("Switchover occured where oldNode=" + oldNode + " and newNode=" + newNode + " with " + updatedRoutes + " updated routes.");
            }
        } else {
            if (logger.isInfoEnabled()) {
                logger.info("Switchover failed where fromJvmRoute=" + oldNode + " and toJvmRoute=" + newNode);
            }
        }
    } catch (Throwable t) {
        if (logger.isInfoEnabled()) {
            logger.info("Switchover failed where fromJvmRoute=" + oldNode + " and toJvmRoute=" + newNode);
            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)

Example 20 with Node

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

the class CallIDAffinityBalancerAlgorithm method nextAvailableNode.

protected synchronized Node nextAvailableNode(Boolean isIpV6) {
    if (invocationContext.sipNodeMap(isIpV6).size() == 0)
        return null;
    Iterator<Entry<KeySip, Node>> currIt = null;
    if (isIpV6)
        currIt = ipv6It;
    else
        currIt = ipv4It;
    if (currIt == null) {
        currIt = invocationContext.sipNodeMap(isIpV6).entrySet().iterator();
        if (isIpV6)
            ipv6It = currIt;
        else
            ipv4It = currIt;
    }
    Entry<KeySip, Node> pair = null;
    int count = invocationContext.sipNodeMap(isIpV6).size();
    while (count > 0) {
        while (currIt.hasNext() && count > 0) {
            pair = currIt.next();
            if (invocationContext.sipNodeMap(isIpV6).containsKey(pair.getKey()) && !invocationContext.sipNodeMap(isIpV6).get(pair.getKey()).isGracefulShutdown() && !invocationContext.sipNodeMap(isIpV6).get(pair.getKey()).isBad()) {
                return pair.getValue();
            } else {
                count--;
            }
        }
        if (!currIt.hasNext())
            currIt = invocationContext.sipNodeMap(isIpV6).entrySet().iterator();
        if (isIpV6)
            ipv6It = currIt;
        else
            ipv4It = currIt;
    }
    return null;
}
Also used : Entry(java.util.Map.Entry) 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