Search in sources :

Example 1 with SrmGetRequestSummaryResponse

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

the class SrmGetRequestSummary method srmGetRequestSummary.

private SrmGetRequestSummaryResponse srmGetRequestSummary() throws SRMInvalidRequestException {
    String[] requestTokens = request.getArrayOfRequestTokens().getStringArray();
    if (requestTokens == null || requestTokens.length == 0) {
        throw new SRMInvalidRequestException("arrayOfRequestTokens is empty");
    }
    TRequestSummary[] requestSummaries = new TRequestSummary[requestTokens.length];
    boolean hasFailure = false;
    boolean hasSuccess = false;
    for (int i = 0; i < requestTokens.length; ++i) {
        String requestToken = requestTokens[i];
        TRequestSummary summary;
        try {
            ContainerRequest<?> request = Request.getRequest(requestToken, ContainerRequest.class);
            try (JDC ignored = request.applyJdc()) {
                summary = request.getRequestSummary();
            }
            hasSuccess = true;
        } catch (SRMInvalidRequestException e) {
            summary = new TRequestSummary();
            summary.setRequestToken(requestToken);
            summary.setStatus(new TReturnStatus(TStatusCode.SRM_INVALID_REQUEST, e.getMessage()));
            hasFailure = true;
        }
        requestSummaries[i] = summary;
    }
    return new SrmGetRequestSummaryResponse(getSummaryReturnStatus(hasFailure, hasSuccess), new ArrayOfTRequestSummary(requestSummaries));
}
Also used : TRequestSummary(org.dcache.srm.v2_2.TRequestSummary) ArrayOfTRequestSummary(org.dcache.srm.v2_2.ArrayOfTRequestSummary) ArrayOfTRequestSummary(org.dcache.srm.v2_2.ArrayOfTRequestSummary) TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) JDC(org.dcache.srm.util.JDC) SrmGetRequestSummaryResponse(org.dcache.srm.v2_2.SrmGetRequestSummaryResponse) SRMInvalidRequestException(org.dcache.srm.SRMInvalidRequestException)

Example 2 with SrmGetRequestSummaryResponse

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

the class SRMGetRequestSummaryClientV2 method start.

@Override
public void start() throws Exception {
    checkCredentialValid();
    try {
        String[] tokens = configuration.getArrayOfRequestTokens();
        SrmGetRequestSummaryRequest request = new SrmGetRequestSummaryRequest();
        request.setArrayOfRequestTokens(new ArrayOfString(tokens));
        SrmGetRequestSummaryResponse response = srm.srmGetRequestSummary(request);
        if (response == null) {
            throw new IOException(" null SrmGetRequestSummaryResponse ");
        }
        TReturnStatus rs = response.getReturnStatus();
        if (rs == null) {
            throw new IOException(" null TReturnStatus ");
        }
        if (response.getArrayOfRequestSummaries() != null) {
            ArrayOfTRequestSummary summaries = response.getArrayOfRequestSummaries();
            if (summaries.getSummaryArray() != null) {
                for (int i = 0; i < summaries.getSummaryArray().length; i++) {
                    TRequestSummary summary = summaries.getSummaryArray(i);
                    if (summary != null) {
                        TReturnStatus st = summary.getStatus();
                        TRequestType type = summary.getRequestType();
                        System.out.println("\tRequest number  : " + summary.getRequestToken());
                        System.out.println("\t  Request type  : " + (type != null ? type.getValue() : "UNKNOWN"));
                        System.out.println("\t Return status");
                        System.out.println("\t\t Status code  : " + (st != null ? st.getStatusCode() : "null"));
                        System.out.println("\t\t Explanation  : " + (st != null ? st.getExplanation() : "null"));
                        System.out.println("\tTotal # of files: " + summary.getTotalNumFilesInRequest());
                        System.out.println("\t completed files: " + summary.getNumOfCompletedFiles());
                        System.out.println("\t   waiting files: " + summary.getNumOfWaitingFiles());
                        System.out.println("\t    failed files: " + summary.getNumOfFailedFiles());
                    }
                }
            }
        }
        if (RequestStatusTool.isFailedRequestStatus(rs)) {
            throw new IOException("srmGetRequestSummary failed, unexpected or failed return status : " + rs.getStatusCode() + " explanation=" + rs.getExplanation());
        }
    } catch (Exception e) {
        throw e;
    }
}
Also used : ArrayOfTRequestSummary(org.dcache.srm.v2_2.ArrayOfTRequestSummary) TRequestSummary(org.dcache.srm.v2_2.TRequestSummary) ArrayOfTRequestSummary(org.dcache.srm.v2_2.ArrayOfTRequestSummary) TRequestType(org.dcache.srm.v2_2.TRequestType) TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) ArrayOfString(org.dcache.srm.v2_2.ArrayOfString) SrmGetRequestSummaryResponse(org.dcache.srm.v2_2.SrmGetRequestSummaryResponse) SrmGetRequestSummaryRequest(org.dcache.srm.v2_2.SrmGetRequestSummaryRequest) ArrayOfString(org.dcache.srm.v2_2.ArrayOfString) IOException(java.io.IOException) IOException(java.io.IOException)

Example 3 with SrmGetRequestSummaryResponse

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

the class SrmGetRequestSummary method getFailedResponse.

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

Example 4 with SrmGetRequestSummaryResponse

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

the class SrmHandler method toGetRequestSummaryResponse.

private SrmGetRequestSummaryResponse toGetRequestSummaryResponse(Map<String, ListenableFuture<TRequestSummary>> futureMap) throws InterruptedException, CacheException, NoRouteToCellException {
    boolean hasFailure = false;
    boolean hasSuccess = false;
    List<TRequestSummary> summaries = new ArrayList<>();
    for (Map.Entry<String, ListenableFuture<TRequestSummary>> entry : futureMap.entrySet()) {
        try {
            summaries.add(entry.getValue().get());
            hasSuccess = true;
        } catch (ExecutionException e) {
            Throwable cause = e.getCause();
            if (cause instanceof SRMException) {
                summaries.add(createRequestSummaryFailure(entry.getKey(), ((SRMException) cause).getStatusCode(), cause.getMessage()));
                hasFailure = true;
            } else {
                Throwables.throwIfInstanceOf(cause, CacheException.class);
                Throwables.throwIfInstanceOf(cause, NoRouteToCellException.class);
                Throwables.throwIfUnchecked(e);
                throw new RuntimeException(e);
            }
        }
    }
    TReturnStatus status;
    if (!hasFailure) {
        status = new TReturnStatus(SRM_SUCCESS, "All request statuses have been retrieved.");
    } else if (hasSuccess) {
        status = new TReturnStatus(SRM_PARTIAL_SUCCESS, "Some request statuses have been retrieved.");
    } else {
        status = new TReturnStatus(SRM_FAILURE, "No request statuses have been retrieved.");
    }
    return new SrmGetRequestSummaryResponse(status, new ArrayOfTRequestSummary(summaries.toArray(TRequestSummary[]::new)));
}
Also used : TRequestSummary(org.dcache.srm.v2_2.TRequestSummary) ArrayOfTRequestSummary(org.dcache.srm.v2_2.ArrayOfTRequestSummary) ArrayOfTRequestSummary(org.dcache.srm.v2_2.ArrayOfTRequestSummary) CacheException(diskCacheV111.util.CacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) ArrayList(java.util.ArrayList) SrmGetRequestSummaryResponse(org.dcache.srm.v2_2.SrmGetRequestSummaryResponse) ArrayOfString(org.dcache.srm.v2_2.ArrayOfString) SRMException(org.dcache.srm.SRMException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map) Collectors.toMap(java.util.stream.Collectors.toMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Aggregations

SrmGetRequestSummaryResponse (org.dcache.srm.v2_2.SrmGetRequestSummaryResponse)4 TReturnStatus (org.dcache.srm.v2_2.TReturnStatus)4 ArrayOfTRequestSummary (org.dcache.srm.v2_2.ArrayOfTRequestSummary)3 TRequestSummary (org.dcache.srm.v2_2.TRequestSummary)3 ArrayOfString (org.dcache.srm.v2_2.ArrayOfString)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 CacheException (diskCacheV111.util.CacheException)1 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)1 NoRouteToCellException (dmg.cells.nucleus.NoRouteToCellException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ExecutionException (java.util.concurrent.ExecutionException)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 SRMException (org.dcache.srm.SRMException)1 SRMInvalidRequestException (org.dcache.srm.SRMInvalidRequestException)1 JDC (org.dcache.srm.util.JDC)1 SrmGetRequestSummaryRequest (org.dcache.srm.v2_2.SrmGetRequestSummaryRequest)1