Search in sources :

Example 1 with JdbcPerunTemplate

use of org.springframework.jdbc.core.JdbcPerunTemplate 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 2 with JdbcPerunTemplate

use of org.springframework.jdbc.core.JdbcPerunTemplate 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 3 with JdbcPerunTemplate

use of org.springframework.jdbc.core.JdbcPerunTemplate in project perun by CESNET.

the class ServicesManagerBlImplTest method setUp.

/*
	 * Tables with reference to service:
	 *   - service_required_attrs
	 *   - service_denials
	 *   - resource_services
	 *   - facility_service_destinations
	 *   - service_service_packages
	 *   - tasks
	 *   - authz
	 * 
	 */
@Before
public void setUp() throws Exception {
    perunSession = perun.getPerunSession(new PerunPrincipal("perunTests", ExtSourcesManager.EXTSOURCE_NAME_INTERNAL, ExtSourcesManager.EXTSOURCE_INTERNAL), new PerunClient());
    jdbcTemplate = new JdbcPerunTemplate(dataSource);
    facility1 = new Facility();
    facility2 = new Facility();
    // 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()));
    testService1.setDelay(1);
    testService1.setRecurrence(1);
    testService1.setEnabled(true);
    testService1.setScript("/hellish/test/script");
    // Test Service #2
    testService2 = new Service();
    testService2.setName("Test_service_2_" + Long.toHexString(System.currentTimeMillis()));
    testService2.setDelay(2);
    testService2.setRecurrence(2);
    testService2.setEnabled(true);
    testService2.setScript("/hellish/test/script2");
    testService1.setId(servicesManager.createService(perunSession, testService1).getId());
    testService2.setId(servicesManager.createService(perunSession, testService2).getId());
    // attribute
    attribute = new AttributeDefinition();
    attribute.setFriendlyName("ServicesManagerTestAttribute");
    attribute.setDescription("TestingAttribute");
    attribute.setNamespace(AttributesManager.NS_ENTITYLESS_ATTR_DEF);
    attribute.setType(String.class.getName());
    attribute = ((PerunBl) perun).getAttributesManagerBl().createAttribute(perunSession, attribute);
    // required attributes
    List<AttributeDefinition> attrlist = new ArrayList<>();
    attrlist.add(attribute);
    ((PerunBl) perun).getServicesManagerBl().addRequiredAttributes(perunSession, testService1, attrlist);
    // 
    // 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);
    facility1.setId(testFacilityId1);
    // Testing Facility #2
    testFacilityId2 = Utils.getNewId(jdbcTemplate, "facilities_id_seq");
    jdbcTemplate.update("insert into facilities(id, name) values (?,?)", testFacilityId2, "Cluster_" + testFacilityId2);
    facility2.setId(testFacilityId2);
    // vo
    vo = new Vo(0, "ServicesManagerTestVo", "RMTestVo");
    vo = ((PerunBl) perun).getVosManagerBl().createVo(perunSession, vo);
    // resource
    resource = new Resource();
    resource.setName("ServicesManagerTestResource");
    resource.setDescription("Testovaci");
    resource = ((PerunBl) perun).getResourcesManagerBl().createResource(perunSession, resource, vo, facility1);
    // resource services
    ((PerunBl) perun).getResourcesManagerBl().assignService(perunSession, resource, testService1);
    // facility_service_destinations
    destination = ((PerunBl) perun).getServicesManagerBl().getDestinationById(perunSession, testDestinationId1);
    ((PerunBl) perun).getServicesManagerBl().addDestination(perunSession, testService1, facility1, destination);
    // service package
    servicesPackage = new ServicesPackage();
    servicesPackage.setName("ResourcesManagertTestSP");
    servicesPackage.setDescription("testingServicePackage");
    servicesPackage = ((PerunBl) perun).getServicesManagerBl().createServicesPackage(perunSession, servicesPackage);
    // service_service_packages
    ((PerunBl) perun).getServicesManagerBl().addServiceToServicesPackage(perunSession, servicesPackage, testService1);
    // tasks
    task = new Task();
    task.setFacility(facility1);
    task.setService(testService1);
    task.setSchedule(0L);
    task.setStatus(TaskStatus.DONE);
    List<Destination> destinationsList = new ArrayList<>();
    destinationsList.add(destination);
    task.setDestinations(destinationsList);
    ((PerunBl) perun).getTasksManagerBl().insertTask(perunSession, task);
// authz
// authz entries for service are removed in ServicesManagerImpl::deleteService(),
// no point in testing here
}
Also used : Destination(cz.metacentrum.perun.core.api.Destination) Owner(cz.metacentrum.perun.core.api.Owner) Task(cz.metacentrum.perun.taskslib.model.Task) ArrayList(java.util.ArrayList) Resource(cz.metacentrum.perun.core.api.Resource) Service(cz.metacentrum.perun.core.api.Service) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) JdbcPerunTemplate(org.springframework.jdbc.core.JdbcPerunTemplate) PerunClient(cz.metacentrum.perun.core.api.PerunClient) PerunPrincipal(cz.metacentrum.perun.core.api.PerunPrincipal) Vo(cz.metacentrum.perun.core.api.Vo) Facility(cz.metacentrum.perun.core.api.Facility) ServicesPackage(cz.metacentrum.perun.core.api.ServicesPackage) Before(org.junit.Before)

Example 4 with JdbcPerunTemplate

use of org.springframework.jdbc.core.JdbcPerunTemplate in project perun by CESNET.

the class Auditer method setPerunPool.

public void setPerunPool(DataSource perunPool) {
    this.jdbc = new JdbcPerunTemplate(perunPool);
    this.jdbc.setQueryTimeout(BeansUtils.getCoreConfig().getQueryTimeout());
}
Also used : JdbcPerunTemplate(org.springframework.jdbc.core.JdbcPerunTemplate)

Example 5 with JdbcPerunTemplate

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

Aggregations

JdbcPerunTemplate (org.springframework.jdbc.core.JdbcPerunTemplate)10 PerunClient (cz.metacentrum.perun.core.api.PerunClient)5 PerunPrincipal (cz.metacentrum.perun.core.api.PerunPrincipal)5 Service (cz.metacentrum.perun.core.api.Service)5 Before (org.junit.Before)5 Owner (cz.metacentrum.perun.core.api.Owner)4 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)3 ExecService (cz.metacentrum.perun.taskslib.model.ExecService)3 Destination (cz.metacentrum.perun.core.api.Destination)2 Facility (cz.metacentrum.perun.core.api.Facility)2 Resource (cz.metacentrum.perun.core.api.Resource)2 Vo (cz.metacentrum.perun.core.api.Vo)2 Task (cz.metacentrum.perun.taskslib.model.Task)2 ArrayList (java.util.ArrayList)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)1 ServicesPackage (cz.metacentrum.perun.core.api.ServicesPackage)1 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)1 ServiceExistsException (cz.metacentrum.perun.core.api.exceptions.ServiceExistsException)1 PerunBl (cz.metacentrum.perun.core.bl.PerunBl)1