Search in sources :

Example 21 with PerunClient

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

the class ResourcesManagerBlImplTest method setUp.

@Before
public void setUp() throws Exception {
    candidate = new Candidate();
    candidate.setFirstName("some");
    candidate.setId(0);
    candidate.setMiddleName("");
    candidate.setLastName("testingUser");
    candidate.setTitleBefore("");
    candidate.setTitleAfter("");
    ues = new UserExtSource(extSource, "extLogin");
    candidate.setUserExtSource(ues);
    candidate.setAttributes(new HashMap<>());
    sess = perun.getPerunSession(new PerunPrincipal("perunTests", ExtSourcesManager.EXTSOURCE_NAME_INTERNAL, ExtSourcesManager.EXTSOURCE_INTERNAL), new PerunClient());
    vo = new Vo(0, "ResourcesBlImplTestVo", "ResMgrBlImplTestVo");
    vo = perun.getVosManagerBl().createVo(sess, vo);
    member = perun.getMembersManagerBl().createMemberSync(sess, vo, candidate);
    group = new Group("testGroup", "testGroup");
    group = perun.getGroupsManagerBl().createGroup(sess, vo, group);
    perun.getGroupsManagerBl().addMember(sess, group, member);
    facility = new Facility(0, "testFac");
    facility = perun.getFacilitiesManagerBl().createFacility(sess, facility);
    resource = new Resource(0, "testRes", null, facility.getId(), vo.getId());
    resource = perun.getResourcesManagerBl().createResource(sess, resource, vo, facility);
    perun.getResourcesManagerBl().assignGroupToResource(sess, group, resource, false, false, false);
    // second branch
    vo2 = new Vo(0, "FacilitiesManagerBlImplTestVo2", "FacMgrBlImplTestVo2");
    vo2 = perun.getVosManagerBl().createVo(sess, vo2);
    member2 = perun.getMembersManagerBl().createMemberSync(sess, vo2, candidate);
    group2 = new Group("testGroup", "testGroup");
    group2 = perun.getGroupsManagerBl().createGroup(sess, vo2, group2);
    perun.getGroupsManagerBl().addMember(sess, group2, member2);
    resource2 = new Resource(0, "testRes2", null, facility.getId(), vo2.getId());
    resource2 = perun.getResourcesManagerBl().createResource(sess, resource2, vo2, facility);
    // third branch
    facility2 = new Facility(0, "testFac2");
    facility2 = perun.getFacilitiesManagerBl().createFacility(sess, facility2);
    resource3 = new Resource(0, "testRes3", null, facility2.getId(), vo2.getId());
    resource3 = perun.getResourcesManagerBl().createResource(sess, resource3, vo2, facility2);
    perun.getResourcesManagerBl().assignGroupToResources(sess, group2, Arrays.asList(resource2, resource3), false, false, false);
    user = perun.getUsersManagerBl().getUserByMember(sess, member);
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) Group(cz.metacentrum.perun.core.api.Group) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) PerunClient(cz.metacentrum.perun.core.api.PerunClient) Resource(cz.metacentrum.perun.core.api.Resource) PerunPrincipal(cz.metacentrum.perun.core.api.PerunPrincipal) Vo(cz.metacentrum.perun.core.api.Vo) Facility(cz.metacentrum.perun.core.api.Facility) Before(org.junit.Before)

Example 22 with PerunClient

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

the class SearcherBlImplTest method setUp.

@Before
public void setUp() throws Exception {
    sess = perun.getPerunSession(new PerunPrincipal("perunTests", ExtSourcesManager.EXTSOURCE_NAME_INTERNAL, ExtSourcesManager.EXTSOURCE_INTERNAL), new PerunClient());
    // first branch
    vo1 = new Vo(0, "GroupsManagerBlImplTestVo", "GrpMgrBlImplTestVo");
    vo1 = perun.getVosManagerBl().createVo(sess, vo1);
    group1InVo1 = new Group("testGroup11", "testGroup");
    group1InVo1 = perun.getGroupsManagerBl().createGroup(sess, vo1, group1InVo1);
    group2InVo1 = new Group("testGroup12", "testGroup");
    group2InVo1 = perun.getGroupsManagerBl().createGroup(sess, vo1, group2InVo1);
    // second branch
    vo2 = new Vo(0, "FacilitiesManagerBlImplTestVo2", "FacMgrBlImplTestVo2");
    vo2 = perun.getVosManagerBl().createVo(sess, vo2);
    group1InVo2 = new Group("testGroup21", "testGroup");
    group1InVo2 = perun.getGroupsManagerBl().createGroup(sess, vo2, group1InVo2);
    group2InVo2 = new Group("testGroup22", "testGroup");
    group2InVo2 = perun.getGroupsManagerBl().createGroup(sess, vo2, group2InVo2);
}
Also used : Group(cz.metacentrum.perun.core.api.Group) PerunClient(cz.metacentrum.perun.core.api.PerunClient) PerunPrincipal(cz.metacentrum.perun.core.api.PerunPrincipal) Vo(cz.metacentrum.perun.core.api.Vo) Before(org.junit.Before)

Example 23 with PerunClient

use of cz.metacentrum.perun.core.api.PerunClient 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 24 with PerunClient

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

the class urn_perun_member_group_attribute_def_virt_isGroupAdminTest method setUp.

@Before
public void setUp() throws Exception {
    classInstance = new urn_perun_member_group_attribute_def_virt_isGroupAdmin();
    usersManager = perun.getUsersManager();
    vosManager = perun.getVosManager();
    membersManager = perun.getMembersManager();
    groupsManager = perun.getGroupsManager();
    final PerunPrincipal pp = new PerunPrincipal("perunTests", ExtSourcesManager.EXTSOURCE_NAME_INTERNAL, ExtSourcesManager.EXTSOURCE_INTERNAL);
    this.session = new PerunSessionImpl(perun, pp, new PerunClient());
    this.attrDef = classInstance.getAttributeDefinition();
    this.attribute = new Attribute(attrDef);
    this.user = setUpUser();
    this.vo = setUpVo();
    this.member = setUpMember(vo);
    this.group = setUpGroup(vo, member);
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) PerunClient(cz.metacentrum.perun.core.api.PerunClient) PerunPrincipal(cz.metacentrum.perun.core.api.PerunPrincipal) PerunSessionImpl(cz.metacentrum.perun.core.impl.PerunSessionImpl) Before(org.junit.Before)

Example 25 with PerunClient

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

the class AbstractTest method setUpSess.

@Before
public void setUpSess() throws Exception {
    final PerunPrincipal pp = new PerunPrincipal("perunTests", ExtSourcesManager.EXTSOURCE_NAME_INTERNAL, ExtSourcesManager.EXTSOURCE_INTERNAL);
    sess = perun.getPerunSession(pp, new PerunClient());
}
Also used : PerunClient(cz.metacentrum.perun.core.api.PerunClient) PerunPrincipal(cz.metacentrum.perun.core.api.PerunPrincipal)

Aggregations

PerunClient (cz.metacentrum.perun.core.api.PerunClient)25 PerunPrincipal (cz.metacentrum.perun.core.api.PerunPrincipal)24 Before (org.junit.Before)13 Facility (cz.metacentrum.perun.core.api.Facility)8 Service (cz.metacentrum.perun.core.api.Service)8 Vo (cz.metacentrum.perun.core.api.Vo)8 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)8 Group (cz.metacentrum.perun.core.api.Group)7 Resource (cz.metacentrum.perun.core.api.Resource)7 ArrayList (java.util.ArrayList)6 PerunSession (cz.metacentrum.perun.core.api.PerunSession)5 User (cz.metacentrum.perun.core.api.User)5 JdbcPerunTemplate (org.springframework.jdbc.core.JdbcPerunTemplate)5 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)4 Owner (cz.metacentrum.perun.core.api.Owner)4 UserNotExistsException (cz.metacentrum.perun.core.api.exceptions.UserNotExistsException)4 ExecService (cz.metacentrum.perun.taskslib.model.ExecService)4 Attribute (cz.metacentrum.perun.core.api.Attribute)3 Candidate (cz.metacentrum.perun.core.api.Candidate)3 Destination (cz.metacentrum.perun.core.api.Destination)3