use of org.mobicents.tools.heartbeat.api.NodeShutdownRequestPacket 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.NodeShutdownRequestPacket in project load-balancer by RestComm.
the class Client method sendPacket.
@Override
public synchronized void sendPacket(String command) {
if (clientBootstrap != null && !executor.isShutdown()) {
future = clientBootstrap.connect(isa);
switch(command) {
case Protocol.START:
if (packet == null || !(packet instanceof StartRequestPacket)) {
node.getProperties().put(Protocol.SESSION_ID, "" + System.currentTimeMillis());
packet = new StartRequestPacket(node);
}
break;
case Protocol.HEARTBEAT:
if (packet != null && !(packet instanceof HeartbeatRequestPacket))
packet = new HeartbeatRequestPacket(node);
break;
case Protocol.SHUTDOWN:
packet = new NodeShutdownRequestPacket(node);
break;
case Protocol.STOP:
packet = new NodeStopRequestPacket(node);
break;
}
future.awaitUninterruptibly();
future.getChannel().write(createRequest(command, null));
}
}
Aggregations