public CosmosDBConfigurationProvider(WebHostBuilderContext context, CosmosDBConfiguration configuration, IWatcherClient watcherClient, IParser <string> parser)
        {
            _context       = context ?? throw new ArgumentNullException(nameof(context));
            _configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
            _parser        = parser ?? throw new ArgumentNullException(nameof(parser));

            if (watcherClient == null)
            {
                throw new ArgumentNullException(nameof(watcherClient));
            }

            if (string.IsNullOrWhiteSpace(configuration.ConnectionString))
            {
                throw new ArgumentNullException(nameof(configuration), "Connectionstring is missing from configuration");
            }

            if (string.IsNullOrWhiteSpace(configuration.Database))
            {
                throw new ArgumentNullException(nameof(configuration), "Database is missing from configuration");
            }

            if (string.IsNullOrWhiteSpace(configuration.PrimaryKey))
            {
                throw new ArgumentNullException(nameof(configuration), "Primary key is missing from configuration");
            }

            if (_configuration.ReloadOnChange)
            {
                _changeTokenRegistration = ChangeToken.OnChange(watcherClient.Watch, LoadSettings);
            }
        }
Example #2
0
 public CosmosDBConfigurationSource(WebHostBuilderContext context, CosmosDBConfiguration configuration)
 {
     _context       = context ?? throw new ArgumentNullException(nameof(context));
     _configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
     _watcherClient = new CosmosDBWatcherClient(_context, _configuration);
     _parser        = new JsonParser();
 }
        static void Main(string[] args)
        {
            CosmosDBConfiguration environmentConfiguration = ConfigurationService.Configuration;

            Console.WriteLine($"Starting benchmark and dropping results on {environmentConfiguration.ReportsPath}.");
            BenchmarkRunner.Run <ItemBenchmark>(new CustomBenchmarkConfiguration(environmentConfiguration));
        }
        private void AddConfigurationAndGatewayServices(IServiceCollection services)
        {
            var cosmosDBConfiguration = new CosmosDBConfiguration();

            Configuration.Bind("CosmosDB", cosmosDBConfiguration);
            services.AddSingleton(cosmosDBConfiguration);

            var eventGridConfiguration = new EventGridConfiguration();

            Configuration.Bind("EventGrid", eventGridConfiguration);
            services.AddSingleton(eventGridConfiguration);

            var websocketConfiguration = new WebsocketConfiguration();

            Configuration.Bind("Websocket", websocketConfiguration);
            services.AddSingleton(websocketConfiguration);

            services.AddSingleton <IDecisionChannel, DecisionChannelRx>();
            services.AddSingleton <IPerceptionChannel, PerceptionChannelRx>();

            if (eventGridConfiguration.Enabled)
            {
                services.AddSingleton(s => new EventGridClient(new TopicCredentials(eventGridConfiguration.PersonProfileContextPerceptionTopicKey)));
                services.AddSingleton <PerceptionChannelAdapterEventGrid>();
            }
            else
            {
                // Individual components and their dependencies, seemlessly replaced by Azure functions in the cloud
                services.AddSingleton(s => new DocumentClient(new Uri(cosmosDBConfiguration.AccountEndpoint), cosmosDBConfiguration.AccountKey));
                services.AddSingleton <PersonComponent>();
                services.AddSingleton <IPersonRepository, PersonRepositoryCosmosDb>();
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="JobApplicationQuery"/> class.
 /// constructor
 /// </summary>
 /// <param name="falconQueryClient">falcon query client</param>
 /// <param name="graphProvider">graph provider</param>
 /// <param name="configManager">config manager</param>
 /// <param name="pilotInterceptor">pilot interceptor</param>
 /// <param name="redisCacheIV">Redis Cache for Caching the response</param>
 /// <param name="logger">The instance for <see cref="ILogger{JobApplicationQuery}"/>.</param>
 public JobApplicationQuery(
     ICosmosQueryClientProvider cosmosQueryClientProvider,
     IOptions <CosmosDBConfiguration> cosmosDBConfiguration,
     ILogger <JobApplicationQuery> logger)
 {
     this.cosmosQueryClientProvider = cosmosQueryClientProvider;
     this.logger = logger;
     this.cosmosDBConfiguration = cosmosDBConfiguration?.Value;
 }
Example #6
0
        public void Constructor_ThrowsArgumentNullException_WhenConfigurationMissingConnectionstring(string value)
        {
            var configuration = new CosmosDBConfiguration
            {
                ConnectionString = value
            };

            // ReSharper disable ObjectCreationAsStatement
            Action sut = () => new CosmosDBConfigurationProvider(new WebHostBuilderContext(), configuration, new Mock <IWatcherClient>().Object, new Mock <IParser <string> >().Object);

            sut.Should().ThrowExactly <ArgumentNullException>().And.Message.Should().StartWith("Connectionstring");
        }
 public CustomBenchmarkConfiguration(CosmosDBConfiguration configuration)
 {
     this.Add(JitOptimizationsValidator.DontFailOnError);
     this.Add(DefaultConfig.Instance.GetLoggers().ToArray());
     this.Add(StatisticColumn.P90);
     this.Add(StatisticColumn.P95);
     this.Add(StatisticColumn.P100);
     this.Add(StatisticColumn.OperationsPerSecond);
     this.Add(MarkdownExporter.Default);
     this.Add(CsvExporter.Default);
     this.Add(DefaultConfig.Instance.GetColumnProviders().ToArray());
     this.ArtifactsPath = CustomBenchmarkConfiguration.GetReportPath(configuration);
 }
        public CosmosQueryClientProvider(IOptions <CosmosDBConfiguration> cosmosDBConfiguration, ILogger <CosmosQueryClientProvider> logger)
        {
            this.logger = logger;
            this.cosmosDBConfiguration = cosmosDBConfiguration?.Value;
            this.cosmosDBConfiguration = new CosmosDBConfiguration
            {
                Key                = "",
                Database           = "",
                Uri                = "",
                GTACommonContainer = "",
            };

            this.documentClient = this.GetDocumentClient();
        }
        /// <summary>
        /// Enables use of the CosmosDB extensions
        /// </summary>
        /// <param name="config">The <see cref="JobHostConfiguration"/> to configure.</param>
        /// <param name="cosmosDBConfig">The <see cref="CosmosDBConfiguration"/> to use.</param>
        public static void UseCosmosDB(this JobHostConfiguration config, CosmosDBConfiguration cosmosDBConfig = null)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            if (cosmosDBConfig == null)
            {
                cosmosDBConfig = new CosmosDBConfiguration();
            }

            config.RegisterExtensionConfigProvider(cosmosDBConfig);
        }
Example #10
0
        public void Constructor_DoesNotThrowArgumentNullException_WhenParametersArePopulated()
        {
            var configuration = new CosmosDBConfiguration
            {
                ConnectionString = "A",
                Database         = "B",
                PrimaryKey       = "C"
            };

            // ReSharper disable ObjectCreationAsStatement
            Action sut = () => new CosmosDBConfigurationProvider(new WebHostBuilderContext(), configuration, new Mock <IWatcherClient>().Object, new Mock <IParser <string> >().Object);

            sut.Should().NotThrow <ArgumentNullException>();
        }
Example #11
0
        public CosmosDBConfigurationProvider(WebHostBuilderContext context, CosmosDBConfiguration configuration, CosmosDBWatcherClient watcherClient)
        {
            _context       = context ?? throw new ArgumentNullException(nameof(context));
            _configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));

            if (watcherClient == null)
            {
                throw new ArgumentNullException(nameof(watcherClient));
            }

            if (_configuration.ReloadOnChange)
            {
                _changeTokenRegistration = ChangeToken.OnChange(watcherClient.Watch, LoadSettings);
            }
        }
Example #12
0
        public CosmosDBWatcherClient(WebHostBuilderContext context, CosmosDBConfiguration configuration)
        {
            var cosmosClient = new CosmosClient(configuration.ConnectionString, configuration.PrimaryKey);

            var leaseContainer = cosmosClient.GetContainer(configuration.Database, "leases");

            var monitoredContainer = cosmosClient.GetContainer(configuration.Database, context.HostingEnvironment.ApplicationName);

            var builder = monitoredContainer
                          .GetChangeFeedProcessorBuilder <object>(string.Empty,
                                                                  async(changes, token) => await ProcessChanges(token))
                          .WithInstanceName($"{context.HostingEnvironment.ApplicationName}-{context.HostingEnvironment.EnvironmentName}")
                          .WithLeaseContainer(leaseContainer)
                          .WithPollInterval(new TimeSpan(0, 0, 0, 5));

            _processor = builder.Build();
        }
        public MongoCosmosClient(CosmosDBConfiguration config)
        {
            MongoClientSettings settings = new MongoClientSettings();

            settings.Server      = new MongoServerAddress(config.DatabaseServer, 10255);
            settings.UseTls      = true;
            settings.SslSettings = new SslSettings();
            settings.SslSettings.EnabledSslProtocols = SslProtocols.Tls12;
            settings.RetryWrites = false;

            MongoIdentity         identity = new MongoInternalIdentity(config.DatabaseName, config.DatabaseUser);
            MongoIdentityEvidence evidence = new PasswordEvidence(config.DatabasePassword);

            settings.Credential = new MongoCredential("SCRAM-SHA-1", identity, evidence);

            _mongoClient = new MongoClient(settings);
        }
Example #14
0
        private async Task RunTestAsync(Type testType, string testName, ICosmosDBServiceFactory factory, TraceWriter testTrace, object argument = null, string configConnectionString = ConfigConnStr, bool includeDefaultConnectionString = true)
        {
            ExplicitTypeLocator  locator = new ExplicitTypeLocator(testType);
            JobHostConfiguration config  = new JobHostConfiguration
            {
                TypeLocator = locator,
            };

            config.Tracing.Tracers.Add(testTrace);

            var arguments = new Dictionary <string, object>
            {
                { "triggerData", argument }
            };

            var cosmosDBConfig = new CosmosDBConfiguration()
            {
                ConnectionString       = configConnectionString,
                CosmosDBServiceFactory = factory
            };

            var resolver = new TestNameResolver();

            resolver.Values.Add("Database", "ResolvedDatabase");
            resolver.Values.Add("Collection", "ResolvedCollection");
            resolver.Values.Add("MyConnectionString", AttributeConnStr);
            resolver.Values.Add("Query", "ResolvedQuery");
            if (includeDefaultConnectionString)
            {
                resolver.Values.Add(CosmosDBConfiguration.AzureWebJobsCosmosDBConnectionStringName, DefaultConnStr);
            }

            config.NameResolver = resolver;

            config.UseCosmosDB(cosmosDBConfig);

            JobHost host = new JobHost(config);

            await host.StartAsync();

            await host.CallAsync(testType.GetMethod(testName), arguments);

            await host.StopAsync();
        }
        public async Task Configuration_Caches_Clients()
        {
            // Arrange
            var config = new CosmosDBConfiguration
            {
                ConnectionString = "AccountEndpoint=https://someuri;AccountKey=c29tZV9rZXk=;",
            };
            var attribute = new CosmosDBAttribute {
                Id = "abcdef"
            };

            // Act
            var context1 = config.CreateContext(attribute);
            var context2 = config.CreateContext(attribute);
            var binder   = await config.BindForItemAsync(attribute, typeof(Item));

            // Assert
            Assert.Single(config.ClientCache);
        }
        private static CosmosDBEnumerableBuilder <T> CreateBuilder <T>(out Mock <ICosmosDBService> mockService)
            where T : class
        {
            CosmosDBConfiguration config = new CosmosDBConfiguration
            {
                ConnectionString = "AccountEndpoint=https://someuri;AccountKey=c29tZV9rZXk=;"
            };

            mockService = new Mock <ICosmosDBService>(MockBehavior.Strict);
            Mock <ICosmosDBServiceFactory> mockServiceFactory = new Mock <ICosmosDBServiceFactory>(MockBehavior.Strict);

            mockServiceFactory
            .Setup(m => m.CreateService(It.IsAny <string>()))
            .Returns(mockService.Object);

            config.CosmosDBServiceFactory = mockServiceFactory.Object;

            return(new CosmosDBEnumerableBuilder <T>(config));
        }
        private CosmosDBConfiguration InitializeConfig(string defaultConnStr)
        {
            var config = new CosmosDBConfiguration();

            var nameResolver = new TestNameResolver();

            nameResolver.Values[CosmosDBConfiguration.AzureWebJobsCosmosDBConnectionStringName] = defaultConnStr;

            var jobHostConfig = new JobHostConfiguration();

            jobHostConfig.AddService <INameResolver>(nameResolver);

            var context = new ExtensionConfigContext()
            {
                Config = jobHostConfig
            };

            config.Initialize(context);

            return(config);
        }
Example #18
0
        private Task OnExecuteAsync(CommandLineApplication application)
        {
            var cosmosConfiguration = new CosmosDBConfiguration {
                DatabaseServer   = CommandDatabaseServerAddress,
                DatabaseName     = CommandDatabaseName,
                DatabaseUser     = CommandDatabaseServerIdentity,
                DatabasePassword = CommandDatabaseServerPassword
            };

            _cosmosClient = new MongoCosmosClient(cosmosConfiguration);

            try
            {
                Console.WriteLine($"[{DateTime.Now.ToShortTimeString()}]Beginning operations...\n");
                Console.WriteLine($"[{DateTime.Now.ToShortTimeString()}]#### --- Settings --- ####");
                Console.WriteLine($"[{DateTime.Now.ToShortTimeString()}]Timeout(s) :: {_defaultTimeout().TotalSeconds}");
                Console.WriteLine($"[{DateTime.Now.ToShortTimeString()}]Delete data:: {CommandDeleteData}");

                _testRunStatistics.StartCollecting();
                new Thread(InsertDocuments).Start();
                new Thread(ConsumeDocuments).Start();
            }
            catch (CosmosException de)
            {
                Exception baseException = de.GetBaseException();
                ConsoleWrite(ConsoleColor.Red, $"{de.StatusCode} error occurred: {de}");
                return(Task.FromResult(1));
            }
            catch (Exception e)
            {
                ConsoleWrite(ConsoleColor.Red, $"Error occurred: {e}");
                return(Task.FromResult(1));
            }

            return(Task.Delay(-1));
        }
 public CosmosDBClientBuilder(CosmosDBConfiguration config)
 {
     _config = config;
 }
Example #20
0
        public CosmosDBWatcherClient(CosmosClient cosmosClient, WebHostBuilderContext context, CosmosDBConfiguration configuration)
        {
            _cosmosClient = cosmosClient ?? throw new ArgumentNullException(nameof(cosmosClient));

            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            if (string.IsNullOrWhiteSpace(configuration.Database))
            {
                throw new ArgumentNullException(nameof(configuration), "Database is missing from configuration");
            }

            if (string.IsNullOrWhiteSpace(configuration.LeaseContainerName))
            {
                throw new ArgumentNullException(nameof(configuration), "Lease container name is missing from configuration");
            }

            var leaseContainer = _cosmosClient.GetContainer(configuration.Database, configuration.LeaseContainerName);

            var monitoredContainer = _cosmosClient.GetContainer(configuration.Database, configuration.GetDataSourceName(context.HostingEnvironment));

            var builder = monitoredContainer
                          .GetChangeFeedProcessorBuilder <object>(string.Empty,
                                                                  async(changes, token) => await ProcessChanges(token))
                          .WithInstanceName($"{configuration.GetDataSourceName(context.HostingEnvironment)}-{configuration.GetEnvironment(context.HostingEnvironment)}")
                          .WithLeaseContainer(leaseContainer);

            if (configuration.PollingIntervalInSeconds < 1)
            {
                _processor = builder.Build();
                return;
            }

            builder.WithPollInterval(new TimeSpan(0, 0, 0, configuration.PollingIntervalInSeconds));
            _processor = builder.Build();
        }
 public void ValidateInputBindings_Succeeds_WithValidBindings(CosmosDBAttribute attribute, Type parameterType)
 {
     CosmosDBConfiguration.ValidateInputBinding(attribute, parameterType);
 }
 public void ValidateInputBindings_Throws_WithInvalidBindings(CosmosDBAttribute attribute, Type parameterType)
 {
     Assert.Throws <InvalidOperationException>(() => CosmosDBConfiguration.ValidateInputBinding(attribute, parameterType));
 }
 public CosmosDBCollectorBuilder(CosmosDBConfiguration config)
 {
     _config = config;
 }
 public CosmosDBJArrayBuilder(CosmosDBConfiguration config)
 {
     _builder = new CosmosDBEnumerableBuilder <JObject>(config);
 }
        public void TryGetEnumerableType(Type type, bool expectedResult)
        {
            bool actualResult = CosmosDBConfiguration.IsSupportedEnumerable(type);

            Assert.Equal(expectedResult, actualResult);
        }
 public static string GetReportPath(CosmosDBConfiguration configuration) => configuration.ReportsPath;
 public CosmosDBConfigurationSource(WebHostBuilderContext context, CosmosDBConfiguration configuration)
 {
     _context       = context;
     _configuration = configuration;
 }