Search in sources :

Example 1 with HashedGenData

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

the class ServicesManagerEntryIntegrationTest method testGetHashedDataWithGroups.

@Test
public void testGetHashedDataWithGroups() throws Exception {
    System.out.println(CLASS_NAME + "testGetHashedDataWithGroups");
    vo = setUpVo();
    facility = setUpFacility();
    resource = setUpResource();
    service = setUpService();
    member = setUpMember();
    group = setUpGroup();
    perun.getGroupsManager().addMember(sess, group, member);
    perun.getResourcesManager().assignGroupToResource(sess, group, resource, false, false, false);
    // set element's name/id as required attributes to get some attributes for every element
    Attribute reqFacAttr;
    reqFacAttr = perun.getAttributesManager().getAttribute(sess, facility, A_F_C_NAME);
    perun.getServicesManager().addRequiredAttribute(sess, service, reqFacAttr);
    Attribute reqResAttr;
    reqResAttr = perun.getAttributesManager().getAttribute(sess, resource, A_R_C_NAME);
    perun.getServicesManager().addRequiredAttribute(sess, service, reqResAttr);
    Attribute reqGrpAttr;
    reqGrpAttr = perun.getAttributesManager().getAttribute(sess, group, A_G_C_NAME);
    perun.getServicesManager().addRequiredAttribute(sess, service, reqGrpAttr);
    Attribute reqMemAttr;
    reqMemAttr = perun.getAttributesManager().getAttribute(sess, member, A_M_C_ID);
    perun.getServicesManager().addRequiredAttribute(sess, service, reqMemAttr);
    Attribute reqVoAttr;
    reqVoAttr = perun.getAttributesManager().getAttribute(sess, vo, A_V_C_ID);
    perun.getServicesManager().addRequiredAttribute(sess, service, reqVoAttr);
    // finally assign service
    perun.getResourcesManager().assignService(sess, resource, service);
    // create second (but same) resource
    Resource resource2 = new Resource();
    resource2.setName("HierarchDataResource");
    resource2 = perun.getResourcesManager().createResource(sess, resource2, vo, facility);
    perun.getResourcesManager().assignGroupToResource(sess, group, resource2, false, false, false);
    perun.getResourcesManager().assignService(sess, resource2, service);
    // create third resource but without service
    Resource resource3 = new Resource();
    resource3.setName("HierarchDataResource2");
    resource3 = perun.getResourcesManager().createResource(sess, resource3, vo, facility);
    HashedGenData data = perun.getServicesManagerBl().getHashedDataWithGroups(sess, service, facility, false);
    assertThat(data.getAttributes()).isNotEmpty();
    Map<String, Map<String, Object>> attributes = data.getAttributes();
    String facilityAttrsHash = "f-" + facility.getId();
    String memberAttrsHash = "m-" + member.getId();
    String groupAttrsHash = "g-" + group.getId();
    String voAttrsHash = "v-" + vo.getId();
    String resource1AttrsHash = "r-" + resource.getId();
    String resource2AttrsHash = "r-" + resource2.getId();
    // Verify that the list of all attributes contains correct attributes
    assertThat(attributes).containsOnlyKeys(facilityAttrsHash, memberAttrsHash, resource1AttrsHash, groupAttrsHash, resource2AttrsHash, voAttrsHash);
    Map<String, Object> facilityAttributes = attributes.get(facilityAttrsHash);
    assertThat(facilityAttributes).hasSize(1);
    assertThat(facilityAttributes.get(A_F_C_NAME)).isEqualTo(facility.getName());
    Map<String, Object> memberAttributes = attributes.get(memberAttrsHash);
    assertThat(memberAttributes).hasSize(1);
    assertThat(memberAttributes.get(A_M_C_ID)).isEqualTo(member.getId());
    Map<String, Object> groupAttributes = attributes.get(groupAttrsHash);
    assertThat(groupAttributes).hasSize(1);
    assertThat(groupAttributes.get(A_G_C_NAME)).isEqualTo(group.getName());
    Map<String, Object> resource1Attributes = attributes.get(resource1AttrsHash);
    assertThat(resource1Attributes).hasSize(1);
    assertThat(resource1Attributes.get(A_R_C_NAME)).isEqualTo(resource.getName());
    Map<String, Object> voAttributes = attributes.get(voAttrsHash);
    assertThat(voAttributes).hasSize(1);
    assertThat(voAttributes.get(A_V_C_ID)).isEqualTo(vo.getId());
    Map<String, Object> resource2Attributes = attributes.get(resource2AttrsHash);
    assertThat(resource2Attributes).hasSize(1);
    assertThat(resource2Attributes.get(A_R_C_NAME)).isEqualTo(resource2.getName());
    // verify hierarchy
    GenDataNode facilityNode = data.getHierarchy().get(facility.getId());
    assertThat(facilityNode.getMembers()).hasSize(1);
    assertThat(facilityNode.getChildren()).hasSize(2);
    GenDataNode res1Node = facilityNode.getChildren().get(resource.getId());
    assertThat(res1Node.getMembers()).hasSize(1);
    assertThat(res1Node.getChildren()).hasSize(1);
    assertThat(((GenResourceDataNode) res1Node).getVoId()).isEqualTo(vo.getId());
    assertThat(res1Node.getMembers()).containsKey(member.getId());
    GenDataNode res2Node = facilityNode.getChildren().get(resource2.getId());
    assertThat(res2Node.getMembers()).hasSize(1);
    assertThat(res2Node.getChildren()).hasSize(1);
    assertThat(((GenResourceDataNode) res2Node).getVoId()).isEqualTo(vo.getId());
    assertThat(res2Node.getMembers()).containsKey(member.getId());
    GenDataNode res1GroupNode = res1Node.getChildren().get(group.getId());
    assertThat(res1GroupNode.getChildren()).isEmpty();
    assertThat(res1GroupNode.getMembers()).hasSize(1);
    assertThat(res1GroupNode.getMembers()).containsKey(member.getId());
    GenDataNode res2GroupNode = res2Node.getChildren().get(group.getId());
    assertThat(res2GroupNode.getChildren()).isEmpty();
    assertThat(res2GroupNode.getMembers()).hasSize(1);
    assertThat(res2GroupNode.getMembers()).containsKey(member.getId());
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) GenDataNode(cz.metacentrum.perun.core.api.GenDataNode) Resource(cz.metacentrum.perun.core.api.Resource) GenResourceDataNode(cz.metacentrum.perun.core.api.GenResourceDataNode) Map(java.util.Map) HashMap(java.util.HashMap) HashedGenData(cz.metacentrum.perun.core.api.HashedGenData) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 2 with HashedGenData

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

the class HierarchicalHashedDataGenerator method generateData.

@Override
public HashedGenData generateData() {
    dataProvider.loadFacilityAttributes();
    List<Resource> resources = sess.getPerunBl().getFacilitiesManagerBl().getAssignedResources(sess, facility, null, service);
    Map<Integer, GenDataNode> childNodes = resources.stream().collect(toMap(Resource::getId, this::getDataForResource));
    dataProvider.getFacilityAttributesHashes();
    Map<String, Map<String, Object>> attributes = dataProvider.getAllFetchedAttributes();
    Map<Integer, Integer> memberIdsToUserIds = allMembers.stream().collect(toMap(Member::getId, Member::getUserId));
    GenDataNode root = new GenDataNode.Builder().children(childNodes).members(memberIdsToUserIds).build();
    return new HashedGenData(attributes, root, facility.getId());
}
Also used : GenDataNode(cz.metacentrum.perun.core.api.GenDataNode) Resource(cz.metacentrum.perun.core.api.Resource) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) HashedGenData(cz.metacentrum.perun.core.api.HashedGenData)

Example 3 with HashedGenData

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

the class GroupsHashedDataGenerator method generateData.

@Override
public HashedGenData generateData() {
    dataProvider.loadFacilityAttributes();
    List<Resource> resources = sess.getPerunBl().getFacilitiesManagerBl().getAssignedResources(sess, facility, null, service);
    Map<Integer, GenDataNode> childNodes = resources.stream().collect(toMap(Resource::getId, this::getDataForResource));
    dataProvider.getFacilityAttributesHashes();
    Map<String, Map<String, Object>> attributes = dataProvider.getAllFetchedAttributes();
    Map<Integer, Integer> memberIdsToUserIds = allMembers.stream().collect(toMap(Member::getId, Member::getUserId));
    GenDataNode root = new GenDataNode.Builder().children(childNodes).members(memberIdsToUserIds).build();
    return new HashedGenData(attributes, root, facility.getId());
}
Also used : GenDataNode(cz.metacentrum.perun.core.api.GenDataNode) Resource(cz.metacentrum.perun.core.api.Resource) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) HashedGenData(cz.metacentrum.perun.core.api.HashedGenData)

Example 4 with HashedGenData

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

the class ServicesManagerEntryIntegrationTest method testGetHashedHierarchicalData.

@Test
public void testGetHashedHierarchicalData() throws Exception {
    System.out.println(CLASS_NAME + "testGetHashedHierarchicalData");
    vo = setUpVo();
    facility = setUpFacility();
    resource = setUpResource();
    service = setUpService();
    member = setUpMember();
    group = setUpGroup();
    perun.getGroupsManager().addMember(sess, group, member);
    perun.getResourcesManager().assignGroupToResource(sess, group, resource, false, false, false);
    // set element's name/id as required attributes to get some attributes for every element
    Attribute reqFacAttr;
    reqFacAttr = perun.getAttributesManager().getAttribute(sess, facility, A_F_C_NAME);
    perun.getServicesManager().addRequiredAttribute(sess, service, reqFacAttr);
    Attribute reqResAttr;
    reqResAttr = perun.getAttributesManager().getAttribute(sess, resource, A_R_C_NAME);
    perun.getServicesManager().addRequiredAttribute(sess, service, reqResAttr);
    Attribute reqGrpAttr;
    reqGrpAttr = perun.getAttributesManager().getAttribute(sess, group, A_G_C_NAME);
    perun.getServicesManager().addRequiredAttribute(sess, service, reqGrpAttr);
    Attribute reqMemAttr;
    reqMemAttr = perun.getAttributesManager().getAttribute(sess, member, A_M_C_ID);
    perun.getServicesManager().addRequiredAttribute(sess, service, reqMemAttr);
    Attribute reqVoAttr;
    reqVoAttr = perun.getAttributesManager().getAttribute(sess, vo, A_V_C_ID);
    perun.getServicesManager().addRequiredAttribute(sess, service, reqVoAttr);
    // finally assign service
    perun.getResourcesManager().assignService(sess, resource, service);
    // create second (but same) resource
    Resource resource2 = new Resource();
    resource2.setName("HierarchDataResource");
    resource2 = perun.getResourcesManager().createResource(sess, resource2, vo, facility);
    perun.getResourcesManager().assignGroupToResource(sess, group, resource2, false, false, false);
    perun.getResourcesManager().assignService(sess, resource2, service);
    // create third resource but without service
    Resource resource3 = new Resource();
    resource3.setName("HierarchDataResource2");
    resource3 = perun.getResourcesManager().createResource(sess, resource3, vo, facility);
    HashedGenData data = perun.getServicesManagerBl().getHashedHierarchicalData(sess, service, facility, false);
    assertThat(data.getAttributes()).isNotEmpty();
    Map<String, Map<String, Object>> attributes = data.getAttributes();
    String facilityAttrsHash = "f-" + facility.getId();
    String memberAttrsHash = "m-" + member.getId();
    String groupAttrsHash = "g-" + group.getId();
    String voAttrsHash = "v-" + vo.getId();
    String resource1AttrsHash = "r-" + resource.getId();
    String resource2AttrsHash = "r-" + resource2.getId();
    String resource3AttrsHash = "r-" + resource3.getId();
    // Verify that the list of all attributes contains correct attributes
    assertThat(attributes).containsOnlyKeys(facilityAttrsHash, memberAttrsHash, resource1AttrsHash, resource2AttrsHash, voAttrsHash);
    Map<String, Object> facilityAttributes = attributes.get(facilityAttrsHash);
    assertThat(facilityAttributes).hasSize(1);
    assertThat(facilityAttributes.get(A_F_C_NAME)).isEqualTo(facility.getName());
    Map<String, Object> memberAttributes = attributes.get(memberAttrsHash);
    assertThat(memberAttributes).hasSize(1);
    assertThat(memberAttributes.get(A_M_C_ID)).isEqualTo(member.getId());
    Map<String, Object> voAttributes = attributes.get(voAttrsHash);
    assertThat(voAttributes).hasSize(1);
    assertThat(voAttributes.get(A_V_C_ID)).isEqualTo(vo.getId());
    Map<String, Object> resource1Attributes = attributes.get(resource1AttrsHash);
    assertThat(resource1Attributes).hasSize(1);
    assertThat(resource1Attributes.get(A_R_C_NAME)).isEqualTo(resource.getName());
    Map<String, Object> resource2Attributes = attributes.get(resource2AttrsHash);
    assertThat(resource2Attributes).hasSize(1);
    assertThat(resource2Attributes.get(A_R_C_NAME)).isEqualTo(resource2.getName());
    // verify hierarchy
    GenDataNode facilityNode = data.getHierarchy().get(facility.getId());
    assertThat(facilityNode.getMembers()).hasSize(1);
    assertThat(facilityNode.getChildren()).hasSize(2);
    GenDataNode res1Node = facilityNode.getChildren().get(resource.getId());
    assertThat(res1Node.getMembers().keySet()).hasSize(1);
    assertThat(((GenResourceDataNode) res1Node).getVoId()).isEqualTo(vo.getId());
    assertThat(res1Node.getChildren()).isEmpty();
    assertThat(res1Node.getMembers()).containsKey(member.getId());
    GenDataNode res2Node = facilityNode.getChildren().get(resource2.getId());
    assertThat(((GenResourceDataNode) res2Node).getVoId()).isEqualTo(vo.getId());
    assertThat(res2Node.getMembers()).hasSize(1);
    assertThat(res2Node.getChildren()).isEmpty();
    assertThat(res2Node.getMembers()).containsKey(member.getId());
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) GenDataNode(cz.metacentrum.perun.core.api.GenDataNode) Resource(cz.metacentrum.perun.core.api.Resource) GenResourceDataNode(cz.metacentrum.perun.core.api.GenResourceDataNode) Map(java.util.Map) HashMap(java.util.HashMap) HashedGenData(cz.metacentrum.perun.core.api.HashedGenData) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Aggregations

GenDataNode (cz.metacentrum.perun.core.api.GenDataNode)4 HashedGenData (cz.metacentrum.perun.core.api.HashedGenData)4 Resource (cz.metacentrum.perun.core.api.Resource)4 Map (java.util.Map)4 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)2 Attribute (cz.metacentrum.perun.core.api.Attribute)2 GenResourceDataNode (cz.metacentrum.perun.core.api.GenResourceDataNode)2 HashMap (java.util.HashMap)2 Collectors.toMap (java.util.stream.Collectors.toMap)2 Test (org.junit.Test)2