/// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            GetInstancesResponse response = new GetInstancesResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("instances", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <Instance, InstanceUnmarshaller>(InstanceUnmarshaller.Instance);
                    response.Instances = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("nextPageToken", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.NextPageToken = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
예제 #2
0
        private async Task <IEnumerable <Service> > GetServicesAsync(ApplicationList applicationList, GetInstancesResponse usage)
        {
            var app = applicationList.SingleOrDefault(a =>
            {
                var appName = $"{a.ApplicationName.AbsoluteUri}/";
                return(usage.ServiceTypeUri.StartsWith(appName));
            });

            if (app == null)
            {
                return(new List <Service>());
            }

            return((await _fabricClient.QueryManager.GetServiceListAsync(app.ApplicationName))
                   .Where(g => g.ServiceName.AbsoluteUri.Contains(usage.ServiceTypeUri))
                   .ToList());
        }
예제 #3
0
        private async Task <IDictionary <string, IEnumerable <OrphanInfo> > > DetectDetachedServices(ApplicationList applicationList, GetInstancesResponse usage, bool incrementCount, int timesSeenBeforeOrphaned)
        {
            var detachedServices = (await GetServicesAsync(applicationList, usage))
                                   .Where(s => usage.VacantInstances.All(i => s.ServiceName.AbsoluteUri.EndsWith(i.ToString()) == false))
                                   .Where(s => usage.OccupiedInstances.All(i => s.ServiceName.AbsoluteUri.EndsWith(i.ToString()) == false))
                                   .ToList();

            var possibleOrphans = _detachedServices.ContainsKey(usage.ServiceTypeUri) ? _detachedServices[usage.ServiceTypeUri] : new Dictionary <Uri, int>();

            // First remove all previously detected detached services that are no longer detached for the service type
            possibleOrphans.Keys.Except(detachedServices.Select(x => x.ServiceName)).ToList().ForEach(key => possibleOrphans.Remove(key));

            if (incrementCount && possibleOrphans.Any())
            {
                possibleOrphans.Keys.ToList().ForEach(x => possibleOrphans[x] += 1);
            }

            // Add in newly detected detached services
            detachedServices.Select(x => x.ServiceName).Except(possibleOrphans.Keys).ToList().ForEach(name => possibleOrphans.Add(name, 1));

            _detachedServices[usage.ServiceTypeUri] = possibleOrphans;

            return(new Dictionary <string, IEnumerable <OrphanInfo> >
            {
                {
                    usage.ServiceTypeUri,
                    detachedServices.Where(s => possibleOrphans[s.ServiceName] >= timesSeenBeforeOrphaned)
                    .Select(s => new OrphanInfo(s.ServiceName.AbsoluteUri, usage.ServiceTypeUri, s.HealthState, s.ServiceStatus))
                }
            });
        }