use of cz.metacentrum.perun.taskslib.model.ExecService in project perun by CESNET.
the class GeneralServiceManagerImpl method createCompleteService.
@Override
@Transactional(rollbackFor = Exception.class)
public Service createCompleteService(PerunSession perunSession, String serviceName, String scriptPath, int defaultDelay, boolean enabled) throws InternalErrorException, PrivilegeException, ServiceExistsException {
if (!AuthzResolver.isAuthorized(perunSession, Role.PERUNADMIN)) {
throw new PrivilegeException(perunSession, "createCompleteService");
}
Service service = null;
try {
service = servicesManager.getServiceByName(perunSession, serviceName);
if (service != null) {
throw new ServiceExistsException(service);
}
} catch (ServiceNotExistsException e) {
service = new Service();
service.setName(serviceName);
service = servicesManager.createService(perunSession, service);
}
ExecService genExecService = new ExecService();
genExecService.setService(service);
genExecService.setDefaultDelay(defaultDelay);
genExecService.setEnabled(enabled);
genExecService.setScript(scriptPath);
genExecService.setExecServiceType(ExecServiceType.GENERATE);
genExecService.setId(execServiceDao.insertExecService(genExecService));
ExecService sendExecService = new ExecService();
sendExecService.setService(service);
sendExecService.setDefaultDelay(defaultDelay);
sendExecService.setEnabled(enabled);
sendExecService.setScript(scriptPath);
sendExecService.setExecServiceType(ExecServiceType.SEND);
sendExecService.setId(execServiceDao.insertExecService(sendExecService));
this.createDependency(sendExecService, genExecService);
return service;
}
use of cz.metacentrum.perun.taskslib.model.ExecService in project perun by CESNET.
the class GeneralServiceManagerImpl method getFacilityAssignedServicesForGUI.
@Override
public List<ServiceForGUI> getFacilityAssignedServicesForGUI(PerunSession perunSession, Facility facility) throws PrivilegeException, FacilityNotExistsException, InternalErrorException {
// result list
List<ServiceForGUI> result = new ArrayList<ServiceForGUI>();
// get assigned services
List<Service> services = getServicesManager().getAssignedServices(perunSession, facility);
for (Service service : services) {
// flag
boolean allowed = true;
// new ServiceForGUI
ServiceForGUI newService = new ServiceForGUI(service);
// get their exec services
List<ExecService> execs = execServiceDao.listExecServices(service.getId());
for (ExecService exec : execs) {
// if generate
if (exec.getExecServiceType().equals(ExecService.ExecServiceType.GENERATE)) {
if (execServiceDenialDao.isExecServiceDeniedOnFacility(exec.getId(), facility.getId()) == true) {
newService.setGenAllowedOnFacility(false);
allowed = false;
} else {
newService.setGenAllowedOnFacility(true);
}
newService.setGenExecService(exec);
} else {
// if send
if (execServiceDenialDao.isExecServiceDeniedOnFacility(exec.getId(), facility.getId()) == true) {
newService.setSendAllowedOnFacility(false);
allowed = false;
} else {
newService.setSendAllowedOnFacility(true);
}
newService.setSendExecService(exec);
}
}
newService.setAllowedOnFacility(allowed);
result.add(newService);
}
return result;
}
use of cz.metacentrum.perun.taskslib.model.ExecService in project perun by CESNET.
the class ExecServiceDaoTest method testGetExecService.
@Test
public void testGetExecService() {
System.out.println("ExecServiceDao.getExecService");
try {
log.debug("testGetExecService: 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);
execService.setId(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);
execService2.setId(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);
execService3.setId(execServiceDao.insertExecService(execService3));
assertEquals(execServiceDao.getExecService(execService2.getId()).getScript(), execService2.getScript());
assertEquals(execServiceDao.getExecService(execService3.getId()).getScript(), execService3.getScript());
assertEquals(execServiceDao.getExecService(execService.getId()).getScript(), execService.getScript());
} catch (Exception e) {
log.error(e.getMessage(), e);
fail();
}
}
use of cz.metacentrum.perun.taskslib.model.ExecService in project perun by CESNET.
the class ExecServiceDenialDaoTest method testListDenialsForFacility.
@Test
public void testListDenialsForFacility() {
System.out.println("ExecServiceDenialDao.listDenialsForFacility");
try {
log.debug("testListDenialsForFacility: Inserting a new denial...");
execServiceDenialDao.banExecServiceOnFacility(testExecService1.getId(), testFacilityId1);
execServiceDenialDao.banExecServiceOnFacility(testExecService2.getId(), testFacilityId1);
log.debug("testListDenialsForFacility: Listing all denials (denied services) for the facility...");
List<ExecService> deniedExecServices = execServiceDenialDao.listDenialsForFacility(testFacilityId1);
assertNotNull(deniedExecServices);
for (ExecService deniedExecService : deniedExecServices) {
log.debug("\tCLUSTER:" + testFacilityId1);
log.debug("\tID:" + deniedExecService.getId());
log.debug("\tDefDELAY:" + deniedExecService.getDefaultDelay());
log.debug("\tDefRecurrence:" + deniedExecService.getDefaultRecurrence());
log.debug("\tENABLED:" + deniedExecService.isEnabled());
log.debug("\tService:" + deniedExecService.getService().getName());
log.debug("\tSCRIPT:" + deniedExecService.getScript());
log.debug("\tTYPE:" + deniedExecService.getExecServiceType().toString());
}
assertEquals(deniedExecServices.size(), 2);
assertEquals(execServiceDenialDao.listDenialsForFacility(testFacilityId2).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 beforeClass.
@Before
public void beforeClass() {
try {
perunSession = perun.getPerunSession(new PerunPrincipal("perunTests", ExtSourcesManager.EXTSOURCE_NAME_INTERNAL, ExtSourcesManager.EXTSOURCE_INTERNAL), new PerunClient());
} catch (InternalErrorException e) {
log.error(e.toString());
}
jdbcTemplate = new JdbcPerunTemplate(dataSource);
// Test Owner
int newOwnerId = 0;
try {
newOwnerId = Utils.getNewId(jdbcTemplate, "owners_id_seq");
} catch (InternalErrorException e) {
log.error(e.toString(), e);
}
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()));
try {
testService1.setId(servicesManager.createService(perunSession, testService1).getId());
testService2.setId(servicesManager.createService(perunSession, testService2).getId());
} catch (InternalErrorException e) {
log.error(e.toString());
} catch (PrivilegeException e) {
log.error(e.toString());
} catch (ServiceExistsException e) {
log.error(e.toString());
}
// 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(testService1);
testExecService2.setScript("/hellish/test/script2");
testExecService2.setExecServiceType(ExecServiceType.SEND);
try {
testExecService2.setId(execServiceDao.insertExecService(testExecService2));
} catch (InternalErrorException e) {
log.error(e.toString(), e);
}
// Test ExecService #3 (Parent:testService2)
testExecService3 = new ExecService();
testExecService3.setDefaultDelay(3);
testExecService3.setDefaultRecurrence(3);
testExecService3.setEnabled(true);
testExecService3.setService(testService2);
testExecService3.setScript("/hellish/test/script3");
testExecService3.setExecServiceType(ExecServiceType.SEND);
try {
testExecService3.setId(execServiceDao.insertExecService(testExecService3));
} catch (InternalErrorException e) {
log.error(e.toString(), e);
}
}
Aggregations