/// <summary> /// Display a summary of the run to the user, including locations of any assets. /// </summary> public static void DisplayRunSummary(LogsharkRequest request) { // Display logset hash, if relevant. if (!String.IsNullOrWhiteSpace(request.RunContext.LogsetHash)) { Log.InfoFormat("Logset hash for this run was '{0}'.", request.RunContext.LogsetHash); } // Display Postgres output location, if relevant. int pluginSuccesses = request.RunContext.PluginResponses.Count(pluginResponse => pluginResponse.SuccessfulExecution); if (pluginSuccesses > 0) { Log.InfoFormat("Plugin backing data was written to Postgres database '{0}\\{1}'.", request.Configuration.PostgresConnectionInfo, request.PostgresDatabaseName); } // A plugin may run successfully, yet not output a workbook. We only want to display the workbook output location if at least one workbook was output. int workbooksOutput = request.RunContext.PluginResponses.Sum(pluginResponse => pluginResponse.WorkbooksOutput.Count); if (workbooksOutput > 0) { Log.InfoFormat("Plugin workbook output was saved to '{0}'.", PluginExecutor.GetOutputLocation(request.RunId)); } // Display information about any published workbooks, if relevant. if (request.PublishWorkbooks && pluginSuccesses > 0) { Log.Info(WorkbookPublisher.BuildPublishingSummary(request.RunContext.PublishedWorkbooks)); } }
public PluginExecutor(LogsharkRequest request) { logsharkRequest = request; mongoDatabase = request.Configuration.MongoConnectionInfo.GetDatabase(logsharkRequest.RunContext.MongoDatabaseName); outputDatabaseConnectionFactory = request.Configuration.PostgresConnectionInfo.GetConnectionFactory(logsharkRequest.PostgresDatabaseName); workbookPublisher = new WorkbookPublisher(logsharkRequest); }
public virtual string BuildRunSummary() { var summary = new StringBuilder(); // Display logset hash, if relevant. if (InitializationResult != null && !String.IsNullOrWhiteSpace(InitializationResult.LogsetHash)) { summary.AppendFormat("Logset hash for this run was '{0}'.", InitializationResult.LogsetHash); } // Display Postgres output location, if relevant. if (PluginExecutionResult != null) { int pluginSuccesses = PluginExecutionResult.PluginResponses.Count(pluginResponse => pluginResponse.SuccessfulExecution); if (pluginSuccesses > 0) { Request.Configuration.PostgresConnectionInfo.MatchSome(connectionInfo => { summary.AppendLine(); summary.AppendFormat("Plugin backing data was written to Postgres database '{0}\\{1}'.", connectionInfo, Request.PostgresDatabaseName); }); } // A plugin may run successfully, yet not output a workbook. We only want to display the workbook output location if at least one workbook was output. int workbooksOutput = PluginExecutionResult.PluginResponses.Sum(pluginResponse => pluginResponse.WorkbooksOutput.Count); if (workbooksOutput > 0) { summary.AppendLine(); summary.AppendFormat("Plugin workbook output was saved to '{0}'.", PluginExecutor.GetRunOutputDirectory(Request.Configuration.ApplicationOutputDirectory, Request.RunId)); } // Display information about any published workbooks, if relevant. if (Request.PublishWorkbooks && pluginSuccesses > 0) { var publishedWorkbookResults = PluginExecutionResult.PluginResponses .Where(response => response.WorkbooksPublished != null) .SelectMany(response => response.WorkbooksPublished) .ToList(); summary.AppendLine(); summary.AppendFormat(WorkbookPublisher.BuildPublishingSummary(publishedWorkbookResults)); } } return(summary.ToString()); }
/// <summary> /// Executes a single plugin. /// </summary> /// <param name="pluginType">The type of the plugin to execute.</param> /// <param name="pluginExecutionRequest">Plugin execution options.</param> /// <param name="previousPluginResponses">The set of plugin responses associated with the current run. Used for plugin chaining.</param> /// <returns>Response containing state about the success/failure of the plugin's execution.</returns> protected IPluginResponse ExecutePlugin(Type pluginType, PluginExecutionRequest pluginExecutionRequest, IEnumerable <IPluginResponse> previousPluginResponses) { string pluginName = pluginType.Name; // Setup plugin for execution. IPluginRequest pluginRequest = CreatePluginRequest(pluginType, pluginExecutionRequest); var pluginTimer = new LogsharkTimer("Executed Plugin", pluginName, GlobalEventTimingData.Add); // Execute plugin. IPluginResponse pluginResponse = new PluginResponse(pluginName); try { string outputDatabaseName = GetOutputDatabaseName(pluginName, pluginRequest, pluginExecutionRequest); var plugin = InitializePlugin(pluginType, pluginRequest, pluginExecutionRequest.MongoDatabaseName, outputDatabaseName, previousPluginResponses); Log.InfoFormat("Execution of {0} plugin started at {1}..", pluginName, DateTime.Now.ToString("h:mm tt", CultureInfo.InvariantCulture)); pluginResponse = plugin.Execute(); // Flush any workbooks, if this was a workbook creation plugin. if (plugin is IWorkbookCreationPlugin) { IEnumerable <string> workbookFilePaths = WriteWorkbooksToDisk(pluginRequest.OutputDirectory, plugin as IWorkbookCreationPlugin, pluginResponse, outputDatabaseName); pluginResponse.WorkbooksOutput.AddRange(workbookFilePaths); } // Publish any associated workbooks, if requested. if (pluginExecutionRequest.PublishingOptions != null && pluginExecutionRequest.PublishingOptions.PublishWorkbooks) { var restApiRequestor = new RestApiRequestor(tableauConnectionInfo.Uri, tableauConnectionInfo.Username, tableauConnectionInfo.Password, tableauConnectionInfo.Site); var workbookPublisher = new WorkbookPublisher(tableauConnectionInfo, postgresConnectionInfo, pluginExecutionRequest.PublishingOptions, restApiRequestor); ICollection <PublishedWorkbookResult> workbooksPublished = workbookPublisher.PublishWorkbooks(pluginResponse); pluginResponse.WorkbooksPublished.AddRange(workbooksPublished); } } catch (PluginInitializationException ex) { string errorMessage = String.Format("Failed to initialize {0} plugin: {1}", pluginName, ex.Message); HandlePluginExecutionFailure(pluginResponse, errorMessage, ex); } catch (PublishingException ex) { string errorMessage = String.Format("Failed to publish workbooks: {0}", ex.Message); HandlePluginExecutionFailure(pluginResponse, errorMessage, ex); } catch (Exception ex) { string errorMessage = String.Format("Encountered uncaught exception while executing plugin '{0}': {1}", pluginName, ex.GetFlattenedMessage()); HandlePluginExecutionFailure(pluginResponse, errorMessage, ex); } finally { pluginTimer.Stop(); pluginResponse.PluginRunTime = pluginTimer.Elapsed; LogExecutionOutcome(pluginResponse); } return(pluginResponse); }