Exemplo n.º 1
0
        /// <summary>
        /// Creates all of the required MongoDB collections that this logset requires.
        /// </summary>
        private void CreateMongoDbCollections()
        {
            var collections = new Dictionary <string, HashSet <string> >();

            ISet <IParser> parsers = parserFactory.GetAllParsers();

            // Stuff collection names & indexes into the dictionary, deduping in the process.
            foreach (var parser in parsers)
            {
                var            collectionName = parser.CollectionSchema.CollectionName.ToLowerInvariant();
                IList <string> indexes        = parser.CollectionSchema.Indexes;

                if (!collections.ContainsKey(collectionName))
                {
                    if (LogsetDependencyHelper.IsCollectionRequiredForRequest(collectionName, logsharkRequest))
                    {
                        collections.Add(collectionName, new HashSet <string>());
                    }
                }

                // Add indexes.
                if (collections.ContainsKey(collectionName))
                {
                    foreach (var index in indexes)
                    {
                        if (collections.ContainsKey(collectionName))
                        {
                            collections[collectionName].Add(index);
                        }
                    }
                }
            }

            // New up collections & indexes using the dictionary.
            foreach (var collection in collections)
            {
                var           collectionName = collection.Key;
                ISet <string> indexes        = collection.Value;

                var dbCollection = database.GetCollection <BsonDocument>(collectionName);
                logsharkRequest.RunContext.CollectionsGenerated.Add(collectionName);

                foreach (var index in indexes)
                {
                    var indexKeysBuilder            = new IndexKeysDefinitionBuilder <BsonDocument>();
                    CreateIndexOptions indexOptions = new CreateIndexOptions {
                        Sparse = false
                    };
                    dbCollection.Indexes.CreateOne(indexKeysBuilder.Ascending(index), indexOptions);
                }

                // If we are working against a sharded Mongo cluster, we need to explicitly shard each collection.
                MongoConnectionInfo mongoConnectionInfo = logsharkRequest.Configuration.MongoConnectionInfo;
                if (mongoConnectionInfo.ConnectionType == MongoConnectionType.ShardedCluster)
                {
                    MongoAdminUtil.EnableShardingOnCollectionIfNotEnabled(mongoConnectionInfo.GetClient(), logsharkRequest.RunContext.MongoDatabaseName, collectionName);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Loads of all the logs required for this request.
        /// </summary>
        /// <returns>Log contexts for all logs required for request.</returns>
        public IEnumerable <LogFileContext> LoadRequiredLogs()
        {
            var logsToProcess = new List <LogFileContext>();

            // Filter down to only supported files.
            var supportedFiles = GetSupportedFiles(request.RunContext.RootLogDirectory);

            // Filter supported files to keep only what we need to populate the required collections.
            foreach (var supportedFile in supportedFiles)
            {
                var    parser         = parserFactory.GetParser(supportedFile.FullName);
                string collectionName = parser.CollectionSchema.CollectionName.ToLowerInvariant();

                if (LogsetDependencyHelper.IsCollectionRequiredForRequest(collectionName, request))
                {
                    logsToProcess.Add(new LogFileContext(supportedFile.FullName, request.RunContext.RootLogDirectory));
                }
            }

            return(logsToProcess);
        }