Search in sources :

Example 6 with SRMException

use of org.dcache.srm.SRMException in project dcache by dCache.

the class SrmShell method main.

public static void main(String[] arguments) throws Throwable {
    Args args = new Args(arguments);
    if (args.argc() == 0) {
        System.err.println("Usage: srmfs srm://HOST[:PORT][/DIRECTORY]");
        System.err.println("       srmfs httpg://HOST[:PORT]/WEBSERVICE");
        System.exit(4);
    }
    URI uri;
    try {
        uri = new URI(args.argv(0));
    } catch (URI.MalformedURIException e) {
        uri = null;
        System.err.println(args.argv(0) + ":" + e.getMessage());
        System.exit(1);
    }
    args.shift();
    try (SrmShell shell = new SrmShell(uri, args)) {
        closeOnShutdown(shell);
        shell.start(shell.getShellArgs());
        shell.awaitTransferCompletion();
    } catch (SRMException e) {
        System.err.println(uri + " failed request: " + e.getMessage());
        System.exit(1);
    } catch (IOException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
}
Also used : Args(org.dcache.util.Args) SRMException(org.dcache.srm.SRMException) IOException(java.io.IOException) URI(org.apache.axis.types.URI)

Example 7 with SRMException

use of org.dcache.srm.SRMException in project dcache by dCache.

the class Storage method putDone.

@Override
public void putDone(SRMUser user, String localTransferPath, URI surl, boolean overwrite) throws SRMException {
    try {
        Subject subject = asDcacheUser(user).getSubject();
        Restriction restriction = asDcacheUser(user).getRestriction();
        FsPath fullPath = getPath(surl);
        checkNonBrokenUpload(localTransferPath);
        EnumSet<CreateOption> options = EnumSet.noneOf(CreateOption.class);
        if (overwrite) {
            options.add(CreateOption.OVERWRITE_EXISTING);
        }
        PnfsCommitUpload msg = new PnfsCommitUpload(subject, restriction, FsPath.create(localTransferPath), fullPath, options, EnumSet.of(PNFSID, SIZE, STORAGEINFO));
        msg = _pnfsStub.sendAndWait(msg);
        DoorRequestInfoMessage infoMsg = new DoorRequestInfoMessage(getCellAddress());
        infoMsg.setSubject(subject);
        infoMsg.setBillingPath(fullPath.toString());
        infoMsg.setTransferPath(localTransferPath);
        infoMsg.setTransaction(CDC.getSession());
        infoMsg.setPnfsId(msg.getFileAttributes().getPnfsId());
        infoMsg.setResult(0, "");
        infoMsg.setFileSize(msg.getFileAttributes().getSizeIfPresent().orElse(0L));
        infoMsg.setStorageInfo(msg.getFileAttributes().getStorageInfo());
        Origin origin = Subjects.getOrigin(subject);
        if (origin != null) {
            infoMsg.setClient(origin.getAddress().getHostAddress());
        }
        _billingStub.notify(infoMsg);
    } catch (FileNotFoundCacheException e) {
        throw new SRMInvalidPathException(e.getMessage(), e);
    } catch (FileIsNewCacheException | FileCorruptedCacheException e) {
        throw new SRMException(e.getMessage(), e);
    } catch (PermissionDeniedCacheException e) {
        throw new SRMAuthorizationException("Permission denied.", e);
    } catch (FileExistsCacheException e) {
        throw new SRMDuplicationException(surl + " exists.", e);
    } catch (CacheException e) {
        throw new SRMInternalErrorException(e.getMessage(), e);
    } catch (InterruptedException e) {
        throw new SRMInternalErrorException("Operation interrupted", e);
    } catch (NoRouteToCellException e) {
        throw new SRMInternalErrorException("Internal communication failure", e);
    }
}
Also used : DoorRequestInfoMessage(diskCacheV111.vehicles.DoorRequestInfoMessage) Origin(org.dcache.auth.Origin) SRMAuthorizationException(org.dcache.srm.SRMAuthorizationException) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) CacheException(diskCacheV111.util.CacheException) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMInvalidPathException(org.dcache.srm.SRMInvalidPathException) Subject(javax.security.auth.Subject) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) Restriction(org.dcache.auth.attributes.Restriction) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMException(org.dcache.srm.SRMException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) CreateOption(org.dcache.namespace.CreateOption) PnfsCommitUpload(diskCacheV111.vehicles.PnfsCommitUpload) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) SRMDuplicationException(org.dcache.srm.SRMDuplicationException) FsPath(diskCacheV111.util.FsPath)

Example 8 with SRMException

use of org.dcache.srm.SRMException in project dcache by dCache.

the class Storage method moveEntry.

@Override
public void moveEntry(SRMUser abstractUser, URI from, URI to) throws SRMException {
    DcacheUser user = asDcacheUser(abstractUser);
    PnfsHandler handler = new PnfsHandler(_pnfs, user.getSubject(), user.getRestriction());
    FsPath fromPath = getPath(from);
    FsPath toPath = getPath(to);
    try {
        try {
            FileAttributes attr = handler.getFileAttributes(toPath.toString(), EnumSet.of(TYPE));
            /* We now know the destination exists. In case the
                 * source and destination names are identical, we
                 * silently ignore the request.
                 */
            if (fromPath.equals(toPath)) {
                return;
            }
            if (attr.getFileType() != FileType.DIR) {
                throw new SRMDuplicationException("Destination exists");
            }
            toPath = toPath.child(fromPath.name());
        } catch (FileNotFoundCacheException e) {
        /* Destination name does not exist; not a problem.
                 */
        }
        handler.renameEntry(fromPath.toString(), toPath.toString(), false);
    } catch (FileNotFoundCacheException e) {
        throw new SRMInvalidPathException("No such file or directory", e);
    } catch (FileExistsCacheException e) {
        throw new SRMDuplicationException("Destination exists", e);
    } catch (NotDirCacheException e) {
        /* The parent of the target name did not exist or was not
             * a directory.
             */
        FsPath parent = toPath.parent();
        throw new SRMInvalidPathException("No such directory: " + parent, e);
    } catch (PermissionDeniedCacheException e) {
        throw new SRMAuthorizationException("Permission denied");
    } catch (TimeoutCacheException e) {
        _log.error("Failed to rename {} due to timeout", fromPath);
        throw new SRMInternalErrorException("Internal name space timeout");
    } catch (CacheException e) {
        _log.error("Failed to rename {}: {}", fromPath, e.getMessage());
        throw new SRMException(String.format("Rename failed [rc=%d,msg=%s]", e.getRc(), e.getMessage()));
    }
}
Also used : SRMAuthorizationException(org.dcache.srm.SRMAuthorizationException) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) CacheException(diskCacheV111.util.CacheException) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMInvalidPathException(org.dcache.srm.SRMInvalidPathException) PnfsHandler(diskCacheV111.util.PnfsHandler) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMException(org.dcache.srm.SRMException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileAttributes(org.dcache.vehicles.FileAttributes) NotDirCacheException(diskCacheV111.util.NotDirCacheException) SRMDuplicationException(org.dcache.srm.SRMDuplicationException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) FsPath(diskCacheV111.util.FsPath) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException)

Example 9 with SRMException

use of org.dcache.srm.SRMException in project dcache by dCache.

the class Storage method checkWritePrivileges.

/**
 * Ensures that the user has write privileges for a path. That includes checking lookup
 * privileges. The file must exist for the call to succeed.
 *
 * @param user The user ID
 * @param surl The path to the file
 * @throws SRMAuthorizationException if the user lacks write privileges for this path.
 * @throws SRMInvalidPathException   if the file does not exist
 * @throws SRMInternalErrorException for transient errors
 * @throws SRMException              for other errors
 */
private void checkWritePrivileges(SRMUser user, URI surl) throws SRMException {
    try {
        DcacheUser dCacheUser = asDcacheUser(user);
        FsPath path = getPath(surl);
        PnfsHandler handler = new PnfsHandler(_pnfs, dCacheUser.getSubject(), dCacheUser.getRestriction());
        handler.getFileAttributes(path.toString(), EnumSet.noneOf(FileAttribute.class), EnumSet.of(AccessMask.WRITE_DATA), false);
    } catch (TimeoutCacheException e) {
        throw new SRMInternalErrorException("Internal name space timeout", e);
    } catch (FileNotFoundCacheException e) {
        throw new SRMInvalidPathException("Parent path does not exist", e);
    } catch (PermissionDeniedCacheException e) {
        throw new SRMAuthorizationException("Permission denied");
    } catch (CacheException e) {
        throw new SRMException(String.format("Operation failed [rc=%d,msg=%s]", e.getRc(), e.getMessage()));
    }
}
Also used : SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMAuthorizationException(org.dcache.srm.SRMAuthorizationException) SRMException(org.dcache.srm.SRMException) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) CacheException(diskCacheV111.util.CacheException) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMInvalidPathException(org.dcache.srm.SRMInvalidPathException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) PnfsHandler(diskCacheV111.util.PnfsHandler) FsPath(diskCacheV111.util.FsPath) FileAttribute(org.dcache.namespace.FileAttribute) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException)

Example 10 with SRMException

use of org.dcache.srm.SRMException in project dcache by dCache.

the class Storage method setFileMetaData.

@Override
public void setFileMetaData(SRMUser abstractUser, URI surl, FileMetaData fmd) throws SRMException {
    DcacheUser user = asDcacheUser(abstractUser);
    FsPath path = getPath(surl);
    PnfsHandler handler = new PnfsHandler(_pnfs, user.getSubject(), user.getRestriction());
    try {
        if (!(fmd instanceof DcacheFileMetaData)) {
            throw new SRMException("Storage.setFileMetaData: " + "metadata in not dCacheMetaData");
        }
        int mode = ((DcacheFileMetaData) fmd).permMode;
        handler.setFileAttributes(path, FileAttributes.ofMode(mode));
    } catch (TimeoutCacheException e) {
        throw new SRMInternalErrorException("PnfsManager is unavailable: " + e.getMessage(), e);
    } catch (FileNotFoundCacheException e) {
        throw new SRMInvalidPathException("No such file or directory", e);
    } catch (PermissionDeniedCacheException e) {
        throw new SRMAuthorizationException("Permission denied");
    } catch (CacheException e) {
        throw new SRMException("SetFileMetaData failed for " + fmd.SURL + "; return code=" + e.getRc() + " reason=" + e.getMessage());
    }
}
Also used : SRMAuthorizationException(org.dcache.srm.SRMAuthorizationException) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) CacheException(diskCacheV111.util.CacheException) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMInvalidPathException(org.dcache.srm.SRMInvalidPathException) PnfsHandler(diskCacheV111.util.PnfsHandler) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMException(org.dcache.srm.SRMException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FsPath(diskCacheV111.util.FsPath) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException)

Aggregations

SRMException (org.dcache.srm.SRMException)52 SRMInternalErrorException (org.dcache.srm.SRMInternalErrorException)34 SRMAuthorizationException (org.dcache.srm.SRMAuthorizationException)26 SRMInvalidPathException (org.dcache.srm.SRMInvalidPathException)25 CacheException (diskCacheV111.util.CacheException)20 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)19 TimeoutCacheException (diskCacheV111.util.TimeoutCacheException)17 TReturnStatus (org.dcache.srm.v2_2.TReturnStatus)17 FileCorruptedCacheException (diskCacheV111.util.FileCorruptedCacheException)16 FileExistsCacheException (diskCacheV111.util.FileExistsCacheException)16 FileIsNewCacheException (diskCacheV111.util.FileIsNewCacheException)16 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)16 NotDirCacheException (diskCacheV111.util.NotDirCacheException)16 SRMInvalidRequestException (org.dcache.srm.SRMInvalidRequestException)14 FsPath (diskCacheV111.util.FsPath)11 NoRouteToCellException (dmg.cells.nucleus.NoRouteToCellException)10 SRMDuplicationException (org.dcache.srm.SRMDuplicationException)8 PnfsHandler (diskCacheV111.util.PnfsHandler)7 Subject (javax.security.auth.Subject)7 ArrayOfString (org.dcache.srm.v2_2.ArrayOfString)7