public async Task <ActionConfirmation> Create(Service service) { var validatorConfirmation = _serviceValidator.Validate(service, ActionType.Create); if (!validatorConfirmation.WasSuccessful) { return(validatorConfirmation); } if (_consensusContext.IsLeader()) { var consensusResult = await _logReplication.DistributeEntry(service, MethodType.Create); if (consensusResult.WasSuccessful) { _serviceRepository.Create(service); if (ShouldExecuteHealthChecking(service)) { _serviceHealthWorker.RunHealthChecker(service); } } else { return(ActionConfirmation.CreateError($"Distribute item to other services fails: '{consensusResult.Message}'.")); } } else { _serviceRepository.Create(service); } return(ActionConfirmation.CreateSuccessful()); }
public async Task <ActionConfirmation> Create(KvProperty kvProperty) { var validatorConfirmation = _kvPropertyValidator.Validate(kvProperty, ActionType.Create); if (!validatorConfirmation.WasSuccessful) { return(validatorConfirmation); } if (_consensusContext.IsLeader()) { var consensusResult = await _logReplication.DistributeEntry(kvProperty, MethodType.Create); if (consensusResult.WasSuccessful) { _kvPropertyRepository.Create(kvProperty); } else { return(ActionConfirmation.CreateError($"Distribute item to other services fails: '{consensusResult.Message}'.")); } } else { _kvPropertyRepository.Create(kvProperty); } return(ActionConfirmation.CreateSuccessful()); }
public async Task <ActionResult> Post([FromBody] KvProperty kvProperty) { if (!_consensusContext.IsLeader()) { return(Redirect($"{_consensusContext.NodeVote.LeaderNode.Address}/api/key-values")); } var actionConfirmation = await _kvPropertyService.Create(kvProperty); if (actionConfirmation.WasSuccessful) { return(Created($"api/key-values/{kvProperty.Key}", kvProperty)); } else { return(BadRequest(actionConfirmation)); } }
public async Task <ActionResult> Post([FromBody] Service service) { if (!_consensusContext.IsLeader()) { return(Redirect($"{_consensusContext.NodeVote.LeaderNode.Address}/api/services")); } var actionConfirmation = await _servicesService.Create(service); if (actionConfirmation.WasSuccessful) { return(Created($"api/services/{service.Id}", service)); } else { return(BadRequest(actionConfirmation)); } }