use of cz.metacentrum.perun.dispatcher.jms.DispatcherQueue in project perun by CESNET.
the class SchedulingPoolImpl method checkTasksDb.
@Override
public void checkTasksDb() {
log.debug("Going to cross-check tasks in database...");
for (Pair<Task, Integer> pair : taskManager.listAllTasksAndClients()) {
Task task = pair.getLeft();
DispatcherQueue taskQueue = dispatcherQueuePool.getDispatcherQueueByClient(pair.getRight());
TaskStatus status = task.getStatus();
if (status == null) {
task.setStatus(TaskStatus.NONE);
}
Task local_task = null;
TaskStatus local_status = null;
log.debug(" checking task " + task.toString());
if (taskQueue == null) {
log.warn(" there is no task queue for client " + pair.getRight());
// continue;
}
synchronized (tasksById) {
Pair<Task, DispatcherQueue> local_pair = tasksById.get(task.getId());
if (local_pair != null) {
local_task = local_pair.getLeft();
}
if (local_task == null) {
local_task = tasksByServiceAndFacility.get(new Pair<Integer, Integer>(task.getExecServiceId(), task.getFacilityId()));
}
if (local_task == null) {
for (TaskStatus sts : TaskStatus.class.getEnumConstants()) {
List<Task> tasklist = pool.get(sts);
if (tasklist != null) {
local_task = tasklist.get(task.getId());
}
if (local_task != null) {
local_status = sts;
break;
}
}
}
}
if (local_task == null) {
try {
log.debug(" task not found in any of local structures, adding fresh");
addToPool(task, taskQueue);
} catch (InternalErrorException e) {
log.error("Error adding task to the local structures: " + e.getMessage());
}
} else {
synchronized (tasksById) {
if (!tasksById.containsKey(local_task.getId())) {
log.debug(" task not known by id, adding");
tasksById.put(local_task.getId(), new Pair<Task, DispatcherQueue>(local_task, taskQueue));
}
if (!tasksByServiceAndFacility.containsKey(new Pair<Integer, Integer>(local_task.getExecServiceId(), local_task.getFacilityId()))) {
log.debug(" task not known by ExecService and Facility, adding");
tasksByServiceAndFacility.put(new Pair<Integer, Integer>(local_task.getExecServiceId(), local_task.getFacilityId()), task);
}
if (local_status != null && local_status != local_task.getStatus()) {
log.debug(" task listed with wrong status, removing");
if (pool.get(local_status) != null) {
pool.get(local_status).remove(local_task.getId());
} else {
log.error(" no task list for status " + local_status);
}
}
if (pool.get(local_task.getStatus()) != null && !pool.get(local_task.getStatus()).contains(local_task)) {
log.debug(" task not listed with its status, adding");
pool.get(local_task.getStatus()).add(local_task);
}
}
}
}
}
use of cz.metacentrum.perun.dispatcher.jms.DispatcherQueue in project perun by CESNET.
the class TaskSchedulerImpl method sendToEngine.
private void sendToEngine(Task task) {
DispatcherQueue dispatcherQueue;
try {
dispatcherQueue = schedulingPool.getQueueForTask(task);
} catch (InternalErrorException e1) {
log.error("No engine set for task " + task.toString() + ", could not send it!");
return;
}
if (dispatcherQueue == null) {
// where should we send the task?
if (dispatcherQueuePool.poolSize() > 0) {
dispatcherQueue = dispatcherQueuePool.getPool().iterator().next();
try {
schedulingPool.setQueueForTask(task, dispatcherQueue);
} catch (InternalErrorException e) {
log.error("Could not assign new queue for task {}: {}", task.getId(), e);
return;
}
log.debug("Assigned new queue " + dispatcherQueue.getQueueName() + " to task " + task.getId());
} else {
// bad luck...
log.error("Task " + task.toString() + " has no engine assigned and there are no engines registered...");
return;
}
}
// task|[engine_id]|[task_id][is_forced][exec_service_id][facility]|[destination_list]|[dependency_list]
// - the task|[engine_id] part is added by dispatcherQueue
List<Destination> destinations = task.getDestinations();
if (destinations == null || destinations.isEmpty()) {
log.debug("No destinations for task " + task.toString() + ", trying to query the database...");
try {
initPerunSession();
destinations = perun.getServicesManager().getDestinations(perunSession, task.getExecService().getService(), task.getFacility());
} catch (ServiceNotExistsException e) {
log.error("No destinations found for task " + task.getId());
task.setEndTime(new Date(System.currentTimeMillis()));
schedulingPool.setTaskStatus(task, TaskStatus.ERROR);
return;
} catch (FacilityNotExistsException e) {
log.error("Facility for task {} does not exist...", task.getId());
task.setEndTime(new Date(System.currentTimeMillis()));
schedulingPool.setTaskStatus(task, TaskStatus.ERROR);
return;
} catch (PrivilegeException e) {
log.error("Privilege error accessing the database: " + e.getMessage());
task.setEndTime(new Date(System.currentTimeMillis()));
schedulingPool.setTaskStatus(task, TaskStatus.ERROR);
return;
} catch (InternalErrorException e) {
log.error("Internal error: " + e.getMessage());
task.setEndTime(new Date(System.currentTimeMillis()));
schedulingPool.setTaskStatus(task, TaskStatus.ERROR);
return;
}
}
log.debug("Fetched destinations: " + ((destinations == null) ? "[]" : destinations.toString()));
task.setDestinations(destinations);
StringBuilder destinations_s = new StringBuilder("Destinations [");
if (destinations != null) {
for (Destination destination : destinations) {
destinations_s.append(destination.serializeToString() + ", ");
}
}
destinations_s.append("]");
String dependencies = "";
dispatcherQueue.sendMessage("[" + task.getId() + "][" + task.isPropagationForced() + "]|[" + fixStringSeparators(task.getExecService().serializeToString()) + "]|[" + fixStringSeparators(task.getFacility().serializeToString()) + "]|[" + fixStringSeparators(destinations_s.toString()) + "]|[" + dependencies + "]");
task.setStartTime(new Date(System.currentTimeMillis()));
task.setEndTime(null);
schedulingPool.setTaskStatus(task, TaskStatus.PROCESSING);
}
use of cz.metacentrum.perun.dispatcher.jms.DispatcherQueue in project perun by CESNET.
the class DispatcherManagerImpl method cleanOldTaskResults.
/*
* public PerunSession getPerunSession() { if (this.dispatcherSession ==
* null) { try { String perunPrincipal =
* propertiesBean.getProperty("perun.principal.name"); String extSourceName
* = propertiesBean.getProperty("perun.principal.extSourceName"); String
* extSourceType =
* propertiesBean.getProperty("perun.principal.extSourceType");
* PerunPrincipal pp = new PerunPrincipal(perunPrincipal, extSourceName,
* extSourceType); this.dispatcherSession = perun.getPerunSession(pp); }
* catch (InternalErrorException e) { log.error(e.toString()); } } return
* this.dispatcherSession; }
*/
@Override
public void cleanOldTaskResults() {
for (DispatcherQueue queue : dispatcherQueuePool.getPool()) {
try {
int numRows = resultManager.clearOld(queue.getClientID(), 3);
log.debug("Cleaned {} old task results for engine {}", numRows, queue.getClientID());
} catch (Throwable e) {
log.error("Error cleaning old task results for engine {} : {}", queue.getClientID(), e);
}
}
}
use of cz.metacentrum.perun.dispatcher.jms.DispatcherQueue in project perun by CESNET.
the class SchedulingPoolTest method setup.
@Before
public void setup() throws InternalErrorException {
task1 = new Task();
task1.setId(1);
task1.setExecService(execservice1);
task1.setFacility(facility1);
task1.setDestinations(destinations);
task1.setStatus(TaskStatus.NONE);
task1.setSchedule(new Date(System.currentTimeMillis()));
dispatcherQueue = new DispatcherQueue(1, "test-queue");
schedulingPool.addToPool(task1, dispatcherQueue);
}
use of cz.metacentrum.perun.dispatcher.jms.DispatcherQueue in project perun by CESNET.
the class EventProcessorTest method eventProcessorTest.
@Test(timeout = 10000)
public void eventProcessorTest() {
System.out.println("EventProcessor.eventProcessorTest()");
DispatcherQueue dispatcherQueue = new DispatcherQueueMock(1, "testQueue");
eventProcessor.getDispatcherQueuePool().addDispatcherQueue(dispatcherQueue);
eventProcessor.setEventQueue(new EventQueueMock());
eventProcessor.setSchedulingPool(new SchedulingPoolMock());
evProcessor = eventProcessor.new EvProcessor();
// runs inside this thread, should end when message is delivered
// this necessitates the use of test timeout
evProcessor.run();
log.debug("CreatedTask: " + createdTask);
Assert.isTrue(execservice2.equals(createdTask.getExecService()), "task execService is different");
Assert.isTrue(facility1.equals(createdTask.getFacility()), "task Facility is different");
Assert.isTrue(createdTask.getStatus().equals(TaskStatus.NONE));
}
Aggregations