Ejemplo n.º 1
0
 public void saveTask(Task task) {
   Task oldTask = findTask(task.getName());
   if (oldTask == null) {
     tasks.add(task);
   } else {
     for (int i = 0; i < tasks.size(); i++) {
       if (StringUtils.equals(tasks.get(i).getName(), task.getName())) {
         tasks.set(i, task);
       }
     }
   }
 }
Ejemplo n.º 2
0
  /*
   * Test method for 'fi.helsinki.cs.kohahdus.trainer.Task.setName(String)'
   */
  public void testSetName() {
    progtask.setName("Tehtävä kutonen");
    result = progtask.getName();
    expected = "Tehtävä kutonen";
    assertEquals(expected, result);

    progtask.setName("");
    result = progtask.getName();
    expected = "";
    assertEquals(expected, result);

    progtask.setName(null);
    result = progtask.getName();
    expected = null;
    assertEquals(expected, result);
  }
Ejemplo n.º 3
0
 public Task removeTask(String taskName) {
   for (int i = 0; i < tasks.size(); i++) {
     Task task = tasks.get(i);
     if (StringUtils.equals(task.getName(), taskName)) {
       tasks.remove(i);
       return task;
     }
   }
   return null;
 }
  /**
   * Returns control when task is complete.
   *
   * @param json
   * @param logger
   */
  private String waitForDeploymentCompletion(JSON json, OctopusApi api, Log logger) {
    final long WAIT_TIME = 5000;
    final double WAIT_RANDOM_SCALER = 100.0;
    JSONObject jsonObj = (JSONObject) json;
    String id = jsonObj.getString("TaskId");
    Task task = null;
    String lastState = "Unknown";
    try {
      task = api.getTask(id);
    } catch (IOException ex) {
      logger.error("Error getting task: " + ex.getMessage());
      return null;
    }

    logger.info("Task info:");
    logger.info("\tId: " + task.getId());
    logger.info("\tName: " + task.getName());
    logger.info("\tDesc: " + task.getDescription());
    logger.info("\tState: " + task.getState());
    logger.info("\n\nStarting wait...");
    boolean completed = task.getIsCompleted();
    while (!completed) {
      try {
        task = api.getTask(id);
      } catch (IOException ex) {
        logger.error("Error getting task: " + ex.getMessage());
        return null;
      }

      completed = task.getIsCompleted();
      lastState = task.getState();
      logger.info("Task state: " + lastState);
      if (completed) {
        break;
      }
      try {
        Thread.sleep(WAIT_TIME + (long) (Math.random() * WAIT_RANDOM_SCALER));
      } catch (InterruptedException ex) {
        logger.info("Wait interrupted!");
        logger.info(ex.getMessage());
        completed = true; // bail out of wait loop
      }
    }
    logger.info("Wait complete!");
    return lastState;
  }
Ejemplo n.º 5
0
 // Overriding the compareTo method
 public int compareTo(Task t) {
   return (this.getName()).compareTo(t.getName());
 }
Ejemplo n.º 6
0
 public Task findTask(String taskName) {
   for (Task task : tasks) {
     if (taskName.equals(task.getName())) return task;
   }
   return null;
 }