use of cz.metacentrum.perun.taskslib.model.ExecService in project perun by CESNET.
the class ExecServiceDenialDaoTest method setUp.
@Before
public void setUp() throws InternalErrorException, OwnerNotExistsException, ServiceExistsException, PrivilegeException {
perunSession = perun.getPerunSession(new PerunPrincipal("perunTests", ExtSourcesManager.EXTSOURCE_NAME_INTERNAL, ExtSourcesManager.EXTSOURCE_INTERNAL), new PerunClient());
jdbcTemplate = new JdbcPerunTemplate(dataSource);
// Test Owner
int newOwnerId = Utils.getNewId(jdbcTemplate, "owners_id_seq");
testOwner = new Owner();
testOwner.setContact("Call me babe");
testOwner.setType(OwnerType.technical);
testOwner.setName("Tester-" + Long.toHexString(System.currentTimeMillis()));
testOwner.setId(newOwnerId);
jdbcTemplate.update("insert into owners(id, name, contact, type) values (?,?,?,?)", newOwnerId, testOwner.getName(), testOwner.getContact(), testOwner.getType().toString());
// Test Service #1
testService1 = new Service();
testService1.setName("Test_service_1_" + Long.toHexString(System.currentTimeMillis()));
// Test Service #2
testService2 = new Service();
testService2.setName("Test_service_2_" + Long.toHexString(System.currentTimeMillis()));
testService1.setId(servicesManager.createService(perunSession, testService1).getId());
testService2.setId(servicesManager.createService(perunSession, testService2).getId());
// Testing Destination #1
testDestinationId1 = Utils.getNewId(jdbcTemplate, "destinations_id_seq");
jdbcTemplate.update("insert into destinations(id, destination, type) values (?,?,'host')", testDestinationId1, "test.destination." + testDestinationId1);
// Testing Destination #2
testDestinationId2 = Utils.getNewId(jdbcTemplate, "destinations_id_seq");
jdbcTemplate.update("insert into destinations(id, destination, type) values (?,?,'host')", testDestinationId2, "test.destination." + testDestinationId2);
// Testing Facility #1
testFacilityId1 = Utils.getNewId(jdbcTemplate, "facilities_id_seq");
jdbcTemplate.update("insert into facilities(id, name) values (?,?)", testFacilityId1, "Cluster_" + testFacilityId1);
// Testing Facility #2
testFacilityId2 = Utils.getNewId(jdbcTemplate, "facilities_id_seq");
jdbcTemplate.update("insert into facilities(id, name) values (?,?)", testFacilityId2, "Cluster_" + testFacilityId2);
// Test ExecService #1 (Parent:testService1)
testExecService1 = new ExecService();
testExecService1.setDefaultDelay(1);
testExecService1.setDefaultRecurrence(1);
testExecService1.setEnabled(true);
testExecService1.setService(testService1);
testExecService1.setScript("/hellish/test/script");
testExecService1.setExecServiceType(ExecServiceType.GENERATE);
try {
testExecService1.setId(execServiceDao.insertExecService(testExecService1));
} catch (InternalErrorException e) {
log.error(e.toString(), e);
}
// Test ExecService #2 (Parent:testService1)
testExecService2 = new ExecService();
testExecService2.setDefaultDelay(2);
testExecService2.setDefaultRecurrence(2);
testExecService2.setEnabled(true);
testExecService2.setService(testService2);
testExecService2.setScript("/hellish/test/script2");
testExecService2.setExecServiceType(ExecServiceType.SEND);
try {
testExecService2.setId(execServiceDao.insertExecService(testExecService2));
} catch (InternalErrorException e) {
log.error(e.toString(), e);
}
}
use of cz.metacentrum.perun.taskslib.model.ExecService in project perun by CESNET.
the class ExecServiceDependencyDaoTest method testListExecServicesDependingOn.
@Test
public void testListExecServicesDependingOn() {
System.out.println("ExecServiceDependencyDao.listExecServicesDependingOn");
try {
log.debug("testListExecServicesDependingOn: Testing...");
execServiceDependencyDao.createDependency(testExecService1.getId(), testExecService2.getId());
execServiceDependencyDao.createDependency(testExecService3.getId(), testExecService2.getId());
List<ExecService> execServices = execServiceDependencyDao.listExecServicesDependingOn(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.listExecServicesDependingOn(testExecService1.getId()).size(), 0);
assertEquals(execServiceDependencyDao.listExecServicesDependingOn(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 AuditParser method createExecService.
private static ExecService createExecService(Map<String, String> beanAttr) {
if (beanAttr == null)
return null;
ExecService execService = new ExecService();
execService.setId(Integer.valueOf(beanAttr.get("id")).intValue());
execService.setDefaultDelay(Integer.valueOf(beanAttr.get("defaultDelay")).intValue());
execService.setDefaultRecurrence(Integer.valueOf(beanAttr.get("defaultRecurrence")).intValue());
execService.setEnabled(Boolean.valueOf(beanAttr.get("enabled")).booleanValue());
if (beanAttr.get("script").equals("\\0"))
execService.setScript(null);
else {
execService.setScript(BeansUtils.eraseEscaping(beanAttr.get("script")));
}
Service service;
if (beanAttr.get("service").equals("\\0"))
service = null;
else {
List<Pair<String, Map<String, String>>> serviceList = beansToMap(beanAttr.get("service"));
service = createService(serviceList.get(0).getRight());
}
execService.setService(service);
ExecService.ExecServiceType exType;
if (beanAttr.get("type").equals("\\0"))
exType = null;
else {
String type = beanAttr.get("type");
if (type.equals("GENERATE"))
exType = ExecServiceType.GENERATE;
else if (type.equals("SEND"))
exType = ExecServiceType.SEND;
else
exType = null;
}
execService.setExecServiceType(exType);
return execService;
}
use of cz.metacentrum.perun.taskslib.model.ExecService in project perun by CESNET.
the class GeneralServiceManagerImpl method planServicePropagation.
@Override
public boolean planServicePropagation(PerunSession perunSession, Facility facility, Service service) throws ServiceNotExistsException, FacilityNotExistsException, InternalErrorException, PrivilegeException {
List<ExecService> listOfExecServices = listExecServices(perunSession, service.getId());
for (ExecService es : listOfExecServices) {
//Global
if (!es.isEnabled())
return false;
//Local
if (execServiceDenialDao.isExecServiceDeniedOnFacility(es.getId(), facility.getId()))
return false;
}
//Call log method out of transaction
perunSession.getPerun().getAuditer().log(perunSession, PROPAGATION_PLANNED + "On {} and {}", facility, service);
return true;
}
use of cz.metacentrum.perun.taskslib.model.ExecService in project perun by CESNET.
the class GeneralServiceManagerImpl method planServicePropagation.
@Override
public boolean planServicePropagation(PerunSession perunSession, Service service) throws ServiceNotExistsException, InternalErrorException, PrivilegeException {
List<ExecService> listOfExecServices = listExecServices(perunSession, service.getId());
for (ExecService es : listOfExecServices) {
//Global
if (!es.isEnabled())
return false;
}
//Call log method out of transaction
perunSession.getPerun().getAuditer().log(perunSession, PROPAGATION_PLANNED + "On {} ", service);
return true;
}
Aggregations