Example #1
0
  /**
   * Return recall tasks for being taken over. The status of the tasks that are returned is set to
   * in progress.
   *
   * @param input a key value pair in which the value is the number of results to be returned in the
   * @return the tasks ready to takeover
   * @throws TapeRecallException
   */
  @PUT
  @Consumes("text/plain")
  @Produces("text/plain")
  public Response putTakeoverTasks(InputStream input) throws TapeRecallException {

    // retrieve the Input String
    String inputStr = buildInputString(input);

    log.debug("@PUT (input string) = '{}'", inputStr);

    // retrieve the number of tasks to takeover (default = 1)
    int numbOfTask = 1;

    // retrieve value from Body param
    String keyTakeover = config.getTaskoverKey();

    int eqIndex = inputStr.indexOf('=');

    if (eqIndex > 0) {

      String value = inputStr.substring(eqIndex);
      String key = inputStr.substring(0, eqIndex);

      if (key.equals(keyTakeover)) {

        try {

          // trim out the '\n' end.
          numbOfTask = Integer.valueOf(value.substring(1, value.length() - 1));

        } catch (NumberFormatException e) {

          throw new TapeRecallException(
              "Unable to understand " + "the number value = '" + value + "'");
        }
      }
    }

    // retrieve the tasks
    ArrayList<TapeRecallTO> tasks = new TapeRecallCatalog().takeoverNTasksWithDoubles(numbOfTask);

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

    ArrayList<TapeRecallTO> groupTasks = new ArrayList<TapeRecallTO>();

    for (ArrayList<TapeRecallTO> groupTaskList : groupTaskMap.values()) {

      try {

        groupTasks.add(makeOne(groupTaskList));

      } catch (IllegalArgumentException e) {

        log.error(
            "Unable to makeOne the task list . IllegalArgumentException : {}", e.getMessage(), e);
        log.error("Erroneous task list (long output): {}", groupTaskList.toString());
        log.error("Skip the erroneous task list and go on...Please contact StoRM support");
      }
    }

    if (tasks.size() > groupTasks.size()) {

      log.debug("Taking over some multy-group tasks");
    }

    log.debug(
        "Number of tasks recalled : <{}> over <{}> tasks requested",
        groupTasks.size(),
        tasks.size());

    // need a generic entity
    GenericEntity<List<TapeRecallTO>> entity = new GenericEntity<List<TapeRecallTO>>(tasks) {};

    return Response.ok(entity).build();
  }