Search in sources :

Example 36 with Service

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;
}
Also used : ServiceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ServiceNotExistsException) ExecService(cz.metacentrum.perun.taskslib.model.ExecService) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) ExecService(cz.metacentrum.perun.taskslib.model.ExecService) Service(cz.metacentrum.perun.core.api.Service) ServiceExistsException(cz.metacentrum.perun.core.api.exceptions.ServiceExistsException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 37 with 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;
}
Also used : ServiceForGUI(cz.metacentrum.perun.controller.model.ServiceForGUI) ExecService(cz.metacentrum.perun.taskslib.model.ExecService) ArrayList(java.util.ArrayList) ExecService(cz.metacentrum.perun.taskslib.model.ExecService) Service(cz.metacentrum.perun.core.api.Service)

Example 38 with Service

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);
}
Also used : PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) ArrayList(java.util.ArrayList) Service(cz.metacentrum.perun.core.api.Service) Facility(cz.metacentrum.perun.core.api.Facility)

Example 39 with Service

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()));
    }
}
Also used : RichDestination(cz.metacentrum.perun.core.api.RichDestination) Service(cz.metacentrum.perun.core.api.Service) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 40 with Service

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;
}
Also used : Service(cz.metacentrum.perun.core.api.Service)

Aggregations

Service (cz.metacentrum.perun.core.api.Service)66 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)44 Test (org.junit.Test)44 ArrayList (java.util.ArrayList)11 Facility (cz.metacentrum.perun.core.api.Facility)10 Destination (cz.metacentrum.perun.core.api.Destination)9 Member (cz.metacentrum.perun.core.api.Member)8 ExecService (cz.metacentrum.perun.taskslib.model.ExecService)8 User (cz.metacentrum.perun.core.api.User)6 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)6 Attribute (cz.metacentrum.perun.core.api.Attribute)5 BanOnFacility (cz.metacentrum.perun.core.api.BanOnFacility)5 Group (cz.metacentrum.perun.core.api.Group)5 Host (cz.metacentrum.perun.core.api.Host)5 Resource (cz.metacentrum.perun.core.api.Resource)5 RichDestination (cz.metacentrum.perun.core.api.RichDestination)5 RichUser (cz.metacentrum.perun.core.api.RichUser)5 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)4 PerunClient (cz.metacentrum.perun.core.api.PerunClient)4 PerunPrincipal (cz.metacentrum.perun.core.api.PerunPrincipal)4