Esempio n. 1
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);
            }
        }
Esempio n. 2
0
        public AzureBlobEtwCsvUploader(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);

            // Read blob-specific settings from settings.xml
            this.blobUploadSettings = this.GetSettings();
            if (false == this.blobUploadSettings.Enabled)
            {
                // Upload to Azure blob storage 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()
                {
                    // 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.EtwTraceContainerName),
                    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.EtwTraceContainerName);

                        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.EtwTraceContainerName);

                        var param = new EtwCsvUploadWorker.EtwCsvUploadWorkerParameters
                        {
                            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,
                            DiskSpaceManager = initParam.DiskSpaceManager
                        };

                        EtwCsvUploadWorker newWorker;
                        try
                        {
                            newWorker = new EtwCsvUploadWorker(param);
                        }
                        catch (InvalidOperationException)
                        {
                            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.EtwTraceContainerName);
                            throw;
                        }

                        workerInfo = new UploadWorkerInfo
                        {
                            Key          = key,
                            RefCount     = 1,
                            UploadWorker = newWorker
                        };
                        UploadWorkers.Add(workerInfo);
                        this.uploadWorker = workerInfo.UploadWorker;
                    }
                }
            }
            else
            {
                // Create a new upload worker object
                EtwCsvUploadWorker.EtwCsvUploadWorkerParameters param = new EtwCsvUploadWorker.EtwCsvUploadWorkerParameters()
                {
                    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,
                    DiskSpaceManager = initParam.DiskSpaceManager
                };
                this.uploadWorker = new EtwCsvUploadWorker(param);
            }
        }