Beispiel #1
0
        /// <summary>
        /// Creates all of the required MongoDB collections that this logset requires.
        /// </summary>
        protected ISet <string> CreateMongoDbCollections(ISet <string> requestedCollections, IMongoDatabase database, IParserFactory parserFactory)
        {
            IDictionary <string, ISet <string> > collectionIndexMap = BuildCollectionIndexMap(requestedCollections, parserFactory);

            // Create collections & indexes using the dictionary.
            ISet <string> collectionsCreated = new SortedSet <string>();

            foreach (var collection in collectionIndexMap)
            {
                var           collectionName = collection.Key;
                ISet <string> indexes        = collection.Value;

                IMongoCollection <BsonDocument> dbCollection = database.GetCollection <BsonDocument>(collectionName);
                collectionsCreated.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.
                if (mongoConnectionInfo.ConnectionType == MongoConnectionType.ShardedCluster)
                {
                    MongoAdminHelper.EnableShardingOnCollectionIfNotEnabled(mongoConnectionInfo.GetClient(), database.DatabaseNamespace.DatabaseName, collectionName);
                }
            }

            return(collectionsCreated);
        }
Beispiel #2
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);
                }
            }
        }
Beispiel #3
0
 protected bool RemoteLogsetHasData(string mongoDatabaseName)
 {
     return(MongoAdminHelper.DatabaseExists(mongoConnectionInfo.GetClient(), mongoDatabaseName));
 }