Search in sources :

Example 41 with Node

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

the class WorstCaseUdpTestAffinityAlgorithm method processAssignedExternalRequest.

public Node processAssignedExternalRequest(Request request, Node assignedNode) {
    Boolean isIpV6 = LbUtils.isValidInet6Address(assignedNode.getIp());
    // if((y++)%2==0) if(request.getHeader("CSeq").toString().contains("1")) return assignedNode;
    String callId = ((SIPHeader) request.getHeader(headerName)).getValue();
    CSeqHeader cs = (CSeqHeader) request.getHeader(CSeqHeader.NAME);
    long cseq = cs.getSeqNumber();
    if (callIdMap.get(callId) != null) {
        assignedNode = callIdMap.get(callId);
    }
    ViaHeader via = (ViaHeader) request.getHeader(Via.NAME);
    String transport = via.getTransport().toLowerCase();
    RouteHeader route = (RouteHeader) request.getHeader(RouteHeader.NAME);
    SipURI uri = null;
    if (route != null) {
        uri = (SipURI) route.getAddress().getURI();
    } else {
        uri = (SipURI) request.getRequestURI();
    }
    try {
        Node node;
        if (!request.getMethod().equalsIgnoreCase("ACK")) {
            // Gvag: new transaction should go to a new node
            // getNodeA(callId+cseq);
            Node newNode = nextAvailableNode(isIpV6);
            if (newNode == null) {
                // for(Node currNode:invocationContext.nodes) {
                for (Node currNode : invocationContext.sipNodeMap(isIpV6).values()) {
                    if (!currNode.equals(assignedNode)) {
                        newNode = currNode;
                    }
                }
            }
            node = newNode;
        } else
            node = assignedNode;
        uri.setHost(node.getIp());
        if (balancerContext.internalTransport != null) {
            transport = balancerContext.internalTransport.toLowerCase();
        } else if (balancerContext.terminateTLSTraffic)
            if (transport.equalsIgnoreCase(ListeningPoint.TLS))
                transport = ListeningPoint.TCP.toLowerCase();
            else if (transport.equalsIgnoreCase(ListeningPointExt.WSS))
                transport = ListeningPointExt.WS.toLowerCase();
        Integer port = Integer.parseInt(node.getProperties().get(transport + "Port"));
        uri.setPort(port);
        callIdMap.put(callId, node);
        setNodeA(callId + cseq, node);
        if (request.getRequestURI().isSipURI()) {
            SipURI ruri = (SipURI) request.getRequestURI();
            String rurihostid = ruri.getHost() + ruri.getPort();
            String originalhostid = assignedNode.getIp() + assignedNode.getProperties().get(transport + "Port");
            if (rurihostid.equals(originalhostid)) {
                ruri.setPort(port);
                ruri.setHost(node.getIp());
            }
        }
        return node;
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return assignedNode;
}
Also used : CSeqHeader(javax.sip.header.CSeqHeader) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RouteHeader(javax.sip.header.RouteHeader) SIPHeader(gov.nist.javax.sip.header.SIPHeader) ViaHeader(javax.sip.header.ViaHeader) Node(org.mobicents.tools.heartbeat.api.Node) ParseException(java.text.ParseException) SipURI(javax.sip.address.SipURI)

Example 42 with Node

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

the class WorstCaseUdpTestAffinityAlgorithm 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)

Example 43 with Node

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

the class WorstCaseUdpTestAffinityAlgorithm method selectNewNode.

protected Node selectNewNode(Node node, String callId) {
    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());
        node = nextAvailableNode(isIpV6);
        if (node == 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 44 with Node

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

the class WorstCaseUdpTestAffinityAlgorithm method groupedFailover.

public synchronized void groupedFailover(Node oldNode, Node newNode) {
    try {
        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 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 45 with Node

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

the class SmppToProviderActiveStandbyAlgorithm method processBindToProvider.

@Override
public Node processBindToProvider() {
    if (invocationContext.smppNodeMap.size() == 0)
        return null;
    if (invocationContext.activeNodeKey == null) {
        new ArrayList(invocationContext.smppNodeMap.values()).get(0);
        invocationContext.activeNodeKey = new KeySmpp((Node) new ArrayList(invocationContext.smppNodeMap.values()).get(0));
        return invocationContext.smppNodeMap.get(invocationContext.activeNodeKey);
    } else
        return invocationContext.smppNodeMap.get(invocationContext.activeNodeKey);
}
Also used : KeySmpp(org.mobicents.tools.sip.balancer.KeySmpp) Node(org.mobicents.tools.heartbeat.api.Node) ArrayList(java.util.ArrayList)

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