Beispiel #1
0
        public async Task <ServiceIssuesResult> GetMissingResourceHealth(ServiceIssuesReguest issuesReguest)
        {
            try
            {
                var azureResHealth = await GetAzureResourceHealthForSubs(issuesReguest);

                if (azureResHealth != null)
                {
                    var existingDb = await GetList();

                    if (existingDb.IsNullOrEmptyCollection())
                    {
                        return(azureResHealth);
                    }

                    var ids     = existingDb.Select(a => a.TrackingId).ToList();
                    var missing = azureResHealth.ServiceIssues.Where(a => !ids.Contains(a.TrackingId)).ToList();
                    azureResHealth.ServiceIssues = missing; //removing exisitng saved or created tickets
                    return(azureResHealth);
                }
                return(null);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Beispiel #2
0
 public Task <ServiceIssuesResult> GetMissingResourceHealth(ServiceIssuesReguest issuesReguest, CancellationToken cancelToken = default)
 {
     //if (!queryStartTime.HasValue)
     //    queryStartTime = DateTime.Today.AddMonths(-1);
     //api/ServiceIssue/GetByTrackingId/1VWB-V9Gxxx
     //api/ServiceIssue/GetMissingResourceHealth/queryStartTime/9/6/2021
     return(base.RestSend <ServiceIssuesResult, ServiceIssuesResultDto, ServiceIssuesReguest>(HttpMethod.Get, issuesReguest, $"GetMissingResourceHealth", cancelToken));
 }
Beispiel #3
0
        public async Task <ServiceIssuesResult> GetAzureResourceHealthForSubs(ServiceIssuesReguest issuesReguest)
        {
            try
            {
                var subs = await _subscriptionRepository.GetCachedSubcriptions(); //v3

                if (subs.HasAnyInCollection())
                {
                    var id  = ApiIdentity.GetUserName();
                    var ids = subs.Select(a => a.Id).ToList();
#if DEBUG
                    //int addDuplicatesForTesting = 100;
                    int addDuplicatesForTesting = 0;
                    if (addDuplicatesForTesting > 0)
                    {
                        List <string> list = new();
                        Enumerable.Range(1, addDuplicatesForTesting).ToList().ForEach(a => list.AddRange(ids));
                        ids = list;
                    }
#endif
                    int cachefor = (issuesReguest.CacheInForMinutes.HasValue && issuesReguest.CacheInForMinutes.Value > 0) ? issuesReguest.CacheInForMinutes.Value : 60;

                    #region v3 split into chunks

                    var keyhePartitioned = GetCommonCacheKey + issuesReguest.QueryStartTime.ToShortDateString() + ids.Count;
                    if (issuesReguest.ResetCache)
                    {
                        //_cacheProvider.ClearCache(keyhePartitioned, id);
                        ResetIssuesCache();
                    }

                    if (issuesReguest.CacheInForMinutes.HasValue && issuesReguest.CacheInForMinutes.Value > 0)
                    {
                        var cache = _cacheProvider.GetFromCache <ServiceIssuesResult>(keyhePartitioned, id);
                        if (cache != null)
                        {
                            return(cache);
                        }
                    }

                    var parti = await _azureHealthService.GetResourceHealthPartitioned(ids, issuesReguest.QueryStartTime.ToShortDateString());

                    var res = new ServiceIssuesResult {
                        ServiceIssues = parti, TotalSubs = subs.Count, IssuedTimeUtc = DateTime.UtcNow
                    };
                    _cacheProvider.SetCache(keyhePartitioned, id, res, cachefor * 60);

                    var commonCache = _cacheProvider.GetFromCache <HoldIssuesCache>(GetCommonCacheKey);
                    if (commonCache == null)
                    {
                        commonCache = new HoldIssuesCache();
                    }
                    if (commonCache.IdListKeysPairs.TryGetValue(id, out List <string> keysList))
                    {
                        keysList.Add(keyhePartitioned);
                    }
                    else
                    {
                        commonCache.IdListKeysPairs.Add(id, new List <string> {
                            keyhePartitioned
                        });
                    }

                    _cacheProvider.SetCache(GetCommonCacheKey, commonCache, cachefor * 60);
                    return(res);

                    #endregion

                    #region Old Code
                    //bool testBothMethods = false;
                    //#region v2 parallel, improvemn can be 10X times  faster, from 120 sec down to 20 sec in list of 1500 subs

                    //var keyhePar = nameof(_azureHealthService.GetResourceHealthParallel) + reguest.QueryStartTime + ids.Count;
                    //var vparalelel = await _cacheProvider.GetOrAddAsync(keyhePar, id, cachefor * 60, () => _azureHealthService.GetResourceHealthParallel(ids, reguest.QueryStartTime.ToShortDateString()));

                    //#endregion

                    //#region v1 code to do verificatio for paraller and normal for each await call

                    //if (testBothMethods)
                    //{
                    //    var keyhe = nameof(_azureHealthService.GetResourceHealth) + reguest.QueryStartTime + ids.Count;
                    //    var vornmal = await _cacheProvider.GetOrAddAsync(keyhe, id, cachefor * 60, () => _azureHealthService.GetResourceHealth(ids, reguest.QueryStartTime.ToShortDateString()));

                    //    //foreach (var item in vornmal)
                    //    //{
                    //    //    var par = vparalelel.FirstOrDefault(a => item.TrackingId.Equals(a.TrackingId));
                    //    //    if (par == null)
                    //    //        ;//bug does not exist
                    //    //    else
                    //    //    {
                    //    //        if (par.ImpactedSubscriptions.Length != item.ImpactedSubscriptions.Length)
                    //    //            ; //bad
                    //    //        if (par.ImpactedServices.Length != item.ImpactedServices.Length)
                    //    //            ; //bad
                    //    //        if (par.ImpactedRegions.Length != item.ImpactedRegions.Length)
                    //    //            ; //bad
                    //    //    }
                    //    //}
                    //}

                    //#endregion

                    //return new ServiceIssuesResult { ServiceIssues = vparalelel, TotalSubs = subs.Count };
                    #endregion
                }
                return(null);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Beispiel #4
0
        public async Task <ActionResult <ServiceIssuesResultDto> > GetMissingResourceHealth([FromBody] ServiceIssuesReguest issuesRegues)
        {
            _logger.LogInformation(ApiLogEvents.GetItem, $"{nameof(GetMissingResourceHealth)} Started {issuesRegues}", issuesRegues);

            var repoObj = await _repository.GetMissingResourceHealth(issuesRegues);

            if (repoObj == null)
            {
                return(null);
            }

            var result = _mapper.Map <ServiceIssuesResultDto>(repoObj);

            return(result);
        }