Search in sources :

Example 1 with SerializationException

use of dmg.cells.nucleus.SerializationException in project dcache by dCache.

the class AnsiTerminalCommand method runAsciiMode.

private void runAsciiMode() throws IOException {
    Ansi.setEnabled(_useColors);
    while (true) {
        String prompt = Ansi.ansi().bold().a(_userAdminShell.getPrompt()).boldOff().toString();
        Object result;
        try {
            String str = _console.readLine(prompt);
            try {
                if (str == null) {
                    throw new CommandExitException();
                }
                result = _userAdminShell.executeCommand(str);
            } catch (IllegalArgumentException e) {
                result = e.toString();
            } catch (SerializationException e) {
                result = "There is a bug here, please report to support@dcache.org";
                LOGGER.error("This must be a bug, please report to support@dcache.org.", e);
            } catch (CommandSyntaxException e) {
                result = e;
            } catch (CommandExitException e) {
                break;
            } catch (CommandPanicException e) {
                result = "Command '" + str + "' triggered a bug (" + e.getTargetException() + "); the service log file contains additional information. Please " + "contact support@dcache.org.";
            } catch (CommandException e) {
                result = e.getMessage();
            } catch (NoRouteToCellException e) {
                result = "Cell name does not exist or cell is not started: " + e.getMessage();
                LOGGER.warn("The cell the command was sent to is no " + "longer there: {}", e.getMessage());
            } catch (RuntimeException e) {
                result = String.format("Command '%s' triggered a bug (%s); please" + " locate this message in the log file of the admin service and" + " send an email to support@dcache.org with this line and the" + " following stack-trace", str, e);
                LOGGER.error((String) result, e);
            }
        } catch (InterruptedIOException e) {
            _console.getCursorBuffer().clear();
            _console.println();
            result = null;
        } catch (InterruptedException e) {
            _console.println("^C");
            _console.flush();
            _console.getCursorBuffer().clear();
            result = null;
        } catch (IOException e) {
            throw e;
        } catch (Exception e) {
            result = e.getMessage();
            if (result == null) {
                result = e.getClass().getSimpleName() + ": (null)";
            }
        }
        if (result != null) {
            if (result instanceof CommandSyntaxException) {
                CommandSyntaxException e = (CommandSyntaxException) result;
                Ansi sb = Ansi.ansi();
                sb.fg(RED).a("Syntax error: ").a(e.getMessage()).newline();
                String help = e.getHelpText();
                if (help != null) {
                    sb.fg(CYAN);
                    sb.a("Help : ").newline();
                    sb.a(help);
                }
                _console.println(sb.reset().toString());
            } else {
                String s;
                s = Strings.toMultilineString(result);
                if (!s.isEmpty()) {
                    _console.println(s);
                    _console.flush();
                }
            }
        }
        _console.flush();
    }
}
Also used : InterruptedIOException(java.io.InterruptedIOException) SerializationException(dmg.cells.nucleus.SerializationException) CommandException(dmg.util.CommandException) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) CommandExitException(dmg.util.CommandExitException) CommandExitException(dmg.util.CommandExitException) InterruptedIOException(java.io.InterruptedIOException) SerializationException(dmg.cells.nucleus.SerializationException) CommandSyntaxException(dmg.util.CommandSyntaxException) CommandException(dmg.util.CommandException) IOException(java.io.IOException) CommandPanicException(dmg.util.CommandPanicException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) Ansi(org.fusesource.jansi.Ansi) CommandSyntaxException(dmg.util.CommandSyntaxException) CommandPanicException(dmg.util.CommandPanicException)

Example 2 with SerializationException

use of dmg.cells.nucleus.SerializationException in project dcache by dCache.

the class DirectCommand method executeCommands.

private void executeCommands() {
    for (String command : commands) {
        Object error = null;
        try {
            Object result = shell.executeCommand(command);
            String s = Strings.toString(result);
            if (!s.isEmpty()) {
                outWriter.println(s);
            }
            outWriter.flush();
        } catch (IllegalArgumentException e) {
            error = e.toString();
        } catch (SerializationException e) {
            error = "There is a bug here, please report to support@dcache.org";
            LOGGER.error("This must be a bug, please report to support@dcache.org.", e);
        } catch (CommandSyntaxException e) {
            error = e;
        } catch (CommandEvaluationException | CommandAclException e) {
            error = e.getMessage();
        } catch (CommandExitException e) {
            break;
        } catch (CommandPanicException e) {
            error = String.format("Command '%s' triggered a bug (%s);" + "the service log file contains additional information. Please " + "contact support@dcache.org.", command, e.getTargetException());
        } catch (CommandException e) {
            error = e.getMessage();
        } catch (NoRouteToCellException e) {
            error = "Cell name does not exist or cell is not started: " + e.getMessage();
            LOGGER.warn("Command cannot be executed in the cell, cell is gone {}", e.getMessage());
        } catch (RuntimeException e) {
            error = String.format("Command '%s' triggered a bug (%s); please" + " locate this message in the log file of the admin service and" + " send an email to support@dcache.org with this line and the" + " following stack-trace", command, e);
            LOGGER.error((String) error, e);
        } catch (Exception e) {
            error = e.getMessage();
            if (error == null) {
                error = e.getClass().getSimpleName() + ": (null)";
            }
        }
        if (error != null) {
            if (error instanceof CommandSyntaxException) {
                CommandSyntaxException e = (CommandSyntaxException) error;
                errorWriter.append("Syntax error: ").println(e.getMessage());
            } else {
                errorWriter.println(error);
            }
            errorWriter.flush();
        }
    }
}
Also used : SerializationException(dmg.cells.nucleus.SerializationException) CommandEvaluationException(dmg.util.CommandEvaluationException) CommandException(dmg.util.CommandException) CommandExitException(dmg.util.CommandExitException) CommandException(dmg.util.CommandException) CommandAclException(dmg.util.CommandAclException) CommandPanicException(dmg.util.CommandPanicException) CommandExitException(dmg.util.CommandExitException) SerializationException(dmg.cells.nucleus.SerializationException) CommandSyntaxException(dmg.util.CommandSyntaxException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) CommandEvaluationException(dmg.util.CommandEvaluationException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) CommandSyntaxException(dmg.util.CommandSyntaxException) CommandAclException(dmg.util.CommandAclException) CommandPanicException(dmg.util.CommandPanicException)

Example 3 with SerializationException

use of dmg.cells.nucleus.SerializationException in project dcache by dCache.

the class NoTerminalCommand method repl.

private void repl() throws IOException {
    Ansi.setEnabled(false);
    while (true) {
        Object error = null;
        try {
            String str = _reader.readLine();
            try {
                if (str == null) {
                    throw new CommandExitException();
                }
                Object result = _userAdminShell.executeCommand(str);
                String s = Strings.toString(result);
                if (!s.isEmpty()) {
                    _writer.println(s);
                }
                _writer.flush();
            } catch (IllegalArgumentException e) {
                error = e.toString();
            } catch (SerializationException e) {
                error = "There is a bug here, please report to support@dcache.org";
                LOGGER.error("This must be a bug, please report to support@dcache.org.", e);
            } catch (CommandSyntaxException e) {
                error = e;
            } catch (CommandEvaluationException | CommandAclException e) {
                error = e.getMessage();
            } catch (CommandExitException e) {
                break;
            } catch (CommandPanicException e) {
                error = "Command '" + str + "' triggered a bug (" + e.getTargetException() + "); the service log file contains additional information. Please " + "contact support@dcache.org.";
            } catch (CommandException e) {
                error = e.getMessage();
            } catch (NoRouteToCellException e) {
                error = "Cell name does not exist or cell is not started: " + e.getMessage();
                LOGGER.warn("The cell the command was sent to is no " + "longer there: {}", e.getMessage());
            } catch (RuntimeException e) {
                error = String.format("Command '%s' triggered a bug (%s); please" + " locate this message in the log file of the admin service and" + " send an email to support@dcache.org with this line and the" + " following stack-trace", str, e);
                LOGGER.error((String) error, e);
            }
        } catch (InterruptedException e) {
            error = null;
        } catch (IOException e) {
            throw e;
        } catch (Exception e) {
            error = e.getMessage();
            if (error == null) {
                error = e.getClass().getSimpleName() + ": (null)";
            }
        }
        if (error != null) {
            if (error instanceof CommandSyntaxException) {
                CommandSyntaxException e = (CommandSyntaxException) error;
                _error.append("Syntax error: ").println(e.getMessage());
            } else {
                _error.println(error);
            }
            _error.flush();
        }
    }
}
Also used : SerializationException(dmg.cells.nucleus.SerializationException) CommandEvaluationException(dmg.util.CommandEvaluationException) CommandException(dmg.util.CommandException) IOException(java.io.IOException) CommandExitException(dmg.util.CommandExitException) CommandException(dmg.util.CommandException) CommandAclException(dmg.util.CommandAclException) IOException(java.io.IOException) CommandPanicException(dmg.util.CommandPanicException) CommandExitException(dmg.util.CommandExitException) SerializationException(dmg.cells.nucleus.SerializationException) CommandSyntaxException(dmg.util.CommandSyntaxException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) CommandEvaluationException(dmg.util.CommandEvaluationException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) CommandSyntaxException(dmg.util.CommandSyntaxException) CommandAclException(dmg.util.CommandAclException) CommandPanicException(dmg.util.CommandPanicException)

Example 4 with SerializationException

use of dmg.cells.nucleus.SerializationException in project dcache by dCache.

the class LegacyAdminShellCommand method runAsciiMode.

private void runAsciiMode() throws IOException {
    Ansi.setEnabled(_console.getTerminal().isAnsiSupported() && _useColors);
    while (!_adminShellThread.isInterrupted()) {
        String prompt = Ansi.ansi().bold().a(_shell.getPrompt()).boldOff().toString();
        String str = _console.readLine(prompt);
        Object result;
        try {
            if (str == null) {
                throw new CommandExitException();
            }
            if (_useColors) {
                String trimmed = str.trim();
                if (trimmed.startsWith("help ")) {
                    str = "help -format=" + HelpFormat.ANSI + trimmed.substring(4);
                } else if (trimmed.equals("help")) {
                    str = "help -format=" + HelpFormat.ANSI;
                }
            }
            result = _shell.executeCommand(str);
        } catch (IllegalArgumentException e) {
            result = e.getMessage() + " (Please check the spelling of your command or your config file(s)!)";
        } catch (SerializationException e) {
            result = "There is a bug here, please report to support@dcache.org";
            LOGGER.error("This must be a bug, please report to support@dcache.org.", e);
        } catch (CommandSyntaxException e) {
            result = e;
        } catch (CommandEvaluationException e) {
            result = e.getMessage();
        } catch (CommandExitException e) {
            break;
        } catch (CommandPanicException e) {
            result = "Command '" + str + "' triggered a bug (" + e.getTargetException() + "); the service log file contains additional information. Please " + "contact support@dcache.org.";
        } catch (CommandException e) {
            result = e.getMessage();
        } catch (NoRouteToCellException e) {
            result = "Cell name does not exist or cell is not started: " + e.getMessage();
            LOGGER.warn("The cell the command was sent to is no " + "longer there: {}", e.getMessage());
        } catch (InterruptedException e) {
            result = e.getMessage();
        } catch (RuntimeException e) {
            result = String.format("Command '%s' triggered a bug (%s); please" + " locate this message in the log file of the admin service and" + " send an email to support@dcache.org with this line and the" + " following stack-trace", str, e);
            LOGGER.error((String) result, e);
        } catch (Exception e) {
            result = e.getMessage();
            if (result == null) {
                result = e.getClass().getSimpleName() + ": (null)";
            }
        }
        if (result != null) {
            String s;
            if (result instanceof CommandSyntaxException) {
                CommandSyntaxException e = (CommandSyntaxException) result;
                Ansi sb = Ansi.ansi();
                sb.fg(RED).a("Syntax error: ").a(e.getMessage()).newline();
                String help = e.getHelpText();
                if (help != null) {
                    sb.fg(CYAN);
                    sb.a("Help : ").newline();
                    sb.a(help);
                }
                s = sb.reset().toString();
            } else {
                s = Strings.toMultilineString(result);
            }
            if (!s.isEmpty()) {
                _console.println(s);
                _console.flush();
            }
        }
    }
}
Also used : SerializationException(dmg.cells.nucleus.SerializationException) CommandEvaluationException(dmg.util.CommandEvaluationException) CommandException(dmg.util.CommandException) CommandExitException(dmg.util.CommandExitException) CommandExitException(dmg.util.CommandExitException) SerializationException(dmg.cells.nucleus.SerializationException) CommandSyntaxException(dmg.util.CommandSyntaxException) CommandEvaluationException(dmg.util.CommandEvaluationException) CommandException(dmg.util.CommandException) IOException(java.io.IOException) CommandPanicException(dmg.util.CommandPanicException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) Ansi(org.fusesource.jansi.Ansi) CommandSyntaxException(dmg.util.CommandSyntaxException) CommandPanicException(dmg.util.CommandPanicException)

Example 5 with SerializationException

use of dmg.cells.nucleus.SerializationException in project dcache by dCache.

the class CellEndpointHelper method sendMessage.

@Override
public void sendMessage(CellMessage envelope, CellMessageAnswerable callback, Executor executor, long timeout, SendFlag... flags) throws SerializationException {
    if (!asList(flags).contains(SendFlag.PASS_THROUGH)) {
        envelope.addSourceAddress(_address);
    }
    CellMessage answer = currentTest().messageArrived(envelope);
    Object obj = answer.getMessageObject();
    if (obj instanceof Exception) {
        callback.exceptionArrived(envelope, (Exception) obj);
    } else {
        callback.answerArrived(envelope, answer);
    }
}
Also used : CellMessage(dmg.cells.nucleus.CellMessage) SerializationException(dmg.cells.nucleus.SerializationException)

Aggregations

SerializationException (dmg.cells.nucleus.SerializationException)5 NoRouteToCellException (dmg.cells.nucleus.NoRouteToCellException)4 CommandException (dmg.util.CommandException)4 CommandExitException (dmg.util.CommandExitException)4 CommandPanicException (dmg.util.CommandPanicException)4 CommandSyntaxException (dmg.util.CommandSyntaxException)4 CommandEvaluationException (dmg.util.CommandEvaluationException)3 IOException (java.io.IOException)3 CommandAclException (dmg.util.CommandAclException)2 Ansi (org.fusesource.jansi.Ansi)2 CellMessage (dmg.cells.nucleus.CellMessage)1 InterruptedIOException (java.io.InterruptedIOException)1