コード例 #1
0
        public async Task StartSystem(
            List <AutoScalingGroupSettings> lstSettings, bool isRdsMultyAz)
        {
            try
            {
                ElasticBeanstalkServices service = new ElasticBeanstalkServices();
                service.DisableScheduleActions(false);
                //Start RDS
                RDSHelper rdsHelper = new RDSHelper(GlobalVariables.Enviroment, GlobalVariables.Region, GlobalVariables.Color);
                try
                {
                    var response = await rdsHelper.GetRDSInstance();

                    await rdsHelper.StartRdsInstance(response.DBInstanceIdentifier, isRdsMultyAz);
                }
                catch (Exception ex)
                {
                    if (ex.GetType().Name == "InvalidDBInstanceStateException")
                    {
                        LogServices.WriteLog(
                            $"RDS instance is not stopped, system starting will continue. Detailed message: {ex.Message}",
                            LogType.Warn, GlobalVariables.Enviroment.ToString());
                    }
                }
                //Start applications by changing the auto scaling group
                var autoScalingHelper = new AutoScalingHelper(GlobalVariables.Enviroment, GlobalVariables.Region, GlobalVariables.Color);
                var lstGroup          = await autoScalingHelper.GetEnvironmentAutoScalingGroupList();

                var jumpBox = lstGroup.Find(o => o.Name.IndexOf("Jump") >= 0);
                if (jumpBox.MaxSize == 0)
                {
                    var settings = new AutoScalingGroupSettings()
                    {
                        MaxSize         = 1,
                        MinSize         = 1,
                        DesiredCapacity = 1
                    };
                    await autoScalingHelper.ChangeScalingGroup(jumpBox.AutoScalingGroupName, settings);
                }
                foreach (var group in lstGroup)
                {
                    var settings = lstSettings.Find(o => group.Name.IndexOf(o.Environment.ToString()) == 0 &&
                                                    group.Name.IndexOf(o.Application.ToString()) > 0);
                    if (settings != null)
                    {
                        await autoScalingHelper.ChangeScalingGroup(group.AutoScalingGroupName, settings);
                    }
                }
            }
            catch (Exception ex)
            {
                LogServices.WriteLog(ex.Message + " Stack trace: " + ex.StackTrace, LogType.Error, GlobalVariables.Enviroment.ToString());
            }
        }
コード例 #2
0
        public async Task ChangeScalingGroup(string groupName, AutoScalingGroupSettings settings, string region = null)
        {
            if (region != null)
            {
                client = new AmazonAutoScalingClient(
                    CredentiaslManager.GetCredential(profile),
                    AwsCommon.GetRetionEndpoint(region));
            }
            UpdateAutoScalingGroupRequest request = new UpdateAutoScalingGroupRequest();

            request.MaxSize                = settings.MaxSize;
            request.MinSize                = settings.MinSize;
            request.DesiredCapacity        = settings.DesiredCapacity;
            request.HealthCheckType        = settings.HealthCheckType;
            request.HealthCheckGracePeriod = settings.HealthCheckGracePeriod;
            request.AutoScalingGroupName   = groupName;
            await client.UpdateAutoScalingGroupAsync(request);
        }
コード例 #3
0
        public void InitAutoScalingGroupSettings(string env)
        {
            AutoScaleGroupSettingsDb db = new AutoScaleGroupSettingsDb();

            foreach (var application in Enum.GetNames(typeof(ApplicationServer)))
            {
                AutoScalingGroupSettings settings = new AutoScalingGroupSettings()
                {
                    Application            = (ApplicationServer)Enum.Parse(typeof(ApplicationServer), application),
                    Environment            = env,
                    MaxSize                = 1,
                    MinSize                = 1,
                    DesiredCapacity        = 1,
                    HealthCheckGracePeriod = 600,
                    HealthCheckType        = "EC2"
                };
                db.Add(settings);
            }
        }
コード例 #4
0
        private async void btnAsgUpdate_Click(object sender, EventArgs e)
        {
            var datasource = gvAsg.DataSource;
            var helper     = new AwsUtilities.AutoScalingHelper(
                GlobalVariables.Enviroment,
                GlobalVariables.Region,
                GlobalVariables.Color);
            int selectCol = gvAsg.ColumnCount - 1;

            foreach (DataGridViewRow row in gvAsg.Rows)
            {
                if (row.Cells[selectCol].Value != null && (bool)row.Cells[selectCol].Value)
                {
                    var rowDs    = ((List <SA_AutoScalingGroup>)datasource)[row.Index];
                    var settings = new AutoScalingGroupSettings()
                    {
                        MaxSize                = rowDs.MaxSize,
                        MinSize                = rowDs.MinSize,
                        DesiredCapacity        = rowDs.DesiredCapacity,
                        HealthCheckType        = rowDs.HealthCheckType,
                        HealthCheckGracePeriod = rowDs.HealthCheckGracePeriod
                    };
                    var confirmResult = MessageBox.Show(
                        string.Format("Are you sure to change autoscaling group settings: '{0}' to be '{1}-{2}-{3}'? Pleae check the settings first and then click YES button!",
                                      rowDs.AutoScalingGroupName, rowDs.MaxSize, rowDs.MinSize, rowDs.DesiredCapacity),
                        "Confirm Updating Auto Scaling Group Settings",
                        MessageBoxButtons.YesNo);
                    if (confirmResult == DialogResult.Yes)
                    {
                        await helper.ChangeScalingGroup(
                            rowDs.AutoScalingGroupName, settings,
                            ((KeyValuePair <string, string>)ddlAsgRegion.SelectedItem).Key);
                    }
                }
            }
        }
コード例 #5
0
 public void Add(AutoScalingGroupSettings obj)
 {
     helper.CreateItem(tableName, obj);
 }