Esempio n. 1
0
        public async Task Run()
        {
            var cancellationTokenSource = new CancellationTokenSource();
            var userId = await _servicesClient.GetUserId(cancellationTokenSource.Token);

            if (userId == null)
            {
                return; //probably cancelled
            }
            _loadBalancerProtocol.UserId = userId;
            _ropuProtocol.UserId         = userId.Value;
            Task keyInfoTask     = _keysClient.Run(cancellationTokenSource.Token);
            Task waitForKeysTask = _keysClient.WaitForkeys();
            await Task.WhenAny(keyInfoTask, waitForKeysTask); //this way we will know of error fromt eh keyInfoTask


            Task callManagementTask    = _loadBalancerProtocol.Run();
            Task mediaTask             = _ropuProtocol.Run();
            Task regisrationExpiryTask = _registra.CheckExpiries();
            Task registrationTask      = _servicesClient.ServiceRegistration(cancellationTokenSource.Token);

            Task registerTask = Register();


            await TaskCordinator.WaitAll(callManagementTask, mediaTask, registerTask, regisrationExpiryTask, registrationTask, keyInfoTask);
        }
Esempio n. 2
0
        public async Task Run()
        {
            var cancellationTokenSource = new CancellationTokenSource();

            var userId = await _servicesClient.GetUserId(cancellationTokenSource.Token);

            if (userId == null)
            {
                return; // probably cancelled
            }

            await _callControllers.Initialize();

            _loadBalancerProtocol.UserId = userId;

            var keyInfoTask    = _keysClient.Run(cancellationTokenSource.Token);
            var callManagement = _loadBalancerProtocol.Run();
            var removeExpired  = RemoveExpiredControllers();
            var webdateWeb     = UpdateWeb();

            var serviceClientTask = _servicesClient.ServiceRegistration(cancellationTokenSource.Token);

            await TaskCordinator.WaitAll(
                keyInfoTask,
                callManagement,
                removeExpired,
                webdateWeb,
                serviceClientTask);
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        public async Task Run()
        {
            var cancellationTokenSource = new CancellationTokenSource();

            uint?userId = await _servicesClient.GetUserId(cancellationTokenSource.Token);

            if (userId == null)
            {
                return; //must have been cancelled
            }

            var keysClientTask = _keysClient.Run(cancellationTokenSource.Token);

            await _keysClient.WaitForkeys();

            _loadBalancerProtocol.UserId = userId;
            var loadBalancerTask  = _loadBalancerProtocol.Run();
            var ropuProtocolTask  = _ropuProtocol.Run();
            var registerTask      = Register();
            var serviceClientTask = _servicesClient.ServiceRegistration(cancellationTokenSource.Token);

            await TaskCordinator.WaitAll(
                loadBalancerTask,
                registerTask,
                ropuProtocolTask,
                serviceClientTask,
                keysClientTask);
        }
Esempio n. 5
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));
            }
        }
Esempio n. 6
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));
            }
            ;
        }
Esempio n. 7
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));
        }
Esempio n. 8
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);
                }
            }
        }
Esempio n. 9
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();
            }
        }
Esempio n. 10
0
 async Task InformServingNodeOfGroupCallControllers(IPEndPoint servingNodeEndPoint)
 {
     var managers = _callControllers.GroupCallControllers;
     await TaskCordinator.Retry(() => _loadBalancerProtocol.SendGroupCallControllers(managers, servingNodeEndPoint));
 }