public HomeController( SuperDumpRepository superDumpRepo, BundleRepository bundleRepo, DumpRepository dumpRepo, IDumpStorage dumpStorage, IOptions <SuperDumpSettings> settings, PathHelper pathHelper, RelationshipRepository relationshipRepo, SimilarityService similarityService, ElasticSearchService elasticService, ILoggerFactory loggerFactory, IAuthorizationHelper authorizationHelper, JiraIssueRepository jiraIssueRepository, SearchService searchService, DownloadService downloadService) { this.superDumpRepo = superDumpRepo; this.bundleRepo = bundleRepo; this.dumpRepo = dumpRepo; this.dumpStorage = dumpStorage; this.settings = settings.Value; this.pathHelper = pathHelper; this.relationshipRepo = relationshipRepo; this.similarityService = similarityService; logger = loggerFactory.CreateLogger <HomeController>(); this.authorizationHelper = authorizationHelper; this.jiraIssueRepository = jiraIssueRepository; this.searchService = searchService; this.downloadService = downloadService; }
private void InitFakeJiraRepository(out FakeJiraApiService fakeJiraApiService, out FakeJiraIssueStorage fakeJiraIssueStorage, out JiraIssueRepository jiraIssueRepository, out BundleRepository bundleRepository) { var settings = Options.Create(new SuperDumpSettings { UseJiraIntegration = true, JiraIntegrationSettings = new JiraIntegrationSettings { } }); var pathHelper = new PathHelper("", "", ""); var dumpStorage = new FakeDumpStorage(CreateFakeDumps()); var bundleStorage = dumpStorage; var dumpRepo = new DumpRepository(dumpStorage, pathHelper, settings); bundleRepository = new BundleRepository(bundleStorage, dumpRepo); fakeJiraApiService = new FakeJiraApiService(); fakeJiraIssueStorage = new FakeJiraIssueStorage(); var identicalDumpStorage = new FakeIdenticalDumpStorage(); var identicalDumpRepository = new IdenticalDumpRepository(identicalDumpStorage, bundleRepository); var loggerFactory = new LoggerFactory(); jiraIssueRepository = new JiraIssueRepository(settings, fakeJiraApiService, bundleRepository, fakeJiraIssueStorage, identicalDumpRepository, loggerFactory); }
public AdminController(SimilarityService similarityService, DumpRepository dumpRepository, BundleRepository bundleRepository, ILoggerFactory loggerFactory, IdenticalDumpRepository identicalDumpRepository, JiraIssueRepository jiraIssueRepository, IOptions <SuperDumpSettings> settings, ElasticSearchService elasticService) { this.similarityService = similarityService; this.bundleRepository = bundleRepository; this.identicalDumpRepository = identicalDumpRepository; this.jiraIssueRepository = jiraIssueRepository; this.elasticService = elasticService; logger = loggerFactory.CreateLogger <AdminController>(); this.settings = settings.Value; }
public SearchServiceBenchmarks() { /// fake a repository of N very similar dumps. Then let similarity calculation run /// simulate filesystem access with Thread.Sleep in FakeDumpStorage N = 100000; var settings = Options.Create(new SuperDumpSettings { WarnBeforeDeletionInDays = 2, UseJiraIntegration = false, JiraIntegrationSettings = new JiraIntegrationSettings() }); var settingsWithJira = Options.Create(new SuperDumpSettings { WarnBeforeDeletionInDays = 2, UseJiraIntegration = true, JiraIntegrationSettings = new JiraIntegrationSettings() }); this.pathHelper = new PathHelper("", "", ""); this.loggerFactory = new LoggerFactory(); this.dumpStorage = new FakeDumpStorage(CreateFakeDumps(N)); this.dumpRepo = new DumpRepository(dumpStorage, pathHelper, settings); this.bundleRepo = new BundleRepository(dumpStorage, dumpRepo); this.identicalDumpStorage = new FakeIdenticalDumpStorage(); this.identicalDumpRepository = new IdenticalDumpRepository(identicalDumpStorage, bundleRepo); this.jiraIssueStorage = new FakeJiraIssueStorage(); this.jiraApiService = new FakeJiraApiService(); this.jiraIssueRepository = new JiraIssueRepository(settings, jiraApiService, bundleRepo, jiraIssueStorage, identicalDumpRepository, loggerFactory); // The Similarity Service and Elastic Search Service is not initialized since it is not required for testing the SimpleSearch this.searchService = new SearchService(bundleRepo, dumpRepo, null, null, settings, jiraIssueRepository); this.searchServiceWithJira = new SearchService(bundleRepo, dumpRepo, null, null, settingsWithJira, jiraIssueRepository); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IOptions <SuperDumpSettings> settings, IServiceProvider serviceProvider, SlackNotificationService sns, IAuthorizationHelper authorizationHelper, ILoggerFactory loggerFactory) { Task.Run(async() => await app.ApplicationServices.GetService <BundleRepository>().Populate()); Task.Run(async() => await app.ApplicationServices.GetService <RelationshipRepository>().Populate()); Task.Run(async() => await app.ApplicationServices.GetService <IdenticalDumpRepository>().Populate()); if (settings.Value.UseJiraIntegration) { Task.Run(async() => await app.ApplicationServices.GetService <JiraIssueRepository>().Populate()); } if (settings.Value.UseHttpsRedirection) { app.UseHttpsRedirection(); } app.UseStaticFiles(); app.UseRouting(); if (settings.Value.UseLdapAuthentication) { app.UseAuthentication(); app.UseAuthorization(); app.UseSwaggerAuthorizationMiddleware(authorizationHelper); } else { app.UseAuthorization(); app.MapWhen(context => context.Request.Path.StartsWithSegments("/Login") || context.Request.Path.StartsWithSegments("/api/Token"), appBuilder => appBuilder.Run(async context => { context.Response.StatusCode = 404; await context.Response.WriteAsync(""); })); } if (settings.Value.UseAllRequestLogging) { ILogger logger = loggerFactory.CreateLogger("SuperDumpServiceRequests"); app.Use(async(context, next) => { logger.LogRequest(context); await next.Invoke(); }); } app.UseHangfireDashboard("/hangfire", new DashboardOptions { Authorization = new[] { new CustomAuthorizeFilter(authorizationHelper) } }); app.UseHangfireServer(new BackgroundJobServerOptions { Queues = new[] { "download" }, WorkerCount = settings.Value.MaxConcurrentBundleExtraction }); app.UseHangfireServer(new BackgroundJobServerOptions { Queues = new[] { "analysis" }, WorkerCount = settings.Value.MaxConcurrentAnalysis }); app.UseHangfireServer(new BackgroundJobServerOptions { Queues = new[] { "elasticsearch" }, WorkerCount = 1 }); app.UseHangfireServer(new BackgroundJobServerOptions { Queues = new[] { "retention" }, WorkerCount = 1 }); app.UseHangfireServer(new BackgroundJobServerOptions { Queues = new[] { "similarityanalysis" }, WorkerCount = 8 }); if (settings.Value.UseJiraIntegration) { app.UseHangfireServer(new BackgroundJobServerOptions { Queues = new[] { "jirastatus" }, WorkerCount = 2 }); JiraIssueRepository jiraIssueRepository = app.ApplicationServices.GetService <JiraIssueRepository>(); jiraIssueRepository.StartRefreshHangfireJob(); jiraIssueRepository.StartBundleSearchHangfireJob(); } app.ApplicationServices.GetService <DumpRetentionService>().StartService(); if (settings.Value.UseAmazonSqs) { app.UseHangfireServer(new BackgroundJobServerOptions { Queues = new[] { "amazon-sqs-poll" }, WorkerCount = 2 }); AmazonSqsPollingService amazonSqsService = app.ApplicationServices.GetService <AmazonSqsPollingService>(); amazonSqsService.StartHangfireJob(); } GlobalJobFilters.Filters.Add(new AutomaticRetryAttribute { Attempts = 0 }); app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); }); app.UseHealthChecks("/healthcheck"); LogProvider.SetCurrentLogProvider(new ColouredConsoleLogProvider()); if (env.EnvironmentName == "Development") { app.UseDeveloperExceptionPage(); BrowserLinkExtensions.UseBrowserLink(app); // using the extension method directly somehow did not work in .NET Core 2.0 (ambiguous extension method) } else { app.UseExceptionHandler("/Home/Error"); } app.UseWebSockets(); app.MapWebSocketManager("/cmd", serviceProvider.GetService <WebTermHandler>()); //app.UseMvcWithDefaultRoute(); //app.UseMvc(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}"); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IOptions <SuperDumpSettings> settings, IServiceProvider serviceProvider, SlackNotificationService sns, IAuthorizationHelper authorizationHelper, ILoggerFactory loggerFactory, IOneAgentSdk oneAgentSdk) { Task.Run(async() => await app.ApplicationServices.GetService <BundleRepository>().Populate()); Task.Run(async() => await app.ApplicationServices.GetService <RelationshipRepository>().Populate()); Task.Run(async() => await app.ApplicationServices.GetService <IdenticalDumpRepository>().Populate()); if (settings.Value.UseJiraIntegration) { Task.Run(async() => await app.ApplicationServices.GetService <JiraIssueRepository>().Populate()); } // configure Logger loggerFactory.AddConsole(config.GetSection("Logging")); var fileLogConfig = config.GetSection("FileLogging"); var logPath = Path.GetDirectoryName(fileLogConfig.GetValue <string>("PathFormat")); Directory.CreateDirectory(logPath); loggerFactory.AddFile(config.GetSection("FileLogging")); if (settings.Value.UseAllRequestLogging) { loggerFactory.AddFile(config.GetSection("RequestFileLogging")); } loggerFactory.AddDebug(); oneAgentSdk.SetLoggingCallback(new DynatraceSdkLogger(loggerFactory.CreateLogger <DynatraceSdkLogger>())); if (settings.Value.UseHttpsRedirection) { app.UseHttpsRedirection(); } if (settings.Value.UseLdapAuthentication) { app.UseAuthentication(); app.UseSwaggerAuthorizationMiddleware(authorizationHelper); } else { app.MapWhen(context => context.Request.Path.StartsWithSegments("/Login") || context.Request.Path.StartsWithSegments("/api/Token"), appBuilder => appBuilder.Run(async context => { context.Response.StatusCode = 404; await context.Response.WriteAsync(""); })); } if (settings.Value.UseAllRequestLogging) { ILogger logger = loggerFactory.CreateLogger("SuperDumpServiceRequests"); app.Use(async(context, next) => { logger.LogRequest(context); await next.Invoke(); }); } app.UseHangfireDashboard("/hangfire", new DashboardOptions { Authorization = new[] { new CustomAuthorizeFilter(authorizationHelper) } }); app.UseHangfireServer(new BackgroundJobServerOptions { Queues = new[] { "download" }, WorkerCount = settings.Value.MaxConcurrentBundleExtraction }); app.UseHangfireServer(new BackgroundJobServerOptions { Queues = new[] { "analysis" }, WorkerCount = settings.Value.MaxConcurrentAnalysis }); app.UseHangfireServer(new BackgroundJobServerOptions { Queues = new[] { "elasticsearch" }, WorkerCount = 1 }); app.UseHangfireServer(new BackgroundJobServerOptions { Queues = new[] { "retention" }, WorkerCount = 1 }); app.UseHangfireServer(new BackgroundJobServerOptions { Queues = new[] { "similarityanalysis" }, WorkerCount = 8 }); if (settings.Value.UseJiraIntegration) { app.UseHangfireServer(new BackgroundJobServerOptions { Queues = new[] { "jirastatus" }, WorkerCount = 2 }); JiraIssueRepository jiraIssueRepository = app.ApplicationServices.GetService <JiraIssueRepository>(); jiraIssueRepository.StartRefreshHangfireJob(); jiraIssueRepository.StartBundleSearchHangfireJob(); } app.ApplicationServices.GetService <DumpRetentionService>().StartService(); GlobalJobFilters.Filters.Add(new AutomaticRetryAttribute { Attempts = 0 }); app.UseSwagger(); app.UseSwaggerUi(); app.UseHealthChecks("/healthcheck"); LogProvider.SetCurrentLogProvider(new ColouredConsoleLogProvider()); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); BrowserLinkExtensions.UseBrowserLink(app); // using the extension method directly somehow did not work in .NET Core 2.0 (ambiguous extension method) } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseWebSockets(); app.MapWebSocketManager("/cmd", serviceProvider.GetService <WebTermHandler>()); app.UseMvcWithDefaultRoute(); }
public async Task TestJiraIssueRepository() { // setup dependencies var settings = Options.Create(new SuperDumpSettings { UseJiraIntegration = true, JiraIntegrationSettings = new JiraIntegrationSettings { } }); var pathHelper = new PathHelper("", "", ""); var dumpStorage = new FakeDumpStorage(CreateFakeDumps()); var bundleStorage = dumpStorage; var dumpRepo = new DumpRepository(dumpStorage, pathHelper); var bundleRepo = new BundleRepository(bundleStorage, dumpRepo); var jiraApiService = new FakeJiraApiService(); var jiraIssueStorage = new FakeJiraIssueStorage(); var identicalDumpStorage = new FakeIdenticalDumpStorage(); var identicalDumpRepository = new IdenticalDumpRepository(identicalDumpStorage, bundleRepo); var loggerFactory = new LoggerFactory(); var jiraIssueRepository = new JiraIssueRepository(settings, jiraApiService, bundleRepo, jiraIssueStorage, identicalDumpRepository, loggerFactory); // population await jiraIssueStorage.Store("bundle1", new List <JiraIssueModel> { new JiraIssueModel("JRA-1111") }); await jiraIssueStorage.Store("bundle2", new List <JiraIssueModel> { new JiraIssueModel("JRA-2222"), new JiraIssueModel("JRA-3333") }); await jiraIssueStorage.Store("bundle9", new List <JiraIssueModel> { new JiraIssueModel("JRA-9999") }); await bundleRepo.Populate(); await jiraIssueRepository.Populate(); // actual test Assert.Collection(jiraIssueRepository.GetIssues("bundle1"), item => Assert.Equal("JRA-1111", item.Key)); Assert.Collection(jiraIssueRepository.GetIssues("bundle2"), item => Assert.Equal("JRA-2222", item.Key), item => Assert.Equal("JRA-3333", item.Key)); Assert.Collection(jiraIssueRepository.GetIssues("bundle9"), item => Assert.Equal("JRA-9999", item.Key)); Assert.Empty(jiraIssueRepository.GetIssues("bundle3")); // fake, that in jira some bundles have been referenced in new issues jiraApiService.SetFakeJiraIssues("bundle1", new JiraIssueModel[] { new JiraIssueModel("JRA-1111") }); // same jiraApiService.SetFakeJiraIssues("bundle2", new JiraIssueModel[] { new JiraIssueModel("JRA-2222"), new JiraIssueModel("JRA-4444") }); // one added, one removed jiraApiService.SetFakeJiraIssues("bundle3", new JiraIssueModel[] { new JiraIssueModel("JRA-1111"), new JiraIssueModel("JRA-5555") }); // new jiraApiService.SetFakeJiraIssues("bundle9", null); // removed jira issues await jiraIssueRepository.SearchBundleIssuesAsync(bundleRepo.GetAll(), true); Assert.Collection(jiraIssueRepository.GetIssues("bundle1"), item => Assert.Equal("JRA-1111", item.Key)); Assert.Collection(jiraIssueRepository.GetIssues("bundle2"), item => Assert.Equal("JRA-2222", item.Key), item => Assert.Equal("JRA-4444", item.Key)); Assert.Collection(jiraIssueRepository.GetIssues("bundle3"), item => Assert.Equal("JRA-1111", item.Key), item => Assert.Equal("JRA-5555", item.Key)); Assert.Empty(jiraIssueRepository.GetIssues("bundle9")); var res = await jiraIssueRepository.GetAllIssuesByBundleIdsWithoutWait(new string[] { "bundle1", "bundle2", "bundle7", "bundle666", "bundle9" }); Assert.Equal(2, res.Count()); Assert.Collection(res["bundle1"], item => Assert.Equal("JRA-1111", item.Key)); Assert.Collection(res["bundle2"], item => Assert.Equal("JRA-2222", item.Key), item => Assert.Equal("JRA-4444", item.Key)); Assert.Empty(jiraIssueRepository.GetIssues("bundle7")); Assert.Empty(jiraIssueRepository.GetIssues("bundle666")); Assert.Empty(jiraIssueRepository.GetIssues("bundle9")); }