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