Search in sources :

Example 16 with Exception

use of java.lang.Exception in project commons by twitter.

the class ExceptionHandlingScheduledExecutorServiceTest method setUp.

@Before
public void setUp() throws Exception {
    signallingHandler = createMock(Thread.UncaughtExceptionHandler.class);
    executorService = MoreExecutors.exceptionHandlingExecutor(Executors.newSingleThreadScheduledExecutor(), signallingHandler);
    final ExecutorServiceShutdown executorServiceShutdown = new ExecutorServiceShutdown(executorService, Amount.of(3L, Time.SECONDS));
    addTearDown(new TearDown() {

        @Override
        public void tearDown() throws Exception {
            executorServiceShutdown.execute();
        }
    });
}
Also used : TearDown(com.google.common.testing.TearDown) IllegalArgumentException(java.lang.IllegalArgumentException) Exception(java.lang.Exception) NullPointerException(java.lang.NullPointerException) ExecutionException(java.util.concurrent.ExecutionException) Before(org.junit.Before)

Example 17 with Exception

use of java.lang.Exception in project hive by apache.

the class JobDebugger method showJobFailDebugInfo.

private String showJobFailDebugInfo() throws IOException {
    console.printError("Error during job, obtaining debugging information...");
    if (!conf.get("mapred.job.tracker", "local").equals("local")) {
        // Show Tracking URL for remotely running jobs.
        console.printError("Job Tracking URL: " + rj.getTrackingURL());
    }
    // Loop to get all task completion events because getTaskCompletionEvents
    // only returns a subset per call
    TaskInfoGrabber tlg = new TaskInfoGrabber();
    Thread t = new Thread(tlg);
    try {
        t.start();
        t.join(HiveConf.getIntVar(conf, HiveConf.ConfVars.TASKLOG_DEBUG_TIMEOUT));
    } catch (InterruptedException e) {
        console.printError("Timed out trying to finish grabbing task log URLs, " + "some task info may be missing");
    }
    // Remove failures for tasks that succeeded
    for (String task : successes) {
        failures.remove(task);
    }
    if (failures.keySet().size() == 0) {
        return null;
    }
    // Find the highest failure count
    computeMaxFailures();
    // Display Error Message for tasks with the highest failure count
    String jtUrl = null;
    try {
        jtUrl = JobTrackerURLResolver.getURL(conf);
    } catch (Exception e) {
        console.printError("Unable to retrieve URL for Hadoop Task logs. " + e.getMessage());
    }
    String msg = null;
    for (String task : failures.keySet()) {
        if (failures.get(task).intValue() == maxFailures) {
            TaskInfo ti = taskIdToInfo.get(task);
            String jobId = ti.getJobId();
            String taskUrl = (jtUrl == null) ? null : jtUrl + "/taskdetails.jsp?jobid=" + jobId + "&tipid=" + task.toString();
            TaskLogProcessor tlp = new TaskLogProcessor(conf);
            for (String logUrl : ti.getLogUrls()) {
                tlp.addTaskAttemptLogUrl(logUrl);
            }
            if (HiveConf.getBoolVar(conf, HiveConf.ConfVars.JOB_DEBUG_CAPTURE_STACKTRACES) && stackTraces != null) {
                if (!stackTraces.containsKey(jobId)) {
                    stackTraces.put(jobId, new ArrayList<List<String>>());
                }
                stackTraces.get(jobId).addAll(tlp.getStackTraces());
            }
            if (HiveConf.getBoolVar(conf, HiveConf.ConfVars.SHOW_JOB_FAIL_DEBUG_INFO)) {
                List<ErrorAndSolution> errors = tlp.getErrors();
                StringBuilder sb = new StringBuilder();
                // We use a StringBuilder and then call printError only once as
                // printError will write to both stderr and the error log file. In
                // situations where both the stderr and the log file output is
                // simultaneously output to a single stream, this will look cleaner.
                sb.append("\n");
                sb.append("Task with the most failures(" + maxFailures + "): \n");
                sb.append("-----\n");
                sb.append("Task ID:\n  " + task + "\n\n");
                if (taskUrl != null) {
                    sb.append("URL:\n  " + taskUrl + "\n");
                }
                for (ErrorAndSolution e : errors) {
                    sb.append("\n");
                    sb.append("Possible error:\n  " + e.getError() + "\n\n");
                    sb.append("Solution:\n  " + e.getSolution() + "\n");
                }
                sb.append("-----\n");
                sb.append("Diagnostic Messages for this Task:\n");
                String[] diagMesgs = ti.getDiagnosticMesgs();
                for (String mesg : diagMesgs) {
                    sb.append(mesg + "\n");
                }
                msg = sb.toString();
                console.printError(msg);
            }
            // Only print out one task because that's good enough for debugging.
            break;
        }
    }
    return msg;
}
Also used : MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) Exception(java.lang.Exception) ErrorAndSolution(org.apache.hadoop.hive.ql.exec.errors.ErrorAndSolution) TaskLogProcessor(org.apache.hadoop.hive.ql.exec.errors.TaskLogProcessor) ArrayList(java.util.ArrayList) List(java.util.List)

Example 18 with Exception

use of java.lang.Exception in project clojure by clojure.

the class LispReader method read.

private static Object read(PushbackReader r, boolean eofIsError, Object eofValue, Character returnOn, Object returnOnValue, boolean isRecursive, Object opts, Object pendingForms) {
    if (RT.READEVAL.deref() == UNKNOWN)
        throw Util.runtimeException("Reading disallowed - *read-eval* bound to :unknown");
    opts = installPlatformFeature(opts);
    try {
        for (; ; ) {
            if (pendingForms instanceof List && !((List) pendingForms).isEmpty())
                return ((List) pendingForms).remove(0);
            int ch = read1(r);
            while (isWhitespace(ch)) ch = read1(r);
            if (ch == -1) {
                if (eofIsError)
                    throw Util.runtimeException("EOF while reading");
                return eofValue;
            }
            if (returnOn != null && (returnOn.charValue() == ch)) {
                return returnOnValue;
            }
            if (Character.isDigit(ch)) {
                Object n = readNumber(r, (char) ch);
                return n;
            }
            IFn macroFn = getMacro(ch);
            if (macroFn != null) {
                Object ret = macroFn.invoke(r, (char) ch, opts, pendingForms);
                //no op macros return the reader
                if (ret == r)
                    continue;
                return ret;
            }
            if (ch == '+' || ch == '-') {
                int ch2 = read1(r);
                if (Character.isDigit(ch2)) {
                    unread(r, ch2);
                    Object n = readNumber(r, (char) ch);
                    return n;
                }
                unread(r, ch2);
            }
            String token = readToken(r, (char) ch);
            return interpretToken(token);
        }
    } catch (Exception e) {
        if (isRecursive || !(r instanceof LineNumberingPushbackReader))
            throw Util.sneakyThrow(e);
        LineNumberingPushbackReader rdr = (LineNumberingPushbackReader) r;
        //throw Util.runtimeException(String.format("ReaderError:(%d,1) %s", rdr.getLineNumber(), e.getMessage()), e);
        throw new ReaderException(rdr.getLineNumber(), rdr.getColumnNumber(), e);
    }
}
Also used : ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Object(java.lang.Object) String(java.lang.String) IllegalStateException(java.lang.IllegalStateException) UnsupportedOperationException(java.lang.UnsupportedOperationException) IOException(java.io.IOException) NumberFormatException(java.lang.NumberFormatException) RuntimeException(java.lang.RuntimeException) IllegalArgumentException(java.lang.IllegalArgumentException) Exception(java.lang.Exception)

Example 19 with Exception

use of java.lang.Exception in project OpenAM by OpenRock.

the class ValidateURL method isServerURLValidInternal.

/*
     * Checks if server url is valid
     * 
     * @param url @param props @param state
     * 
     * @return ValidationResult
     */
private ValidationResult isServerURLValidInternal(String url, Map props, IStateAccess state) {
    LocalizedMessage returnMessage = null;
    ValidationResultStatus validRes = ValidationResultStatus.STATUS_FAILED;
    boolean invalidDeploymentURI = false;
    try {
        URL serverUrl = new URL(url);
        String protocol = serverUrl.getProtocol();
        String hostName = serverUrl.getHost();
        int portNum = serverUrl.getPort();
        if (portNum == -1) {
            if (protocol.equals("http")) {
                portNum = 80;
            } else if (protocol.equals("https")) {
                portNum = 443;
            }
        }
        String sPortNum = new Integer(portNum).toString();
        String deploymentURI = serverUrl.getPath();
        if (deploymentURI.length() > 0) {
            Map tokens = state.getData();
            tokens.put("AM_SERVICES_PROTO", protocol);
            tokens.put("AM_SERVICES_HOST", hostName);
            tokens.put("AM_SERVICES_PORT", sPortNum);
            tokens.put("AM_SERVICES_DEPLOY_URI", deploymentURI);
            state.putData(tokens);
            // Establish the connection
            URLConnection urlConnect = serverUrl.openConnection();
            urlConnect.connect();
            returnMessage = LocalizedMessage.get(LOC_VA_MSG_VAL_SERVER_URL, new Object[] { url });
            state.put("isServerURLValid", "true");
            validRes = ValidationResultStatus.STATUS_SUCCESS;
        } else {
            invalidDeploymentURI = true;
            validRes = ValidationResultStatus.STATUS_FAILED;
            returnMessage = LocalizedMessage.get(LOC_VA_MSG_IN_VAL_DEPLOYMENT_URI, new Object[] { url });
        }
    } catch (UnknownHostException uhe) {
        Debug.log("ValidateURL.isServerUrlValid threw exception :", uhe);
        returnMessage = LocalizedMessage.get(LOC_VA_WRN_UN_REACHABLE_SERVER_URL, new Object[] { url });
        state.put("isServerURLValid", "false");
        validRes = ValidationResultStatus.STATUS_WARNING;
    } catch (ConnectException ce) {
        Debug.log("ValidateURL.isServerUrlValid threw exception :", ce);
        returnMessage = LocalizedMessage.get(LOC_VA_WRN_UN_REACHABLE_SERVER_URL, new Object[] { url });
        state.put("isServerURLValid", "false");
        validRes = ValidationResultStatus.STATUS_WARNING;
    } catch (Exception e) {
        if (url.toLowerCase().startsWith("https")) {
            Debug.log("ValidateURL.isServerUrlValid threw exception :", e);
            returnMessage = LocalizedMessage.get(LOC_VA_WRN_UN_REACHABLE_SSL_SERVER_URL, new Object[] { url });
            state.put("isServerURLValid", "false");
            validRes = ValidationResultStatus.STATUS_WARNING;
        } else {
            Debug.log("ValidateURL.isServerUrlValid threw exception :", e);
        }
    }
    if (validRes.getIntValue() == ValidationResultStatus.INT_STATUS_FAILED) {
        if (!invalidDeploymentURI) {
            returnMessage = LocalizedMessage.get(LOC_VA_WRN_IN_VAL_SERVER_URL, new Object[] { url });
        }
    }
    return new ValidationResult(validRes, null, returnMessage);
}
Also used : UnknownHostException(java.net.UnknownHostException) URL(java.net.URL) URLConnection(java.net.URLConnection) MalformedURLException(java.net.MalformedURLException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) Exception(java.lang.Exception) Map(java.util.Map) LocalizedMessage(com.sun.identity.install.tools.util.LocalizedMessage) ConnectException(java.net.ConnectException)

Example 20 with Exception

use of java.lang.Exception in project jdk8u_jdk by JetBrains.

the class MSOID method main.

public static void main(String[] args) throws Exception {
    // msoid.txt is a NegTokenInit packet sent from Internet Explorer to
    // IIS server on a test machine. No sensitive info included.
    byte[] header = Files.readAllBytes(Paths.get(System.getProperty("test.src"), "msoid.txt"));
    byte[] token = Base64.getMimeDecoder().decode(Arrays.copyOfRange(header, 10, header.length));
    GSSCredential cred = null;
    GSSContext ctx = GSSManager.getInstance().createContext(cred);
    try {
        ctx.acceptSecContext(token, 0, token.length);
        // and acceptor chooses another mech and goes on
        throw new Exception("Should fail");
    } catch (GSSException gsse) {
        // After the fix, GSS_KRB5_MECH_OID_MS is recognized but the token
        // cannot be accepted because we don't have any krb5 credential.
        gsse.printStackTrace();
        if (gsse.getMajor() != GSSException.NO_CRED) {
            throw gsse;
        }
        for (StackTraceElement st : gsse.getStackTrace()) {
            if (st.getClassName().startsWith("sun.security.jgss.krb5.")) {
                // Good, it is already in krb5 mech's hand.
                return;
            }
        }
        throw gsse;
    }
}
Also used : GSSException(org.ietf.jgss.GSSException) GSSCredential(org.ietf.jgss.GSSCredential) GSSContext(org.ietf.jgss.GSSContext) GSSException(org.ietf.jgss.GSSException) Exception(java.lang.Exception)

Aggregations

Exception (java.lang.Exception)32 IOException (java.io.IOException)15 ParseException (java.text.ParseException)12 Test (org.junit.Test)12 String (java.lang.String)11 SQLException (java.sql.SQLException)11 SQLTimeoutException (java.sql.SQLTimeoutException)11 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)11 ExpectedException (org.junit.rules.ExpectedException)11 PreparedStatement (java.sql.PreparedStatement)8 ResultSet (java.sql.ResultSet)7 RuntimeException (java.lang.RuntimeException)6 Statement (java.sql.Statement)6 ArrayList (java.util.ArrayList)5 IllegalArgumentException (java.lang.IllegalArgumentException)4 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)3 IllegalStateException (java.lang.IllegalStateException)3 NumberFormatException (java.lang.NumberFormatException)3 Object (java.lang.Object)3