Search in sources :

Example 1 with ContainerRequest

use of org.dcache.srm.request.ContainerRequest in project dcache by dCache.

the class SrmReleaseFiles method srmReleaseFiles.

private SrmReleaseFilesResponse srmReleaseFiles() throws DataAccessException, SRMInvalidRequestException, SRMInternalErrorException {
    ArrayOfAnyURI arrayOfSURLs = srmReleaseFilesRequest.getArrayOfSURLs();
    org.apache.axis.types.URI[] surls;
    if (arrayOfSURLs != null) {
        surls = arrayOfSURLs.getUrlArray();
    } else {
        surls = null;
    }
    if (surls != null && surls.length == 0) {
        throw new SRMInvalidRequestException("Request contains no SURL");
    }
    String requestToken = srmReleaseFilesRequest.getRequestToken();
    if (requestToken == null) {
        if (surls == null) {
            throw new SRMInvalidRequestException("Request contains no SURL");
        }
        return releaseBySURLs(surls);
    }
    ContainerRequest<?> requestToRelease;
    try {
        requestToRelease = Request.getRequest(requestToken, ContainerRequest.class);
    } catch (SRMInvalidRequestException e) {
        return unpinBySURLAndRequestToken(requestToken, surls);
    }
    try (JDC ignored = requestToRelease.applyJdc()) {
        TSURLReturnStatus[] surlReturnStatuses;
        if (requestToRelease instanceof GetRequest) {
            GetRequest getRequest = (GetRequest) requestToRelease;
            if (surls == null) {
                surlReturnStatuses = getRequest.release();
            } else {
                surlReturnStatuses = getRequest.releaseFiles(surls);
            }
            getRequest.updateStatus();
        } else if (requestToRelease instanceof BringOnlineRequest) {
            BringOnlineRequest bringOnlineRequest = (BringOnlineRequest) requestToRelease;
            if (surls == null) {
                surlReturnStatuses = bringOnlineRequest.release();
            } else {
                surlReturnStatuses = bringOnlineRequest.releaseFiles(surls);
            }
            bringOnlineRequest.updateStatus();
        } else {
            throw new SRMInvalidRequestException("No such get or bring online request: " + requestToken);
        }
        return new SrmReleaseFilesResponse(getSummaryReturnStatus(surlReturnStatuses), new ArrayOfTSURLReturnStatus(surlReturnStatuses));
    }
}
Also used : JDC(org.dcache.srm.util.JDC) ArrayOfAnyURI(org.dcache.srm.v2_2.ArrayOfAnyURI) URI(java.net.URI) SrmReleaseFilesResponse(org.dcache.srm.v2_2.SrmReleaseFilesResponse) GetRequest(org.dcache.srm.request.GetRequest) BringOnlineRequest(org.dcache.srm.request.BringOnlineRequest) ContainerRequest(org.dcache.srm.request.ContainerRequest) ArrayOfTSURLReturnStatus(org.dcache.srm.v2_2.ArrayOfTSURLReturnStatus) TSURLReturnStatus(org.dcache.srm.v2_2.TSURLReturnStatus) ArrayOfTSURLReturnStatus(org.dcache.srm.v2_2.ArrayOfTSURLReturnStatus) SRMInvalidRequestException(org.dcache.srm.SRMInvalidRequestException) ArrayOfAnyURI(org.dcache.srm.v2_2.ArrayOfAnyURI)

Example 2 with ContainerRequest

use of org.dcache.srm.request.ContainerRequest in project dcache by dCache.

the class SRM method cancelRequest.

public void cancelRequest(StringBuilder sb, long requestId) throws SRMInvalidRequestException {
    Job job = Job.getJob(requestId, Job.class);
    if (job == null || !(job instanceof ContainerRequest)) {
        sb.append("request with id ").append(requestId).append(" is not found\n");
        return;
    }
    ContainerRequest<?> r = (ContainerRequest<?>) job;
    try {
        r.setState(State.CANCELED, "Canceled by admin through cancel command.");
        sb.append("state changed, no guarantee that the process will end immediately\n");
        sb.append(r.toString(false)).append('\n');
    } catch (IllegalStateTransition ist) {
        sb.append("Illegal State Transition : ").append(ist.getMessage());
        LOGGER.error("Illegal State Transition : {}", ist.getMessage());
    }
}
Also used : IllegalStateTransition(org.dcache.srm.scheduler.IllegalStateTransition) ContainerRequest(org.dcache.srm.request.ContainerRequest) Job(org.dcache.srm.request.Job)

Aggregations

ContainerRequest (org.dcache.srm.request.ContainerRequest)2 URI (java.net.URI)1 SRMInvalidRequestException (org.dcache.srm.SRMInvalidRequestException)1 BringOnlineRequest (org.dcache.srm.request.BringOnlineRequest)1 GetRequest (org.dcache.srm.request.GetRequest)1 Job (org.dcache.srm.request.Job)1 IllegalStateTransition (org.dcache.srm.scheduler.IllegalStateTransition)1 JDC (org.dcache.srm.util.JDC)1 ArrayOfAnyURI (org.dcache.srm.v2_2.ArrayOfAnyURI)1 ArrayOfTSURLReturnStatus (org.dcache.srm.v2_2.ArrayOfTSURLReturnStatus)1 SrmReleaseFilesResponse (org.dcache.srm.v2_2.SrmReleaseFilesResponse)1 TSURLReturnStatus (org.dcache.srm.v2_2.TSURLReturnStatus)1