Search in sources :

Example 1 with AbstractStorageElement

use of org.dcache.srm.AbstractStorageElement 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 2 with AbstractStorageElement

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

the class GetFileRequest method processStateChange.

@Override
protected void processStateChange(State newState, String description) {
    State oldState = getState();
    LOGGER.debug("State changed from {} to {}", oldState, newState);
    switch(newState) {
        case READY:
            try {
                getContainerRequest().resetRetryDeltaTime();
            } catch (SRMInvalidRequestException ire) {
                LOGGER.error(ire.toString());
            }
            break;
        case DONE:
        case FAILED:
        case CANCELED:
            AbstractStorageElement storage = getStorage();
            try {
                SRMUser user = getUser();
                String fileId = getFileId();
                String pinId = getPinId();
                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("Unpinned (pinId={}).", future.checkedGet());
                        } catch (SRMException e) {
                            LOGGER.error("Unpinning failed: {}", e.getMessage());
                        }
                    }, MoreExecutors.directExecutor());
                } else {
                    BringOnlineFileRequest.unpinBySURLandRequestToken(storage, user, String.valueOf(getRequestId()), getSurl());
                }
            } catch (SRMInternalErrorException | SRMInvalidRequestException e) {
                LOGGER.error(e.toString());
            }
    }
    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 3 with AbstractStorageElement

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

the class CopyRequest method identify.

private void identify() throws IOException, SRMException {
    wlock();
    try {
        URI source = getFileRequests().get(0).getSourceSurl();
        String sourceProtocol = source.getScheme();
        String sourceHost = source.getHost();
        int sourcePort = source.getPort();
        URI destination = getFileRequests().get(0).getDestinationSurl();
        String destinationProtocol = destination.getScheme();
        String destinationHost = destination.getHost();
        int destinationPort = destination.getPort();
        for (CopyFileRequest cfr : getFileRequests().subList(1, getNumOfFileRequest())) {
            URI sourceSurl = cfr.getSourceSurl();
            URI destinationSurl = cfr.getDestinationSurl();
            if (!sourceSurl.getScheme().equals(sourceProtocol) || !sourceSurl.getHost().equals(sourceHost) || sourceSurl.getPort() != sourcePort) {
                String err = "Source URL " + sourceSurl + " is inconsistent with first source URL";
                LOGGER.error(err);
                throw new IOException(err);
            }
            if (!destinationSurl.getScheme().equals(destinationProtocol) || !destinationSurl.getHost().equals(destinationHost) || destinationSurl.getPort() != destinationPort) {
                String err = "Destination URL " + destinationSurl + " is inconsistent with first destination URL";
                LOGGER.error(err);
                throw new IOException(err);
            }
        }
        isSourceSrm = sourceProtocol.equals("srm");
        isDestinationSrm = destinationProtocol.equals("srm");
        AbstractStorageElement storage = SRM.getSRM().getStorage();
        isSourceLocal = storage.isLocalSurl(source);
        isDestinationLocal = storage.isLocalSurl(destination);
        LOGGER.debug("src (srm={}, local={}), dest (srm={}, local={})", isSourceSrm, isSourceLocal, isDestinationSrm, isDestinationLocal);
        if (!isSourceLocal && !isDestinationLocal) {
            LOGGER.error("Both source ({}) and destination ({}) URLs are remote.", source, destination);
            throw new SRMInvalidRequestException("Both source and destination URLs are remote.");
        }
    } finally {
        wunlock();
    }
}
Also used : AbstractStorageElement(org.dcache.srm.AbstractStorageElement) IOException(java.io.IOException) URI(java.net.URI) SRMInvalidRequestException(org.dcache.srm.SRMInvalidRequestException)

Aggregations

AbstractStorageElement (org.dcache.srm.AbstractStorageElement)3 SRMInvalidRequestException (org.dcache.srm.SRMInvalidRequestException)3 SRMException (org.dcache.srm.SRMException)2 SRMInternalErrorException (org.dcache.srm.SRMInternalErrorException)2 SRMUser (org.dcache.srm.SRMUser)2 State (org.dcache.srm.scheduler.State)2 IOException (java.io.IOException)1 URI (java.net.URI)1