Search in sources :

Example 21 with TReturnStatus

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

the class SRMCopyClientV2 method abortAllPendingFiles.

private void abortAllPendingFiles() throws Exception {
    if (pendingSurlsMap.isEmpty()) {
        return;
    }
    if (requestToken == null) {
        return;
    }
    java.net.URI[] surl_strings = pendingSurlsMap.keySet().toArray(new java.net.URI[pendingSurlsMap.size()]);
    int len = surl_strings.length;
    say("Releasing all remaining file requests");
    URI[] surlArray = new URI[len];
    for (int i = 0; i < len; ++i) {
        URI uri = new URI(surl_strings[i].toASCIIString());
        surlArray[i] = uri;
    }
    SrmAbortFilesRequest srmAbortFilesRequest = new SrmAbortFilesRequest();
    srmAbortFilesRequest.setRequestToken(requestToken);
    srmAbortFilesRequest.setArrayOfSURLs(new ArrayOfAnyURI(surlArray));
    SrmAbortFilesResponse srmAbortFilesResponse = srm.srmAbortFiles(srmAbortFilesRequest);
    if (srmAbortFilesResponse == null) {
        logger.elog(" srmAbortFilesResponse is null");
    } else {
        TReturnStatus returnStatus = srmAbortFilesResponse.getReturnStatus();
        if (returnStatus == null) {
            esay("srmAbortFiles return status is null");
            return;
        }
        say("srmAbortFiles status code=" + returnStatus.getStatusCode());
    }
}
Also used : SrmAbortFilesRequest(org.dcache.srm.v2_2.SrmAbortFilesRequest) TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) SrmAbortFilesResponse(org.dcache.srm.v2_2.SrmAbortFilesResponse) ArrayOfAnyURI(org.dcache.srm.v2_2.ArrayOfAnyURI) URI(org.apache.axis.types.URI) ArrayOfAnyURI(org.dcache.srm.v2_2.ArrayOfAnyURI)

Example 22 with TReturnStatus

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

the class SRMExtendFileLifeTimeClientV2 method start.

@Override
public void start() throws Exception {
    checkCredentialValid();
    ArrayOfAnyURI surlarray = new ArrayOfAnyURI();
    URI[] uriarray = new URI[surls.length];
    URI uri;
    for (int i = 0; i < uriarray.length; i++) {
        uri = new URI(surl_strings[i]);
        uriarray[i] = uri;
    }
    surlarray.setUrlArray(uriarray);
    SrmExtendFileLifeTimeRequest req = new SrmExtendFileLifeTimeRequest();
    req.setArrayOfSURLs(surlarray);
    req.setRequestToken(configuration.getExtendFileLifetimeRequestToken());
    req.setNewFileLifeTime(configuration.getNewFileLifetime());
    req.setNewPinLifeTime(configuration.getNewPinLifetime());
    SrmExtendFileLifeTimeResponse resp = srm.srmExtendFileLifeTime(req);
    if (resp == null) {
        esay("Received null SrmExtendFileLifeTimeResponse");
        System.exit(1);
    }
    try {
        TReturnStatus rs = resp.getReturnStatus();
        if (rs.getStatusCode() != TStatusCode.SRM_SUCCESS || configuration.isDebug()) {
            TStatusCode rc = rs.getStatusCode();
            StringBuilder sb = new StringBuilder();
            sb.append("Return code: ").append(rc.toString()).append("\n");
            sb.append("Explanation: ").append(rs.getExplanation()).append("\n");
            if (resp.getArrayOfFileStatuses() != null) {
                if (resp.getArrayOfFileStatuses().getStatusArray() != null) {
                    for (int i = 0; i < resp.getArrayOfFileStatuses().getStatusArray().length; i++) {
                        TSURLLifetimeReturnStatus t = resp.getArrayOfFileStatuses().getStatusArray()[i];
                        sb.append("surl[").append(i).append("] ").append(t.getSurl()).append("\n");
                        sb.append("\tReturn code: ").append(t.getStatus().getStatusCode().toString()).append("\n");
                        sb.append("\tExplanation: ").append(t.getStatus().getExplanation()).append("\n");
                        sb.append("\t\tfilelifetime=").append(t.getFileLifetime()).append("\n");
                        sb.append("\t\tpinlifetime=").append(t.getPinLifetime()).append("\n");
                    }
                } else {
                    sb.append("array of file statuse is null\n");
                }
            } else {
                sb.append("array of file statuse is null\n");
            }
            if (rs.getStatusCode() != TStatusCode.SRM_SUCCESS) {
                esay(sb.toString());
                System.exit(1);
            } else {
                say(sb.toString());
            }
        } else {
            System.exit(0);
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}
Also used : TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) SrmExtendFileLifeTimeRequest(org.dcache.srm.v2_2.SrmExtendFileLifeTimeRequest) TSURLLifetimeReturnStatus(org.dcache.srm.v2_2.TSURLLifetimeReturnStatus) URI(org.apache.axis.types.URI) ArrayOfAnyURI(org.dcache.srm.v2_2.ArrayOfAnyURI) ArrayOfAnyURI(org.dcache.srm.v2_2.ArrayOfAnyURI) TStatusCode(org.dcache.srm.v2_2.TStatusCode) SrmExtendFileLifeTimeResponse(org.dcache.srm.v2_2.SrmExtendFileLifeTimeResponse)

Example 23 with TReturnStatus

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

the class SRMGetClientV2 method abortAllPendingFiles.

private void abortAllPendingFiles() throws Exception {
    if (pendingSurlsToIndex.isEmpty()) {
        return;
    }
    if (requestToken != null) {
        String[] surl_strings = pendingSurlsToIndex.keySet().toArray(new String[pendingSurlsToIndex.size()]);
        int len = surl_strings.length;
        say("Releasing all remaining file requests");
        URI[] surlArray = new URI[len];
        for (int i = 0; i < len; ++i) {
            surlArray[i] = new URI(surl_strings[i]);
        }
        SrmAbortFilesRequest srmAbortFilesRequest = new SrmAbortFilesRequest();
        srmAbortFilesRequest.setRequestToken(requestToken);
        srmAbortFilesRequest.setArrayOfSURLs(new ArrayOfAnyURI(surlArray));
        SrmAbortFilesResponse srmAbortFilesResponse = srm.srmAbortFiles(srmAbortFilesRequest);
        if (srmAbortFilesResponse == null) {
            logger.elog(" srmAbortFilesResponse is null");
        } else {
            TReturnStatus returnStatus = srmAbortFilesResponse.getReturnStatus();
            if (returnStatus == null) {
                esay("srmAbortFiles return status is null");
                return;
            }
            say("srmAbortFiles status code=" + returnStatus.getStatusCode());
        }
    }
}
Also used : SrmAbortFilesRequest(org.dcache.srm.v2_2.SrmAbortFilesRequest) TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) SrmAbortFilesResponse(org.dcache.srm.v2_2.SrmAbortFilesResponse) ArrayOfString(org.dcache.srm.v2_2.ArrayOfString) ArrayOfAnyURI(org.dcache.srm.v2_2.ArrayOfAnyURI) URI(org.apache.axis.types.URI) ArrayOfAnyURI(org.dcache.srm.v2_2.ArrayOfAnyURI)

Example 24 with TReturnStatus

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

the class SRMGetSpaceTokensClientV2 method start.

@Override
public void start() throws Exception {
    checkCredentialValid();
    try {
        String tokenDescription = configuration.getSpaceTokenDescription();
        SrmGetSpaceTokensRequest request = new SrmGetSpaceTokensRequest();
        request.setUserSpaceTokenDescription(tokenDescription);
        SrmGetSpaceTokensResponse response = srm.srmGetSpaceTokens(request);
        if (response == null) {
            throw new IOException(" null SrmGetSpaceTokensResponse");
        }
        TReturnStatus rs = response.getReturnStatus();
        if (rs == null) {
            throw new IOException(" null TReturnStatus ");
        }
        if (RequestStatusTool.isFailedRequestStatus(rs)) {
            throw new IOException("SrmGetSpaceTokens failed, unexpected or failed return status : " + rs.getStatusCode() + " explanation=" + rs.getExplanation());
        }
        if (response.getArrayOfSpaceTokens() == null || response.getArrayOfSpaceTokens().getStringArray() == null) {
            throw new IOException("SrmGetSpaceTokens returned null array of space tokens");
        }
        String[] spaceTokens = response.getArrayOfSpaceTokens().getStringArray();
        System.out.println("Space Reservation Tokens:");
        for (String spaceToken : spaceTokens) {
            System.out.println(spaceToken);
        }
    } catch (Exception e) {
        throw e;
    }
}
Also used : TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) SrmGetSpaceTokensResponse(org.dcache.srm.v2_2.SrmGetSpaceTokensResponse) IOException(java.io.IOException) SrmGetSpaceTokensRequest(org.dcache.srm.v2_2.SrmGetSpaceTokensRequest) IOException(java.io.IOException)

Example 25 with TReturnStatus

use of org.dcache.srm.v2_2.TReturnStatus 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)

Aggregations

TReturnStatus (org.dcache.srm.v2_2.TReturnStatus)117 URI (org.apache.axis.types.URI)28 ArrayOfAnyURI (org.dcache.srm.v2_2.ArrayOfAnyURI)28 TStatusCode (org.dcache.srm.v2_2.TStatusCode)27 SRMException (org.dcache.srm.SRMException)19 ArrayOfString (org.dcache.srm.v2_2.ArrayOfString)19 IOException (java.io.IOException)18 URI (java.net.URI)17 SRMInvalidRequestException (org.dcache.srm.SRMInvalidRequestException)17 SRMInternalErrorException (org.dcache.srm.SRMInternalErrorException)16 SRMAuthorizationException (org.dcache.srm.SRMAuthorizationException)13 TSURLReturnStatus (org.dcache.srm.v2_2.TSURLReturnStatus)12 SRMInvalidPathException (org.dcache.srm.SRMInvalidPathException)11 ArrayOfTSURLReturnStatus (org.dcache.srm.v2_2.ArrayOfTSURLReturnStatus)8 SrmReleaseFilesResponse (org.dcache.srm.v2_2.SrmReleaseFilesResponse)8 TRetentionPolicyInfo (org.dcache.srm.v2_2.TRetentionPolicyInfo)8 UnsignedLong (org.apache.axis.types.UnsignedLong)7 SrmAbortFilesResponse (org.dcache.srm.v2_2.SrmAbortFilesResponse)7 TMetaDataPathDetail (org.dcache.srm.v2_2.TMetaDataPathDetail)7 FileMetaData (org.dcache.srm.FileMetaData)6