Search in sources :

Example 1 with GetAllDomainsReply

use of dmg.cells.services.GetAllDomainsReply in project dcache by dCache.

the class CellInfoCollector method collectData.

@Override
public Map<String, ListenableFutureWrapper<CellInfo>> collectData() throws InterruptedException {
    GetAllDomainsReply reply;
    try {
        reply = stub.send(new CellPath("RoutingMgr"), new GetAllDomainsRequest(), GetAllDomainsReply.class).get();
    } catch (ExecutionException e) {
        LOGGER.error("Could not contact Routing Manager: {}, {}.", e.getMessage(), String.valueOf(e.getCause()));
        return Collections.EMPTY_MAP;
    }
    Map<String, ListenableFutureWrapper<CellInfo>> map = new TreeMap<>();
    CellInfo frontendInfo = supplier.get();
    /*
         *  Remove Frontend, and substitute with the supplier.
         *  Otherwise, the message fails.
         */
    Collection<String> cells = reply.getDomains().get(frontendInfo.getDomainName());
    cells.remove(frontendInfo.getCellName());
    reply.getDomains().entrySet().stream().map(this::getCellPaths).flatMap(Collection::stream).map(this::getCellInfo).forEach((future) -> map.put(future.getKey(), future));
    ListenableFutureWrapper<CellInfo> wrapper = new ListenableFutureWrapper<>();
    wrapper.setKey(frontendInfo.getCellName() + "@" + frontendInfo.getDomainName());
    wrapper.setSent(System.currentTimeMillis());
    wrapper.setFuture(Futures.immediateFuture(frontendInfo));
    map.put(wrapper.getKey(), wrapper);
    return map;
}
Also used : GetAllDomainsReply(dmg.cells.services.GetAllDomainsReply) CellPath(dmg.cells.nucleus.CellPath) GetAllDomainsRequest(dmg.cells.services.GetAllDomainsRequest) CellInfo(dmg.cells.nucleus.CellInfo) Collection(java.util.Collection) ExecutionException(java.util.concurrent.ExecutionException) ListenableFutureWrapper(org.dcache.util.collector.ListenableFutureWrapper) TreeMap(java.util.TreeMap)

Example 2 with GetAllDomainsReply

use of dmg.cells.services.GetAllDomainsReply in project dcache by dCache.

the class UserAdminShell method expandCellPatterns.

/**
 * Expands a list of cell address globs into a list of cell addresses.
 * <p>
 * Processes globs on both the left and right side of the '@' separator of a cell address. Also
 * processes the special '/' pool group separator, interpreting the left side as a pool name
 * pattern and the right side as a pool group pattern.
 * <p>
 * The result is sorted lexicographically and case insensitive, but the order of the input
 * patterns is preserved (ie. the output contains matching cells in the same order).
 */
private List<String> expandCellPatterns(List<String> patterns) throws CacheException, InterruptedException, ExecutionException, NoRouteToCellException {
    /* Query domains and well-known cells on demand. */
    Supplier<Future<Map<String, Collection<String>>>> domains = Suppliers.memoize(() -> transform(_cellStub.send(new CellPath("RoutingMgr"), new GetAllDomainsRequest(), GetAllDomainsReply.class), GetAllDomainsReply::getDomains));
    List<ListenableFuture<List<String>>> futures = new ArrayList<>();
    for (String pattern : patterns) {
        int i = pattern.indexOf('@');
        if (i >= 0) {
            /* Find the cells of each matching domain.
                 */
            Predicate<String> matchesCellName = toGlobPredicate(pattern.substring(0, i));
            Predicate<String> matchesDomainName = toGlobPredicate(pattern.substring(i + 1));
            CellStub.get(domains.get()).keySet().stream().filter(matchesDomainName).sorted(CASE_INSENSITIVE_ORDER).map(domain -> getCells(domain, matchesCellName)).forEach(futures::add);
            continue;
        }
        i = pattern.indexOf('/');
        if (i >= 0) {
            Predicate<String> matchesPool = toGlobPredicate(pattern.substring(0, i));
            if (i + 1 == pattern.length()) {
                /* Special case when no pool group is specified - matches over all pools, even those
                     * not in a pool group.
                     */
                futures.add(transform(getPools(matchesPool), (List<String> pools) -> pools.stream().sorted(CASE_INSENSITIVE_ORDER).collect(toList())));
            } else {
                /* Find the pools of each matching pool group.
                     */
                Predicate<String> matchesPoolGroup = toGlobPredicate(pattern.substring(i + 1));
                futures.add(transform(getPoolsInGroups(matchesPoolGroup), (List<String> pools) -> pools.stream().filter(matchesPool).sorted(CASE_INSENSITIVE_ORDER).collect(toList())));
            }
            continue;
        }
        Predicate<String> matchesCellName = toGlobPredicate(pattern);
        /* Add matching well-known cells. */
        CellStub.get(domains.get()).values().stream().flatMap(Collection::stream).filter(matchesCellName).sorted(CASE_INSENSITIVE_ORDER).map(Collections::singletonList).map(Futures::immediateFuture).forEach(futures::add);
    }
    /* Collect and flatten the result. */
    return allAsList(futures).get().stream().flatMap(Collection::stream).collect(toList());
}
Also used : CellPath(dmg.cells.nucleus.CellPath) GetAllDomainsRequest(dmg.cells.services.GetAllDomainsRequest) 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) ArrayList(java.util.ArrayList) AuthorizedString(dmg.util.AuthorizedString) CellEndpoint(dmg.cells.nucleus.CellEndpoint) SettableFuture(com.google.common.util.concurrent.SettableFuture) Future(java.util.concurrent.Future) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Futures.immediateFuture(com.google.common.util.concurrent.Futures.immediateFuture) Collection(java.util.Collection) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Collections(java.util.Collections)

Aggregations

CellPath (dmg.cells.nucleus.CellPath)2 GetAllDomainsReply (dmg.cells.services.GetAllDomainsReply)2 GetAllDomainsRequest (dmg.cells.services.GetAllDomainsRequest)2 CharMatcher (com.google.common.base.CharMatcher)1 Joiner (com.google.common.base.Joiner)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Splitter (com.google.common.base.Splitter)1 Supplier (com.google.common.base.Supplier)1 Suppliers (com.google.common.base.Suppliers)1 Throwables (com.google.common.base.Throwables)1 Iterables (com.google.common.collect.Iterables)1 Iterables.concat (com.google.common.collect.Iterables.concat)1 Iterables.filter (com.google.common.collect.Iterables.filter)1 Maps.immutableEntry (com.google.common.collect.Maps.immutableEntry)1 Range (com.google.common.collect.Range)1 Futures (com.google.common.util.concurrent.Futures)1 Futures.allAsList (com.google.common.util.concurrent.Futures.allAsList)1 Futures.catchingAsync (com.google.common.util.concurrent.Futures.catchingAsync)1 Futures.immediateFuture (com.google.common.util.concurrent.Futures.immediateFuture)1 Futures.transform (com.google.common.util.concurrent.Futures.transform)1