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);
}
}
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();
}
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);
}
}
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());
}
}
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 "";
}
Aggregations