Search in sources :

Example 1 with StartRequestPacket

use of org.mobicents.tools.heartbeat.api.StartRequestPacket 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);
}
Also used : PodList(io.fabric8.kubernetes.api.model.PodList) ContainerStatus(io.fabric8.kubernetes.api.model.ContainerStatus) Timer(java.util.Timer) TimerTask(java.util.TimerTask) Pod(io.fabric8.kubernetes.api.model.Pod) StartRequestPacket(org.mobicents.tools.heartbeat.api.StartRequestPacket) Node(org.mobicents.tools.heartbeat.api.Node) HeartbeatRequestPacket(org.mobicents.tools.heartbeat.api.HeartbeatRequestPacket) JsonObject(com.google.gson.JsonObject) List(java.util.List) PodList(io.fabric8.kubernetes.api.model.PodList) NodeShutdownRequestPacket(org.mobicents.tools.heartbeat.api.NodeShutdownRequestPacket)

Example 2 with StartRequestPacket

use of org.mobicents.tools.heartbeat.api.StartRequestPacket 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));
    }
}
Also used : StartRequestPacket(org.mobicents.tools.heartbeat.api.StartRequestPacket) HeartbeatRequestPacket(org.mobicents.tools.heartbeat.api.HeartbeatRequestPacket) NodeStopRequestPacket(org.mobicents.tools.heartbeat.api.NodeStopRequestPacket) NodeShutdownRequestPacket(org.mobicents.tools.heartbeat.api.NodeShutdownRequestPacket)

Aggregations

HeartbeatRequestPacket (org.mobicents.tools.heartbeat.api.HeartbeatRequestPacket)2 NodeShutdownRequestPacket (org.mobicents.tools.heartbeat.api.NodeShutdownRequestPacket)2 StartRequestPacket (org.mobicents.tools.heartbeat.api.StartRequestPacket)2 JsonObject (com.google.gson.JsonObject)1 ContainerStatus (io.fabric8.kubernetes.api.model.ContainerStatus)1 Pod (io.fabric8.kubernetes.api.model.Pod)1 PodList (io.fabric8.kubernetes.api.model.PodList)1 List (java.util.List)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 Node (org.mobicents.tools.heartbeat.api.Node)1 NodeStopRequestPacket (org.mobicents.tools.heartbeat.api.NodeStopRequestPacket)1