Search in sources :

Example 1 with SRMUser

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

the class PutFileRequest method run.

@Override
public void run() throws IllegalStateTransition, SRMException {
    LOGGER.trace("run");
    if (!getState().isFinal()) {
        if (getFileId() == null) {
            // SRM_DUPLICATION_ERROR must be returned at the file level.
            if (SRM.getSRM().hasMultipleUploads(getSurl())) {
                if (!getContainerRequest().isOverwrite()) {
                    throw new SRMDuplicationException("The requested SURL is locked by another upload.");
                } else {
                    throw new SRMFileBusyException("The requested SURL is locked by another upload.");
                }
            }
            addHistoryEvent("Doing name space lookup.");
            SRMUser user = getUser();
            CheckedFuture<String, ? extends SRMException> future = getStorage().prepareToPut(user, getSurl(), getSize(), Objects.toString(getAccessLatency(), null), Objects.toString(getRetentionPolicy(), null), getSpaceReservationId(), getContainerRequest().isOverwrite());
            future.addListener(new PutCallbacks(user, getId(), surl, future), MoreExecutors.directExecutor());
            return;
        }
        computeTurl();
        wlock();
        try {
            if (getState() == State.INPROGRESS) {
                setState(State.RQUEUED, "Putting on a \"Ready\" Queue.");
            }
        } finally {
            wunlock();
        }
    }
}
Also used : SRMUser(org.dcache.srm.SRMUser) SRMFileBusyException(org.dcache.srm.SRMFileBusyException) SRMDuplicationException(org.dcache.srm.SRMDuplicationException)

Example 2 with SRMUser

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

the class DatabaseRequestStorage method getJob.

@Override
protected final R getJob(Connection _con, long ID, Long NEXTJOBID, long CREATIONTIME, long LIFETIME, int STATE, String SCHEDULERID, long SCHEDULER_TIMESTAMP, int NUMOFRETR, long LASTSTATETRANSITIONTIME, ResultSet set, int next_index) throws SQLException {
    Long CREDENTIALID = set.getLong(next_index++);
    int RETRYDELTATIME = set.getInt(next_index++);
    boolean SHOULDUPDATERETRYDELTATIME = set.getBoolean(next_index++);
    String DESCRIPTION = set.getString(next_index++);
    String CLIENTHOST = set.getString(next_index++);
    String STATUSCODE = set.getString(next_index++);
    long id = set.getLong(next_index++);
    SRMUser user = set.wasNull() ? srmUserPersistenceManager.createAnonymous() : // FIXME: Using client host for this is not correct as the client may specify a different host
    srmUserPersistenceManager.find(CLIENTHOST, id);
    return getRequest(_con, ID, NEXTJOBID, CREATIONTIME, LIFETIME, STATE, user, SCHEDULERID, SCHEDULER_TIMESTAMP, NUMOFRETR, LASTSTATETRANSITIONTIME, CREDENTIALID, RETRYDELTATIME, SHOULDUPDATERETRYDELTATIME, DESCRIPTION, CLIENTHOST, STATUSCODE, set, next_index);
}
Also used : SRMUser(org.dcache.srm.SRMUser)

Example 3 with SRMUser

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

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

the class BringOnlineFileRequest method processStateChange.

@Override
protected void processStateChange(State newState, String description) {
    State oldState = getState();
    LOGGER.debug("State changed from {} to {}", oldState, getState());
    switch(newState) {
        case READY:
            try {
                getContainerRequest().resetRetryDeltaTime();
            } catch (SRMInvalidRequestException ire) {
                LOGGER.error(ire.toString());
            }
            break;
        case CANCELED:
        case FAILED:
            try {
                SRMUser user = getUser();
                String pinId = getPinId();
                String fileId = getFileId();
                AbstractStorageElement storage = getStorage();
                if (fileId != null && pinId != null) {
                    LOGGER.info("State changed to final state, unpinning fileId = {} pinId = {}.", fileId, pinId);
                    CheckedFuture<String, ? extends SRMException> future = storage.unPinFile(null, fileId, pinId);
                    future.addListener(() -> {
                        try {
                            LOGGER.debug("File unpinned (pinId={}).", future.checkedGet());
                        } catch (SRMException e) {
                            LOGGER.error("Unpinning failed: {}", e.getMessage());
                        }
                    }, MoreExecutors.directExecutor());
                } else {
                    unpinBySURLandRequestToken(storage, user, String.valueOf(getRequestId()), getSurl());
                }
            } catch (SRMInternalErrorException | SRMInvalidRequestException ire) {
                LOGGER.error(ire.toString());
            }
            break;
    }
    super.processStateChange(newState, description);
}
Also used : SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) SRMUser(org.dcache.srm.SRMUser) SRMException(org.dcache.srm.SRMException) AbstractStorageElement(org.dcache.srm.AbstractStorageElement) State(org.dcache.srm.scheduler.State) SRMInvalidRequestException(org.dcache.srm.SRMInvalidRequestException)

Example 5 with SRMUser

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

the class BringOnlineRequest method release.

public TSURLReturnStatus[] release() throws SRMInternalErrorException {
    SRMUser user = getUser();
    int len = getNumOfFileRequest();
    TSURLReturnStatus[] surlReturnStatuses = new TSURLReturnStatus[len];
    LOGGER.debug("releaseFiles, releasing all {} files", len);
    List<BringOnlineFileRequest> requests = getFileRequests();
    for (int i = 0; i < len; i++) {
        BringOnlineFileRequest request = requests.get(i);
        org.apache.axis.types.URI surl;
        try {
            surl = new org.apache.axis.types.URI(request.getSurlString());
        } catch (org.apache.axis.types.URI.MalformedURIException e) {
            throw new RuntimeException("Failed to convert Java URI to Axis URI. " + "Please report this to support@dcache.org: " + e.getMessage(), e);
        }
        surlReturnStatuses[i] = new TSURLReturnStatus(surl, request.release(user));
    }
    return surlReturnStatuses;
}
Also used : SRMUser(org.dcache.srm.SRMUser) URI(java.net.URI) TSURLReturnStatus(org.dcache.srm.v2_2.TSURLReturnStatus)

Aggregations

SRMUser (org.dcache.srm.SRMUser)10 URI (java.net.URI)3 AbstractStorageElement (org.dcache.srm.AbstractStorageElement)3 SRMInternalErrorException (org.dcache.srm.SRMInternalErrorException)3 TSURLReturnStatus (org.dcache.srm.v2_2.TSURLReturnStatus)3 SRMException (org.dcache.srm.SRMException)2 SRMFileRequestNotFoundException (org.dcache.srm.SRMFileRequestNotFoundException)2 SRMInvalidRequestException (org.dcache.srm.SRMInvalidRequestException)2 State (org.dcache.srm.scheduler.State)2 TReturnStatus (org.dcache.srm.v2_2.TReturnStatus)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 KeyStoreException (java.security.KeyStoreException)1 CertPath (java.security.cert.CertPath)1 CertificateEncodingException (java.security.cert.CertificateEncodingException)1 LoginReply (org.dcache.auth.LoginReply)1 SRM (org.dcache.srm.SRM)1 SRMDuplicationException (org.dcache.srm.SRMDuplicationException)1 SRMFileBusyException (org.dcache.srm.SRMFileBusyException)1 SRMNotSupportedException (org.dcache.srm.SRMNotSupportedException)1