Search in sources :

Example 6 with NoRouteToCellException

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();
}
Also used : CellPath(dmg.cells.nucleus.CellPath) Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) AuthorizedString(dmg.util.AuthorizedString) AclException(dmg.util.AclException) CommandAclException(dmg.util.CommandAclException) Maps.immutableEntry(com.google.common.collect.Maps.immutableEntry) DirectoryEntry(org.dcache.util.list.DirectoryEntry) CancellationException(java.util.concurrent.CancellationException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map)

Example 7 with NoRouteToCellException

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);
    }
}
Also used : TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) CacheException(diskCacheV111.util.CacheException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) AclException(dmg.util.AclException) CommandAclException(dmg.util.CommandAclException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException)

Example 8 with NoRouteToCellException

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;
    }
}
Also used : Ansi(org.fusesource.jansi.Ansi) Arrays(java.util.Arrays) Futures.transformAsync(com.google.common.util.concurrent.Futures.transformAsync) Subjects(org.dcache.auth.Subjects) ListDirectoryHandler(org.dcache.util.list.ListDirectoryHandler) PoolManagerPoolInformation(diskCacheV111.vehicles.PoolManagerPoolInformation) CellMessage(dmg.cells.nucleus.CellMessage) LoggerFactory(org.slf4j.LoggerFactory) CommandThrowableException(dmg.util.CommandThrowableException) AclException(dmg.util.AclException) SettableFuture(com.google.common.util.concurrent.SettableFuture) Restrictions(org.dcache.auth.attributes.Restrictions) Collections.singletonList(java.util.Collections.singletonList) Command(dmg.util.command.Command) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Future(java.util.concurrent.Future) Iterables.concat(com.google.common.collect.Iterables.concat) Maps.immutableEntry(com.google.common.collect.Maps.immutableEntry) Arrays.asList(java.util.Arrays.asList) GetAllDomainsRequest(dmg.cells.services.GetAllDomainsRequest) Map(java.util.Map) Version(org.dcache.util.Version) Splitter(com.google.common.base.Splitter) EnumSet(java.util.EnumSet) PrintWriter(java.io.PrintWriter) FileAttributes(org.dcache.vehicles.FileAttributes) CommandException(dmg.util.CommandException) Futures.allAsList(com.google.common.util.concurrent.Futures.allAsList) CancellationException(java.util.concurrent.CancellationException) Collections.emptyList(java.util.Collections.emptyList) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Range(com.google.common.collect.Range) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) DirectoryStream(org.dcache.util.list.DirectoryStream) CommandAclException(dmg.util.CommandAclException) CharArrayWriter(java.io.CharArrayWriter) Serializable(java.io.Serializable) Objects(java.util.Objects) List(java.util.List) DirectoryEntry(org.dcache.util.list.DirectoryEntry) Stream(java.util.stream.Stream) CellMessageAnswerable(dmg.cells.nucleus.CellMessageAnswerable) GREEN(org.fusesource.jansi.Ansi.Color.GREEN) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) Optional(java.util.Optional) Iterables.filter(com.google.common.collect.Iterables.filter) CellPath(dmg.cells.nucleus.CellPath) Joiner(com.google.common.base.Joiner) Argument(dmg.util.command.Argument) Collectors.partitioningBy(java.util.stream.Collectors.partitioningBy) Iterables(com.google.common.collect.Iterables) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) FsPath(diskCacheV111.util.FsPath) Completer(jline.console.completer.Completer) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) CASE_INSENSITIVE_ORDER(java.lang.String.CASE_INSENSITIVE_ORDER) CellAddressCore(dmg.cells.nucleus.CellAddressCore) Supplier(com.google.common.base.Supplier) NetLoggerBuilder(org.dcache.util.NetLoggerBuilder) Callable(java.util.concurrent.Callable) CellEndpoint(dmg.cells.nucleus.CellEndpoint) CommandExitException(dmg.util.CommandExitException) ArrayList(java.util.ArrayList) CacheException(diskCacheV111.util.CacheException) CellStub(org.dcache.cells.CellStub) CommandInterpreter(dmg.util.CommandInterpreter) Suppliers(com.google.common.base.Suppliers) StreamSupport(java.util.stream.StreamSupport) FileType(org.dcache.namespace.FileType) Futures.immediateFuture(com.google.common.util.concurrent.Futures.immediateFuture) PnfsId(diskCacheV111.util.PnfsId) PingMessage(dmg.cells.network.PingMessage) Logger(org.slf4j.Logger) StringsCompleter(jline.console.completer.StringsCompleter) PoolManagerGetPoolsByPoolGroupMessage(diskCacheV111.vehicles.PoolManagerGetPoolsByPoolGroupMessage) RED(org.fusesource.jansi.Ansi.Color.RED) CharMatcher(com.google.common.base.CharMatcher) HelpFormat(dmg.util.command.HelpFormat) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes) Throwables(com.google.common.base.Throwables) Glob(org.dcache.util.Glob) Futures.catchingAsync(com.google.common.util.concurrent.Futures.catchingAsync) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Glob.parseGlobToPattern(org.dcache.util.Glob.parseGlobToPattern) Collectors.toList(java.util.stream.Collectors.toList) Futures(com.google.common.util.concurrent.Futures) AuthorizedString(dmg.util.AuthorizedString) GetAllDomainsReply(dmg.cells.services.GetAllDomainsReply) Args(org.dcache.util.Args) CommandLine(dmg.util.command.CommandLine) FileAttribute(org.dcache.namespace.FileAttribute) Futures.transform(com.google.common.util.concurrent.Futures.transform) Collections(java.util.Collections) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) CacheException(diskCacheV111.util.CacheException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) AuthorizedString(dmg.util.AuthorizedString) ExecutionException(java.util.concurrent.ExecutionException) CellEndpoint(dmg.cells.nucleus.CellEndpoint)

Example 9 with NoRouteToCellException

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());
    }
}
Also used : HTMLWriter(diskCacheV111.util.HTMLWriter) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) CacheException(diskCacheV111.util.CacheException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) HttpException(dmg.util.HttpException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException)

Example 10 with NoRouteToCellException

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);
    }
}
Also used : CacheException(diskCacheV111.util.CacheException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) CreateOption(org.dcache.namespace.CreateOption) PnfsCommitUpload(diskCacheV111.vehicles.PnfsCommitUpload)

Aggregations

NoRouteToCellException (dmg.cells.nucleus.NoRouteToCellException)67 CacheException (diskCacheV111.util.CacheException)55 TimeoutCacheException (diskCacheV111.util.TimeoutCacheException)25 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)22 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)19 ArrayList (java.util.ArrayList)15 ApiOperation (io.swagger.annotations.ApiOperation)14 ApiResponses (io.swagger.annotations.ApiResponses)14 Produces (javax.ws.rs.Produces)14 BadRequestException (javax.ws.rs.BadRequestException)13 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)13 Path (javax.ws.rs.Path)13 CellPath (dmg.cells.nucleus.CellPath)11 ExecutionException (java.util.concurrent.ExecutionException)11 ForbiddenException (javax.ws.rs.ForbiddenException)11 GET (javax.ws.rs.GET)11 FsPath (diskCacheV111.util.FsPath)10 PnfsId (diskCacheV111.util.PnfsId)10 SRMException (org.dcache.srm.SRMException)10 SRMInternalErrorException (org.dcache.srm.SRMInternalErrorException)10