use of cz.metacentrum.perun.core.api.Service 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.core.api.Service 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.core.api.Service in project perun by CESNET.
the class ServicesManagerEntry method addDestination.
public Destination addDestination(PerunSession perunSession, List<Service> services, Facility facility, Destination destination) throws PrivilegeException, InternalErrorException, ServiceNotExistsException, FacilityNotExistsException, DestinationAlreadyAssignedException, WrongPatternException {
Utils.checkPerunSession(perunSession);
Utils.notNull(services, "services");
Utils.checkDestinationType(destination);
getPerunBl().getFacilitiesManagerBl().checkFacilityExists(perunSession, facility);
// Authorization
if (!AuthzResolver.isAuthorized(perunSession, Role.FACILITYADMIN, facility)) {
throw new PrivilegeException(perunSession, "addDestination");
}
//prepare lists of facilities
List<Facility> facilitiesByHostname = new ArrayList<Facility>();
List<Facility> facilitiesByDestination = new ArrayList<Facility>();
if (destination.getType().equals(Destination.DESTINATIONHOSTTYPE) || destination.getType().equals(Destination.DESTINATIONUSERHOSTTYPE) || destination.getType().equals(Destination.DESTINATIONUSERHOSTPORTTYPE)) {
facilitiesByHostname = getPerunBl().getFacilitiesManagerBl().getFacilitiesByHostName(perunSession, destination.getHostNameFromDestination());
if (facilitiesByHostname.isEmpty())
facilitiesByDestination = getPerunBl().getFacilitiesManagerBl().getFacilitiesByDestination(perunSession, destination.getHostNameFromDestination());
if (!facilitiesByHostname.isEmpty()) {
boolean hasRight = false;
for (Facility facilityByHostname : facilitiesByHostname) {
if (AuthzResolver.isAuthorized(perunSession, Role.FACILITYADMIN, facilityByHostname)) {
hasRight = true;
break;
}
}
if (!hasRight)
throw new PrivilegeException("You have no right to add this destination.");
}
if (!facilitiesByDestination.isEmpty()) {
boolean hasRight = false;
for (Facility facilityByDestination : facilitiesByDestination) {
if (AuthzResolver.isAuthorized(perunSession, Role.FACILITYADMIN, facilityByDestination)) {
hasRight = true;
break;
}
}
if (!hasRight)
throw new PrivilegeException("You have no right to add this destination.");
}
}
for (Service s : services) {
getServicesManagerBl().checkServiceExists(perunSession, s);
}
Utils.notNull(destination, "destination");
Utils.notNull(destination.getDestination(), "destination.destination");
Utils.notNull(destination.getType(), "destination.type");
return getServicesManagerBl().addDestination(perunSession, services, facility, destination);
}
use of cz.metacentrum.perun.core.api.Service in project perun by CESNET.
the class ServicesManagerEntryIntegrationTest method addDestinationForMoreThanOneService.
@Test
public void addDestinationForMoreThanOneService() throws Exception {
System.out.println(CLASS_NAME + "addDestinationForMoreThanOneService");
List<Service> services = setUpServices();
facility = setUpFacility();
destination = setUpDestination();
perun.getServicesManager().addDestination(sess, services, facility, destination);
List<RichDestination> destinations = perun.getServicesManager().getRichDestinations(sess, facility, services.get(0));
destinations.addAll(perun.getServicesManager().getRichDestinations(sess, facility, services.get(1)));
assertTrue("service should have 1 destination", destinations.size() == 2);
for (RichDestination rd : destinations) {
assertTrue("destination in richDestination need to be our destination", rd.getDestination().equals(destination.getDestination()));
assertTrue("type of destination need to be our type of destination", rd.getType().equals(destination.getType()));
assertTrue("richDestination has service from our list of services", services.contains(rd.getService()));
}
}
use of cz.metacentrum.perun.core.api.Service in project perun by CESNET.
the class ServicesManagerEntryIntegrationTest method setUpService.
// PRIVATE METHODS ----------------------------------------------------
private Service setUpService() throws Exception {
Service service = new Service();
service.setName("ServicesManagerTestService");
service = perun.getServicesManager().createService(sess, service);
assertNotNull("unable to create service", service);
return service;
}
Aggregations