Search in sources :

Example 81 with Service

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

the class ResourcesManagerEntry method removeServices.

@Override
public void removeServices(PerunSession sess, Resource resource, List<Service> services) throws PrivilegeException, ResourceNotExistsException, ServiceNotExistsException, ServiceNotAssignedException {
    Utils.checkPerunSession(sess);
    getResourcesManagerBl().checkResourceExists(sess, resource);
    for (Service service : services) {
        getPerunBl().getServicesManagerBl().checkServiceExists(sess, service);
    }
    // Authorization
    for (Service service : services) {
        if (!AuthzResolver.authorizedInternal(sess, "removeServices_Resource_List<Service>_policy", service, resource)) {
            throw new PrivilegeException(sess, "removeServices");
        }
    }
    getResourcesManagerBl().removeServices(sess, resource, services);
}
Also used : PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) Service(cz.metacentrum.perun.core.api.Service)

Example 82 with Service

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

the class ResourcesManagerBlImplUnitTest method fillAndSetRequiredAttributesForGroups.

@Test
public void fillAndSetRequiredAttributesForGroups() throws Exception {
    System.out.println(CLASS_NAME + "fillAndSetRequiredAttributesForGroups");
    Resource resource = new Resource();
    List<Service> services = new ArrayList<>();
    Group g1 = new Group("G1", "G1");
    Group g2 = new Group("G2", "G2");
    List<Group> groups = new ArrayList<>();
    groups.add(g1);
    groups.add(g2);
    List<Attribute> requiredAttributes = Collections.singletonList(mock(Attribute.class));
    List<Attribute> filledAttributes = Collections.singletonList(mock(Attribute.class));
    when(resourcesManagerBlMock.getAssignedGroups(sessionMock, resource)).thenReturn(groups);
    when(attributesManagerBlMock.getRequiredAttributes(any(), anyList(), any(), any(), anyBoolean())).thenReturn(requiredAttributes);
    when(attributesManagerBlMock.fillAttributes(any(), any(Resource.class), any(Group.class), anyList(), anyBoolean())).thenReturn(filledAttributes);
    doCallRealMethod().when(resourcesManagerBlMock).fillAndSetRequiredAttributesForGroups(any(), anyList(), any());
    resourcesManagerBlMock.fillAndSetRequiredAttributesForGroups(sessionMock, services, resource);
    for (Group group : groups) {
        verify(attributesManagerBlMock, times(1)).fillAttributes(sessionMock, resource, group, requiredAttributes, true);
        verify(attributesManagerBlMock, times(1)).setAttributes(sessionMock, resource, group, filledAttributes, true);
    }
}
Also used : Group(cz.metacentrum.perun.core.api.Group) Attribute(cz.metacentrum.perun.core.api.Attribute) Resource(cz.metacentrum.perun.core.api.Resource) ServiceAssignedToResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ServiceAssignedToResource) ArrayList(java.util.ArrayList) Service(cz.metacentrum.perun.core.api.Service) Test(org.junit.Test)

Example 83 with Service

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

the class ResourcesManagerBlImplUnitTest method updateAllRequiredAttributesForAllowedMembers.

@Test
public void updateAllRequiredAttributesForAllowedMembers() throws Exception {
    System.out.println(CLASS_NAME + "updateAllRequiredAttributesForAllowedMembers");
    Facility facility = new Facility(1, "Facility");
    Resource resource = new Resource(9, "", "", facility.getId());
    Member m1 = new Member(1);
    Member m2 = new Member(2);
    User u1 = new User(1, "", "", "", "", "");
    User u2 = new User(2, "", "", "", "", "");
    List<Service> services = new ArrayList<>();
    List<Member> members = Arrays.asList(m1, m2);
    List<User> users = Arrays.asList(u1, u2);
    for (int i = 0; i < users.size(); i++) {
        when(perunBlMock.getUsersManagerBl().getUserByMember(sessionMock, members.get(i))).thenReturn(users.get(i));
    }
    when(perunBlMock.getUsersManagerBl().getUserByMember(sessionMock, m2)).thenReturn(u2);
    when(perunBlMock.getFacilitiesManagerBl().getFacilityById(sessionMock, facility.getId())).thenReturn(facility);
    when(resourcesManagerImplMock.getAllowedMembers(sessionMock, resource)).thenReturn(members);
    resourcesManagerBl.updateAllRequiredAttributesForAllowedMembers(sessionMock, resource, services);
    for (int i = 0; i < users.size(); i++) {
        verify(attributesManagerBlMock, times(1)).setRequiredAttributes(sessionMock, services, facility, resource, users.get(i), members.get(i), true);
    }
}
Also used : User(cz.metacentrum.perun.core.api.User) Resource(cz.metacentrum.perun.core.api.Resource) ServiceAssignedToResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ServiceAssignedToResource) ArrayList(java.util.ArrayList) Service(cz.metacentrum.perun.core.api.Service) Facility(cz.metacentrum.perun.core.api.Facility) Member(cz.metacentrum.perun.core.api.Member) Test(org.junit.Test)

Example 84 with Service

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

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

the class AttributesManagerBlImplUnitTests method getRequiredAttributes_services_resource_group_OnlyGroupResourceAttributes.

@Test
public void getRequiredAttributes_services_resource_group_OnlyGroupResourceAttributes() throws Exception {
    System.out.println(CLASS_NAME + "getRequiredAttributes_services_resource_group_OnlyGroupResourceAttributes");
    List<Service> services = new ArrayList<>();
    Resource resource = new Resource();
    Group group = new Group();
    Attribute groupAttribute = new Attribute();
    Attribute groupResourceAttribute = new Attribute();
    when(attrManagerImplMock.getRequiredAttributes(sessionMock, services, resource, group)).thenReturn(Collections.singletonList(groupResourceAttribute));
    when(attrManagerImplMock.getRequiredAttributes(sessionMock, services, group)).thenReturn(Collections.singletonList(groupAttribute));
    List<Attribute> attributes = attrManagerBlImpl.getRequiredAttributes(sessionMock, services, resource, group, false);
    assertThat(attributes).containsOnly(groupResourceAttribute);
}
Also used : Group(cz.metacentrum.perun.core.api.Group) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) ArrayList(java.util.ArrayList) Resource(cz.metacentrum.perun.core.api.Resource) Service(cz.metacentrum.perun.core.api.Service) Test(org.junit.Test)

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