示例#1
0
        protected PublishedWorkbookResult PublishWorkbook(RestApiRequestor requestor, string pluginName, string workbookPath, bool overwriteExistingWorkbook = true)
        {
            var workbookFilename = Path.GetFileName(workbookPath);

            // Tag the workbook with the name of the plugin that generated it.
            logsharkRequest.WorkbookTags.Add(pluginName);

            Log.InfoFormat("Publishing workbook '{0}' to {1}..", workbookFilename, tableauConnectionInfo.ToUri());

            var publishWorkbookRequest = new PublishWorkbookRequest(workbookPath)
            {
                PluginName         = pluginName,
                SiteId             = siteId,
                SiteName           = tableauConnectionInfo.Site,
                ProjectId          = projectId,
                ProjectName        = logsharkRequest.ProjectName,
                DatasourceUserName = postgresConnectionInfo.Username,
                DatasourcePassword = postgresConnectionInfo.Password,
                Tags = logsharkRequest.WorkbookTags,
                OverwriteExistingWorkbook = overwriteExistingWorkbook,
                ShowSheetsAsTabs          = true,
                publishingTimeoutSeconds  = tableauConnectionInfo.PublishingTimeoutSeconds
            };

            PublishedWorkbookResult result = requestor.PublishWorkbookWithEmbeddedCredentials(publishWorkbookRequest);
            int attemptsMade = 1;

            while (!result.IsSuccessful && attemptsMade < CoreConstants.WORKBOOK_PUBLISHING_MAX_ATTEMPTS)
            {
                Log.WarnFormat("Workbook publishing attempt #{0} failed.  Retrying in {1} {2}..",
                               attemptsMade, CoreConstants.WORKBOOK_PUBLISHING_RETRY_DELAY_SEC, "second".Pluralize(CoreConstants.WORKBOOK_PUBLISHING_RETRY_DELAY_SEC));
                Thread.Sleep(1000 * CoreConstants.WORKBOOK_PUBLISHING_RETRY_DELAY_SEC);

                result = requestor.PublishWorkbookWithEmbeddedCredentials(publishWorkbookRequest);
                attemptsMade++;
            }

            if (!result.IsSuccessful)
            {
                Log.ErrorFormat("Publishing of workbook '{0}' failed: {1} [{2} {3} made]", workbookFilename, result.ErrorMessage, attemptsMade, "attempt".Pluralize(attemptsMade));
            }

            return(result);
        }
 protected void InitializeProject(RestApiRequestor requestor)
 {
     // Get all of the information we'll need to compose our publishing requests, and cache it for future publishing attempts.
     if (String.IsNullOrWhiteSpace(siteId))
     {
         siteId = requestor.GetSiteId();
     }
     if (String.IsNullOrWhiteSpace(projectId))
     {
         projectId = requestor.GetOrCreateProject(logsharkRequest.ProjectName, BuildProjectDescription());
     }
     if (String.IsNullOrWhiteSpace(groupId))
     {
         groupId = requestor.GetGroupId(LogsharkConstants.DEFAULT_PROJECT_PERMISSIONS_GROUP);
     }
     if (!hasSetProjectPermissions)
     {
         requestor.AddDefaultProjectPermissions(projectId, groupId, LogsharkConstants.DEFAULT_PROJECT_PERMISSIONS);
         hasSetProjectPermissions = true;
     }
 }
        protected ICollection <PublishedWorkbookResult> PublishWorkbooks(string pluginName, IEnumerable <string> workbooksToPublish)
        {
            var requestor = new RestApiRequestor(tableauConnectionInfo.ToUri(), tableauConnectionInfo.Username, tableauConnectionInfo.Password, tableauConnectionInfo.Site);

            try
            {
                InitializeProject(requestor);
            }
            catch (Exception ex)
            {
                throw new PublishingException(String.Format("Unable to initialize Tableau Server for publishing: {0}", ex.Message), ex);
            }

            // Publish all the workbooks.
            var publishedWorkbookResults = new List <PublishedWorkbookResult>();

            foreach (var workbook in workbooksToPublish)
            {
                PublishedWorkbookResult publishedWorkbookResult = PublishWorkbook(requestor, pluginName, workbook);
                publishedWorkbookResults.Add(publishedWorkbookResult);
            }

            return(publishedWorkbookResults);
        }
示例#4
0
        /// <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);
        }