protected internal override void HandleInternal(ChannelHandlerContext ctx, RpcInfo info) { // This is just like what's done in RpcProgramMountd#handleInternal and // RpcProgramNfs3#handleInternal. RpcCall rpcCall = (RpcCall)info.Header(); int procedure = rpcCall.GetProcedure(); if (procedure != 0) { bool portMonitorSuccess = DoPortMonitoring(info.RemoteAddress()); if (!portMonitorSuccess) { SendRejectedReply(rpcCall, info.RemoteAddress(), ctx); return; } } resultSize = info.Data().ReadableBytes(); RpcAcceptedReply reply = RpcAcceptedReply.GetAcceptInstance(1234, new VerifierNone ()); XDR @out = new XDR(); reply.Write(@out); ChannelBuffer b = ChannelBuffers.WrappedBuffer(@out.AsReadOnlyWrap().Buffer()); RpcResponse rsp = new RpcResponse(b, info.RemoteAddress()); RpcUtil.SendRpcResponse(ctx, rsp); }
private void ReadNextChunk() { ChannelBuffer readBuffer = ReadNext(); /* Header layout: * [ , ][ , x] 0: last chunk in message, 1: there a more chunks after this one * [ , ][ , x ] 0: success, 1: failure * [ , ][xxxx,xx ] internal protocol version * [xxxx,xxxx][ , ] application protocol version */ sbyte[] header = new sbyte[2]; readBuffer.readBytes(header); _more = (header[0] & 0x1) != 0; _failure = (header[0] & 0x2) != 0; AssertSameProtocolVersion(header, _internalProtocolVersion, _applicationProtocolVersion); if (!_more && _buffer == null) { // Optimization: this is the first chunk and it'll be the only chunk // in this message. _buffer = readBuffer; } else { _buffer = _buffer == null?ChannelBuffers.dynamicBuffer() : _buffer; DiscardReadBytes(); _buffer.writeBytes(readBuffer); } if (_failure) { ReadAndThrowFailureResponse(); } }
/// <exception cref="System.Exception"/> public override void MessageReceived(ChannelHandlerContext ctx, MessageEvent e) { RpcResponse r = (RpcResponse)e.GetMessage(); byte[] fragmentHeader = XDR.RecordMark(r.Data().ReadableBytes(), true); ChannelBuffer header = ChannelBuffers.WrappedBuffer(fragmentHeader); ChannelBuffer d = ChannelBuffers.WrappedBuffer(header, r.Data()); e.GetChannel().Write(d); }
protected internal virtual ChannelBuffer MapSlave(Channel channel, RequestContext slave) { // Checking for machineId -1 excludes the "empty" slave contexts // which some communication points pass in as context. if (slave != null && slave.MachineId() != RequestContext.Empty.machineId()) { _connectedSlaveChannels.add(channel, slave); } return(ChannelBuffers.dynamicBuffer()); }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected: //ORIGINAL LINE: protected void handleRequest(org.jboss.netty.buffer.ChannelBuffer buffer, final org.jboss.netty.channel.Channel channel) protected internal virtual void HandleRequest(ChannelBuffer buffer, Channel channel) { sbyte?continuation = ReadContinuationHeader(buffer, channel); if (continuation == null) { return; } if (continuation.Value == ChunkingChannelBuffer.CONTINUATION_MORE) { PartialRequest partialRequest = _partialRequests[channel]; if (partialRequest == null) { // This is the first chunk in a multi-chunk request RequestType type = GetRequestContext(buffer.readByte()); RequestContext context = ReadContext(buffer); ChannelBuffer targetBuffer = MapSlave(channel, context); partialRequest = new PartialRequest(this, type, context, targetBuffer); _partialRequests[channel] = partialRequest; } partialRequest.Add(buffer); } else { PartialRequest partialRequest = _partialRequests.Remove(channel); RequestType type; RequestContext context; ChannelBuffer targetBuffer; ChannelBuffer bufferToReadFrom; ChannelBuffer bufferToWriteTo; if (partialRequest == null) { // This is the one and single chunk in the request type = GetRequestContext(buffer.readByte()); context = ReadContext(buffer); targetBuffer = MapSlave(channel, context); bufferToReadFrom = buffer; bufferToWriteTo = targetBuffer; } else { // This is the last chunk in a multi-chunk request type = partialRequest.Type; context = partialRequest.Context; targetBuffer = partialRequest.Buffer; partialRequest.Add(buffer); bufferToReadFrom = targetBuffer; bufferToWriteTo = ChannelBuffers.dynamicBuffer(); } bufferToWriteTo.clear(); ChunkingChannelBuffer chunkingBuffer = NewChunkingBuffer(bufferToWriteTo, channel, _chunkSize, InternalProtocolVersion, _applicationProtocolVersion); SubmitSilent(_targetCallExecutor, new TargetCaller(this, type, channel, context, chunkingBuffer, bufferToReadFrom)); } }
/// <summary>Write an XDR message to a TCP ChannelBuffer</summary> public static ChannelBuffer WriteMessageTcp(XDR request, bool last) { Preconditions.CheckState(request.state == XDR.State.Writing); ByteBuffer b = request.buf.Duplicate(); b.Flip(); byte[] fragmentHeader = XDR.RecordMark(b.Limit(), last); ByteBuffer headerBuf = ByteBuffer.Wrap(fragmentHeader); // TODO: Investigate whether making a copy of the buffer is necessary. return(ChannelBuffers.CopiedBuffer(headerBuf, b)); }
protected internal static void SendRejectedReply(RpcCall call, EndPoint remoteAddress , ChannelHandlerContext ctx) { XDR @out = new XDR(); RpcDeniedReply reply = new RpcDeniedReply(call.GetXid(), RpcReply.ReplyState.MsgDenied , RpcDeniedReply.RejectState.AuthError, new VerifierNone()); reply.Write(@out); ChannelBuffer buf = ChannelBuffers.WrappedBuffer(@out.AsReadOnlyWrap().Buffer()); RpcResponse rsp = new RpcResponse(buf, remoteAddress); RpcUtil.SendRpcResponse(ctx, rsp); }
protected internal virtual void SendError(ChannelHandlerContext ctx, string message , HttpResponseStatus status) { HttpResponse response = new DefaultHttpResponse(HttpVersion.Http11, status); response.SetHeader(HttpHeaders.Names.ContentType, "text/plain; charset=UTF-8"); // Put shuffle version into http header response.SetHeader(ShuffleHeader.HttpHeaderName, ShuffleHeader.DefaultHttpHeaderName ); response.SetHeader(ShuffleHeader.HttpHeaderVersion, ShuffleHeader.DefaultHttpHeaderVersion ); response.SetContent(ChannelBuffers.CopiedBuffer(message, CharsetUtil.Utf8)); // Close the connection as soon as the error message is sent. ctx.GetChannel().Write(response).AddListener(ChannelFutureListener.Close); }
/// <exception cref="System.IO.IOException"/> public virtual void Handle(Org.Jboss.Netty.Channel.Channel channel, Org.Apache.Hadoop.Security.Token.Token <DelegationTokenIdentifier> token, string serviceUrl) { NUnit.Framework.Assert.AreEqual(this._enclosing.testToken, token); byte[] bytes = Sharpen.Runtime.GetBytesForString(TestDelegationTokenRemoteFetcher .ExpDate); ChannelBuffer cbuffer = ChannelBuffers.Buffer(bytes.Length); cbuffer.WriteBytes(bytes); HttpResponse response = new DefaultHttpResponse(HttpVersion.Http11, HttpResponseStatus .Ok); response.SetHeader(HttpHeaders.Names.ContentLength, bytes.Length.ToString()); response.SetContent(cbuffer); channel.Write(response).AddListener(ChannelFutureListener.Close); }
/// <exception cref="System.IO.IOException"/> protected internal virtual ChannelFuture SendMapOutput(ChannelHandlerContext ctx, Org.Jboss.Netty.Channel.Channel ch, string user, string mapId, int reduce, ShuffleHandler.Shuffle.MapOutputInfo mapOutputInfo) { IndexRecord info = mapOutputInfo.indexRecord; ShuffleHeader header = new ShuffleHeader(mapId, info.partLength, info.rawLength, reduce); DataOutputBuffer dob = new DataOutputBuffer(); header.Write(dob); ch.Write(ChannelBuffers.WrappedBuffer(dob.GetData(), 0, dob.GetLength())); FilePath spillfile = new FilePath(mapOutputInfo.mapOutputFileName.ToString()); RandomAccessFile spill; try { spill = SecureIOUtils.OpenForRandomRead(spillfile, "r", user, null); } catch (FileNotFoundException) { ShuffleHandler.Log.Info(spillfile + " not found"); return null; } ChannelFuture writeFuture; if (ch.GetPipeline().Get<SslHandler>() == null) { FadvisedFileRegion partition = new FadvisedFileRegion(spill, info.startOffset, info .partLength, this._enclosing.manageOsCache, this._enclosing.readaheadLength, this ._enclosing.readaheadPool, spillfile.GetAbsolutePath(), this._enclosing.shuffleBufferSize , this._enclosing.shuffleTransferToAllowed); writeFuture = ch.Write(partition); writeFuture.AddListener(new _ChannelFutureListener_1135(partition)); } else { // TODO error handling; distinguish IO/connection failures, // attribute to appropriate spill output // HTTPS cannot be done with zero copy. FadvisedChunkedFile chunk = new FadvisedChunkedFile(spill, info.startOffset, info .partLength, this._enclosing.sslFileBufferSize, this._enclosing.manageOsCache, this ._enclosing.readaheadLength, this._enclosing.readaheadPool, spillfile.GetAbsolutePath ()); writeFuture = ch.Write(chunk); } this._enclosing.metrics.shuffleConnections.Incr(); this._enclosing.metrics.shuffleOutputBytes.Incr(info.partLength); // optimistic return writeFuture; }
/// <exception cref="System.Exception"/> public override void MessageReceived(ChannelHandlerContext ctx, MessageEvent e) { HttpRequest request = (HttpRequest)e.GetMessage(); if (request.GetMethod() == HttpMethod.Options) { // Mimic SPNEGO authentication HttpResponse response = new DefaultHttpResponse(HttpVersion.Http11, HttpResponseStatus .Ok); response.AddHeader("Set-Cookie", "hadoop-auth=1234"); e.GetChannel().Write(response).AddListener(ChannelFutureListener.Close); } else { if (request.GetMethod() != HttpMethod.Get) { e.GetChannel().Close(); } } UnmodifiableIterator <KeyValuePair <string, TestDelegationTokenRemoteFetcher.Handler > > iter = this.routes.GetEnumerator(); while (iter.HasNext()) { KeyValuePair <string, TestDelegationTokenRemoteFetcher.Handler> entry = iter.Next( ); if (request.GetUri().Contains(entry.Key)) { TestDelegationTokenRemoteFetcher.Handler handler = entry.Value; try { handler.Handle(e.GetChannel(), this.token, this.serviceUrl); } catch (Exception ee) { this._enclosing.assertionError = ee; HttpResponse response = new DefaultHttpResponse(HttpVersion.Http11, HttpResponseStatus .BadRequest); response.SetContent(ChannelBuffers.CopiedBuffer(ee.Message, Encoding.Default)); e.GetChannel().Write(response).AddListener(ChannelFutureListener.Close); } return; } } }
private void SendAcceptedReply(RpcCall call, EndPoint remoteAddress, RpcAcceptedReply.AcceptState acceptState, ChannelHandlerContext ctx) { RpcAcceptedReply reply = RpcAcceptedReply.GetInstance(call.GetXid(), acceptState, Verifier.VerifierNone); XDR @out = new XDR(); reply.Write(@out); if (acceptState == RpcAcceptedReply.AcceptState.ProgMismatch) { @out.WriteInt(lowProgVersion); @out.WriteInt(highProgVersion); } ChannelBuffer b = ChannelBuffers.WrappedBuffer(@out.AsReadOnlyWrap().Buffer()); RpcResponse rsp = new RpcResponse(b, remoteAddress); RpcUtil.SendRpcResponse(ctx, rsp); }
protected internal override ChannelContext create() { _outerInstance.msgLog.info(threadInfo() + "Trying to open a new channel from " + _outerInstance.origin + " to " + _outerInstance.destination); // We must specify the origin address in case the server has multiple IPs per interface ChannelFuture channelFuture = _outerInstance.bootstrap.connect(_outerInstance.destination, _outerInstance.origin); channelFuture.awaitUninterruptibly(5, TimeUnit.SECONDS); if (channelFuture.Success) { _outerInstance.msgLog.info(threadInfo() + "Opened a new channel from " + channelFuture.Channel.LocalAddress + " to " + channelFuture.Channel.RemoteAddress); return(new ChannelContext(channelFuture.Channel, ChannelBuffers.dynamicBuffer(), ByteBuffer.allocate(1024 * 1024))); } Exception cause = channelFuture.Cause; string msg = _outerInstance.GetType().Name + " could not connect from " + _outerInstance.origin + " to " + _outerInstance.destination; _outerInstance.msgLog.debug(msg); throw outerInstance.traceComException(new ComException(msg, cause), "Client.start"); }
/// <exception cref="System.IO.IOException"/> public virtual void Handle(Org.Jboss.Netty.Channel.Channel channel, Org.Apache.Hadoop.Security.Token.Token <DelegationTokenIdentifier> token, string serviceUrl) { NUnit.Framework.Assert.AreEqual(this._enclosing.testToken, token); Credentials creds = new Credentials(); creds.AddToken(new Text(serviceUrl), token); DataOutputBuffer @out = new DataOutputBuffer(); creds.Write(@out); int fileLength = @out.GetData().Length; ChannelBuffer cbuffer = ChannelBuffers.Buffer(fileLength); cbuffer.WriteBytes(@out.GetData()); HttpResponse response = new DefaultHttpResponse(HttpVersion.Http11, HttpResponseStatus .Ok); response.SetHeader(HttpHeaders.Names.ContentLength, fileLength.ToString()); response.SetContent(cbuffer); channel.Write(response).AddListener(ChannelFutureListener.Close); }
protected override object Decode(ChannelHandlerContext ctx, Org.Jboss.Netty.Channel.Channel channel, ChannelBuffer buf) { if (buf.ReadableBytes() < 4) { return(null); } buf.MarkReaderIndex(); byte[] fragmentHeader = new byte[4]; buf.ReadBytes(fragmentHeader); int length = XDR.FragmentSize(fragmentHeader); bool isLast = XDR.IsLastFragment(fragmentHeader); if (buf.ReadableBytes() < length) { buf.ResetReaderIndex(); return(null); } ChannelBuffer newFragment = buf.ReadSlice(length); if (currentFrame == null) { currentFrame = newFragment; } else { currentFrame = ChannelBuffers.WrappedBuffer(currentFrame, newFragment); } if (isLast) { ChannelBuffer completeFrame = currentFrame; currentFrame = null; return(completeFrame); } else { return(null); } }
/// <exception cref="System.Exception"/> public override void MessageReceived(ChannelHandlerContext ctx, MessageEvent e) { ChannelBuffer buf = (ChannelBuffer)e.GetMessage(); ByteBuffer b = buf.ToByteBuffer().AsReadOnlyBuffer(); XDR @in = new XDR(b, XDR.State.Reading); RpcInfo info = null; try { RpcCall callHeader = RpcCall.Read(@in); ChannelBuffer dataBuffer = ChannelBuffers.WrappedBuffer(@in.Buffer().Slice()); info = new RpcInfo(callHeader, dataBuffer, ctx, e.GetChannel(), e.GetRemoteAddress ()); } catch (Exception) { Log.Info("Malformed RPC request from " + e.GetRemoteAddress()); } if (info != null) { Channels.FireMessageReceived(ctx, info); } }
protected internal virtual ChannelBuffer NewChannelBuffer() { return(ChannelBuffers.dynamicBuffer(_capacity)); }
/// <summary>Write an XDR message to a UDP ChannelBuffer</summary> public static ChannelBuffer WriteMessageUdp(XDR response) { Preconditions.CheckState(response.state == XDR.State.Reading); // TODO: Investigate whether making a copy of the buffer is necessary. return(ChannelBuffers.CopiedBuffer(response.buf)); }
protected override void HandleInternal(ChannelHandlerContext ctx, RpcInfo info) { RpcCall rpcCall = (RpcCall)info.Header(); MountInterface.MNTPROC mntproc = MountInterface.MNTPROC.FromValue(rpcCall.GetProcedure ()); int xid = rpcCall.GetXid(); byte[] data = new byte[info.Data().ReadableBytes()]; info.Data().ReadBytes(data); XDR xdr = new XDR(data); XDR @out = new XDR(); IPAddress client = ((IPEndPoint)info.RemoteAddress()).Address; if (mntproc == MountInterface.MNTPROC.Null) { @out = NullOp(@out, xid, client); } else { if (mntproc == MountInterface.MNTPROC.Mnt) { // Only do port monitoring for MNT if (!DoPortMonitoring(info.RemoteAddress())) { @out = MountResponse.WriteMNTResponse(Nfs3Status.Nfs3errAcces, @out, xid, null); } else { @out = Mnt(xdr, @out, xid, client); } } else { if (mntproc == MountInterface.MNTPROC.Dump) { @out = Dump(@out, xid, client); } else { if (mntproc == MountInterface.MNTPROC.Umnt) { @out = Umnt(xdr, @out, xid, client); } else { if (mntproc == MountInterface.MNTPROC.Umntall) { Umntall(@out, xid, client); } else { if (mntproc == MountInterface.MNTPROC.Export) { // Currently only support one NFS export IList <NfsExports> hostsMatchers = new AList <NfsExports>(); if (hostsMatcher != null) { hostsMatchers.AddItem(hostsMatcher); @out = MountResponse.WriteExportList(@out, xid, exports, hostsMatchers); } else { // This means there are no valid exports provided. RpcAcceptedReply.GetInstance(xid, RpcAcceptedReply.AcceptState.ProcUnavail, new VerifierNone ()).Write(@out); } } else { // Invalid procedure RpcAcceptedReply.GetInstance(xid, RpcAcceptedReply.AcceptState.ProcUnavail, new VerifierNone ()).Write(@out); } } } } } } ChannelBuffer buf = ChannelBuffers.WrappedBuffer(@out.AsReadOnlyWrap().Buffer()); RpcResponse rsp = new RpcResponse(buf, info.RemoteAddress()); RpcUtil.SendRpcResponse(ctx, rsp); }
private ChunkingChannelBuffer NewChunkingBuffer(Channel channel) { return(NewChunkingBuffer(ChannelBuffers.dynamicBuffer(), channel, _chunkSize, InternalProtocolVersion, _applicationProtocolVersion)); }
/// <exception cref="System.Exception"/> public override void MessageReceived(ChannelHandlerContext ctx, MessageEvent e) { RpcInfo info = (RpcInfo)e.GetMessage(); RpcCall rpcCall = (RpcCall)info.Header(); int portmapProc = rpcCall.GetProcedure(); int xid = rpcCall.GetXid(); XDR @in = new XDR(info.Data().ToByteBuffer().AsReadOnlyBuffer(), XDR.State.Reading ); XDR @out = new XDR(); if (portmapProc == PmapprocNull) { @out = NullOp(xid, @in, @out); } else { if (portmapProc == PmapprocSet) { @out = Set(xid, @in, @out); } else { if (portmapProc == PmapprocUnset) { @out = Unset(xid, @in, @out); } else { if (portmapProc == PmapprocDump) { @out = Dump(xid, @in, @out); } else { if (portmapProc == PmapprocGetport) { @out = Getport(xid, @in, @out); } else { if (portmapProc == PmapprocGetversaddr) { @out = Getport(xid, @in, @out); } else { Log.Info("PortmapHandler unknown rpc procedure=" + portmapProc); RpcAcceptedReply reply = RpcAcceptedReply.GetInstance(xid, RpcAcceptedReply.AcceptState .ProcUnavail, new VerifierNone()); reply.Write(@out); } } } } } } ChannelBuffer buf = ChannelBuffers.WrappedBuffer(@out.AsReadOnlyWrap().Buffer()); RpcResponse rsp = new RpcResponse(buf, info.RemoteAddress()); RpcUtil.SendRpcResponse(ctx, rsp); }