use of cz.metacentrum.perun.taskslib.model.ExecService in project perun by CESNET.
the class ExecServiceDependencyDaoTest method testListExecServicesThisExecServiceDependsOn.
@Test
public void testListExecServicesThisExecServiceDependsOn() {
System.out.println("ExecServiceDependencyDao.listExecServicesThisExecServiceDependsOn");
try {
log.debug("testListExecServicesThisExecServiceDependsOn: Testing...");
execServiceDependencyDao.createDependency(testExecService2.getId(), testExecService1.getId());
execServiceDependencyDao.createDependency(testExecService2.getId(), testExecService3.getId());
List<ExecService> execServices = execServiceDependencyDao.listExecServicesThisExecServiceDependsOn(testExecService2.getId());
assertNotNull(execServices);
for (ExecService execService : execServices) {
log.debug("\tID:" + execService.getId());
log.debug("\tDefDELAY:" + execService.getDefaultDelay());
log.debug("\tDefRecurrence:" + execService.getDefaultRecurrence());
log.debug("\tENABLED:" + execService.isEnabled());
log.debug("\tService:" + execService.getService().getName());
log.debug("\tSCRIPT:" + execService.getScript());
log.debug("\tTYPE:" + execService.getExecServiceType().toString());
}
assertEquals(execServices.size(), 2);
assertEquals(execServiceDependencyDao.listExecServicesThisExecServiceDependsOn(testExecService1.getId()).size(), 0);
assertEquals(execServiceDependencyDao.listExecServicesThisExecServiceDependsOn(testExecService3.getId()).size(), 0);
} catch (Exception e) {
log.error(e.getMessage(), e);
fail();
}
}
use of cz.metacentrum.perun.taskslib.model.ExecService in project perun by CESNET.
the class ExecServiceDependencyDaoTest method testListExecServicesThisExecServiceDependsOnWithType.
@Test
public void testListExecServicesThisExecServiceDependsOnWithType() {
System.out.println("ExecServiceDependencyDao.listExecServicesThisExecServiceDependsOnWithType");
try {
log.debug("testListExecServicesThisExecServiceDependsOn: Testing...");
//Depends on GENERATE
execServiceDependencyDao.createDependency(testExecService2.getId(), testExecService1.getId());
//Depends on SEND
execServiceDependencyDao.createDependency(testExecService2.getId(), testExecService3.getId());
List<ExecService> execServices = execServiceDependencyDao.listExecServicesThisExecServiceDependsOn(testExecService2.getId(), ExecServiceType.GENERATE);
assertNotNull(execServices);
for (ExecService execService : execServices) {
log.debug("\tID:" + execService.getId());
log.debug("\tDefDELAY:" + execService.getDefaultDelay());
log.debug("\tDefRecurrence:" + execService.getDefaultRecurrence());
log.debug("\tENABLED:" + execService.isEnabled());
log.debug("\tService:" + execService.getService().getName());
log.debug("\tSCRIPT:" + execService.getScript());
log.debug("\tTYPE:" + execService.getExecServiceType().toString());
}
//There are 2 dependencies, but only one of them is of type GENERATE...
assertEquals(execServices.size(), 1);
execServices = execServiceDependencyDao.listExecServicesThisExecServiceDependsOn(testExecService2.getId(), ExecServiceType.SEND);
assertNotNull(execServices);
for (ExecService execService : execServices) {
log.debug("\tID:" + execService.getId());
log.debug("\tDefDELAY:" + execService.getDefaultDelay());
log.debug("\tDefRecurrence:" + execService.getDefaultRecurrence());
log.debug("\tENABLED:" + execService.isEnabled());
log.debug("\tService:" + execService.getService().getName());
log.debug("\tSCRIPT:" + execService.getScript());
log.debug("\tTYPE:" + execService.getExecServiceType().toString());
}
//There are 2 dependencies, but only one of them is of type SEND...
assertEquals(execServices.size(), 1);
//These should be 0
assertEquals(execServiceDependencyDao.listExecServicesThisExecServiceDependsOn(testExecService1.getId(), ExecServiceType.SEND).size(), 0);
assertEquals(execServiceDependencyDao.listExecServicesThisExecServiceDependsOn(testExecService1.getId(), ExecServiceType.GENERATE).size(), 0);
assertEquals(execServiceDependencyDao.listExecServicesThisExecServiceDependsOn(testExecService3.getId(), ExecServiceType.SEND).size(), 0);
assertEquals(execServiceDependencyDao.listExecServicesThisExecServiceDependsOn(testExecService3.getId(), ExecServiceType.GENERATE).size(), 0);
} catch (Exception e) {
log.error(e.getMessage(), e);
fail();
}
}
use of cz.metacentrum.perun.taskslib.model.ExecService in project perun by CESNET.
the class TaskResultDaoTest method testClearOldTaskResult.
@Test
public void testClearOldTaskResult() throws InternalErrorException, PrivilegeException, ServiceExistsException, OwnerNotExistsException, FacilityExistsException, ServiceNotExistsException, FacilityNotExistsException, DestinationAlreadyAssignedException, WrongPatternException {
System.out.println("TaskResultDao.clearOld");
Owner testOwner = new Owner();
testOwner.setContact("Call me");
testOwner.setName("Tester-" + Long.toHexString(System.currentTimeMillis()));
testOwner.setType(OwnerType.technical);
testOwner = ownersManager.createOwner(perunSession, testOwner);
Service testService = new Service();
testService.setName("Test_service_1_" + Long.toHexString(System.currentTimeMillis()));
testService = servicesManager.createService(perunSession, testService);
Service testService2 = new Service();
testService2.setName("Test_service_2_" + Long.toHexString(System.currentTimeMillis()));
testService2 = servicesManager.createService(perunSession, testService2);
Facility facility = new Facility();
facility.setName("Facility 1-" + Long.toHexString(System.currentTimeMillis()));
facility.setDescription("Description");
facility = facilitiesManager.createFacility(perunSession, facility);
Facility facility2 = new Facility();
facility2.setName("Facility 2-" + Long.toHexString(System.currentTimeMillis()));
facility2.setDescription("Description");
facility2 = facilitiesManager.createFacility(perunSession, facility2);
ExecService testExecService = new ExecService();
testExecService.setDefaultDelay(1);
testExecService.setDefaultRecurrence(1);
testExecService.setEnabled(true);
testExecService.setService(testService);
testExecService.setScript("serviceGenerate.bash");
testExecService.setExecServiceType(ExecService.ExecServiceType.GENERATE);
testExecService.setId(execServiceDao.insertExecService(testExecService));
ExecService testExecService2 = new ExecService();
testExecService2.setDefaultDelay(1);
testExecService2.setDefaultRecurrence(1);
testExecService2.setEnabled(true);
testExecService2.setService(testService2);
testExecService2.setScript("serviceGenerate.bash");
testExecService2.setExecServiceType(ExecService.ExecServiceType.GENERATE);
testExecService2.setId(execServiceDao.insertExecService(testExecService2));
Destination destination1 = new Destination();
destination1.setDestination("Destination-1-" + Long.toHexString(System.currentTimeMillis()));
destination1.setType(Destination.DESTINATIONEMAILTYPE);
destination1 = servicesManager.addDestination(perunSession, testService, facility, destination1);
Destination destination2 = new Destination();
destination2.setDestination("Destination-2-" + Long.toHexString(System.currentTimeMillis()));
destination2.setType(Destination.DESTINATIONEMAILTYPE);
destination2 = servicesManager.addDestination(perunSession, testService, facility, destination2);
Destination destination3 = new Destination();
destination3.setDestination("Destination-3-" + Long.toHexString(System.currentTimeMillis()));
destination3.setType(Destination.DESTINATIONEMAILTYPE);
destination3 = servicesManager.addDestination(perunSession, testService2, facility2, destination3);
Task testTask1 = new Task();
testTask1.setDelay(10);
testTask1.setExecService(testExecService);
testTask1.setFacility(facility);
testTask1.setRecurrence(10);
testTask1.setSchedule(new Date());
testTask1.setStatus(Task.TaskStatus.PROCESSING);
testTask1.setId(taskDao.scheduleNewTask(testTask1, virtualEngineID));
Task testTask2 = new Task();
testTask2.setDelay(10);
testTask2.setExecService(testExecService2);
testTask2.setFacility(facility2);
testTask2.setRecurrence(10);
testTask2.setSchedule(new Date());
testTask2.setStatus(Task.TaskStatus.PROCESSING);
testTask2.setId(taskDao.scheduleNewTask(testTask2, virtualEngineID));
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -2);
TaskResult taskResult = new TaskResult();
taskResult.setDestinationId(destination1.getId());
taskResult.setErrorMessage("error message");
taskResult.setReturnCode(0);
taskResult.setStandardMessage("std message");
taskResult.setStatus(TaskResult.TaskResultStatus.DONE);
taskResult.setTaskId(testTask1.getId());
taskResult.setTimestamp(cal.getTime());
taskResult.setService(testService);
taskResult.setId(taskResultDao.insertNewTaskResult(taskResult, virtualEngineID));
TaskResult taskResult2 = new TaskResult();
taskResult2.setDestinationId(destination3.getId());
taskResult2.setErrorMessage("error message");
taskResult2.setReturnCode(0);
taskResult2.setStandardMessage("std message");
taskResult2.setStatus(TaskResult.TaskResultStatus.DONE);
taskResult2.setTaskId(testTask2.getId());
taskResult2.setTimestamp(cal.getTime());
taskResult2.setService(testService2);
taskResult2.setId(taskResultDao.insertNewTaskResult(taskResult2, virtualEngineID));
cal.add(Calendar.DATE, -5);
TaskResult oldTaskResult = new TaskResult();
oldTaskResult.setDestinationId(destination1.getId());
oldTaskResult.setErrorMessage("error message");
oldTaskResult.setReturnCode(0);
oldTaskResult.setStandardMessage("std message");
oldTaskResult.setStatus(TaskResult.TaskResultStatus.DONE);
oldTaskResult.setTaskId(testTask1.getId());
oldTaskResult.setTimestamp(cal.getTime());
oldTaskResult.setService(testService);
oldTaskResult.setId(taskResultDao.insertNewTaskResult(oldTaskResult, virtualEngineID));
TaskResult oldTaskResult2 = new TaskResult();
oldTaskResult2.setDestinationId(destination3.getId());
oldTaskResult2.setErrorMessage("error message");
oldTaskResult2.setReturnCode(0);
oldTaskResult2.setStandardMessage("std message");
oldTaskResult2.setStatus(TaskResult.TaskResultStatus.DONE);
oldTaskResult2.setTaskId(testTask2.getId());
oldTaskResult2.setTimestamp(cal.getTime());
oldTaskResult2.setService(testService2);
oldTaskResult2.setId(taskResultDao.insertNewTaskResult(oldTaskResult2, virtualEngineID));
TaskResult uniqueTaskResult = new TaskResult();
uniqueTaskResult.setDestinationId(destination2.getId());
uniqueTaskResult.setErrorMessage("error message");
uniqueTaskResult.setReturnCode(0);
uniqueTaskResult.setStandardMessage("std message");
uniqueTaskResult.setStatus(TaskResult.TaskResultStatus.DONE);
uniqueTaskResult.setTaskId(testTask1.getId());
uniqueTaskResult.setTimestamp(cal.getTime());
uniqueTaskResult.setService(testService);
uniqueTaskResult.setId(taskResultDao.insertNewTaskResult(uniqueTaskResult, virtualEngineID));
TaskResult uniqueTaskResult2 = new TaskResult();
uniqueTaskResult2.setDestinationId(destination2.getId());
uniqueTaskResult2.setErrorMessage("error message");
uniqueTaskResult2.setReturnCode(0);
uniqueTaskResult2.setStandardMessage("std message");
uniqueTaskResult2.setStatus(TaskResult.TaskResultStatus.DONE);
uniqueTaskResult2.setTaskId(testTask2.getId());
uniqueTaskResult2.setTimestamp(cal.getTime());
uniqueTaskResult2.setService(testService2);
uniqueTaskResult2.setId(taskResultDao.insertNewTaskResult(uniqueTaskResult2, virtualEngineID));
TaskResult foundTaskResult1 = taskResultDao.getTaskResultById(taskResult.getId());
TaskResult foundTaskResult2 = taskResultDao.getTaskResultById(oldTaskResult.getId());
TaskResult foundTaskResult3 = taskResultDao.getTaskResultById(uniqueTaskResult.getId());
TaskResult foundTaskResult4 = taskResultDao.getTaskResultById(taskResult2.getId());
TaskResult foundTaskResult5 = taskResultDao.getTaskResultById(oldTaskResult2.getId());
TaskResult foundTaskResult6 = taskResultDao.getTaskResultById(uniqueTaskResult2.getId());
assertEquals(taskResult, foundTaskResult1);
assertEquals(oldTaskResult, foundTaskResult2);
assertEquals(uniqueTaskResult, foundTaskResult3);
assertEquals(taskResult2, foundTaskResult4);
assertEquals(oldTaskResult2, foundTaskResult5);
assertEquals(uniqueTaskResult2, foundTaskResult6);
taskResultDao.clearOld(virtualEngineID, 6);
foundTaskResult1 = taskResultDao.getTaskResultById(taskResult.getId());
foundTaskResult3 = taskResultDao.getTaskResultById(uniqueTaskResult.getId());
foundTaskResult4 = taskResultDao.getTaskResultById(taskResult2.getId());
foundTaskResult6 = taskResultDao.getTaskResultById(uniqueTaskResult2.getId());
assertEquals(taskResult, foundTaskResult1);
assertEquals(uniqueTaskResult, foundTaskResult3);
assertEquals(taskResult2, foundTaskResult4);
assertEquals(uniqueTaskResult2, foundTaskResult6);
try {
taskResultDao.getTaskResultById(oldTaskResult.getId());
fail("TaskResult " + taskResult + " should not have been found");
} catch (EmptyResultDataAccessException e) {
}
try {
taskResultDao.getTaskResultById(oldTaskResult2.getId());
fail("TaskResult " + taskResult2 + " should not have been found");
} catch (EmptyResultDataAccessException e) {
}
taskResultDao.clearOld(virtualEngineID, 1);
foundTaskResult1 = taskResultDao.getTaskResultById(taskResult.getId());
foundTaskResult3 = taskResultDao.getTaskResultById(uniqueTaskResult.getId());
foundTaskResult4 = taskResultDao.getTaskResultById(taskResult2.getId());
foundTaskResult6 = taskResultDao.getTaskResultById(uniqueTaskResult2.getId());
assertEquals(taskResult, foundTaskResult1);
assertEquals(uniqueTaskResult, foundTaskResult3);
assertEquals(taskResult2, foundTaskResult4);
assertEquals(uniqueTaskResult2, foundTaskResult6);
}
use of cz.metacentrum.perun.taskslib.model.ExecService in project perun by CESNET.
the class ExecServiceDaoTest method testInsertExecService.
@Test
public void testInsertExecService() {
System.out.println("ExecServiceDao.insertExecService");
try {
log.debug("testInsertExecService: Inserting a new ExecService...");
// Test ExecService #1 (Parent:testService1)
ExecService execService = new ExecService();
execService.setDefaultDelay(1);
execService.setDefaultRecurrence(1);
execService.setEnabled(true);
execService.setService(testService1);
execService.setScript("/hellish/test/script");
execService.setExecServiceType(ExecServiceType.GENERATE);
int newExecServiceId = execServiceDao.insertExecService(execService);
// Test ExecService #2 (Parent:testService1)
ExecService execService2 = new ExecService();
execService2.setDefaultDelay(2);
execService2.setDefaultRecurrence(2);
execService2.setEnabled(true);
execService2.setService(testService1);
execService2.setScript("/hellish/test/script2");
execService2.setExecServiceType(ExecServiceType.SEND);
int newExecServiceId2 = execServiceDao.insertExecService(execService2);
// Test ExecService #3 (Parent:testService2)
ExecService execService3 = new ExecService();
execService3.setDefaultDelay(3);
execService3.setDefaultRecurrence(3);
execService3.setEnabled(true);
execService3.setService(testService2);
execService3.setScript("/hellish/test/script3");
execService3.setExecServiceType(ExecServiceType.SEND);
int newExecServiceId3 = execServiceDao.insertExecService(execService3);
assertTrue(newExecServiceId > 0);
assertTrue(newExecServiceId2 > newExecServiceId);
assertTrue(newExecServiceId3 > newExecServiceId2);
} catch (Exception e) {
log.error(e.getMessage(), e);
fail();
}
}
use of cz.metacentrum.perun.taskslib.model.ExecService in project perun by CESNET.
the class ExecServiceDaoTest method testCountExecServices.
@Test
public void testCountExecServices() {
System.out.println("ExecServiceDao.countExecServices");
try {
log.debug("testCountExecServices: Counting execExecServices...");
int countBeforeTest = execServiceDao.countExecServices();
log.debug("testCountExecServices: Inserting execServices...");
// Test ExecService #1 (Parent:testService1)
ExecService execService = new ExecService();
execService.setDefaultDelay(1);
execService.setDefaultRecurrence(1);
execService.setEnabled(true);
execService.setService(testService1);
execService.setScript("/hellish/test/script");
execService.setExecServiceType(ExecServiceType.GENERATE);
execServiceDao.insertExecService(execService);
// Test ExecService #2 (Parent:testService1)
ExecService execService2 = new ExecService();
execService2.setDefaultDelay(2);
execService2.setDefaultRecurrence(2);
execService2.setEnabled(true);
execService2.setService(testService1);
execService2.setScript("/hellish/test/script2");
execService2.setExecServiceType(ExecServiceType.SEND);
execServiceDao.insertExecService(execService2);
// Test ExecService #3 (Parent:testService2)
ExecService execService3 = new ExecService();
execService3.setDefaultDelay(3);
execService3.setDefaultRecurrence(3);
execService3.setEnabled(true);
execService3.setService(testService2);
execService3.setScript("/hellish/test/script3");
execService3.setExecServiceType(ExecServiceType.SEND);
execServiceDao.insertExecService(execService3);
log.debug("testCountExecServices: Counting execExecServices...");
int countAfterTest = execServiceDao.countExecServices();
assertTrue(countAfterTest == countBeforeTest + 3);
} catch (Exception e) {
log.error(e.getMessage(), e);
fail();
}
}
Aggregations