protected override void Init(IDictionary <string, string> arguments, CancellationToken cancellationToken)
        {
            var gallery            = arguments.GetOrThrow <string>(Arguments.Gallery);
            var index              = arguments.GetOrThrow <string>(Arguments.Index);
            var packageBaseAddress = arguments.GetOrThrow <string>(Arguments.ContentBaseAddress);
            var source             = arguments.GetOrThrow <string>(Arguments.Source);
            var requireSignature   = arguments.GetOrDefault(Arguments.RequireSignature, false);
            var verbose            = arguments.GetOrDefault(Arguments.Verbose, false);

            CommandHelpers.AssertAzureStorage(arguments);

            var monitoringStorageFactory = CommandHelpers.CreateStorageFactory(arguments, verbose);
            var auditingStorageFactory   = CommandHelpers.CreateSuffixedStorageFactory("Auditing", arguments, verbose);

            var endpointInputs        = CommandHelpers.GetEndpointFactoryInputs(arguments);
            var messageHandlerFactory = CommandHelpers.GetHttpMessageHandlerFactory(TelemetryService, verbose);

            Logger.LogInformation(
                "CONFIG gallery: {Gallery} index: {Index} storage: {Storage} auditingStorage: {AuditingStorage} endpoints: {Endpoints}",
                gallery, index, monitoringStorageFactory, auditingStorageFactory, string.Join(", ", endpointInputs.Select(e => e.Name)));

            _packageValidator = new PackageValidatorFactory(LoggerFactory)
                                .Create(gallery, index, packageBaseAddress, auditingStorageFactory, endpointInputs, messageHandlerFactory, requireSignature, verbose);

            _queue = CommandHelpers.CreateStorageQueue <PackageValidatorContext>(arguments, PackageValidatorContext.Version);

            _statusService = CommandHelpers.GetPackageMonitoringStatusService(arguments, monitoringStorageFactory, LoggerFactory);

            _notificationService = new LoggerMonitoringNotificationService(LoggerFactory.CreateLogger <LoggerMonitoringNotificationService>());

            _regResource = Repository.Factory.GetCoreV3(index).GetResource <RegistrationResourceV3>(cancellationToken);

            _client = new CollectorHttpClient(messageHandlerFactory());
        }
        protected override void Init(IDictionary <string, string> arguments, CancellationToken cancellationToken)
        {
            var verbose = arguments.GetOrDefault(Arguments.Verbose, false);

            _maxRequeueQueueSize = arguments.GetOrDefault(Arguments.MaxRequeueQueueSize, DefaultMaxQueueSize);

            CommandHelpers.AssertAzureStorage(arguments);

            var monitoringStorageFactory = CommandHelpers.CreateStorageFactory(arguments, verbose);

            _statusService = CommandHelpers.GetPackageMonitoringStatusService(arguments, monitoringStorageFactory, LoggerFactory);

            _queue = CommandHelpers.CreateStorageQueue <PackageValidatorContext>(arguments, PackageValidatorContext.Version);
        }
        protected override void Init(IDictionary <string, string> arguments, CancellationToken cancellationToken)
        {
            var verbose = arguments.GetOrDefault(Arguments.Verbose, false);

            _maxRequeueQueueSize = arguments.GetOrDefault(Arguments.MaxRequeueQueueSize, DefaultMaxQueueSize);

            CommandHelpers.AssertAzureStorage(arguments);

            var monitoringStorageFactory = CommandHelpers.CreateStorageFactory(arguments, verbose);

            _statusService = CommandHelpers.GetPackageMonitoringStatusService(arguments, monitoringStorageFactory, LoggerFactory);
            _packageValidatorContextQueue = CommandHelpers.CreateStorageQueue <PackageValidatorContext>(arguments, PackageValidatorContext.Version);

            Logger.LogInformation(
                "CONFIG storage: {Storage}",
                monitoringStorageFactory);

            _monitoringCursor = ValidationFactory.GetFront(monitoringStorageFactory);
            _galleryCursor    = CreateCursor(monitoringStorageFactory, GalleryCursorFileName);
            _deletedCursor    = CreateCursor(monitoringStorageFactory, DeletedCursorFileName);

            var connectionString    = arguments.GetOrThrow <string>(Arguments.ConnectionString);
            var galleryDbConnection = new AzureSqlConnectionFactory(
                connectionString,
                SecretInjector,
                LoggerFactory.CreateLogger <AzureSqlConnectionFactory>());

            var packageContentUriBuilder = new PackageContentUriBuilder(
                arguments.GetOrThrow <string>(Arguments.PackageContentUrlFormat));

            var timeoutInSeconds = arguments.GetOrDefault(Arguments.SqlCommandTimeoutInSeconds, 300);

            _galleryDatabaseQueryService = new GalleryDatabaseQueryService(
                galleryDbConnection,
                packageContentUriBuilder,
                TelemetryService,
                timeoutInSeconds);

            var auditingStorageFactory = CommandHelpers.CreateSuffixedStorageFactory(
                "Auditing",
                arguments,
                verbose,
                new SemaphoreSlimThrottle(new SemaphoreSlim(ServicePointManager.DefaultConnectionLimit)));

            _auditingStorage = auditingStorageFactory.Create();

            var messageHandlerFactory = CommandHelpers.GetHttpMessageHandlerFactory(TelemetryService, verbose);

            _client = new CollectorHttpClient(messageHandlerFactory());
        }
Example #4
0
        protected override void Init(IDictionary <string, string> arguments, CancellationToken cancellationToken)
        {
            var gallery                    = arguments.GetOrThrow <string>(Arguments.Gallery);
            var index                      = arguments.GetOrThrow <string>(Arguments.Index);
            var packageBaseAddress         = arguments.GetOrThrow <string>(Arguments.ContentBaseAddress);
            var source                     = arguments.GetOrThrow <string>(Arguments.Source);
            var requireRepositorySignature = arguments.GetOrDefault(Arguments.RequireRepositorySignature, false);
            var verbose                    = arguments.GetOrDefault(Arguments.Verbose, false);

            var timeoutInSeconds = arguments.GetOrDefault(Arguments.SqlCommandTimeoutInSeconds, 300);
            var sqlTimeout       = TimeSpan.FromSeconds(timeoutInSeconds);

            var connectionString    = arguments.GetOrThrow <string>(Arguments.ConnectionString);
            var galleryDbConnection = new AzureSqlConnectionFactory(
                connectionString,
                SecretInjector,
                LoggerFactory.CreateLogger <AzureSqlConnectionFactory>());
            var packageContentUriBuilder = new PackageContentUriBuilder(
                arguments.GetOrThrow <string>(Arguments.PackageContentUrlFormat));
            var galleryDatabase = new GalleryDatabaseQueryService(
                galleryDbConnection,
                packageContentUriBuilder,
                TelemetryService,
                timeoutInSeconds);

            CommandHelpers.AssertAzureStorage(arguments);

            var monitoringStorageFactory = CommandHelpers.CreateStorageFactory(arguments, verbose);
            var auditingStorageFactory   = CommandHelpers.CreateSuffixedStorageFactory("Auditing", arguments, verbose);

            var endpointConfiguration = CommandHelpers.GetEndpointConfiguration(arguments);
            var messageHandlerFactory = CommandHelpers.GetHttpMessageHandlerFactory(TelemetryService, verbose);

            Logger.LogInformation(
                "CONFIG gallery: {Gallery} index: {Index} storage: {Storage} auditingStorage: {AuditingStorage} registration cursor uri: {RegistrationCursorUri} flat-container cursor uri: {FlatContainerCursorUri}",
                gallery, index, monitoringStorageFactory, auditingStorageFactory, endpointConfiguration.RegistrationCursorUri, endpointConfiguration.FlatContainerCursorUri);

            var validatorConfig = new ValidatorConfiguration(
                packageBaseAddress,
                requireRepositorySignature);

            _packageValidator = ValidationFactory.CreatePackageValidator(
                gallery,
                index,
                auditingStorageFactory,
                validatorConfig,
                endpointConfiguration,
                messageHandlerFactory,
                galleryDatabase,
                LoggerFactory);

            _queue = CommandHelpers.CreateStorageQueue <PackageValidatorContext>(arguments, PackageValidatorContext.Version);

            _statusService = CommandHelpers.GetPackageMonitoringStatusService(arguments, monitoringStorageFactory, LoggerFactory);

            _notificationService = new LoggerMonitoringNotificationService(LoggerFactory.CreateLogger <LoggerMonitoringNotificationService>());

            _client = new CollectorHttpClient(messageHandlerFactory());

            _queueLoopDuration = TimeSpan.FromHours(
                arguments.GetOrDefault(
                    Arguments.QueueLoopDurationHours,
                    DefaultQueueLoopDurationHours));

            _queueDelay = TimeSpan.FromSeconds(
                arguments.GetOrDefault(
                    Arguments.QueueDelaySeconds,
                    DefaultQueueDelaySeconds));

            _workerCount = arguments.GetOrDefault(Arguments.WorkerCount, DefaultWorkerCount);

            SetUserAgentString();
        }
 public PackageMonitoringStatusServiceTests()
 {
     Service = new PackageMonitoringStatusService(
         new MemoryStorageFactory(),
         new Mock <ILogger <PackageMonitoringStatusService> >().Object);
 }