public async Task ClearOrphanEvents()

in src/PatchOrchestrationApplication/CoordinatorService/src/RepairManagerHelper.cs [435:480]


        public async Task ClearOrphanEvents(CancellationToken cancellationToken)
        {
            try
            {
                Uri nodeAgentServiceUri = new Uri(NodeAgentServiceName);
                ServiceHealth health = await this.fabricClient.HealthManager.GetServiceHealthAsync(nodeAgentServiceUri);
                List<HealthEvent> healthEventsToCheck = new List<HealthEvent>();
                foreach (var e in health.HealthEvents)
                {
                    if (e.HealthInformation.Property.Contains(WUOperationStatus) || e.HealthInformation.Property.Contains(WUOperationSetting))
                    {
                        healthEventsToCheck.Add(e);
                    }
                }
                cancellationToken.ThrowIfCancellationRequested();

                NodeList nodeList = await this.fabricClient.QueryManager.GetNodeListAsync(null, null, this.DefaultTimeoutForOperation, cancellationToken);
                Dictionary<string, bool> propertyDict = new Dictionary<string, bool>();
                if (healthEventsToCheck.Count == 2*nodeList.Count)
                {
                    return;
                }
                else
                {
                    foreach (var node in nodeList)
                    {
                        propertyDict.Add(WUOperationStatus + "-" + node.NodeName, true);
                        propertyDict.Add(WUOperationSetting + "-" + node.NodeName, true);
                    }

                    string NodeNotPartOfClusterDescription = "This node is no longer part of the cluster.";
                    foreach (var e in healthEventsToCheck)
                    {
                        if (!propertyDict.ContainsKey(e.HealthInformation.Property))
                        {
                            ServiceEventSource.Current.VerboseMessage("Property {0}'s event is removed from CoordinatorService by updating TTL to 1 minute.", e.HealthInformation.Property);
                            HealthManagerHelper.PostNodeHealthReport(fabricClient, nodeAgentServiceUri, e.HealthInformation.SourceId, e.HealthInformation.Property, NodeNotPartOfClusterDescription, HealthState.Ok, 1);
                        }
                    }
                }
            }
            catch(Exception ex)
            {
                ServiceEventSource.Current.ErrorMessage("ClearOrphanEvents failed with exception {0}", ex.ToString());
            }
        }