public boolean isDone(Operation operation) {
    Task task;
    try {
      task = scheduler.getTaskByName(operation.getName());
    } catch (ScheduleException se) {
      return false;
    }

    if (task.getStatus() == TaskStatus.SUSPEND) {
      return false;
    }

    TaskIDCounter counter = taskIdMapper.selectByPrimaryKey(task.getTaskid());
    if (counter == null || counter.getCounter() < operation.getNumber()) {
      return false;
    }
    InstanceID instanceID =
        new InstanceID(
            TaskID.forName(task.getTaskid()), counter.getCounter() - operation.getNumber() + 1);
    List<TaskAttempt> recentAttempts = getTaskAttemptByInstanceID(instanceID);
    if (recentAttempts == null || recentAttempts.size() == 0) {
      return false;
    }
    TaskAttempt history = recentAttempts.get(0);
    if (LOG.isDebugEnabled()) {
      LOG.debug("attempt : " + history.getAttemptid() + " status : " + history.getStatus());
    }
    int status = history.getStatus();

    // TODO bugs.
    if ((status == AttemptStatus.SUCCEEDED
        || status == AttemptStatus.FAILED
        || status == AttemptStatus.KILLED)) {
      if (history.getReturnvalue() != null && history.getReturnvalue() == operation.getValue()) {
        return true;
      } else {
        return false;
      }
    } else {
      return false;
    }
  }
Esempio n. 2
0
  @Override
  protected void loadData() {
    /*
     * insert tasks
     */
    Task task1 = new Task();
    task1.setTaskid(TASKID1);
    task1.setName("test1");
    task1.setStatus(TaskStatus.RUNNING);
    task1.setAllowmultiinstances(1);
    taskMapper.insertSelective(task1);

    Task task2 = new Task();
    task2.setTaskid(TASKID2);
    task2.setName("test2");
    task2.setStatus(TaskStatus.RUNNING);
    task2.setAllowmultiinstances(2);
    taskMapper.insertSelective(task2);

    Task task3 = new Task();
    task3.setTaskid(TASKID3);
    task3.setName("test3");
    task3.setStatus(TaskStatus.RUNNING);
    task3.setAllowmultiinstances(3);
    taskMapper.insertSelective(task3);

    /*
     * insert attempt
     */
    TaskAttempt attempt1 = new TaskAttempt();
    attempt1.setTaskid(TASKID1);
    String instanceID1 = idFactory.newInstanceID(TASKID1);
    attempt1.setInstanceid(instanceID1);
    attempt1.setAttemptid(idFactory.newAttemptID(instanceID1));
    attempt1.setStatus(AttemptStatus.RUNNING);
    attemptMapper.insertSelective(attempt1);

    TaskAttempt attempt2 = new TaskAttempt();
    attempt2.setTaskid(TASKID2);
    String instanceID2 = idFactory.newInstanceID(TASKID2);
    attempt2.setInstanceid(instanceID2);
    attempt2.setAttemptid(idFactory.newAttemptID(instanceID2));
    attempt2.setStatus(AttemptStatus.RUNNING);
    attemptMapper.insertSelective(attempt2);

    TaskAttempt attempt3 = new TaskAttempt();
    attempt3.setTaskid(TASKID3);
    String instanceID3 = idFactory.newInstanceID(TASKID3);
    attempt3.setInstanceid(instanceID3);
    attempt3.setAttemptid(idFactory.newAttemptID(instanceID3));
    attempt3.setStatus(AttemptStatus.RUNNING);
    attemptMapper.insertSelective(attempt3);

    /*
     * Engine load task
     */
    engine.load();
    engine.setMaxConcurrency(5);

    /*
     * set next to null
     */
    filter1.setNext(null);

    /*
     * load attemptcontext
     */

    TaskAttempt attempt4 = new TaskAttempt();
    attempt4.setTaskid(TASKID3);
    String instanceID4 = idFactory.newInstanceID(TASKID3);
    attempt4.setInstanceid(instanceID4);
    attempt4.setAttemptid(idFactory.newAttemptID(instanceID4));
    attempt4.setStatus(AttemptStatus.DEPENDENCY_PASS);
    contexts.add(new AttemptContext(attempt4, task3));

    TaskAttempt attempt5 = new TaskAttempt();
    attempt5.setTaskid(TASKID3);
    String instanceID5 = idFactory.newInstanceID(TASKID3);
    attempt5.setInstanceid(instanceID5);
    attempt5.setAttemptid(idFactory.newAttemptID(instanceID5));
    attempt5.setStatus(AttemptStatus.DEPENDENCY_PASS);
    contexts.add(new AttemptContext(attempt5, task3));

    TaskAttempt attempt6 = new TaskAttempt();
    attempt6.setTaskid(TASKID3);
    String instanceID6 = idFactory.newInstanceID(TASKID3);
    attempt6.setInstanceid(instanceID6);
    attempt6.setAttemptid(idFactory.newAttemptID(instanceID6));
    attempt6.setStatus(AttemptStatus.DEPENDENCY_PASS);
    contexts.add(new AttemptContext(attempt6, task3));

    TaskAttempt attempt7 = new TaskAttempt();
    attempt7.setTaskid(TASKID1);
    String instanceID7 = idFactory.newInstanceID(TASKID1);
    attempt7.setInstanceid(instanceID7);
    attempt7.setAttemptid(idFactory.newAttemptID(instanceID7));
    attempt7.setStatus(AttemptStatus.DEPENDENCY_PASS);
    contexts.add(new AttemptContext(attempt7, task1));

    TaskAttempt attempt8 = new TaskAttempt();
    attempt8.setTaskid(TASKID2);
    String instanceID8 = idFactory.newInstanceID(TASKID2);
    attempt8.setInstanceid(instanceID8);
    attempt8.setAttemptid(idFactory.newAttemptID(instanceID8));
    attempt8.setStatus(AttemptStatus.DEPENDENCY_PASS);
    contexts.add(new AttemptContext(attempt8, task2));
  }