Search in sources :

Example 11 with CellPath

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());
}
Also used : CellPath(dmg.cells.nucleus.CellPath) Test(org.junit.Test)

Example 12 with CellPath

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();
}
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 13 with CellPath

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;
}
Also used : CellPath(dmg.cells.nucleus.CellPath) AuthorizedString(dmg.util.AuthorizedString) CellEndpoint(dmg.cells.nucleus.CellEndpoint)

Example 14 with CellPath

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);
}
Also used : CellPath(dmg.cells.nucleus.CellPath) XrootdDoorAdressInfoMessage(org.dcache.vehicles.XrootdDoorAdressInfoMessage) InetSocketAddress(java.net.InetSocketAddress) XrootdProtocolInfo(org.dcache.vehicles.XrootdProtocolInfo) InetAddress(java.net.InetAddress)

Example 15 with 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);
}
Also used : CellPath(dmg.cells.nucleus.CellPath) CellAddressCore(dmg.cells.nucleus.CellAddressCore) PoolManagerCellInfo(diskCacheV111.poolManager.PoolManagerCellInfo) HashSet(java.util.HashSet) Set(java.util.Set) PoolCellInfo(diskCacheV111.pools.PoolCellInfo) PoolManagerCellInfo(diskCacheV111.poolManager.PoolManagerCellInfo) CellInfo(dmg.cells.nucleus.CellInfo) PingMessage(dmg.cells.network.PingMessage) LoginBrokerInfo(dmg.cells.services.login.LoginBrokerInfo)

Aggregations

CellPath (dmg.cells.nucleus.CellPath)77 CacheException (diskCacheV111.util.CacheException)20 CellMessage (dmg.cells.nucleus.CellMessage)19 CellAddressCore (dmg.cells.nucleus.CellAddressCore)15 PnfsId (diskCacheV111.util.PnfsId)14 FileAttributes (org.dcache.vehicles.FileAttributes)14 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)12 NoRouteToCellException (dmg.cells.nucleus.NoRouteToCellException)9 CellStub (org.dcache.cells.CellStub)9 PnfsGetFileAttributes (org.dcache.vehicles.PnfsGetFileAttributes)9 HashSet (java.util.HashSet)8 ExecutionException (java.util.concurrent.ExecutionException)8 FileAttribute (org.dcache.namespace.FileAttribute)8 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)7 PoolMoverKillMessage (diskCacheV111.vehicles.PoolMoverKillMessage)7 Map (java.util.Map)7 PoolMgrSelectReadPoolMsg (diskCacheV111.vehicles.PoolMgrSelectReadPoolMsg)6 IOException (java.io.IOException)6 PoolV2Mode (diskCacheV111.pools.PoolV2Mode)5