Beispiel #1
0
  @Override
  public void run() throws IllegalStateTransition, SRMException {
    logger.trace("run");
    if (!getState().isFinal()) {
      if (getFileId() == null) {
        // [SRM 2.2, 5.5.2, t)] Upon srmPrepareToPut, SURL entry is inserted to the name space, and
        // any
        // methods that access the SURL such as srmLs, srmBringOnline and srmPrepareToGet must
        // return
        // SRM_FILE_BUSY at the file level. If another srmPrepareToPut or srmCopy is requested on
        // the same SURL, SRM_FILE_BUSY must be returned if the SURL can be overwritten, otherwise
        // SRM_DUPLICATION_ERROR must be returned at the file level.
        for (PutFileRequest request :
            SRM.getSRM().getActiveFileRequests(PutFileRequest.class, getSurl())) {
          if (request != this) {
            if (!getContainerRequest().isOverwrite()) {
              throw new SRMDuplicationException("The requested SURL is locked by another upload.");
            } else {
              throw new SRMFileBusyException("The requested SURL is locked by another upload.");
            }
          }
        }

        addHistoryEvent("Doing name space lookup.");
        SRMUser user = getUser();
        CheckedFuture<String, ? extends SRMException> future =
            getStorage()
                .prepareToPut(
                    user,
                    getSurl(),
                    getSize(),
                    Objects.toString(getAccessLatency(), null),
                    Objects.toString(getRetentionPolicy(), null),
                    getSpaceReservationId(),
                    getContainerRequest().isOverwrite());
        future.addListener(
            new PutCallbacks(user, getId(), surl, future), MoreExecutors.directExecutor());
        return;
      }

      computeTurl();

      wlock();
      try {
        if (getState() == State.INPROGRESS) {
          setState(State.RQUEUED, "Putting on a \"Ready\" Queue.");
        }
      } finally {
        wunlock();
      }
    }
  }
 public SrmPrepareToPut(
     SRMUser user,
     RequestCredential credential,
     SrmPrepareToPutRequest request,
     AbstractStorageElement storage,
     SRM srm,
     String clientHost) {
   this.request = checkNotNull(request);
   this.user = checkNotNull(user);
   this.credential = checkNotNull(credential);
   this.storage = checkNotNull(storage);
   this.configuration = checkNotNull(srm.getConfiguration());
   this.clientHost = clientHost;
   this.srm = checkNotNull(srm);
 }
Beispiel #3
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) {
        }
      }
    }
Beispiel #4
0
  /** restore constructor */
  public CopyRequest(
      long id,
      Long nextJobId,
      long creationTime,
      long lifetime,
      int stateId,
      String errorMessage,
      SRMUser user,
      String scheduelerId,
      long schedulerTimeStamp,
      int numberOfRetries,
      long lastStateTransitionTime,
      JobHistory[] jobHistoryArray,
      Long credentialId,
      ImmutableList<CopyFileRequest> fileRequest,
      int retryDeltaTime,
      boolean should_updateretryDeltaTime,
      String description,
      String client_host,
      String statusCodeString,
      TFileStorageType storageType,
      TRetentionPolicy targetRetentionPolicy,
      TAccessLatency targetAccessLatency) {
    super(
        id,
        nextJobId,
        creationTime,
        lifetime,
        stateId,
        errorMessage,
        user,
        scheduelerId,
        schedulerTimeStamp,
        numberOfRetries,
        lastStateTransitionTime,
        jobHistoryArray,
        fileRequest,
        retryDeltaTime,
        should_updateretryDeltaTime,
        description,
        client_host,
        statusCodeString);

    ArrayList<String> allowedProtocols = new ArrayList<>(4);

    if (getConfiguration().isUseGsiftpForSrmCopy()) {
      allowedProtocols.add("gsiftp");
    }
    if (getConfiguration().isUseHttpForSrmCopy()) {
      allowedProtocols.add("http");
    }
    if (getConfiguration().isUseDcapForSrmCopy()) {
      allowedProtocols.add("dcap");
    }
    if (getConfiguration().isUseFtpForSrmCopy()) {
      allowedProtocols.add("ftp");
    }

    clientTransport = getConfiguration().getClientTransport();

    protocols = allowedProtocols.toArray(new String[allowedProtocols.size()]);
    this.qosPlugin = QOSPluginFactory.createInstance(SRM.getSRM());
    this.storageType = storageType;
    this.targetAccessLatency = targetAccessLatency;
    this.targetRetentionPolicy = targetRetentionPolicy;
    this.overwriteMode = null;
    this.credentialId = credentialId;
    targetSpaceToken = null;
  }
Beispiel #5
0
  public CopyRequest(
      SRMUser user,
      Long requestCredentialId,
      URI[] sourceUrl,
      URI[] destinationUrl,
      String spaceToken,
      long lifetime,
      long maxUpdatePeriod,
      TFileStorageType storageType,
      TRetentionPolicy targetRetentionPolicy,
      TAccessLatency targetAccessLatency,
      String description,
      String clientHost,
      TOverwriteMode overwriteMode,
      ImmutableMap<String, String> extraInfo) {
    super(
        user,
        maxUpdatePeriod,
        lifetime,
        description,
        clientHost,
        id -> {
          checkArgument(
              sourceUrl.length == destinationUrl.length,
              "unequal number of elements in url arrays");
          ImmutableList.Builder<CopyFileRequest> requests = ImmutableList.builder();
          for (int i = 0; i < sourceUrl.length; ++i) {
            requests.add(
                new CopyFileRequest(
                    id,
                    requestCredentialId,
                    sourceUrl[i],
                    destinationUrl[i],
                    spaceToken,
                    lifetime,
                    extraInfo));
          }
          return requests.build();
        });

    ArrayList<String> allowedProtocols = new ArrayList<>(4);
    if (getConfiguration().isUseGsiftpForSrmCopy()) {
      allowedProtocols.add("gsiftp");
    }
    if (getConfiguration().isUseHttpForSrmCopy()) {
      allowedProtocols.add("http");
    }
    if (getConfiguration().isUseDcapForSrmCopy()) {
      allowedProtocols.add("dcap");
    }
    if (getConfiguration().isUseFtpForSrmCopy()) {
      allowedProtocols.add("ftp");
    }

    clientTransport = getConfiguration().getClientTransport();
    protocols = allowedProtocols.toArray(new String[allowedProtocols.size()]);
    this.qosPlugin = QOSPluginFactory.createInstance(SRM.getSRM());
    this.storageType = storageType;
    this.targetAccessLatency = targetAccessLatency;
    this.targetRetentionPolicy = targetRetentionPolicy;
    this.overwriteMode = overwriteMode;
    this.targetSpaceToken = spaceToken;
    this.credentialId = requestCredentialId;
    LOG.debug("Request.createCopyRequest : created new request succesfully");
  }
Beispiel #6
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();
      }
    }
  }
  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());
    }
  }