use of dmg.cells.nucleus.CellPath in project dcache by dCache.
the class CellPathTest method testCellPath.
@Test
public void testCellPath() {
CellPath path = new CellPath("source");
path.add("gateway1");
path.add("gateway2");
path.add("destination");
assertEquals("Incorrect path constructed", "[>source@local:gateway1@local:gateway2@local:destination@local]", path.toString());
path = path.revert();
assertEquals("Incorrect reverce path constructed", "[>destination@local:gateway2@local:gateway1@local:source@local]", path.toString());
}
use of dmg.cells.nucleus.CellPath 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.CellPath in project dcache by dCache.
the class UserAdminShell method completeSendCommand.
/**
* Completes the \s command. Is able to complete the last address of the destination argument.
* If only a single cell is provided as a destination, the command argument itself is completed
* too (using that cell as a source for completion candidates).
*/
private int completeSendCommand(String buffer, int cursor, List<CharSequence> candidates) {
Completable arguments = new Completable(buffer, cursor, candidates);
if (!arguments.hasTail()) {
int lastDestinationStart = arguments.head.lastIndexOf(',') + 1;
String lastDestination = arguments.head.substring(lastDestinationStart);
int i = completeCellWildcard(lastDestination, lastDestination.length(), candidates);
return (i == -1) ? -1 : lastDestinationStart + i;
} else if (!arguments.head.contains(",") && !isExpandable(arguments.head)) {
return arguments.completeTail(createRemoteCompleter(new CellPath(arguments.head)));
}
return -1;
}
use of dmg.cells.nucleus.CellPath in project dcache by dCache.
the class XrootdTransferService method sendAddressToDoor.
/**
* Sends our address to the door. Copied from the old xrootd mover.
*/
@Override
protected void sendAddressToDoor(NettyMover<XrootdProtocolInfo> mover, int port) throws SocketException, CacheException {
XrootdProtocolInfo protocolInfo = mover.getProtocolInfo();
InetAddress localIP = NetworkUtils.getLocalAddress(protocolInfo.getSocketAddress().getAddress());
CellPath cellpath = protocolInfo.getXrootdDoorCellPath();
XrootdDoorAdressInfoMessage doorMsg = new XrootdDoorAdressInfoMessage(protocolInfo.getXrootdFileHandle(), new InetSocketAddress(localIP, port));
doorStub.notify(cellpath, doorMsg);
LOGGER.debug("sending redirect {} to Xrootd-door {}", localIP, cellpath);
}
use of dmg.cells.nucleus.CellPath in project dcache by dCache.
the class WebCollectorV3 method messageArrived.
@Override
public void messageArrived(CellMessage message) {
Object reply = message.getMessageObject();
int modified = 0;
if (reply instanceof LoginBrokerInfo) {
LoginBrokerInfo brokerInfo = (LoginBrokerInfo) reply;
synchronized (_infoLock) {
LOGGER.debug("Login broker reports: {}@{}", brokerInfo.getCellName(), brokerInfo.getDomainName());
if (addQuery(new CellAddressCore(brokerInfo.getCellName(), brokerInfo.getDomainName()))) {
modified++;
}
}
} else if (reply instanceof PingMessage) {
synchronized (_infoLock) {
addQuery(message.getSourceAddress());
}
} else {
CellPath path = message.getSourcePath();
CellAddressCore address = path.getSourceAddress();
CellQueryInfo info;
synchronized (_infoLock) {
info = _infoMap.get(address);
if (info == null) {
// We may have registered the cell as a well known cell
info = _infoMap.get(new CellAddressCore(address.getCellName()));
if (info == null) {
LOGGER.info("Unexpected reply arrived from: {}", path);
return;
}
}
}
if (reply instanceof CellInfo) {
LOGGER.debug("CellInfo: {}", ((CellInfo) reply).getCellName());
info.infoArrived((CellInfo) reply);
}
if (reply instanceof PoolManagerCellInfo) {
Set<CellAddressCore> pools = ((PoolManagerCellInfo) reply).getPoolCells();
synchronized (_infoLock) {
for (CellAddressCore pool : pools) {
if (addQuery(pool)) {
modified++;
}
}
}
}
}
_sleepHandler.topologyChanged(modified > 0);
}
Aggregations