Exemple #1
0
        protected override void Load(ContainerBuilder builder)
        {
            _ = builder.RegisterInstance(new TenantIdentifier(_tenant.Id, _tenant.Name)).AsSelf().SingleInstance();

            _ = builder.RegisterType <HostingBackgroundJobManager>()
                .As <IBackgroundJobManager>()
                .SingleInstance();

            var tenantConnectionString = _applicationConfiguration.IsTempTenantDefined()
                ? _applicationConfiguration.GetTempTenantConnectionString()
                : _tenant.TenantDb?.ConnectionString;

            switch (_applicationConfiguration.GetDbProvider())
            {
            case DbProviderType.RavenDb:
                _ = builder.RegisterModule(new RavenDbTenantModule(tenantConnectionString));
                _ = builder.RegisterType <RavenSessionManagementAttribute>()
                    .AsWebApiActionFilterFor <ApiController>()
                    .InstancePerRequest();
                break;

            case DbProviderType.SqlServer:
                var loggingEnabled             = _testEnvironment.HasOptions(TestEnvironmentOptions.PerformanceLog);
                var longRunningCommandsTimeout = _applicationConfiguration.GetValue <int?>("SqlServerDb:LongRunningCommandsTimeout");
                _ = builder.RegisterModule(new SqlServerTenantModule(tenantConnectionString,
                                                                     new SqlServerDbContextRegistrationFeatures {
                    Logging = loggingEnabled
                },
                                                                     new SqlServerDbContextRegistrationFeatures {
                    Logging = loggingEnabled, CommandTimeout = longRunningCommandsTimeout ?? 600
                }));
                _ = builder.RegisterModule(new SqlServerFeatureManagementModule(_featureManager));
                _ = builder.RegisterModule(new SynchronizationServiceSqlServerServiceModule(tenantConnectionString));
                _ = builder.RegisterModule(new IntelligenceAutofacModule(tenantConnectionString));
                break;
            }

            // Register System Tests Manager
            _ = builder.RegisterType <SystemTestsManager>().As <ISystemTestsManager>();

            // Register System Tasks Manager
            _ = builder.RegisterType <SystemTasksManager>().As <ISystemTasksManager>();

            if (!_testEnvironment.HasOptions(TestEnvironmentOptions.AutoBookStub))
            {
                _ = builder.Register(x =>
                {
                    var autoBookSettingsRepository = x.Resolve <IAutoBookSettingsRepository>();
                    var autoBookSettings           = autoBookSettingsRepository.Get();

                    // TODO: Must be seeded once on application start
                    if (autoBookSettings == null)       // AutoBook settings not found, add default settings
                    {
                        autoBookSettings = AutoBookHelper.GetDefaultAutoBookSettings();
                        autoBookSettingsRepository.AddOrUpdate(autoBookSettings);
                        autoBookSettingsRepository.SaveChanges();
                    }

                    return(autoBookSettings);
                }).InstancePerLifetimeScope();

                _ = builder.Register(x =>
                {
                    var autoBookSettings     = x.Resolve <AutoBookSettings>();
                    var auditEventRepository = x.Resolve <IAuditEventRepository>();
                    return(new AWSAutoBooksAPI(autoBookSettings.ProvisioningAPIURL, _autobookProviderApiAccessToken, auditEventRepository));
                })
                    .As <IAutoBooksAPI <AWSPAAutoBook, AWSPACreateAutoBook> >()
                    .InstancePerDependency();

                // Register AutoBooks Management for collectively managing AutoBooks
                _ = builder.Register(x =>
                {
                    var autoBookRepository       = x.Resolve <IAutoBookRepository>();
                    var autoBookTypeRepository   = x.Resolve <IAutoBookInstanceConfigurationRepository>();
                    var auditEventRepository     = x.Resolve <IAuditEventRepository>();
                    var awsInstanceConfiguration = x.Resolve <IAWSInstanceConfigurationRepository>();
                    var autoBookSettings         = x.Resolve <AutoBookSettings>();
                    var repositoryFactory        = x.Resolve <IRepositoryFactory>();
                    var autoBooksApi             = x.Resolve <IAutoBooksAPI <AWSPAAutoBook, AWSPACreateAutoBook> >();

                    return(new AWSAutoBooks(repositoryFactory, autoBookRepository, autoBookTypeRepository,
                                            awsInstanceConfiguration,
                                            auditEventRepository, autoBookSettings, autoBooksApi, _autobookProviderApiAccessToken));
                })
                    .As <IAutoBooks>()
                    .InstancePerDependency();
            }
            else
            {
                _ = builder.Register(x =>
                {
                    var autoBookSettingsRepository = x.Resolve <IAutoBookSettingsRepository>();
                    var autoBookSettings           = autoBookSettingsRepository.Get();

                    // TODO: Must be seeded once on application start
                    if (autoBookSettings == null)
                    {
                        autoBookSettings = AutoBookHelper.GetDefaultAutoBookSettings();
                        autoBookSettingsRepository.AddOrUpdate(autoBookSettings);
                        autoBookSettingsRepository.SaveChanges();
                    }

                    var returnAutoBookSettings                = AutoBookHelper.GetDefaultAutoBookSettings();
                    returnAutoBookSettings.MaxInstances       = System.Int32.MaxValue;
                    returnAutoBookSettings.CreationTimeout    = Duration.Zero;
                    returnAutoBookSettings.ApplicationVersion = "v1-test-env";

                    return(returnAutoBookSettings);
                }).InstancePerLifetimeScope();

                _ = builder.RegisterType <AWSAutoBooksAPIStub>()
                    .As <IAutoBooksAPI <AWSPAAutoBook, AWSPACreateAutoBook> >()
                    .As <IAutoBooksTestHandler>()
                    .InstancePerDependency();

                _ = builder.RegisterType <TestEnvironmentAWSAutoBooks>().As <IAutoBooks>().InstancePerDependency();
            }

            _ = builder.RegisterType <TestEnvironmentDataService>()
                .As <ITestEnvironmentDataService>()
                .InstancePerLifetimeScope();

            _ = builder.RegisterType <HubNotification <RunNotificationHub, RunNotification> >()
                .As <IHubNotification <RunNotification> >()
                .InstancePerLifetimeScope();

            _ = builder.RegisterType <HubNotification <LandmarkRunStatusNotificationHub, LandmarkRunStatusNotification> >()
                .As <IHubNotification <LandmarkRunStatusNotification> >()
                .InstancePerLifetimeScope();

            _ = builder.RegisterType <HubNotification <InfoMessageNotificationHub, InfoMessageNotification> >()
                .As <IHubNotification <InfoMessageNotification> >()
                .InstancePerLifetimeScope();

            _ = builder.RegisterType <HubNotification <ScenarioNotificationHub, ScenarioNotificationModel> >()
                .As <IHubNotification <ScenarioNotificationModel> >()
                .InstancePerLifetimeScope();

            _ = builder.RegisterType <ReportExportNotificationHub>()
                .AsSelf()
                .InstancePerLifetimeScope();

            // Register Environments Management for collectively managing environments
            _ = builder.Register(x =>
            {
                var mapper           = x.Resolve <IMapper>();
                var autoBookSettings = x.Resolve <AutoBookSettings>();
                var environmentApi   =
                    new AWSEnvironmentAPI(autoBookSettings.ProvisioningAPIURL, _autobookProviderApiAccessToken);

                return(new AWSEnvironment(environmentApi, mapper));
            })
                .As <IEnvironment>();

            // Register Autobook Provider API
            _ = builder.Register(x =>
            {
                var autoBookSettings = x.Resolve <AutoBookSettings>();
                return(new ProviderLogsAPI(autoBookSettings.ProvisioningAPIURL, _autobookProviderApiAccessToken));
            })
                .As <IProviderLogsAPI>();

            _ = builder.RegisterType <AutoBookCreateBackgroundJob>()
                .AsSelf()
                .As <IBackgroundJob>();

            _ = builder.RegisterType <AutoBookDeleteBackgroundJob>()
                .AsSelf()
                .As <IBackgroundJob>();

            _ = builder.RegisterType <RunCompletionBackgroundJob>()
                .AsSelf()
                .As <IBackgroundJob>();

            _ = builder.RegisterType <GenerateRecommendationsReportBackgroundJob>()
                .AsSelf()
                .As <IBackgroundJob>();

            _ = builder.RegisterType <LandmarkTriggerRunJob>()
                .AsSelf()
                .As <IBackgroundJob>();

            _ = builder.RegisterType <RunStatusChecker>().InstancePerDependency();

            if (_testEnvironment.HasOptions(TestEnvironmentOptions.LandmarkServicesStub))
            {
                _ = builder.RegisterType <LandmarkApiClientStub>()
                    .As <ILandmarkApiClient>()
                    .SingleInstance();

                _ = builder.RegisterType <LandmarkAutoBookPayloadProviderStub>()
                    .As <ILandmarkAutoBookPayloadProvider>()
                    .SingleInstance();
            }

            if (_testEnvironment.HasOptions(TestEnvironmentOptions.PerformanceLog))
            {
                _ = builder.Register(context =>
                                     context.ResolveOptionalNamed <ILoggerFactory>(SqlServerAutofacModuleBase
                                                                                   .DbContextLoggerFactoryRegistrationName)?.CreateLogger <PerformanceLog>() ??
                                     new NullLogger <PerformanceLog>())
                    .As <ILogger <PerformanceLog> >()
                    .InstancePerLifetimeScope();

                _ = builder.Register(context =>
                {
                    var tenantIdentifier = context.Resolve <TenantIdentifier>();
                    return(new SerilogLoggerFactory(new LoggerConfiguration()
                                                    .MinimumLevel.Debug()
                                                    .Enrich.With <UtcTimeLogEventEnricher>()
                                                    .Enrich.With(new PerformanceLogCorrelationIdLogEventEnricher("perf-test-id"))
                                                    .WriteTo.Async(a =>
                                                                   a.File(PerformanceLog.GetLogFileNameTemplate(tenantIdentifier),
                                                                          outputTemplate: "{UtcTime}|[{Level:u3}]|{CorrelationId}|{Message:lj}{NewLine}{Exception}",
                                                                          rollingInterval: RollingInterval.Day,
                                                                          shared: true))
                                                    .CreateLogger(), true));
                })
                    .Named <ILoggerFactory>(SqlServerAutofacModuleBase.DbContextLoggerFactoryRegistrationName)
                    .SingleInstance();
            }
        }
Exemple #2
0
        public async Task <object?> ProcessAsync(IWorkSession session, IList <Diagnostic> diagnostics, CancellationToken cancellationToken)
        {
            PerformanceLog.Checkpoint("SlowUpdate.ProcessAsync.Start");
            var targetName = GetAndEnsureTargetName(session);

            _topLevelProgramSupport.UpdateOutputKind(session, diagnostics);

            if (targetName is TargetNames.Ast or TargetNames.Explain)
            {
                var astTarget = _astTargets[session.LanguageName];
                var ast       = await astTarget.GetAstAsync(session, cancellationToken).ConfigureAwait(false);

                if (targetName == TargetNames.Explain)
                {
                    return(await _explainer.ExplainAsync(ast, session, cancellationToken).ConfigureAwait(false));
                }
                return(ast);
            }

            if (diagnostics.Any(d => d.Severity == DiagnosticSeverity.Error))
            {
                return(null);
            }

            if (targetName == LanguageNames.VisualBasic)
            {
                return(VisualBasicNotAvailable);
            }

            if (targetName is not(TargetNames.Run or TargetNames.Verify) && !_decompilers.ContainsKey(targetName))
            {
                throw new NotSupportedException($"Target '{targetName}' is not (yet?) supported by this branch.");
            }

            MemoryStream?assemblyStream = null;
            MemoryStream?symbolStream   = null;

            try {
                assemblyStream = _memoryStreamManager.GetStream();
                if (targetName is TargetNames.Run or TargetNames.IL)
                {
                    symbolStream = _memoryStreamManager.GetStream();
                }

                var compilationStopwatch = session.ShouldReportPerformance() ? Stopwatch.StartNew() : null;
                var compiled             = await _compiler.TryCompileToStreamAsync(assemblyStream, symbolStream, session, diagnostics, cancellationToken).ConfigureAwait(false);

                compilationStopwatch?.Stop();
                if (!compiled.assembly)
                {
                    assemblyStream.Dispose();
                    symbolStream?.Dispose();
                    return(null);
                }

                if (targetName == TargetNames.Verify)
                {
                    assemblyStream.Dispose();
                    symbolStream?.Dispose();
                    return("✔️ Compilation completed.");
                }

                assemblyStream.Seek(0, SeekOrigin.Begin);
                symbolStream?.Seek(0, SeekOrigin.Begin);
                AssemblyLog.Log("1.Compiled", assemblyStream, compiled.symbols ? symbolStream : null);

                var streams = new CompilationStreamPair(assemblyStream, compiled.symbols ? symbolStream : null);
                if (targetName == TargetNames.Run)
                {
                    if (!session.HasContainerExperimentFailed())
                    {
                        try {
                            var output = await _containerExecutor.ExecuteAsync(streams, session, cancellationToken);

                            if (compilationStopwatch != null)
                            {
                                // TODO: Prettify
                                output += $"\n  COMPILATION: {compilationStopwatch.ElapsedMilliseconds,15}ms";
                            }
                            streams.Dispose();
                            _monitor.Metric(ContainerExperimentMetrics.ContainerRunCount, 1);
                            return(output);
                        }
                        catch (Exception ex) {
                            _monitor.Metric(ContainerExperimentMetrics.ContainerFailureCount, 1);
                            _monitor.Exception(ex, session);
                            session.SetContainerExperimentException(ex);
                            assemblyStream.Seek(0, SeekOrigin.Begin);
                            symbolStream?.Seek(0, SeekOrigin.Begin);
                        }
                    }

                    _monitor.Metric(ContainerExperimentMetrics.LegacyRunCount, 1);
                    return(_executor.Execute(streams, session));
                }

                // it's fine not to Dispose() here -- MirrorSharp will dispose it after calling WriteResult()
                return(streams);
            }
            catch {
                assemblyStream?.Dispose();
                symbolStream?.Dispose();
                throw;
            }
        }
Exemple #3
0
        //ObservableCollection<PerformanceLogSummary> BoundData {
        //    get {
        //        return (SummaryGrid.ItemsSource as ObservableCollection<PerformanceLogSummary>);
        //    }
        //}

        void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            if (totalCount == 0)
            {
                startTime = DateTime.Now;
                jsUpdateElement.InvokeSelf("startTime", startTime);
            }
            lock (m_lock) {
                totalCount        += 1;
                percentageComplete = Decimal.Divide((Decimal.Divide((decimal)totalCount, (decimal)repeatTest)), serializerPeformanceItem.Count()) * 100;
                webClientQueue.Enqueue((WebClient)sender);
            }
            jsUpdateElement.InvokeSelf("counter", totalCount);
            jsUpdateElement.InvokeSelf("percentage", percentageComplete);

            if (e.Error == null)
            {
                PerformanceLog perfLog = m_logQueue.Dequeue();
                var            summary = from entry in m_logQueue.Dequeue().Entries
                                         select new {
                    Description = entry.Description,
                    Value       = entry.Value,
                    EntryType   = entry.PerformanceLogEntryType
                };

                PerformanceLogSummary perfLogSummary = new PerformanceLogSummary();
                perfLogSummary.Sequence = totalCount;

                List <bool> deserializationWasCorrect = new List <bool>();

                foreach (var item in summary)
                {
                    switch (item.EntryType)
                    {
                    case PerformanceLogEntryType.CompiledObjectCreation:
                        perfLogSummary.CompiledObjectCreationTime = (double)item.Value;
                        break;

                    case PerformanceLogEntryType.Serialization:
                        perfLogSummary.SerializationTime = (double)item.Value;
                        break;

                    case PerformanceLogEntryType.Deserialization:
                        perfLogSummary.DeserializationTime = (double)item.Value;
                        break;

                    case PerformanceLogEntryType.SendSerializedObjectTime:
                        perfLogSummary.SendSerializedObjectTime = (double)item.Value;
                        break;

                    case PerformanceLogEntryType.ReceiveSerializedObjectTime:
                        perfLogSummary.ReceiveSerializedObjectTime = (double)item.Value;
                        break;

                    case PerformanceLogEntryType.StreamSize:
                        perfLogSummary.StreamSize = (double)item.Value;
                        break;

                    case PerformanceLogEntryType.DeserializationCorrect:
                        deserializationWasCorrect.Add((bool)item.Value);
                        break;

                    case PerformanceLogEntryType.TotalDuration:
                        perfLogSummary.TotalDuration = (double)item.Value;
                        break;

                    default:
                        break;
                    }
                }
                perfLogSummary.DeserializationWasCorrect = !deserializationWasCorrect.Contains(false);
                PerformanceLogList.Items.Add(perfLogSummary);
                //BoundData.Insert(totalCount, perfLogSummary);

                //double totalSum = summary.Sum(total => total.Value);

                //PerformanceLogList.Items.Add(new PerformanceLogSummary {
                //    AverageDeserializationTime = totalSum,
                //    AverageSerializationTime = totalSum
                //});
            }
            if (percentageComplete == 100)
            {
                finishTime = DateTime.Now;
                jsUpdateElement.InvokeSelf("finishTime", finishTime);
                jsUpdateElement.InvokeSelf("totalTime", finishTime.Subtract(startTime).TotalMilliseconds);
            }
        }
Exemple #4
0
        public PerformanceLog RunSerializationTest(long sequenceID, SerializerPerformanceTestAgent agent)
        {
            Stopwatch timer = new Stopwatch();

            Stopwatch.UnitPrecision = UnitPrecision.NANOSECONDS;
            PerformanceLog perfLog = new PerformanceLog {
                Entries       = new List <Entry>(),
                UnitPrecision = Stopwatch.UnitPrecision
            };

            if (totalCount == 0)
            {
                startTime = DateTime.Now;
                UpdateUI(() => jsUpdateElement.InvokeSelf("startTime", startTime));
            }

            Person person = null;

            Uri uri = new Uri(String.Format("http://localhost:9999/Person_{0}.xml", sequenceID), UriKind.Absolute);

            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);

            int id = (int)sequenceID;

            using (timer) {
                timer.Scope = () => {
                    timer.LogScope("Create a Person object", perfLog, PerformanceLogEntryType.CompiledObjectCreation, () => {
                        person = CreatePerson(sequenceID);
                    });

                    Stream serializedMemoryStream = null;

                    timer.LogScope("Serialize the Person object to a MemoryStream", perfLog, PerformanceLogEntryType.Serialization, () => {
                        serializedMemoryStream = SerializeToStream <Person>(person, null, agent.ISerializerTestAgent);
                    }).LogData("Length (in bytes) of memoryStream", serializedMemoryStream.Length, PerformanceLogEntryType.StreamSize);


                    timer.LogScope("Send the serialized MemoryStream to S3", perfLog, PerformanceLogEntryType.SendSerializedObjectTime, () => {
                        //client.OpenWriteAsync(uri);
                    });

                    timer.LogScope("Request the serialized object back from S3", perfLog, PerformanceLogEntryType.ReceiveSerializedObjectTime, () => {
                        request.BeginGetResponse(new AsyncCallback(ReadCallback), request);
                    });

                    Person newPersonFromMemoryStream = null;

                    using (serializedMemoryStream) {
                        timer.LogScope("Deserialize and parse the Person object from a MemoryStream", perfLog, PerformanceLogEntryType.Deserialization, () => {
                            newPersonFromMemoryStream = DeserializeFromStream <Person>(serializedMemoryStream, agent.ISerializerTestAgent);
                        });
                    }

                    CompareValuesAndLogResults(person, newPersonFromMemoryStream, perfLog, typeof(MemoryStream), PerformanceLogEntryType.DeserializationCorrect);
                };

                perfLog.LogData("Duration of test", timer.Duration, PerformanceLogEntryType.TotalDuration);
            }

            return(perfLog);
        }
Exemple #5
0
        public async Task <object?> ProcessAsync(IWorkSession session, IList <Diagnostic> diagnostics, CancellationToken cancellationToken)
        {
            PerformanceLog.Checkpoint("SlowUpdate.ProcessAsync.Start");
            var targetName = GetAndEnsureTargetName(session);

            if (targetName == TargetNames.Ast || targetName == TargetNames.Explain)
            {
                var astTarget = _astTargets[session.LanguageName];
                var ast       = await astTarget.GetAstAsync(session, cancellationToken).ConfigureAwait(false);

                if (targetName == TargetNames.Explain)
                {
                    return(await _explainer.ExplainAsync(ast, session, cancellationToken).ConfigureAwait(false));
                }
                return(ast);
            }

            if (diagnostics.Any(d => d.Severity == DiagnosticSeverity.Error))
            {
                return(null);
            }

            if (targetName == LanguageNames.VisualBasic)
            {
                return(VisualBasicNotAvailable);
            }

            if (targetName != TargetNames.Run && targetName != TargetNames.Verify && !_decompilers.ContainsKey(targetName))
            {
                throw new NotSupportedException($"Target '{targetName}' is not (yet?) supported by this branch.");
            }

            MemoryStream?assemblyStream = null;
            MemoryStream?symbolStream   = null;

            try {
                assemblyStream = _memoryStreamManager.GetStream();
                if (targetName == TargetNames.Run || targetName == TargetNames.IL)
                {
                    symbolStream = _memoryStreamManager.GetStream();
                }

                var compiled = await _compiler.TryCompileToStreamAsync(assemblyStream, symbolStream, session, diagnostics, cancellationToken).ConfigureAwait(false);

                if (!compiled.assembly)
                {
                    assemblyStream.Dispose();
                    symbolStream?.Dispose();
                    return(null);
                }

                if (targetName == TargetNames.Verify)
                {
                    assemblyStream.Dispose();
                    symbolStream?.Dispose();
                    return("✔️ Compilation completed.");
                }

                assemblyStream.Seek(0, SeekOrigin.Begin);
                symbolStream?.Seek(0, SeekOrigin.Begin);
                AssemblyLog.Log("1.Compiled", assemblyStream);

                var streams = new CompilationStreamPair(assemblyStream, compiled.symbols ? symbolStream : null);
                if (targetName == TargetNames.Run)
                {
                    return(_executor.Execute(streams, session));
                }

                // it's fine not to Dispose() here -- MirrorSharp will dispose it after calling WriteResult()
                return(streams);
            }
            catch {
                assemblyStream?.Dispose();
                symbolStream?.Dispose();
                throw;
            }
        }
        private void PostProgressChanged(AsyncOperation asyncOp, PerformanceLog perfLog)
        {
            long percentageComplete = (m_progress.TotalTasksCompleted / m_progress.TotalTasksToComplete) * 100;

            asyncOp.Post(reportOperationProgressChanged, new OperationProgressChangedEventArgs((int)percentageComplete, perfLog, m_progress.TotalTasksCompleted, m_progress.TotalTasksToComplete));
        }