use of org.mobicents.tools.heartbeat.api.Node in project load-balancer by RestComm.
the class ServerControllerKube method startServer.
@Override
public void startServer() {
timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
PodList pods = kube.pods().list();
List<Pod> items = pods.getItems();
for (Pod pod : items) {
if (isValidPod(pod)) {
String currSessionId = getSessionId(pod);
Node currNode = activeNodes.get(currSessionId);
if (currNode == null) {
for (ContainerStatus status : pod.getStatus().getContainerStatuses()) {
if (status.getName().startsWith(nodeName) && status.getReady()) {
Node newNode = getNodeFromPod(pod);
JsonObject jsonObject = parser.parse(gson.toJson(new StartRequestPacket(newNode))).getAsJsonObject();
listener.startRequestReceived(null, jsonObject);
activeNodes.put(newNode.getProperties().get(Protocol.SESSION_ID), newNode);
}
}
} else if (!isGracefulShutdown(pod) || currNode.isGracefulShutdown()) {
JsonObject jsonObject = parser.parse(gson.toJson(new HeartbeatRequestPacket(currNode))).getAsJsonObject();
listener.heartbeatRequestReceived(null, jsonObject);
} else {
if (!currNode.isGracefulShutdown()) {
currNode.setGracefulShutdown(true);
JsonObject jsonObject = parser.parse(gson.toJson(new NodeShutdownRequestPacket(currNode))).getAsJsonObject();
listener.shutdownRequestReceived(null, jsonObject);
}
}
}
}
}
}, 2000, pullPeriod);
}
use of org.mobicents.tools.heartbeat.api.Node in project load-balancer by RestComm.
the class ClusterSubdomainAffinityAlgorithmTest method testPartnerFailover.
// Test actual failover by adding a lot of noise nodes and only 1 partner for the original
@Test
public void testPartnerFailover() throws Exception, ParseException {
try {
ClusterSubdomainAffinityAlgorithm algorithm = new ClusterSubdomainAffinityAlgorithm();
algorithm.balancerContext = new BalancerContext();
algorithm.balancerContext.lbConfig = new LoadBalancerConfiguration();
algorithm.balancerContext.lbConfig.getSipConfiguration().getAlgorithmConfiguration().setSubclusterMap(failoverGroup);
algorithm.balancerContext.smppToNodeAlgorithmClassName = algorithm.balancerContext.lbConfig.getSmppConfiguration().getSmppToNodeAlgorithmClass();
algorithm.balancerContext.smppToProviderAlgorithmClassName = algorithm.balancerContext.lbConfig.getSmppConfiguration().getSmppToProviderAlgorithmClass();
algorithm.balancerContext.algorithmClassName = ClusterSubdomainAffinityAlgorithm.class.getName();
InvocationContext ctx = new InvocationContext("0", algorithm.balancerContext);
// ctx.nodes = new CopyOnWriteArrayList<Node>();
ctx.sipNodeMap(false).clear();
for (int q = 0; q < 100; q++) {
Node node = new Node("alphabeticalNoise" + q, "alphabeticalNoise" + q);
ctx.sipNodeMap(false).put(new KeySip(node, false), node);
}
for (int q = 0; q < 100; q++) {
Node node = new Node(q + "alphabeticalNoise" + q, q + "alphabeticalNoise" + q);
ctx.sipNodeMap(false).put(new KeySip(node, false), node);
}
Node originalNode = new Node("original", "original");
Node partnerNode = new Node("partner", "partner");
// This is dead BalancerContext.balancerContext.nodes.add(originalNode);
ctx.sipNodeMap(false).put(new KeySip(partnerNode, false), partnerNode);
for (int q = 0; q < 100; q++) {
Node node = new Node("nonParner" + q, "nonPartner" + q);
ctx.sipNodeMap(false).put(new KeySip(node, false), node);
}
algorithm.callIdMap.put("cid", originalNode);
Request request = SipFactory.getInstance().createMessageFactory().createRequest(inviteRequest);
algorithm.loadSubclusters(failoverGroup);
algorithm.invocationContext = ctx;
Node resultNode = algorithm.processExternalRequest(request, false);
assertEquals("partner", resultNode.getIp());
originalNode = null;
partnerNode = null;
resultNode = null;
} finally {
// BalancerContext.balancerContext.nodes = null;
}
}
use of org.mobicents.tools.heartbeat.api.Node in project load-balancer by RestComm.
the class BalancerDispatcher method bindRequested.
@Override
public void bindRequested(Long sessionId, ServerConnectionImpl serverConnection, Pdu packet) {
// InvocationContext invocationContext = balancerRunner.getLatestInvocationContext();
balancerRunner.balancerContext.smppRequestsToServer.getAndIncrement();
balancerRunner.incMessages();
balancerRunner.balancerContext.smppRequestsProcessedById.get(packet.getCommandId()).incrementAndGet();
balancerRunner.balancerContext.smppBytesToServer.addAndGet(packet.getCommandLength());
serverSessions.put(sessionId, serverConnection);
SmppSessionConfiguration sessionConfig = serverConnection.getConfig();
if (!serverConnection.getConfig().isUseSsl())
sessionConfig.setUseSsl(false);
else
sessionConfig.setUseSsl(!balancerRunner.balancerContext.terminateTLSTraffic);
counterConnections.compareAndSet(Integer.MAX_VALUE, 0);
Node currNode = ctx.smppToProviderBalancerAlgorithm.processBindToProvider();
sessionConfig.setHost(currNode.getIp());
sessionConfig.setPort(Integer.parseInt((String) currNode.getProperties().get("smppPort")));
clientSessions.put(sessionId, new ClientConnectionImpl(sessionId, sessionConfig, this, monitorExecutor, balancerRunner, packet, currNode));
handlerService.execute(new BinderRunnable(sessionId, packet, serverSessions, clientSessions, currNode, balancerRunner));
}
use of org.mobicents.tools.heartbeat.api.Node in project load-balancer by RestComm.
the class BlackholeAppServer method start.
public void start() {
timer = new Timer();
try {
socket = new DatagramSocket(port, InetAddress.getByName(lbAddress));
try {
tcpSocket = new ServerSocket(port);
tcpThread = new Thread() {
public void run() {
while (true) {
try {
sock = tcpSocket.accept();
new Thread() {
public void run() {
while (true) {
try {
numUnitsReceived += sock.getInputStream().read(temp);
} catch (IOException e) {
return;
}
}
}
}.start();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
};
tcpThread.start();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
thread = new Thread() {
public void run() {
try {
while (true) {
socket.receive(packet);
numUnitsReceived++;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
thread.start();
} catch (SocketException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
appServerNode = new Node(name, "127.0.0.1");
appServerNode.getProperties().put("udpPort", "" + port);
appServerNode.getProperties().put("tcpPort", "" + port);
}
use of org.mobicents.tools.heartbeat.api.Node in project load-balancer by RestComm.
the class NodeTest method testEquals.
@Test
public void testEquals() throws Exception {
Node node1 = new Node("mobicents.org", "192.168.0.10");
node1.getProperties().put(Protocol.UDP_PORT, "5060");
Node node2 = node1;
assertTrue(node1.equals(node2));
node2 = new Node("mobicents.org", "192.168.0.20");
node2.getProperties().put(Protocol.UDP_PORT, "5060");
assertFalse(node1.equals(node2));
node2 = new Node("mobicents.org", "192.168.0.10");
node2.getProperties().put(Protocol.UDP_PORT, "5060");
assertTrue(node1.equals(node2));
node1.getProperties().put(Protocol.TCP_PORT, "5060");
node2.getProperties().put(Protocol.TCP_PORT, "5060");
assertTrue(node1.equals(node2));
node1.getProperties().put(Protocol.TLS_PORT, "5061");
assertFalse(node1.equals(node2));
node2.getProperties().put(Protocol.TLS_PORT, "5061");
node2.getProperties().put(Protocol.WS_PORT, "5062");
assertFalse(node1.equals(node2));
}
Aggregations