public TransferJob findPooledJob()

in src/main/java/com/google/gcs/sdrs/service/worker/rule/impl/StsRuleExecutor.java [778:827]


  public TransferJob findPooledJob(
      String projectId,
      String bucketName,
      @Nullable String scheduledAt,
      RetentionRuleType retentionRuleType)
      throws IOException {
    PooledStsJob pooledJob =
        stsJobDao.getJob(
            bucketName, projectId, scheduledAt, retentionRuleType.toDatabaseRepresentation());
    boolean isOnDemandPoolCreation =
        SdrsApplication.getAppConfigProperty(
                    "sts.jobPoolOnDemand." + retentionRuleType.toString().toLowerCase())
                != null
            ? true
            : false;
    if (pooledJob == null && isOnDemandPoolCreation) {
      // create STS job pool
      String destinationBucket = StsUtil.buildDestinationBucketName(bucketName);
      List<TransferJob> transferJobList =
          createJobPool(projectId, bucketName, destinationBucket, retentionRuleType);
      pooledJob = saveJobPoolAndGetNextJob(transferJobList, scheduledAt, retentionRuleType);
    }
    String jobName = null;
    if (pooledJob != null) {
      jobName = pooledJob.getName();

      logger.info(
          String.format(
              "STS job found from the pool to run at %s for %s/%s",
              pooledJob.getSchedule(), projectId, bucketName));
    } else {
      logger.error(String.format("No pooled STS job found for %s/%s", projectId, bucketName));
      return null;
    }

    if (scheduledAt != null) {
      scheduledAt = pooledJob.getSchedule();
    }

    TransferJob transferJob = StsUtil.getExistingJob(client, projectId, jobName);
    if (!isValidPooledJob(transferJob, jobName, projectId, bucketName, scheduledAt)) {
      logger.error(
          String.format(
              "Pooled job %s scheduled at %s for %s/%s is not valid",
              jobName, scheduledAt, projectId, bucketName));
      return null;
    }

    return transferJob;
  }