Search in sources :

Example 1 with InvalidMessageCacheException

use of diskCacheV111.util.InvalidMessageCacheException in project dcache by dCache.

the class ChimeraNameSpaceProvider method checkIsTemporaryDirectory.

protected void checkIsTemporaryDirectory(FsPath temporaryPath, FsPath temporaryDir) throws NotFileCacheException, InvalidMessageCacheException {
    checkState(_uploadDirectory != null, "Upload directory is not configured.");
    FsPath temporaryDirContainer = getParentOfFile(temporaryDir);
    if (_uploadDirectory.startsWith("/")) {
        if (!temporaryDirContainer.hasPrefix(FsPath.create(_uploadDirectory))) {
            throw new InvalidMessageCacheException(temporaryPath + " is not part of the " + _uploadDirectory + " tree.");
        }
    } else {
        if (!temporaryDirContainer.contains(_uploadDirectory)) {
            throw new InvalidMessageCacheException(temporaryPath + " is not part of the " + _uploadDirectory + " tree.");
        }
    }
    if (temporaryDir.isRoot()) {
        throw new InvalidMessageCacheException("A temporary upload path cannot be in the root directory.");
    }
}
Also used : InvalidMessageCacheException(diskCacheV111.util.InvalidMessageCacheException) FsPath(diskCacheV111.util.FsPath)

Example 2 with InvalidMessageCacheException

use of diskCacheV111.util.InvalidMessageCacheException in project dcache by dCache.

the class PnfsManagerV3 method populatePnfsId.

private PnfsId populatePnfsId(PnfsMessage message) throws CacheException {
    PnfsId pnfsId = message.getPnfsId();
    if (pnfsId == null) {
        String path = message.getPnfsPath();
        if (path == null) {
            throw new InvalidMessageCacheException("no pnfsid or path defined");
        }
        pnfsId = _nameSpaceProvider.pathToPnfsid(message.getSubject(), path, message.isFollowSymlink());
        message.setPnfsId(pnfsId);
    }
    return pnfsId;
}
Also used : InvalidMessageCacheException(diskCacheV111.util.InvalidMessageCacheException) PnfsId(diskCacheV111.util.PnfsId)

Example 3 with InvalidMessageCacheException

use of diskCacheV111.util.InvalidMessageCacheException in project dcache by dCache.

the class ProbeResponseEngine method queryUrl.

@Override
public void queryUrl(HttpRequest request) throws HttpException {
    try {
        String[] urlItems = request.getRequestTokens();
        if (urlItems.length < 2) {
            throw new HttpException(404, "No such property");
        }
        /* urlItems[0] is the mount point.
             */
        BeanQueryMessage queryMessage = (urlItems.length == 3) ? new BeanQuerySinglePropertyMessage(urlItems[2]) : new BeanQueryAllPropertiesMessage();
        BeanQueryMessage queryReply = stub.sendAndWait(new CellPath(urlItems[1]), queryMessage);
        request.setContentType("application/json; charset=utf-8");
        Writer writer = new OutputStreamWriter(request.getOutputStream(), UTF_8);
        writer.append(new GsonBuilder().serializeSpecialFloatingPointValues().setPrettyPrinting().disableHtmlEscaping().create().toJson(queryReply.getResult()));
        writer.flush();
    } catch (NoRouteToCellException e) {
        throw new HttpException(503, "The cell was unreachable, suspect trouble.");
    } catch (TimeoutCacheException e) {
        throw new HttpException(503, "The cell took too long to reply, suspect trouble.");
    } catch (InvalidMessageCacheException e) {
        throw new HttpException(404, "No such property");
    } catch (CacheException | IOException e) {
        throw new HttpException(500, e.getMessage());
    } catch (InterruptedException e) {
        throw new HttpException(503, "Received interrupt whilst processing data. Please try again later.");
    }
}
Also used : CellPath(dmg.cells.nucleus.CellPath) GsonBuilder(com.google.gson.GsonBuilder) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) CacheException(diskCacheV111.util.CacheException) InvalidMessageCacheException(diskCacheV111.util.InvalidMessageCacheException) InvalidMessageCacheException(diskCacheV111.util.InvalidMessageCacheException) IOException(java.io.IOException) BeanQueryMessage(org.dcache.vehicles.BeanQueryMessage) BeanQueryAllPropertiesMessage(org.dcache.vehicles.BeanQueryAllPropertiesMessage) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) HttpException(dmg.util.HttpException) BeanQuerySinglePropertyMessage(org.dcache.vehicles.BeanQuerySinglePropertyMessage) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException)

Example 4 with InvalidMessageCacheException

use of diskCacheV111.util.InvalidMessageCacheException in project dcache by dCache.

the class PnfsManagerV3 method deleteEntry.

public void deleteEntry(PnfsDeleteEntryMessage pnfsMessage) {
    String path = pnfsMessage.getPnfsPath();
    PnfsId pnfsId = pnfsMessage.getPnfsId();
    Subject subject = pnfsMessage.getSubject();
    Set<FileType> allowed = pnfsMessage.getAllowedFileTypes();
    Set<FileAttribute> requested = pnfsMessage.getRequestedAttributes();
    try {
        if (path == null && pnfsId == null) {
            throw new InvalidMessageCacheException("pnfsid or path have to be defined for PnfsDeleteEntryMessage");
        }
        checkMask(pnfsMessage);
        checkRestriction(pnfsMessage, DELETE);
        FileAttributes attributes;
        if (path != null) {
            LOGGER.info("delete PNFS entry for {}", path);
            if (pnfsId != null) {
                attributes = _nameSpaceProvider.deleteEntry(subject, allowed, pnfsId, path, requested);
            } else {
                requested.add(PNFSID);
                attributes = _nameSpaceProvider.deleteEntry(subject, allowed, path, requested);
                pnfsMessage.setPnfsId(attributes.getPnfsId());
            }
        } else {
            LOGGER.info("delete PNFS entry for {}", pnfsId);
            attributes = _nameSpaceProvider.deleteEntry(subject, allowed, pnfsId, requested);
        }
        pnfsMessage.setFileAttributes(attributes);
        pnfsMessage.setSucceeded();
    } catch (FileNotFoundCacheException e) {
        pnfsMessage.setFailed(CacheException.FILE_NOT_FOUND, e.getMessage());
    } catch (CacheException e) {
        LOGGER.warn("Failed to delete entry: {}", e.getMessage());
        pnfsMessage.setFailed(e.getRc(), e.getMessage());
    } catch (RuntimeException e) {
        LOGGER.error("Failed to delete entry", e);
        pnfsMessage.setFailed(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, e);
    }
}
Also used : FileType(org.dcache.namespace.FileType) MissingResourceCacheException(diskCacheV111.util.MissingResourceCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) InvalidMessageCacheException(diskCacheV111.util.InvalidMessageCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) CacheException(diskCacheV111.util.CacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) InvalidMessageCacheException(diskCacheV111.util.InvalidMessageCacheException) PnfsId(diskCacheV111.util.PnfsId) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) PnfsSetFileAttributes(org.dcache.vehicles.PnfsSetFileAttributes) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes) FileAttributes(org.dcache.vehicles.FileAttributes) Subject(javax.security.auth.Subject) FileAttribute(org.dcache.namespace.FileAttribute)

Example 5 with InvalidMessageCacheException

use of diskCacheV111.util.InvalidMessageCacheException in project dcache by dCache.

the class PnfsManagerV3 method rename.

public void rename(PnfsRenameMessage msg) {
    try {
        checkMask(msg);
        PnfsId pnfsId = msg.getPnfsId();
        String sourcePath = msg.getPnfsPath();
        String destinationPath = msg.newName();
        // This case is for compatibility with versions before 2.14
        if (sourcePath == null) {
            if (pnfsId == null) {
                throw new InvalidMessageCacheException("Either path or pnfs id is required.");
            }
            sourcePath = _nameSpaceProvider.pnfsidToPath(msg.getSubject(), pnfsId);
        }
        LOGGER.info("Rename {} to new name: {}", sourcePath, destinationPath);
        checkRestriction(msg, MANAGE, FsPath.create(sourcePath).parent());
        checkRestriction(msg, MANAGE, FsPath.create(destinationPath).parent());
        boolean overwrite = msg.getOverwrite() && !msg.getRestriction().isRestricted(DELETE, FsPath.create(destinationPath));
        _nameSpaceProvider.rename(msg.getSubject(), pnfsId, sourcePath, destinationPath, overwrite);
    } catch (CacheException e) {
        msg.setFailed(e.getRc(), e.getMessage());
    } catch (RuntimeException e) {
        LOGGER.error(e.toString(), e);
        msg.setFailed(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, "Pnfs rename 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) InvalidMessageCacheException(diskCacheV111.util.InvalidMessageCacheException) PnfsId(diskCacheV111.util.PnfsId)

Aggregations

InvalidMessageCacheException (diskCacheV111.util.InvalidMessageCacheException)8 CacheException (diskCacheV111.util.CacheException)6 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)3 PnfsId (diskCacheV111.util.PnfsId)3 FileAttributes (org.dcache.vehicles.FileAttributes)3 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)2 MissingResourceCacheException (diskCacheV111.util.MissingResourceCacheException)2 NotDirCacheException (diskCacheV111.util.NotDirCacheException)2 TimeoutCacheException (diskCacheV111.util.TimeoutCacheException)2 NoRouteToCellException (dmg.cells.nucleus.NoRouteToCellException)2 URI (java.net.URI)2 GsonBuilder (com.google.gson.GsonBuilder)1 FsPath (diskCacheV111.util.FsPath)1 CellPath (dmg.cells.nucleus.CellPath)1 HttpException (dmg.util.HttpException)1 File (java.io.File)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 Date (java.util.Date)1