protected override async Task <Response> OnExecute(ExecutionContext context, Request request) { var branch = await context.Branch().ConfigureAwait(false); using var transaction = branch.BeginTransaction(); var serviceNode = new ServiceNode() { Id = NodeId.Create <ServiceNode>(request.Id), ServiceId = request.Id, Metadata = NodeMetadata.Create(context.TimeProvider()) }; if (await branch.Services.PutIfAbsentAsync(serviceNode.Id, serviceNode) .ConfigureAwait(false)) { await transaction.CommitAsync().ConfigureAwait(false); return(new Response() { Service = serviceNode.ToOutput() }); } throw new ExecutionException(ExecutionErrorType.Conflict, $"Service {request.Id} already exist"); }
public async Task Create(string branchId, string?sourceBranchId) { var node = CreateNode(); node.Id = NodeId.Create <TBranchNode>(branchId); node.Metadata = NodeMetadata.Create(timeProvider); node.SourceId = sourceBranchId; if (await branchCache.PutIfAbsentAsync(node.Id, node).ConfigureAwait(false)) { Schema.Create(Ignite, branchId); if (sourceBranchId != null) { if (await Exists(sourceBranchId).ConfigureAwait(false)) { await Schema.Copy(Ignite, sourceBranchId, branchId).ConfigureAwait(false); } else { throw new IgniteException($"Branch {sourceBranchId} does not exist"); } } } }