Search in sources :

Example 6 with TaskStatus

use of cz.metacentrum.perun.engine.scheduling.TaskStatus in project perun by CESNET.

the class TaskStatusManagerImpl method getTaskStatus.

@Override
public TaskStatus getTaskStatus(Task task) {
    TaskStatus taskStatus;
    synchronized (taskToStatusMap) {
        if (taskToStatusMap.containsKey(task.getId())) {
            taskStatus = taskToStatusMap.get(task.getId());
        } else {
            taskStatus = new TaskStatusImpl(task);
            taskToStatusMap.put(task.getId(), taskStatus);
        }
    }
    // TODO: persist created taskStatus in storage
    return taskStatus;
}
Also used : TaskStatus(cz.metacentrum.perun.engine.scheduling.TaskStatus)

Example 7 with TaskStatus

use of cz.metacentrum.perun.engine.scheduling.TaskStatus in project perun by CESNET.

the class TaskStatusManagerImpl method onTaskDestinationDone.

@Override
public void onTaskDestinationDone(Task task, Destination destination, TaskResult result) {
    if (result != null) {
        try {
            jmsQueueManager.reportFinishedDestination(task, destination, result);
        } catch (JMSException e) {
            log.error("Failed to report finished task " + task.toString() + ": " + e.getMessage());
        }
    }
    if (task.getExecService().getExecServiceType().equals(ExecServiceType.GENERATE)) {
        task.setEndTime(new Date(System.currentTimeMillis()));
        schedulingPool.setTaskStatus(task, cz.metacentrum.perun.taskslib.model.Task.TaskStatus.DONE);
    } else {
        TaskStatus taskStatus = this.getTaskStatus(task);
        try {
            taskStatus.setDestinationStatus(destination, TaskDestinationStatus.DONE);
            taskStatus.setDestinationResult(destination, result);
        } catch (InternalErrorException e) {
            log.error("Error setting DONE status for task " + task.toString() + ": " + e.getMessage());
        }
        if (taskStatus.isTaskFinished()) {
            task.setEndTime(new Date(System.currentTimeMillis()));
            schedulingPool.setTaskStatus(task, taskStatus.getTaskStatus());
        }
    }
    // report success on forced propagations immediately...
    if (task.isPropagationForced() && task.getStatus().equals(cz.metacentrum.perun.taskslib.model.Task.TaskStatus.DONE)) {
        log.debug("TASK " + task.toString() + " finished");
        try {
            log.debug("TASK reported as finished at " + System.currentTimeMillis());
            jmsQueueManager.reportFinishedTask(task, "Destinations []");
            schedulingPool.removeTask(task);
            log.debug("TASK {} removed from database.", task.getId());
        } catch (JMSException e) {
            log.error("Failed to report finished task " + task.toString() + ": " + e.getMessage());
        }
    }
}
Also used : JMSException(javax.jms.JMSException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) TaskStatus(cz.metacentrum.perun.engine.scheduling.TaskStatus) Date(java.util.Date)

Example 8 with TaskStatus

use of cz.metacentrum.perun.engine.scheduling.TaskStatus in project perun by CESNET.

the class TaskStatusImplTest method getTaskStatusTest.

@Test
public void getTaskStatusTest() throws InternalErrorException {
    System.out.println("TaskStatusImpl.getTaskStatusTest");
    TaskStatus taskStatus = new TaskStatusImpl(task1);
    Assert.isTrue(taskStatus.getTaskStatus().equals(Task.TaskStatus.PROCESSING));
    taskStatus.setDestinationStatus(destination1, TaskDestinationStatus.DONE);
    Assert.isTrue(taskStatus.getTaskStatus().equals(Task.TaskStatus.PROCESSING));
    taskStatus.setDestinationStatus(destination3, TaskDestinationStatus.ERROR);
    Assert.isTrue(taskStatus.getTaskStatus().equals(Task.TaskStatus.PROCESSING));
    taskStatus.setDestinationStatus(destination4, TaskDestinationStatus.DONE);
    Assert.isTrue(taskStatus.getTaskStatus().equals(Task.TaskStatus.PROCESSING));
    taskStatus.setDestinationStatus(destination2, TaskDestinationStatus.DONE);
    Assert.isTrue(taskStatus.getTaskStatus().equals(Task.TaskStatus.DONE));
    taskStatus = new TaskStatusImpl(task1);
    Assert.isTrue(taskStatus.getTaskStatus().equals(Task.TaskStatus.PROCESSING));
    taskStatus.setDestinationStatus(destination1, TaskDestinationStatus.DONE);
    Assert.isTrue(taskStatus.getTaskStatus().equals(Task.TaskStatus.PROCESSING));
    taskStatus.setDestinationStatus(destination3, TaskDestinationStatus.DONE);
    Assert.isTrue(taskStatus.getTaskStatus().equals(Task.TaskStatus.PROCESSING));
    taskStatus.setDestinationStatus(destination2, TaskDestinationStatus.ERROR);
    Assert.isTrue(taskStatus.getTaskStatus().equals(Task.TaskStatus.ERROR));
}
Also used : TaskStatusImpl(cz.metacentrum.perun.engine.scheduling.impl.TaskStatusImpl) TaskStatus(cz.metacentrum.perun.engine.scheduling.TaskStatus) Test(org.junit.Test) AbstractEngineTest(cz.metacentrum.perun.engine.AbstractEngineTest)

Example 9 with TaskStatus

use of cz.metacentrum.perun.engine.scheduling.TaskStatus in project perun by CESNET.

the class TaskStatusImplTest method setDestinationStatusTest.

@Test
public void setDestinationStatusTest() throws InternalErrorException {
    System.out.println("TaskStatusImpl.setDestinationStatusTest");
    TaskStatus taskStatus = new TaskStatusImpl(task1);
    taskStatus.setDestinationStatus(destination1, TaskDestinationStatus.DONE);
    Assert.isTrue(taskStatus.getDestinationStatus(destination1).equals(TaskDestinationStatus.DONE));
}
Also used : TaskStatusImpl(cz.metacentrum.perun.engine.scheduling.impl.TaskStatusImpl) TaskStatus(cz.metacentrum.perun.engine.scheduling.TaskStatus) Test(org.junit.Test) AbstractEngineTest(cz.metacentrum.perun.engine.AbstractEngineTest)

Example 10 with TaskStatus

use of cz.metacentrum.perun.engine.scheduling.TaskStatus in project perun by CESNET.

the class TaskStatusManagerImplTest method getTaskStatusTest.

@Test
public void getTaskStatusTest() {
    System.out.println("TaskStatusManagerImpl.getTaskStatusTest");
    TaskStatus taskStatus1 = taskStatusManager.getTaskStatus(task1);
    TaskStatus taskStatus2 = taskStatusManager.getTaskStatus(task1);
    Assert.isTrue(taskStatus1 == taskStatus2);
}
Also used : TaskStatus(cz.metacentrum.perun.engine.scheduling.TaskStatus) Test(org.junit.Test) AbstractEngineTest(cz.metacentrum.perun.engine.AbstractEngineTest)

Aggregations

TaskStatus (cz.metacentrum.perun.engine.scheduling.TaskStatus)10 AbstractEngineTest (cz.metacentrum.perun.engine.AbstractEngineTest)7 Test (org.junit.Test)7 TaskStatusImpl (cz.metacentrum.perun.engine.scheduling.impl.TaskStatusImpl)5 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)2 Date (java.util.Date)2 JMSException (javax.jms.JMSException)2 Destination (cz.metacentrum.perun.core.api.Destination)1