private void StopUploaderForWinFabFolder(FileShareUploader uploader)
        {
            if (null == uploader)
            {
                return;
            }

            uploader.Dispose();
        }
        private bool CreateUploaderForWinFabFolder(
            string source,
            string destination,
            string workFolder,
            out FileShareUploader uploader)
        {
            uploader = null;

            // Create and initialize the uploader
            try
            {
                FileShareUploader newUploader = new FileShareUploader(
                    this.traceSource,
                    this.logSourceId,
                    false, // runningOnBehalfOfApplication
                    source,
                    destination,
                    this.fileUploadSettings.AccessInfo,
                    workFolder,
                    this.fileUploadSettings.UploadInterval,
                    this.fileUploadSettings.FileSyncInterval,
                    this.fileUploadSettings.FileDeletionAgeMinutes,
                    this.fileUploadSettings.DestinationIsLocalAppFolder,
                    this.initParam.FabricNodeId);
                newUploader.Start();

                this.traceSource.WriteInfo(
                    this.logSourceId,
                    "Upload to file share is configured.  Destination: {0}, Local folder path: {1}, Upload interval (minutes): {2}.",
                    destination,
                    source,
                    this.fileUploadSettings.UploadInterval);
                uploader = newUploader;
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        private void StopUploaderForApplicationFolder(FileShareUploader uploader)
        {
            if (null == uploader)
            {
                return;
            }

            lock (AllUploaders)
            {
                // Drop the reference count on the uploader object
                UploaderInfo uploaderInfo = AllUploaders.FirstOrDefault(w => w.Uploader.Equals(uploader));
                uploaderInfo.RefCount--;
                if (0 == uploaderInfo.RefCount)
                {
                    // Tell the uploader object to stop
                    this.traceSource.WriteInfo(
                        this.logSourceId,
                        "Stopping uploader object for application type {0}, source {1} and destination {2} ...",
                        uploaderInfo.Key.ApplicationType,
                        uploaderInfo.Key.SourcePath,
                        uploaderInfo.Key.DestinationPath);

                    uploaderInfo.Uploader.Dispose();
                    AllUploaders.Remove(uploaderInfo);
                }
                else
                {
                    this.traceSource.WriteInfo(
                        this.logSourceId,
                        "Uploader object for application type {0}, source {1} and destination {2} is still in use by other uploaders, so let it continue running",
                        uploaderInfo.Key.ApplicationType,
                        uploaderInfo.Key.SourcePath,
                        this.fileUploadSettings.DestinationPath);
                }
            }
        }
Esempio n. 4
0
        internal EtwCsvUploadWorker(EtwCsvUploadWorkerParameters param, FabricEvents.ExtensionsEvents traceSource)
        {
            // Initialization
            Action onError = () =>
            {
                if (null != this.etlToCsvWriter)
                {
                    this.etlToCsvWriter.Dispose();
                }
            };

            this.logSourceId        = param.UploaderInstanceId;
            this.traceSource        = traceSource;
            this.fileUploadSettings = param.Settings;
            this.etwCsvFolder       = string.Empty;
            this.initParam          = param;

            if (false == this.fileUploadSettings.DestinationIsLocalAppFolder)
            {
                // Append fabric node instance name to destination path, so that
                // each node uploads to a different subfolder.
                this.destinationPathForNode = Path.Combine(
                    this.fileUploadSettings.DestinationPath,
                    param.FabricNodeInstanceName);
            }
            else
            {
                this.destinationPathForNode = this.fileUploadSettings.DestinationPath;
            }

            // Create a sub-directory for ourselves under the log directory
            this.etwCsvFolder = this.GetEtwCsvSubDirectory();
            if (!string.IsNullOrWhiteSpace(this.etwCsvFolder))
            {
                // Create the helper object that writes events delivered from the ETL
                // files into CSV files.
                this.etlToCsvWriter = new EtlToCsvFileWriter(
                    new TraceEventSourceFactory(),
                    this.logSourceId,
                    param.FabricNodeId,
                    this.etwCsvFolder,
                    false,
                    param.DiskSpaceManager,
                    new EtlToCsvFileWriterConfigReader());
            }

            // Set the event filter
            this.etlToCsvWriter.SetEtwEventFilter(
                this.fileUploadSettings.Filter,
                param.IsReadingFromApplicationManifest ? string.Empty : WinFabDefaultFilter.StringRepresentation,
                param.IsReadingFromApplicationManifest ? string.Empty : WinFabSummaryFilter.StringRepresentation,
                !param.IsReadingFromApplicationManifest);

            // Create a sub-directory for the uploader under the log directory
            if (!this.GetUploaderWorkSubDirectory())
            {
                onError();
                throw new InvalidOperationException();
            }

            try
            {
                this.uploader = new FileShareUploader(
                    this.traceSource,
                    this.logSourceId,
                    param.IsReadingFromApplicationManifest,
                    this.etwCsvFolder,
                    this.destinationPathForNode,
                    this.fileUploadSettings.AccessInfo,
                    this.workFolder,
                    this.fileUploadSettings.UploadInterval,
                    this.fileUploadSettings.FileSyncInterval,
                    this.fileUploadSettings.FileDeletionAgeMinutes,
                    this.fileUploadSettings.DestinationIsLocalAppFolder,
                    param.FabricNodeId);
                this.uploader.Start();
            }
            catch (Exception)
            {
                onError();
                throw;
            }

            this.traceSource.WriteInfo(
                this.logSourceId,
                "Upload to file share is configured. Destination: {0}, Local trace Path: {1}.",
                this.fileUploadSettings.DestinationPath,
                this.etwCsvFolder);
        }
Esempio n. 5
0
        internal void UpdateSettings(FileShareEtwCsvUploader.FileUploadSettings newSettings)
        {
            bool updateFilter   = this.ShouldUpdateFilter(newSettings);
            bool updateUploader = this.ShouldUpdateUploader(newSettings);

            if (updateFilter || updateUploader)
            {
                this.fileUploadSettings = newSettings;
            }

            if (updateFilter)
            {
                if (null != this.etlToCsvWriter)
                {
                    // Update the filter
                    Debug.Assert(this.initParam.IsReadingFromApplicationManifest, "Event filter updates are not allowed for cluster level diagnostics.");
                    this.etlToCsvWriter.SetEtwEventFilter(
                        this.fileUploadSettings.Filter,
                        string.Empty,
                        string.Empty,
                        false);
                    this.traceSource.WriteInfo(
                        this.logSourceId,
                        "ETW event filter has been updated due to settings change. New ETW event filter: {0}.",
                        this.fileUploadSettings.Filter);
                }
            }

            if (updateUploader)
            {
                this.traceSource.WriteInfo(
                    this.logSourceId,
                    "Due to settings change, the uploader will be stopped and restarted.");

                // Stop the uploader
                if (null != this.uploader)
                {
                    this.uploader.Dispose();
                }

                // Restart the upload with the new settings
                try
                {
                    this.uploader = new FileShareUploader(
                        this.traceSource,
                        this.logSourceId,
                        this.initParam.IsReadingFromApplicationManifest,
                        this.etwCsvFolder,
                        this.destinationPathForNode,
                        this.fileUploadSettings.AccessInfo,
                        this.workFolder,
                        this.fileUploadSettings.UploadInterval,
                        this.fileUploadSettings.FileSyncInterval,
                        this.fileUploadSettings.FileDeletionAgeMinutes,
                        this.fileUploadSettings.DestinationIsLocalAppFolder,
                        this.initParam.FabricNodeId);
                    this.uploader.Start();
                }
                catch (Exception)
                {
                    this.uploader = null;
                    this.traceSource.WriteError(
                        this.logSourceId,
                        "Failed to restart uploader.");
                }
            }
        }
        private bool CreateUploaderForApplicationFolder(
            string uploaderId,
            string source,
            string destination,
            string workFolder,
            out FileShareUploader uploader)
        {
            uploader = null;
            bool success;
            FileShareUploader newUploader = null;

            // Check if we can use an existing uploader object
            UploaderKey key = new UploaderKey()
            {
                SourcePath      = source,
                DestinationPath = destination,
                ApplicationType = this.configReader.GetApplicationType(),
            };

            lock (AllUploaders)
            {
                UploaderInfo uploaderInfo = AllUploaders.FirstOrDefault(w => w.Matches(key));
                if (null != uploaderInfo)
                {
                    // Existing uploader object is available. Increment its reference count
                    this.traceSource.WriteInfo(
                        this.logSourceId,
                        "Existing uploader object for application type {0}, source {1} and destination {2} is available and will be used.",
                        key.ApplicationType,
                        source,
                        destination);

                    uploaderInfo.RefCount++;
                    newUploader = uploaderInfo.Uploader;
                    success     = true;
                }
                else
                {
                    // Create a new uploader object
                    this.traceSource.WriteInfo(
                        this.logSourceId,
                        "Creating uploader object for application type {0}, source {1} and destination {2} ...",
                        key.ApplicationType,
                        source,
                        destination);

                    // Create and initialize the uploader
                    try
                    {
                        newUploader = new FileShareUploader(
                            this.traceSource,
                            uploaderId,
                            true, // runningOnBehalfOfApplication
                            source,
                            destination,
                            this.fileUploadSettings.AccessInfo,
                            workFolder,
                            this.fileUploadSettings.UploadInterval,
                            this.fileUploadSettings.FileSyncInterval,
                            this.fileUploadSettings.FileDeletionAgeMinutes,
                            this.fileUploadSettings.DestinationIsLocalAppFolder,
                            this.initParam.FabricNodeId);
                        newUploader.Start();
                        success = true;
                    }
                    catch (Exception)
                    {
                        success = false;
                    }

                    if (success)
                    {
                        uploaderInfo = new UploaderInfo()
                        {
                            Key      = key,
                            RefCount = 1,
                            Uploader = newUploader
                        };
                        AllUploaders.Add(uploaderInfo);
                    }
                    else
                    {
                        this.traceSource.WriteError(
                            this.logSourceId,
                            "Failed to create uploader object for application type {0}, source {1} and destination {2}.",
                            key.ApplicationType,
                            source,
                            destination);
                    }
                }
            }

            if (success)
            {
                this.traceSource.WriteInfo(
                    this.logSourceId,
                    "Upload to file share is configured.  Destination: {0}, Local folder path: {1}, Upload interval (minutes): {2}.",
                    destination,
                    source,
                    this.fileUploadSettings.UploadInterval);
                uploader = newUploader;
            }

            return(success);
        }