public Task<TaskHealthResponse> CheckStatusOfOwnedTasks()
        {
            var response = new TaskHealthResponse
            {
                Tasks = OwnedSubjects.Select(uri => new PersistentTaskStatus
                {
                    Status = SubjectStatus[uri],
                    Subject = uri
                }).ToArray()
            };

            return response.ToCompletionTask();
        }
        public void Add(ITransportPeer peer, TaskHealthResponse response)
        {
            var subjects = response.AllSubjects().ToArray();

            if (response.ResponseFailed)
            {
                _unavailablePeers.Add(peer);

                _removals[peer].AddRange(subjects);
            }
            else
            {
                _availablePeers.Add(peer);

                response.Tasks.Each(x => _status[x.Subject].ReadPeerStatus(peer, x.Status));
            }
        }
        public void add_missing_subjects_no_change()
        {
            var response = new TaskHealthResponse
            {
                Tasks = new[]
                {
                    new PersistentTaskStatus(subject1, HealthStatus.Active),
                    new PersistentTaskStatus(subject2, HealthStatus.Active),
                    new PersistentTaskStatus(subject3, HealthStatus.Active),
                    new PersistentTaskStatus(subject4, HealthStatus.Active),
                }
            };

            response.AddMissingSubjects(new []{subject1, subject2, subject3, subject4});

            response.Tasks.Count().ShouldEqual(4);
        }
Ejemplo n.º 4
0
        public Task <TaskHealthResponse> Handle(TaskHealthRequest request)
        {
            Debug.WriteLine("Received message {0} from {1}", request, _envelope.ReplyUri);

            return(_controller.CheckStatusOfOwnedTasks().ContinueWith(t => {
                if (t.IsFaulted)
                {
                    return TaskHealthResponse.ErrorFor(request.Subjects);
                }

                var response = t.Result;
                response.AddMissingSubjects(request.Subjects);

                Debug.WriteLine("Responding with {0} on node {1} from health request from {2}", response, _graph.NodeId, _envelope.ReplyUri);

                return response;
            }));
        }
Ejemplo n.º 5
0
        public Task <TaskHealthResponse> CheckStatusOfOwnedTasks()
        {
            var subjects = CurrentlyOwnedSubjects();

            if (!subjects.Any())
            {
                return(TaskHealthResponse.Empty().ToCompletionTask());
            }

            var checks = subjects
                         .Select(subject => CheckStatus(subject).ContinueWith(t => new PersistentTaskStatus(subject, t.Result)))
                         .ToArray();

            return(Task.Factory.ContinueWhenAll(checks, tasks => new TaskHealthResponse
            {
                Tasks = tasks.Select(x => x.Result).ToArray()
            }));
        }
        public void Add(ITransportPeer peer, TaskHealthResponse response)
        {
            var subjects = response.AllSubjects().ToArray();

            if (response.ResponseFailed)
            {
                _unavailablePeers.Add(peer);


                _removals[peer].AddRange(subjects);
            }
            else
            {
                _availablePeers.Add(peer);

                response.Tasks.Each(x => _status[x.Subject].ReadPeerStatus(peer, x.Status));
            }
        }
        public void add_missing_subjects_with_gaps()
        {
            var response = new TaskHealthResponse
            {
                Tasks = new[]
                {
                    new PersistentTaskStatus(subject1, HealthStatus.Active),
                    //new PersistentTaskStatus(subject2, HealthStatus.Active),
                    //new PersistentTaskStatus(subject3, HealthStatus.Active),
                    new PersistentTaskStatus(subject4, HealthStatus.Active),
                }
            };

            response.AddMissingSubjects(new[] { subject1, subject2, subject3, subject4 });

            response.Tasks.Count().ShouldEqual(4);

            response.Tasks.ShouldContain(new PersistentTaskStatus(subject2, HealthStatus.Inactive));
            response.Tasks.ShouldContain(new PersistentTaskStatus(subject3, HealthStatus.Inactive));
        }
Ejemplo n.º 8
0
        public Task <TaskHealthResponse> CheckStatusOfOwnedTasks()
        {
            var subjects = CurrentlyOwnedSubjects().ToArray();

            if (!subjects.Any())
            {
                return(Task.FromResult(TaskHealthResponse.Empty()));
            }

            var request = new TaskHealthRequest
            {
                Subjects = subjects
            };

            return(_serviceBus.Request <TaskHealthResponse>(request, new RequestOptions
            {
                Destination = ControlChannel,
                Timeout = _settings.HealthCheckMessageTimeout
            }).ContinueWith(t => {
                if (t.IsFaulted)
                {
                    _logger.Error(NodeId, "Could not retrieve persistent status checks", t.Exception);

                    t.Exception.Handle(e => true);

                    return TaskHealthResponse.ErrorFor(subjects);
                }

                if (t.IsCompleted)
                {
                    var response = t.Result;
                    response.AddMissingSubjects(subjects);

                    return response;
                }

                _logger.Info(() => "Persistent task health status timedout for node " + NodeId);
                return TaskHealthResponse.ErrorFor(subjects);
            }));
        }
Ejemplo n.º 9
0
        protected override void theContextIs()
        {
            var subjects = new Uri[] { subject1, subject2, subject3, subject4 };

            theNode.OwnedTasks = subjects;

            theResponse = new TaskHealthResponse
            {
                Tasks = new PersistentTaskStatus[0]
            };

            theServiceBus.ExpectMessage(new TaskHealthRequest { Subjects = subjects })
                .AtDestination(theNode.Addresses.First())
                .Returns(theResponse);

            theReturnedTask = thePeer.CheckStatusOfOwnedTasks();
            theReturnedTask.Wait();
        }