Search in sources :

Example 1 with SRMNotSupportedException

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

the class SrmService method messageArrived.

public SrmResponse messageArrived(SrmRequest request) throws SRMException {
    try {
        CertPath certPath = getFirst(request.getSubject().getPublicCredentials(CertPath.class), null);
        LoginReply login = new LoginReply(request.getSubject(), request.getLoginAttributes());
        SRMUser user = userManager.persist(certPath, login);
        String requestName = request.getRequestName();
        Class<?> requestClass = request.getRequest().getClass();
        String capitalizedRequestName = Character.toUpperCase(requestName.charAt(0)) + requestName.substring(1);
        LOGGER.debug("About to call {} handler", requestName);
        Constructor<?> handlerConstructor;
        Object handler;
        Method handleGetResponseMethod;
        try {
            Class<?> handlerClass = Class.forName("org.dcache.srm.handler." + capitalizedRequestName);
            handlerConstructor = handlerClass.getConstructor(SRMUser.class, requestClass, AbstractStorageElement.class, SRM.class, String.class);
            handler = handlerConstructor.newInstance(user, request.getRequest(), storage, srm, request.getRemoteHost());
            if (handler instanceof CredentialAwareHandler) {
                CredentialAwareHandler credentialAware = (CredentialAwareHandler) handler;
                RequestCredential requestCredential = saveRequestCredential(request.getSubject(), request.getCredential());
                credentialAware.setCredential(requestCredential);
            }
            handleGetResponseMethod = handlerClass.getMethod("getResponse");
        } catch (ClassNotFoundException e) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.info("handler discovery and dynamic loading failed", e);
            } else {
                LOGGER.info("handler discovery and dynamic loading failed");
            }
            throw new SRMNotSupportedException(requestName + " is unsupported");
        }
        Object result = handleGetResponseMethod.invoke(handler);
        return new SrmResponse(id, result);
    } catch (CertificateEncodingException | KeyStoreException e) {
        throw new SRMInternalErrorException("Failed to process certificate chain.", e);
    } catch (InvocationTargetException | NoSuchMethodException | InstantiationException | IllegalAccessException | RuntimeException e) {
        LOGGER.error("Please report this failure to support@dcache.org", e);
        throw new SRMInternalErrorException("Internal error (server log contains additional information)");
    }
}
Also used : SRMUser(org.dcache.srm.SRMUser) SRMNotSupportedException(org.dcache.srm.SRMNotSupportedException) RequestCredential(org.dcache.srm.request.RequestCredential) LoginReply(org.dcache.auth.LoginReply) SRM(org.dcache.srm.SRM) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) CertPath(java.security.cert.CertPath) SrmResponse(org.dcache.srm.SrmResponse) AbstractStorageElement(org.dcache.srm.AbstractStorageElement) CredentialAwareHandler(org.dcache.srm.handler.CredentialAwareHandler) CertificateEncodingException(java.security.cert.CertificateEncodingException) Method(java.lang.reflect.Method) KeyStoreException(java.security.KeyStoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with SRMNotSupportedException

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

the class SrmShell method cd.

@SuppressWarnings("fallthrough")
private void cd(String path) throws URI.MalformedURIException, RemoteException, SRMException, InterruptedException {
    if (!path.endsWith("/")) {
        path = path + "/";
    }
    URI uri = new URI(pwd, path);
    checkValidPath(fs.stat(uri).getType() == TFileType.DIRECTORY, "Not a directory");
    switch(checkCdPermission) {
        case SRM_CHECK_PERMISSION:
            try {
                TPermissionMode permission = fs.checkPermission(uri);
                if (permission != TPermissionMode.RWX && permission != TPermissionMode.RX && permission != TPermissionMode.WX && permission != TPermissionMode.X) {
                    throw new SRMAuthorizationException("Access denied");
                }
                break;
            } catch (SRMNotSupportedException e) {
                /* StoRM does not support checkPermission:
                     *
                     *     https://ggus.eu/index.php?mode=ticket_info&ticket_id=124634
                     */
                notifications.add("The CheckPermission operation is not supported, using directory listing instead.");
                checkCdPermission = PermissionOperation.SRM_LS;
            // fall-through: use srmLs
            }
        case SRM_LS:
            fs.list(uri, false);
    }
    pwd = uri;
}
Also used : SRMAuthorizationException(org.dcache.srm.SRMAuthorizationException) SRMNotSupportedException(org.dcache.srm.SRMNotSupportedException) TPermissionMode(org.dcache.srm.v2_2.TPermissionMode) URI(org.apache.axis.types.URI)

Example 3 with SRMNotSupportedException

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

the class Storage method srmGetSpaceMetaData.

/**
 * @param spaceTokens
 * @return
 * @throws SRMException
 */
@Override
public TMetaDataSpace[] srmGetSpaceMetaData(SRMUser user, String[] spaceTokens) throws SRMException {
    guardSpaceManagerEnabled();
    GetSpaceMetaData getSpaces = new GetSpaceMetaData(spaceTokens);
    try {
        getSpaces = _spaceManagerStub.sendAndWait(getSpaces);
    } catch (TimeoutCacheException e) {
        throw new SRMInternalErrorException("Space manager timeout", e);
    } catch (NoRouteToCellException e) {
        throw new SRMNotSupportedException("Space manager is unavailable", e);
    } catch (InterruptedException e) {
        throw new SRMInternalErrorException("Operation interrupted", e);
    } catch (CacheException e) {
        _log.warn("GetSpaceMetaData failed with rc={} error={}", e.getRc(), e.getMessage());
        throw new SRMException("Space manager failure: " + e.getMessage(), e);
    }
    Space[] spaces = getSpaces.getSpaces();
    TMetaDataSpace[] spaceMetaDatas = new TMetaDataSpace[spaces.length];
    for (int i = 0; i < spaceMetaDatas.length; ++i) {
        Space space = spaces[i];
        TMetaDataSpace metaDataSpace = new TMetaDataSpace();
        TReturnStatus status;
        if (space != null) {
            Long expirationTime = space.getExpirationTime();
            if (expirationTime == null) {
                metaDataSpace.setLifetimeAssigned(-1);
                metaDataSpace.setLifetimeLeft(-1);
            } else {
                long lifetimeleft = Math.max(0, MILLISECONDS.toSeconds(expirationTime - System.currentTimeMillis()));
                metaDataSpace.setLifetimeAssigned((int) MILLISECONDS.toSeconds(expirationTime - space.getCreationTime()));
                metaDataSpace.setLifetimeLeft((int) lifetimeleft);
            }
            RetentionPolicy retentionPolicy = space.getRetentionPolicy();
            TRetentionPolicy policy = retentionPolicy.equals(RetentionPolicy.CUSTODIAL) ? TRetentionPolicy.CUSTODIAL : retentionPolicy.equals(RetentionPolicy.OUTPUT) ? TRetentionPolicy.OUTPUT : TRetentionPolicy.REPLICA;
            AccessLatency accessLatency = space.getAccessLatency();
            TAccessLatency latency = accessLatency.equals(AccessLatency.ONLINE) ? TAccessLatency.ONLINE : TAccessLatency.NEARLINE;
            UnsignedLong totalSize = new UnsignedLong(space.getSizeInBytes());
            UnsignedLong unusedSize = new UnsignedLong(space.getSizeInBytes() - space.getUsedSizeInBytes());
            metaDataSpace.setRetentionPolicyInfo(new TRetentionPolicyInfo(policy, latency));
            metaDataSpace.setTotalSize(totalSize);
            metaDataSpace.setGuaranteedSize(totalSize);
            metaDataSpace.setUnusedSize(unusedSize);
            SpaceState spaceState = space.getState();
            switch(spaceState) {
                case RESERVED:
                    status = new TReturnStatus(TStatusCode.SRM_SUCCESS, null);
                    break;
                case EXPIRED:
                    status = new TReturnStatus(TStatusCode.SRM_SPACE_LIFETIME_EXPIRED, "The lifetime on the space that is associated with the spaceToken has expired already");
                    break;
                default:
                    status = new TReturnStatus(TStatusCode.SRM_FAILURE, "Space has been released");
                    break;
            }
            metaDataSpace.setOwner("VoGroup=" + space.getVoGroup() + " VoRole=" + space.getVoRole());
        } else {
            status = new TReturnStatus(TStatusCode.SRM_INVALID_REQUEST, "No such space");
        }
        metaDataSpace.setStatus(status);
        metaDataSpace.setSpaceToken(spaceTokens[i]);
        spaceMetaDatas[i] = metaDataSpace;
    }
    return spaceMetaDatas;
}
Also used : GetSpaceMetaData(diskCacheV111.services.space.message.GetSpaceMetaData) Space(diskCacheV111.services.space.Space) TMetaDataSpace(org.dcache.srm.v2_2.TMetaDataSpace) SRMNotSupportedException(org.dcache.srm.SRMNotSupportedException) TAccessLatency(org.dcache.srm.v2_2.TAccessLatency) AccessLatency(diskCacheV111.util.AccessLatency) UnsignedLong(org.apache.axis.types.UnsignedLong) 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) TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) TRetentionPolicy(org.dcache.srm.v2_2.TRetentionPolicy) RetentionPolicy(diskCacheV111.util.RetentionPolicy) TRetentionPolicy(org.dcache.srm.v2_2.TRetentionPolicy) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) SRMException(org.dcache.srm.SRMException) TRetentionPolicyInfo(org.dcache.srm.v2_2.TRetentionPolicyInfo) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) SpaceState(diskCacheV111.services.space.SpaceState) UnsignedLong(org.apache.axis.types.UnsignedLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) TAccessLatency(org.dcache.srm.v2_2.TAccessLatency) TMetaDataSpace(org.dcache.srm.v2_2.TMetaDataSpace) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException)

Example 4 with SRMNotSupportedException

use of org.dcache.srm.SRMNotSupportedException 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 5 with SRMNotSupportedException

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

the class SrmPrepareToGet method srmPrepareToGet.

private SrmPrepareToGetResponse srmPrepareToGet() throws IllegalStateTransition, InterruptedException, SRMInvalidRequestException, SRMNotSupportedException, SRMInternalErrorException {
    String[] protocols = getTransferProtocols(request);
    String clientHost = getClientHost(request).orElse(this.clientHost);
    long lifetime = Lifetimes.calculateLifetime(request.getDesiredTotalRequestTime(), configuration.getGetLifetime());
    String[] supportedProtocols = storage.supportedGetProtocols();
    URI[] surls = getSurls(request);
    if (protocols != null && protocols.length > 0) {
        boolean isAnyProtocolSupported = any(asList(protocols), in(asList(supportedProtocols)));
        if (!isAnyProtocolSupported) {
            throw new SRMNotSupportedException("Protocol(s) not supported: " + Arrays.toString(protocols));
        }
    }
    GetRequest r = new GetRequest(srm.getSrmId(), user, surls, protocols, lifetime, configuration.getGetMaxPollPeriod(), request.getUserRequestDescription(), clientHost, isStagingAllowed());
    try (JDC ignored = r.applyJdc()) {
        srm.acceptNewJob(r);
        return r.getSrmPrepareToGetResponse(configuration.getGetSwitchToAsynchronousModeDelay());
    }
}
Also used : SRMNotSupportedException(org.dcache.srm.SRMNotSupportedException) GetRequest(org.dcache.srm.request.GetRequest) SrmPrepareToGetRequest(org.dcache.srm.v2_2.SrmPrepareToGetRequest) JDC(org.dcache.srm.util.JDC) URI(java.net.URI)

Aggregations

SRMNotSupportedException (org.dcache.srm.SRMNotSupportedException)10 SRMInternalErrorException (org.dcache.srm.SRMInternalErrorException)6 SRMAuthorizationException (org.dcache.srm.SRMAuthorizationException)4 SRMException (org.dcache.srm.SRMException)4 SRMInvalidRequestException (org.dcache.srm.SRMInvalidRequestException)4 Space (diskCacheV111.services.space.Space)3 AccessLatency (diskCacheV111.util.AccessLatency)3 URI (java.net.URI)3 JDC (org.dcache.srm.util.JDC)3 TAccessLatency (org.dcache.srm.v2_2.TAccessLatency)3 TRetentionPolicy (org.dcache.srm.v2_2.TRetentionPolicy)3 SpaceState (diskCacheV111.services.space.SpaceState)2 GetSpaceMetaData (diskCacheV111.services.space.message.GetSpaceMetaData)2 RetentionPolicy (diskCacheV111.util.RetentionPolicy)2 UnsignedLong (org.apache.axis.types.UnsignedLong)2 SRMAbortedException (org.dcache.srm.SRMAbortedException)2 SRMDuplicationException (org.dcache.srm.SRMDuplicationException)2 SRMExceedAllocationException (org.dcache.srm.SRMExceedAllocationException)2 SRMInvalidPathException (org.dcache.srm.SRMInvalidPathException)2 SRMNonEmptyDirectoryException (org.dcache.srm.SRMNonEmptyDirectoryException)2