Search in sources :

Example 1 with PnfsCreateUploadPath

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

the class XrootdDoor method getUploadPath.

private FsPath getUploadPath(Subject subject, Restriction restriction, boolean createDir, boolean overwrite, Long size, FsPath path, FsPath rootPath) throws CacheException, InterruptedException {
    try {
        EnumSet<CreateOption> options = EnumSet.noneOf(CreateOption.class);
        if (overwrite) {
            options.add(CreateOption.OVERWRITE_EXISTING);
        }
        if (createDir) {
            options.add(CreateOption.CREATE_PARENTS);
        }
        PnfsCreateUploadPath msg = new PnfsCreateUploadPath(subject, restriction, path, rootPath, size, null, null, null, options);
        msg = _pnfsStub.sendAndWait(msg);
        return msg.getUploadPath();
    } catch (NoRouteToCellException ex) {
        throw new CacheException("Internal communication failure", ex);
    }
}
Also used : PnfsCreateUploadPath(diskCacheV111.vehicles.PnfsCreateUploadPath) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) CacheException(diskCacheV111.util.CacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) CreateOption(org.dcache.namespace.CreateOption)

Example 2 with PnfsCreateUploadPath

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

the class PnfsManagerTest method testCancelUpload.

@Test
public void testCancelUpload() throws ChimeraFsException {
    FsPath root = FsPath.ROOT;
    FsPath path = FsPath.create("/test");
    PnfsCreateUploadPath create = new PnfsCreateUploadPath(Subjects.ROOT, Restrictions.none(), path, root, null, null, null, null, EnumSet.noneOf(CreateOption.class));
    _pnfsManager.createUploadPath(create);
    assertThat(create.getReturnCode(), is(0));
    PnfsCancelUpload cancel = new PnfsCancelUpload(Subjects.ROOT, Restrictions.none(), create.getUploadPath(), path, EnumSet.noneOf(FileAttribute.class), "request aborted");
    _pnfsManager.cancelUpload(cancel);
    assertThat(cancel.getReturnCode(), is(0));
    assertNotExists(create.getUploadPath().toString());
    assertNotExists("/test");
}
Also used : PnfsCreateUploadPath(diskCacheV111.vehicles.PnfsCreateUploadPath) PnfsCancelUpload(diskCacheV111.vehicles.PnfsCancelUpload) CreateOption(org.dcache.namespace.CreateOption) FsPath(diskCacheV111.util.FsPath) FileAttribute(org.dcache.namespace.FileAttribute) Test(org.junit.Test)

Example 3 with PnfsCreateUploadPath

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

the class PnfsManagerV3 method createUploadPath.

void createUploadPath(PnfsCreateUploadPath message) {
    try {
        checkRestriction(message, UPLOAD);
        FsPath uploadPath = _nameSpaceProvider.createUploadPath(message.getSubject(), message.getPath(), message.getRootPath(), message.getSize(), message.getAccessLatency(), message.getRetentionPolicy(), message.getSpaceToken(), message.getOptions());
        message.setUploadPath(uploadPath);
        message.setSucceeded();
    } catch (CacheException e) {
        message.setFailed(e.getRc(), e.getMessage());
    } catch (RuntimeException e) {
        LOGGER.error("Create upload path failed", e);
        message.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) FsPath(diskCacheV111.util.FsPath)

Example 4 with PnfsCreateUploadPath

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

the class Storage method messageArrived.

public void messageArrived(PnfsCreateUploadPath msg) {
    // Catches replies for which the callback timed out
    if (msg.isReply() && msg.getReturnCode() == 0) {
        PnfsCancelUpload message = new PnfsCancelUpload(msg.getSubject(), msg.getRestriction(), msg.getUploadPath(), msg.getPath(), EnumSet.noneOf(FileAttribute.class), "SRM upload aborted: timeout creating upload path");
        _pnfsStub.notify(message);
    }
}
Also used : PnfsCancelUpload(diskCacheV111.vehicles.PnfsCancelUpload) FileAttribute(org.dcache.namespace.FileAttribute)

Example 5 with PnfsCreateUploadPath

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

the class Storage method prepareToPut.

@Override
public CheckedFuture<String, ? extends SRMException> prepareToPut(final SRMUser srmUser, URI surl, Long size, String accessLatency, String retentionPolicy, String spaceToken, boolean overwrite) {
    try {
        DcacheUser user = asDcacheUser(srmUser);
        Subject subject = user.getSubject();
        Restriction restriction = user.getRestriction();
        FsPath fullPath = getPath(surl);
        if (spaceToken != null) {
            if (!_isSpaceManagerEnabled) {
                return immediateFailedCheckedFuture(new SRMNotSupportedException(SPACEMANAGER_DISABLED_MESSAGE));
            }
            /* This check could and maybe should be done on the SRM side of AbstractStorageElement:
                 * The targetSpaceToken is the same for all SURLs in an srmPrepareToPut request, and the
                 * SRM_EXCEED_ALLOCATION should also be returned if the entire srmPrepareToPut request
                 * is larger than available space in the reservation - that's a check we cannot possibly
                 * to on an individual SURL.
                 */
            try {
                Optional<Space> optionalSpace = spaces.get(spaceToken);
                if (!optionalSpace.isPresent()) {
                    return immediateFailedCheckedFuture(new SRMInvalidRequestException("The space token " + spaceToken + " does not refer to an existing known space reservation."));
                }
                Space space = optionalSpace.get();
                if (space.getExpirationTime() != null && space.getExpirationTime() < System.currentTimeMillis()) {
                    return immediateFailedCheckedFuture(new SRMSpaceLifetimeExpiredException("Space reservation associated with the space token " + spaceToken + " is expired."));
                }
                if (size != null && space.getAvailableSpaceInBytes() < size) {
                    return immediateFailedCheckedFuture(new SRMExceedAllocationException("Space associated with the space token " + spaceToken + " is not enough to hold SURL."));
                }
            } catch (ExecutionException e) {
                return immediateFailedCheckedFuture(new SRMException("Failure while querying space reservation: " + e.getCause().getMessage()));
            }
        }
        AccessLatency al = (accessLatency != null) ? AccessLatency.valueOf(accessLatency) : null;
        RetentionPolicy rp = (retentionPolicy != null) ? RetentionPolicy.valueOf(retentionPolicy) : null;
        EnumSet<CreateOption> options = EnumSet.noneOf(CreateOption.class);
        if (overwrite) {
            options.add(CreateOption.OVERWRITE_EXISTING);
        }
        if (config.isRecursiveDirectoryCreation()) {
            options.add(CreateOption.CREATE_PARENTS);
        }
        PnfsCreateUploadPath msg = new PnfsCreateUploadPath(subject, restriction, fullPath, user.getRoot(), size, al, rp, spaceToken, options);
        final SettableFuture<String> future = SettableFuture.create();
        CellStub.addCallback(_pnfsStub.send(msg), new AbstractMessageCallback<PnfsCreateUploadPath>() {

            int failures = 0;

            @Override
            public void success(PnfsCreateUploadPath message) {
                future.set(message.getUploadPath().toString());
            }

            @Override
            public void failure(int rc, Object error) {
                failures++;
                String msg = Objects.toString(error, "");
                switch(rc) {
                    case CacheException.PERMISSION_DENIED:
                        future.setException(new SRMAuthorizationException(msg));
                        break;
                    case CacheException.FILE_EXISTS:
                        future.setException(new SRMDuplicationException(msg));
                        break;
                    case CacheException.FILE_NOT_FOUND:
                    case CacheException.NOT_DIR:
                        future.setException(new SRMInvalidPathException(msg));
                        break;
                    case CacheException.LOCKED:
                        if (failures < 3) {
                            /* Usually due to concurrent uploads to the same non-existing target
                                       * directory. Retry a few times.
                                       */
                            PnfsCreateUploadPath retry = new PnfsCreateUploadPath(subject, restriction, fullPath, user.getRoot(), size, al, rp, spaceToken, options);
                            CellStub.addCallback(_pnfsStub.send(retry), this, _executor);
                        } else {
                            future.setException(new SRMInternalErrorException(msg));
                        }
                        break;
                    case CacheException.TIMEOUT:
                    default:
                        future.setException(new SRMInternalErrorException(msg));
                        break;
                }
            }
        }, _executor);
        return Futures.makeChecked(future, new ToSRMException());
    } catch (SRMAuthorizationException | SRMInvalidPathException e) {
        return immediateFailedCheckedFuture(e);
    }
}
Also used : SRMNotSupportedException(org.dcache.srm.SRMNotSupportedException) SRMAuthorizationException(org.dcache.srm.SRMAuthorizationException) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) SRMException(org.dcache.srm.SRMException) SRMSpaceLifetimeExpiredException(org.dcache.srm.SRMSpaceLifetimeExpiredException) ExecutionException(java.util.concurrent.ExecutionException) SRMDuplicationException(org.dcache.srm.SRMDuplicationException) FsPath(diskCacheV111.util.FsPath) Space(diskCacheV111.services.space.Space) TMetaDataSpace(org.dcache.srm.v2_2.TMetaDataSpace) SRMExceedAllocationException(org.dcache.srm.SRMExceedAllocationException) PnfsCreateUploadPath(diskCacheV111.vehicles.PnfsCreateUploadPath) TAccessLatency(org.dcache.srm.v2_2.TAccessLatency) AccessLatency(diskCacheV111.util.AccessLatency) SRMInvalidPathException(org.dcache.srm.SRMInvalidPathException) RetentionPolicy(diskCacheV111.util.RetentionPolicy) TRetentionPolicy(org.dcache.srm.v2_2.TRetentionPolicy) Subject(javax.security.auth.Subject) Restriction(org.dcache.auth.attributes.Restriction) CreateOption(org.dcache.namespace.CreateOption) SRMInvalidRequestException(org.dcache.srm.SRMInvalidRequestException)

Aggregations

FsPath (diskCacheV111.util.FsPath)4 PnfsCreateUploadPath (diskCacheV111.vehicles.PnfsCreateUploadPath)4 CreateOption (org.dcache.namespace.CreateOption)4 PnfsCancelUpload (diskCacheV111.vehicles.PnfsCancelUpload)3 FileAttribute (org.dcache.namespace.FileAttribute)3 CacheException (diskCacheV111.util.CacheException)2 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)2 Test (org.junit.Test)2 Space (diskCacheV111.services.space.Space)1 AccessLatency (diskCacheV111.util.AccessLatency)1 FileExistsCacheException (diskCacheV111.util.FileExistsCacheException)1 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)1 InvalidMessageCacheException (diskCacheV111.util.InvalidMessageCacheException)1 MissingResourceCacheException (diskCacheV111.util.MissingResourceCacheException)1 NotDirCacheException (diskCacheV111.util.NotDirCacheException)1 RetentionPolicy (diskCacheV111.util.RetentionPolicy)1 NoRouteToCellException (dmg.cells.nucleus.NoRouteToCellException)1 ExecutionException (java.util.concurrent.ExecutionException)1 Subject (javax.security.auth.Subject)1 Restriction (org.dcache.auth.attributes.Restriction)1