Ejemplo n.º 1
0
 @Override
 public void toString(StringBuilder sb, boolean longformat) {
   sb.append(getMethod())
       .append("Request #")
       .append(getId())
       .append(" created by ")
       .append(getUser());
   sb.append(" with credentials : ")
       .append(getCredential())
       .append(" state = ")
       .append(getState());
   sb.append("\n SURL(s) : ");
   for (LsFileRequest fr : getFileRequests()) {
     sb.append(fr.getSurlString()).append(" ");
   }
   sb.append("\n count      : ").append(getCount());
   sb.append("\n offset     : ").append(getOffset());
   sb.append("\n longFormat : ").append(getLongFormat());
   sb.append("\n numOfLevels: ").append(getNumOfLevels());
   if (longformat) {
     sb.append("\n status code=").append(getStatusCode());
     sb.append("\n error message=").append(getErrorMessage());
     sb.append("\n History of State Transitions: \n");
     sb.append(getHistory());
     for (LsFileRequest fr : getFileRequests()) {
       fr.toString(sb, longformat);
     }
   } else {
     sb.append(" number of surls in request:").append(getFileRequests().size());
   }
 }
Ejemplo n.º 2
0
 public TMetaDataPathDetail[] getPathDetailArray() {
   int len = getFileRequests().size();
   TMetaDataPathDetail detail[] = new TMetaDataPathDetail[len];
   for (int i = 0; i < len; ++i) {
     LsFileRequest fr = getFileRequests().get(i);
     detail[i] = fr.getMetaDataPathDetail();
   }
   return detail;
 }
Ejemplo n.º 3
0
 @Nonnull
 @Override
 public LsFileRequest getFileRequestBySurl(URI surl) throws SRMFileRequestNotFoundException {
   for (LsFileRequest request : getFileRequests()) {
     if (request.getSurl().equals(surl)) {
       return request;
     }
   }
   throw new SRMFileRequestNotFoundException(
       "ls file request for surl =" + surl + " is not found");
 }
Ejemplo n.º 4
0
  @Override
  public void scheduleWith(Scheduler scheduler)
      throws InterruptedException, IllegalStateTransition {
    // save this request in request storage unconditionally
    // file requests will get stored as soon as they are
    // scheduled, and the saved state needs to be consistent
    saveJob(true);

    for (LsFileRequest request : getFileRequests()) {
      request.scheduleWith(scheduler);
    }
  }
Ejemplo n.º 5
0
 @Override
 protected void stateChanged(State oldState) {
   State state = getState();
   if (state.isFinal()) {
     for (LsFileRequest fr : getFileRequests()) {
       fr.wlock();
       try {
         State fr_state = fr.getState();
         if (!fr_state.isFinal()) {
           fr.setState(state, "Changing file state because request state has changed.");
         }
       } catch (IllegalStateTransition ist) {
         logger.error("Illegal State Transition : " + ist.getMessage());
       } finally {
         fr.wunlock();
       }
     }
   }
 }
Ejemplo n.º 6
0
 @Override
 public final TReturnStatus getTReturnStatus() {
   wlock();
   try {
     getRequestStatus();
     if (getStatusCode() != null) {
       return new TReturnStatus(getStatusCode(), getExplanation());
     }
     int len = getNumOfFileRequest();
     if (len == 0) {
       return new TReturnStatus(
           TStatusCode.SRM_INTERNAL_ERROR,
           "Could not find (deserialize) files in the request,  NumOfFileRequest is 0");
     }
     int failed_req = 0;
     int canceled_req = 0;
     int pending_req = 0;
     int running_req = 0;
     int done_req = 0;
     int got_exception = 0;
     int auth_failure = 0;
     for (LsFileRequest fr : getFileRequests()) {
       TReturnStatus fileReqRS = fr.getReturnStatus();
       TStatusCode fileReqSC = fileReqRS.getStatusCode();
       try {
         if (fileReqSC == TStatusCode.SRM_REQUEST_QUEUED) {
           pending_req++;
         } else if (fileReqSC == TStatusCode.SRM_REQUEST_INPROGRESS) {
           running_req++;
         } else if (fileReqSC == TStatusCode.SRM_ABORTED) {
           canceled_req++;
         } else if (fileReqSC == TStatusCode.SRM_AUTHORIZATION_FAILURE) {
           auth_failure++;
         } else if (RequestStatusTool.isFailedFileRequestStatus(fileReqRS)) {
           failed_req++;
         } else {
           done_req++;
         }
       } catch (Exception e) {
         logger.error(e.toString());
         got_exception++;
       }
     }
     boolean isFinalState = getState().isFinal();
     if (done_req == len) {
       if (!isFinalState) {
         try {
           setState(State.DONE, "Operation completed.");
         } catch (IllegalStateTransition ist) {
           logger.error("Illegal State Transition : " + ist.getMessage());
         }
       }
       return new TReturnStatus(TStatusCode.SRM_SUCCESS, null);
     }
     if (canceled_req == len) {
       return new TReturnStatus(TStatusCode.SRM_ABORTED, "All ls file requests were cancelled");
     }
     if ((pending_req == len) || (pending_req + running_req == len) || running_req == len) {
       return new TReturnStatus(
           TStatusCode.SRM_REQUEST_QUEUED, "All ls file requests are pending");
     }
     if (auth_failure == len) {
       return new TReturnStatus(
           TStatusCode.SRM_AUTHORIZATION_FAILURE,
           "Client is not authorized to request information");
     }
     if (got_exception == len) {
       return new TReturnStatus(
           TStatusCode.SRM_INTERNAL_ERROR,
           "SRM has an internal transient error, and client may try again");
     }
     if (running_req > 0 || pending_req > 0) {
       return new TReturnStatus(
           TStatusCode.SRM_REQUEST_INPROGRESS,
           "Some files are completed, and some files are still on the queue. Details are on the files status");
     } else {
       if (done_req > 0) {
         if (!isFinalState) {
           try {
             setState(State.DONE, State.DONE.toString());
           } catch (IllegalStateTransition ist) {
             logger.error("Illegal State Transition : " + ist.getMessage());
           }
         }
         return new TReturnStatus(
             TStatusCode.SRM_PARTIAL_SUCCESS,
             "Some SURL requests successfully completed, and some SURL requests failed. Details are on the files status");
       } else {
         if (!isFinalState) {
           try {
             setState(State.FAILED, State.FAILED.toString());
           } catch (IllegalStateTransition ist) {
             logger.error("Illegal State Transition : " + ist.getMessage());
           }
         }
         return new TReturnStatus(
             TStatusCode.SRM_FAILURE, "All ls requests failed in some way or another");
       }
     }
   } finally {
     wunlock();
   }
 }