Example #1
0
        /// <summary>
        /// 删除Checkpoint
        /// </summary>
        /// <param name="checkPointRequest"></param>
        /// <returns></returns>
        public ResponseResult DeleteCheckpoint(CheckPointRequest checkPointRequest)
        {
            ObsWebServiceRequest obsWebServiceRequest = new DISWebServiceRequest();
            IRequest             requestobs           = new DISDefaultRequest(obsWebServiceRequest, Constants.SERVICENAME)
            {
                HttpMethod = HttpMethodName.DELETE.ToString()
            };

            var resourcePath = ResourcePathBuilder.Standard()
                               .WithProjectId(_disConfig.GetProjectId())
                               .WithResource(new CheckPointResource(null))
                               .Build();

            requestobs.ResourcePath = resourcePath;
            //requestobs.ResourcePath = resourcePath.TrimEnd('/') + "?stream_name=" + checkPointRequest.StreamName + "&app_name=" + checkPointRequest.AppName;

            //if (!string.IsNullOrEmpty(checkPointRequest.PartitionId))
            //{
            //    requestobs.ResourcePath += "&partition_id=" + checkPointRequest.PartitionId;
            //}

            //if (!string.IsNullOrEmpty(checkPointRequest.CheckpointType))
            //{
            //    requestobs.ResourcePath += "&checkpoint_type=" + checkPointRequest.CheckpointType;
            //}

            ResponseResult results = this.Request <ResponseResult>(checkPointRequest, requestobs);

            return(results);
        }
        /// <summary>
        /// 删除Checkpoint
        /// </summary>
        /// <param name="streamName">通道名称</param>
        /// <param name="appName">App名称</param>
        /// <param name="partitionId">分区ID</param>
        /// <param name="checkpointType">Checkpoint类型</param>
        /// <returns></returns>
        public static ResponseResult DeleteCheckpoint(string streamName = "", string appName = "", string partitionId = "", string checkpointType = "LAST_READ")
        {
            var dic     = new DISIngestionClient();
            var request = new CheckPointRequest();

            if (!String.IsNullOrEmpty(streamName))
            {
                request.StreamName = streamName;
            }

            if (!String.IsNullOrEmpty(appName))
            {
                request.AppName = appName;
            }

            if (!String.IsNullOrEmpty(partitionId))
            {
                request.PartitionId = partitionId;
            }

            if (!String.IsNullOrEmpty(checkpointType))
            {
                request.CheckpointType = checkpointType;
            }

            ResponseResult response = dic.DeleteCheckpoint(request);

            Console.WriteLine(response);
            return(response);
        }
Example #3
0
        internal async Task <bool> DownloadCheckPointAsync(uint blockCount)
        {
            {
                uint endBlock      = (blockCount / 100) * 100;
                var  blockResponse = await RequestTransactionBlocksAsync(endBlock, 1);

                var ns = TcpClient.GetStream();
                using (var ms = new MemoryStream())
                {
                    for (uint i = 0; i <= blockResponse.Blocks.Last().BlockNumber / 10000; i++)
                    {
                        CheckPointRequest checkPointRequest =
                            new CheckPointRequest
                        {
                            Operation   = NetOperationType.CheckPoint,
                            RequestType = RequestType.Request,
                            StartBlock  = i * 10000,
                            EndBlock    = ((i + 1) * 10000) - 1
                        };
                        if (checkPointRequest.EndBlock > blockResponse.Blocks.Last().BlockNumber - 1)
                        {
                            checkPointRequest.EndBlock = blockResponse.Blocks.Last().BlockNumber - 1;
                        }
                        checkPointRequest.CheckPointBlockCount = endBlock;
                        checkPointRequest.RequestId            = 12345;
                        checkPointRequest.CheckPointHash       = blockResponse.Blocks.Last().CheckPointHash;
                        using (MemoryStream requestStream = new MemoryStream())
                        {
                            checkPointRequest.SaveToStream(requestStream);
                            requestStream.Position = 0;
                            requestStream.CopyTo(ns);
                            ns.Flush();
                        }
                        WaitForData(10000);
                        Log.Info("Data received");
                        using (var responseStream = new MemoryStream())
                        {
                            var rp = await ReadResponse(responseStream);

                            Log.Info("All Data received");
                            responseStream.Position = 0;
                            CheckPointResponse response = new CheckPointResponse(responseStream);
                        }
                    }
                    return(true);
                }
            }
        }
Example #4
0
        internal void DownloadCheckPoint(uint blockCount)
        {
            const uint REQUEST_ID = 123456;

            void Handler(object o, BlockResponseEventArgs e)
            {
                if (e.BlockResponse.RequestId == REQUEST_ID)
                {
                    Log.Debug(e.BlockResponse.Blocks.First().BlockNumber);
                    for (uint i = 0; i <= e.BlockResponse.Blocks.Last().BlockNumber / 10000; i++)
                    {
                        CheckPointRequest checkPointRequest =
                            new CheckPointRequest
                        {
                            Operation   = NetOperationType.CheckPoint,
                            RequestType = RequestType.Request,
                            StartBlock  = i * 10000,
                            EndBlock    = ((i + 1) * 10000) - 1
                        };
                        if (checkPointRequest.EndBlock > e.BlockResponse.Blocks.Last().BlockNumber - 1)
                        {
                            checkPointRequest.EndBlock = e.BlockResponse.Blocks.Last().BlockNumber - 1;
                        }
                        checkPointRequest.CheckPointBlockCount = 14700;
                        checkPointRequest.RequestId            = 12345;
                        checkPointRequest.CheckPointHash       = e.BlockResponse.Blocks.Last().CheckPointHash;
                        using (MemoryStream ms = new MemoryStream())
                        {
                            checkPointRequest.SaveToStream(ms);
                            NetworkStream ns = TcpClient.GetStream();
                            ms.Position = 0;
                            ms.CopyTo(ns);
                            ns.Flush();
                        }
                    }
                }
            }

            BlockResponse += Handler;
            RequestBlockChain(blockCount, 1, REQUEST_ID, NetOperationType.Transactions);
        }
Example #5
0
        protected virtual void HandleRequests(MessageHeader rp, MemoryStream ms)
        {
            switch (rp.Operation)
            {
            case NetOperationType.Blocks:
                BlockRequest blockRequest  = new BlockRequest(ms, rp);
                var          blockResponse = new BlockResponse
                {
                    RequestId = blockRequest.RequestId,
                    Blocks    = BlockChain.Instance.GetBlocks(blockRequest.StartBlock, blockRequest.EndBlock)
                };
                using (MemoryStream memoryStream = new MemoryStream())
                {
                    blockResponse.SaveToStream(memoryStream);
                    memoryStream.Position = 0;
                    SendRaw(memoryStream);
                }

                break;

            case NetOperationType.Transactions:
            {
                BlockRequest  transactionBlockRequest  = new BlockRequest(ms, rp);
                BlockResponse transactionBlockResponse = new BlockResponse
                {
                    RequestId = transactionBlockRequest.RequestId,
                    Blocks    = BlockChain.Instance.GetBlocks(transactionBlockRequest.StartBlock,
                                                              transactionBlockRequest.EndBlock).ToList()
                };
                using (MemoryStream memoryStream = new MemoryStream())
                {
                    transactionBlockResponse.SaveToStream(memoryStream);
                    memoryStream.Position = 0;
                    SendRaw(memoryStream);
                }
                break;
            }

            case NetOperationType.CheckPoint:
                var checkPointRequest  = new CheckPointRequest(ms, rp);
                var checkPointResponse = new CheckPointResponse
                {
                    RequestId = checkPointRequest.RequestId
                };
                break;

            case NetOperationType.Hello:
                HelloRequest request = new HelloRequest(ms, rp);
                Node.Instance.NodeServers.UpdateNodeServers(request.NodeServers);
                HelloResponse response = new HelloResponse(request)
                {
                    Timestamp   = DateTime.UtcNow,
                    Error       = 0,
                    ServerPort  = Node.NetParams.Port,
                    Block       = BlockChain.Instance.GetLastBlock(),
                    WorkSum     = CheckPoints.WorkSum,
                    AccountKey  = Node.Instance.NodeKey,
                    RequestType = RequestType.Response,
                    Operation   = NetOperationType.Hello
                };
                using (MemoryStream vm = new MemoryStream())
                {
                    response.SaveToStream(vm);
                    vm.Position = 0;
                    SendRaw(vm);
                }
                break;
            }
        }