Ejemplo n.º 1
0
        async Task UpdateServingNodes(IPEndPoint from, IPEndPoint servingNodeEndpoint)
        {
            var existingServingNodeEndPoints =
                from node in _servingNodes.GetControllers()
                where node.ServingEndPoint != servingNodeEndpoint
                select node.ServingEndPoint;

            //inform that serving node of all existing serving nodes
            await TaskCordinator.Retry(() => _loadBalancerProtocol.SendServingNodes(existingServingNodeEndPoints, from));

            //inform existing serving nodes of the new node
            var existingControlNodeEndPoints =
                from node in _servingNodes.GetControllers()
                where node.ServingEndPoint != servingNodeEndpoint
                select node.ControlEndPoint;
            var existingCallControllers =
                from controller in _callControllers.Controllers
                select controller.LoadBalancerEndPoint;

            foreach (var endPoint in existingControlNodeEndPoints.Concat(existingCallControllers))
            {
                TaskCordinator.DontWait(() => TaskCordinator.Retry(() => _loadBalancerProtocol.SendServingNodes(new IPEndPoint[] { servingNodeEndpoint }, endPoint)));
            }

            await InformServingNodeOfGroupCallControllers(from);
        }
Ejemplo n.º 2
0
        public async void GroupsChanged(IEnumerable <GroupCallController> groupCallcontrollers)
        {
            var managers = _callControllers.GroupCallControllers;

            foreach (var servingNode in _servingNodes.GetControllers())
            {
                await TaskCordinator.Retry(() => _loadBalancerProtocol.SendGroupCallControllers(groupCallcontrollers, servingNode.ControlEndPoint));
            }
        }
Ejemplo n.º 3
0
        public async void GroupCallControllerRemoved(ushort groupId)
        {
            var managers = _callControllers.GroupCallControllers;

            foreach (var servingNode in _servingNodes.GetControllers())
            {
                await TaskCordinator.Retry(() => _loadBalancerProtocol.SendGroupCallControllerRemoved(groupId, servingNode.ControlEndPoint));
            }
            ;
        }
Ejemplo n.º 4
0
        public async void HandleRegisterCallController(IPEndPoint from, ushort requestId, IPEndPoint callControlEndpoint)
        {
            Console.WriteLine($"Call Controller Registered at end point {callControlEndpoint} from {from}");
            byte?controllerId = _callControllers.Register(from, new RegisteredCallController(from, callControlEndpoint));

            _loadBalancerProtocol.SendAck(requestId, from);

            if (controllerId == null)
            {
                Console.WriteLine("To many call controllers registered");
                //TODO: probably need a response to indicate this
                return;
            }

            await TaskCordinator.Retry(() => _loadBalancerProtocol.SendControllerRegistrationInfo(controllerId.Value, 10, from));

            //inform Call Controller of exiting Serving Nodes
            var existingServingNodeEndPoints =
                from node in _servingNodes.GetControllers()
                select node.ServingEndPoint;
            await TaskCordinator.Retry(() => _loadBalancerProtocol.SendServingNodes(existingServingNodeEndPoints, from));
        }
Ejemplo n.º 5
0
        async Task Register()
        {
            while (true)
            {
                var  callManagementServerEndpoint = _serviceDiscovery.CallManagementServerEndpoint();
                bool registered = await _loadBalancerProtocol.SendRegisterCallController(
                    new IPEndPoint(_serviceDiscovery.GetMyAddress(), _ropuProtocol.MediaPort),
                    callManagementServerEndpoint);

                if (registered)
                {
                    Console.WriteLine("Registered");
                    while (true)
                    {
                        await Task.Delay(GetRefreshIntervalMilliseconds());

                        if (_controllerId == null)
                        {
                            //never received a Controller Registration Info Packet
                            Console.WriteLine("Never received a Controller Registration Info Packet");
                            //need to resend our registration
                            break;
                        }
                        if (!await TaskCordinator.Retry(() => _loadBalancerProtocol.SendControllerRefreshCallController(_controllerId.Value, callManagementServerEndpoint)))
                        {
                            registered = false;
                            break;
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Failed to register");
                    await Task.Delay(2000);
                }
            }
        }
Ejemplo n.º 6
0
        async Task RemoveExpiredControllers()
        {
            while (!_closing)
            {
                await Task.Delay(5000); //todo: find the time till the next controller expires and wait that long

                _servingNodes.RemoveExpired(removedNode =>
                {
                    var servingNodeEndpoint          = removedNode.ServingEndPoint;
                    var existingServingNodeEndPoints =
                        from node in _servingNodes.GetControllers()
                        select node.ControlEndPoint;
                    var callContollerEndPoints =
                        from node in _callControllers.Controllers
                        select node.LoadBalancerEndPoint;
                    foreach (var endPoint in existingServingNodeEndPoints.Concat(callContollerEndPoints))
                    {
                        Console.WriteLine($"Sending ServingNodeRemoved to {endPoint}");
                        TaskCordinator.DontWait(() => TaskCordinator.Retry(() => _loadBalancerProtocol.SendServingNodeRemoved(servingNodeEndpoint, endPoint)));
                    }
                });
                _callControllers.RemoveExpired();
            }
        }
Ejemplo n.º 7
0
 async Task InformServingNodeOfGroupCallControllers(IPEndPoint servingNodeEndPoint)
 {
     var managers = _callControllers.GroupCallControllers;
     await TaskCordinator.Retry(() => _loadBalancerProtocol.SendGroupCallControllers(managers, servingNodeEndPoint));
 }