예제 #1
0
        public StatusMessage Validate(MonitoringMessage message)
        {
            // ReSharper disable once NotAccessedVariable
            MonitoringMessageType mt;

            return(!Enum.TryParse(message.MessageType, out mt)
                ? StatusMessage.InvalidMonitoringMessageTypeValue
                : StatusMessage.Ok);
        }
예제 #2
0
 public EFDbModel.MonitoringMessage Convert(MonitoringMessage message)
 {
     //should already be validated to convert
     Enum.TryParse(message.MessageType, out MonitoringMessageType mt);
     return(new EFDbModel.MonitoringMessage()
     {
         MessageType = mt,
         MessageSourceNodeName = message.MessageSourceNodeName,
         NumSkippedChildren = message.NumSkippedChildren
     });
 }
 private IEnumerable<SubscriptionSummary> ToSummaryDto(HttpEntityManager manager, MonitoringMessage.GetPersistentSubscriptionStatsCompleted message)
 {
     if (message == null) yield break;
     if (message.SubscriptionStats == null) yield break;
     foreach (var stat in message.SubscriptionStats)
     {
         var info = new SubscriptionSummary
         {
             Links = new List<RelLink>()
             {
                 new RelLink(MakeUrl(manager, string.Format("/subscriptions/{0}/{1}", stat.EventStreamId,stat.GroupName)), "detail"),
             },
             EventStreamId = stat.EventStreamId,
             GroupName = stat.GroupName,
             Status = stat.Status,
             AverageItemsPerSecond = stat.AveragePerSecond,
             TotalItemsProcessed = stat.TotalItems,
             LastKnownEventNumber = stat.LastKnownMessage,
             LastProcessedEventNumber = stat.LastProcessedEventNumber,
             ParkedMessageUri = MakeUrl(manager, string.Format("/streams/$persistentsubscription-{0}::{1}-parked", stat.EventStreamId, stat.GroupName)),
             TotalInFlightMessages = stat.TotalInFlightMessages,
         };
         if (stat.Connections != null)
         {
             info.ConnectionCount = stat.Connections.Count;
         }
         yield return info;
     }
 }
 private IEnumerable<SubscriptionInfo> ToDto(HttpEntityManager manager, MonitoringMessage.GetPersistentSubscriptionStatsCompleted message)
 {
     if (message == null) yield break;
     if (message.SubscriptionStats == null) yield break;
     foreach (var stat in message.SubscriptionStats)
     {
         var info = new SubscriptionInfo
         {
             Links = new List<RelLink>()
             {
                 new RelLink(MakeUrl(manager, string.Format("/subscriptions/{0}/{1}", stat.EventStreamId,stat.GroupName)), "detail"),
                 new RelLink(MakeUrl(manager, string.Format("/subscriptions/{0}/{1}/replayParked", stat.EventStreamId,stat.GroupName)), "replayParked")
             },
             EventStreamId = stat.EventStreamId,
             GroupName = stat.GroupName,
             Status = stat.Status,
             AverageItemsPerSecond = stat.AveragePerSecond,
             TotalItemsProcessed = stat.TotalItems,
             CountSinceLastMeasurement = stat.CountSinceLastMeasurement,
             LastKnownEventNumber = stat.LastKnownMessage,
             LastProcessedEventNumber = stat.LastProcessedEventNumber,
             ReadBufferCount = stat.ReadBufferCount,
             LiveBufferCount = stat.LiveBufferCount,
             RetryBufferCount = stat.RetryBufferCount,
             TotalInFlightMessages = stat.TotalInFlightMessages,
             ParkedMessageUri = MakeUrl(manager, string.Format("/streams/$persistentsubscription-{0}::{1}-parked", stat.EventStreamId, stat.GroupName)),
             Config = new SubscriptionConfigData
             {
                 CheckPointAfterMilliseconds = stat.CheckPointAfterMilliseconds,
                 BufferSize = stat.BufferSize,
                 LiveBufferSize = stat.LiveBufferSize,
                 MaxCheckPointCount = stat.MaxCheckPointCount,
                 MaxRetryCount = stat.MaxRetryCount,
                 MessageTimeoutMilliseconds = stat.MessageTimeoutMilliseconds,
                 MinCheckPointCount = stat.MinCheckPointCount,
                 NamedConsumerStrategy = stat.NamedConsumerStrategy,
                 PreferRoundRobin = stat.NamedConsumerStrategy == SystemConsumerStrategies.RoundRobin,
                 ReadBatchSize = stat.ReadBatchSize,
                 ResolveLinktos = stat.ResolveLinktos,
                 StartFrom = stat.StartFrom,
                 ExtraStatistics = stat.ExtraStatistics,
             },
             Connections = new List<ConnectionInfo>()
         };
         if (stat.Connections != null)
         {
             foreach (var connection in stat.Connections)
             {
                 info.Connections.Add(new ConnectionInfo
                 {
                     Username = connection.Username, 
                     From = connection.From,
                     AverageItemsPerSecond = connection.AverageItemsPerSecond,
                     CountSinceLastMeasurement = connection.CountSinceLastMeasurement,
                     TotalItemsProcessed = connection.TotalItems,
                     AvailableSlots = connection.AvailableSlots,
                     InFlightMessages = connection.InFlightMessages,
                     ExtraStatistics = connection.ObservedMeasurements ?? new Dictionary<string, int>()
                 });
             }
         }
         yield return info;
     }
 }
        private static TestIDsSet AddTestDataSet(NtwkDBContext context)
        {
            var testProfile = new Profile
            {
                ID   = 0,
                Name = TestProfileName,
                StartMonitoringOnLaunch   = true,
                DepthMonitoring           = true,
                MonitoringStartHour       = 0,
                MonitoringSessionDuration = 24,
                MonitorInterval           = 10
            };

            context.Profiles.Add(testProfile);
            context.SaveChanges();

            // tags
            NodeTag[] testTags = Enumerable.Range(0, 3)
                                 .Select(i => new NodeTag
            {
                ID   = 0,
                Name = TagNames[i]
            }).ToArray();
            context.Tags.AddRange(testTags);
            context.SaveChanges();

            // nodes
            NtwkNode[] testNodes = new NtwkNode[3];
            {
                uint[] ips = new[]
                {
                    167837697u,
                    3232292602u,
                    167837697u
                };
                bool[] t = new[] { false, true, false };
                bool[] s = new[] { true, false, true };
                for (int i = 0; i < 3; i++)
                {
                    testNodes[i] = new NtwkNode
                    {
                        ID         = 0,
                        Parent     = null,
                        Name       = NodeNames[i],
                        ip         = ips[i],
                        OpenTelnet = t[i],
                        OpenSSH    = s[i],
                        OpenPing   = true
                    };
                }

                context.Nodes.Add(testNodes[0]);
                context.SaveChanges();
                testNodes[1].Parent = testNodes[0];
                context.Nodes.Add(testNodes[1]);
                context.Nodes.Add(testNodes[2]);
                context.SaveChanges();
            }


            CustomWebService[] testWebServices;
            {
                string[] wsStrings =
                {
                    "http://{node_ip}:8080",
                    "https://{node_ip}:{param1}"
                };
                string[] wsP1 = new[] { null, "Port" };
                testWebServices = Enumerable.Range(0, 2)
                                  .Select(i => new CustomWebService
                {
                    ID            = 0,
                    Name          = WebServicesNames[i],
                    ServiceStr    = wsStrings[i],
                    Parametr1Name = wsP1[i]
                }).ToArray();
                context.WebServices.AddRange(testWebServices);
                context.SaveChanges();
            }


            {
                //TagAttachments
                NodeTag[] t = new[]
                {
                    testTags[0], testTags[0], testTags[1], testTags[2]
                };
                NtwkNode[] n = new[]
                {
                    testNodes[0], testNodes[1], testNodes[1], testNodes[2]
                };
                context.TagAttachments.AddRange(Enumerable.Range(0, 4)
                                                .Select(i => new TagAttachment
                {
                    ID   = 0,
                    Tag  = t[i],
                    Node = n[i],
                })
                                                );
                context.SaveChanges();
            }


            {
                // WebServiceBindings
                CustomWebService[] s = new[]
                {
                    testWebServices[0], testWebServices[0],
                    testWebServices[1], testWebServices[1], testWebServices[1]
                };
                NtwkNode[] n = new[]
                {
                    testNodes[0], testNodes[1],
                    testNodes[0], testNodes[1], testNodes[2]
                };
                string[] p = new[]
                {
                    null, null,
                    "80", "55315", ""
                };
                context.WebServiceBindings.AddRange(Enumerable.Range(0, 5)
                                                    .Select(i => new CustomWsBinding
                {
                    ID      = 0,
                    Service = s[i],
                    Node    = n[i],
                    Param1  = p[i]
                })
                                                    );
                context.SaveChanges();
            }


            {
                // test monitoring session data
                MonitoringSession testSession = new MonitoringSession
                {
                    ID = 0,
                    CreatedByProfile      = testProfile,
                    ParticipatingNodesNum = 2,
                    CreationTime          = 1528359015,
                    LastPulseTime         = 1528360285,
                };
                MonitoringPulseResult[] pulses = new[]
                {
                    new MonitoringPulseResult
                    {
                        ID           = 0,
                        Responded    = 2,
                        Silent       = 0,
                        Skipped      = 0,
                        CreationTime = 1528359015
                    },
                    new MonitoringPulseResult
                    {
                        ID           = 0,
                        Responded    = 0,
                        Silent       = 1,
                        Skipped      = 1,
                        CreationTime = 1528360285
                    }
                };
                var monMessageForSecondPulse = new MonitoringMessage
                {
                    ID                    = 0,
                    MessageType           = MonitoringMessageType.DangerNoPingReturnedSkippedChildren,
                    MessageSourceNodeName = NodeNames[0],
                    NumSkippedChildren    = 0
                };
                context.MonitoringSessions.Add(testSession);
                context.MonitoringPulses.AddRange(pulses);
                context.SaveChanges();
                pulses[1] = context.MonitoringPulses
                            .Include(p => p.Messages)
                            .Single(p => p.ID == pulses[1].ID);
                testSession = context.MonitoringSessions
                              .Include(s => s.Pulses)
                              .Single(s => s.ID == testSession.ID);
                testSession.Pulses.Add(pulses[0]);
                testSession.Pulses.Add(pulses[1]);
                pulses[1].Messages.Add(monMessageForSecondPulse);
                context.SaveChanges();
            }

            TestIDsSet idsSet = new TestIDsSet
            {
                ProfileId      = testProfile.ID,
                WebServicesIDs = testWebServices.Select(s => s.ID).ToArray(),
                NodesIDs       = testNodes.Select(n => n.ID).ToArray(),
                TagsIDs        = testTags.Select(t => t.ID).ToArray(),
            };

            CreateClosuresForTestNodes(context, idsSet);
            return(idsSet);
        }