示例#1
0
        private static async Task InitAndRunAsync()
        {
            var instrumentationKey = await AzureStorage.GetAppInsightsInstrumentationKeyAsync(Environment.GetEnvironmentVariable("ApplicationInsightsAccountName"));

            var defaultStorageAccountName = Environment.GetEnvironmentVariable("DefaultStorageAccountName");
            var cromwellUrl = ConfigurationManager.AppSettings.Get("CromwellUrl");

            var serviceCollection = new ServiceCollection()
                                    .AddLogging(loggingBuilder =>
            {
                if (!string.IsNullOrWhiteSpace(instrumentationKey))
                {
                    loggingBuilder.AddApplicationInsights(instrumentationKey);
                }
                else
                {
                    Console.WriteLine("Warning: AppInsights key was null, and so AppInsights logging will not be enabled.  Check if this VM has Contributor access to the Application Insights instance.");
                }

                loggingBuilder.AddConsole();
            });

            var serviceProvider = serviceCollection.BuildServiceProvider();

            var environment = new CromwellOnAzureEnvironment(
                serviceProvider.GetRequiredService <ILoggerFactory>(),
                new AzureStorage(serviceProvider.GetRequiredService <ILoggerFactory>().CreateLogger <AzureStorage>(), defaultStorageAccountName),
                new CromwellApiClient.CromwellApiClient(cromwellUrl));

            serviceCollection.AddSingleton(s => new TriggerEngine(s.GetRequiredService <ILoggerFactory>(), environment));
            serviceProvider = serviceCollection.BuildServiceProvider();
            var engine = serviceProvider.GetService <TriggerEngine>();
            await engine.RunAsync();
        }
示例#2
0
        private static async Task InitAndRunAsync()
        {
            var instrumentationKey = await AzureStorage.GetAppInsightsInstrumentationKeyAsync(Environment.GetEnvironmentVariable("ApplicationInsightsAccountName"));

            var defaultStorageAccountName = Environment.GetEnvironmentVariable("DefaultStorageAccountName");
            var cosmosDbAccountName       = Environment.GetEnvironmentVariable("CosmosDbAccountName");
            var cromwellUrl = ConfigurationManager.AppSettings.Get("CromwellUrl");

            var serviceCollection = new ServiceCollection()
                                    .AddLogging(loggingBuilder =>
            {
                if (!string.IsNullOrWhiteSpace(instrumentationKey))
                {
                    loggingBuilder.AddApplicationInsights(instrumentationKey,
                                                          options =>
                    {
                        options.TrackExceptionsAsExceptionTelemetry = false;
                    });
                }
                else
                {
                    Console.WriteLine("Warning: AppInsights key was null, and so AppInsights logging will not be enabled.  Check if this VM has Contributor access to the Application Insights instance.");
                }

                loggingBuilder.AddConsole();
            });

            var serviceProvider = serviceCollection.BuildServiceProvider();

            (var storageAccounts, var storageAccount) = await AzureStorage.GetStorageAccountsUsingMsiAsync(defaultStorageAccountName);

            (var cosmosDbEndpoint, var cosmosDbKey) = await GetCosmosDbEndpointAndKeyAsync(cosmosDbAccountName);

            var environment = new CromwellOnAzureEnvironment(
                serviceProvider.GetRequiredService <ILoggerFactory>(),
                storageAccount,
                new CromwellApiClient.CromwellApiClient(cromwellUrl),
                new CosmosDbRepository <TesTask>(
                    cosmosDbEndpoint,
                    cosmosDbKey,
                    Constants.CosmosDbDatabaseId,
                    Constants.CosmosDbContainerId,
                    Constants.CosmosDbPartitionId),
                storageAccounts);

            serviceCollection.AddSingleton(s => new TriggerEngine(s.GetRequiredService <ILoggerFactory>(), environment, TimeSpan.FromSeconds(20), TimeSpan.FromSeconds(30)));
            serviceProvider = serviceCollection.BuildServiceProvider();
            var engine = serviceProvider.GetService <TriggerEngine>();
            await engine.RunAsync();
        }
示例#3
0
        public static async Task <(IEnumerable <IAzureStorage>, IAzureStorage)> GetStorageAccountsUsingMsiAsync(string accountName)
        {
            IAzureStorage defaultAzureStorage = default;

            (var accounts, var defaultAccount) = await GetCloudStorageAccountsUsingMsiAsync(accountName);

            return(accounts.Select(GetAzureStorage).ToList(), defaultAzureStorage ?? throw new Exception($"Azure Storage account with name: {accountName} not found in list of {accounts.Count} storage accounts."));

            IAzureStorage GetAzureStorage(CloudStorageAccount cloudStorage)
            {
                var azureStorage = new AzureStorage(cloudStorage, new HttpClient());

                if (cloudStorage.Equals(defaultAccount))
                {
                    defaultAzureStorage = azureStorage;
                }
                return(azureStorage);
            }
        }