Search in sources :

Example 6 with JdbcPerunTemplate

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

the class MailManagerImpl method setDataSource.

// Spring setters
public void setDataSource(DataSource dataSource) {
    this.jdbc = new JdbcPerunTemplate(dataSource);
    this.jdbc.setQueryTimeout(BeansUtils.getCoreConfig().getQueryTimeout());
}
Also used : JdbcPerunTemplate(org.springframework.jdbc.core.JdbcPerunTemplate)

Example 7 with JdbcPerunTemplate

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

the class ConsolidatorManagerImpl method setDataSource.

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

Example 8 with JdbcPerunTemplate

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

the class TasksManagerBlImplTest method setUp.

@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);
    tasksManager = ((PerunBl) perun).getTasksManagerBl();
    facility1 = new Facility();
    facility2 = new Facility();
    // 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");
    testService1.setId(servicesManager.createService(perunSession, testService1).getId());
    // Test Service #2
    testService2 = new Service();
    testService2.setName("Test_service_2_" + Long.toHexString(System.currentTimeMillis()));
    testService2.setDelay(1);
    testService2.setRecurrence(1);
    testService2.setEnabled(true);
    testService2.setScript("/hellish/test/script");
    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);
    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);
    // facility_service_destinations
    destination1 = ((PerunBl) perun).getServicesManagerBl().getDestinationById(perunSession, testDestinationId1);
    destination2 = ((PerunBl) perun).getServicesManagerBl().getDestinationById(perunSession, testDestinationId2);
    ((PerunBl) perun).getServicesManagerBl().addDestination(perunSession, testService1, facility1, destination1);
    ((PerunBl) perun).getServicesManagerBl().addDestination(perunSession, testService1, facility1, destination2);
    ((PerunBl) perun).getServicesManagerBl().addDestination(perunSession, testService1, facility2, destination2);
    // vo
    vo = new Vo(0, "TasksManagerTestVo", "TMTestVo");
    vo = ((PerunBl) perun).getVosManagerBl().createVo(perunSession, vo);
    // resource
    resource = new Resource();
    resource.setName("TasksManagerTestResource");
    resource.setDescription("Testovaci");
    resource = ((PerunBl) perun).getResourcesManagerBl().createResource(perunSession, resource, vo, facility1);
    // tasks
    task1 = new Task();
    task1.setFacility(facility1);
    task1.setService(testService1);
    task1.setSchedule(0L);
    task1.setStatus(TaskStatus.DONE);
    List<Destination> destinationsList = new ArrayList<>();
    destinationsList.add(destination1);
    destinationsList.add(destination2);
    task1.setDestinations(destinationsList);
    task1Id = tasksManager.insertTask(perunSession, task1);
    task1.setId(task1Id);
    // tasks
    task2 = new Task();
    task2.setFacility(facility2);
    task2.setService(testService1);
    task2.setSchedule(0L);
    task2.setStatus(TaskStatus.WARNING);
    destinationsList = new ArrayList<>();
    destinationsList.add(destination2);
    task2.setDestinations(destinationsList);
    task2Id = tasksManager.insertTask(perunSession, task2);
    task2.setId(task2Id);
    // task results
    result1 = new TaskResult();
    result1.setDestination(destination1);
    result1.setDestinationId(testDestinationId1);
    result1.setService(testService1);
    result1.setTaskId(task1Id);
    result1.setStatus(TaskResultStatus.DONE);
    result1.setTimestamp(new Date());
    result1Id = tasksManager.insertNewTaskResult(perunSession, result1);
    result1.setId(result1Id);
    // task results
    result2 = new TaskResult();
    result2.setDestination(destination1);
    result2.setDestinationId(testDestinationId1);
    result2.setService(testService1);
    result2.setTaskId(task1Id);
    result2.setStatus(TaskResultStatus.DONE);
    result2.setTimestamp(Date.from(LocalDate.now().minusDays(7).atStartOfDay(ZoneId.systemDefault()).toInstant()));
    result2Id = tasksManager.insertNewTaskResult(perunSession, result2);
    result2.setId(result2Id);
    // task results
    result3 = new TaskResult();
    result3.setDestination(destination2);
    result3.setDestinationId(testDestinationId2);
    result3.setService(testService1);
    result3.setTaskId(task1Id);
    result3.setStatus(TaskResultStatus.DONE);
    result3.setTimestamp(Date.from(LocalDate.now().minusDays(7).atStartOfDay(ZoneId.systemDefault()).toInstant()));
    result3Id = tasksManager.insertNewTaskResult(perunSession, result3);
    result3.setId(result3Id);
    jdbcTemplate.query("select id from tasks_results where task_id = ?", row -> {
        System.out.println("ID: " + row.getInt("id"));
    }, task2Id);
}
Also used : Destination(cz.metacentrum.perun.core.api.Destination) Task(cz.metacentrum.perun.taskslib.model.Task) Resource(cz.metacentrum.perun.core.api.Resource) ArrayList(java.util.ArrayList) Service(cz.metacentrum.perun.core.api.Service) Date(java.util.Date) LocalDate(java.time.LocalDate) 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) TaskResult(cz.metacentrum.perun.taskslib.model.TaskResult) Facility(cz.metacentrum.perun.core.api.Facility) Before(org.junit.Before)

Example 9 with JdbcPerunTemplate

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

the class AppAutoRejectionScheduler method setDataSource.

@Autowired
public void setDataSource(DataSource dataSource) {
    this.jdbc = new JdbcPerunTemplate(dataSource);
    this.jdbc.setQueryTimeout(BeansUtils.getCoreConfig().getQueryTimeout());
}
Also used : JdbcPerunTemplate(org.springframework.jdbc.core.JdbcPerunTemplate) Autowired(org.springframework.beans.factory.annotation.Autowired)

Example 10 with JdbcPerunTemplate

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

the class ExpirationNotifScheduler method setDataSource.

@Autowired
public void setDataSource(DataSource dataSource) {
    this.jdbc = new JdbcPerunTemplate(dataSource);
    this.jdbc.setQueryTimeout(BeansUtils.getCoreConfig().getQueryTimeout());
}
Also used : JdbcPerunTemplate(org.springframework.jdbc.core.JdbcPerunTemplate) Autowired(org.springframework.beans.factory.annotation.Autowired)

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