Search in sources :

Example 1 with SrmStatusOfLsRequestResponse

use of org.dcache.srm.v2_2.SrmStatusOfLsRequestResponse in project dcache by dCache.

the class SRMLsClientV2 method start.

@Override
public void start() throws Exception {
    checkCredentialValid();
    try {
        SrmLsRequest req = new SrmLsRequest();
        req.setAllLevelRecursive(Boolean.FALSE);
        req.setFullDetailedList(configuration.isLongLsFormat());
        req.setNumOfLevels(configuration.getRecursionDepth());
        req.setOffset(configuration.getLsOffset());
        if (configuration.getLsCount() != null) {
            req.setCount(configuration.getLsCount());
        }
        URI[] turlia = new URI[surls.length];
        for (int i = 0; i < surls.length; ++i) {
            turlia[i] = new URI(surl_strings[i]);
        }
        req.setArrayOfSURLs(new ArrayOfAnyURI(turlia));
        hook = new Thread(this);
        Runtime.getRuntime().addShutdownHook(hook);
        configuration.getStorageSystemInfo().ifPresent(req::setStorageSystemInfo);
        SrmLsResponse response = srm.srmLs(req);
        if (response == null) {
            throw new Exception("srm ls response is null!");
        }
        TReturnStatus rs = response.getReturnStatus();
        requestToken = response.getRequestToken();
        if (rs == null) {
            throw new IOException(" null TReturnStatus ");
        }
        StringBuffer sb = new StringBuffer();
        String statusText = "Return status:\n" + " - Status code:  " + response.getReturnStatus().getStatusCode().getValue() + '\n' + " - Explanation:  " + response.getReturnStatus().getExplanation();
        logger.log(statusText);
        if (RequestStatusTool.isFailedRequestStatus(rs)) {
            sb.append(statusText).append('\n');
        }
        if (!RequestStatusTool.isTransientStateStatus(rs)) {
            if (response.getDetails() == null) {
                throw new IOException(sb.toString() + "srm ls response path details array is null!");
            } else {
                if (response.getDetails().getPathDetailArray() != null) {
                    TMetaDataPathDetail[] details = response.getDetails().getPathDetailArray();
                    printResults(sb, details, 0, " ", configuration.isLongLsFormat());
                }
            }
            if (RequestStatusTool.isFailedRequestStatus(rs)) {
                throw new IOException(sb.toString());
            }
            System.out.println(sb.toString());
        } else {
            if (requestToken == null) {
                throw new IOException("Request is queued on the server, however the server did not provide a request token.");
            }
            if (RequestStatusTool.isFailedRequestStatus(rs)) {
                throw new IOException(sb.toString());
            }
            // we assume this is asynchronous call
            SrmStatusOfLsRequestRequest statusRequest = new SrmStatusOfLsRequestRequest();
            statusRequest.setRequestToken(requestToken);
            statusRequest.setOffset(req.getOffset());
            statusRequest.setCount(req.getCount());
            statusRequest.setAuthorizationID(req.getAuthorizationID());
            long estimatedWaitInSeconds = 2;
            while (true) {
                if (estimatedWaitInSeconds > 60) {
                    estimatedWaitInSeconds = 60;
                }
                try {
                    say("sleeping " + estimatedWaitInSeconds + " seconds ...");
                    Thread.sleep(estimatedWaitInSeconds * 1000);
                } catch (InterruptedException ie) {
                    esay("Interrupted, quitting");
                    if (requestToken != null) {
                        abortRequest();
                    }
                    System.exit(1);
                }
                estimatedWaitInSeconds *= 2;
                SrmStatusOfLsRequestResponse statusResponse = srm.srmStatusOfLsRequest(statusRequest);
                if (statusResponse == null) {
                    throw new IOException("SrmStatusOfLsRequestResponse is null for request " + requestToken);
                }
                TReturnStatus status = statusResponse.getReturnStatus();
                if (status == null) {
                    throw new IOException(" null return status");
                }
                if (status.getStatusCode() == null) {
                    throw new IOException(" null status code");
                }
                if (!RequestStatusTool.isTransientStateStatus(status)) {
                    statusText = "Return status:\n" + " - Status code:  " + status.getStatusCode().getValue() + '\n' + " - Explanation:  " + status.getExplanation() + '\n' + " - request token: " + requestToken;
                    logger.log(statusText);
                    if (RequestStatusTool.isFailedRequestStatus(status)) {
                        sb.append(statusText).append('\n');
                    }
                    if (statusResponse.getDetails() == null) {
                        throw new IOException(sb.toString() + "srm ls response path details array is null!");
                    } else {
                        if (statusResponse.getDetails().getPathDetailArray() != null) {
                            TMetaDataPathDetail[] details = statusResponse.getDetails().getPathDetailArray();
                            printResults(sb, details, 0, " ", configuration.isLongLsFormat());
                            if (RequestStatusTool.isFailedRequestStatus(status)) {
                                throw new IOException(sb.toString());
                            }
                            System.out.println(sb.toString());
                        }
                    }
                    break;
                }
            }
        }
    } catch (Exception e) {
        esay(e.getMessage());
        try {
            if (requestToken != null) {
                abortRequest();
            }
        } catch (Exception e1) {
            logger.elog(e1.toString());
        } finally {
            Runtime.getRuntime().removeShutdownHook(hook);
            System.exit(1);
        }
    } finally {
        Runtime.getRuntime().removeShutdownHook(hook);
    }
}
Also used : SrmLsResponse(org.dcache.srm.v2_2.SrmLsResponse) TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) SrmStatusOfLsRequestRequest(org.dcache.srm.v2_2.SrmStatusOfLsRequestRequest) TMetaDataPathDetail(org.dcache.srm.v2_2.TMetaDataPathDetail) IOException(java.io.IOException) ArrayOfAnyURI(org.dcache.srm.v2_2.ArrayOfAnyURI) URI(org.apache.axis.types.URI) IOException(java.io.IOException) SrmLsRequest(org.dcache.srm.v2_2.SrmLsRequest) SrmStatusOfLsRequestResponse(org.dcache.srm.v2_2.SrmStatusOfLsRequestResponse) ArrayOfAnyURI(org.dcache.srm.v2_2.ArrayOfAnyURI)

Example 2 with SrmStatusOfLsRequestResponse

use of org.dcache.srm.v2_2.SrmStatusOfLsRequestResponse in project dcache by dCache.

the class SrmStatusOfLsRequest method getFailedResponse.

public static final SrmStatusOfLsRequestResponse getFailedResponse(String error, TStatusCode statusCode) {
    SrmStatusOfLsRequestResponse srmStatusOfLsRequestResponse = new SrmStatusOfLsRequestResponse();
    srmStatusOfLsRequestResponse.setReturnStatus(new TReturnStatus(statusCode, error));
    return srmStatusOfLsRequestResponse;
}
Also used : TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) SrmStatusOfLsRequestResponse(org.dcache.srm.v2_2.SrmStatusOfLsRequestResponse)

Example 3 with SrmStatusOfLsRequestResponse

use of org.dcache.srm.v2_2.SrmStatusOfLsRequestResponse in project dcache by dCache.

the class AxisSrmFileSystem method doBulkStat.

private TMetaDataPathDetail[] doBulkStat(URI[] surls) throws RemoteException, SRMException, InterruptedException {
    SrmLsResponse response = srm.srmLs(new SrmLsRequest(null, new ArrayOfAnyURI(surls), null, null, true, false, 0, 0, surls.length));
    ArrayOfTMetaDataPathDetail details;
    if (response.getReturnStatus().getStatusCode() != TStatusCode.SRM_REQUEST_QUEUED && response.getReturnStatus().getStatusCode() != TStatusCode.SRM_REQUEST_INPROGRESS) {
        checkSuccess(response.getReturnStatus(), TStatusCode.SRM_SUCCESS, TStatusCode.SRM_PARTIAL_SUCCESS, TStatusCode.SRM_FAILURE);
        details = response.getDetails();
    } else {
        SrmStatusOfLsRequestResponse status;
        do {
            TimeUnit.SECONDS.sleep(1);
            status = srm.srmStatusOfLsRequest(new SrmStatusOfLsRequestRequest(null, response.getRequestToken(), 0, surls.length));
        } while (status.getReturnStatus().getStatusCode() == TStatusCode.SRM_REQUEST_QUEUED || status.getReturnStatus().getStatusCode() == TStatusCode.SRM_REQUEST_INPROGRESS);
        checkSuccess(status.getReturnStatus(), TStatusCode.SRM_SUCCESS, TStatusCode.SRM_PARTIAL_SUCCESS, TStatusCode.SRM_FAILURE);
        details = status.getDetails();
    }
    return details.getPathDetailArray();
}
Also used : SrmLsResponse(org.dcache.srm.v2_2.SrmLsResponse) SrmStatusOfLsRequestRequest(org.dcache.srm.v2_2.SrmStatusOfLsRequestRequest) ArrayOfTMetaDataPathDetail(org.dcache.srm.v2_2.ArrayOfTMetaDataPathDetail) SrmStatusOfLsRequestResponse(org.dcache.srm.v2_2.SrmStatusOfLsRequestResponse) ArrayOfAnyURI(org.dcache.srm.v2_2.ArrayOfAnyURI) SrmLsRequest(org.dcache.srm.v2_2.SrmLsRequest)

Example 4 with SrmStatusOfLsRequestResponse

use of org.dcache.srm.v2_2.SrmStatusOfLsRequestResponse in project dcache by dCache.

the class AxisSrmFileSystem method list.

private TMetaDataPathDetail list(URI surl, boolean verbose, int offset, int count) throws RemoteException, SRMException, InterruptedException {
    SrmLsResponse response = srm.srmLs(new SrmLsRequest(null, new ArrayOfAnyURI(new URI[] { surl }), null, null, verbose, false, 1, offset, count));
    while (response.getReturnStatus().getStatusCode() == TStatusCode.SRM_REQUEST_QUEUED || response.getReturnStatus().getStatusCode() == TStatusCode.SRM_REQUEST_INPROGRESS) {
        TimeUnit.SECONDS.sleep(1);
        SrmStatusOfLsRequestResponse status = srm.srmStatusOfLsRequest(new SrmStatusOfLsRequestRequest(null, response.getRequestToken(), offset, count));
        response.setDetails(status.getDetails());
        response.setReturnStatus(status.getReturnStatus());
    }
    checkSuccess(response.getReturnStatus());
    TMetaDataPathDetail details = response.getDetails().getPathDetailArray()[0];
    checkBulkSuccess(response.getReturnStatus(), Collections.singletonList(details.getStatus()));
    return details;
}
Also used : SrmLsResponse(org.dcache.srm.v2_2.SrmLsResponse) SrmStatusOfLsRequestRequest(org.dcache.srm.v2_2.SrmStatusOfLsRequestRequest) TMetaDataPathDetail(org.dcache.srm.v2_2.TMetaDataPathDetail) ArrayOfTMetaDataPathDetail(org.dcache.srm.v2_2.ArrayOfTMetaDataPathDetail) SrmStatusOfLsRequestResponse(org.dcache.srm.v2_2.SrmStatusOfLsRequestResponse) ArrayOfAnyURI(org.dcache.srm.v2_2.ArrayOfAnyURI) SrmLsRequest(org.dcache.srm.v2_2.SrmLsRequest)

Aggregations

SrmStatusOfLsRequestResponse (org.dcache.srm.v2_2.SrmStatusOfLsRequestResponse)4 ArrayOfAnyURI (org.dcache.srm.v2_2.ArrayOfAnyURI)3 SrmLsRequest (org.dcache.srm.v2_2.SrmLsRequest)3 SrmLsResponse (org.dcache.srm.v2_2.SrmLsResponse)3 SrmStatusOfLsRequestRequest (org.dcache.srm.v2_2.SrmStatusOfLsRequestRequest)3 ArrayOfTMetaDataPathDetail (org.dcache.srm.v2_2.ArrayOfTMetaDataPathDetail)2 TMetaDataPathDetail (org.dcache.srm.v2_2.TMetaDataPathDetail)2 TReturnStatus (org.dcache.srm.v2_2.TReturnStatus)2 IOException (java.io.IOException)1 URI (org.apache.axis.types.URI)1