Exemple #1
0
        public async Task <IActionResult> Index()
        {
            var chaosSettings = await _httpClient.GetGeneralChaosSettings();

            var viewModel = new GeneralChaosSettingViewModel(chaosSettings);

            // set some default values arbitrarily
            if (viewModel.Frequency == default || viewModel.MaxDuration == default)
            {
                viewModel.Frequency   = new TimeSpan(23, 59, 0);
                viewModel.MaxDuration = new TimeSpan(0, 15, 0);
            }

            return(View(viewModel));
        }
Exemple #2
0
        public async Task <IActionResult> UpdateGeneralSettings(GeneralChaosSettingViewModel viewModel)
        {
            // TODO: use FluentValidation insteaad, would be better.
            if (viewModel.MaxDuration > viewModel.Frequency)
            {
                ModelState.AddModelError("MaxDuration", "Duration should be less than Frequency.");
            }

            if (viewModel.ClusterChaosEnabled)
            {
                if (string.IsNullOrWhiteSpace(viewModel.VMScaleSetName) || string.IsNullOrWhiteSpace(viewModel.ResourceGroupName))
                {
                    ModelState.AddModelError("VMScaleSetName", "Virtual machine scale set name and resource group name are mandatory.");
                }

                if (viewModel.PercentageNodesToStop == default && viewModel.PercentageNodesToRestart == default)
                {
                    ModelState.AddModelError("VMScaleSetName", "You need to specify a value either for Percentage Nodes To Stop or Percentage Nodes To Restart");
                }
            }

            if (!ModelState.IsValid)
            {
                return(View("Index", viewModel));
            }

            var chaosSettings    = viewModel as GeneralChaosSetting;
            var originalSettings = await _httpClient.GetGeneralChaosSettings();

            chaosSettings.Id = Guid.NewGuid();
            chaosSettings.OperationChaosSettings = originalSettings.OperationChaosSettings;
            chaosSettings.ExecutionInformation   = originalSettings.ExecutionInformation;

            await _httpClient.UpdateGeneralChaosSettings(chaosSettings);

            return(RedirectToAction("Index"));
        }