public override Task <ClientProto.StatusResponse> GetReady(ClientProto.BlockInfo blockInfo, ServerCallContext context) { ClientProto.StatusResponse response = new ClientProto.StatusResponse { Type = ClientProto.StatusResponse.Types.StatusType.Success }; if (blockInfo.IpAddress.Count() == 0) { response.Type = ClientProto.StatusResponse.Types.StatusType.Ready; return(Task.FromResult(response)); } else { Guid blockId = Guid.Parse(blockInfo.BlockId.Value); Channel channel = null; string ipAddress = ""; try { ipAddress = blockInfo.IpAddress[0]; blockInfo.IpAddress.RemoveAt(0); channel = ConnectionManager.Instance.CreateChannel(blockId, ipAddress, Constants.Port.ToString()); var client = new ClientProto.ClientProto.ClientProtoClient(channel); client.GetReady(blockInfo); } catch (RpcException e) { ConnectionManager.Instance.ShutDownChannel(blockId, channel); response.Message = "Failed to get ready for " + ipAddress + ": " + e.Message; } // We will always return ready as if it reaches this far there is at least 1 node in the pipeline, which is good enough! return(Task.FromResult(response)); } }
/// <summary> /// Creates the pipeline for streaming the block to DataNodes /// </summary> /// <param name="blockInfo">Info of the block. Contains blockid, blocksize, and ipaddresses for pipeline creation</param> /// <param name="client">Client connection with first DataNode in pipe</param> /// <returns>Success of pipeline creation</returns> private bool GetPipeLineReady(ClientProto.BlockInfo blockInfo, out ClientProto.ClientProto.ClientProtoClient client) { ClientProto.StatusResponse readyResponse = new ClientProto.StatusResponse { Type = ClientProto.StatusResponse.Types.StatusType.Fail }; try { Channel channel = new Channel(blockInfo.IpAddress[0] + ":" + "50051", ChannelCredentials.Insecure); blockInfo.IpAddress.RemoveAt(0); client = new ClientProto.ClientProto.ClientProtoClient(channel); readyResponse = client.GetReady(blockInfo); return(true); } catch (Exception e) { #if Debug Console.WriteLine("Get ready failed: " + e.Message); #endif client = null; return(false); } }