コード例 #1
0
        public async Task ShutDownSystem(bool stopJumpBox)
        {
            var autoScalingHelper = new AutoScalingHelper(GlobalVariables.Enviroment, GlobalVariables.Region, GlobalVariables.Color);
            var lstGroup          = await autoScalingHelper.GetEnvironmentAutoScalingGroupList();

            if (!stopJumpBox)
            {
                var jumpBox = lstGroup.Find(o => o.Name.IndexOf("Jump") >= 0);
                if (jumpBox != null)
                {
                    lstGroup.Remove(jumpBox);
                }
            }
            foreach (var group in lstGroup)
            {
                await autoScalingHelper.StopScalingGroup(group.AutoScalingGroupName);
            }

            ElasticBeanstalkServices service = new ElasticBeanstalkServices();

            service.DisableScheduleActions(true);

            //helper.ShutdownSystem();
            RDSHelper rdsHelper = new RDSHelper(GlobalVariables.Enviroment, GlobalVariables.Region, GlobalVariables.Color);
            var       response  = await rdsHelper.GetRDSInstance();

            await rdsHelper.StopRdsInstance(response.DBInstanceIdentifier);
        }
コード例 #2
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());
            }
        }