Exemple #1
0
        public GetResponse Get(ByteSequence key, GetOption option)
        {
            Etcdserverpb.RangeRequest request = new Etcdserverpb.RangeRequest();
            request.Key          = key.GetByteString();
            request.KeysOnly     = option.IsCountOnly();
            request.Limit        = option.GetLimit();
            request.Revision     = option.GetRevision();
            request.KeysOnly     = option.IsKeysOnly();
            request.Serializable = option.isSerializable();
            request.SortOrder    = OptionsUtil.ToRangeRequestSortOrder(option.GetSortOrder());
            request.SortTarget   = OptionsUtil.ToRangeRequestSortTarget(option.GetSortField());
            if (option.GetEndKey() != null)
            {
                request.RangeEnd = option.GetEndKey().GetByteString();
            }
            var         rsp      = kVClient.Range(request);
            GetResponse response = new GetResponse(rsp);

            return(response);
            //return Util.ToCompletableFutureWithRetry(
            //    stub.Range(request),
            //     new FunctionResponse<Etcdserverpb.RangeRequest, GetResponse>(),
            //    Util.IsRetriable
            //);
        }
Exemple #2
0
        public IWatcher Watch(ByteSequence key, WatchOption watchOption)
        {
            if (IsClosed())
            {
                throw new ClosedWatchClientException();
            }
            WatcherImpl watcher = new WatcherImpl(key, watchOption, this);

            // this.pendingWatchers.Enqueue(watcher);

            Etcdserverpb.WatchRequest       request       = new Etcdserverpb.WatchRequest();
            Etcdserverpb.WatchCreateRequest createRequest = new Etcdserverpb.WatchCreateRequest();
            createRequest.Key            = key.GetByteString();
            createRequest.PrevKv         = watchOption.isPrevKV();
            createRequest.ProgressNotify = watchOption.isProgressNotify();
            createRequest.RangeEnd       = watchOption.getEndKey().GetByteString();
            createRequest.StartRevision  = watchOption.getRevision();
            request.CreateRequest        = createRequest;
            Grpc.Core.CallOptions callOptions = new Grpc.Core.CallOptions();
            watchClient.Watch(callOptions);
            // watchClient.Watch()
            // watchClient.Watch()

            //  if (this.pendingWatchers.Count == 1) {
            // head of the queue send watchCreate request.
            //  WatchRequest request = this.toWatchCreateRequest(watcher);
            // this.getGrpcWatchStreamObserver().onNext(request);
            // }

            return(watcher);
        }
Exemple #3
0
        public UnlockResponse UnLock(ByteSequence lockKey)
        {
            V3Lockpb.UnlockRequest request = new V3Lockpb.UnlockRequest();
            request.Key = lockKey.GetByteString();
            var            rsp      = lockClient.Unlock(request);
            UnlockResponse response = new UnlockResponse(rsp);

            return(response);
            //return Util.ToCompletableFutureWithRetry(
            //       stub.Unlock(request),
            //       new FunctionResponse<V3Lockpb.UnlockRequest, UnlockResponse>(),
            //       Util.IsRetriable
            //);
        }
Exemple #4
0
        public DeleteResponse Delete(ByteSequence key, DeleteOption option)
        {
            Etcdserverpb.DeleteRangeRequest request = new Etcdserverpb.DeleteRangeRequest();
            request.Key      = key.GetByteString();
            request.PrevKv   = option.IsPrevKV;
            request.RangeEnd = option.EndKey.GetByteString();
            var            rsp      = kVClient.DeleteRange(request);
            DeleteResponse response = new DeleteResponse(rsp);

            return(response);
            //return Util.ToCompletableFutureWithRetry(
            //    stub.DeleteRange(request),
            //   new FunctionResponse<Etcdserverpb.DeleteRangeRequest, DeleteResponse>()
            //);
        }
Exemple #5
0
        public LockResponse Lock(ByteSequence name, long leaseId)
        {
            V3Lockpb.LockRequest request = new V3Lockpb.LockRequest();
            request.Name  = name.GetByteString();
            request.Lease = leaseId;
            var          rsp      = lockClient.Lock(request);
            LockResponse response = new LockResponse(rsp);

            return(response);
            //   return Util.ToCompletableFutureWithRetry(
            //    stub.Lock(request),
            //    new FunctionResponse<V3Lockpb.LockRequest, LockResponse>(),
            //    Util.IsRetriable

            //);
        }
Exemple #6
0
        public PutResponse Put(ByteSequence key, ByteSequence value,
                               PutOption option)
        {
            Etcdserverpb.PutRequest request = new Etcdserverpb.PutRequest();
            request.Key    = key.GetByteString();
            request.Value  = value.GetByteString();
            request.Lease  = option.LeaseId;
            request.PrevKv = option.PrevKV;
            var         rsp      = kVClient.Put(request);
            PutResponse response = new PutResponse(rsp);

            return(response);
            //return Util.ToCompletableFutureWithRetry(
            //     stub.Put(request),
            //     new FunctionResponse<Etcdserverpb.PutRequest, PutResponse>(),
            //     Util.IsRetriable
            //);
        }
Exemple #7
0
            public void Resume()
            {
                if (closed)
                {
                    return;
                }

                if (stream == null)
                {
                    // id is not really useful today but it may be in etcd 3.4
                    watchID = -1;
                    Etcdserverpb.WatchCreateRequest createRequest = new Etcdserverpb.WatchCreateRequest
                    {
                        Key            = key.GetByteString(),
                        PrevKv         = watchOption.IsPrevKV,
                        ProgressNotify = watchOption.IsProgressNotify,
                        RangeEnd       = watchOption.EndKey.GetByteString(),
                        StartRevision  = watchOption.Revision
                    };
                    if (watchOption.EndKey.IsPresent)
                    {
                        createRequest.RangeEnd = watchOption.EndKey.GetByteString();
                    }
                    if (watchOption.IsNoDelete)
                    {
                        createRequest.Filters.Add(Etcdserverpb.WatchCreateRequest.Types.FilterType.Nodelete);
                    }
                    if (watchOption.IsNoPut)
                    {
                        createRequest.Filters.Add(Etcdserverpb.WatchCreateRequest.Types.FilterType.Noput);
                    }
                    Grpc.Core.CallOptions     callOptions = new Grpc.Core.CallOptions();
                    Etcdserverpb.WatchRequest request     = new Etcdserverpb.WatchRequest
                    {
                        CreateRequest = createRequest
                    };
                    var rsp = watchClient.Watch(callOptions);
                    rsp.RequestStream.WriteAsync(request);
                    stream       = rsp;
                    this.watchID = rsp.ResponseStream.Current.WatchId;
                }
            }
Exemple #8
0
        public AuthRoleGrantPermissionResponse RoleGrantPermission(ByteSequence role,
                                                                   ByteSequence key, ByteSequence rangeEnd, auth.Permission.Type permType)
        {
            Authpb.Permission.Types.Type type;
            switch (permType)
            {
            case Permission.Type.WRITE:
                type = Authpb.Permission.Types.Type.Write;
                break;

            case Permission.Type.READWRITE:
                type = Authpb.Permission.Types.Type.Readwrite;
                break;

            case Permission.Type.READ:
                type = Authpb.Permission.Types.Type.Read;
                break;

            default:
                type = Authpb.Permission.Types.Type.Readwrite;
                break;
            }
            Authpb.Permission perm = new Authpb.Permission();
            perm.Key      = key.GetByteString();
            perm.RangeEnd = rangeEnd.GetByteString();
            perm.PermType = type;
            Etcdserverpb.AuthRoleGrantPermissionRequest roleGrantPermissionRequest = new Etcdserverpb.AuthRoleGrantPermissionRequest();
            roleGrantPermissionRequest.Name = role.ToString();
            roleGrantPermissionRequest.Perm = perm;
            var rsp = authClient.RoleGrantPermission(roleGrantPermissionRequest);
            AuthRoleGrantPermissionResponse response = new AuthRoleGrantPermissionResponse(rsp);

            return(response);
            // return Util.ToCompletableFuture(
            // this.stub.roleGrantPermission(roleGrantPermissionRequest),
            //  new FunctionResponse<Etcdserverpb.AuthRoleGrantPermissionRequest, AuthRoleGrantPermissionResponse>());
        }