Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            // load aws settings from app.config
            //AWS.LoadSettings();

            // manually set AWS settings
            AWS.AccessKeyID     = ConfigurationManager.AppSettings.Get("AWSAccessKeyID");
            AWS.SecretAccessKey = ConfigurationManager.AppSettings.Get("AWSSecretAccessKey");
            AWS.RegionEndpoint  = ConfigurationManager.AppSettings.Get("AWSRegionEndpoint");

            // build modifications
            PreparedModifications prepared_modifications = AutoScale.BuildModificatons();

            // print out changes to be made
            Console.WriteLine(prepared_modifications.ToString(true));

            // apply modifications
            //ModificationResults modification_results = AutoScale.ApplyModifications(prepared_modifications);

            // print out modification results
            //Console.WriteLine(modification_results.ToString());

            Console.WriteLine("Done");
            Console.Read();
        }
Ejemplo n.º 2
0
        public static ModificationResults ApplyModifications(PreparedModifications prepared_modifications, bool continue_on_error = true)
        {
            ModificationResults modification_results = new ModificationResults();

            if (prepared_modifications.modified_throughputs.Any())
            {
                var table_name_groups = prepared_modifications.modified_throughputs
                                        .Where(modified_throughput => modified_throughput.new_provisioned_throughput != null)
                                        .GroupBy(modified_throughput => modified_throughput.table_name)
                                        .ToList();

                foreach (var table_name_group in table_name_groups)
                {
                    try
                    {
                        UpdateTableRequest update_table_request = new UpdateTableRequest {
                            TableName = table_name_group.Key
                        };
                        update_table_request.ProvisionedThroughput       = null;
                        update_table_request.GlobalSecondaryIndexUpdates = new List <GlobalSecondaryIndexUpdate>();

                        ModifiedThroughput table_modified_throughput = table_name_group.SingleOrDefault(modified_throughput => string.IsNullOrEmpty(modified_throughput.index_name));
                        if (table_modified_throughput != null)
                        {
                            update_table_request.ProvisionedThroughput = table_modified_throughput.new_provisioned_throughput;
                        }

                        List <ModifiedThroughput> index_modified_throughputs = table_name_group.Where(modified_throughput => !string.IsNullOrEmpty(modified_throughput.index_name)).ToList();
                        foreach (var index_modified_throughput in index_modified_throughputs)
                        {
                            GlobalSecondaryIndexUpdate global_secondary_index_update = new GlobalSecondaryIndexUpdate
                            {
                                Update = new UpdateGlobalSecondaryIndexAction
                                {
                                    IndexName             = index_modified_throughput.index_name,
                                    ProvisionedThroughput = index_modified_throughput.new_provisioned_throughput
                                }
                            };
                            update_table_request.GlobalSecondaryIndexUpdates.Add(global_secondary_index_update);
                        }

                        AmazonDynamoDBClient amazon_dynamo_db_client = AWS.GetAmazonDynamoDBClient();
                        amazon_dynamo_db_client.UpdateTable(update_table_request);
                        modification_results.SuccessfulUpdates.Add(table_name_group.Key);
                    }
                    catch (Exception exception)
                    {
                        modification_results.Errors.Add(new Tuple <string, Exception>(table_name_group.Key, exception));
                        if (!continue_on_error)
                        {
                            break;
                        }
                    }
                }
            }

            return(modification_results);
        }
Ejemplo n.º 3
0
        public static PreparedModifications BuildModificatons(string rules_config_file_path = null, bool include_non_changes = false)
        {
            try
            {
                PreparedModifications prepared_modifications = new PreparedModifications();
                Rules rules = LoadRules(rules_config_file_path);
                List <ThroughputModification> throughput_modifications = rules.GenerateThroughputModifications();

                if (throughput_modifications.Any())
                {
                    AmazonDynamoDBClient amazon_dynamo_db_client = AWS.GetAmazonDynamoDBClient();
                    ListTablesResponse   list_table_response     = amazon_dynamo_db_client.ListTables();
                    List <string>        table_names             = list_table_response.TableNames;
                    table_names.ForEach(table_name =>
                    {
                        // find all throughput modifications that have applicable rules (both table/index level) for this table name
                        List <ThroughputModification> qualified_throughput_modifications = throughput_modifications.Where(throughput_modification => throughput_modification.Qualify(table_name)).ToList();
                        if (qualified_throughput_modifications.Any())
                        {
                            DescribeTableResponse describe_table_response = amazon_dynamo_db_client.DescribeTable(table_name);
                            TableDescription table = describe_table_response.Table;

                            // find all throughput modifications that have applicable rules at the table level only
                            List <ThroughputModification> qualified_table_throughput_modifications = qualified_throughput_modifications
                                                                                                     .Where(throughput_modification => throughput_modification.QualifyTable(table_name))
                                                                                                     .OrderByDescending(throughput_modification => throughput_modification.GetTableMatchScore(table_name))
                                                                                                     .ThenByDescending(throughput_modification => throughput_modification.index_id)
                                                                                                     .ToList();

                            if (qualified_table_throughput_modifications.Any())
                            {
                                ModifiedThroughput modified_throughput = BuildModifiedThroughput(table_name, null, table.ProvisionedThroughput, qualified_table_throughput_modifications);
                                if (include_non_changes || modified_throughput.new_provisioned_throughput != null)
                                {
                                    prepared_modifications.modified_throughputs.Add(modified_throughput);
                                }
                            }

                            List <GlobalSecondaryIndexDescription> global_secondary_indexes = table.GlobalSecondaryIndexes;
                            global_secondary_indexes.ForEach(global_secondary_index =>
                            {
                                // find all throughput modifications that have applicable rules at the index level only
                                string index_name = global_secondary_index.IndexName;
                                List <ThroughputModification> qualified_index_throughput_modifications = qualified_throughput_modifications
                                                                                                         .Where(throughput_modification => throughput_modification.QualifyIndex(table_name, index_name))
                                                                                                         .OrderByDescending(throughput_modfication => throughput_modfication.GetIndexMatchScore(table_name, index_name))
                                                                                                         .ThenByDescending(throughput_modification => throughput_modification.index_id)
                                                                                                         .ToList();

                                if (qualified_index_throughput_modifications.Any())
                                {
                                    ModifiedThroughput modified_throughput = BuildModifiedThroughput(table_name, index_name, global_secondary_index.ProvisionedThroughput, qualified_index_throughput_modifications);
                                    if (include_non_changes || modified_throughput.new_provisioned_throughput != null)
                                    {
                                        prepared_modifications.modified_throughputs.Add(modified_throughput);
                                    }
                                }
                            });
                        }
                    });
                }

                return(prepared_modifications);
            }
            catch (Exception exception)
            {
                // provide custom exception handling here
                throw;
            }
        }