Search in sources :

Example 1 with SRMExceedAllocationException

use of org.dcache.srm.SRMExceedAllocationException 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)

Example 2 with SRMExceedAllocationException

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

the class TStatusCodes method checkSuccess.

public static void checkSuccess(TReturnStatus returnStatus, TStatusCode... success) throws SRMException {
    TStatusCode statusCode = returnStatus.getStatusCode();
    String explanation = returnStatus.getExplanation();
    if (asList(success).contains(statusCode)) {
        return;
    }
    if (explanation == null) {
        explanation = "Operation failed with " + returnStatus.getStatusCode();
    }
    if (statusCode == TStatusCode.SRM_FAILURE) {
        throw new SRMException(explanation);
    } else if (statusCode == TStatusCode.SRM_PARTIAL_SUCCESS) {
        throw new SRMOtherException(statusCode, explanation);
    } else if (statusCode == TStatusCode.SRM_AUTHENTICATION_FAILURE) {
        throw new SRMOtherException(statusCode, explanation);
    } else if (statusCode == TStatusCode.SRM_AUTHORIZATION_FAILURE) {
        throw new SRMAuthorizationException(explanation);
    } else if (statusCode == TStatusCode.SRM_INVALID_REQUEST) {
        throw new SRMInvalidRequestException(explanation);
    } else if (statusCode == TStatusCode.SRM_INVALID_PATH) {
        throw new SRMInvalidPathException(explanation);
    } else if (statusCode == TStatusCode.SRM_FILE_LIFETIME_EXPIRED) {
        throw new SRMOtherException(statusCode, explanation);
    } else if (statusCode == TStatusCode.SRM_SPACE_LIFETIME_EXPIRED) {
        throw new SRMSpaceLifetimeExpiredException(explanation);
    } else if (statusCode == TStatusCode.SRM_EXCEED_ALLOCATION) {
        throw new SRMExceedAllocationException(explanation);
    } else if (statusCode == TStatusCode.SRM_NO_USER_SPACE) {
        throw new SRMOtherException(statusCode, explanation);
    } else if (statusCode == TStatusCode.SRM_NO_FREE_SPACE) {
        throw new SRMNoFreeSpaceException(explanation);
    } else if (statusCode == TStatusCode.SRM_DUPLICATION_ERROR) {
        throw new SRMDuplicationException(explanation);
    } else if (statusCode == TStatusCode.SRM_NON_EMPTY_DIRECTORY) {
        throw new SRMNonEmptyDirectoryException(explanation);
    } else if (statusCode == TStatusCode.SRM_TOO_MANY_RESULTS) {
        throw new SRMTooManyResultsException(explanation);
    } else if (statusCode == TStatusCode.SRM_INTERNAL_ERROR) {
        throw new SRMInternalErrorException(explanation);
    } else if (statusCode == TStatusCode.SRM_FATAL_INTERNAL_ERROR) {
        throw new SRMInternalErrorException(explanation);
    } else if (statusCode == TStatusCode.SRM_NOT_SUPPORTED) {
        throw new SRMNotSupportedException(explanation);
    } else if (statusCode == TStatusCode.SRM_REQUEST_QUEUED) {
        throw new SRMOtherException(statusCode, explanation);
    } else if (statusCode == TStatusCode.SRM_REQUEST_INPROGRESS) {
        throw new SRMOtherException(statusCode, explanation);
    } else if (statusCode == TStatusCode.SRM_ABORTED) {
        throw new SRMAbortedException(explanation);
    } else if (statusCode == TStatusCode.SRM_RELEASED) {
        throw new SRMReleasedException(explanation);
    } else if (statusCode == TStatusCode.SRM_FILE_PINNED) {
        throw new SRMOtherException(statusCode, explanation);
    } else if (statusCode == TStatusCode.SRM_FILE_IN_CACHE) {
        throw new SRMOtherException(statusCode, explanation);
    } else if (statusCode == TStatusCode.SRM_SPACE_AVAILABLE) {
        throw new SRMOtherException(statusCode, explanation);
    } else if (statusCode == TStatusCode.SRM_LOWER_SPACE_GRANTED) {
        throw new SRMOtherException(statusCode, explanation);
    } else if (statusCode == TStatusCode.SRM_REQUEST_TIMED_OUT) {
        throw new SRMRequestTimedOutException(explanation);
    } else if (statusCode == TStatusCode.SRM_LAST_COPY) {
        throw new SRMOtherException(statusCode, explanation);
    } else if (statusCode == TStatusCode.SRM_FILE_BUSY) {
        throw new SRMOtherException(statusCode, explanation);
    } else if (statusCode == TStatusCode.SRM_FILE_LOST) {
        throw new SRMOtherException(statusCode, explanation);
    } else if (statusCode == TStatusCode.SRM_FILE_UNAVAILABLE) {
        throw new SRMFileUnvailableException(explanation);
    } else if (statusCode == TStatusCode.SRM_CUSTOM_STATUS) {
        throw new SRMOtherException(statusCode, explanation);
    } else {
        throw new SRMOtherException(statusCode, explanation);
    }
}
Also used : SRMExceedAllocationException(org.dcache.srm.SRMExceedAllocationException) SRMAuthorizationException(org.dcache.srm.SRMAuthorizationException) SRMNotSupportedException(org.dcache.srm.SRMNotSupportedException) SRMNonEmptyDirectoryException(org.dcache.srm.SRMNonEmptyDirectoryException) SRMInvalidPathException(org.dcache.srm.SRMInvalidPathException) SRMAbortedException(org.dcache.srm.SRMAbortedException) TStatusCode(org.dcache.srm.v2_2.TStatusCode) SRMTooManyResultsException(org.dcache.srm.SRMTooManyResultsException) SRMRequestTimedOutException(org.dcache.srm.SRMRequestTimedOutException) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) SRMException(org.dcache.srm.SRMException) SRMFileUnvailableException(org.dcache.srm.SRMFileUnvailableException) SRMReleasedException(org.dcache.srm.SRMReleasedException) SRMOtherException(org.dcache.srm.SRMOtherException) SRMSpaceLifetimeExpiredException(org.dcache.srm.SRMSpaceLifetimeExpiredException) SRMInvalidRequestException(org.dcache.srm.SRMInvalidRequestException) SRMNoFreeSpaceException(org.dcache.srm.SRMNoFreeSpaceException) SRMDuplicationException(org.dcache.srm.SRMDuplicationException)

Aggregations

SRMAuthorizationException (org.dcache.srm.SRMAuthorizationException)2 SRMDuplicationException (org.dcache.srm.SRMDuplicationException)2 SRMExceedAllocationException (org.dcache.srm.SRMExceedAllocationException)2 SRMException (org.dcache.srm.SRMException)2 SRMInternalErrorException (org.dcache.srm.SRMInternalErrorException)2 SRMInvalidPathException (org.dcache.srm.SRMInvalidPathException)2 SRMInvalidRequestException (org.dcache.srm.SRMInvalidRequestException)2 SRMNotSupportedException (org.dcache.srm.SRMNotSupportedException)2 SRMSpaceLifetimeExpiredException (org.dcache.srm.SRMSpaceLifetimeExpiredException)2 Space (diskCacheV111.services.space.Space)1 AccessLatency (diskCacheV111.util.AccessLatency)1 FsPath (diskCacheV111.util.FsPath)1 RetentionPolicy (diskCacheV111.util.RetentionPolicy)1 PnfsCreateUploadPath (diskCacheV111.vehicles.PnfsCreateUploadPath)1 ExecutionException (java.util.concurrent.ExecutionException)1 Subject (javax.security.auth.Subject)1 Restriction (org.dcache.auth.attributes.Restriction)1 CreateOption (org.dcache.namespace.CreateOption)1 SRMAbortedException (org.dcache.srm.SRMAbortedException)1 SRMFileUnvailableException (org.dcache.srm.SRMFileUnvailableException)1