Esempio n. 1
0
  private SrmRmdirResponse srmRmdir() throws SRMException {
    URI surl = URI.create(request.getSURL().toString());
    String path = getPath(surl);

    /* If surl is a prefix to any active upload, then we report the directory as
     * non-empty. This is not strictly required by the SRM spec, however S2 tests
     * (usecase.RmdirBeingPutInto) check for this behaviour.
     */
    for (PutFileRequest putFileRequest : Job.getActiveJobs(PutFileRequest.class)) {
      String requestPath = getPath(putFileRequest.getSurl());
      if (path.equals(requestPath)) {
        throw new SRMInvalidPathException("Not a directory");
      }
      if (requestPath.startsWith(path)) {
        throw new SRMNonEmptyDirectoryException("Directory is not empty");
      }
    }

    storage.removeDirectory(user, surl, request.getRecursive() != null && request.getRecursive());
    return new SrmRmdirResponse(new TReturnStatus(TStatusCode.SRM_SUCCESS, null));
  }
 private PreparedStatement getStatement(Connection connection, String query, Job job)
     throws SQLException {
   PutFileRequest request = (PutFileRequest) job;
   TRetentionPolicy retentionPolicy = request.getRetentionPolicy();
   TAccessLatency accessLatency = request.getAccessLatency();
   return getPreparedStatement(
       connection,
       query,
       request.getNextJobId(),
       request.getCreationTime(),
       request.getLifetime(),
       request.getState().getStateId(),
       request.getErrorMessage(),
       request.getSchedulerId(),
       request.getSchedulerTimeStamp(),
       0, // num of retries
       request.getLastStateTransitionTime(),
       request.getRequestId(),
       request.getStatusCodeString(),
       request.getSurlString(),
       request.getTurlString(),
       request.getFileId(),
       null, // parentFileId (unused)
       request.getSpaceReservationId(),
       request.getSize(),
       (retentionPolicy != null ? retentionPolicy.getValue() : null),
       (accessLatency != null ? accessLatency.getValue() : null),
       request.getId());
 }
 @Override
 public PreparedStatement getCreateStatement(Connection connection, Job job) throws SQLException {
   if (job == null || !(job instanceof PutFileRequest)) {
     throw new IllegalArgumentException("fr is not PutFileRequest");
   }
   PutFileRequest request = (PutFileRequest) job;
   TRetentionPolicy retentionPolicy = request.getRetentionPolicy();
   TAccessLatency accessLatency = request.getAccessLatency();
   return getPreparedStatement(
       connection,
       INSERT_SQL,
       request.getId(),
       request.getNextJobId(),
       request.getCreationTime(),
       request.getLifetime(),
       request.getState().getStateId(),
       request.getErrorMessage(),
       request.getSchedulerId(),
       request.getSchedulerTimeStamp(),
       0, // num of retries
       request.getLastStateTransitionTime(),
       request.getRequestId(),
       request.getStatusCodeString(),
       request.getSurlString(),
       request.getTurlString(),
       request.getFileId(),
       null, // parentFileId (unused)
       request.getSpaceReservationId(),
       request.getSize(),
       (retentionPolicy != null ? retentionPolicy.getValue() : null),
       (accessLatency != null ? accessLatency.getValue() : null));
 }
Esempio n. 4
0
  @Override
  public synchronized void run() throws NonFatalJobFailure, FatalJobFailure {
    try {
      LsRequest parent = getContainerRequest();
      long t0 = 0;
      if (logger.isDebugEnabled()) {
        t0 = System.currentTimeMillis();
      }

      PutFileRequest request =
          Iterables.getFirst(SRM.getSRM().getActiveFileRequests(PutFileRequest.class, surl), null);
      if (request != null) {
        // [SRM 2.2, 4.4.3]
        //
        // SRM_FILE_BUSY
        //
        //     client requests for a file which there is an active
        //     srmPrepareToPut (no srmPutDone is yet called) request for.
        try {
          FileMetaData fmd = getStorage().getFileMetaData(getUser(), surl, request.getFileId());
          metaDataPathDetail =
              convertFileMetaDataToTMetaDataPathDetail(surl, fmd, parent.getLongFormat());
        } catch (SRMInvalidPathException e) {
          metaDataPathDetail = new TMetaDataPathDetail();
          metaDataPathDetail.setType(TFileType.FILE);
        }
        metaDataPathDetail.setPath(getPath(surl));
        metaDataPathDetail.setStatus(
            new TReturnStatus(
                TStatusCode.SRM_FILE_BUSY, "The requested SURL is locked by an upload."));
      } else {
        metaDataPathDetail =
            getMetaDataPathDetail(
                surl,
                0,
                parent.getOffset(),
                parent.getCount(),
                parent.getNumOfLevels(),
                parent.getLongFormat());
      }
      if (logger.isDebugEnabled()) {
        logger.debug("LsFileRequest.run(), TOOK " + (System.currentTimeMillis() - t0));
      }
      try {
        getContainerRequest().resetRetryDeltaTime();
      } catch (SRMInvalidRequestException ire) {
        logger.error(ire.toString());
      }
      setState(State.DONE, State.DONE.toString());
    } catch (SRMException | DataAccessException | URISyntaxException | IllegalStateTransition e) {
      wlock();
      try {
        TReturnStatus status;
        String msg = e.getMessage();
        if (e instanceof SRMInternalErrorException) {
          status = new TReturnStatus(TStatusCode.SRM_FAILURE, msg);
        } else if (e instanceof SRMTooManyResultsException) {
          status = new TReturnStatus(TStatusCode.SRM_TOO_MANY_RESULTS, msg);
        } else if (e instanceof SRMAuthorizationException) {
          status = new TReturnStatus(TStatusCode.SRM_AUTHORIZATION_FAILURE, msg);
        } else if (e instanceof SRMInvalidPathException) {
          status = new TReturnStatus(TStatusCode.SRM_INVALID_PATH, msg);
        } else if (e instanceof DataAccessException) {
          status = new TReturnStatus(TStatusCode.SRM_INTERNAL_ERROR, msg);
        } else {
          if (e instanceof RuntimeException) {
            logger.error(e.toString(), e);
          }
          status = new TReturnStatus(TStatusCode.SRM_FAILURE, msg);
        }
        metaDataPathDetail = new TMetaDataPathDetail();
        metaDataPathDetail.setPath(getPath(surl));
        metaDataPathDetail.setStatus(status);
        setStatusCode(status.getStatusCode());
        setState(State.FAILED, msg);
      } catch (IllegalStateTransition ist) {
        logger.error("Illegal State Transition : " + ist.getMessage());
      } finally {
        wunlock();
      }
    }
  }
Esempio n. 5
0
    @Override
    public void run() {
      try {
        PutFileRequest fr = Job.getJob(fileRequestJobId, PutFileRequest.class);

        try {
          String fileId = future.checkedGet();

          State state = fr.getState();
          switch (state) {
            case INPROGRESS:
              logger.trace("Storage info arrived for file {}.", fr.getSurlString());
              fr.setFileId(fileId);
              fr.saveJob(true);
              Scheduler.getScheduler(fr.getSchedulerId()).execute(fr);
              break;
            case CANCELED:
            case FAILED:
              fr.getStorage().abortPut(fr.getUser(), fileId, fr.getSurl(), fr.getErrorMessage());
              break;
            default:
              logger.error("Put request is in an unexpected state in callback: {}", state);
              fr.getStorage().abortPut(fr.getUser(), fileId, fr.getSurl(), fr.getErrorMessage());
              break;
          }
        } catch (SRMException e) {
          fr.setStateAndStatusCode(State.FAILED, e.getMessage(), e.getStatusCode());
        }
      } catch (IllegalStateTransition ist) {
        if (!ist.getFromState().isFinal()) {
          logger.error(ist.getMessage());
        }
      } catch (SRMInvalidRequestException e) {
        try {
          String fileId = future.checkedGet();
          SRM.getSRM()
              .getStorage()
              .abortPut(user, fileId, surl, "Request was aborted while being prepared.");
        } catch (SRMException ignored) {
        }
      }
    }