Search in sources :

Example 1 with SRMInvalidRequestException

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

the class LsFileRequest method getMetaDataPathDetail.

protected TMetaDataPathDetail getMetaDataPathDetail() throws SRMInvalidRequestException {
    rlock();
    try {
        if (metaDataPathDetail != null) {
            return metaDataPathDetail;
        }
        if (getState() == State.DONE) {
            /* If the request has been processed yet metaDataPathDetail
                 * is null then the information is no longer known.  This
                 * can happen if the information has been delivered to the
                 * client, this Request has been garbage collected, and the
                 * request was fetched back from the database to process a
                 * StatusOfLsRequest request.
                 */
            throw new SRMInvalidRequestException("Response no longer available.");
        }
        TMetaDataPathDetail detail = new TMetaDataPathDetail();
        detail.setPath(getPath(surl));
        detail.setStatus(getReturnStatus());
        return detail;
    } finally {
        runlock();
    }
}
Also used : ArrayOfTMetaDataPathDetail(org.dcache.srm.v2_2.ArrayOfTMetaDataPathDetail) TMetaDataPathDetail(org.dcache.srm.v2_2.TMetaDataPathDetail) SRMInvalidRequestException(org.dcache.srm.SRMInvalidRequestException)

Example 2 with SRMInvalidRequestException

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

the class RequestCredential method acceptAlternative.

/**
 * Allow a user to specify an alternative credential to use.
 */
public synchronized void acceptAlternative(String description) throws SRMInvalidRequestException {
    if (description == null) {
        return;
    }
    if (!description.startsWith("gridsite:")) {
        throw new SRMInvalidRequestException("Unknown credential type: " + description);
    }
    String idLabel = description.substring(9);
    try {
        long id = Long.parseLong(idLabel);
        RequestCredential credential = storage.getRequestCredential(id);
        if (credential == null || !credential.credentialName.equals(this.credentialName)) {
            // discovering which other credentials exist.
            throw new IllegalArgumentException("Unknown credential: " + credentialName);
        }
        if (credential.getDelegatedCredentialRemainingLifetime() == 0) {
            throw new IllegalArgumentException("Credential " + description + " has expired");
        }
        updateCredential(credential.delegatedCredential);
    } catch (NumberFormatException e) {
        throw new SRMInvalidRequestException("Badly formatted credential id: " + idLabel);
    }
}
Also used : SRMInvalidRequestException(org.dcache.srm.SRMInvalidRequestException)

Example 3 with SRMInvalidRequestException

use of org.dcache.srm.SRMInvalidRequestException 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 4 with SRMInvalidRequestException

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

the class SrmPrepareToGet method isStagingAllowed.

private boolean isStagingAllowed() throws SRMInvalidRequestException {
    boolean allowed = true;
    ArrayOfTExtraInfo info = request.getStorageSystemInfo();
    if (info != null) {
        TExtraInfo[] array = info.getExtraInfoArray();
        if (array != null) {
            List<String> stageValues = Arrays.stream(array).filter(i -> Objects.equals(i.getKey(), "stage")).map(i -> i.getValue()).collect(Collectors.toList());
            if (!stageValues.isEmpty()) {
                if (stageValues.size() > 1) {
                    throw new SRMInvalidRequestException("Multiple storageSystemInfo 'stage' entries.");
                }
                String stageValue = stageValues.get(0);
                if (stageValue == null) {
                    throw new SRMInvalidRequestException("Missing value for storageSystemInfo 'stage' entry.");
                }
                switch(stageValue) {
                    case "allow":
                        allowed = true;
                        break;
                    case "deny":
                        allowed = false;
                        break;
                    default:
                        throw new SRMInvalidRequestException("Invalid value \"" + stageValue + "\" for storageSystemInfo 'stage' entry, must be \"allow\" or \"deny\"");
                }
            }
        }
    }
    return allowed;
}
Also used : Arrays(java.util.Arrays) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) ArrayOfTExtraInfo(org.dcache.srm.v2_2.ArrayOfTExtraInfo) TExtraInfo(org.dcache.srm.v2_2.TExtraInfo) TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) LoggerFactory(org.slf4j.LoggerFactory) IllegalStateTransition(org.dcache.srm.scheduler.IllegalStateTransition) TGetFileRequest(org.dcache.srm.v2_2.TGetFileRequest) Lifetimes(org.dcache.srm.util.Lifetimes) AbstractStorageElement(org.dcache.srm.AbstractStorageElement) Predicates.in(com.google.common.base.Predicates.in) SRMInvalidRequestException(org.dcache.srm.SRMInvalidRequestException) Arrays.asList(java.util.Arrays.asList) Objects.requireNonNull(java.util.Objects.requireNonNull) Tools(org.dcache.srm.util.Tools) GetRequest(org.dcache.srm.request.GetRequest) URI(java.net.URI) SrmPrepareToGetResponse(org.dcache.srm.v2_2.SrmPrepareToGetResponse) SRM(org.dcache.srm.SRM) JDC(org.dcache.srm.util.JDC) Logger(org.slf4j.Logger) TTransferParameters(org.dcache.srm.v2_2.TTransferParameters) Configuration(org.dcache.srm.util.Configuration) SRMUser(org.dcache.srm.SRMUser) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) SrmPrepareToGetRequest(org.dcache.srm.v2_2.SrmPrepareToGetRequest) SRMNotSupportedException(org.dcache.srm.SRMNotSupportedException) Optional(java.util.Optional) TStatusCode(org.dcache.srm.v2_2.TStatusCode) Iterables.any(com.google.common.collect.Iterables.any) ArrayOfTExtraInfo(org.dcache.srm.v2_2.ArrayOfTExtraInfo) TExtraInfo(org.dcache.srm.v2_2.TExtraInfo) ArrayOfTExtraInfo(org.dcache.srm.v2_2.ArrayOfTExtraInfo) SRMInvalidRequestException(org.dcache.srm.SRMInvalidRequestException)

Example 5 with SRMInvalidRequestException

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

the class SrmPrepareToPut method getProtocols.

private String[] getProtocols() throws SRMInvalidRequestException {
    String[] protocols = null;
    TTransferParameters transferParameters = request.getTransferParameters();
    if (transferParameters != null && transferParameters.getArrayOfTransferProtocols() != null) {
        protocols = transferParameters.getArrayOfTransferProtocols().getStringArray();
    }
    protocols = Tools.trimStringArray(protocols);
    if (protocols == null || protocols.length < 1) {
        throw new SRMInvalidRequestException("request contains no transfer protocols.");
    }
    return protocols;
}
Also used : TTransferParameters(org.dcache.srm.v2_2.TTransferParameters) SRMInvalidRequestException(org.dcache.srm.SRMInvalidRequestException)

Aggregations

SRMInvalidRequestException (org.dcache.srm.SRMInvalidRequestException)32 URI (java.net.URI)13 TReturnStatus (org.dcache.srm.v2_2.TReturnStatus)13 SRMException (org.dcache.srm.SRMException)11 SRMInternalErrorException (org.dcache.srm.SRMInternalErrorException)9 JDC (org.dcache.srm.util.JDC)7 UnsignedLong (org.apache.axis.types.UnsignedLong)6 SRMAuthorizationException (org.dcache.srm.SRMAuthorizationException)5 SRMInvalidPathException (org.dcache.srm.SRMInvalidPathException)5 AbstractStorageElement (org.dcache.srm.AbstractStorageElement)4 SRMNotSupportedException (org.dcache.srm.SRMNotSupportedException)4 FileMetaData (org.dcache.srm.FileMetaData)3 SRMUser (org.dcache.srm.SRMUser)3 IllegalStateTransition (org.dcache.srm.scheduler.IllegalStateTransition)3 State (org.dcache.srm.scheduler.State)3 TAccessLatency (org.dcache.srm.v2_2.TAccessLatency)3 TRetentionPolicy (org.dcache.srm.v2_2.TRetentionPolicy)3 URI (org.apache.axis.types.URI)2 SRMAbortedException (org.dcache.srm.SRMAbortedException)2 SRMRequestTimedOutException (org.dcache.srm.SRMRequestTimedOutException)2