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;
}
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);
}
}
}
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;
}
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);
}
}
}
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;
}
Aggregations