Example #1
0
  /**
   * Creates a map with the taskIds as keys and the list of tasks related to each taskId (key) as
   * value
   *
   * @param tasks
   * @return
   */
  private HashMap<UUID, ArrayList<TapeRecallTO>> buildGroupTaskMap(ArrayList<TapeRecallTO> tasks) {

    HashMap<UUID, ArrayList<TapeRecallTO>> groupTaskMap =
        new HashMap<UUID, ArrayList<TapeRecallTO>>();

    for (TapeRecallTO task : tasks) {

      ArrayList<TapeRecallTO> taskList = groupTaskMap.get(task.getGroupTaskId());

      if (taskList == null) {

        taskList = new ArrayList<TapeRecallTO>();
        groupTaskMap.put(task.getGroupTaskId(), taskList);
      }

      taskList.add(task);
    }

    return groupTaskMap;
  }
Example #2
0
  /**
   * Given a list of tasks with the same taskId oproduces a single task merging the list members
   *
   * @param recallTasks
   * @return
   */
  private TapeRecallTO makeOne(ArrayList<TapeRecallTO> recallTasks)
      throws IllegalArgumentException {

    TapeRecallTO taskTO = new TapeRecallTO();

    UUID taskId = recallTasks.get(0).getTaskId();

    // verify that all have the same task id
    for (TapeRecallTO recallTask : recallTasks) {

      if (!recallTask.getTaskId().equals(taskId)) {

        log.error(
            "Received a list of not omogeneous tasks, the taskid '{}' is not matched by : {}",
            taskId,
            recallTask.toString());

        throw new IllegalArgumentException("Received a list of not omogeneous tasks");
      }
    }

    for (TapeRecallTO recallTask : recallTasks) {

      // set common fields from any of the tasks
      taskTO.setTaskId(recallTask.getTaskId());
      taskTO.setGroupTaskId(recallTask.getGroupTaskId());
      taskTO.setRequestToken(recallTask.getRequestToken());
      taskTO.setRequestType(recallTask.getRequestType());
      taskTO.setFileName(recallTask.getFileName());
      taskTO.setUserID(recallTask.getUserID());
      taskTO.setVoName(recallTask.getVoName());
      taskTO.setStatus(TapeRecallStatus.QUEUED);

      break;
    }

    /*
     * merge task on recall related fields to have a pin that starts as soon as
     * requested and last as long as needed
     */

    int maxRetryAttempt = 0;

    Date minInsertionInstant = null;
    Date minDeferredRecallInstant = null;
    Date maxPinExpirationInstant = null;

    for (TapeRecallTO recallTask : recallTasks) {

      if (recallTask.getRetryAttempt() > maxRetryAttempt) {
        maxRetryAttempt = recallTask.getRetryAttempt();
      }

      if (minInsertionInstant == null
          || recallTask.getInsertionInstant().before(minInsertionInstant)) {

        minInsertionInstant = recallTask.getInsertionInstant();
      }

      if (minDeferredRecallInstant == null
          || recallTask.getDeferredRecallInstant().before(minDeferredRecallInstant)) {

        minDeferredRecallInstant = recallTask.getDeferredRecallInstant();
      }

      Date currentPinExpirationInstant =
          new Date(
              recallTask.getDeferredRecallInstant().getTime()
                  + (recallTask.getPinLifetime() * 1000));

      if (maxPinExpirationInstant == null
          || currentPinExpirationInstant.after(maxPinExpirationInstant)) {

        maxPinExpirationInstant = currentPinExpirationInstant;
      }
    }

    taskTO.setRetryAttempt(maxRetryAttempt);
    taskTO.setInsertionInstant(minInsertionInstant);
    taskTO.setDeferredRecallInstant(minDeferredRecallInstant);

    int pinLifeTime =
        (int) (maxPinExpirationInstant.getTime() - minDeferredRecallInstant.getTime()) / 1000;

    taskTO.setPinLifetime(pinLifeTime);

    return taskTO;
  }