Search in sources :

Example 1 with PnfsMessage

use of diskCacheV111.vehicles.PnfsMessage in project dcache by dCache.

the class LegacyAdminShell method uncache.

private String uncache(String destination, String target, StringBuffer sb) throws Exception {
    if ((target == null) || (target.isEmpty())) {
        target = "*";
    }
    boolean verbose = sb != null;
    PnfsId pnfsId;
    if (destination.startsWith("/pnfs")) {
        PnfsGetFileAttributes map = new PnfsGetFileAttributes(destination, EnumSet.of(FileAttribute.PNFSID));
        map.setFollowSymlink(false);
        map = (PnfsGetFileAttributes) sendObject("PnfsManager", map);
        if (map.getReturnCode() != 0) {
            Object o = map.getErrorObject();
            if (o instanceof Exception) {
                throw (Exception) o;
            } else {
                throw new Exception(o.toString());
            }
        }
        pnfsId = map.getFileAttributes().getPnfsId();
    } else {
        pnfsId = new PnfsId(destination);
    }
    checkPermission("pool.*.uncache");
    PnfsGetCacheLocationsMessage pnfsMessage = new PnfsGetCacheLocationsMessage(pnfsId);
    pnfsMessage = (PnfsGetCacheLocationsMessage) sendObject("PnfsManager", pnfsMessage);
    if (pnfsMessage.getReturnCode() != 0) {
        throw new FileNotFoundException(destination);
    }
    List<String> locations = pnfsMessage.getCacheLocations();
    if (verbose) {
        sb.append("Location(s) : ");
        for (Object location : locations) {
            sb.append(location.toString()).append(",");
        }
        sb.append("\n");
    }
    if (target.equals("*")) {
        if (verbose) {
            sb.append("Selection : <all>\n");
        }
    } else if (locations.contains(target)) {
        if (verbose) {
            sb.append("Selection : ").append(target).append("\n");
        }
        locations = new ArrayList<>();
        locations.add(target);
    } else {
        if (verbose) {
            sb.append("Selection : <nothing>\n");
        }
        return sb == null ? "" : sb.toString();
    }
    PoolRemoveFilesMessage remove;
    for (Object location : locations) {
        String poolName = location.toString();
        if (verbose) {
            sb.append(poolName).append(" : ");
        }
        try {
            remove = new PoolRemoveFilesMessage(poolName, pnfsId.toString());
            remove = (PoolRemoveFilesMessage) sendObject(poolName, remove);
            if (verbose) {
                int rc = remove.getReturnCode();
                if (rc != 0) {
                    Object obj = remove.getErrorObject();
                    if ((obj != null) && (obj instanceof Object[])) {
                        Object o = ((Object[]) obj)[0];
                        if (o != null) {
                            sb.append("[").append(rc).append("] Failed ").append(o.toString());
                        }
                    } else if (obj != null) {
                        sb.append("[").append(rc).append("] Failed ").append(obj.toString());
                    }
                } else {
                    sb.append("ok");
                }
            }
        } catch (Exception ee) {
            if (verbose) {
                sb.append(ee.getMessage());
            }
        }
        if (verbose) {
            sb.append("\n");
        }
    }
    return sb == null ? "" : sb.toString();
}
Also used : PnfsGetCacheLocationsMessage(diskCacheV111.vehicles.PnfsGetCacheLocationsMessage) PnfsId(diskCacheV111.util.PnfsId) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) PoolRemoveFilesMessage(diskCacheV111.vehicles.PoolRemoveFilesMessage) AuthorizedString(dmg.util.AuthorizedString) CommandThrowableException(dmg.util.CommandThrowableException) AclException(dmg.util.AclException) CommandException(dmg.util.CommandException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) FileNotFoundException(java.io.FileNotFoundException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) CommandExitException(dmg.util.CommandExitException) SerializationException(dmg.cells.nucleus.SerializationException) CacheException(diskCacheV111.util.CacheException) CommandSyntaxException(dmg.util.CommandSyntaxException) ExecutionException(java.util.concurrent.ExecutionException) CellEndpoint(dmg.cells.nucleus.CellEndpoint)

Example 2 with PnfsMessage

use of diskCacheV111.vehicles.PnfsMessage in project dcache by dCache.

the class PnfsManagerV3 method updateFlag.

private void updateFlag(PnfsFlagMessage pnfsMessage) {
    PnfsId pnfsId = pnfsMessage.getPnfsId();
    PnfsFlagMessage.FlagOperation operation = pnfsMessage.getOperation();
    String flagName = pnfsMessage.getFlagName();
    String value = pnfsMessage.getValue();
    Subject subject = pnfsMessage.getSubject();
    LOGGER.info("update flag " + operation + " flag=" + flagName + " value=" + value + " for " + pnfsId);
    try {
        // Note that dcap clients may bypass restrictions by not
        // specifying a path when interacting via mounted namespace.
        checkRestriction(pnfsMessage, UPDATE_METADATA);
        if (operation == PnfsFlagMessage.FlagOperation.GET) {
            pnfsMessage.setValue(updateFlag(subject, pnfsId, operation, flagName, value));
        } else {
            updateFlag(subject, pnfsId, operation, flagName, value);
        }
    } catch (FileNotFoundCacheException e) {
        pnfsMessage.setFailed(e.getRc(), e.getMessage());
    } catch (CacheException e) {
        LOGGER.warn("Exception in updateFlag: " + e);
        pnfsMessage.setFailed(e.getRc(), e.getMessage());
    } catch (RuntimeException e) {
        LOGGER.error("Exception in updateFlag", e);
        pnfsMessage.setFailed(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, e);
    }
}
Also used : MissingResourceCacheException(diskCacheV111.util.MissingResourceCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) InvalidMessageCacheException(diskCacheV111.util.InvalidMessageCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) CacheException(diskCacheV111.util.CacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) PnfsId(diskCacheV111.util.PnfsId) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) Subject(javax.security.auth.Subject) PnfsFlagMessage(diskCacheV111.vehicles.PnfsFlagMessage)

Example 3 with PnfsMessage

use of diskCacheV111.vehicles.PnfsMessage in project dcache by dCache.

the class PnfsManagerV3 method getCacheLocations.

public void getCacheLocations(PnfsGetCacheLocationsMessage pnfsMessage) {
    Subject subject = pnfsMessage.getSubject();
    try {
        checkRestriction(pnfsMessage, READ_METADATA);
        PnfsId pnfsId = populatePnfsId(pnfsMessage);
        LOGGER.info("get cache locations for {}", pnfsId);
        checkMask(pnfsMessage);
        pnfsMessage.setCacheLocations(_nameSpaceProvider.getCacheLocation(subject, pnfsId));
        pnfsMessage.setSucceeded();
    } catch (FileNotFoundCacheException fnf) {
        pnfsMessage.setFailed(CacheException.FILE_NOT_FOUND, fnf.getMessage());
    } catch (CacheException e) {
        LOGGER.warn("Exception in getCacheLocations: {}", e.toString());
        pnfsMessage.setFailed(e.getRc(), e.getMessage());
    } catch (RuntimeException e) {
        LOGGER.error("Exception in getCacheLocations", e);
        pnfsMessage.setFailed(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, "Pnfs lookup failed");
    }
}
Also used : MissingResourceCacheException(diskCacheV111.util.MissingResourceCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) InvalidMessageCacheException(diskCacheV111.util.InvalidMessageCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) CacheException(diskCacheV111.util.CacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) PnfsId(diskCacheV111.util.PnfsId) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) Subject(javax.security.auth.Subject)

Example 4 with PnfsMessage

use of diskCacheV111.vehicles.PnfsMessage in project dcache by dCache.

the class PnfsManagerV3 method createEntry.

public void createEntry(PnfsCreateEntryMessage pnfsMessage) {
    checkArgument(pnfsMessage.getFileAttributes().isDefined(TYPE));
    FileAttributes assign = pnfsMessage.getFileAttributes();
    FileType type = assign.removeFileType();
    Subject subject = pnfsMessage.getSubject();
    String path = pnfsMessage.getPnfsPath();
    try {
        File file = new File(path);
        checkMask(subject, file.getParent(), pnfsMessage.getAccessMask());
        Set<FileAttribute> requested = pnfsMessage.getAcquire();
        FileAttributes attrs = null;
        switch(type) {
            case DIR:
                LOGGER.info("create directory {}", path);
                checkMkdirAllowed(pnfsMessage);
                PnfsId pnfsId = _nameSpaceProvider.createDirectory(subject, path, assign);
                pnfsMessage.setPnfsId(pnfsId);
                // the createEntry seem to be ok.
                try {
                    LOGGER.info("Trying to get storageInfo for {}", pnfsId);
                    /* If we were allowed to create the entry above, then
                         * we also ought to be allowed to read it here. Hence
                         * we use ROOT as the subject.
                         */
                    attrs = _nameSpaceProvider.getFileAttributes(ROOT, pnfsId, requested);
                } catch (CacheException e) {
                    LOGGER.warn("Can't determine storageInfo: {}", e.toString());
                }
                break;
            case REGULAR:
                LOGGER.info("create file {}", path);
                checkRestriction(pnfsMessage, UPLOAD);
                requested.add(FileAttribute.STORAGEINFO);
                requested.add(FileAttribute.PNFSID);
                attrs = _nameSpaceProvider.createFile(subject, path, assign, requested);
                StorageInfo info = attrs.getStorageInfo();
                if (info.getKey("path") == null) {
                    info.setKey("path", path);
                }
                info.setKey("uid", Integer.toString(assign.getOwnerIfPresent().orElse(-1)));
                info.setKey("gid", Integer.toString(assign.getGroupIfPresent().orElse(-1)));
                // REVISIT: consider removing xattr injection once pools can accept FileAttribute.XATTR
                if (assign.isDefined(XATTR)) {
                    assign.getXattrs().forEach((k, v) -> info.setKey(STORAGE_INFO_XATTR_PREFIX + k, v));
                }
                pnfsMessage.setPnfsId(attrs.getPnfsId());
                break;
            case LINK:
                checkArgument(pnfsMessage instanceof PnfsCreateSymLinkMessage);
                String destination = ((PnfsCreateSymLinkMessage) pnfsMessage).getDestination();
                LOGGER.info("create symlink {} to {}", path, destination);
                checkRestrictionOnParent(pnfsMessage, MANAGE);
                pnfsId = _nameSpaceProvider.createSymLink(subject, path, destination, assign);
                pnfsMessage.setPnfsId(pnfsId);
                break;
            default:
                throw new IllegalArgumentException("Unsupported type: " + type);
        }
        pnfsMessage.setFileAttributes(attrs);
        pnfsMessage.setSucceeded();
    } catch (CacheException e) {
        pnfsMessage.setFailed(e.getRc(), e.getMessage());
    } catch (RuntimeException e) {
        LOGGER.error("Bug found when creating entry:", e);
        pnfsMessage.setFailed(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, e);
    }
}
Also used : MissingResourceCacheException(diskCacheV111.util.MissingResourceCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) InvalidMessageCacheException(diskCacheV111.util.InvalidMessageCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) CacheException(diskCacheV111.util.CacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) PnfsId(diskCacheV111.util.PnfsId) PnfsCreateSymLinkMessage(org.dcache.vehicles.PnfsCreateSymLinkMessage) Subject(javax.security.auth.Subject) FileType(org.dcache.namespace.FileType) StorageInfo(diskCacheV111.vehicles.StorageInfo) PnfsSetFileAttributes(org.dcache.vehicles.PnfsSetFileAttributes) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes) FileAttributes(org.dcache.vehicles.FileAttributes) File(java.io.File) FileAttribute(org.dcache.namespace.FileAttribute)

Example 5 with PnfsMessage

use of diskCacheV111.vehicles.PnfsMessage in project dcache by dCache.

the class PnfsManagerV3 method postProcessFlush.

private void postProcessFlush(CellMessage envelope, PoolFileFlushedMessage pnfsMessage) {
    long timeout = envelope.getAdjustedTtl() - envelope.getLocalAge();
    /* Asynchronously notify flush notification targets about the flush. */
    PoolFileFlushedMessage notification = new PoolFileFlushedMessage(pnfsMessage.getPoolName(), pnfsMessage.getPnfsId(), pnfsMessage.getFileAttributes());
    List<ListenableFuture<PoolFileFlushedMessage>> futures = new ArrayList<>();
    for (String address : _flushNotificationTargets) {
        futures.add(_stub.send(new CellPath(address), notification, timeout));
    }
    /* Only generate positive reply if all notifications succeeded. */
    Futures.addCallback(Futures.allAsList(futures), new FutureCallback<List<PoolFileFlushedMessage>>() {

        @Override
        public void onSuccess(List<PoolFileFlushedMessage> result) {
            pnfsMessage.setSucceeded();
            reply();
        }

        @Override
        public void onFailure(Throwable t) {
            pnfsMessage.setFailed(CacheException.DEFAULT_ERROR_CODE, "PNFS manager failed while notifying other " + "components about the flush: " + t.getMessage());
            reply();
        }

        private void reply() {
            envelope.revertDirection();
            sendMessage(envelope);
        }
    });
}
Also used : CellPath(dmg.cells.nucleus.CellPath) PoolFileFlushedMessage(diskCacheV111.vehicles.PoolFileFlushedMessage) ArrayList(java.util.ArrayList) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

PnfsId (diskCacheV111.util.PnfsId)11 CacheException (diskCacheV111.util.CacheException)9 InvalidMessageCacheException (diskCacheV111.util.InvalidMessageCacheException)8 MissingResourceCacheException (diskCacheV111.util.MissingResourceCacheException)8 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)7 NotDirCacheException (diskCacheV111.util.NotDirCacheException)7 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)7 Subject (javax.security.auth.Subject)5 PnfsGetCacheLocationsMessage (diskCacheV111.vehicles.PnfsGetCacheLocationsMessage)4 PnfsGetFileAttributes (org.dcache.vehicles.PnfsGetFileAttributes)4 PnfsSetFileAttributes (org.dcache.vehicles.PnfsSetFileAttributes)4 ArrayList (java.util.ArrayList)3 FileAttribute (org.dcache.namespace.FileAttribute)3 FileAttributes (org.dcache.vehicles.FileAttributes)3 TimeoutCacheException (diskCacheV111.util.TimeoutCacheException)2 PnfsMessage (diskCacheV111.vehicles.PnfsMessage)2 StorageInfo (diskCacheV111.vehicles.StorageInfo)2 CellEndpoint (dmg.cells.nucleus.CellEndpoint)2 CellMessage (dmg.cells.nucleus.CellMessage)2 NoRouteToCellException (dmg.cells.nucleus.NoRouteToCellException)2