Пример #1
0
        private (IAppCache cache, AzureProxy azureProxy, IAzureProxy cachingAzureProxy, IStorageAccessProvider storageAccessProvider, IRepository <TesTask> repository) ConfigureServices()
        {
            var cache = new CachingService();

            var                    azureProxy            = new AzureProxy(Configuration["BatchAccountName"], azureOfferDurableId, loggerFactory.CreateLogger <AzureProxy>());
            IAzureProxy            cachingAzureProxy     = new CachingWithRetriesAzureProxy(azureProxy, cache);
            IStorageAccessProvider storageAccessProvider = new StorageAccessProvider(loggerFactory.CreateLogger <StorageAccessProvider>(), Configuration, cachingAzureProxy);

            var configurationUtils = new ConfigurationUtils(Configuration, cachingAzureProxy, storageAccessProvider, loggerFactory.CreateLogger <ConfigurationUtils>());

            configurationUtils.ProcessAllowedVmSizesConfigurationFileAsync().Wait();

            (var cosmosDbEndpoint, var cosmosDbKey) = azureProxy.GetCosmosDbEndpointAndKeyAsync(Configuration["CosmosDbAccountName"]).Result;
            var cosmosDbRepository = new CosmosDbRepository <TesTask>(cosmosDbEndpoint, cosmosDbKey, Constants.CosmosDbDatabaseId, Constants.CosmosDbContainerId, Constants.CosmosDbPartitionId);

            return(cache, azureProxy, cachingAzureProxy, storageAccessProvider, cosmosDbRepository);
        }
Пример #2
0
        /// <summary>
        /// This method gets called by the runtime. Use this method to add services to the container.
        /// </summary>
        /// <param name="services"></param>
        public void ConfigureServices(IServiceCollection services)
        {
            var cache = new CachingService();

            services.AddSingleton <IAppCache>(cache);

            var         azureProxy        = new AzureProxy(Configuration["BatchAccountName"], azureOfferDurableId, loggerFactory.CreateLogger <AzureProxy>());
            IAzureProxy cachingAzureProxy = new CachingWithRetriesAzureProxy(azureProxy, cache);

            services.AddSingleton(cachingAzureProxy);
            services.AddSingleton(azureProxy);

            services
            .AddControllers()
            .AddNewtonsoftJson(opts =>
            {
                opts.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
                opts.SerializerSettings.Converters.Add(new StringEnumConverter(new CamelCaseNamingStrategy()));
            });

            (var cosmosDbEndpoint, var cosmosDbKey) = azureProxy.GetCosmosDbEndpointAndKeyAsync(Configuration["CosmosDbAccountName"]).Result;

            var cosmosDbRepository = new CosmosDbRepository <TesTask>(cosmosDbEndpoint, cosmosDbKey, CosmosDbDatabaseId, CosmosDbCollectionId, CosmosDbPartitionId);
            var repository         = new CachingWithRetriesRepository <TesTask>(cosmosDbRepository);

            services.AddSingleton <IRepository <TesTask> >(repository);
            services.AddSingleton <IBatchScheduler>(new BatchScheduler(loggerFactory.CreateLogger <BatchScheduler>(), Configuration, cachingAzureProxy));

            services
            .AddSwaggerGen(c =>
            {
                c.SwaggerDoc("0.3.0", new OpenApiInfo
                {
                    Version     = "0.3.0",
                    Title       = "Task Execution Service",
                    Description = "Task Execution Service (ASP.NET Core 3.1)",
                    Contact     = new OpenApiContact()
                    {
                        Name = "Microsoft Genomics",
                        Url  = new Uri("https://github.com/microsoft/CromwellOnAzure")
                    },
                });
                c.CustomSchemaIds(type => type.FullName);
                c.IncludeXmlComments($"{AppContext.BaseDirectory}{Path.DirectorySeparatorChar}{Assembly.GetEntryAssembly().GetName().Name}.xml");
                c.OperationFilter <GeneratePathParamsValidationFilter>();
            });

            services.AddHostedService <Scheduler>();
            services.AddHostedService <DeleteCompletedBatchJobsHostedService>();
            services.AddHostedService <DeleteOrphanedAutoPoolsHostedService>();
            services.AddHostedService <RefreshVMSizesAndPricesHostedService>();

            // Configure AppInsights Azure Service when in PRODUCTION environment
            if (hostingEnvironment.IsProduction())
            {
                var applicationInsightsAccountName = Configuration["ApplicationInsightsAccountName"];
                var instrumentationKey             = AzureProxy.GetAppInsightsInstrumentationKeyAsync(applicationInsightsAccountName).Result;

                if (instrumentationKey != null)
                {
                    services.AddApplicationInsightsTelemetry(instrumentationKey);
                }
            }
            else
            {
                services.AddApplicationInsightsTelemetry();
            }
        }