/// <summary> Initialization function for this storage provider. </summary> /// <see cref="IProvider.Init"/> public async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { Log = providerRuntime.GetLogger("Storage.AzureBlobStorage"); try { this.Name = name; ConfigureJsonSerializerSettings(config); if (!config.Properties.ContainsKey("DataConnectionString")) throw new BadProviderConfigException("The DataConnectionString setting has not been configured in the cloud role. Please add a DataConnectionString setting with a valid Azure Storage connection string."); var account = CloudStorageAccount.Parse(config.Properties["DataConnectionString"]); var blobClient = account.CreateCloudBlobClient(); var containerName = config.Properties.ContainsKey("ContainerName") ? config.Properties["ContainerName"] : "grainstate"; container = blobClient.GetContainerReference(containerName); await container.CreateIfNotExistsAsync().ConfigureAwait(false); Log.Info((int)AzureProviderErrorCode.AzureBlobProvider_InitProvider, "Init: Name={0} ServiceId={1} {2}", name, providerRuntime.ServiceId.ToString(), string.Join(" ", FormatPropertyMessage(config))); Log.Info((int)AzureProviderErrorCode.AzureBlobProvider_ParamConnectionString, "AzureBlobStorage Provider is using DataConnectionString: {0}", ConfigUtilities.PrintDataConnectionInfo(config.Properties["DataConnectionString"])); } catch (Exception ex) { Log.Error((int)AzureProviderErrorCode.AzureBlobProvider_InitProvider, ex.ToString(), ex); throw; } }
public async Task Init( string name, IProviderRuntime providerRuntime, IProviderConfiguration config ) { Log = providerRuntime.GetLogger( this.GetType().Name ); try { ConfigureJsonSerializerSettings( config ); if( !config.Properties.ContainsKey( "DataConnectionString" ) ) { throw new BadProviderConfigException( "The DataConnectionString setting has not been configured in the cloud role. Please add a DataConnectionString setting with a valid Azure Storage connection string." ); } else { var account = CloudStorageAccount.Parse( config.Properties[ "DataConnectionString" ] ); var blobClient = account.CreateCloudBlobClient(); var containerName = config.Properties.ContainsKey( "ContainerName" ) ? config.Properties[ "ContainerName" ] : "grainstate"; container = blobClient.GetContainerReference( containerName ); await container.CreateIfNotExistsAsync(); } } catch( Exception ex ) { Log.Error( 0, ex.ToString(), ex ); throw; } }
public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { this.logger = providerRuntime.GetLogger("Dashboard"); var router = new Router(); new DashboardController(router, TaskScheduler.Current, providerRuntime); var options = new StartOptions { ServerFactory = "Nowin", Port = config.Properties.ContainsKey("Port") ? int.Parse(config.Properties["Port"]) : 8080, }; var username = config.Properties.ContainsKey("Username") ? config.Properties["Username"] : null; var password = config.Properties.ContainsKey("Password") ? config.Properties["Password"] : null; try { host = WebApp.Start(options, app => new WebServer(router, username, password).Configuration(app)); } catch (Exception ex) { this.logger.Error(10001, ex.ToString()); } this.logger.Verbose($"Dashboard listening on {options.Port}"); this.profiler = new GrainProfiler(TaskScheduler.Current, providerRuntime); var dashboardGrain = providerRuntime.GrainFactory.GetGrain<IDashboardGrain>(0); return dashboardGrain.Init(); }
public virtual Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { Name = name; logger = providerRuntime.GetLogger(GetType().Name); logger.Info("Init Name={0}", Name); Interlocked.Increment(ref initCount); return TaskDone.Done; }
public async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { Name = name; logger = providerRuntime.GetLogger("SqlStatisticsPublisher"); //TODO: Orleans does not yet provide the type of database used (to, e.g., to load dlls), so SQL Server is assumed. database = RelationalStorageUtilities.CreateGenericStorageInstance(WellKnownRelationalInvariants.SqlServer, config.Properties["ConnectionString"]); await InitOrleansQueriesAsync(); }
/// <summary> /// Initializes publisher /// </summary> /// <param name="name">Provider name</param> /// <param name="providerRuntime">Provider runtime API</param> /// <param name="config">Provider configuration</param> /// <returns></returns> public async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { Name = name; logger = providerRuntime.GetLogger("SqlStatisticsPublisher"); string adoInvariant = AdoNetInvariants.InvariantNameSqlServer; if (config.Properties.ContainsKey("AdoInvariant")) adoInvariant = config.Properties["AdoInvariant"]; orleansQueries = await RelationalOrleansQueries.CreateInstance(adoInvariant, config.Properties["ConnectionString"]); }
/// <summary> /// Initializes the storage provider. /// </summary> /// <param name="name">The name of this provider instance.</param> /// <param name="providerRuntime">A Orleans runtime object managing all storage providers.</param> /// <param name="config">Configuration info for this provider instance.</param> /// <returns>Completion promise for this operation.</returns> public virtual Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { // ASSERT Log != null Log = providerRuntime.GetLogger(this.GetType().FullName); Log.Info("Init {0}", name); Name = name; ConnectionString = config.GetProperty("ConnectionString"); string mapName = config.GetProperty("MapName"); string shardCredentials = config.GetProperty("ShardCredentials"); string factoryTypeName = config.GetProperty("StateMapFactoryType"); _ignore = config.GetPropertyBool("Ignore", false); if (_ignore) Log.Info("!!!Actual SQL persistance will be ignored!!!"); // Look for a specified StateMapFactoryType or the first type implementing IGrainStateMapFactory Type factoryType = null; foreach (var asm in AppDomain.CurrentDomain.GetAssemblies()) { foreach (var type in asm.GetTypes()) { if (type != null && (!string.IsNullOrEmpty(factoryTypeName) && type.FullName == factoryTypeName || string.IsNullOrEmpty(factoryTypeName) && null != type.GetInterface(typeof (IGrainStateMapFactory).FullName))) { factoryType = type; break; } } } if (null == factoryType) throw new ArgumentException(string.Format("Could not locate a state map factory type {0}", factoryTypeName)); var factory = (IGrainStateMapFactory)Activator.CreateInstance(factoryType); var grainStateMap = factory.CreateGrainStateMap(); _dataManager = new SqlDataManager(providerRuntime.GetLogger("SqlDataManager"), grainStateMap, ConnectionString, shardCredentials, mapName); return TaskDone.Done; }
public async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { Name = name; logger = providerRuntime.GetLogger("SqlStatisticsPublisher"); string adoInvariant = AdoNetInvariants.InvariantNameSqlServer; if (config.Properties.ContainsKey("AdoInvariant")) adoInvariant = config.Properties["AdoInvariant"]; database = RelationalStorageUtilities.CreateGenericStorageInstance(adoInvariant, config.Properties["ConnectionString"]); queryConstants = await database.InitializeOrleansQueriesAsync(); }
public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { Log = providerRuntime.GetLogger(this.GetType().FullName); ConnectString = config.Properties["DataConnectionString"]; if (config.Properties.ContainsKey("Table")) { Table = config.Properties["Table"]; CustomTable = true; } return TaskDone.Done; }
/// <summary> /// Initializes publisher /// </summary> /// <param name="name">Provider name</param> /// <param name="providerRuntime">Provider runtime API</param> /// <param name="config">Provider configuration</param> /// <returns></returns> public async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { Name = name; logger = providerRuntime.GetLogger("SqlStatisticsPublisher"); string adoInvariant = AdoNetInvariants.InvariantNameSqlServer; if (config.Properties.ContainsKey("AdoInvariant")) { adoInvariant = config.Properties["AdoInvariant"]; } orleansQueries = await RelationalOrleansQueries.CreateInstance(adoInvariant, config.Properties["ConnectionString"]); }
/// <summary> Initialization function for this storage provider. </summary> /// <see cref="IProvider.Init"/> public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { Name = name; serviceId = providerRuntime.ServiceId.ToString(); if (config.Properties.ContainsKey(TABLE_NAME_PROPERTY_NAME)) { tableName = config.Properties[TABLE_NAME_PROPERTY_NAME]; } isDeleteStateOnClear = config.Properties.ContainsKey(DELETE_ON_CLEAR_PROPERTY_NAME) && "true".Equals(config.Properties[DELETE_ON_CLEAR_PROPERTY_NAME], StringComparison.OrdinalIgnoreCase); Log = providerRuntime.GetLogger("Storage.AWSDynamoDBStorage." + id); var initMsg = string.Format("Init: Name={0} ServiceId={1} Table={2} DeleteStateOnClear={3}", Name, serviceId, tableName, isDeleteStateOnClear); if (config.Properties.ContainsKey(USE_JSON_FORMAT_PROPERTY_NAME)) { useJsonFormat = "true".Equals(config.Properties[USE_JSON_FORMAT_PROPERTY_NAME], StringComparison.OrdinalIgnoreCase); } this.jsonSettings = SerializationManager.UpdateSerializerSettings(SerializationManager.GetDefaultJsonSerializerSettings(), config); initMsg = string.Format("{0} UseJsonFormat={1}", initMsg, useJsonFormat); Log.Info(ErrorCode.StorageProviderBase, "AWS DynamoDB Provider: {0}", initMsg); storage = new DynamoDBStorage(config.Properties[DATA_CONNECTION_STRING_PROPERTY_NAME], Log); return(storage.InitializeTable(tableName, new List <KeySchemaElement> { new KeySchemaElement { AttributeName = GRAIN_REFERENCE_PROPERTY_NAME, KeyType = KeyType.HASH }, new KeySchemaElement { AttributeName = GRAIN_TYPE_PROPERTY_NAME, KeyType = KeyType.RANGE } }, new List <AttributeDefinition> { new AttributeDefinition { AttributeName = GRAIN_REFERENCE_PROPERTY_NAME, AttributeType = ScalarAttributeType.S }, new AttributeDefinition { AttributeName = GRAIN_TYPE_PROPERTY_NAME, AttributeType = ScalarAttributeType.S } })); }
/// <summary> Initialization function for this storage provider. </summary> /// <see cref="IProvider#Init"/> public async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { Name = name; serviceId = providerRuntime.ServiceId.ToString(); this.serializationManager = providerRuntime.ServiceProvider.GetRequiredService <SerializationManager>(); if (!config.Properties.ContainsKey(REDIS_CONNECTION_STRING) || string.IsNullOrWhiteSpace(config.Properties[REDIS_CONNECTION_STRING])) { throw new ArgumentException("RedisConnectionString is not set."); } var connectionString = config.Properties[REDIS_CONNECTION_STRING]; connectionMultiplexer = await ConnectionMultiplexer.ConnectAsync(connectionString); if (!config.Properties.ContainsKey(REDIS_DATABASE_NUMBER) || string.IsNullOrWhiteSpace(config.Properties[REDIS_DATABASE_NUMBER])) { //do not throw an ArgumentException but use the default database redisDatabase = connectionMultiplexer.GetDatabase(); } else { var databaseNumber = Convert.ToInt16(config.Properties[REDIS_DATABASE_NUMBER]); redisDatabase = connectionMultiplexer.GetDatabase(databaseNumber); } //initialize to use the default of JSON storage (this is to provide backwards compatiblity with previous version useJsonFormat = true; if (config.Properties.ContainsKey(USE_JSON_FORMAT_PROPERTY)) { useJsonFormat = "true".Equals(config.Properties[USE_JSON_FORMAT_PROPERTY], StringComparison.OrdinalIgnoreCase); } jsonSettings = new Newtonsoft.Json.JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All, PreserveReferencesHandling = PreserveReferencesHandling.Objects, DateFormatHandling = DateFormatHandling.IsoDateFormat, DefaultValueHandling = DefaultValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor, }; Log = providerRuntime.GetLogger("StorageProvider.RedisStorage." + serviceId); }
public async override Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { Log = providerRuntime.GetLogger(this.GetType().FullName); Log.Info(0, "Init ErrorInjection={0}", ErrorInjection); try { SetErrorInjection(ErrorInjectionPoint.None); await base.Init(name, providerRuntime, config); } catch (Exception exc) { Log.Error(0, "Unexpected error during Init", exc); throw; } }
public async override Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { Log = providerRuntime.GetLogger(this.GetType().FullName); Log.Info(0, "Init ErrorInjection={0}", ErrorInjection); try { SetErrorInjection(ErrorInjectionPoint.None); await base.Init(name, providerRuntime, config); } catch (Exception exc) { Log.Error(0, "Unexpected error during Init", exc); throw; } }
public async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { Name = name; logger = providerRuntime.GetLogger("SqlStatisticsPublisher"); string adoInvariant = AdoNetInvariants.InvariantNameSqlServer; if (config.Properties.ContainsKey("AdoInvariant")) { adoInvariant = config.Properties["AdoInvariant"]; } database = RelationalStorageUtilities.CreateGenericStorageInstance(adoInvariant, config.Properties["ConnectionString"]); queryConstants = await database.InitializeOrleansQueriesAsync(); }
public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { Name = name; Log = providerRuntime.GetLogger(GetType().Name); string Url = config.Properties["Url"]; string DefaultDatabase = config.Properties["DefaultDatabase"]; if (string.IsNullOrEmpty(Url)) { this.Log.Info("Starting RavenDB Storage Provider InMemory"); return this.InMemoryMode(); } return this.ServerMode(Url, DefaultDatabase); }
/// <summary> Initialization function for this storage provider. </summary> /// <see cref="IProvider#Init"/> public async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { Name = name; serviceId = providerRuntime.ServiceId.ToString(); if (!config.Properties.ContainsKey(CONNECTION_STRING) || string.IsNullOrWhiteSpace(config.Properties[CONNECTION_STRING])) { throw new ArgumentException("Specify a value for:", CONNECTION_STRING); } var connectionString = config.Properties[CONNECTION_STRING]; sqlconnBuilder = new SqlConnectionStringBuilder(connectionString); //a validation of the connection would be wise to perform here //await new SqlConnection(sqlconnBuilder.ConnectionString).OpenAsync(); //initialize to use the default of JSON storage (this is to provide backwards compatiblity with previous version useJsonOrBinaryFormat = StorageFormatEnum.Binary; if (config.Properties.ContainsKey(USE_JSON_FORMAT_PROPERTY)) { if ("true".Equals(config.Properties[USE_JSON_FORMAT_PROPERTY], StringComparison.OrdinalIgnoreCase)) { useJsonOrBinaryFormat = StorageFormatEnum.Json; } if ("both".Equals(config.Properties[USE_JSON_FORMAT_PROPERTY], StringComparison.OrdinalIgnoreCase)) { useJsonOrBinaryFormat = StorageFormatEnum.Both; } } jsonSettings = new Newtonsoft.Json.JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All, PreserveReferencesHandling = PreserveReferencesHandling.Objects, DateFormatHandling = DateFormatHandling.IsoDateFormat, DefaultValueHandling = DefaultValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor }; Log = providerRuntime.GetLogger("StorageProvider.SimpleSQLServerStorage." + serviceId); }
public virtual Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { this.Name = name; string loggerName = string.Format("Storage.{0}-{1}", this.GetType().Name, _id); Log = providerRuntime.GetLogger(loggerName); Log.Info(0, "Init Name={0} Config={1}", name, config); this.serializationManager = providerRuntime.ServiceProvider.GetRequiredService <SerializationManager>(); Interlocked.Increment(ref initCount); //blocked by port HierarchicalKeyStore to coreclr StateStore = new HierarchicalKeyStore(numKeys); Log.Info(0, "Finished Init Name={0} Config={1}", name, config); return(TaskDone.Done); }
/// <summary> Initialization function for this storage provider. </summary> /// <see cref="IProvider#Init"/> public async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { serviceId = providerRuntime.ServiceId.ToString(); Log = providerRuntime.GetLogger("StorageProvider.SimpleSQLServerStorage." + serviceId); try { Name = name; this.jsonSettings = SerializationManager.UpdateSerializerSettings(SerializationManager.GetDefaultJsonSerializerSettings(), config); if (!config.Properties.ContainsKey(CONNECTION_STRING) || string.IsNullOrWhiteSpace(config.Properties[CONNECTION_STRING])) { throw new BadProviderConfigException($"Specify a value for: {CONNECTION_STRING}"); } var connectionString = config.Properties[CONNECTION_STRING]; sqlconnBuilder = new SqlConnectionStringBuilder(connectionString); //a validation of the connection would be wise to perform here var sqlCon = new SqlConnection(sqlconnBuilder.ConnectionString); await sqlCon.OpenAsync(); sqlCon.Close(); //initialize to use the default of JSON storage (this is to provide backwards compatiblity with previous version useJsonOrBinaryFormat = StorageFormatEnum.Binary; if (config.Properties.ContainsKey(USE_JSON_FORMAT_PROPERTY)) { if ("true".Equals(config.Properties[USE_JSON_FORMAT_PROPERTY], StringComparison.OrdinalIgnoreCase)) { useJsonOrBinaryFormat = StorageFormatEnum.Json; } if ("both".Equals(config.Properties[USE_JSON_FORMAT_PROPERTY], StringComparison.OrdinalIgnoreCase)) { useJsonOrBinaryFormat = StorageFormatEnum.Both; } } } catch (Exception ex) { Log.Error((int)SimpleSQLServerProviderErrorCodes.SimpleSQLServerProvider_InitProvider, ex.ToString(), ex); throw; } }
/// <summary> /// Initializes the storage provider. /// </summary> /// <param name="name">The name of this provider instance.</param> /// <param name="providerRuntime">A Orleans runtime object managing all storage providers.</param> /// <param name="config">Configuration info for this provider instance.</param> /// <returns>Completion promise for this operation.</returns> public async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { this.Name = name; this.ConfigSectionName = config.Properties["ConfigSectionName"]; string useGuidAsStorageKeyString; config.Properties.TryGetValue("UseGuidAsStorageKey", out useGuidAsStorageKeyString); var useGuidAsStorageKey = true;//default is true if (!string.IsNullOrWhiteSpace(useGuidAsStorageKeyString)) Boolean.TryParse(useGuidAsStorageKeyString, out useGuidAsStorageKey); this.UseGuidAsStorageKey = useGuidAsStorageKey; if (string.IsNullOrWhiteSpace(ConfigSectionName)) throw new ArgumentException("ConfigSectionName property not set"); var configSection = ReadConfig(ConfigSectionName); DataManager = await GrainStateCouchbaseDataManager.Initialize(configSection); Log = providerRuntime.GetLogger(this.GetType().FullName); }
public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { Dashboard.OrleansTS = TaskScheduler.Current; Dashboard.ProviderRuntime = providerRuntime; this.logger = providerRuntime.GetLogger("Dashboard"); var port = config.Properties.ContainsKey("port") ? int.Parse(config.Properties["port"]) : 8080; var url = $"http://localhost:{port}"; this.host = new NancyHost(new Uri(url)); this.host.Start(); this.logger.Verbose($"Dashboard listening on {url}"); var dashboardGrain = providerRuntime.GrainFactory.GetGrain<IDashboardGrain>(0); return dashboardGrain.Init(); }
public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { Dashboard.OrleansTS = TaskScheduler.Current; Dashboard.ProviderRuntime = providerRuntime; this.logger = providerRuntime.GetLogger("Dashboard"); var port = config.Properties.ContainsKey("port") ? int.Parse(config.Properties["port"]) : 8080; var url = $"http://localhost:{port}"; this.host = new NancyHost(new Uri(url)); this.host.Start(); this.logger.Verbose($"Dashboard listening on {url}"); var dashboardGrain = providerRuntime.GrainFactory.GetGrain <IDashboardGrain>(0); return(dashboardGrain.Init()); }
public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { foreach (var server in new[] { "one", "two", "three" }) { providerRuntime.GrainFactory.GetGrain<ITestRaftGrain>(server).AddValue(null); } #if false Task.Factory.StartNew( async () => { var num = 0; var log = providerRuntime.GetLogger("Bootstrap"); var leader = "one"; var grain = providerRuntime.GrainFactory.GetGrain<ITestRaftGrain>(leader); grain.AddValue(null).Ignore(); await Task.Delay(TimeSpan.FromSeconds(4)); while (true) { try { grain = providerRuntime.GrainFactory.GetGrain<ITestRaftGrain>(leader); log.Info("Trying to replicate a log entry..."); await grain.AddValue($"please agree {num}"); num++; await Task.Delay(TimeSpan.FromSeconds(2)); } catch (NotLeaderException exception) { leader = exception.Leader; log.Warn(-1, $"Exception replicating value: {exception}, leader is {leader}"); await Task.Delay(TimeSpan.FromSeconds(4)); } catch (Exception exception) { log.Info(-1, $"Exception replicating value: {exception}"); await Task.Delay(TimeSpan.FromSeconds(4)); } } }); #endif return Task.FromResult(0); }
/// <summary> Initialization function for this storage provider. </summary> /// <see cref="IProvider.Init"/> public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { Name = name; serviceId = providerRuntime.ServiceId.ToString(); if (!config.Properties.ContainsKey(DATA_CONNECTION_STRING) || string.IsNullOrWhiteSpace(config.Properties[DATA_CONNECTION_STRING])) { throw new ArgumentException("DataConnectionString property not set"); } dataConnectionString = config.Properties["DataConnectionString"]; if (config.Properties.ContainsKey(TABLE_NAME_PROPERTY)) { tableName = config.Properties[TABLE_NAME_PROPERTY]; } isDeleteStateOnClear = config.Properties.ContainsKey(DELETE_ON_CLEAR_PROPERTY) && "true".Equals(config.Properties[DELETE_ON_CLEAR_PROPERTY], StringComparison.OrdinalIgnoreCase); Log = providerRuntime.GetLogger("Storage.AzureTableStorage." + id); var initMsg = string.Format("Init: Name={0} ServiceId={1} Table={2} DeleteStateOnClear={3}", Name, serviceId, tableName, isDeleteStateOnClear); if (config.Properties.ContainsKey(USE_JSON_FORMAT_PROPERTY)) { useJsonFormat = "true".Equals(config.Properties[USE_JSON_FORMAT_PROPERTY], StringComparison.OrdinalIgnoreCase); } if (useJsonFormat) { jsonSettings = new Newtonsoft.Json.JsonSerializerSettings(); jsonSettings.TypeNameHandling = Newtonsoft.Json.TypeNameHandling.All; } initMsg = String.Format("{0} UseJsonFormat={1}", initMsg, useJsonFormat); Log.Info((int)AzureProviderErrorCode.AzureTableProvider_InitProvider, initMsg); Log.Info((int)AzureProviderErrorCode.AzureTableProvider_ParamConnectionString, "AzureTableStorage Provider is using DataConnectionString: {0}", ConfigUtilities.PrintDataConnectionInfo(dataConnectionString)); tableDataManager = new GrainStateTableDataManager(tableName, dataConnectionString, Log); return(tableDataManager.InitTableAsync()); }
public async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { this.logger = providerRuntime.GetLogger("Dashboard"); var dashboardTraceListener = new DashboardTraceListener(); var router = new Router(); new DashboardController(router, TaskScheduler.Current, providerRuntime, dashboardTraceListener); var options = new StartOptions { ServerFactory = "Nowin", Port = config.Properties.ContainsKey("Port") ? int.Parse(config.Properties["Port"]) : 8080, }; var username = config.Properties.ContainsKey("Username") ? config.Properties["Username"] : null; var password = config.Properties.ContainsKey("Password") ? config.Properties["Password"] : null; try { host = WebApp.Start(options, app => new WebServer(router, username, password).Configuration(app)); Trace.Listeners.Remove("HostingTraceListener"); } catch (Exception ex) { this.logger.Error(10001, ex.ToString()); } this.logger.Verbose($"Dashboard listening on {options.Port}"); this.profiler = new GrainProfiler(TaskScheduler.Current, providerRuntime); var dashboardGrain = providerRuntime.GrainFactory.GetGrain <IDashboardGrain>(0); await dashboardGrain.Init(); var siloGrain = providerRuntime.GrainFactory.GetGrain <ISiloGrain>(providerRuntime.ToSiloAddress()); await siloGrain.SetOrleansVersion(typeof(SiloAddress).Assembly.GetName().Version.ToString()); Trace.Listeners.Add(dashboardTraceListener); }
public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { foreach (var server in new[] { "one", "two", "three" }) { providerRuntime.GrainFactory.GetGrain <ITestRaftGrain>(server).AddValue(null); } #if false Task.Factory.StartNew( async() => { var num = 0; var log = providerRuntime.GetLogger("Bootstrap"); var leader = "one"; var grain = providerRuntime.GrainFactory.GetGrain <ITestRaftGrain>(leader); grain.AddValue(null).Ignore(); await Task.Delay(TimeSpan.FromSeconds(4)); while (true) { try { grain = providerRuntime.GrainFactory.GetGrain <ITestRaftGrain>(leader); log.Info("Trying to replicate a log entry..."); await grain.AddValue($"please agree {num}"); num++; await Task.Delay(TimeSpan.FromSeconds(2)); } catch (NotLeaderException exception) { leader = exception.Leader; log.Warn(-1, $"Exception replicating value: {exception}, leader is {leader}"); await Task.Delay(TimeSpan.FromSeconds(4)); } catch (Exception exception) { log.Info(-1, $"Exception replicating value: {exception}"); await Task.Delay(TimeSpan.FromSeconds(4)); } } }); #endif return(Task.FromResult(0)); }
/// <summary> Initialization function for this storage provider. </summary> /// <see cref="IProvider.Init"/> public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { Name = name; serviceId = providerRuntime.ServiceId.ToString(); this.serializationManager = providerRuntime.ServiceProvider.GetRequiredService <SerializationManager>(); if (!config.Properties.ContainsKey(DataConnectionStringPropertyName) || string.IsNullOrWhiteSpace(config.Properties[DataConnectionStringPropertyName])) { throw new ArgumentException("DataConnectionString property not set"); } dataConnectionString = config.Properties["DataConnectionString"]; if (config.Properties.ContainsKey(TableNamePropertyName)) { tableName = config.Properties[TableNamePropertyName]; } isDeleteStateOnClear = config.Properties.ContainsKey(DeleteOnClearPropertyName) && "true".Equals(config.Properties[DeleteOnClearPropertyName], StringComparison.OrdinalIgnoreCase); Log = providerRuntime.GetLogger("Storage.AzureTableStorage." + id); var initMsg = string.Format("Init: Name={0} ServiceId={1} Table={2} DeleteStateOnClear={3}", Name, serviceId, tableName, isDeleteStateOnClear); if (config.Properties.ContainsKey(UseJsonFormatPropertyName)) { useJsonFormat = "true".Equals(config.Properties[UseJsonFormatPropertyName], StringComparison.OrdinalIgnoreCase); } var grainFactory = providerRuntime.ServiceProvider.GetRequiredService <IGrainFactory>(); this.jsonSettings = OrleansJsonSerializer.UpdateSerializerSettings(OrleansJsonSerializer.GetDefaultSerializerSettings(this.serializationManager, grainFactory), config); initMsg = String.Format("{0} UseJsonFormat={1}", initMsg, useJsonFormat); Log.Info((int)AzureProviderErrorCode.AzureTableProvider_InitProvider, initMsg); Log.Info((int)AzureProviderErrorCode.AzureTableProvider_ParamConnectionString, "AzureTableStorage Provider is using DataConnectionString: {0}", ConfigUtilities.PrintDataConnectionInfo(dataConnectionString)); tableDataManager = new GrainStateTableDataManager(tableName, dataConnectionString, Log); return(tableDataManager.InitTableAsync()); }
/// <summary> Initialization function for this storage provider. </summary> /// <see cref="IProvider#Init"/> public async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { serviceId = providerRuntime.ServiceId.ToString(); Log = providerRuntime.GetLogger("StorageProvider.SimpleSQLServerStorage." + serviceId); try { Name = name; this.jsonSettings = OrleansJsonSerializer.UpdateSerializerSettings(OrleansJsonSerializer.GetDefaultSerializerSettings(), config); if (!config.Properties.ContainsKey(CONNECTION_STRING) || string.IsNullOrWhiteSpace(config.Properties[CONNECTION_STRING])) { throw new BadProviderConfigException($"Specify a value for: {CONNECTION_STRING}"); } var connectionString = config.Properties[CONNECTION_STRING]; sqlconnBuilder = new SqlConnectionStringBuilder(connectionString); //a validation of the connection would be wise to perform here var sqlCon = new SqlConnection(sqlconnBuilder.ConnectionString); await sqlCon.OpenAsync(); sqlCon.Close(); //initialize to use the default of JSON storage (this is to provide backwards compatiblity with previous version useJsonOrBinaryFormat = StorageFormatEnum.Binary; if (config.Properties.ContainsKey(USE_JSON_FORMAT_PROPERTY)) { if ("true".Equals(config.Properties[USE_JSON_FORMAT_PROPERTY], StringComparison.OrdinalIgnoreCase)) useJsonOrBinaryFormat = StorageFormatEnum.Json; if ("both".Equals(config.Properties[USE_JSON_FORMAT_PROPERTY], StringComparison.OrdinalIgnoreCase)) useJsonOrBinaryFormat = StorageFormatEnum.Both; } } catch (Exception ex) { Log.Error((int) SimpleSQLServerProviderErrorCodes.SimpleSQLServerProvider_InitProvider, ex.ToString(), ex); throw; } }
public MetricsTrackerTelemetryConsumer(IProviderRuntime runtime, TaskScheduler taskScheduler) { try { Runtime = runtime; TaskScheduler = taskScheduler; logger = Runtime.GetLogger(nameof(MetricsTrackerTelemetryConsumer)); Configuration = new MetricsConfiguration(); Counters = new ConcurrentDictionary <string, long>(); CounterHistory = new ConcurrentDictionary <string, ConcurrentQueue <long> >(); Metrics = new ConcurrentDictionary <string, double>(); MetricHistory = new ConcurrentDictionary <string, ConcurrentQueue <double> >(); TimeSpanMetrics = new ConcurrentDictionary <string, TimeSpan>(); TimeSpanMetricHistory = new ConcurrentDictionary <string, ConcurrentQueue <TimeSpan> >(); Requests = new ConcurrentDictionary <string, MeasuredRequest>(); RequestHistory = new ConcurrentDictionary <string, ConcurrentQueue <MeasuredRequest> >(); PreviousInterceptor = Runtime.GetInvokeInterceptor(); // start a message pump to give ourselves the right synchronization context // from which we can communicate with grains via normal grain references // TODO: don't start the pump until it's been requested //StartMessagePump().Ignore(); //Task.Factory.StartNew(() => StartMessagePump(), CancellationToken.None, TaskCreationOptions.None, TaskScheduler); var dispatchTask = Dispatch(() => StartMessagePump()); Management = Runtime.GrainFactory.GetGrain <IManagementGrain>(0); } catch (Exception ex) { logger.TrackException(ex); throw; } }
public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { this.g_Logger = providerRuntime.GetLogger(name); this.Name = name; var m_StartOptions = new StartOptions { ServerFactory = "Nowin", Port = config.Properties.ContainsKey("Port") ? int.Parse(config.Properties["Port"]) : 9186, }; #region 生成Swagger文档 GenerationDocProvider.CreationAssemblyMethodCache("Orleans.UniteExtension.Framework.Interfaces.dll"); GenerationDocProvider.GenerationDocument(string.Empty); #endregion this.OwinHost = WebApp.Start(m_StartOptions, app => new OwinServiceStartup(null).Configure(app)); return(Task.CompletedTask); }
public virtual Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { this.Name = name; string loggerName = string.Format("Storage.{0}-{1}", this.GetType().Name, _id); Log = providerRuntime.GetLogger(loggerName); Log.Info(0, "Init Name={0} Config={1}", name, config); Interlocked.Increment(ref initCount); if (LocalDataStoreInstance.LocalDataStore != null) { // Attached to shared local key store StateStore = LocalDataStoreInstance.LocalDataStore; } else { StateStore = new HierarchicalKeyStore(numKeys); } Log.Info(0, "Finished Init Name={0} Config={1}", name, config); return TaskDone.Done; }
public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { Log = providerRuntime.GetLogger(GetType().FullName); Name = name; if (!config.Properties.ContainsKey(DATA_CONNECTION_STRING) || !config.Properties.ContainsKey(DATABASE_NAME_PROPERTY)) { throw new ArgumentException("ConnectionString Or Database property not set"); } ConnectionString = config.Properties[DATA_CONNECTION_STRING]; Database = config.Properties[DATABASE_NAME_PROPERTY]; UseGuidAsStorageKey = !config.Properties.ContainsKey(USE_GUID_AS_STORAGE_KEY) || "true".Equals(config.Properties[USE_GUID_AS_STORAGE_KEY], StringComparison.OrdinalIgnoreCase); DataManager = new GrainStateMongoDataManager(Database, ConnectionString); return(TaskDone.Done); }
/// <summary> Initialization function for this storage provider. </summary> /// <see cref="IProvider#Init"/> public virtual Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { Name = name; Log = providerRuntime.GetLogger(GetLoggerName()); string numStorageGrainsStr; if (config.Properties.TryGetValue(NUM_STORAGE_GRAINS, out numStorageGrainsStr)) { numStorageGrains = Int32.Parse(numStorageGrainsStr); } Log.Info("Init: Name={0} NumStorageGrains={1}", Name, numStorageGrains); storageGrains = new Lazy <IMemoryStorageGrain> [numStorageGrains]; for (int i = 0; i < numStorageGrains; i++) { int idx = i; // Capture variable to avoid modified closure error storageGrains[idx] = new Lazy <IMemoryStorageGrain>(() => providerRuntime.GrainFactory.GetGrain <IMemoryStorageGrain>(idx)); } return(TaskDone.Done); }
/// <summary> Initialization function for this storage provider. </summary> /// <see cref="IProvider.Init"/> public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { Name = name; serviceId = providerRuntime.ServiceId.ToString(); if (config.Properties.ContainsKey(TABLE_NAME_PROPERTY_NAME)) tableName = config.Properties[TABLE_NAME_PROPERTY_NAME]; isDeleteStateOnClear = config.Properties.ContainsKey(DELETE_ON_CLEAR_PROPERTY_NAME) && "true".Equals(config.Properties[DELETE_ON_CLEAR_PROPERTY_NAME], StringComparison.OrdinalIgnoreCase); Log = providerRuntime.GetLogger("Storage.AWSDynamoDBStorage." + id); var initMsg = string.Format("Init: Name={0} ServiceId={1} Table={2} DeleteStateOnClear={3}", Name, serviceId, tableName, isDeleteStateOnClear); if (config.Properties.ContainsKey(USE_JSON_FORMAT_PROPERTY_NAME)) useJsonFormat = "true".Equals(config.Properties[USE_JSON_FORMAT_PROPERTY_NAME], StringComparison.OrdinalIgnoreCase); this.jsonSettings = SerializationManager.UpdateSerializerSettings(SerializationManager.GetDefaultJsonSerializerSettings(), config); initMsg = string.Format("{0} UseJsonFormat={1}", initMsg, useJsonFormat); Log.Info(ErrorCode.StorageProviderBase, "AWS DynamoDB Provider: {0}", initMsg); storage = new DynamoDBStorage(config.Properties[DATA_CONNECTION_STRING_PROPERTY_NAME], Log); return storage.InitializeTable(tableName, new List<KeySchemaElement> { new KeySchemaElement { AttributeName = GRAIN_REFERENCE_PROPERTY_NAME, KeyType = KeyType.HASH }, new KeySchemaElement { AttributeName = GRAIN_TYPE_PROPERTY_NAME, KeyType = KeyType.RANGE } }, new List<AttributeDefinition> { new AttributeDefinition { AttributeName = GRAIN_REFERENCE_PROPERTY_NAME, AttributeType = ScalarAttributeType.S }, new AttributeDefinition { AttributeName = GRAIN_TYPE_PROPERTY_NAME, AttributeType = ScalarAttributeType.S } }); }
public virtual Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { this.Name = name; string loggerName = string.Format("Storage.{0}-{1}", this.GetType().Name, _id); Log = providerRuntime.GetLogger(loggerName); Log.Info(0, "Init Name={0} Config={1}", name, config); Interlocked.Increment(ref initCount); if (LocalDataStoreInstance.LocalDataStore != null) { // Attached to shared local key store StateStore = LocalDataStoreInstance.LocalDataStore; } else { StateStore = new HierarchicalKeyStore(numKeys); } Log.Info(0, "Finished Init Name={0} Config={1}", name, config); return(TaskDone.Done); }
/// <summary> /// Initializes the storage provider. /// </summary> /// <param name="name">The name of this provider instance.</param> /// <param name="providerRuntime">A Orleans runtime object managing all storage providers.</param> /// <param name="config">Configuration info for this provider instance.</param> /// <returns>Completion promise for this operation.</returns> public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { Log = providerRuntime.GetLogger(this.GetType().FullName); this.Name = name; if (!config.Properties.ContainsKey(DATA_CONNECTION_STRING) || !config.Properties.ContainsKey(DATABASE_NAME_PROPERTY)) { throw new ArgumentException("ConnectionString Or Database property not set"); } this.ConnectionString = config.Properties[DATA_CONNECTION_STRING]; this.Database = config.Properties[DATABASE_NAME_PROPERTY]; this.UseGuidAsStorageKey = !config.Properties.ContainsKey(USE_GUID_AS_STORAGE_KEY) || "true".Equals(config.Properties[USE_GUID_AS_STORAGE_KEY], StringComparison.OrdinalIgnoreCase); DataManager = new GrainStateMongoDataManager(Database, ConnectionString); return TaskDone.Done; }
public async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { _name = name; var logger = providerRuntime.GetLogger("OrleansLog"); const int InfoCode = 1000; const int ErrorCode = 1002; foreach (var subProvider in _subProviders) { var subProviderName = subProvider.Name; subProviderName = subProviderName ?? string.Format("subProvider-{0}_{1}", _name, Guid.NewGuid()); logger.Info(InfoCode, "Info", string.Format("subProviderName is {0}", subProviderName), null, null); try { await subProvider.Init(subProviderName, providerRuntime, config); } catch (Exception e) { logger.Error(ErrorCode, string.Format("Failed to call Init method of provider - {0}, exception: ", subProviderName), null); throw; } } }
public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { this.logger = providerRuntime.GetLogger(name); this.Name = name; var router = new Router(); new GrainController(router, TaskScheduler.Current, providerRuntime); var options = new StartOptions { ServerFactory = "Nowin", Port = config.Properties.ContainsKey("Port") ? int.Parse(config.Properties["Port"]) : 8080, }; var username = config.Properties.ContainsKey("Username") ? config.Properties["Username"] : null; var password = config.Properties.ContainsKey("Password") ? config.Properties["Password"] : null; host = WebApp.Start(options, app => new WebServer(router, username, password).Configure(app)); this.logger.Verbose($"HTTP API listening on {options.Port}"); return Task.FromResult(0); }
public async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { this.Log = providerRuntime.GetLogger(nameof(ArangoStorageProvider)); this.Name = name; var databaseName = config.GetProperty("DatabaseName", "Orleans"); var url = config.GetProperty("Url", "http://localhost:8529"); var username = config.GetProperty("Username", "root"); var password = config.GetProperty("Password", "password"); waitForSync = config.GetBoolProperty("WaitForSync", true); var grainRefConverter = new GrainReferenceConverter(); settings = new JsonSerializer(); settings.DefaultValueHandling = DefaultValueHandling.Include; settings.MissingMemberHandling = MissingMemberHandling.Ignore; settings.ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor; settings.Converters.Add(grainRefConverter); if (!isInitialized) { ArangoDatabase.ChangeSetting(s => { s.Database = databaseName; s.Url = url; s.Credential = new NetworkCredential(username, password); s.DisableChangeTracking = true; s.WaitForSync = waitForSync; s.Serialization.Converters.Add(grainRefConverter); }); isInitialized = true; } Database = new ArangoDatabase(); collectionsList = await Database.ListCollectionsAsync(); }
public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { this.logger = providerRuntime.GetLogger(name); this.Name = name; var router = new Router(); new GrainController(router, TaskScheduler.Current, providerRuntime); var options = new StartOptions { ServerFactory = "Nowin", Port = config.Properties.ContainsKey("Port") ? int.Parse(config.Properties["Port"]) : 8080, }; var username = config.Properties.ContainsKey("Username") ? config.Properties["Username"] : null; var password = config.Properties.ContainsKey("Password") ? config.Properties["Password"] : null; host = WebApp.Start(options, app => new WebServer(router, username, password).Configure(app)); this.logger.Verbose($"HTTP API listening on {options.Port}"); return(Task.FromResult(0)); }
public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { Name = name; this.logger = providerRuntime.GetLogger("MockStatsSiloCollector"); this.grain = providerRuntime.GrainFactory.GetGrain<IStatsCollectorGrain>(0); this.taskScheduler = Silo.CurrentSilo.LocalScheduler; this.schedulingContext = Silo.CurrentSilo.testHook.SchedulingContext; logger.Info("{0} Init called", GetType().Name); return TaskDone.Done; }
public async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { Name = name; Log = providerRuntime.GetLogger(nameof(RedisStorageProvider)); if (config.Properties == null) { throw new ArgumentException("No configuration given"); } if (!config.Properties.TryGetValue("DataConnectionString", out _connectionString)) { throw new ArgumentException("DataConnectionString must be configured for RedisStorageProvider"); } else if (string.IsNullOrWhiteSpace(_connectionString)) { throw new ArgumentException("DataConnectionString was null or whitespace for RedisStorageProvider"); } var serverAndPort = _connectionString.Split(':'); if (serverAndPort.Length == 1) { _host = serverAndPort[0]; _port = 6379; } else if (serverAndPort.Length == 2) { _host = serverAndPort[0]; if (!int.TryParse(serverAndPort[1], out _port)) { throw new ArgumentException($"Couldn't parse port from DataConnectionString: {_connectionString}"); } } if (!config.Properties.TryGetValue("Serializer", out _serializer)) { _serializer = Serializers.Json; } else if (!Serializers.IsValid(_serializer)) { throw new ArgumentException($"Serializer from configuration not valid: {_serializer}"); } if (config.Properties.TryGetValue("DatabaseNumber", out var dbNumber)) { if (!int.TryParse(dbNumber, out _dbNumber)) { throw new ArgumentException($"DatabaseNumber has illegal value in configuration: {dbNumber}"); } } try { var connCfg = new ConfigurationOptions { EndPoints = { { _host, _port }, }, CommandMap = CommandMap.Create(new HashSet <string> { // EXCLUDE commands not supported by YugaByte "SUBSCRIBE", "CLUSTER", "PING", "TIME" }, available: false) }; var diConn = providerRuntime.ServiceProvider.GetService(typeof(IConnectionMultiplexer)) as IConnectionMultiplexer; _connection = diConn ?? await ConnectionMultiplexer.ConnectAsync(connCfg); _db = _connection.GetDatabase(_dbNumber); } catch (RedisConnectionException ex) { throw new Exception($"Could not connect to Redis at: {_connectionString}", ex); } }
/// <summary> /// Initializes the storage provider. /// </summary> /// <param name="name">The name of this provider instance.</param> /// <param name="providerRuntime">A Orleans runtime object managing all storage providers.</param> /// <param name="config">Configuration info for this provider instance.</param> /// <returns>Completion promise for this operation.</returns> public virtual Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { Log = providerRuntime.GetLogger(this.GetType().FullName); return TaskDone.Done; }
/// <summary> Initialization function for this storage provider. </summary> /// <see cref="IProvider.Init"/> public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { Name = name; serviceId = providerRuntime.ServiceId.ToString(); if (!config.Properties.ContainsKey(DATA_CONNECTION_STRING) || string.IsNullOrWhiteSpace(config.Properties[DATA_CONNECTION_STRING])) throw new ArgumentException("DataConnectionString property not set"); dataConnectionString = config.Properties["DataConnectionString"]; if (config.Properties.ContainsKey(TABLE_NAME_PROPERTY)) tableName = config.Properties[TABLE_NAME_PROPERTY]; isDeleteStateOnClear = config.Properties.ContainsKey(DELETE_ON_CLEAR_PROPERTY) && "true".Equals(config.Properties[DELETE_ON_CLEAR_PROPERTY], StringComparison.OrdinalIgnoreCase); Log = providerRuntime.GetLogger("Storage.AzureTableStorage." + id); var initMsg = string.Format("Init: Name={0} ServiceId={1} Table={2} DeleteStateOnClear={3}", Name, serviceId, tableName, isDeleteStateOnClear); if (config.Properties.ContainsKey(USE_JSON_FORMAT_PROPERTY)) useJsonFormat = "true".Equals(config.Properties[USE_JSON_FORMAT_PROPERTY], StringComparison.OrdinalIgnoreCase); if (useJsonFormat) { jsonSettings = new Newtonsoft.Json.JsonSerializerSettings(); jsonSettings.TypeNameHandling = Newtonsoft.Json.TypeNameHandling.All; } initMsg = String.Format("{0} UseJsonFormat={1}", initMsg, useJsonFormat); Log.Info((int)AzureProviderErrorCode.AzureTableProvider_InitProvider, initMsg); Log.Info((int)AzureProviderErrorCode.AzureTableProvider_ParamConnectionString, "AzureTableStorage Provider is using DataConnectionString: {0}", ConfigUtilities.PrintDataConnectionInfo(dataConnectionString)); tableDataManager = new GrainStateTableDataManager(tableName, dataConnectionString, Log); return tableDataManager.InitTableAsync(); }
/// <summary> Initialization function for this storage provider. </summary> /// <see cref="IProvider.Init"/> public async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException("The parameter must contain characters", nameof(name)); } if (providerRuntime == null) { throw new ArgumentNullException(nameof(providerRuntime)); } if (config == null) { throw new ArgumentNullException(nameof(config)); } if (!config.Properties.ContainsKey(DataConnectionStringPropertyName)) { throw new BadProviderConfigException($"The {DataConnectionStringPropertyName} setting has not been configured. Add a {DataConnectionStringPropertyName} setting with a valid connection string."); } this.serializationManager = providerRuntime.ServiceProvider.GetRequiredService <SerializationManager>(); //NOTE: StorageSerializationPicker should be defined outside and given as a parameter in constructor or via Init in IProviderConfiguration perhaps. //Currently this limits one's options to much to the current situation of providing only one serializer for serialization and deserialization //with no regard to state update or serializer changes. Maybe have this serialized as a JSON in props and read via a key? StorageSerializationPicker = new DefaultRelationalStoragePicker(this.ConfigureDeserializers(config, providerRuntime), this.ConfigureSerializers(config, providerRuntime)); //NOTE: Currently there should be only one pair of providers given. That is, only UseJsonFormatPropertyName, UseXmlFormatPropertyName or UseBinaryFormatPropertyName. if (StorageSerializationPicker.Deserializers.Count > 1 || StorageSerializationPicker.Serializers.Count > 1) { throw new ArgumentException("Configuration error, only one serializer and deserializer should be given.", nameof(config)); } if (StorageSerializationPicker.Deserializers.Count == 0 || StorageSerializationPicker.Serializers.Count == 0) { StorageSerializationPicker.Deserializers.Add(new OrleansStorageDefaultBinaryDeserializer(this.serializationManager, UseBinaryFormatPropertyName)); StorageSerializationPicker.Serializers.Add(new OrleansStorageDefaultBinarySerializer(this.serializationManager, UseBinaryFormatPropertyName)); } var connectionInvariant = config.Properties.ContainsKey(DataConnectionInvariantPropertyName) ? config.Properties[DataConnectionInvariantPropertyName] : DefaultAdoInvariantInvariantPropertyName; Storage = RelationalStorage.CreateInstance(connectionInvariant, config.Properties[DataConnectionStringPropertyName]); ServiceId = providerRuntime.ServiceId.ToString(); var queries = await Storage.ReadAsync(DefaultInitializationQuery, command => { }, (selector, resultSetCount, token) => { return(Task.FromResult(Tuple.Create(selector.GetValue <string>("QueryKey"), selector.GetValue <string>("QueryText")))); }).ConfigureAwait(false); CurrentOperationalQueries = new RelationalStorageProviderQueries( queries.Single(i => i.Item1 == "WriteToStorageKey").Item2, queries.Single(i => i.Item1 == "ReadFromStorageKey").Item2, queries.Single(i => i.Item1 == "ClearStorageKey").Item2); Log = providerRuntime.GetLogger(GetType().FullName); Name = name; Log.Info((int)RelationalStorageProviderCodes.RelationalProviderInitProvider, $"Initialized storage provider: ServiceId={ServiceId} ProviderName={Name} Invariant={Storage.InvariantName} ConnectionString={Storage.ConnectionString}."); }
/// <summary> Initialization function for this storage provider. </summary> /// <see cref="IProvider#Init"/> public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { Name = name; // Provider #1 & #2 are required, #3 - #9 are optional if(config.Children.Count == 0) throw new ArgumentException("No provider is defined."); if(config.Children.Count == 1) throw new ArgumentException("At least two providers have to be listed."); Log = providerRuntime.GetLogger("Storage.ShardedStorageProvider." + id); var providers = new List<IStorageProvider>(); int index = 0; foreach( var provider in config.Children) { Log.Info((int)ProviderErrorCode.ShardedStorageProvider_ProviderName, "Provider {0} = {1}", index++, provider.Name); providers.Add((IStorageProvider)provider); } storageProviders = providers.ToArray(); // Storage providers will already have been initialized by the provider manager, so we don't need to orchestrate that return TaskDone.Done; }
public async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { this.Name = name; this.logger = providerRuntime.GetLogger("Dashboard"); this.dashboardTraceListener = new DashboardTraceListener(); var port = config.Properties.ContainsKey("Port") ? int.Parse(config.Properties["Port"]) : 8080; var hostname = config.Properties.ContainsKey("Host") ? config.Properties["Host"] : "*"; var username = config.Properties.ContainsKey("Username") ? config.Properties["Username"] : null; var password = config.Properties.ContainsKey("Password") ? config.Properties["Password"] : null; var credentials = new UserCredentials(username, password); try { var builder = new WebHostBuilder() .ConfigureServices(s => s .AddSingleton(TaskScheduler.Current) .AddSingleton(providerRuntime) .AddSingleton(dashboardTraceListener) ) .ConfigureServices(services => { services .AddMvcCore() .AddApplicationPart(typeof(DashboardController).Assembly) .AddJsonFormatters(); }) .Configure(app => { if (credentials.HasValue()) { // only when usename and password are configured // do we inject basicauth middleware in the pipeline app.UseMiddleware <BasicAuthMiddleware>(credentials); } app.UseMvc(); }) .UseKestrel() .UseUrls($"http://{hostname}:{port}"); host = builder.Build(); host.Start(); } catch (Exception ex) { this.logger.Error(10001, ex.ToString()); } this.logger.Verbose($"Dashboard listening on {port}"); this.profiler = new GrainProfiler(TaskScheduler.Current, providerRuntime); var dashboardGrain = providerRuntime.GrainFactory.GetGrain <IDashboardGrain>(0); await dashboardGrain.Init(); var siloGrain = providerRuntime.GrainFactory.GetGrain <ISiloGrain>(providerRuntime.ToSiloAddress()); await siloGrain.SetOrleansVersion(typeof(SiloAddress).Assembly.GetName().Version.ToString()); Trace.Listeners.Add(dashboardTraceListener); // horrible hack to grab the scheduler // to allow the stats publisher to push // counters to grains OrleansScheduler = TaskScheduler.Current; }
/// <summary> Initialization function for this storage provider. </summary> /// <see cref="IProvider.Init"/> public async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { if(string.IsNullOrWhiteSpace(name)) { throw new ArgumentException("The parameter must contain characters", nameof(name)); } if(providerRuntime == null) { throw new ArgumentNullException(nameof(providerRuntime)); } if(config == null) { throw new ArgumentNullException(nameof(config)); } if(!config.Properties.ContainsKey(DataConnectionStringPropertyName)) { throw new BadProviderConfigException($"The {DataConnectionStringPropertyName} setting has not been configured. Add a {DataConnectionStringPropertyName} setting with a valid connection string."); } //NOTE: StorageSerializationPicker should be defined outside and given as a parameter in constructor or via Init in IProviderConfiguration perhaps. //Currently this limits one's options to much to the current situation of providing only one serializer for serialization and deserialization //with no regard to state update or serializer changes. Maybe have this serialized as a JSON in props and read via a key? StorageSerializationPicker = new DefaultRelationalStoragePicker(ConfigureDeserializers(config), ConfigureSerializers(config)); //NOTE: Currently there should be only one pair of providers given. That is, only UseJsonFormatPropertyName, UseXmlFormatPropertyName or UseBinaryFormatPropertyName. if(StorageSerializationPicker.Deserializers.Count > 1 || StorageSerializationPicker.Serializers.Count > 1) { throw new ArgumentException("Configuration error, only one serializer and deserializer should be given.", nameof(config)); } if(StorageSerializationPicker.Deserializers.Count == 0 || StorageSerializationPicker.Serializers.Count == 0) { StorageSerializationPicker.Deserializers.Add(new OrleansStorageDefaultBinaryDeserializer(UseBinaryFormatPropertyName)); StorageSerializationPicker.Serializers.Add(new OrleansStorageDefaultBinarySerializer(UseBinaryFormatPropertyName)); } var connectionInvariant = config.Properties.ContainsKey(DataConnectionInvariantPropertyName) ? config.Properties[DataConnectionInvariantPropertyName] : DefaultAdoInvariantInvariantPropertyName; Storage = RelationalStorage.CreateInstance(connectionInvariant, config.Properties[DataConnectionStringPropertyName]); ServiceId = providerRuntime.ServiceId.ToString(); var queries = await Storage.ReadAsync(DefaultInitializationQuery, command => { }, (selector, resultSetCount, token) => { return Task.FromResult(Tuple.Create(selector.GetValue<string>("QueryKey"), selector.GetValue<string>("QueryText"))); }).ConfigureAwait(false); CurrentOperationalQueries = new RelationalStorageProviderQueries( queries.Single(i => i.Item1 == "WriteToStorageKey").Item2, queries.Single(i => i.Item1 == "ReadFromStorageKey").Item2, queries.Single(i => i.Item1 == "ClearStorageKey").Item2); Log = providerRuntime.GetLogger(GetType().FullName); Name = name; Log.Info((int)RelationalStorageProviderCodes.RelationalProviderInitProvider, $"Initialized storage provider: ServiceId={ServiceId} ProviderName={Name} Invariant={Storage.InvariantName} ConnectionString={Storage.ConnectionString}."); }
public virtual async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { Name = name; logger = providerRuntime.GetLogger(GetType().Name); logger.Info("Init Name={0}", Name); ILocalContentGrain grain = providerRuntime.GrainFactory.GetGrain<ILocalContentGrain>(Guid.NewGuid()); // issue any grain call to activate this grain. await grain.Init(); logger.Info("Finished Init Name={0}", name); }
/// <summary> Initialization function for this storage provider. </summary> /// <see cref="IProvider.Init"/> public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { Name = name; serviceId = providerRuntime.ServiceId.ToString(); if (!config.Properties.ContainsKey(DataConnectionStringPropertyName) || string.IsNullOrWhiteSpace(config.Properties[DataConnectionStringPropertyName])) throw new ArgumentException("DataConnectionString property not set"); dataConnectionString = config.Properties["DataConnectionString"]; if (config.Properties.ContainsKey(TableNamePropertyName)) tableName = config.Properties[TableNamePropertyName]; isDeleteStateOnClear = config.Properties.ContainsKey(DeleteOnClearPropertyName) && "true".Equals(config.Properties[DeleteOnClearPropertyName], StringComparison.OrdinalIgnoreCase); Log = providerRuntime.GetLogger("Storage.AzureTableStorage." + id); var initMsg = string.Format("Init: Name={0} ServiceId={1} Table={2} DeleteStateOnClear={3}", Name, serviceId, tableName, isDeleteStateOnClear); if (config.Properties.ContainsKey(UseJsonFormatPropertyName)) useJsonFormat = "true".Equals(config.Properties[UseJsonFormatPropertyName], StringComparison.OrdinalIgnoreCase); this.jsonSettings = OrleansJsonSerializer.UpdateSerializerSettings(OrleansJsonSerializer.GetDefaultSerializerSettings(), config); initMsg = String.Format("{0} UseJsonFormat={1}", initMsg, useJsonFormat); Log.Info((int)AzureProviderErrorCode.AzureTableProvider_InitProvider, initMsg); Log.Info((int)AzureProviderErrorCode.AzureTableProvider_ParamConnectionString, "AzureTableStorage Provider is using DataConnectionString: {0}", ConfigUtilities.PrintDataConnectionInfo(dataConnectionString)); tableDataManager = new GrainStateTableDataManager(tableName, dataConnectionString, Log); return tableDataManager.InitTableAsync(); }
/// <summary> /// Initializes the storage provider. /// </summary> /// <param name="name">The name of this provider instance.</param> /// <param name="providerRuntime">A Orleans runtime object managing all storage providers.</param> /// <param name="config">Configuration info for this provider instance.</param> /// <returns>Completion promise for this operation.</returns> public virtual Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { Log = providerRuntime.GetLogger(this.GetType().FullName); return(TaskDone.Done); }
/// <summary> /// Initializes the storage provider. /// </summary> /// <param name="name">The name of this provider instance.</param> /// <param name="providerRuntime">A Orleans runtime object managing all storage providers.</param> /// <param name="config">Configuration info for this provider instance.</param> /// <returns>Completion promise for this operation.</returns> public virtual Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config) { this.Log = providerRuntime.GetLogger(this.GetType().FullName); this.serializerSettings = OrleansJsonSerializer.GetDefaultSerializerSettings(); return(TaskDone.Done); }