Exemplo n.º 1
0
        public virtual void Run()
        {
            // Configure the Server.
            ChannelFactory factory;

            if (workerCount == 0)
            {
                // Use default workers: 2 * the number of available processors
                factory = new NioServerSocketChannelFactory(Executors.NewCachedThreadPool(), Executors
                                                            .NewCachedThreadPool());
            }
            else
            {
                factory = new NioServerSocketChannelFactory(Executors.NewCachedThreadPool(), Executors
                                                            .NewCachedThreadPool(), workerCount);
            }
            server = new ServerBootstrap(factory);
            server.SetPipelineFactory(new _ChannelPipelineFactory_73(this));
            server.SetOption("child.tcpNoDelay", true);
            server.SetOption("child.keepAlive", true);
            // Listen to TCP port
            ch = server.Bind(new IPEndPoint(port));
            IPEndPoint socketAddr = (IPEndPoint)ch.GetLocalAddress();

            boundPort = socketAddr.Port;
            Log.Info("Started listening to TCP requests at port " + boundPort + " for " + rpcProgram
                     + " with workerCount " + workerCount);
        }
Exemplo n.º 2
0
		// TODO change AbstractService to throw InterruptedException
		/// <exception cref="System.Exception"/>
		protected override void ServiceStart()
		{
			Configuration conf = GetConfig();
			userRsrc = new ConcurrentHashMap<string, string>();
			secretManager = new JobTokenSecretManager();
			RecoverState(conf);
			ServerBootstrap bootstrap = new ServerBootstrap(selector);
			try
			{
				pipelineFact = new ShuffleHandler.HttpPipelineFactory(this, conf);
			}
			catch (Exception ex)
			{
				throw new RuntimeException(ex);
			}
			bootstrap.SetOption("child.keepAlive", true);
			bootstrap.SetPipelineFactory(pipelineFact);
			port = conf.GetInt(ShufflePortConfigKey, DefaultShufflePort);
			Org.Jboss.Netty.Channel.Channel ch = bootstrap.Bind(new IPEndPoint(port));
			accepted.AddItem(ch);
			port = ((IPEndPoint)ch.GetLocalAddress()).Port;
			conf.Set(ShufflePortConfigKey, Sharpen.Extensions.ToString(port));
			pipelineFact.Shuffle.SetPort(port);
			Log.Info(GetName() + " listening on port " + port);
			base.ServiceStart();
			sslFileBufferSize = conf.GetInt(SuffleSslFileBufferSizeKey, DefaultSuffleSslFileBufferSize
				);
			connectionKeepAliveEnabled = conf.GetBoolean(ShuffleConnectionKeepAliveEnabled, DefaultShuffleConnectionKeepAliveEnabled
				);
			connectionKeepAliveTimeOut = Math.Max(1, conf.GetInt(ShuffleConnectionKeepAliveTimeOut
				, DefaultShuffleConnectionKeepAliveTimeOut));
			mapOutputMetaInfoCacheSize = Math.Max(1, conf.GetInt(ShuffleMapoutputMetaInfoCacheSize
				, DefaultShuffleMapoutputMetaInfoCacheSize));
		}
Exemplo n.º 3
0
			/// <exception cref="System.Exception"/>
			public override void ExceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
			{
				Org.Jboss.Netty.Channel.Channel ch = e.GetChannel();
				Exception cause = e.GetCause();
				if (cause is TooLongFrameException)
				{
					this.SendError(ctx, HttpResponseStatus.BadRequest);
					return;
				}
				else
				{
					if (cause is IOException)
					{
						if (cause is ClosedChannelException)
						{
							ShuffleHandler.Log.Debug("Ignoring closed channel error", cause);
							return;
						}
						string message = cause.Message.ToString();
						if (ShuffleHandler.IgnorableErrorMessage.Matcher(message).Matches())
						{
							ShuffleHandler.Log.Debug("Ignoring client socket close", cause);
							return;
						}
					}
				}
				ShuffleHandler.Log.Error("Shuffle error: ", cause);
				if (ch.IsConnected())
				{
					ShuffleHandler.Log.Error("Shuffle error " + e);
					this.SendError(ctx, HttpResponseStatus.InternalServerError);
				}
			}
Exemplo n.º 4
0
 public RpcInfo(RpcMessage header, ChannelBuffer data, ChannelHandlerContext channelContext
                , Org.Jboss.Netty.Channel.Channel channel, EndPoint remoteAddress)
 {
     this.header        = header;
     this.data          = data;
     this.channel       = channel;
     this.remoteAddress = remoteAddress;
 }
            /// <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);
                HttpResponse response = new DefaultHttpResponse(HttpVersion.Http11, HttpResponseStatus
                                                                .Ok);

                channel.Write(response).AddListener(ChannelFutureListener.Close);
            }
            /// <exception cref="System.Exception"/>
            public override void ExceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
            {
                Org.Jboss.Netty.Channel.Channel ch = e.GetChannel();
                Exception cause = e.GetCause();

                if (TestDelegationTokenRemoteFetcher.Log.IsDebugEnabled())
                {
                    TestDelegationTokenRemoteFetcher.Log.Debug(cause.Message);
                }
                ch.Close().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);
            }
Exemplo n.º 8
0
			/// <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;
			}
Exemplo n.º 9
0
 internal void Start(int idleTimeMilliSeconds, EndPoint tcpAddress, EndPoint udpAddress
                     )
 {
     tcpServer = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.NewCachedThreadPool
                                                                           (), Executors.NewCachedThreadPool()));
     tcpServer.SetPipelineFactory(new _ChannelPipelineFactory_100(this, idleTimeMilliSeconds
                                                                  ));
     udpServer = new ConnectionlessBootstrap(new NioDatagramChannelFactory(Executors.NewCachedThreadPool
                                                                               ()));
     udpServer.SetPipeline(Channels.Pipeline(RpcUtil.StageRpcMessageParser, handler, RpcUtil
                                             .StageRpcUdpResponse));
     tcpChannel = tcpServer.Bind(tcpAddress);
     udpChannel = udpServer.Bind(udpAddress);
     allChannels.AddItem(tcpChannel);
     allChannels.AddItem(udpChannel);
     Log.Info("Portmap server started at tcp://" + tcpChannel.GetLocalAddress() + ", udp://"
              + udpChannel.GetLocalAddress());
 }
Exemplo n.º 10
0
        public virtual void Run()
        {
            // Configure the client.
            DatagramChannelFactory f = new NioDatagramChannelFactory(Executors.NewCachedThreadPool
                                                                         (), workerCount);

            server = new ConnectionlessBootstrap(f);
            server.SetPipeline(Channels.Pipeline(RpcUtil.StageRpcMessageParser, rpcProgram, RpcUtil
                                                 .StageRpcUdpResponse));
            server.SetOption("broadcast", "false");
            server.SetOption("sendBufferSize", SendBufferSize);
            server.SetOption("receiveBufferSize", ReceiveBufferSize);
            // Listen to the UDP port
            ch = server.Bind(new IPEndPoint(port));
            IPEndPoint socketAddr = (IPEndPoint)ch.GetLocalAddress();

            boundPort = socketAddr.Port;
            Log.Info("Started listening to UDP requests at port " + boundPort + " for " + rpcProgram
                     + " with workerCount " + workerCount);
        }
            /// <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);
            }
Exemplo n.º 12
0
            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);
                }
            }
Exemplo n.º 13
0
			/// <exception cref="System.Exception"/>
			public override void MessageReceived(ChannelHandlerContext ctx, MessageEvent evt)
			{
				HttpRequest request = (HttpRequest)evt.GetMessage();
				if (request.GetMethod() != HttpMethod.Get)
				{
					this.SendError(ctx, HttpResponseStatus.MethodNotAllowed);
					return;
				}
				// Check whether the shuffle version is compatible
				if (!ShuffleHeader.DefaultHttpHeaderName.Equals(request.GetHeader(ShuffleHeader.HttpHeaderName
					)) || !ShuffleHeader.DefaultHttpHeaderVersion.Equals(request.GetHeader(ShuffleHeader
					.HttpHeaderVersion)))
				{
					this.SendError(ctx, "Incompatible shuffle request version", HttpResponseStatus.BadRequest
						);
				}
				IDictionary<string, IList<string>> q = new QueryStringDecoder(request.GetUri()).GetParameters
					();
				IList<string> keepAliveList = q["keepAlive"];
				bool keepAliveParam = false;
				if (keepAliveList != null && keepAliveList.Count == 1)
				{
					keepAliveParam = Sharpen.Extensions.ValueOf(keepAliveList[0]);
					if (ShuffleHandler.Log.IsDebugEnabled())
					{
						ShuffleHandler.Log.Debug("KeepAliveParam : " + keepAliveList + " : " + keepAliveParam
							);
					}
				}
				IList<string> mapIds = this.SplitMaps(q["map"]);
				IList<string> reduceQ = q["reduce"];
				IList<string> jobQ = q["job"];
				if (ShuffleHandler.Log.IsDebugEnabled())
				{
					ShuffleHandler.Log.Debug("RECV: " + request.GetUri() + "\n  mapId: " + mapIds + "\n  reduceId: "
						 + reduceQ + "\n  jobId: " + jobQ + "\n  keepAlive: " + keepAliveParam);
				}
				if (mapIds == null || reduceQ == null || jobQ == null)
				{
					this.SendError(ctx, "Required param job, map and reduce", HttpResponseStatus.BadRequest
						);
					return;
				}
				if (reduceQ.Count != 1 || jobQ.Count != 1)
				{
					this.SendError(ctx, "Too many job/reduce parameters", HttpResponseStatus.BadRequest
						);
					return;
				}
				int reduceId;
				string jobId;
				try
				{
					reduceId = System.Convert.ToInt32(reduceQ[0]);
					jobId = jobQ[0];
				}
				catch (FormatException)
				{
					this.SendError(ctx, "Bad reduce parameter", HttpResponseStatus.BadRequest);
					return;
				}
				catch (ArgumentException)
				{
					this.SendError(ctx, "Bad job parameter", HttpResponseStatus.BadRequest);
					return;
				}
				string reqUri = request.GetUri();
				if (null == reqUri)
				{
					// TODO? add upstream?
					this.SendError(ctx, HttpResponseStatus.Forbidden);
					return;
				}
				HttpResponse response = new DefaultHttpResponse(HttpVersion.Http11, HttpResponseStatus
					.Ok);
				try
				{
					this.VerifyRequest(jobId, ctx, request, response, new Uri("http", string.Empty, this
						.port, reqUri));
				}
				catch (IOException e)
				{
					ShuffleHandler.Log.Warn("Shuffle failure ", e);
					this.SendError(ctx, e.Message, HttpResponseStatus.Unauthorized);
					return;
				}
				IDictionary<string, ShuffleHandler.Shuffle.MapOutputInfo> mapOutputInfoMap = new 
					Dictionary<string, ShuffleHandler.Shuffle.MapOutputInfo>();
				Org.Jboss.Netty.Channel.Channel ch = evt.GetChannel();
				string user = this._enclosing.userRsrc[jobId];
				// $x/$user/appcache/$appId/output/$mapId
				// TODO: Once Shuffle is out of NM, this can use MR APIs to convert
				// between App and Job
				string outputBasePathStr = this.GetBaseLocation(jobId, user);
				try
				{
					this.PopulateHeaders(mapIds, outputBasePathStr, user, reduceId, request, response
						, keepAliveParam, mapOutputInfoMap);
				}
				catch (IOException e)
				{
					ch.Write(response);
					ShuffleHandler.Log.Error("Shuffle error in populating headers :", e);
					string errorMessage = this.GetErrorMessage(e);
					this.SendError(ctx, errorMessage, HttpResponseStatus.InternalServerError);
					return;
				}
				ch.Write(response);
				//Initialize one ReduceContext object per messageReceived call
				ShuffleHandler.ReduceContext reduceContext = new ShuffleHandler.ReduceContext(mapIds
					, reduceId, ctx, user, mapOutputInfoMap, outputBasePathStr);
				for (int i = 0; i < Math.Min(this._enclosing.maxSessionOpenFiles, mapIds.Count); 
					i++)
				{
					ChannelFuture nextMap = this.SendMap(reduceContext);
					if (nextMap == null)
					{
						return;
					}
				}
			}