public void FlushData()
 {
     if (this.configReader.IsReadingFromApplicationManifest)
     {
         UploadWorkerKey key = new UploadWorkerKey()
         {
             // Destination path is an concatenation of storage account name and container name
             DestinationPath = string.Concat(
                 this.blobUploadSettings.StorageAccountFactory.Connection.UseDevelopmentStorage
                     ? AzureConstants.DevelopmentStorageConnectionString
                     : this.blobUploadSettings.StorageAccountFactory.Connection.AccountName,
                 ";", // This separator cannot occur in account name or container name
                 this.blobUploadSettings.LttTraceContainerName),
             ApplicationType = this.configReader.GetApplicationType()
         };
         lock (UploadWorkers)
         {
             // Drop the reference count on the upload worker object
             UploadWorkerInfo workerInfo = UploadWorkers.FirstOrDefault(w => w.Matches(key));
             workerInfo.UploadWorker.FlushData();
         }
     }
     else
     {
         if (null != this.uploadWorker)
         {
             this.uploadWorker.FlushData();
         }
     }
 }
Example #2
0
        public void Dispose()
        {
            if (this.disposed)
            {
                return;
            }

            this.disposed = true;

            if (this.configReader.IsReadingFromApplicationManifest)
            {
                UploadWorkerKey key = new UploadWorkerKey()
                {
                    DestinationPath = this.fileUploadSettings.DestinationPath,
                    ApplicationType = this.configReader.GetApplicationType()
                };
                lock (UploadWorkers)
                {
                    // Drop the reference count on the upload worker object
                    UploadWorkerInfo workerInfo = UploadWorkers.FirstOrDefault(w => w.Matches(key));
                    workerInfo.RefCount--;
                    if (0 == workerInfo.RefCount)
                    {
                        // Tell the worker object to stop
                        this.traceSource.WriteInfo(
                            this.logSourceId,
                            "Stopping upload worker object for application type {0} and destination {1} ...",
                            key.ApplicationType,
                            this.fileUploadSettings.DestinationPath);

                        workerInfo.UploadWorker.Dispose();
                        UploadWorkers.Remove(workerInfo);
                    }
                    else
                    {
                        this.traceSource.WriteInfo(
                            this.logSourceId,
                            "Upload worker object for application type {0} and destination {1} is still in use by other uploaders, so let it continue running",
                            key.ApplicationType,
                            this.fileUploadSettings.DestinationPath);
                    }
                }
            }
            else
            {
                if (null != this.uploadWorker)
                {
                    this.uploadWorker.Dispose();
                }
            }

            GC.SuppressFinalize(this);
        }
Example #3
0
 public void FlushData()
 {
     if (this.configReader.IsReadingFromApplicationManifest)
     {
         UploadWorkerKey key = new UploadWorkerKey()
         {
             DestinationPath = this.fileUploadSettings.DestinationPath,
             ApplicationType = this.configReader.GetApplicationType()
         };
         lock (UploadWorkers)
         {
             // Drop the reference count on the upload worker object
             UploadWorkerInfo workerInfo = UploadWorkers.FirstOrDefault(w => w.Matches(key));
             workerInfo.UploadWorker.FlushData();
         }
     }
     else
     {
         if (null != this.uploadWorker)
         {
             this.uploadWorker.FlushData();
         }
     }
 }
Example #4
0
        public FileShareEtwCsvUploader(ConsumerInitializationParameters initParam)
        {
            // Initialization
            this.initParam    = initParam;
            this.logSourceId  = string.Concat(this.initParam.ApplicationInstanceId, "_", this.initParam.SectionName);
            this.traceSource  = new FabricEvents.ExtensionsEvents(FabricEvents.Tasks.FabricDCA);
            this.configReader = new ConfigReader(initParam.ApplicationInstanceId);

            // Read file-share-specific settings from settings.xml
            this.GetSettings();
            if (false == this.fileUploadSettings.Enabled)
            {
                // Upload to file share is not enabled, so return immediately
                return;
            }

            if (this.configReader.IsReadingFromApplicationManifest)
            {
                // Check if we can use an existing upload worker object
                UploadWorkerKey key = new UploadWorkerKey()
                {
                    DestinationPath = this.fileUploadSettings.DestinationPath,
                    ApplicationType = this.configReader.GetApplicationType(),
                };
                lock (UploadWorkers)
                {
                    UploadWorkerInfo workerInfo = UploadWorkers.FirstOrDefault(w => w.Matches(key));
                    if (null != workerInfo)
                    {
                        // Existing upload worker object is available. Increment its
                        // reference count
                        this.traceSource.WriteInfo(
                            this.logSourceId,
                            "Existing upload worker object for application type {0} and destination {1} is available and will be used.",
                            key.ApplicationType,
                            this.fileUploadSettings.DestinationPath);

                        workerInfo.RefCount++;
                        workerInfo.UploadWorker.UpdateSettings(this.fileUploadSettings);
                        this.uploadWorker = workerInfo.UploadWorker;
                    }
                    else
                    {
                        // Create a new upload worker object
                        this.traceSource.WriteInfo(
                            this.logSourceId,
                            "Creating upload worker object for application type {0} and destination {1} ...",
                            key.ApplicationType,
                            this.fileUploadSettings.DestinationPath);

                        EtwCsvUploadWorker.EtwCsvUploadWorkerParameters param = new EtwCsvUploadWorker.EtwCsvUploadWorkerParameters()
                        {
                            FabricNodeId                     = this.initParam.FabricNodeId,
                            FabricNodeInstanceName           = this.initParam.FabricNodeInstanceName,
                            IsReadingFromApplicationManifest = this.configReader.IsReadingFromApplicationManifest,
                            LogDirectory                     = this.initParam.LogDirectory,
                            WorkDirectory                    = this.initParam.WorkDirectory,
                            UploaderInstanceId               = key.ApplicationType,
                            ParentWorkFolderName             = key.ApplicationType,
                            Settings         = this.fileUploadSettings,
                            DiskSpaceManager = this.initParam.DiskSpaceManager
                        };
                        try
                        {
                            EtwCsvUploadWorker newWorker = new EtwCsvUploadWorker(param, this.traceSource);
                            workerInfo = new UploadWorkerInfo
                            {
                                Key          = key,
                                RefCount     = 1,
                                UploadWorker = newWorker
                            };
                            UploadWorkers.Add(workerInfo);
                            this.uploadWorker = workerInfo.UploadWorker;
                        }
                        catch (InvalidOperationException e)
                        {
                            var message = string.Format(
                                "Failed to create upload worker object for application type {0} and destination {1}.",
                                key.ApplicationType,
                                this.fileUploadSettings.DestinationPath);
                            this.traceSource.WriteError(
                                this.logSourceId,
                                message);
                            throw new InvalidOperationException(message, e);
                        }
                    }
                }
            }
            else
            {
                // Create a new upload worker object
                var param = new EtwCsvUploadWorker.EtwCsvUploadWorkerParameters
                {
                    FabricNodeId                     = this.initParam.FabricNodeId,
                    FabricNodeInstanceName           = this.initParam.FabricNodeInstanceName,
                    IsReadingFromApplicationManifest = this.configReader.IsReadingFromApplicationManifest,
                    LogDirectory                     = this.initParam.LogDirectory,
                    WorkDirectory                    = this.initParam.WorkDirectory,
                    UploaderInstanceId               = this.logSourceId,
                    ParentWorkFolderName             = Utility.ShortWindowsFabricIdForPaths,
                    Settings         = this.fileUploadSettings,
                    DiskSpaceManager = initParam.DiskSpaceManager
                };
                this.uploadWorker = new EtwCsvUploadWorker(param, this.traceSource);
            }
        }
        public AzureBlobCsvUploader(ConsumerInitializationParameters initParam)
        {
            // Initialization
            this.logSourceId  = string.Concat(initParam.ApplicationInstanceId, "_", initParam.SectionName);
            this.traceSource  = new FabricEvents.ExtensionsEvents(FabricEvents.Tasks.FabricDCA);
            this.configReader = new AzureBlobConfigReader(
                new ConfigReader(initParam.ApplicationInstanceId),
                initParam.SectionName,
                this.traceSource,
                this.logSourceId);
            this.diskSpaceManager = initParam.DiskSpaceManager;
            this.disposed         = false;

            // Read blob-specific settings from settings.xml
            this.blobUploadSettings = this.GetSettings();

            if (this.configReader.IsReadingFromApplicationManifest)
            {
                // Check if we can use an existing upload worker object
                UploadWorkerKey key = new UploadWorkerKey()
                {
                    // Destination path is an concatenation of storage account name and container name
                    DestinationPath = string.Concat(
                        this.blobUploadSettings.StorageAccountFactory.Connection.UseDevelopmentStorage ?
                        AzureConstants.DevelopmentStorageConnectionString :
                        this.blobUploadSettings.StorageAccountFactory.Connection.AccountName,
                        ";",                   // This separator cannot occur in account name or container name
                        this.blobUploadSettings.LttTraceContainerName),
                    ApplicationType = this.configReader.GetApplicationType(),
                };
                lock (UploadWorkers)
                {
                    UploadWorkerInfo workerInfo = UploadWorkers.FirstOrDefault(w => w.Matches(key));
                    if (null != workerInfo)
                    {
                        // Existing upload worker object is available. Increment its
                        // reference count
                        this.traceSource.WriteInfo(
                            this.logSourceId,
                            "Existing upload worker object for application type {0}, Azure storage account {1} and container {2} is available and will be used.",
                            key.ApplicationType,
                            this.blobUploadSettings.StorageAccountFactory.Connection.AccountName,
                            this.blobUploadSettings.LttTraceContainerName);

                        (workerInfo.RefCount)++;
                        workerInfo.UploadWorker.UpdateSettings(this.blobUploadSettings);
                        this.uploadWorker = workerInfo.UploadWorker;
                    }
                    else
                    {
                        // Create a new upload worker object
                        this.traceSource.WriteInfo(
                            this.logSourceId,
                            "Creating upload worker object for application type {0}, Azure storage account {1} and container {2} ...",
                            key.ApplicationType,
                            this.blobUploadSettings.StorageAccountFactory.Connection.AccountName,
                            this.blobUploadSettings.LttTraceContainerName);

                        CsvUploadWorker.CsvUploadWorkerParameters param = new CsvUploadWorker.CsvUploadWorkerParameters()
                        {
                            TraceSource                      = this.traceSource,
                            FabricNodeId                     = initParam.FabricNodeId,
                            FabricNodeInstanceName           = initParam.FabricNodeInstanceName,
                            IsReadingFromApplicationManifest = this.configReader.IsReadingFromApplicationManifest,
                            LogDirectory                     = initParam.LogDirectory,
                            WorkDirectory                    = initParam.WorkDirectory,
                            UploaderInstanceId               = key.ApplicationType,
                            ParentWorkFolderName             = key.ApplicationType,
                            Settings = this.blobUploadSettings
                        };

                        CsvUploadWorker newWorker;
                        try
                        {
                            newWorker = new CsvUploadWorker(param, this.diskSpaceManager);
                        }
                        catch (Exception)
                        {
                            this.traceSource.WriteError(
                                this.logSourceId,
                                "Failed to create upload worker object for application type {0}, Azure storage account {1} and container {2}.",
                                key.ApplicationType,
                                this.blobUploadSettings.StorageAccountFactory.Connection.AccountName,
                                this.blobUploadSettings.LttTraceContainerName);
                            throw;
                        }

                        workerInfo = new UploadWorkerInfo()
                        {
                            Key          = key,
                            RefCount     = 1,
                            UploadWorker = newWorker
                        };
                        UploadWorkers.Add(workerInfo);
                        this.uploadWorker = workerInfo.UploadWorker;
                    }
                }
            }
            else
            {
                // Create a new upload worker object
                CsvUploadWorker.CsvUploadWorkerParameters param = new CsvUploadWorker.CsvUploadWorkerParameters()
                {
                    TraceSource                      = this.traceSource,
                    FabricNodeId                     = initParam.FabricNodeId,
                    FabricNodeInstanceName           = initParam.FabricNodeInstanceName,
                    IsReadingFromApplicationManifest = this.configReader.IsReadingFromApplicationManifest,
                    LogDirectory                     = initParam.LogDirectory,
                    WorkDirectory                    = initParam.WorkDirectory,
                    UploaderInstanceId               = this.logSourceId,
                    ParentWorkFolderName             = Utility.ShortWindowsFabricIdForPaths,
                    Settings = this.blobUploadSettings
                };
                this.uploadWorker = new CsvUploadWorker(param, this.diskSpaceManager);
            }
        }
        public void Dispose()
        {
            if (this.disposed)
            {
                return;
            }
            this.disposed = true;

            if (this.configReader.IsReadingFromApplicationManifest)
            {
                UploadWorkerKey key = new UploadWorkerKey()
                {
                    // Destination path is an concatenation of storage account name and container name
                    DestinationPath = string.Concat(
                        this.blobUploadSettings.StorageAccountFactory.Connection.UseDevelopmentStorage ?
                        AzureConstants.DevelopmentStorageConnectionString :
                        this.blobUploadSettings.StorageAccountFactory.Connection.AccountName,
                        ";",                   // This separator cannot occur in account name or container name
                        this.blobUploadSettings.LttTraceContainerName),
                    ApplicationType = this.configReader.GetApplicationType()
                };
                lock (UploadWorkers)
                {
                    // Drop the reference count on the upload worker object
                    UploadWorkerInfo workerInfo = UploadWorkers.FirstOrDefault(w => w.Matches(key));
                    (workerInfo.RefCount)--;
                    if (0 == workerInfo.RefCount)
                    {
                        // Tell the worker object to stop
                        this.traceSource.WriteInfo(
                            this.logSourceId,
                            "Stopping upload worker object for application type {0}, Azure storage account {1} and container {2} ...",
                            key.ApplicationType,
                            this.blobUploadSettings.StorageAccountFactory.Connection.AccountName,
                            this.blobUploadSettings.LttTraceContainerName);

                        workerInfo.UploadWorker.Dispose();
                        UploadWorkers.Remove(workerInfo);
                    }
                    else
                    {
                        this.traceSource.WriteInfo(
                            this.logSourceId,
                            "Upload worker object for application type {0}, Azure storage account {1} and container {2} is still in use by other uploaders, so let it continue running",
                            key.ApplicationType,
                            this.blobUploadSettings.StorageAccountFactory.Connection.AccountName,
                            this.blobUploadSettings.LttTraceContainerName);
                    }
                }
            }
            else
            {
                if (null != this.uploadWorker)
                {
                    this.uploadWorker.Dispose();
                }
            }

            GC.SuppressFinalize(this);
            return;
        }