Search in sources :

Example 1 with CommandException

use of dmg.util.CommandException in project dcache by dCache.

the class UniversalSpringCell method executeSetup.

private void executeSetup(CommandInterpreter interpreter, String source, byte[] data) throws CommandException {
    try {
        BufferedReader in = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(data), UTF_8));
        int lineCount = 1;
        for (String line = in.readLine(); line != null; line = in.readLine(), lineCount++) {
            line = line.trim();
            if (line.isEmpty() || line.charAt(0) == '#') {
                continue;
            }
            try {
                Serializable result = interpreter.command(new Args(line));
                if (result instanceof DelayedReply) {
                    ((DelayedReply) result).take();
                }
            } catch (InterruptedException e) {
                throw new CommandExitException("Error at " + source + ":" + lineCount + ": command interrupted");
            } catch (CommandPanicException e) {
                throw new CommandPanicException("Error at " + source + ":" + lineCount + ": " + e.getMessage(), e);
            } catch (CommandException e) {
                throw new CommandThrowableException("Error at " + source + ":" + lineCount + ": " + e.getMessage(), e);
            }
        }
    } catch (IOException e) {
        // Should not be possible
        throw new RuntimeException(e);
    }
}
Also used : CommandThrowableException(dmg.util.CommandThrowableException) Serializable(java.io.Serializable) Args(org.dcache.util.Args) InputStreamReader(java.io.InputStreamReader) DelayedReply(dmg.cells.nucleus.DelayedReply) CommandException(dmg.util.CommandException) IOException(java.io.IOException) CommandExitException(dmg.util.CommandExitException) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedReader(java.io.BufferedReader) CommandPanicException(dmg.util.CommandPanicException)

Example 2 with CommandException

use of dmg.util.CommandException in project dcache by dCache.

the class DCapDoorInterpreterV3 method com_hello.

// ////////////////////////////////////////////////////////////////
// 
// the command functions  String com_<commandName>(int,int,Args)
// 
public String com_hello(int sessionId, int commandId, VspArgs args) throws CommandException {
    if (args.argc() < 2) {
        throw new CommandExitException("Command Syntax Exception", 2);
    }
    try {
        int major = Integer.parseInt(args.argv(2));
        int minor = Integer.parseInt(args.argv(3));
        Integer bugfix = args.argc() > 4 ? Integer.parseInt(args.argv(4)) : null;
        String patch = args.argv(5);
        _version = new Version(major, minor, bugfix, patch);
    } catch (NumberFormatException e) {
        _log.error("Syntax error in client version number {} : {}", args, e.toString());
        throw new CommandException("Invalid client version number", e);
    }
    /*
          replace current values if alternatives are provided
        */
    _pid = args.getOption("pid", _pid);
    _uid = args.getIntOption("uid", _uid);
    _gid = args.getIntOption("gid", _gid);
    _log.debug("Client Version : {}", _version);
    if (_settings.getMinClientVersion().matches(_version) > 0 || _settings.getMaxClientVersion().matches(_version) < 0) {
        _log.error("Client {} (proc \"{}\" running with uid:{} gid:{}) rejected: bad client version: {}", InetAddresses.toAddrString(_clientAddress), _pid, _uid, _gid, _version);
        throw new CommandExitException("Client version rejected : " + _version, 1);
    }
    String yourName = args.getName();
    if (yourName.equals("server")) {
        _ourName = "client";
    }
    return "0 0 " + _ourName + " welcome " + _version.getMajor() + " " + _version.getMinor();
}
Also used : CommandException(dmg.util.CommandException) CommandExitException(dmg.util.CommandExitException) CellEndpoint(dmg.cells.nucleus.CellEndpoint)

Example 3 with CommandException

use of dmg.util.CommandException in project dcache by dCache.

the class UserAdminShell method sendObject.

private Serializable sendObject(CellPath cellPath, Serializable object) throws NoRouteToCellException, InterruptedException, CommandException, AclException {
    CellAddressCore addr = cellPath.getCurrent();
    checkCdPermission(addr.isLocalAddress() ? addr.getCellName() : addr.toString());
    try {
        return _cellStub.send(cellPath, object, Serializable.class, _timeout).get();
    } catch (ExecutionException e) {
        Throwable cause = e.getCause();
        if (_fullException) {
            return getStackTrace(cause);
        }
        Throwables.throwIfInstanceOf(cause, Error.class);
        Throwables.throwIfInstanceOf(cause, NoRouteToCellException.class);
        Throwables.throwIfInstanceOf(cause, CommandException.class);
        throw new CommandThrowableException(cause.toString(), cause);
    }
}
Also used : CellAddressCore(dmg.cells.nucleus.CellAddressCore) CommandThrowableException(dmg.util.CommandThrowableException) Serializable(java.io.Serializable) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) CommandException(dmg.util.CommandException) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with CommandException

use of dmg.util.CommandException in project dcache by dCache.

the class CellShell method ac_exec_env_$_1_99.

public String ac_exec_env_$_1_99(Args args) throws CommandException {
    try {
        URI uri = new URI("env", args.argv(0), null);
        args.shift();
        return run_reader(uri, args);
    } catch (URISyntaxException e) {
        throw new CommandException(43, e.getMessage());
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) CommandException(dmg.util.CommandException) URI(java.net.URI)

Example 5 with CommandException

use of dmg.util.CommandException in project dcache by dCache.

the class CellShell method _waitForCell.

private String _waitForCell(String cellName, int waitTime, int check, String command) throws CommandException {
    if (check <= 4) {
        check = 5;
    }
    CellPath destination = new CellPath(cellName);
    long finish = System.currentTimeMillis() + (waitTime * 1000);
    CellMessage answer;
    Serializable message = (command == null) ? new PingMessage() : command;
    Object o;
    boolean noRoute;
    while (true) {
        noRoute = false;
        answer = null;
        try {
            _log.warn("waitForCell : Sending request");
            answer = _nucleus.sendAndWait(new CellMessage(destination, message), ((long) check) * 1000);
            _log.warn("waitForCell : got {}", answer);
        } catch (NoRouteToCellException e) {
            noRoute = true;
        } catch (ExecutionException ignored) {
        } catch (InterruptedException e) {
            throw new CommandException(66, "sendAndWait problem : " + e, e);
        }
        if ((answer != null) && ((o = answer.getMessageObject()) != null) && ((o instanceof PingMessage) || (o instanceof String))) {
            break;
        }
        if ((waitTime == 0) || (finish > System.currentTimeMillis())) {
            // 
            if ((!noRoute) && (answer == null)) {
                continue;
            }
            // 
            try {
                Thread.sleep(((long) check) * 1000);
            } catch (InterruptedException ie) {
                throw new CommandException(2, "Command Was interrupted");
            }
            continue;
        }
        throw new CommandException(1, "Command Timed Out");
    }
    return "";
}
Also used : Serializable(java.io.Serializable) CommandException(dmg.util.CommandException) ExecutionException(java.util.concurrent.ExecutionException) PingMessage(dmg.cells.network.PingMessage)

Aggregations

CommandException (dmg.util.CommandException)29 IOException (java.io.IOException)12 CommandExitException (dmg.util.CommandExitException)11 CommandPanicException (dmg.util.CommandPanicException)9 Serializable (java.io.Serializable)7 Args (org.dcache.util.Args)7 NoRouteToCellException (dmg.cells.nucleus.NoRouteToCellException)6 BufferedReader (java.io.BufferedReader)6 InterruptedIOException (java.io.InterruptedIOException)6 CommandSyntaxException (dmg.util.CommandSyntaxException)5 CommandAclException (dmg.util.CommandAclException)4 CommandEvaluationException (dmg.util.CommandEvaluationException)4 CommandThrowableException (dmg.util.CommandThrowableException)4 InputStreamReader (java.io.InputStreamReader)4 URISyntaxException (java.net.URISyntaxException)4 CellEndpoint (dmg.cells.nucleus.CellEndpoint)3 SerializationException (dmg.cells.nucleus.SerializationException)3 FileNotFoundException (java.io.FileNotFoundException)3 URI (java.net.URI)3 ExecutionException (java.util.concurrent.ExecutionException)3