コード例 #1
0
  private SrmPrepareToPutResponse srmPrepareToPut()
      throws IllegalStateTransition, InterruptedException, SRMNotSupportedException,
          SRMInvalidRequestException, SRMInternalErrorException {
    checkFileStorageType(request, TFileStorageType.PERMANENT);
    String[] protocols = getProtocols();
    String clientHost = getClientHost(request).or(this.clientHost);
    String spaceToken = request.getTargetSpaceToken();
    TRetentionPolicy retentionPolicy = null;
    TAccessLatency accessLatency = null;
    if (request.getTargetFileRetentionPolicyInfo() != null) {
      retentionPolicy = request.getTargetFileRetentionPolicyInfo().getRetentionPolicy();
      accessLatency = request.getTargetFileRetentionPolicyInfo().getAccessLatency();
    }
    TPutFileRequest[] fileRequests = getFileRequests(request);

    long lifetime = getLifetime(request, configuration.getPutLifetime());
    TOverwriteMode overwriteMode = getOverwriteMode(request);

    String[] supportedProtocols = storage.supportedPutProtocols();
    boolean isAnyProtocolSupported = any(asList(protocols), in(asList(supportedProtocols)));
    if (!isAnyProtocolSupported) {
      throw new SRMNotSupportedException(
          "Protocol(s) not supported: " + Arrays.toString(protocols));
    }

    URI[] surls = new URI[fileRequests.length];
    Long[] sizes = new Long[fileRequests.length];
    boolean[] wantPermanent = new boolean[fileRequests.length];
    for (int i = 0; i < fileRequests.length; ++i) {
      TPutFileRequest fileRequest = fileRequests[i];
      if (fileRequest == null) {
        throw new SRMInvalidRequestException("file request #" + (i + 1) + " is null.");
      }
      if (fileRequest.getTargetSURL() == null) {
        throw new SRMInvalidRequestException("surl of file request #" + (i + 1) + " is null.");
      }
      URI surl = URI.create(fileRequest.getTargetSURL().toString());
      UnsignedLong knownSize = fileRequest.getExpectedFileSize();
      if (knownSize != null) {
        sizes[i] = knownSize.longValue();
        if (sizes[i] < 0) {
          throw new SRMInvalidRequestException("Negative file size is not allowed.");
        }
      }
      wantPermanent[i] = true; // for now, extract type info from space token in the future
      /*                nextRequest.getFileStorageType()==
      TFileStorageType.PERMANENT;*/
      surls[i] = surl;
    }

    PutRequest r =
        new PutRequest(
            user,
            credential.getId(),
            surls,
            sizes,
            wantPermanent,
            protocols,
            lifetime,
            configuration.getGetRetryTimeout(),
            configuration.getGetMaxNumOfRetries(),
            clientHost,
            spaceToken,
            retentionPolicy,
            accessLatency,
            request.getUserRequestDescription());
    try (JDC ignored = r.applyJdc()) {
      String priority = getExtraInfo(request, "priority");
      if (priority != null) {
        try {
          r.setPriority(Integer.parseInt(priority));
        } catch (NumberFormatException e) {
          LOGGER.warn("Ignoring non-integer user priority: {}", priority);
        }
      }

      if (overwriteMode != null) {
        r.setOverwriteMode(overwriteMode);
      }

      srm.schedule(r);
      // RequestScheduler will take care of the rest
      // getRequestScheduler.add(r);
      // Return the request status
      return r.getSrmPrepareToPutResponse(configuration.getPutSwitchToAsynchronousModeDelay());
    }
  }