public void TestBubbleCache()
        {
            Guid       localBubbleId = Guid.NewGuid();
            Guid       objectId      = Guid.NewGuid();
            Guid       ownerId       = Guid.NewGuid();
            CloudCache m_cloudCache  = new CloudCache(localBubbleId, 1000, new TimeSpan(0, 10, 0, 0));

            CloudObject cloudObject = new CloudObject();

            cloudObject.ObjectId             = objectId;
            cloudObject.OwnerId              = ownerId;
            cloudObject.BubbleId             = localBubbleId;
            cloudObject.Location.X           = 1;
            cloudObject.Location.Y           = 2;
            cloudObject.Location.Z           = 3;
            cloudObject.BoundingSphereRadius = 10;

            m_cloudCache.PutObject(cloudObject, true);

            Assert.IsNotNull(m_cloudCache.GetObject(objectId));
            Assert.IsNotNull(m_cloudCache.GetObject(localBubbleId, cloudObject.RemoteObjectIndex));
            Assert.AreEqual(1, m_cloudCache.GetObjectIds(0, 0, 0, 1, 1, 1, new HashSet <Guid>()).Count);
            Assert.AreEqual(1, m_cloudCache.GetBubbleObjectIds(localBubbleId).Count);
            Assert.AreEqual(1, m_cloudCache.GetParticipantObjectIds(ownerId).Count);


            m_cloudCache.RemoveObject(objectId);

            Assert.IsNull(m_cloudCache.GetObject(objectId));
            Assert.IsNull(m_cloudCache.GetObject(localBubbleId, cloudObject.RemoteObjectIndex));
            Assert.AreEqual(0, m_cloudCache.GetObjectIds(0, 0, 0, 1, 1, 1, new HashSet <Guid>()).Count);
            Assert.AreEqual(0, m_cloudCache.GetBubbleObjectIds(localBubbleId).Count);
            Assert.AreEqual(0, m_cloudCache.GetParticipantObjectIds(ownerId).Count);
        }
        internal IEnumerable <MetricAlert> Get(MediaServicesSetConfig config, string originId, AlertsQuery query)
        {
            var endTime   = DateTime.UtcNow;
            var startTime = endTime.AddHours(-1);

            HealthStatus[] healthLevels = null;

            if (query != null)
            {
                if (query.StartTime != default(DateTime))
                {
                    startTime = query.StartTime.ToUniversalTime();
                }
                if (query.EndTime != default(DateTime))
                {
                    endTime = query.EndTime.ToUniversalTime();
                }
                if (endTime <= startTime)
                {
                    throw new HttpResponseException(System.Net.HttpStatusCode.BadRequest);
                }
                healthLevels = query.StatusLevels;
            }

            var origId      = originId.GuidToOriginId();
            var alertstring = CloudCache.Get(origId + "Alerts");
            List <OriginAlert> alerts;

            if (alertstring != null)
            {
                alerts = JsonConvert.DeserializeObject <List <OriginAlert> >(alertstring);
            }
            else
            {
                var dataAccess = new AzureDataAccess(config.DataStorageConnections);
                alerts = dataAccess.ExecuteReadQuery(context =>
                {
                    var dbAlerts = context.OriginAlerts.Where(alert =>
                                                              alert.OriginId == originId &&
                                                              alert.Timestamp >= startTime &&
                                                              alert.Timestamp <= endTime);

                    if (healthLevels != null)
                    {
                        var predicate = CreatePredicate(healthLevels, "ErrorLevel");
                        dbAlerts      = dbAlerts.Where(predicate);
                    }
                    return(dbAlerts.ToList());
                });
            }

            return(alerts.Select(alert => new MetricAlert
            {
                Name = alert.OriginId,
                Date = alert.Timestamp,
                Description = alert.Details,
                Status = alert.ErrorLevel
            }).OrderByDescending(alt => alt.Date));
        }
Exemple #3
0
        protected List <T> GetAlertsFromCache <T>(string id)
        {
            string alertstring = CloudCache.Get(id + "Alerts");

            if (alertstring != null)
            {
                return(JsonConvert.DeserializeObject <List <T> >(alertstring));
            }
            return(null);
        }
        public void TestBubbleCacheGarbageCollection()
        {
            Guid       localBubbleId  = Guid.NewGuid();
            Guid       remoteBubbleId = Guid.NewGuid();
            Guid       localObjectId  = Guid.NewGuid();
            Guid       remoteObjectId = Guid.NewGuid();
            CloudCache m_cloudCache   = new CloudCache(localBubbleId, 1000, new TimeSpan(0, 0, 0, 0, 10));

            CloudObject localObject = new CloudObject();

            localObject.ObjectId             = localObjectId;
            localObject.BubbleId             = localBubbleId;
            localObject.Location.X           = 1;
            localObject.Location.Y           = 2;
            localObject.Location.Z           = 3;
            localObject.BoundingSphereRadius = 10;
            m_cloudCache.PutObject(localObject, true);

            CloudObject remoteObject = new CloudObject();

            remoteObject.ObjectId             = remoteObjectId;
            remoteObject.BubbleId             = remoteBubbleId;
            remoteObject.Location.X           = 1;
            remoteObject.Location.Y           = 2;
            remoteObject.Location.Z           = 3;
            remoteObject.BoundingSphereRadius = 10;
            m_cloudCache.PutObject(remoteObject, true);

            Assert.IsNotNull(m_cloudCache.GetObject(localObjectId));
            Assert.IsNotNull(m_cloudCache.GetObject(remoteObjectId));
            Assert.IsNotNull(m_cloudCache.GetObject(localBubbleId, localObject.RemoteObjectIndex));
            Assert.IsNotNull(m_cloudCache.GetObject(remoteBubbleId, remoteObject.RemoteObjectIndex));

            m_cloudCache.Process();

            Assert.IsNotNull(m_cloudCache.GetObject(localObjectId));
            Assert.IsNotNull(m_cloudCache.GetObject(remoteObjectId));
            Assert.IsNotNull(m_cloudCache.GetObject(localBubbleId, localObject.RemoteObjectIndex));
            Assert.IsNotNull(m_cloudCache.GetObject(remoteBubbleId, remoteObject.RemoteObjectIndex));

            Thread.Sleep(20);
            m_cloudCache.Process();

            Assert.IsNotNull(m_cloudCache.GetObject(localObjectId));
            Assert.IsNull(m_cloudCache.GetObject(remoteObjectId));
            Assert.IsNotNull(m_cloudCache.GetObject(localBubbleId, localObject.RemoteObjectIndex));
            Assert.IsNull(m_cloudCache.GetObject(remoteBubbleId, remoteObject.RemoteObjectIndex));
        }
        private MediaService GetMediaAccountFromCache(Customer customer, MediaServicesAccountConfig accountConfig)
        {
            var account = CloudCache.GetAs <MediaService>(accountConfig.Id);

            if (account != null)
            {
                customer.ChannelCount = account.Channels.Count;
                customer.OriginCount  = account.Origins.Count;
                customer.ProgramCount = account.Programs.Count;
                customer.ArchiveCount = account.Programs.Where(p => p.State == Sdk.ProgramState.Running.ToString()).Count();
                return(new MediaService
                {
                    Id = account.Id,
                    Name = account.Name,
                    Datacenter = account.Datacenter,
                    Health = account.Health
                });
            }
            return(null);
        }
        public IActionResult Get(string id)
        {
            Stopwatch watch            = new Stopwatch();
            var       mediaServicesSet = App.Config.GetCustomer(id);

            if (mediaServicesSet == null)
            {
                return(NotFound());
            }

            Customer customer = new Customer
            {
                Id       = mediaServicesSet.Name,
                Name     = mediaServicesSet.Name,
                Accounts = mediaServicesSet.MediaServicesAccounts.Select(accountConfig =>
                {
                    var account = CloudCache.GetAs <MediaService>(accountConfig.Id);
                    if (account == null)
                    {
                        Trace.TraceWarning("Cache miss for account:{0}", accountConfig.Id);
                        account = new MediaService
                        {
                            Id         = accountConfig.Id,
                            Name       = accountConfig.AccountName,
                            Datacenter = accountConfig.MetaData.Location
                        };
                    }
                    return(account);
                }).ToList()
            };

            // Get each of the account details in parallel.
            Parallel.ForEach(customer.Accounts.Where(account => account.Channels == null),
                             (account, state, i) => GetAccountDetails(mediaServicesSet.MediaServicesAccounts[(int)i], account));
            customer.Health = customer.Accounts.Select(account => account.Health).DefaultIfEmpty(HealthStatus.Healthy).Max();

            Trace.TraceInformation("Time taken load customer details...: {0}", watch.Elapsed);
            return(Ok(customer));
        }
Exemple #7
0
        internal IEnumerable <MetricAlert> Get(MediaServicesSetConfig config, string originId, AlertsQuery query)
        {
            var endTime   = DateTime.UtcNow;
            var startTime = endTime.AddHours(-1);

            HealthStatus[] healthLevels = null;

            if (query != null)
            {
                if (query.StartTime != default(DateTime))
                {
                    startTime = query.StartTime.ToUniversalTime();
                }
                if (query.EndTime != default(DateTime))
                {
                    endTime = query.EndTime.ToUniversalTime();
                }
                if (endTime <= startTime)
                {
                    throw new HttpResponseException(System.Net.HttpStatusCode.BadRequest);
                }
                healthLevels = query.StatusLevels;
            }

            //var origId = originId.GuidToOriginId();
            string             alertstring = CloudCache.Get(originId + "Alerts");
            List <OriginAlert> originAlerts;

            if (alertstring != null)
            {
                originAlerts = JsonConvert.DeserializeObject <List <OriginAlert> >(alertstring);
            }
            else
            {
                var dataAccess = new AzureDataAccess(config.DataStorageConnections);
                if (healthLevels == null)
                {
                    originAlerts = dataAccess.GetOriginAlerts(originId);
                }
                else
                {
                    originAlerts = dataAccess.GetOriginAlerts(originId, healthLevels);
                }
            }

            List <MetricAlert> alerts = new List <MetricAlert>();

            if (originAlerts != null && originAlerts.Count > 0)
            {
                foreach (var orgAlt in originAlerts)
                {
                    alerts.Add(new MetricAlert
                    {
                        AlertID     = orgAlt.AlertID,
                        Name        = orgAlt.OriginName,
                        Date        = orgAlt.AlertDate.AddTicks(orgAlt.AlertTime.Ticks),
                        Description = orgAlt.Details,
                        Status      = orgAlt.ErrorLevel
                    });
                }
            }
            return(alerts);
        }
        private IEnumerable <MetricAlert> Get(MediaServicesSetConfig config, string channelId, AlertsQuery query)
        {
            var endTime   = DateTime.UtcNow;
            var startTime = endTime.AddHours(-1);

            HealthStatus[] healthLevels = null;
            MetricType[]   metricTypes  = null;

            if (query != null)
            {
                if (query.StartTime != default(DateTime))
                {
                    startTime = query.StartTime.ToUniversalTime();
                }
                if (query.EndTime != default(DateTime))
                {
                    endTime = query.EndTime.ToUniversalTime();
                }
                if (endTime <= startTime)
                {
                    throw new HttpResponseException(System.Net.HttpStatusCode.BadRequest);
                }
                metricTypes  = query.MetricTypes;
                healthLevels = query.StatusLevels;
            }

            var    chid        = channelId.NimbusIdToGuid();
            string alertstring = CloudCache.Get(chid + "Alerts");
            List <ChannelAlert> channelAlerts;

            if (alertstring != null)
            {
                channelAlerts = JsonConvert.DeserializeObject <List <ChannelAlert> >(alertstring);
            }
            else
            {
                var dataAccess = new AzureDataAccess(config.DataStorageConnections);
                channelAlerts = dataAccess.GetChannelAlerts(chid.ToString(), healthLevels, metricTypes);
                #region Not used
                //channelAlerts = dataAccess.ExecuteReadQuery(context =>
                //{
                //    var dbAlerts = context.ChannelAlerts.Where(alert =>
                //       alert.ChannelId == channelId &&
                //       alert.AlertDate >= startTime.AddTicks(alert.AlertTime.Ticks) &&
                //       alert.AlertDate <= endTime);

                //    if (healthLevels != null)
                //    {
                //        var predicate = CreatePredicate(healthLevels, "ErrorLevel");
                //        dbAlerts = dbAlerts.Where(predicate);
                //    }
                //    if (metricTypes != null)
                //    {
                //        var condition = CreatePredicate(metricTypes, "MetricType");
                //        dbAlerts = dbAlerts.Where(condition);
                //    }



                //    return dbAlerts.ToList();
                //});
                #endregion
            }
            List <MetricAlert> alerts = new List <MetricAlert>();
            if (channelAlerts != null)
            {
                foreach (var chAlt in channelAlerts)
                {
                    alerts.Add(new MetricAlert
                    {
                        AlertID     = chAlt.AlertID,
                        Name        = chAlt.ChannelName,
                        Date        = chAlt.AlertDate.AddTicks(chAlt.AlertTime.Ticks),
                        Description = chAlt.Details,
                        Status      = chAlt.ErrorLevel
                    });
                }
            }
            return(alerts);
        }