public async Task <ActionResult> Put(string key, [FromBody] KvProperty kvProperty) { if (!_consensusContext.IsLeader()) { return(Redirect($"{_consensusContext.NodeVote.LeaderNode.Address}/api/key-values")); } var serviceFromStore = _kvPropertyService.Get(key); if (serviceFromStore == null) { return(NotFound()); } kvProperty.Key = key; var actionConfirmation = await _kvPropertyService.Update(kvProperty); if (actionConfirmation.WasSuccessful) { return(Ok()); } else { return(BadRequest(actionConfirmation)); } }
public bool OnLogReplication(AppendEntriesEvent appendEntriesEvent) { if (appendEntriesEvent.Entries != null && appendEntriesEvent.Entries.Count > 0) { foreach (var item in appendEntriesEvent.Entries) { if (item.ObjectType == typeof(ServiceHealth).FullName) { var serviceHealth = JsonConvert.DeserializeObject <ServiceHealth>(item.Value.ToString()); _serviceHealthService.Create(serviceHealth.ServiceId, serviceHealth); } else if (item.ObjectType == typeof(Service).FullName) { var serviceData = JsonConvert.DeserializeObject <Service>(item.Value.ToString()); switch (item.Method) { case MethodType.Create: _servicesService.Create(serviceData); break; case MethodType.Update: _servicesService.Update(serviceData); break; case MethodType.Delete: _servicesService.Delete(serviceData.Id); break; } } else if (item.ObjectType == typeof(KvProperty).FullName) { var kvProperty = JsonConvert.DeserializeObject <KvProperty>(item.Value.ToString()); switch (item.Method) { case MethodType.Create: _kvPropertyService.Create(kvProperty); break; case MethodType.Update: _kvPropertyService.Update(kvProperty); break; case MethodType.Delete: _kvPropertyService.Delete(kvProperty.Key); break; } } } } return(true); }