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());
}
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());
}
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());
}
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());
}
Aggregations