use of dmg.cells.services.GetAllDomainsRequest 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;
}
use of dmg.cells.services.GetAllDomainsRequest 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());
}
Aggregations