Esempio n. 1
0
        public async Task <IEnumerable <ICommand> > RunAsync(CancellationToken cancellationToken)
        {
            var commands = new List <ICommand>();

            var usages = (await _poolProxy.GetInstancesAsync(cancellationToken)).ToList();

            if (cancellationToken.IsCancellationRequested || !usages.Any())
            {
                return(commands);
            }

            var orphansByType = await GetOrphansForManagedTypesAsync(usages, true, TotalTimesDetachedBeforeFlaggedAsOrphan);

            if (cancellationToken.IsCancellationRequested || !orphansByType.Any())
            {
                return(commands);
            }

            foreach (var obt in orphansByType)
            {
                var orphans     = obt.Value.ToList();
                var serviceType = obt.Key;

                if (!orphans.Any())
                {
                    continue;
                }

                var properties = new Dictionary <string, string>
                {
                    { "EventName", $"{RemoveOrphanCommand.OrphanEventPrefix} reported {orphans.Count} orphan(s) found for service type uri {serviceType}." },
                    { "ServiceTypeUri", serviceType }
                };
                _telemetryClient.TrackEvent($"{RemoveOrphanCommand.OrphanEventPrefix} reported warning for service type uri {serviceType}.", properties);
                _telemetryClient.TrackMetric("Orphaned-Service-Count", orphans.Count, new Dictionary <string, string> {
                    { "ServiceTypeUri", serviceType }
                });

                // For each orphan schedule an action to remove it and put this action in the actions collection
                orphans.ForEach(x => commands.Add(_orphanFactory.CreateRemoveOrphanCommand(x)));
            }

            return(commands);
        }
Esempio n. 2
0
        public async Task <ActionResult <Pool> > Get([Required] string serviceTypeUri)
        {
            var configuration = await pools.GetConfigurationAsync(serviceTypeUri);

            if (configuration == null)
            {
                return(NotFound($"Pool {serviceTypeUri} does not exist or has not yet been started."));
            }

            var getInstancesResponse = await pools.GetInstancesAsync(serviceTypeUri, CancellationToken.None);

            var response = new Pool(
                new PoolConfiguration(configuration.ExpirationQuanta, configuration.HasPersistedState, configuration.IdleServicesPoolSize,
                                      configuration.IsServiceStateful, configuration.MaxPoolSize, configuration.MinReplicaSetSize,
                                      (PartitionSchemeDescription)Enum.Parse(typeof(PartitionSchemeDescription), configuration.PartitionScheme.ToString()),
                                      configuration.ServicesAllocationBlockSize, configuration.TargetReplicasetSize),
                getInstancesResponse.OccupiedInstances?.Select(i => i.PartitionId).Distinct(),
                getInstancesResponse.VacantInstances,
                getInstancesResponse.OccupiedInstances?.Select(i => new OccupiedInstance(i.Id, i.ServiceName, i.InstanceName, i.PartitionId))
                );

            return(Ok(response));
        }