Пример #1
0
        public override IPluginResponse Execute(IPluginRequest pluginRequest)
        {
            pluginResponse = CreatePluginResponse();
            logsetHash     = pluginRequest.LogsetHash;
            IMongoCollection <BsonDocument> tabadminCollection = MongoDatabase.GetCollection <BsonDocument>(collectionToQuery);

            persistenceHelper = GetConcurrentBatchPersister <TabadminModelBase>(pluginRequest);

            using (IDbConnection dbConnection = GetOutputDatabaseConnection())
            {
                Log.Info("Processing Tableau Server version data from tabadmin logs...");
                dbConnection.CreateOrMigrateTable <TSVersion>();
                TabadminVersionProcessor.Execute(tabadminCollection, persistenceHelper, pluginResponse, logsetHash);

                // TODO: Create one class for processing Action and Error objects, as they are nearly identical.
                Log.Info("Processing tabadmin error data...");
                dbConnection.CreateOrMigrateTable <TabadminError>();
                TabadminErrorProcessor.Execute(tabadminCollection, persistenceHelper, pluginResponse, logsetHash);

                Log.Info("Processing tabadmin admin action data...");
                dbConnection.CreateOrMigrateTable <TabadminAction>();
                TabadminActionProcessor.Execute(tabadminCollection, persistenceHelper, pluginResponse, logsetHash);

                // Shutdown the persistenceHelper to force a flush to the database, then re-initialize it for future use.
                persistenceHelper.Shutdown();
                persistenceHelper = GetConcurrentBatchPersister <TabadminModelBase>(pluginRequest);

                IList <TSVersion> allTsVersions = dbConnection.Query <TSVersion>("select * from tabadmin_ts_version");

                // TODO: Figure out how to do a lazy query of Error and Action objects, and update them one at a time, rather than loading
                // the entire table into memory. I ran into issues updating the objects while holding the SELECT query connection open with Each().
                // The driver doesn't seem to be able to handle two connections at once.
                Log.Info("Updating version_id foreign keys for TabadminError objects...");
                foreach (var tabadminError in dbConnection.Query <TabadminError>("select * from tabadmin_error"))
                {
                    tabadminError.VersionId = TSVersionHelper.GetTSVersionIdByDate(allTsVersions, tabadminError);
                    dbConnection.Update(tabadminError);
                }

                Log.Info("Updating version_id foreign keys for TabadminAction objects...");
                foreach (var tabadminAction in dbConnection.Query <TabadminAction>("select * from tabadmin_action"))
                {
                    tabadminAction.VersionId = TSVersionHelper.GetTSVersionIdByDate(allTsVersions, tabadminAction);
                    dbConnection.Update(tabadminAction);
                }
            }
            persistenceHelper.Shutdown();

            // Check if we persisted any data.
            if (!PostgresHelper.ContainsRecord <TSVersion>(OutputDatabaseConnectionFactory) &&
                !PostgresHelper.ContainsRecord <TabadminError>(OutputDatabaseConnectionFactory) &&
                !PostgresHelper.ContainsRecord <TabadminAction>(OutputDatabaseConnectionFactory))
            {
                Log.Info("Failed to persist any data from Tabadmin logs!");
                pluginResponse.GeneratedNoData = true;
            }

            return(pluginResponse);
        }
Пример #2
0
        /// <summary>
        /// Execute the processing of version information and persist the results to the database.
        /// </summary>
        /// <param name="collection">A collection initialized for the "tabadmin" collection.</param>
        /// <param name="persister">A generic persister for TabadminModelBase will work.</param>
        /// <param name="pluginResponse">Logshark plugin response.</param>
        /// <param name="logsetHash">The unique fingerprint of the logset.</param>
        public static void Execute(IMongoCollection <BsonDocument> collection, IPersister <TabadminModelBase> persister, PluginResponse pluginResponse, Guid logsetHash)
        {
            var tabadminVersionProcessor = new TabadminVersionProcessor(collection, persister, pluginResponse, logsetHash);

            tabadminVersionProcessor.QueryMongo();
            List <TSVersion> reducedVersionList = tabadminVersionProcessor.ReduceVersionLists();

            tabadminVersionProcessor.AddEndDatesToVersionList(reducedVersionList);
            tabadminVersionProcessor.PersistVersionListToDatabase(reducedVersionList);
        }
Пример #3
0
        public override IPluginResponse Execute()
        {
            var pluginResponse = CreatePluginResponse();

            IMongoCollection <BsonDocument> collection = MongoDatabase.GetCollection <BsonDocument>(ParserConstants.TabAdminCollectionName);

            Log.Info("Processing Tableau Server version data from tabadmin logs...");
            var versions = TabadminVersionProcessor.BuildVersionTimeline(collection).ToList();

            bool persistedData;

            using (var persister = ExtractFactory.CreateExtract <TableauServerVersion>())
                using (GetPersisterStatusWriter(persister, versions.Count))
                {
                    persister.Enqueue(versions);
                    persistedData = persister.ItemsPersisted > 0;
                }

            using (var persister = ExtractFactory.CreateExtract <TabadminError>())
                using (var processor = new SimpleModelProcessor <BsonDocument, TabadminError>(persister, Log))
                {
                    var filter = BuildTabadminErrorFilter();
                    processor.Process(collection, new QueryDefinition <BsonDocument>(filter), document => new TabadminError(document, versions), filter);

                    persistedData = persistedData || persister.ItemsPersisted > 0;
                }

            using (var persister = ExtractFactory.CreateExtract <TabadminAction>())
                using (var processor = new SimpleModelProcessor <BsonDocument, TabadminAction>(persister, Log))
                {
                    var filter = BuildTabadminActionFilter();
                    processor.Process(collection, new QueryDefinition <BsonDocument>(filter), document => new TabadminAction(document, versions), filter);

                    persistedData = persistedData || persister.ItemsPersisted > 0;
                }

            if (!persistedData)
            {
                Log.Info("Failed to persist any data from Tabadmin logs!");
                pluginResponse.GeneratedNoData = true;
            }

            return(pluginResponse);
        }