use of dmg.cells.nucleus.NoRouteToCellException in project dcache by dCache.
the class UserAdminShell method sendToMany.
/**
* Concurrently sends a command to several cells and collects the result from each.
*/
private String sendToMany(Iterable<String> destinations, Serializable object) throws AclException {
/* Check permissions */
try {
checkPermission("cell.*.execute");
} catch (AclException e) {
for (String cell : destinations) {
checkPermission("cell." + cell + ".execute");
}
}
/* Submit */
List<Map.Entry<String, ListenableFuture<Serializable>>> futures = new ArrayList<>();
for (String cell : destinations) {
futures.add(immutableEntry(cell, _cellStub.send(new CellPath(cell), object, Serializable.class, _timeout)));
}
/* Collect results */
StringBuilder result = new StringBuilder();
for (Map.Entry<String, ListenableFuture<Serializable>> entry : futures) {
result.append(Ansi.ansi().bold().a(entry.getKey()).boldOff()).append(":");
try {
String reply = Objects.toString(entry.getValue().get(), "");
if (reply.isEmpty()) {
result.append(Ansi.ansi().fg(GREEN).a(" OK").reset()).append("\n");
} else {
result.append("\n");
for (String s : reply.split("\n")) {
result.append(" ").append(s).append("\n");
}
}
} catch (ExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof NoRouteToCellException) {
result.append(Ansi.ansi().fg(RED).a(" Cell is unreachable.").reset()).append("\n");
} else {
result.append(" ").append(Ansi.ansi().fg(RED).a(cause.getMessage()).reset()).append("\n");
}
} catch (InterruptedException e) {
result.append(" ^C\n");
/* Cancel all uncompleted tasks. Doesn't actually cancel any requests, but will cause
* the remaining uncompleted futures to throw a CancellationException.
*/
for (Map.Entry<String, ListenableFuture<Serializable>> entry2 : futures) {
entry2.getValue().cancel(true);
}
} catch (CancellationException e) {
result.append(" ^C\n");
}
}
return result.toString();
}
use of dmg.cells.nucleus.NoRouteToCellException in project dcache by dCache.
the class UserAdminShell method checkPermission.
/**
* Checks that the current effective user has the given acl.
*
* @throws AclException if the current user does not have the given {@code aclName}
*/
public void checkPermission(String aclName) throws AclException {
Object[] request = new Object[5];
request[0] = "request";
request[1] = "<nobody>";
request[2] = "check-permission";
request[3] = getUser();
request[4] = aclName;
Object[] r;
try {
r = _acmStub.sendAndWait(request, Object[].class);
} catch (TimeoutCacheException | NoRouteToCellException e) {
throw new AclException(e.getMessage());
} catch (CacheException | InterruptedException e) {
throw new AclException("Problem: " + e.getMessage());
}
if (r.length < 6 || !(r[5] instanceof Boolean)) {
throw new AclException("Protocol violation 4456");
}
if (!((Boolean) r[5])) {
throw new AclException(getUser(), aclName);
}
}
use of dmg.cells.nucleus.NoRouteToCellException in project dcache by dCache.
the class UserAdminShell method completeCellWildcard.
/**
* Completes a cell address wildcard. Does not provide completion for cell paths.
*/
private int completeCellWildcard(String buffer, int cursor, List<CharSequence> candidates) {
if (buffer.contains(":")) {
return -1;
}
try {
int i = buffer.indexOf('@');
if (i > -1) {
expandCellPatterns(singletonList(buffer + "*")).stream().map(s -> s.substring(s.indexOf('@') + 1)).forEach(candidates::add);
return i + 1;
}
i = buffer.indexOf('/');
if (i > -1) {
Predicate<String> predicate = toGlobPredicate(buffer.substring(i + 1) + "*");
getPoolGroups().get().stream().filter(predicate).forEach(candidates::add);
return i + 1;
}
candidates.addAll(expandCellPatterns(singletonList(buffer + "*")));
if (_currentPosition != null) {
candidates.addAll(getCells(_currentPosition.remote.getDestinationAddress().getCellDomainName(), toGlobPredicate(buffer + "*")).get());
}
return 0;
} catch (CacheException | NoRouteToCellException | ExecutionException e) {
LOGGER.info("Completion failed: {}", e.toString());
return -1;
} catch (InterruptedException e) {
return -1;
}
}
use of dmg.cells.nucleus.NoRouteToCellException in project dcache by dCache.
the class HttpBillingEngine method printMainStatisticsPage.
private void printMainStatisticsPage(OutputStream out) throws HttpException {
HTMLWriter html = new HTMLWriter(out, _context);
try {
Object[][] x = _billing.sendAndWait("get billing info", Object[][].class);
html.addHeader("/styles/billing.css", "dCache Billing");
printTotalStatistics(html, x);
try {
Map<String, long[]> map = _billing.sendAndWait("get pool statistics", Map.class);
printPoolStatistics(html, map, null);
} catch (InterruptedException | TimeoutCacheException e) {
throw e;
} catch (CacheException e) {
html.print("<p class=\"error\">This 'billingCell' doesn't support: 'get pool statistics':");
html.print("<blockquote><pre>" + e + "</pre></blockquote>");
}
} catch (NoRouteToCellException e) {
throw new HttpException(500, "No connection to billing");
} catch (TimeoutCacheException e) {
throw new HttpException(500, "Request Timed Out");
} catch (InterruptedException | CacheException e) {
throw new HttpException(500, "Problem : " + e.getMessage());
} finally {
html.addFooter(getClass().getName());
}
}
use of dmg.cells.nucleus.NoRouteToCellException in project dcache by dCache.
the class XrootdTransferService method handleUploadDone.
private void handleUploadDone(NettyMover<XrootdProtocolInfo> mover) throws CacheException {
try {
EnumSet<CreateOption> options = EnumSet.noneOf(CreateOption.class);
if (mover.getProtocolInfo().isOverwriteAllowed()) {
options.add(CreateOption.OVERWRITE_EXISTING);
}
PnfsCommitUpload msg = new PnfsCommitUpload(mover.getSubject(), mover.getProtocolInfo().getRestriction(), FsPath.create(mover.getTransferPath()), FsPath.create(mover.getBillingPath()), options, EnumSet.of(PNFSID, SIZE, STORAGEINFO));
pnfsStub.sendAndWait(msg);
} catch (InterruptedException ex) {
throw new CacheException("Operation interrupted", ex);
} catch (NoRouteToCellException ex) {
throw new CacheException("Internal communication failure", ex);
}
}
Aggregations