private void ConfigureServices(IServiceCollection services, IAppCache cache, AzureProxy azureProxy, IAzureProxy cachingAzureProxy, IStorageAccessProvider storageAccessProvider, IRepository <TesTask> repository) => services.AddSingleton(cache) .AddSingleton(cachingAzureProxy) .AddSingleton(azureProxy) .AddControllers() .AddNewtonsoftJson(opts => { opts.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); opts.SerializerSettings.Converters.Add(new StringEnumConverter(new CamelCaseNamingStrategy())); }).Services .AddSingleton <IRepository <TesTask> >(new CachingWithRetriesRepository <TesTask>(repository)) .AddSingleton <IBatchScheduler>(new BatchScheduler(loggerFactory.CreateLogger <BatchScheduler>(), Configuration, cachingAzureProxy, storageAccessProvider)) .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>(); }) .AddHostedService <Scheduler>() .AddHostedService <DeleteCompletedBatchJobsHostedService>() .AddHostedService <DeleteOrphanedBatchJobsHostedService>() .AddHostedService <DeleteOrphanedAutoPoolsHostedService>() .AddHostedService <RefreshVMSizesAndPricesHostedService>() // Configure AppInsights Azure Service when in PRODUCTION environment .IfThenElse(hostingEnvironment.IsProduction(), s => { var applicationInsightsAccountName = Configuration["ApplicationInsightsAccountName"]; var instrumentationKey = AzureProxy.GetAppInsightsInstrumentationKeyAsync(applicationInsightsAccountName).Result; if (instrumentationKey is not null) { return(s.AddApplicationInsightsTelemetry(instrumentationKey)); } return(s); }, s => s.AddApplicationInsightsTelemetry());
/// <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) { IAzureProxy azureProxy = new AzureProxy(Configuration["BatchAccountName"], azureOfferDurableId, loggerFactory.CreateLogger <AzureProxy>()); services.AddSingleton <IAzureProxy>(azureProxy); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Latest); (var cosmosDbEndpoint, var cosmosDbKey) = azureProxy.GetCosmosDbEndpointAndKey(Configuration["CosmosDbAccountName"]).Result; services.AddSingleton <IRepository <TesTask> >(new CosmosDbRepository <TesTask>(cosmosDbEndpoint, cosmosDbKey, CosmosDbDatabaseId, CosmosDbCollectionId, CosmosDbPartitionId)); services.AddSingleton <IBatchScheduler>(new BatchScheduler(loggerFactory.CreateLogger <BatchScheduler>(), Configuration, azureProxy)); services .AddSwaggerGen(c => { c.SwaggerDoc("0.3.0", new Info { Version = "0.3.0", Title = "Task Execution Service", Description = "Task Execution Service (ASP.NET Core 2.0)", Contact = new Contact() { Name = "OpenAPI-Generator Contributors", Url = "https://github.com/openapitools/openapi-generator", Email = "" }, TermsOfService = "" }); c.CustomSchemaIds(type => type.FriendlyId(true)); c.DescribeAllEnumsAsStrings(); c.IncludeXmlComments($"{AppContext.BaseDirectory}{Path.DirectorySeparatorChar}{Assembly.GetEntryAssembly().GetName().Name}.xml"); c.OperationFilter <GeneratePathParamsValidationFilter>(); }); services.AddHostedService <Scheduler>(); services.AddHostedService <DeleteCompletedBatchJobsHostedService>(); services.AddHostedService <DeleteOrphanedAutoPoolsHostedService>(); // 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(); } CacheVmSizesAndPrices(azureProxy); }
/// <summary> /// Create the web host builder. /// </summary> /// <param name="args"></param> /// <returns><see cref="IWebHostBuilder"/></returns> public static IWebHostBuilder CreateWebHostBuilder(string[] args) { return(WebHost.CreateDefaultBuilder(args) .UseApplicationInsights() .UseStartup <Startup>() .UseUrls("http://0.0.0.0:80/") .ConfigureAppConfiguration((context, config) => { var builtConfig = config.Build(); config.AddEnvironmentVariables(); // For Docker-Compose }) .ConfigureLogging((context, logging) => { try { if (context.HostingEnvironment.IsProduction()) { var applicationInsightsAccountName = context.Configuration["ApplicationInsightsAccountName"]; Console.WriteLine($"ApplicationInsightsAccountName: {applicationInsightsAccountName}"); var instrumentationKey = AzureProxy.GetAppInsightsInstrumentationKeyAsync(applicationInsightsAccountName).Result; if (instrumentationKey != null) { logging.AddApplicationInsights(instrumentationKey); } } else { logging.AddApplicationInsights(); logging.AddDebug(); logging.AddConsole(); } // Optional: Apply filters to configure LogLevel Trace or above is sent to // ApplicationInsights for all categories. logging.AddFilter <ApplicationInsightsLoggerProvider>("System", LogLevel.Warning); // Additional filtering For category starting in "Microsoft", // only Warning or above will be sent to Application Insights. logging.AddFilter <ApplicationInsightsLoggerProvider>("Microsoft", LogLevel.Warning); // The following configures LogLevel Information or above to be sent to // Application Insights for categories starting with "TesApi". logging.AddFilter <ApplicationInsightsLoggerProvider>("TesApi", LogLevel.Information); } catch (Exception exc) { Console.WriteLine($"Exception while configuring logging: {exc.ToString()}"); throw; } })); }
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); }
/// <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(); } }
/// <summary> /// Default constructor /// </summary> /// <param name="azureProxy"><see cref="AzureProxy"/></param> /// <param name="cache">Lazy cache using <see cref="IAppCache"/></param> /// <param name="logger"><see cref="ILogger"/> instance</param> public RefreshVMSizesAndPricesHostedService(AzureProxy azureProxy, IAppCache cache, ILogger <RefreshVMSizesAndPricesHostedService> logger) { this.azureProxy = azureProxy; this.cache = cache; this.logger = logger; }