// parse the message and extract the name of the exception and the message
        private static IOException GetExceptionFromResponse(HttpURLConnection con)
        {
            IOException e = null;
            string      resp;

            if (con == null)
            {
                return(null);
            }
            try
            {
                resp = con.GetResponseMessage();
            }
            catch (IOException)
            {
                return(null);
            }
            if (resp == null || resp.IsEmpty())
            {
                return(null);
            }
            string exceptionClass = string.Empty;
            string exceptionMsg   = string.Empty;

            string[] rs = resp.Split(";");
            if (rs.Length < 2)
            {
                return(null);
            }
            exceptionClass = rs[0];
            exceptionMsg   = rs[1];
            Log.Info("Error response from HTTP request=" + resp + ";ec=" + exceptionClass + ";em="
                     + exceptionMsg);
            if (exceptionClass == null || exceptionClass.IsEmpty())
            {
                return(null);
            }
            // recreate exception objects
            try
            {
                Type ec = Sharpen.Runtime.GetType(exceptionClass).AsSubclass <Exception>();
                // we are interested in constructor with String arguments
                Constructor <Exception> constructor = ec.GetConstructor(new Type[] { typeof(string
                                                                                            ) });
                // create an instance
                e = (IOException)constructor.NewInstance(exceptionMsg);
            }
            catch (Exception ee)
            {
                Log.Warn("failed to create object of this class", ee);
            }
            if (e == null)
            {
                return(null);
            }
            e.SetStackTrace(new StackTraceElement[0]);
            // local stack is not relevant
            Log.Info("Exception from HTTP response=" + e.GetLocalizedMessage());
            return(e);
        }
Esempio n. 2
0
        /// <summary>
        /// Helper function to encode the URL of the filename of the job-history
        /// log file.
        /// </summary>
        /// <param name="logFileName">file name of the job-history file</param>
        /// <returns>URL encoded filename</returns>
        /// <exception cref="System.IO.IOException"/>
        public static string EncodeJobHistoryFileName(string logFileName)
        {
            string replacementDelimiterEscape = null;

            // Temporarily protect the escape delimiters from encoding
            if (logFileName.Contains(DelimiterEscape))
            {
                replacementDelimiterEscape = NonOccursString(logFileName);
                logFileName = logFileName.ReplaceAll(DelimiterEscape, replacementDelimiterEscape);
            }
            string encodedFileName = null;

            try
            {
                encodedFileName = URLEncoder.Encode(logFileName, "UTF-8");
            }
            catch (UnsupportedEncodingException uee)
            {
                IOException ioe = new IOException();
                Sharpen.Extensions.InitCause(ioe, uee);
                ioe.SetStackTrace(uee.GetStackTrace());
                throw ioe;
            }
            // Restore protected escape delimiters after encoding
            if (replacementDelimiterEscape != null)
            {
                encodedFileName = encodedFileName.ReplaceAll(replacementDelimiterEscape, DelimiterEscape
                                                             );
            }
            return(encodedFileName);
        }
Esempio n. 3
0
        /// <summary>
        /// Helper function to decode the URL of the filename of the job-history
        /// log file.
        /// </summary>
        /// <param name="logFileName">file name of the job-history file</param>
        /// <returns>URL decoded filename</returns>
        /// <exception cref="System.IO.IOException"/>
        public static string DecodeJobHistoryFileName(string logFileName)
        {
            string decodedFileName = null;

            try
            {
                decodedFileName = URLDecoder.Decode(logFileName, "UTF-8");
            }
            catch (UnsupportedEncodingException uee)
            {
                IOException ioe = new IOException();
                Sharpen.Extensions.InitCause(ioe, uee);
                ioe.SetStackTrace(uee.GetStackTrace());
                throw ioe;
            }
            return(decodedFileName);
        }
Esempio n. 4
0
                /// <exception cref="System.IO.IOException"/>
                /// <exception cref="Org.Apache.Hadoop.Ipc.RPC.VersionMismatch"/>
                public virtual IWritable Call(RPC.Server server, string protocolName, IWritable rpcRequest
                                              , long receivedTime)
                {
                    WritableRpcEngine.Invocation call = (WritableRpcEngine.Invocation)rpcRequest;
                    if (server.verbose)
                    {
                        Log("Call: " + call);
                    }
                    // Verify writable rpc version
                    if (call.GetRpcVersion() != writableRpcVersion)
                    {
                        // Client is using a different version of WritableRpc
                        throw new RpcServerException("WritableRpc version mismatch, client side version="
                                                     + call.GetRpcVersion() + ", server side version=" + writableRpcVersion);
                    }
                    long   clientVersion = call.GetProtocolVersion();
                    string protoName;

                    RPC.Server.ProtoClassProtoImpl protocolImpl;
                    if (call.declaringClassProtocolName.Equals(typeof(VersionedProtocol).FullName))
                    {
                        // VersionProtocol methods are often used by client to figure out
                        // which version of protocol to use.
                        //
                        // Versioned protocol methods should go the protocolName protocol
                        // rather than the declaring class of the method since the
                        // the declaring class is VersionedProtocol which is not
                        // registered directly.
                        // Send the call to the highest  protocol version
                        RPC.Server.VerProtocolImpl highest = server.GetHighestSupportedProtocol(RPC.RpcKind
                                                                                                .RpcWritable, protocolName);
                        if (highest == null)
                        {
                            throw new RpcServerException("Unknown protocol: " + protocolName);
                        }
                        protocolImpl = highest.protocolTarget;
                    }
                    else
                    {
                        protoName = call.declaringClassProtocolName;
                        // Find the right impl for the protocol based on client version.
                        RPC.Server.ProtoNameVer pv = new RPC.Server.ProtoNameVer(call.declaringClassProtocolName
                                                                                 , clientVersion);
                        protocolImpl = server.GetProtocolImplMap(RPC.RpcKind.RpcWritable)[pv];
                        if (protocolImpl == null)
                        {
                            // no match for Protocol AND Version
                            RPC.Server.VerProtocolImpl highest = server.GetHighestSupportedProtocol(RPC.RpcKind
                                                                                                    .RpcWritable, protoName);
                            if (highest == null)
                            {
                                throw new RpcServerException("Unknown protocol: " + protoName);
                            }
                            else
                            {
                                // protocol supported but not the version that client wants
                                throw new RPC.VersionMismatch(protoName, clientVersion, highest.version);
                            }
                        }
                    }
                    // Invoke the protocol method
                    long      startTime = Time.Now();
                    int       qTime     = (int)(startTime - receivedTime);
                    Exception exception = null;

                    try
                    {
                        MethodInfo method = protocolImpl.protocolClass.GetMethod(call.GetMethodName(), call
                                                                                 .GetParameterClasses());
                        server.rpcDetailedMetrics.Init(protocolImpl.protocolClass);
                        object value = method.Invoke(protocolImpl.protocolImpl, call.GetParameters());
                        if (server.verbose)
                        {
                            Log("Return: " + value);
                        }
                        return(new ObjectWritable(method.ReturnType, value));
                    }
                    catch (TargetInvocationException e)
                    {
                        Exception target = e.InnerException;
                        if (target is IOException)
                        {
                            exception = (IOException)target;
                            throw (IOException)target;
                        }
                        else
                        {
                            IOException ioe = new IOException(target.ToString());
                            ioe.SetStackTrace(target.GetStackTrace());
                            exception = ioe;
                            throw ioe;
                        }
                    }
                    catch (Exception e)
                    {
                        if (!(e is IOException))
                        {
                            Log.Error("Unexpected throwable object ", e);
                        }
                        IOException ioe = new IOException(e.ToString());
                        ioe.SetStackTrace(e.GetStackTrace());
                        exception = ioe;
                        throw ioe;
                    }
                    finally
                    {
                        int processingTime = (int)(Time.Now() - startTime);
                        if (Log.IsDebugEnabled())
                        {
                            string msg = "Served: " + call.GetMethodName() + " queueTime= " + qTime + " procesingTime= "
                                         + processingTime;
                            if (exception != null)
                            {
                                msg += " exception= " + exception.GetType().Name;
                            }
                            Log.Debug(msg);
                        }
                        string detailedMetricsName = (exception == null) ? call.GetMethodName() : exception
                                                     .GetType().Name;
                        server.rpcMetrics.AddRpcQueueTime(qTime);
                        server.rpcMetrics.AddRpcProcessingTime(processingTime);
                        server.rpcDetailedMetrics.AddProcessingTime(detailedMetricsName, processingTime);
                    }
                }