private Task Init(CancellationToken ct)
        {
            // Settings could be made configurable from Options.
            jsonSettings = OrleansJsonSerializer.UpdateSerializerSettings(OrleansJsonSerializer.GetDefaultSerializerSettings(typeResolver, grainFactory), false, false, null);

            return(Task.CompletedTask);
        }
        public Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
        {
            _jsonSettings = OrleansJsonSerializer.UpdateSerializerSettings(
                OrleansJsonSerializer.GetDefaultSerializerSettings(
                    providerRuntime.ServiceProvider.GetRequiredService <SerializationManager>(),
                    providerRuntime.GrainFactory),
                config);

            Name = name;
            if (string.IsNullOrWhiteSpace(config.Properties["RootDirectory"]))
            {
                throw new ArgumentException("RootDirectory property not set");
            }

            var directory = new DirectoryInfo(config.Properties["RootDirectory"]);

            if (!directory.Exists)
            {
                directory.Create();
            }

            RootDirectory = directory.FullName;

            return(Task.CompletedTask);
        }
Beispiel #3
0
        public async Task Init(string name, Providers.IProviderRuntime providerRuntime, Providers.IProviderConfiguration config)
        {
            existingCollections = new ConcurrentDictionary <string, bool>();
            createdCollections  = new ConcurrentDictionary <string, bool>();
            Log = providerRuntime.GetLogger("Storage.DocumentDBStorageProvider");
            try
            {
                isFaultTolerant = false; //by default, unless we found otherwise later

                this.jsonSettings = OrleansJsonSerializer.UpdateSerializerSettings(OrleansJsonSerializer.GetDefaultSerializerSettings(), config);
                var url = config.Properties[URL];
                var key = config.Properties[KEY];
                OfferType    = config.Properties[OFFER_TYPE]; //if V1 => S1, S2, S3 else if V2 => RU as integer
                DatabaseName = config.Properties[DATABASE];
                IndexMode    = config.Properties.ContainsKey(INDEXING_MODE) ? config.Properties[INDEXING_MODE] : INDEXING_MODE_CONSISTENT;
                this.Client  = new DocumentClient(new Uri(url), key, new ConnectionPolicy
                {
                    ConnectionMode     = ConnectionMode.Direct,
                    ConnectionProtocol = Protocol.Tcp
                });

                await this.Client.OpenAsync();

                var databases = await this.Client.ReadDatabaseFeedAsync();

                this.Database = databases.Where(d => d.Id == DatabaseName).FirstOrDefault()
                                ?? await this.Client.CreateDatabaseAsync(new Database { Id = DatabaseName });
            }
            catch (Exception ex)
            {
                Log.Error(0, "Error in DocumentDBStorageProvider Init.", ex);
            }
        }
Beispiel #4
0
        /// <summary> Initialization function for this storage provider. </summary>
        private async Task Init(CancellationToken ct)
        {
            var stopWatch = Stopwatch.StartNew();

            try
            {
                this.logger.LogInformation((int)AzureProviderErrorCode.AzureTableProvider_InitProvider, $"AzureTableGrainStorage initializing: {this.options.ToString()}");
                this.logger.LogInformation((int)AzureProviderErrorCode.AzureTableProvider_ParamConnectionString, "AzureTableGrainStorage is using DataConnectionString: {0}", ConfigUtilities.RedactConnectionStringInfo(this.options.ConnectionString));
                this.jsonSettings = OrleansJsonSerializer.UpdateSerializerSettings(OrleansJsonSerializer.GetDefaultSerializerSettings(this.services), this.options.UseFullAssemblyNames, this.options.IndentJson, this.options.TypeNameHandling);

                this.options.ConfigureJsonSerializerSettings?.Invoke(this.jsonSettings);

                var client = this.options.ServiceUri != null ? new BlobServiceClient(this.options.ServiceUri, this.options.TokenCredential) : new BlobServiceClient(this.options.ConnectionString);
                container = client.GetBlobContainerClient(this.options.ContainerName);
                await container.CreateIfNotExistsAsync().ConfigureAwait(false);

                stopWatch.Stop();
                this.logger.LogInformation((int)AzureProviderErrorCode.AzureBlobProvider_InitProvider, $"Initializing provider {this.name} of type {this.GetType().Name} in stage {this.options.InitStage} took {stopWatch.ElapsedMilliseconds} Milliseconds.");
            }
            catch (Exception ex)
            {
                stopWatch.Stop();
                this.logger.LogError((int)ErrorCode.Provider_ErrorFromInit, $"Initialization failed for provider {this.name} of type {this.GetType().Name} in stage {this.options.InitStage} in {stopWatch.ElapsedMilliseconds} Milliseconds.", ex);
                throw;
            }
        }
Beispiel #5
0
        /// <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;
                this.jsonSettings = OrleansJsonSerializer.UpdateSerializerSettings(OrleansJsonSerializer.GetDefaultSerializerSettings(), config);

                if (!config.Properties.ContainsKey(DataConnectionStringPropertyName))
                {
                    throw new BadProviderConfigException($"The {DataConnectionStringPropertyName} setting has not been configured in the cloud role. Please add a {DataConnectionStringPropertyName} setting with a valid Azure Storage connection string.");
                }

                var account       = CloudStorageAccount.Parse(config.Properties[DataConnectionStringPropertyName]);
                var blobClient    = account.CreateCloudBlobClient();
                var containerName = config.Properties.ContainsKey(ContainerNamePropertyName) ? config.Properties[ContainerNamePropertyName] : ContainerNameDefaultValue;
                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;
            }
        }
        /// <summary> Initialization function for this storage provider. </summary>
        private async Task Init(CancellationToken ct)
        {
            var stopWatch = Stopwatch.StartNew();

            try
            {
                this.logger.LogInformation((int)RavenDBProviderErrorCode.RavenDBProvider_InitProvider, $"AzureTableGrainStorage initializing: {this.options.ToString()}");
                this.logger.LogInformation((int)RavenDBProviderErrorCode.RavenDBProvider_ParamConnectionString, "AzureTableGrainStorage is using DataConnectionString: {0}", ConfigUtilities.RedactConnectionStringInfo(this.options.ConnectionString));
                this.jsonSettings = OrleansJsonSerializer.UpdateSerializerSettings(OrleansJsonSerializer.GetDefaultSerializerSettings(this.typeResolver, this.grainFactory), this.options.UseFullAssemblyNames, this.options.IndentJson, this.options.TypeNameHandling);

                this.options.ConfigureJsonSerializerSettings?.Invoke(this.jsonSettings);

                // TODO: RavenDB Specific Code here.

                /*
                 * var account = CloudStorageAccount.Parse(this.options.ConnectionString);
                 * var blobClient = account.CreateCloudBlobClient();
                 * container = blobClient.GetContainerReference(this.options.ContainerName);
                 * await container.CreateIfNotExistsAsync().ConfigureAwait(false);
                 */
                stopWatch.Stop();
                this.logger.LogInformation((int)RavenDBProviderErrorCode.RavenDBProvider_InitProvider, $"Initializing provider {this.name} of type {this.GetType().Name} in stage {this.options.InitStage} took {stopWatch.ElapsedMilliseconds} Milliseconds.");
            }
            catch (Exception ex)
            {
                stopWatch.Stop();
                this.logger.LogError((int)ErrorCode.Provider_ErrorFromInit, $"Initialization failed for provider {this.name} of type {this.GetType().Name} in stage {this.options.InitStage} in {stopWatch.ElapsedMilliseconds} Milliseconds.", ex);
                throw;
            }
        }
        private ICollection <IStorageSerializer> ConfigureSerializers(AdoNetGrainStorageOptions options, IProviderRuntime providerRuntime)
        {
            var serializers = new List <IStorageSerializer>();

            if (options.UseJsonFormat)
            {
                var typeResolver = providerRuntime.ServiceProvider.GetRequiredService <ITypeResolver>();
                var jsonSettings = OrleansJsonSerializer.UpdateSerializerSettings(OrleansJsonSerializer.GetDefaultSerializerSettings(typeResolver, providerRuntime.GrainFactory),
                                                                                  options.UseFullAssemblyNames, options.IndentJson, options.TypeNameHandling);
                options.ConfigureJsonSerializerSettings?.Invoke(jsonSettings);
                serializers.Add(new OrleansStorageDefaultJsonSerializer(jsonSettings, JsonFormatSerializerTag));
            }
            if (options.UseXmlFormat)
            {
                serializers.Add(new OrleansStorageDefaultXmlSerializer(XmlFormatSerializerTag));
            }

            //if none are set true, configure binary format serializer by default
            if (!options.UseXmlFormat && !options.UseJsonFormat)
            {
                serializers.Add(new OrleansStorageDefaultBinarySerializer(this.serializationManager, BinaryFormatSerializerTag));
            }

            return(serializers);
        }
Beispiel #8
0
        /// <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();
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Beispiel #9
0
        /// <summary> Initialization function for this storage provider. </summary>
        private async Task Init(CancellationToken ct)
        {
            var stopWatch = Stopwatch.StartNew();

            try
            {
                this.logger.LogInformation((int) AzureProviderErrorCode.AzureTableProvider_InitProvider, $"AzureBlobGrainStorage initializing: {this.options.ToString()}");
                this.jsonSettings = OrleansJsonSerializer.UpdateSerializerSettings(OrleansJsonSerializer.GetDefaultSerializerSettings(this.services), this.options.UseFullAssemblyNames, this.options.IndentJson, this.options.TypeNameHandling);

                this.options.ConfigureJsonSerializerSettings?.Invoke(this.jsonSettings);

                if (options.CreateClient is not {
                } createClient)
                {
                    throw new OrleansConfigurationException($"No credentials specified. Use the {options.GetType().Name}.{nameof(AzureBlobStorageOptions.ConfigureBlobServiceClient)} method to configure the Azure Blob Service client.");
                }

                var client = await createClient();

                container = client.GetBlobContainerClient(this.options.ContainerName);
                await container.CreateIfNotExistsAsync().ConfigureAwait(false);

                stopWatch.Stop();
                this.logger.LogInformation((int)AzureProviderErrorCode.AzureBlobProvider_InitProvider, $"Initializing provider {this.name} of type {this.GetType().Name} in stage {this.options.InitStage} took {stopWatch.ElapsedMilliseconds} Milliseconds.");
            }
            catch (Exception ex)
            {
                stopWatch.Stop();
                this.logger.LogError((int)ErrorCode.Provider_ErrorFromInit, $"Initialization failed for provider {this.name} of type {this.GetType().Name} in stage {this.options.InitStage} in {stopWatch.ElapsedMilliseconds} Milliseconds.", ex);
                throw;
            }
        }
        public CosmosDBGrainStorage(string name, CosmosDBStorageOptions options, SerializationManager serializationManager,
                                    Providers.IProviderRuntime providerRuntime, IPartitionKeyProvider partitionKeyProvider,
                                    IOptions <ClusterOptions> clusterOptions, IGrainFactory grainFactory, ITypeResolver typeResolver, ILoggerFactory loggerFactory)
        {
            this._name = name;
            this._partitionKeyProvider = partitionKeyProvider;
            this._loggerFactory        = loggerFactory;
            var loggerName = $"{typeof(CosmosDBGrainStorage).FullName}.{name}";

            this._logger  = loggerFactory.CreateLogger(loggerName);
            this._options = options;
            this._serializationManager    = serializationManager;
            this._grainFactory            = grainFactory;
            this._typeResolver            = typeResolver;
            this._serviceId               = clusterOptions.Value.ServiceId;
            this._grainReferenceConverter = providerRuntime.ServiceProvider.GetRequiredService <IGrainReferenceConverter>();

            this._sprocFiles = new Dictionary <string, string>
            {
                { LOOKUP_INDEX_SPROC, $"{LOOKUP_INDEX_SPROC}.js" }
            };

            if (this._options.JsonSerializerSettings == null)
            {
                this._options.JsonSerializerSettings = OrleansJsonSerializer.UpdateSerializerSettings(OrleansJsonSerializer.GetDefaultSerializerSettings(this._typeResolver, this._grainFactory),
                                                                                                      this._options.UseFullAssemblyNames,
                                                                                                      this._options.IndentJson,
                                                                                                      this._options.TypeNameHandling);
                this._options.JsonSerializerSettings.DefaultValueHandling       = DefaultValueHandling.Include;
                this._options.JsonSerializerSettings.PreserveReferencesHandling = PreserveReferencesHandling.None;
            }
        }
Beispiel #11
0
        private Task Init(CancellationToken ct)
        {
            _jsonSettings = OrleansJsonSerializer.UpdateSerializerSettings(OrleansJsonSerializer.GetDefaultSerializerSettings(_typeResolver, _grainFactory), false, false, TypeNameHandling.None);

            _dbClient = new MongoClient(_options.atlasConnectionString);

            return(Task.CompletedTask);
        }
Beispiel #12
0
 private async Task Init(CancellationToken ct)
 {
     this.logger.LogInformation((int)AzureProviderErrorCode.AzureTableProvider_InitProvider, $"AzureTableGrainStorage initializing: {this.options.ToString()}");
     this.logger.LogInformation((int)AzureProviderErrorCode.AzureTableProvider_ParamConnectionString, "AzureTableGrainStorage is using DataConnectionString: {0}", ConfigUtilities.RedactConnectionStringInfo(this.options.DataConnectionString));
     this.JsonSettings     = OrleansJsonSerializer.UpdateSerializerSettings(OrleansJsonSerializer.GetDefaultSerializerSettings(this.typeResolver, this.grainFactory), this.options.UseFullAssemblyNames, this.options.IndentJson, this.options.TypeNameHandling);
     this.tableDataManager = new GrainStateTableDataManager(this.options.TableName, this.options.DataConnectionString, this.loggerFactory);
     await this.tableDataManager.InitTableAsync();
 }
Beispiel #13
0
        private async Task Init(CancellationToken ct)
        {
            _jsonSettings = OrleansJsonSerializer.UpdateSerializerSettings(OrleansJsonSerializer.GetDefaultSerializerSettings(_typeResolver, _grainFactory), false, false, null);

            if (!await _storage.ContainerExits(_container))
            {
                await _storage.CreateContainerAsync(_container);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="JsonGrainStorageSerializer"/> class.
        /// </summary>
        /// <param name="options">The serializer options.</param>
        /// <param name="services">The service provider.</param>
        public JsonGrainStorageSerializer(IOptions <JsonGrainStorageSerializerOptions> options, IServiceProvider services)
        {
            this.jsonSettings = OrleansJsonSerializer.UpdateSerializerSettings(
                OrleansJsonSerializer.GetDefaultSerializerSettings(services),
                options.Value.UseFullAssemblyNames,
                options.Value.IndentJson,
                options.Value.TypeNameHandling);

            options.Value.ConfigureJsonSerializerSettings?.Invoke(this.jsonSettings);
        }
Beispiel #15
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(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);
            var loggerFactory = providerRuntime.ServiceProvider.GetRequiredService <ILoggerFactory>();
            var loggerName    = $"{this.GetType().FullName}.{name}";

            logger = loggerFactory.CreateLogger(loggerName);
            Log    = new LoggerWrapper(logger, loggerName, loggerFactory);
            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);
            }

            var grainFactory = providerRuntime.ServiceProvider.GetRequiredService <IGrainFactory>();

            this.jsonSettings = OrleansJsonSerializer.UpdateSerializerSettings(OrleansJsonSerializer.GetDefaultSerializerSettings(this.serializationManager, grainFactory), config);

            initMsg = string.Format("{0} UseJsonFormat={1}", initMsg, useJsonFormat);

            logger.Info(ErrorCode.StorageProviderBase, "AWS DynamoDB Provider: {0}", initMsg);

            storage = new DynamoDBStorage(config.Properties[DATA_CONNECTION_STRING_PROPERTY_NAME], providerRuntime.ServiceProvider.GetRequiredService <ILoggerFactory>());
            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
                }
            }));
        }
Beispiel #16
0
        /// <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;

                _serializationManager = providerRuntime.ServiceProvider.GetRequiredService <SerializationManager>();
                this.jsonSettings     = OrleansJsonSerializer.UpdateSerializerSettings(OrleansJsonSerializer.GetDefaultSerializerSettings(_serializationManager, providerRuntime.GrainFactory), 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;
                    }
                }

                if (config.Properties.ContainsKey(THROW_ON_DESERIALIZE_ERROR))
                {
                    if ("false".Equals(config.Properties[THROW_ON_DESERIALIZE_ERROR], StringComparison.OrdinalIgnoreCase))
                    {
                        throwOnDeserializeError = false;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error((int)SimpleSQLServerProviderErrorCodes.SimpleSQLServerProvider_InitProvider, ex.ToString(), ex);
                throw;
            }
        }
        /// <summary> Initialization function for this storage provider. </summary>
        public async Task Init(CancellationToken ct)
        {
            var stopWatch = Stopwatch.StartNew();

            try
            {
                var initMsg = string.Format("Init: Name={0} ServiceId={1} Table={2} DeleteStateOnClear={3}",
                                            this.name, this.options.ServiceId, this.options.TableName, this.options.DeleteStateOnClear);

                this.jsonSettings = OrleansJsonSerializer.UpdateSerializerSettings(
                    OrleansJsonSerializer.GetDefaultSerializerSettings(this.typeResolver, this.grainFactory),
                    this.options.UseFullAssemblyNames, this.options.IndentJson, this.options.TypeNameHandling);
                this.options.ConfigureJsonSerializerSettings?.Invoke(this.jsonSettings);

                this.logger.LogInformation((int)ErrorCode.StorageProviderBase, $"AWS DynamoDB Grain Storage {this.name} is initializing: {initMsg}");

                this.storage = new DynamoDBStorage(this.logger, this.options.Service, this.options.AccessKey, this.options.SecretKey,
                                                   this.options.ReadCapacityUnits, this.options.WriteCapacityUnits, this.options.UseProvisionedThroughput);

                await storage.InitializeTable(this.options.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
                    }
                },
                                              secondaryIndexes : null,
                                              ttlAttributeName : this.options.TimeToLive.HasValue?GRAIN_TTL_PROPERTY_NAME : null);

                stopWatch.Stop();
                this.logger.LogInformation((int)ErrorCode.StorageProviderBase,
                                           $"Initializing provider {this.name} of type {this.GetType().Name} in stage {this.options.InitStage} took {stopWatch.ElapsedMilliseconds} Milliseconds.");
            }
            catch (Exception exc)
            {
                stopWatch.Stop();
                this.logger.LogError((int)ErrorCode.Provider_ErrorFromInit, $"Initialization failed for provider {this.name} of type {this.GetType().Name} in stage {this.options.InitStage} in {stopWatch.ElapsedMilliseconds} Milliseconds.", exc);
                throw;
            }
        }
Beispiel #18
0
        private Task Init(CancellationToken ct)
        {
            _jsonSettings = OrleansJsonSerializer.UpdateSerializerSettings(OrleansJsonSerializer.GetDefaultSerializerSettings(_typeResolver, _grainFactory), false, false, null);

            var directory = new DirectoryInfo(_options.RootDirectory);

            if (!directory.Exists)
            {
                directory.Create();
            }

            return(Task.CompletedTask);
        }
        private Task Init(CancellationToken ct)
        {
            try
            {
                _jsonSettings = OrleansJsonSerializer
                                .UpdateSerializerSettings(OrleansJsonSerializer.GetDefaultSerializerSettings(_typeResolver, _grainFactory),
                                                          _options.UseFullAssemblyNames, _options.IndentJson, _options.TypeNameHandling);
                _dataManager = new GrainStateDataManager(_options);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(Task.CompletedTask);
        }
Beispiel #20
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);
            var loggerFactory = providerRuntime.ServiceProvider.GetRequiredService <ILoggerFactory>();
            var loggerName    = $"{this.GetType().FullName}.{Name}";

            logger = loggerFactory.CreateLogger(loggerName);
            Log    = new LoggerWrapper(logger, loggerName, loggerFactory);
            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);

            this.logger.Info((int)AzureProviderErrorCode.AzureTableProvider_InitProvider, initMsg);
            logger.Info((int)AzureProviderErrorCode.AzureTableProvider_ParamConnectionString, "AzureTableStorage Provider is using DataConnectionString: {0}", ConfigUtilities.RedactConnectionStringInfo(dataConnectionString));
            tableDataManager = new GrainStateTableDataManager(tableName, dataConnectionString, loggerFactory);
            return(tableDataManager.InitTableAsync());
        }
        private async Task Init(CancellationToken ct)
        {
            var stopWatch = Stopwatch.StartNew();

            try
            {
                this.logger.LogInformation((int)AzureProviderErrorCode.AzureTableProvider_InitProvider, $"AzureTableGrainStorage {name} initializing: {this.options.ToString()}");
                this.logger.LogInformation((int)AzureProviderErrorCode.AzureTableProvider_ParamConnectionString, $"AzureTableGrainStorage {name} is using DataConnectionString: {ConfigUtilities.RedactConnectionStringInfo(this.options.ConnectionString)}");
                this.JsonSettings     = OrleansJsonSerializer.UpdateSerializerSettings(OrleansJsonSerializer.GetDefaultSerializerSettings(this.typeResolver, this.grainFactory), this.options.UseFullAssemblyNames, this.options.IndentJson, this.options.TypeNameHandling);
                this.tableDataManager = new GrainStateTableDataManager(this.options.TableName, this.options.ConnectionString, this.loggerFactory);
                await this.tableDataManager.InitTableAsync();

                stopWatch.Stop();
                this.logger.LogInformation((int)AzureProviderErrorCode.AzureTableProvider_InitProvider, $"Initializing provider {this.name} of type {this.GetType().Name} in stage {this.options.InitStage} took {stopWatch.ElapsedMilliseconds} Milliseconds.");
            }
            catch (Exception ex)
            {
                stopWatch.Stop();
                this.logger.LogError((int)ErrorCode.Provider_ErrorFromInit, $"Initialization failed for provider {this.name} of type {this.GetType().Name} in stage {this.options.InitStage} in {stopWatch.ElapsedMilliseconds} Milliseconds.", ex);
                throw;
            }
        }
        /// <summary> Initialization function for this storage provider. </summary>
        private async Task Init(CancellationToken ct)
        {
            var stopWatch = Stopwatch.StartNew();

            try
            {
                this.logger.LogInformation((int)MorsteadEtcdProviderErrorCode.MorsteadEtcdProvider_InitProvider, $"MoresteadEtcdGrainStorage initializing: {this.options.ToString()}");
                this.logger.LogInformation((int)MorsteadEtcdProviderErrorCode.MorsteadEtcdProvider_ParamConnectionString, "MoresteadEtcdGrainStorage is using storage key prefix {0}", name);
                this.jsonSettings = OrleansJsonSerializer.UpdateSerializerSettings(OrleansJsonSerializer.GetDefaultSerializerSettings(this.typeResolver, this.grainFactory), this.options.UseFullAssemblyNames, this.options.IndentJson, this.options.TypeNameHandling);

                this.options.ConfigureJsonSerializerSettings?.Invoke(this.jsonSettings);
                etcdClient = new EtcdClient(this.options.ConnectionString);
                stopWatch.Stop();
                this.logger.LogInformation((int)MorsteadEtcdProviderErrorCode.MorsteadEtcdProvider_InitProvider, $"Initializing provider {this.name} of type {this.GetType().Name} in stage {this.options.InitStage} took {stopWatch.ElapsedMilliseconds} Milliseconds.");
            }
            catch (Exception ex)
            {
                stopWatch.Stop();
                this.logger.LogError((int)ErrorCode.Provider_ErrorFromInit, $"Initialization failed for provider {this.name} of type {this.GetType().Name} in stage {this.options.InitStage} in {stopWatch.ElapsedMilliseconds} Milliseconds.", ex);
                throw;
            }
        }
Beispiel #23
0
        /// <summary> Initialization function for this storage provider. </summary>
        private async Task Init(CancellationToken ct)
        {
            var stopWatch = Stopwatch.StartNew();

            if (db != null)
            {
                return;
            }
            try
            {
                this.logger.LogInformation((int)MorsteadProviderErrorCode.MorsteadProvider_InitProvider, $"MoresteadGrainStorage initializing: {this.options.ToString()}");
                this.logger.LogInformation((int)MorsteadProviderErrorCode.MorsteadProvider_ParamConnectionString, "MoresteadGrainStorage is using Container Name {0}", this.options.ContainerName);
                this.jsonSettings = OrleansJsonSerializer.UpdateSerializerSettings(OrleansJsonSerializer.GetDefaultSerializerSettings(this.typeResolver, this.grainFactory), this.options.UseFullAssemblyNames, this.options.IndentJson, this.options.TypeNameHandling);

                this.options.ConfigureJsonSerializerSettings?.Invoke(this.jsonSettings);
                if (!dbs.ContainsKey(this.name))
                {
                    db = new LiteDatabase(this.name);
                    await Task.Run(() => grains = db.GetCollection <MorsteadGrainStorageModel>("grains"));

                    grains.EnsureIndex(x => x.ETag);
                    dbs.Add(name, db);
                }
                else
                {
                    db = dbs[this.name];
                    await Task.Run(() => grains = db.GetCollection <MorsteadGrainStorageModel>("grains"));
                }
                stopWatch.Stop();
                this.logger.LogInformation((int)MorsteadProviderErrorCode.MorsteadProvider_InitProvider, $"Initializing provider {this.name} of type {this.GetType().Name} in stage {this.options.InitStage} took {stopWatch.ElapsedMilliseconds} Milliseconds.");
            }
            catch (Exception ex)
            {
                stopWatch.Stop();
                this.logger.LogError((int)ErrorCode.Provider_ErrorFromInit, $"Initialization failed for provider {this.name} of type {this.GetType().Name} in stage {this.options.InitStage} in {stopWatch.ElapsedMilliseconds} Milliseconds.", ex);
                throw;
            }
        }
Beispiel #24
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(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());
        }
Beispiel #25
0
        private ICollection <IStorageSerializer> ConfigureSerializers(IProviderConfiguration config)
        {
            const string @true       = "true";
            var          serializers = new List <IStorageSerializer>();

            if (config.Properties.ContainsKey(UseJsonFormatPropertyName) && @true.Equals(config.Properties[UseJsonFormatPropertyName], StringComparison.OrdinalIgnoreCase))
            {
                var jsonSettings = OrleansJsonSerializer.UpdateSerializerSettings(OrleansJsonSerializer.GetDefaultSerializerSettings(), config);
                serializers.Add(new OrleansStorageDefaultJsonSerializer(jsonSettings, UseJsonFormatPropertyName));
            }

            if (config.Properties.ContainsKey(UseXmlFormatPropertyName) && @true.Equals(config.Properties[UseXmlFormatPropertyName], StringComparison.OrdinalIgnoreCase))
            {
                serializers.Add(new OrleansStorageDefaultXmlSerializer(UseXmlFormatPropertyName));
            }

            if (config.Properties.ContainsKey(UseBinaryFormatPropertyName) && @true.Equals(config.Properties[UseBinaryFormatPropertyName], StringComparison.OrdinalIgnoreCase))
            {
                serializers.Add(new OrleansStorageDefaultBinarySerializer(UseBinaryFormatPropertyName));
            }

            return(serializers);
        }
        private ICollection <IStorageDeserializer> ConfigureDeserializers(IProviderConfiguration config, IProviderRuntime providerRuntime)
        {
            const string @true         = "true";
            var          deserializers = new List <IStorageDeserializer>();

            if (config.Properties.ContainsKey(UseJsonFormatPropertyName) && @true.Equals(config.Properties[UseJsonFormatPropertyName], StringComparison.OrdinalIgnoreCase))
            {
                var jsonSettings = OrleansJsonSerializer.UpdateSerializerSettings(OrleansJsonSerializer.GetDefaultSerializerSettings(this.serializationManager, providerRuntime.GrainFactory), config);
                deserializers.Add(new OrleansStorageDefaultJsonDeserializer(jsonSettings, UseJsonFormatPropertyName));
            }

            if (config.Properties.ContainsKey(UseXmlFormatPropertyName) && @true.Equals(config.Properties[UseXmlFormatPropertyName], StringComparison.OrdinalIgnoreCase))
            {
                deserializers.Add(new OrleansStorageDefaultXmlDeserializer(UseXmlFormatPropertyName));
            }

            if (config.Properties.ContainsKey(UseBinaryFormatPropertyName) && @true.Equals(config.Properties[UseBinaryFormatPropertyName], StringComparison.OrdinalIgnoreCase))
            {
                deserializers.Add(new OrleansStorageDefaultBinaryDeserializer(this.serializationManager, UseBinaryFormatPropertyName));
            }

            return(deserializers);
        }
Beispiel #27
0
        private ICollection <IStorageDeserializer> ConfigureDeserializers(AdoNetGrainStorageOptions options, IProviderRuntime providerRuntime)
        {
            var deserializers = new List <IStorageDeserializer>();

            if (options.UseJsonFormat)
            {
                var jsonSettings = OrleansJsonSerializer.UpdateSerializerSettings(OrleansJsonSerializer.GetDefaultSerializerSettings(providerRuntime.ServiceProvider), options.UseFullAssemblyNames, options.IndentJson, options.TypeNameHandling);
                options.ConfigureJsonSerializerSettings?.Invoke(jsonSettings);

                deserializers.Add(new OrleansStorageDefaultJsonDeserializer(jsonSettings, JsonFormatSerializerTag));
            }

            if (options.UseXmlFormat)
            {
                deserializers.Add(new OrleansStorageDefaultXmlDeserializer(XmlFormatSerializerTag));
            }
            //if none are set true, configure binary format serializer by default
            if (!options.UseXmlFormat && !options.UseJsonFormat)
            {
                deserializers.Add(new OrleansStorageDefaultBinaryDeserializer(this.serializer, BinaryFormatSerializerTag));
            }

            return(deserializers);
        }
Beispiel #28
0
 protected virtual JsonSerializerSettings ReturnSerializerSettings(ITypeResolver typeResolver, IProviderRuntime providerRuntime, IProviderConfiguration config)
 {
     return(OrleansJsonSerializer.UpdateSerializerSettings(OrleansJsonSerializer.GetDefaultSerializerSettings(typeResolver, providerRuntime.GrainFactory), config));
 }