Ejemplo n.º 1
0
        protected override void Initialize(LogsetParsingRequest request)
        {
            IMongoDatabase database      = mongoConnectionInfo.GetDatabase(request.LogsetHash);
            IParserFactory parserFactory = request.ArtifactProcessor.GetParserFactory(request.Target);

            var metadata = new LogProcessingMetadata(request);

            metadataWriter.Write(metadata, request.LogsetHash);

            CreateMongoDbCollections(request.CollectionsToParse, database, parserFactory);
        }
        /// <summary>
        /// Indicates whether the given MongoDB database contains at least one document.
        /// </summary>
        /// <param name="mongoDatabaseName">The name of the MongoDB database to check.</param>
        /// <returns>True if at least one document exists in the specified database.</returns>
        protected bool ContainsData(string mongoDatabaseName)
        {
            try
            {
                IMongoDatabase database = mongoConnectionInfo.GetDatabase(mongoDatabaseName);

                foreach (var collectionDocument in database.ListCollections().ToList())
                {
                    string collectionName = collectionDocument.GetValue("name").AsString;
                    IMongoCollection <BsonDocument> collection = database.GetCollection <BsonDocument>(collectionName);

                    if (ContainsData(collection))
                    {
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.ErrorFormat("Encountered exception while validating contents of MongoDB database {0}: {1}", mongoDatabaseName, ex.Message);
                return(false);
            }

            return(false);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Handles initialization of an IPlugin object for a given plugin type.
        /// </summary>
        protected IPlugin InitializePlugin(Type pluginType, string mongoDatabaseName, string postgresDatabaseName, IEnumerable <IPluginResponse> previousPluginResponses)
        {
            Log.InfoFormat("Initializing {0} plugin..", pluginType.Name);

            try
            {
                // Create plugin object.
                var plugin = (IPlugin)Activator.CreateInstance(pluginType);

                // Set database connections.
                plugin.MongoDatabase = mongoConnectionInfo.GetDatabase(mongoDatabaseName);
                plugin.OutputDatabaseConnectionFactory = postgresConnectionInfo.GetConnectionFactory(postgresDatabaseName);

                if (PluginLoader.IsPostExecutionPlugin(pluginType))
                {
                    IPostExecutionPlugin postExecutionPlugin = (IPostExecutionPlugin)plugin;
                    postExecutionPlugin.PluginResponses = previousPluginResponses;
                    return(postExecutionPlugin);
                }
                else
                {
                    return(plugin);
                }
            }
            catch (Exception ex)
            {
                throw new PluginInitializationException(ex.Message, ex);
            }
        }
Ejemplo n.º 4
0
        void IModelDataGatewayInitializeable.Initialize<T>(ModelActionOption option, IContext context, T t, ICriterion criterion, ResolveDbKey<T> dbkeyResolver)
        {
            string key = ResolveConnectionStringKey(context);
            if (String.IsNullOrWhiteSpace(key))
            {
                key = dbkeyResolver.Invoke(context);
            }
            if (String.IsNullOrEmpty(key))
            {
                var message = Exceptions.ComposeDbConnectionStringKeyResolutionError<T>(option, t, context);
                context.SetError(500, message.ToPublish() );
                EventWriter.WriteError(message.ToLog(), SeverityType.Error);
            }
            else
            {
                var cn = ConfigurationManager.ConnectionStrings[key];
                if (cn != null)
                {
                    MongoConnectionInfo info = new MongoConnectionInfo();
                    if (info.Initialize(cn))
                    {
                        MongoDb = info.GetDatabase();
                    }

                    if (MongoDb == null)
                    {
                        var message = Exceptions.ComposeDbConnectionCreationError<T>(option, t, context, key);
                        context.SetError(500, message.ToPublish());
                        EventWriter.WriteError(message.ToLog(), SeverityType.Error);
                    }
                    else
                    {
                        Collection = GetCollection();
                        if (Collection == null)
                        {
                            context.SetError(500, "MongoDB.Collection is Null");
                        }
                        else if (eXtensibleConfig.CaptureMetrics)
                        {
                            IRequestContext ctx = context as IRequestContext;
                            ctx.SetMetric(XFConstants.Metrics.Scope.DataStore, XFConstants.Metrics.Database.Datasource, String.Format("server:{0};database:{1};", cn.ConnectionString, key)); ;
                        }
                    }
                }
                else
                {
                    var message = Exceptions.ComposeDbConnectionCreationError<T>(option, t, context, key);
                    context.SetError(500, message.ToPublish());
                    EventWriter.WriteError(message.ToLog(), SeverityType.Error);
                }

            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Instantiates a plugin request for the given plugin type.
        /// </summary>
        /// <param name="pluginType">The type of the plugin.</param>
        /// <param name="pluginExecutionRequest">The options associated with the plugin request.</param>
        /// <returns>IPluginRequest with all appropriate state initialized.</returns>
        protected IPluginRequest CreatePluginRequest(Type pluginType, PluginExecutionRequest pluginExecutionRequest)
        {
            Guid   logsetHash              = Guid.Parse(pluginExecutionRequest.LogsetHash);
            string outputDirectory         = GetPluginOutputDirectory(pluginExecutionRequest.RunId);
            string applicationLogDirectory = GetApplicationLogDirectory();
            var    mongoDatabase           = mongoConnectionInfo.GetDatabase(pluginExecutionRequest.MongoDatabaseName);

            var pluginRequest = new PluginRequest(logsetHash, outputDirectory, applicationTempDirectory, applicationLogDirectory, pluginExecutionRequest.RunId, mongoDatabase);

            // Append all global and plugin specific arguments to the plugin argument map.
            foreach (string argumentKey in pluginExecutionRequest.PluginArguments.Keys)
            {
                if (argumentKey.StartsWith(pluginType.Name + ".", StringComparison.InvariantCultureIgnoreCase) ||
                    argumentKey.StartsWith("Global.", StringComparison.InvariantCultureIgnoreCase))
                {
                    pluginRequest.SetRequestArgument(argumentKey, pluginExecutionRequest.PluginArguments[argumentKey]);
                }
            }

            return(pluginRequest);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Returns an object with all of the metadata about the processing of a logset.
        /// </summary>
        /// <returns>LogProcessingMetadata object pulled from Mongo.</returns>
        public LogProcessingMetadata Read(string databaseName)
        {
            IMongoCollection <LogProcessingMetadata> metadataCollection = mongoConnectionInfo.GetDatabase(databaseName).GetCollection <LogProcessingMetadata>(MongoMetadataCollectionName);

            return(GetMetadata(metadataCollection, databaseName));
        }