use of cz.metacentrum.perun.taskslib.model.ExecService in project perun by CESNET.
the class AbstractEngineTest method setup.
@Before
public void setup() throws Exception {
// determine engine ID
engineId = Integer.parseInt(propertiesBean.getProperty("engine.unique.id"));
// create session
sess = perun.getPerunSession(new PerunPrincipal("perunTests", ExtSourcesManager.EXTSOURCE_NAME_INTERNAL, ExtSourcesManager.EXTSOURCE_INTERNAL), new PerunClient());
// create expected core objects
facility = perun.getFacilitiesManagerBl().createFacility(sess, new Facility(0, "EngineTestFacility"));
service = perun.getServicesManagerBl().createService(sess, new Service(0, "test_service"));
destination1 = perun.getServicesManagerBl().addDestination(sess, service, facility, new Destination(0, "par_dest1", "host", "PARALLEL"));
destination2 = perun.getServicesManagerBl().addDestination(sess, service, facility, new Destination(0, "par_dest2", "host", "PARALLEL"));
destination3 = perun.getServicesManagerBl().addDestination(sess, service, facility, new Destination(0, "one_dest1", "host", "ONE"));
destination4 = perun.getServicesManagerBl().addDestination(sess, service, facility, new Destination(0, "one_dest2", "host", "ONE"));
execService1 = new ExecService();
execService1.setService(service);
execService1.setExecServiceType(ExecService.ExecServiceType.SEND);
execService1.setEnabled(true);
execService1.setDefaultDelay(1);
// this command always return true
execService1.setScript("/bin/true");
execService1.setId(controller.insertExecService(sess, execService1));
execService2 = new ExecService();
execService2.setService(service);
execService2.setExecServiceType(ExecService.ExecServiceType.SEND);
execService2.setEnabled(true);
execService2.setDefaultDelay(1);
// this command always return true
execService2.setScript("/bin/true");
execService2.setId(controller.insertExecService(sess, execService2));
execService_gen = new ExecService();
execService_gen.setService(service);
execService_gen.setExecServiceType(ExecService.ExecServiceType.GENERATE);
execService_gen.setEnabled(true);
execService_gen.setDefaultDelay(1);
// this command always return true
execService_gen.setScript("/bin/true");
execService_gen.setId(controller.insertExecService(sess, execService_gen));
List<Destination> destinations = new ArrayList<Destination>() {
{
add(destination1);
add(destination2);
add(destination3);
add(destination4);
}
};
// create Tasks in shared perun-core DB (as if action was initiated by dispatcher).
task1 = new Task();
task1.setDestinations(destinations);
task1.setFacility(facility);
task1.setExecService(execService1);
task1.setSchedule(new Date());
task1.setStatus(Task.TaskStatus.NONE);
task1.setId(taskDaoCore.scheduleNewTask(task1, engineId));
task2 = new Task();
task2.setDestinations(destinations);
task2.setFacility(facility);
task2.setExecService(execService2);
task2.setSchedule(new Date());
task2.setStatus(Task.TaskStatus.NONE);
task2.setId(taskDaoCore.scheduleNewTask(task2, engineId));
task_gen = new Task();
task_gen.setDestinations(destinations);
task_gen.setFacility(facility);
task_gen.setExecService(execService_gen);
task_gen.setSchedule(new Date());
task_gen.setStatus(Task.TaskStatus.NONE);
task_gen.setId(taskDaoCore.scheduleNewTask(task_gen, engineId));
}
use of cz.metacentrum.perun.taskslib.model.ExecService in project perun by CESNET.
the class PropagationMaintainerImpl method setAllGenerateDependenciesToNone.
/*
* @Override public Statistics getStatistics() { throw new
* UnsupportedOperationException("Nah..."); }
*/
private void setAllGenerateDependenciesToNone(Task task) {
List<ExecService> dependencies = this.dependenciesResolver.listDependencies(task.getExecService());
for (ExecService dependencyToBeSetDirty : dependencies) {
if (dependencyToBeSetDirty.getExecServiceType().equals(ExecServiceType.GENERATE)) {
Task taskToBeSetDirty = schedulingPool.getTask(dependencyToBeSetDirty, task.getFacility());
if (taskToBeSetDirty != null) {
log.debug("Setting GEN dependency task {} to NONE state to regenerate data for completed task {}", taskToBeSetDirty, task);
schedulingPool.setTaskStatus(taskToBeSetDirty, TaskStatus.NONE);
try {
schedulingPool.setQueueForTask(taskToBeSetDirty, null);
} catch (InternalErrorException e) {
log.error("Could not set destination queue for task {}: {}", task.getId(), e.getMessage());
}
}
}
}
}
use of cz.metacentrum.perun.taskslib.model.ExecService in project perun by CESNET.
the class PropagationMaintainerImpl method rescheduleErrorTasks.
private void rescheduleErrorTasks() {
log.info("I am gonna list tasks in ERROR and reschedule if necessary...");
for (Task task : schedulingPool.getErrorTasks()) {
if (task.getEndTime() == null) {
log.error("RECOVERY FROM INCONSISTENT STATE: ERROR task does not have end_time! Setting end_time to task.getDelay + 1.");
// getDelay is in minutes, therefore we multiply it with 60*1000
Date endTime = new Date(System.currentTimeMillis() - ((task.getDelay() + 1) * 60000));
task.setEndTime(endTime);
}
int howManyMinutesAgo = (int) (System.currentTimeMillis() - task.getEndTime().getTime()) / 1000 / 60;
if (howManyMinutesAgo < 0) {
log.error("RECOVERY FROM INCONSISTENT STATE: ERROR task appears to have ended in future.");
Date endTime = new Date(System.currentTimeMillis() - ((task.getDelay() + 1) * 60000));
task.setEndTime(endTime);
howManyMinutesAgo = task.getDelay() + 1;
}
log.info("TASK [" + task + "] in ERROR state completed " + howManyMinutesAgo + " minutes ago.");
// XXX - apparently this is not what the authors had in mind,
// commented out
// check and set recurrence
// int recurrence = task.getRecurrence() - 1;
// if(recurrence < 0) {
// // no more retries, sorry
// log.info("TASK [ " + task +
// "] in ERROR state has no more retries, bailing out.");
// continue;
// }
// task.setRecurrence(recurrence);
// If DELAY time has passed, we reschedule...
int recurrence = task.getRecurrence() + 1;
if (recurrence > task.getExecService().getDefaultRecurrence() && howManyMinutesAgo < 60 * 12 && !task.isSourceUpdated()) {
log.info("TASK [ " + task + "] in ERROR state has no more retries, bailing out.");
} else if (howManyMinutesAgo >= recurrence * task.getDelay() || task.isSourceUpdated()) {
// check if service is still assigned on facility
try {
List<Service> assignedServices = perun.getServicesManager().getAssignedServices(perunSession, task.getFacility());
if (assignedServices.contains(task.getExecService().getService())) {
ExecService execService = task.getExecService();
Facility facility = task.getFacility();
if (recurrence > execService.getDefaultRecurrence()) {
// this ERROR task is rescheduled for being here too long
task.setRecurrence(0);
task.setDestinations(null);
log.info("TASK id " + task.getId() + " is in ERROR state long enough, ");
}
task.setRecurrence(recurrence);
log.info("TASK [" + task + "] in ERROR state is going to be rescheduled: taskScheduler.propagateService(execService:ID " + execService.getId() + ", new Date(System.currentTimeMillis()), facility:ID " + facility.getId() + ");");
// taskScheduler.propagateService(task, new
// Date(System.currentTimeMillis()));
taskScheduler.scheduleTask(task);
log.info("TASK [" + task + "] in ERROR state has been rescheduled.");
// Also (to be sure) reschedule all Tasks that depend on
// this Task
//
// While engine starts in state GEN = ERROR, SEND = DONE
// => GEN will be rescheduled but without this SEND will
// never be propagated
List<ExecService> dependantServices = dependenciesResolver.listDependantServices(execService);
for (ExecService dependantService : dependantServices) {
Task dependantTask = schedulingPool.getTask(dependantService, facility);
if (dependantTask == null) {
dependantTask = new Task();
dependantTask.setExecService(dependantService);
dependantTask.setFacility(facility);
dependantTask.setRecurrence(dependantService.getDefaultRecurrence());
schedulingPool.addToPool(dependantTask, schedulingPool.getQueueForTask(task));
taskScheduler.scheduleTask(dependantTask);
log.info("{} was rescheduled because it depends on {}", dependantTask, task);
}
}
} else {
// delete this tasks (SEND and GEN) because service is
// no longer assigned to facility
schedulingPool.removeTask(task);
log.warn("Removed TASK {} from database, beacuse service is no longer assigned to this facility.", task.toString());
}
} catch (FacilityNotExistsException e) {
schedulingPool.removeTask(task);
log.error("Removed TASK {} from database, facility no longer exists.", task.getId());
} catch (InternalErrorException e) {
log.error("{}", e);
} catch (PrivilegeException e) {
log.error("Consistency error. {}", e);
}
}
}
/*
* Original implementation:
*
* //TODO: Take into account Recurrence! for (Task task :
* taskManager.listAllTasksInState(TaskStatus.ERROR,
* Integer.parseInt(propertiesBean.getProperty("engine.unique.id")))) {
* if (task.getEndTime() == null) { log.error(
* "RECOVERY FROM INCONSISTATE STATE: ERROR task does not have end_time! Setting end_time to task.getDelay + 1."
* ); // getDelay is in minutes, therefore we multiply it with 60*1000
* Date endTime = new Date(System.currentTimeMillis() -
* ((task.getDelay() + 1) * 60000)); task.setEndTime(endTime);
* taskManager.updateTask(task,
* Integer.parseInt(propertiesBean.getProperty("engine.unique.id"))); }
* int howManyMinutesAgo = (int) (System.currentTimeMillis() -
* task.getEndTime().getTime()) / 1000 / 60; log.info("TASK [" + task +
* "] in ERROR state completed " + howManyMinutesAgo + " minutes ago.");
* //If DELAY time has passed, we reschedule... if (howManyMinutesAgo >=
* task.getDelay()) { //check if service is still assigned on facility
* try { List<Service> assignedServices =
* Rpc.ServicesManager.getAssignedServices(engineManager.getRpcCaller(),
* task.getFacility());
* if(assignedServices.contains(task.getExecService().getService())) {
* try { taskManager.updateTask(task,
* Integer.parseInt(propertiesBean.getProperty("engine.unique.id")));
* ExecService execService = task.getExecService(); Facility facility =
* task.getFacility(); log.info("TASK [" + task +
* "] in ERROR state is going to be rescheduled: taskScheduler.propagateService(execService:ID "
* + execService.getId() +
* ", new Date(System.currentTimeMillis()), facility:ID " +
* facility.getId() + ");"); taskScheduler.propagateService(execService,
* new Date(System.currentTimeMillis()), facility); log.info("TASK [" +
* task + "] in ERROR state has been rescheduled.");
*
* //Also (to be sure) reschedule all execServices which depends on this
* exec service // //While engine starts in state GEN = ERROR, SEND =
* DONE => GEN will be rescheduled but without this SEND will never be
* propagated List<ExecService> dependentExecServices =
* Rpc.GeneralServiceManager
* .listExecServicesDependingOn(engineManager.getRpcCaller(),
* execService); if(dependentExecServices != null) { for(ExecService
* dependantExecService : dependentExecServices) {
* taskScheduler.propagateService(dependantExecService, new
* Date(System.currentTimeMillis()), facility);
* log.info("{} was rescheduled because it depends on {}",
* dependantExecService, execService); } }
*
* } catch (InternalErrorException e) { log.error(e.toString(), e); } }
* else { //delete this tasks (SEND and GEN) because service is no
* longer assigned to facility List<ExecService> execServicesGenAndSend
* =
* Rpc.GeneralServiceManager.listExecServices(engineManager.getRpcCaller
* (), task.getExecService().getService().getId()); for(ExecService
* execService : execServicesGenAndSend) { Task taskToDelete =
* taskManager.getTask(execService, task.getFacility(),
* Integer.parseInt(propertiesBean.getProperty("engine.unique.id")));
* if(taskToDelete!= null) {
* resultManager.clearByTask(taskToDelete.getId(),
* Integer.parseInt(propertiesBean.getProperty("engine.unique.id")));
* taskManager.removeTask(taskToDelete.getId(),
* Integer.parseInt(propertiesBean.getProperty("engine.unique.id"))); }
* } } } catch(PrivilegeException ex) {
* log.error("Consistency error. {}", ex); }
* catch(FacilityNotExistsException ex) {
* log.error("Consistency error - found task for non-existing facility. {}"
* , ex); } catch(ServiceNotExistsException ex) {
* log.error("Consistency error - found task for non-existing service. {}"
* , ex); } catch(InternalErrorException ex) { log.error("{}", ex); } }
* }
*/
}
use of cz.metacentrum.perun.taskslib.model.ExecService in project perun by CESNET.
the class AbstractDispatcherTest method setUpSess.
@Before
public void setUpSess() throws Exception {
if (sess == null) {
PerunPrincipal pp = new PerunPrincipal("perunTests", ExtSourcesManager.EXTSOURCE_NAME_INTERNAL, ExtSourcesManager.EXTSOURCE_INTERNAL);
sess = perun.getPerunSession(pp, new PerunClient());
// create VO for tests
vo1 = new Vo(0, "testVo", "testVo");
vo1 = perun.getVosManager().createVo(sess, vo1);
// create some group in there
group1 = new Group("falcon", "desc");
group1 = perun.getGroupsManager().createGroup(sess, vo1, group1);
// create user in the VO
// skip the xEntry (authorization check),
// could skip the xBl a go directly to xImpl to avoid writing audit
// log
user1 = new User(0, "firstName", "lastName", "", "", "");
user1 = perun.getUsersManagerBl().createUser(sess, user1);
// make the user the member of the group
member1 = perun.getMembersManager().createMember(sess, vo1, user1);
member1.setStatus("VALID");
perun.getGroupsManager().addMember(sess, group1, member1);
// now create some facility
facility1 = new Facility(0, "testFacility", "desc");
facility1 = perun.getFacilitiesManager().createFacility(sess, facility1);
// create a resource
resource1 = new Resource(0, "testResource", "test resource", facility1.getId(), vo1.getId());
resource1 = perun.getResourcesManager().createResource(sess, resource1, vo1, facility1);
// assign the group to this resource
perun.getResourcesManager().assignGroupToResource(sess, group1, resource1);
// create service
service1 = new Service(0, "testService");
service1 = perun.getServicesManager().createService(sess, service1);
// assign service to the resource
perun.getResourcesManager().assignService(sess, resource1, service1);
// create execService
execservice1 = new ExecService();
execservice1.setDefaultDelay(1);
execservice1.setScript("/bin/true");
execservice1.setEnabled(true);
execservice1.setExecServiceType(ExecService.ExecServiceType.SEND);
execservice1.setService(service1);
int id = generalServiceManager.insertExecService(sess, execservice1);
// stash back the created id (this should be really done somewhere else)
execservice1.setId(id);
// create execService
execservice2 = new ExecService();
execservice2.setDefaultDelay(1);
execservice2.setScript("/bin/true");
execservice2.setEnabled(true);
execservice2.setExecServiceType(ExecService.ExecServiceType.SEND);
execservice2.setService(service1);
id = generalServiceManager.insertExecService(sess, execservice2);
// stash back the created id (this should be really done somewhere else)
execservice2.setId(id);
}
}
use of cz.metacentrum.perun.taskslib.model.ExecService in project perun by CESNET.
the class EventExecServiceResolverTest method parseEventTest.
@Test
public void parseEventTest() throws ServiceNotExistsException, InvalidEventMessageException, InternalErrorException, PrivilegeException {
System.out.println("EventExecServiceResolver.parseEventTest()");
String message = member1.serializeToString() + " added to " + group1.serializeToString() + ".";
Event event = new Event();
event.setTimeStamp(System.currentTimeMillis());
event.setHeader("portishead");
event.setData(message);
Map<Facility, Set<ExecService>> resolvedServices = eventExecServiceResolver.parseEvent(event.toString());
Assert.assertTrue("We should resolved only one facility-service", resolvedServices.size() == 1);
Set<ExecService> resolved = resolvedServices.get(facility1);
Assert.assertTrue("We should have 2 exec services", resolved.size() == 2);
Assert.assertTrue("Our exec service 1 is missing", resolved.contains(execservice1));
Assert.assertTrue("Our exec service 2 is missing", resolved.contains(execservice2));
}
Aggregations