Search in sources :

Example 1 with Service

use of cz.metacentrum.perun.core.api.Service in project perun by CESNET.

the class GeneralServiceManagerImpl method insertExecService.

@Override
public int insertExecService(PerunSession perunSession, ExecService execService) throws InternalErrorException, PrivilegeException, ServiceExistsException {
    Service service = null;
    try {
        service = servicesManager.getServiceByName(perunSession, execService.getService().getName());
    } catch (ServiceNotExistsException e) {
        service = servicesManager.createService(perunSession, execService.getService());
    }
    execService.setService(service);
    return execServiceDao.insertExecService(execService);
}
Also used : ServiceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ServiceNotExistsException) ExecService(cz.metacentrum.perun.taskslib.model.ExecService) Service(cz.metacentrum.perun.core.api.Service)

Example 2 with Service

use of cz.metacentrum.perun.core.api.Service in project perun by CESNET.

the class ExecServiceDaoTest method setUp.

@Before
public void setUp() throws InternalErrorException, OwnerNotExistsException, ServiceExistsException, PrivilegeException {
    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 = Utils.getNewId(jdbcTemplate, "owners_id_seq");
    testOwner = new Owner();
    testOwner.setContact("Call me babe");
    testOwner.setName("Tester-" + Long.toHexString(System.currentTimeMillis()));
    testOwner.setType(OwnerType.technical);
    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());
}
Also used : JdbcPerunTemplate(org.springframework.jdbc.core.JdbcPerunTemplate) Owner(cz.metacentrum.perun.core.api.Owner) PerunClient(cz.metacentrum.perun.core.api.PerunClient) PerunPrincipal(cz.metacentrum.perun.core.api.PerunPrincipal) ExecService(cz.metacentrum.perun.taskslib.model.ExecService) Service(cz.metacentrum.perun.core.api.Service) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Before(org.junit.Before)

Example 3 with Service

use of cz.metacentrum.perun.core.api.Service 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);
    }
}
Also used : JdbcPerunTemplate(org.springframework.jdbc.core.JdbcPerunTemplate) Owner(cz.metacentrum.perun.core.api.Owner) ExecService(cz.metacentrum.perun.taskslib.model.ExecService) PerunClient(cz.metacentrum.perun.core.api.PerunClient) PerunPrincipal(cz.metacentrum.perun.core.api.PerunPrincipal) ExecService(cz.metacentrum.perun.taskslib.model.ExecService) Service(cz.metacentrum.perun.core.api.Service) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Before(org.junit.Before)

Example 4 with Service

use of cz.metacentrum.perun.core.api.Service in project perun by CESNET.

the class TasksManagerBlImpl method getFacilityServicesState.

@Override
public List<ServiceState> getFacilityServicesState(PerunSession sess, Facility facility) {
    Map<Service, ServiceState> serviceStates = new HashMap<>();
    // fill states for all services which are currently on facility
    for (Service service : perun.getServicesManagerBl().getAssignedServices(sess, facility)) {
        serviceStates.put(service, new ServiceState(service, facility));
        serviceStates.get(service).setBlockedOnFacility(getServicesManagerBl().isServiceBlockedOnFacility(service, facility));
        // service has destination on facility
        serviceStates.get(service).setHasDestinations(!perun.getServicesManagerBl().getDestinations(sess, service, facility).isEmpty());
    }
    // fill states for all tasks on facility
    List<Task> tasks = getTasksManagerImpl().listAllTasksForFacility(facility.getId());
    for (Task task : tasks) {
        Service taskService = task.getService();
        ServiceState serviceState = serviceStates.get(taskService);
        if (serviceState == null) {
            serviceState = new ServiceState(taskService, facility);
            serviceStates.put(taskService, serviceState);
            // fill destinations if service was not assigned
            serviceStates.get(taskService).setHasDestinations(!perun.getServicesManagerBl().getDestinations(sess, taskService, facility).isEmpty());
        }
        // fill service state
        serviceState.setTask(task);
        serviceStates.get(taskService).setBlockedOnFacility(getServicesManagerBl().isServiceBlockedOnFacility(task.getService(), facility));
    }
    return new ArrayList<>(serviceStates.values());
}
Also used : Task(cz.metacentrum.perun.taskslib.model.Task) ServiceState(cz.metacentrum.perun.controller.model.ServiceState) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Service(cz.metacentrum.perun.core.api.Service)

Example 5 with Service

use of cz.metacentrum.perun.core.api.Service in project perun by CESNET.

the class ResourcesManagerBlImpl method assignServices.

@Override
public void assignServices(PerunSession sess, Resource resource, List<Service> services) throws ServiceAlreadyAssignedException, WrongAttributeValueException, WrongReferenceAttributeValueException {
    for (Service service : services) {
        getResourcesManagerImpl().assignService(sess, resource, service);
        getPerunBl().getAuditer().log(sess, new ServiceAssignedToResource(service, resource));
    }
    boolean requiresAttributes = services.stream().anyMatch(s -> !getPerunBl().getAttributesManagerBl().getRequiredAttributesDefinition(sess, s).isEmpty());
    if (!requiresAttributes) {
        // there are new no attributes to check or add
        return;
    }
    try {
        fillAndSetRequiredAttributesForGroups(sess, services, resource);
        checkSemanticsOfFacilityAndResourceRequiredAttributes(sess, resource);
        updateAllRequiredAttributesForAllowedMembers(sess, resource, services);
    } catch (WrongAttributeAssignmentException | GroupResourceMismatchException | MemberResourceMismatchException | AttributeNotExistsException e) {
        throw new ConsistencyErrorException(e);
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) MemberResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException) ServiceAssignedToResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ServiceAssignedToResource) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) Service(cz.metacentrum.perun.core.api.Service) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException)

Aggregations

Service (cz.metacentrum.perun.core.api.Service)115 Test (org.junit.Test)64 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)55 Facility (cz.metacentrum.perun.core.api.Facility)31 ArrayList (java.util.ArrayList)26 Resource (cz.metacentrum.perun.core.api.Resource)22 Destination (cz.metacentrum.perun.core.api.Destination)20 Member (cz.metacentrum.perun.core.api.Member)17 User (cz.metacentrum.perun.core.api.User)17 Group (cz.metacentrum.perun.core.api.Group)15 Vo (cz.metacentrum.perun.core.api.Vo)13 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)13 Attribute (cz.metacentrum.perun.core.api.Attribute)11 RichUser (cz.metacentrum.perun.core.api.RichUser)11 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)11 Task (cz.metacentrum.perun.taskslib.model.Task)10 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)8 PerunClient (cz.metacentrum.perun.core.api.PerunClient)8 PerunPrincipal (cz.metacentrum.perun.core.api.PerunPrincipal)8 ExecService (cz.metacentrum.perun.taskslib.model.ExecService)8