예제 #1
0
        public AzureBlobFolderUploader(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 AzureBlobConfigReader(
                new ConfigReader(initParam.ApplicationInstanceId),
                this.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;
            }

            var accountName = this.blobUploadSettings.StorageAccountFactory.Connection.UseDevelopmentStorage
                ? AzureConstants.DevelopmentStorageConnectionString
                : this.blobUploadSettings.StorageAccountFactory.Connection.AccountName;

            this.destinationKey = string.Join(
                "_",
                StandardPluginTypes.AzureBlobFolderUploader,
                accountName,
                this.blobUploadSettings.ContainerName);
        }
예제 #2
0
        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);
            }
        }