Esempio n. 1
0
 public Task InitializeMembershipTable(GlobalConfiguration config, bool tryInitTableVersion)
 {
     deploymentId = config.DeploymentId;
     storage      = new DynamoDBStorage(config.DataConnectionString, loggerFactory);
     logger.Info(ErrorCode.MembershipBase, "Initializing AWS DynamoDB Membership Table");
     return(storage.InitializeTable(TABLE_NAME_DEFAULT_VALUE,
                                    new List <KeySchemaElement>
     {
         new KeySchemaElement {
             AttributeName = SiloInstanceRecord.DEPLOYMENT_ID_PROPERTY_NAME, KeyType = KeyType.HASH
         },
         new KeySchemaElement {
             AttributeName = SiloInstanceRecord.SILO_IDENTITY_PROPERTY_NAME, KeyType = KeyType.RANGE
         }
     },
                                    new List <AttributeDefinition>
     {
         new AttributeDefinition {
             AttributeName = SiloInstanceRecord.DEPLOYMENT_ID_PROPERTY_NAME, AttributeType = ScalarAttributeType.S
         },
         new AttributeDefinition {
             AttributeName = SiloInstanceRecord.SILO_IDENTITY_PROPERTY_NAME, AttributeType = ScalarAttributeType.S
         }
     }));
 }
Esempio n. 2
0
        public Task InitializeGatewayListProvider()
        {
            this.storage = new DynamoDBStorage(
                this.logger,
                this.options.Service,
                this.options.AccessKey,
                this.options.SecretKey,
                this.options.Token,
                this.options.ProfileName,
                this.options.ReadCapacityUnits,
                this.options.WriteCapacityUnits);

            return(this.storage.InitializeTable(this.options.TableName,
                                                new List <KeySchemaElement>
            {
                new KeySchemaElement {
                    AttributeName = SiloInstanceRecord.DEPLOYMENT_ID_PROPERTY_NAME, KeyType = KeyType.HASH
                },
                new KeySchemaElement {
                    AttributeName = SiloInstanceRecord.SILO_IDENTITY_PROPERTY_NAME, KeyType = KeyType.RANGE
                }
            },
                                                new List <AttributeDefinition>
            {
                new AttributeDefinition {
                    AttributeName = SiloInstanceRecord.DEPLOYMENT_ID_PROPERTY_NAME, AttributeType = ScalarAttributeType.S
                },
                new AttributeDefinition {
                    AttributeName = SiloInstanceRecord.SILO_IDENTITY_PROPERTY_NAME, AttributeType = ScalarAttributeType.S
                }
            }));
        }
Esempio n. 3
0
        public Task InitializeMembershipTable(bool tryInitTableVersion)
        {
            this.storage = new DynamoDBStorage(this.loggerFactory, this.options.Service, this.options.AccessKey, this.options.SecretKey,
                                               this.options.ReadCapacityUnits, this.options.WriteCapacityUnits);

            logger.Info(ErrorCode.MembershipBase, "Initializing AWS DynamoDB Membership Table");
            return(storage.InitializeTable(this.options.TableName,
                                           new List <KeySchemaElement>
            {
                new KeySchemaElement {
                    AttributeName = SiloInstanceRecord.DEPLOYMENT_ID_PROPERTY_NAME, KeyType = KeyType.HASH
                },
                new KeySchemaElement {
                    AttributeName = SiloInstanceRecord.SILO_IDENTITY_PROPERTY_NAME, KeyType = KeyType.RANGE
                }
            },
                                           new List <AttributeDefinition>
            {
                new AttributeDefinition {
                    AttributeName = SiloInstanceRecord.DEPLOYMENT_ID_PROPERTY_NAME, AttributeType = ScalarAttributeType.S
                },
                new AttributeDefinition {
                    AttributeName = SiloInstanceRecord.SILO_IDENTITY_PROPERTY_NAME, AttributeType = ScalarAttributeType.S
                }
            }));
        }
        public Task InitializeGatewayListProvider(ClientConfiguration conf)
        {
            gatewayListRefreshPeriod = conf.GatewayListRefreshPeriod;
            deploymentId             = conf.DeploymentId;

            storage = new DynamoDBStorage(conf.DataConnectionString, loggerFactory);
            return(storage.InitializeTable(TABLE_NAME_DEFAULT_VALUE,
                                           new List <KeySchemaElement>
            {
                new KeySchemaElement {
                    AttributeName = SiloInstanceRecord.DEPLOYMENT_ID_PROPERTY_NAME, KeyType = KeyType.HASH
                },
                new KeySchemaElement {
                    AttributeName = SiloInstanceRecord.SILO_IDENTITY_PROPERTY_NAME, KeyType = KeyType.RANGE
                }
            },
                                           new List <AttributeDefinition>
            {
                new AttributeDefinition {
                    AttributeName = SiloInstanceRecord.DEPLOYMENT_ID_PROPERTY_NAME, AttributeType = ScalarAttributeType.S
                },
                new AttributeDefinition {
                    AttributeName = SiloInstanceRecord.SILO_IDENTITY_PROPERTY_NAME, AttributeType = ScalarAttributeType.S
                }
            }));
        }
Esempio n. 5
0
        /// <summary>
        /// Initialize current instance with specific global configuration and logger
        /// </summary>
        /// <param name="config"> Global configuration to initialize with </param>
        /// <param name="logger"> Specific logger to use in current instance </param>
        /// <returns></returns>
        public Task Init(GlobalConfiguration config, Logger logger)
        {
            deploymentId = config.DeploymentId;
            serviceId = config.ServiceId;

            this.logger = logger;

            storage = new DynamoDBStorage(config.DataConnectionStringForReminders, logger);
            logger.Info(ErrorCode.ReminderServiceBase, "Initializing AWS DynamoDB Reminders Table");

            var secondaryIndex = new GlobalSecondaryIndex
            {
                IndexName = SERVICE_ID_INDEX,
                Projection = new Projection { ProjectionType = ProjectionType.ALL },
                KeySchema = new List<KeySchemaElement>
                {
                    new KeySchemaElement { AttributeName = SERVICE_ID_PROPERTY_NAME, KeyType = KeyType.HASH},
                    new KeySchemaElement { AttributeName = GRAIN_HASH_PROPERTY_NAME, KeyType = KeyType.RANGE }
                }
            };

            return storage.InitializeTable(TABLE_NAME_DEFAULT_VALUE,
                new List<KeySchemaElement>
                {
                    new KeySchemaElement { AttributeName = REMINDER_ID_PROPERTY_NAME, KeyType = KeyType.HASH },
                    new KeySchemaElement { AttributeName = GRAIN_HASH_PROPERTY_NAME, KeyType = KeyType.RANGE }
                },
                new List<AttributeDefinition>
                {
                    new AttributeDefinition { AttributeName = REMINDER_ID_PROPERTY_NAME, AttributeType = ScalarAttributeType.S },
                    new AttributeDefinition { AttributeName = GRAIN_HASH_PROPERTY_NAME, AttributeType = ScalarAttributeType.N },
                    new AttributeDefinition { AttributeName = SERVICE_ID_PROPERTY_NAME, AttributeType = ScalarAttributeType.S }
                },
                new List<GlobalSecondaryIndex> { secondaryIndex });
        }
Esempio n. 6
0
 /// <summary>
 /// Parse data connection string to fill in fields in <paramref name="options"/>
 /// </summary>
 /// <param name="dataConnectionString"></param>
 /// <param name="options"></param>
 public static void ParseDataConnectionString(string dataConnectionString, DynamoDBGatewayListProviderOptions options)
 {
     DynamoDBStorage.ParseDataConnectionString(dataConnectionString, out var accessKey, out var secretKey, out var service, out var readCapacityUnits, out var writeCapacityUnits);
     options.AccessKey          = accessKey;
     options.Service            = service;
     options.SecretKey          = secretKey;
     options.ReadCapacityUnits  = readCapacityUnits;
     options.WriteCapacityUnits = writeCapacityUnits;
 }
Esempio n. 7
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
                }
            }));
        }
Esempio n. 8
0
        /// <summary>
        /// Initialize current instance with specific global configuration and logger
        /// </summary>
        /// <param name="config"> Global configuration to initialize with </param>
        /// <param name="logger"> Specific logger to use in current instance </param>
        /// <returns></returns>
        public Task Init(GlobalConfiguration config, Logger logger)
        {
            deploymentId = config.DeploymentId;
            serviceId    = config.ServiceId;

            this.logger = logger;

            storage = new DynamoDBStorage(config.DataConnectionStringForReminders, logger);
            logger.Info(ErrorCode.ReminderServiceBase, "Initializing AWS DynamoDB Reminders Table");

            var secondaryIndex = new GlobalSecondaryIndex
            {
                IndexName  = SERVICE_ID_INDEX,
                Projection = new Projection {
                    ProjectionType = ProjectionType.ALL
                },
                KeySchema = new List <KeySchemaElement>
                {
                    new KeySchemaElement {
                        AttributeName = SERVICE_ID_PROPERTY_NAME, KeyType = KeyType.HASH
                    },
                    new KeySchemaElement {
                        AttributeName = GRAIN_HASH_PROPERTY_NAME, KeyType = KeyType.RANGE
                    }
                }
            };

            return(storage.InitializeTable(TABLE_NAME_DEFAULT_VALUE,
                                           new List <KeySchemaElement>
            {
                new KeySchemaElement {
                    AttributeName = REMINDER_ID_PROPERTY_NAME, KeyType = KeyType.HASH
                },
                new KeySchemaElement {
                    AttributeName = GRAIN_HASH_PROPERTY_NAME, KeyType = KeyType.RANGE
                }
            },
                                           new List <AttributeDefinition>
            {
                new AttributeDefinition {
                    AttributeName = REMINDER_ID_PROPERTY_NAME, AttributeType = ScalarAttributeType.S
                },
                new AttributeDefinition {
                    AttributeName = GRAIN_HASH_PROPERTY_NAME, AttributeType = ScalarAttributeType.N
                },
                new AttributeDefinition {
                    AttributeName = SERVICE_ID_PROPERTY_NAME, AttributeType = ScalarAttributeType.S
                }
            },
                                           new List <GlobalSecondaryIndex> {
                secondaryIndex
            }));
        }
        /// <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;
            }
        }
Esempio n. 10
0
        public async Task InitializeMembershipTable(bool tryInitTableVersion)
        {
            this.storage = new DynamoDBStorage(
                this.logger,
                this.options.Service,
                this.options.AccessKey,
                this.options.SecretKey,
                this.options.Token,
                this.options.ProfileName,
                this.options.ReadCapacityUnits,
                this.options.WriteCapacityUnits,
                this.options.UseProvisionedThroughput,
                this.options.CreateIfNotExists,
                this.options.UpdateIfExists);

            logger.LogInformation((int)ErrorCode.MembershipBase, "Initializing AWS DynamoDB Membership Table");
            await storage.InitializeTable(this.options.TableName,
                                          new List <KeySchemaElement>
            {
                new KeySchemaElement {
                    AttributeName = SiloInstanceRecord.DEPLOYMENT_ID_PROPERTY_NAME, KeyType = KeyType.HASH
                },
                new KeySchemaElement {
                    AttributeName = SiloInstanceRecord.SILO_IDENTITY_PROPERTY_NAME, KeyType = KeyType.RANGE
                }
            },
                                          new List <AttributeDefinition>
            {
                new AttributeDefinition {
                    AttributeName = SiloInstanceRecord.DEPLOYMENT_ID_PROPERTY_NAME, AttributeType = ScalarAttributeType.S
                },
                new AttributeDefinition {
                    AttributeName = SiloInstanceRecord.SILO_IDENTITY_PROPERTY_NAME, AttributeType = ScalarAttributeType.S
                }
            });

            // even if I am not the one who created the table,
            // try to insert an initial table version if it is not already there,
            // so we always have a first table version row, before this silo starts working.
            if (tryInitTableVersion)
            {
                // ignore return value, since we don't care if I inserted it or not, as long as it is in there.
                bool created = await TryCreateTableVersionEntryAsync();

                if (created)
                {
                    logger.LogInformation("Created new table version row.");
                }
            }
        }
        /// <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>Initialize current instance with specific global configuration and logger</summary>
        public Task Init()
        {
            this.storage = new DynamoDBStorage(this.logger, this.options.Service, this.options.AccessKey, this.options.SecretKey,
                                               this.options.ReadCapacityUnits, this.options.WriteCapacityUnits);

            this.logger.Info(ErrorCode.ReminderServiceBase, "Initializing AWS DynamoDB Reminders Table");

            var secondaryIndex = new GlobalSecondaryIndex
            {
                IndexName  = SERVICE_ID_INDEX,
                Projection = new Projection {
                    ProjectionType = ProjectionType.ALL
                },
                KeySchema = new List <KeySchemaElement>
                {
                    new KeySchemaElement {
                        AttributeName = SERVICE_ID_PROPERTY_NAME, KeyType = KeyType.HASH
                    },
                    new KeySchemaElement {
                        AttributeName = GRAIN_HASH_PROPERTY_NAME, KeyType = KeyType.RANGE
                    }
                }
            };

            return(this.storage.InitializeTable(this.options.TableName,
                                                new List <KeySchemaElement>
            {
                new KeySchemaElement {
                    AttributeName = REMINDER_ID_PROPERTY_NAME, KeyType = KeyType.HASH
                },
                new KeySchemaElement {
                    AttributeName = GRAIN_HASH_PROPERTY_NAME, KeyType = KeyType.RANGE
                }
            },
                                                new List <AttributeDefinition>
            {
                new AttributeDefinition {
                    AttributeName = REMINDER_ID_PROPERTY_NAME, AttributeType = ScalarAttributeType.S
                },
                new AttributeDefinition {
                    AttributeName = GRAIN_HASH_PROPERTY_NAME, AttributeType = ScalarAttributeType.N
                },
                new AttributeDefinition {
                    AttributeName = SERVICE_ID_PROPERTY_NAME, AttributeType = ScalarAttributeType.S
                }
            },
                                                new List <GlobalSecondaryIndex> {
                secondaryIndex
            }));
        }
Esempio n. 13
0
        /// <summary>
        /// Initialize current instance with specific global configuration and logger
        /// </summary>
        /// <param name="config"> Global configuration to initialize with </param>
        /// <returns></returns>
        public Task Init()
        {
            this.storage = new DynamoDBStorage(this.storageOptions.ConnectionString, this.loggerFactory);
            this.logger.Info(ErrorCode.ReminderServiceBase, "Initializing AWS DynamoDB Reminders Table");

            var secondaryIndex = new GlobalSecondaryIndex
            {
                IndexName  = SERVICE_ID_INDEX,
                Projection = new Projection {
                    ProjectionType = ProjectionType.ALL
                },
                KeySchema = new List <KeySchemaElement>
                {
                    new KeySchemaElement {
                        AttributeName = SERVICE_ID_PROPERTY_NAME, KeyType = KeyType.HASH
                    },
                    new KeySchemaElement {
                        AttributeName = GRAIN_HASH_PROPERTY_NAME, KeyType = KeyType.RANGE
                    }
                }
            };

            return(this.storage.InitializeTable(TABLE_NAME_DEFAULT_VALUE,
                                                new List <KeySchemaElement>
            {
                new KeySchemaElement {
                    AttributeName = REMINDER_ID_PROPERTY_NAME, KeyType = KeyType.HASH
                },
                new KeySchemaElement {
                    AttributeName = GRAIN_HASH_PROPERTY_NAME, KeyType = KeyType.RANGE
                }
            },
                                                new List <AttributeDefinition>
            {
                new AttributeDefinition {
                    AttributeName = REMINDER_ID_PROPERTY_NAME, AttributeType = ScalarAttributeType.S
                },
                new AttributeDefinition {
                    AttributeName = GRAIN_HASH_PROPERTY_NAME, AttributeType = ScalarAttributeType.N
                },
                new AttributeDefinition {
                    AttributeName = SERVICE_ID_PROPERTY_NAME, AttributeType = ScalarAttributeType.S
                }
            },
                                                new List <GlobalSecondaryIndex> {
                secondaryIndex
            }));
        }
Esempio n. 14
0
 public Task InitializeMembershipTable(GlobalConfiguration config, bool tryInitTableVersion, Logger log)
 {
     logger = log;
     deploymentId = config.DeploymentId;
     storage = new DynamoDBStorage(config.DataConnectionString, log);
     logger.Info(ErrorCode.MembershipBase, "Initializing AWS DynamoDB Membership Table");
     return storage.InitializeTable(TABLE_NAME_DEFAULT_VALUE,
         new List<KeySchemaElement>
         {
             new KeySchemaElement { AttributeName = SiloInstanceRecord.DEPLOYMENT_ID_PROPERTY_NAME, KeyType = KeyType.HASH },
             new KeySchemaElement { AttributeName = SiloInstanceRecord.SILO_IDENTITY_PROPERTY_NAME, KeyType = KeyType.RANGE }
         },
         new List<AttributeDefinition>
         {
             new AttributeDefinition { AttributeName = SiloInstanceRecord.DEPLOYMENT_ID_PROPERTY_NAME, AttributeType = ScalarAttributeType.S },
             new AttributeDefinition { AttributeName = SiloInstanceRecord.SILO_IDENTITY_PROPERTY_NAME, AttributeType = ScalarAttributeType.S }
         });
 }
        public Task InitializeGatewayListProvider(ClientConfiguration conf, Logger logger)
        {
            gatewayListRefreshPeriod = conf.GatewayListRefreshPeriod;
            deploymentId = conf.DeploymentId;

            storage = new DynamoDBStorage(conf.DataConnectionString, logger);
            return storage.InitializeTable(TABLE_NAME_DEFAULT_VALUE,
                new List<KeySchemaElement>
                {
                    new KeySchemaElement { AttributeName = SiloInstanceRecord.DEPLOYMENT_ID_PROPERTY_NAME, KeyType = KeyType.HASH },
                    new KeySchemaElement { AttributeName = SiloInstanceRecord.SILO_IDENTITY_PROPERTY_NAME, KeyType = KeyType.RANGE }
                },
                new List<AttributeDefinition>
                {
                    new AttributeDefinition { AttributeName = SiloInstanceRecord.DEPLOYMENT_ID_PROPERTY_NAME, AttributeType = ScalarAttributeType.S },
                    new AttributeDefinition { AttributeName = SiloInstanceRecord.SILO_IDENTITY_PROPERTY_NAME, AttributeType = ScalarAttributeType.S }
                });
        }
 public Task InitializeGatewayListProvider()
 {
     storage = new DynamoDBStorage(loggerFactory, options.AccessKey, options.SecretKey, options.Service, options.ReadCapacityUnits, options.WriteCapacityUnits);
     return(storage.InitializeTable(TABLE_NAME_DEFAULT_VALUE,
                                    new List <KeySchemaElement>
     {
         new KeySchemaElement {
             AttributeName = SiloInstanceRecord.DEPLOYMENT_ID_PROPERTY_NAME, KeyType = KeyType.HASH
         },
         new KeySchemaElement {
             AttributeName = SiloInstanceRecord.SILO_IDENTITY_PROPERTY_NAME, KeyType = KeyType.RANGE
         }
     },
                                    new List <AttributeDefinition>
     {
         new AttributeDefinition {
             AttributeName = SiloInstanceRecord.DEPLOYMENT_ID_PROPERTY_NAME, AttributeType = ScalarAttributeType.S
         },
         new AttributeDefinition {
             AttributeName = SiloInstanceRecord.SILO_IDENTITY_PROPERTY_NAME, AttributeType = ScalarAttributeType.S
         }
     }));
 }
Esempio n. 17
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(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 }
                });
        }
Esempio n. 18
0
        /// <summary>Initialize current instance with specific global configuration and logger</summary>
        public Task Init()
        {
            this.storage = new DynamoDBStorage(
                this.logger,
                this.options.Service,
                this.options.AccessKey,
                this.options.SecretKey,
                this.options.Token,
                this.options.ProfileName,
                this.options.ReadCapacityUnits,
                this.options.WriteCapacityUnits,
                this.options.UseProvisionedThroughput,
                this.options.CreateIfNotExists,
                this.options.UpdateIfExists);

            this.logger.LogInformation((int)ErrorCode.ReminderServiceBase, "Initializing AWS DynamoDB Reminders Table");

            var serviceIdGrainHashGlobalSecondaryIndex = new GlobalSecondaryIndex
            {
                IndexName  = SERVICE_ID_GRAIN_HASH_INDEX,
                Projection = new Projection {
                    ProjectionType = ProjectionType.ALL
                },
                KeySchema = new List <KeySchemaElement>
                {
                    new KeySchemaElement {
                        AttributeName = SERVICE_ID_PROPERTY_NAME, KeyType = KeyType.HASH
                    },
                    new KeySchemaElement {
                        AttributeName = GRAIN_HASH_PROPERTY_NAME, KeyType = KeyType.RANGE
                    }
                }
            };

            var serviceIdGrainReferenceGlobalSecondaryIndex = new GlobalSecondaryIndex
            {
                IndexName  = SERVICE_ID_GRAIN_REFERENCE_INDEX,
                Projection = new Projection {
                    ProjectionType = ProjectionType.ALL
                },
                KeySchema = new List <KeySchemaElement>
                {
                    new KeySchemaElement {
                        AttributeName = SERVICE_ID_PROPERTY_NAME, KeyType = KeyType.HASH
                    },
                    new KeySchemaElement {
                        AttributeName = GRAIN_REFERENCE_PROPERTY_NAME, KeyType = KeyType.RANGE
                    }
                }
            };

            return(this.storage.InitializeTable(this.options.TableName,
                                                new List <KeySchemaElement>
            {
                new KeySchemaElement {
                    AttributeName = REMINDER_ID_PROPERTY_NAME, KeyType = KeyType.HASH
                },
                new KeySchemaElement {
                    AttributeName = GRAIN_HASH_PROPERTY_NAME, KeyType = KeyType.RANGE
                }
            },
                                                new List <AttributeDefinition>
            {
                new AttributeDefinition {
                    AttributeName = REMINDER_ID_PROPERTY_NAME, AttributeType = ScalarAttributeType.S
                },
                new AttributeDefinition {
                    AttributeName = GRAIN_HASH_PROPERTY_NAME, AttributeType = ScalarAttributeType.N
                },
                new AttributeDefinition {
                    AttributeName = SERVICE_ID_PROPERTY_NAME, AttributeType = ScalarAttributeType.S
                },
                new AttributeDefinition {
                    AttributeName = GRAIN_REFERENCE_PROPERTY_NAME, AttributeType = ScalarAttributeType.S
                }
            },
                                                new List <GlobalSecondaryIndex> {
                serviceIdGrainHashGlobalSecondaryIndex, serviceIdGrainReferenceGlobalSecondaryIndex
            }));
        }