public async Task UpdateChaosSettings(GeneralChaosSetting settings) { await _cache.SetAsync( CHAOS_KEY, settings, new DistributedCacheEntryOptions { SlidingExpiration = TimeSpan.FromDays(1) }); }
internal static async Task StopNodes(GeneralChaosSetting chaosSetting, int percentage) { _chaosSetting = chaosSetting; await GetAccessToken(_chaosSetting.TenantId, _chaosSetting.ClientId, _chaosSetting.ClientKey); var unhealthyNodes = await GetNodesToRestartStop(percentage); await RestartOrStopVM(Operation.PowerOff, unhealthyNodes); }
public GeneralChaosSettingViewModel(GeneralChaosSetting setting) { Id = setting.Id; AutomaticChaosInjectionEnabled = setting.AutomaticChaosInjectionEnabled; MaxDuration = setting.MaxDuration; Frequency = setting.Frequency; PercentageNodesToRestart = setting.PercentageNodesToRestart; PercentageNodesToStop = setting.PercentageNodesToStop; OperationChaosSettings = setting.OperationChaosSettings; ClusterChaosEnabled = setting.ClusterChaosEnabled; ResourceGroupName = setting.ResourceGroupName; VMScaleSetName = setting.VMScaleSetName; ClusterChaosInjectionRate = setting.ClusterChaosInjectionRate; }
public async Task <IActionResult> Post([FromBody] GeneralChaosSetting settings) { // TODO: use FluentValidation insteaad, would be better. if (settings.MaxDuration > settings.Frequency) { return(BadRequest("Duration should be less than Frequency.")); } if (settings.ClusterChaosEnabled) { if (string.IsNullOrWhiteSpace(settings.VMScaleSetName) || string.IsNullOrWhiteSpace(settings.ResourceGroupName)) { return(BadRequest("Virtual machine scale set name and resource group name are mandatory.")); } if (settings.PercentageNodesToStop == default && settings.PercentageNodesToRestart == default) { return(BadRequest("You need to specify a value either for Percentage Nodes To Stop or Percentage Nodes To Restart")); } } var currentSettings = await _chaosRepository.GetChaosSettingsAsync(); if (currentSettings != null) { // just in case automatic injection is disabled when the watchmonkey has released the monkeys. if (settings.AutomaticChaosInjectionEnabled == false && currentSettings.ExecutionInformation.MonkeysReleased) { settings.ExecutionInformation.MonkeysReleased = false; settings.ExecutionInformation.ChaosStoppedAt = new DateTimeOffset(DateTime.UtcNow); } // every time automatic injection changes, I change the LastTimeExecuted in order to start to watch after that change, // otherwise if the last time the watchmonkey released the monkeys was let's say 2 days ago and the frequency is one day, // it's gonna release the monkeys immediately next time the watchmonkey is executed and it should be the next day (given that example) after I updated that setting. if (settings.AutomaticChaosInjectionEnabled != currentSettings.AutomaticChaosInjectionEnabled) { settings.ExecutionInformation.LastTimeExecuted = new DateTimeOffset(DateTime.UtcNow); } } await _chaosRepository.UpdateChaosSettings(settings); return(Ok()); }
public async Task UpdateChaosSettings(GeneralChaosSetting settings) { _settingsToUpdate = new Dictionary <string, object>(); var currentSettings = await GetChaosSettingsAsync(); GetSettingsToUpdate(settings); var client = new ConfigurationClient(_configuration.GetConnectionString("AppConfig")); foreach (var settingToUpdate in _settingsToUpdate) { if (!SettingHasChanged(settingToUpdate.Key, settingToUpdate.Value.ToNullString(), currentSettings)) { continue; } var setting = new ConfigurationSetting(settingToUpdate.Key, settingToUpdate.Value.ToNullString()); await client.SetConfigurationSettingAsync(setting); } // find which settings are going to be deleted. var seetingsToDelete = currentSettings?.OperationChaosSettings? .Where(settingToDelete => !settings.OperationChaosSettings.Select(x => x.Id).Contains(settingToDelete.Id)); if (seetingsToDelete != null) { foreach (var settingToDelete in seetingsToDelete) { _settingsToUpdate = new Dictionary <string, object>(); GetSettingsToUpdate(settingToDelete, "OperationChaosSettings", currentSettings.OperationChaosSettings.IndexOf(settingToDelete)); foreach (var settingToUpdate in _settingsToUpdate) { await client.DeleteConfigurationSettingAsync(settingToUpdate.Key); } } } // We always update our sentinel in order to all the settings will be refreshed. await client.SetConfigurationSettingAsync(new ConfigurationSetting("GeneralChaosSetting:Sentinel", "True")); }
public async Task <IActionResult> SimulateTrip(TripRequestModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState.AllErrors())); } _generalChaosSetting = await _generalChaosSettingFactory.Value; var tripID = await CreateTrip(model); await _hubContext.Clients.All.SendAsync("NotifyTrip", "Created"); await AcceptOrStartTrip(_tripApiSettings.Value.AcceptUrl, tripID); await _hubContext.Clients.All.SendAsync("NotifyTrip", "Accepted"); await AcceptOrStartTrip(_tripApiSettings.Value.StartUrl, tripID); await _hubContext.Clients.All.SendAsync("NotifyTrip", "Started"); for (var index = 0; index < model.Directions.Count; index += 5) { var direction = model.Directions[index]; if (index + 5 >= model.Directions.Count) { direction = _originsAndDestinations.Values.SingleOrDefault(x => x.Description == model.To); } await UpdateTripLocation(tripID, direction); await _hubContext.Clients.All.SendAsync("UpdateCurrentPosition", direction); } await _hubContext.Clients.All.SendAsync("NotifyTrip", "Finished"); return(Ok()); }
public AzureAppConfigurationRepository(IOptionsSnapshot <GeneralChaosSetting> chaosSettings, IConfiguration configuration) { _chaosSettings = chaosSettings.Value; _configuration = configuration; }