use of cz.metacentrum.perun.core.api.ServiceAttributes in project perun by CESNET.
the class ServicesManagerEntryIntegrationTest method getDataWithGroups.
// TODO getFlatData() - not implemented yet
@Test
public void getDataWithGroups() throws Exception {
vo = setUpVo();
facility = setUpFacility();
resource = setUpResource();
service = setUpService();
member = setUpMember();
group = setUpGroup();
perun.getGroupsManager().addMember(sess, group, member);
perun.getResourcesManager().assignGroupToResource(sess, group, resource);
// set element's name/id as required attributes to get some attributes for every element
Attribute reqFacAttr;
reqFacAttr = perun.getAttributesManager().getAttribute(sess, facility, "urn:perun:facility:attribute-def:core:name");
perun.getServicesManager().addRequiredAttribute(sess, service, reqFacAttr);
Attribute reqResAttr;
reqResAttr = perun.getAttributesManager().getAttribute(sess, resource, "urn:perun:resource:attribute-def:core:name");
perun.getServicesManager().addRequiredAttribute(sess, service, reqResAttr);
Attribute reqGrpAttr;
reqGrpAttr = perun.getAttributesManager().getAttribute(sess, group, "urn:perun:group:attribute-def:core:name");
perun.getServicesManager().addRequiredAttribute(sess, service, reqGrpAttr);
Attribute reqMemAttr;
reqMemAttr = perun.getAttributesManager().getAttribute(sess, member, "urn:perun:member:attribute-def:core:id");
perun.getServicesManager().addRequiredAttribute(sess, service, reqMemAttr);
// finally assign service
perun.getResourcesManager().assignService(sess, resource, service);
// create second (but same) resource
resource.setName("HierarchDataResource");
resource = perun.getResourcesManager().createResource(sess, resource, vo, facility);
perun.getResourcesManager().assignGroupToResource(sess, group, resource);
perun.getResourcesManager().assignService(sess, resource, service);
// get it's required attribute with value for testing purpose
Attribute reqResAttr2 = perun.getAttributesManager().getAttribute(sess, resource, "urn:perun:resource:attribute-def:core:name");
//create third resource but without service
resource.setName("HierarchDataResource2");
resource = perun.getResourcesManager().createResource(sess, resource, vo, facility);
// get it's required attribute with value for testing purpose
Attribute reqResAttr3 = perun.getAttributesManager().getAttribute(sess, resource, "urn:perun:resource:attribute-def:core:name");
/*
* Returned structure
*
* see javadoc for ServicesManager - getDataWithGroups
*
*/
List<ServiceAttributes> facilities = new ArrayList<ServiceAttributes>();
facilities.add(perun.getServicesManager().getDataWithGroups(sess, service, facility));
assertNotNull("Unable to get hierarchical data with groups", facilities);
assertTrue("Only 1 facility shoud be returned", facilities.size() == 1);
assertNotNull("returned facility shouldn't be null", facilities.get(0));
// get all required facility attributes
// = should be 1 required attribute for 1 facility
List<Attribute> facAttr = new ArrayList<Attribute>();
facAttr = facilities.get(0).getAttributes();
assertNotNull("Unable to get facility attrbutes required by service", facAttr);
assertTrue("Only 1 facility attribute should be returned", facAttr.size() == 1);
assertTrue("Our facility required attribute not returned", facAttr.contains(reqFacAttr));
// get all facility resources
// = should be 2 resources for 1 facility (3rd resource is without proper service)
List<ServiceAttributes> resources = new ArrayList<ServiceAttributes>();
resources = facilities.get(0).getChildElements();
assertNotNull("Unable to get facility resources", resources);
assertTrue("Two resource should be returned", resources.size() == 2);
assertNotNull("Our 1st resource shouldn't be null", resources.get(0));
assertNotNull("Our 2nd resource shouldn't be null", resources.get(1));
//get all attributes from all resources
List<Attribute> resAttr = new ArrayList<Attribute>();
for (int i = 0; i < resources.size(); i++) {
resAttr.addAll(resources.get(i).getAttributes());
}
assertNotNull("Unable to get required resource attrbutes", resAttr);
assertTrue("Two required resource attributes should be returned for 2 resources", resAttr.size() == 2);
assertTrue("Our 1st resource required attribute not returned", resAttr.contains(reqResAttr));
assertTrue("Our 2nd resource required attribute not returned", resAttr.contains(reqResAttr2));
assertFalse("Wrong resource returned with the others - resource without service", resAttr.contains(reqResAttr3));
// 1st are GROUPS / 2nd are MEMBERS
for (int i = 0; i < resources.size(); i++) {
List<ServiceAttributes> resElem = new ArrayList<ServiceAttributes>();
resElem = resources.get(i).getChildElements();
assertNotNull("Unable to get resource elements from resource", resElem);
assertTrue("There should be only 2 virtual nodes - groups/members", resElem.size() == 2);
//get members from resource
List<ServiceAttributes> members = new ArrayList<ServiceAttributes>();
members.addAll(resElem.get(1).getChildElements());
assertNotNull("Unable to get members from resource", members);
assertTrue("There should be 1 member from each resource", members.size() == 1);
assertNotNull("1st member shouldn't be null", members.get(0));
//get member attributes for all members on resource
List<Attribute> memAttr = new ArrayList<Attribute>();
for (int n = 0; n < members.size(); n++) {
memAttr.addAll(members.get(n).getAttributes());
}
assertNotNull("Unable to get attributes from member", memAttr);
assertTrue("There should be only 1 attribute for each member on resource", memAttr.size() == 1);
assertTrue("Should return our required member attribute", memAttr.contains(reqMemAttr));
//get groups from resource
List<ServiceAttributes> groups = new ArrayList<ServiceAttributes>();
groups.addAll(resElem.get(0).getChildElements());
assertNotNull("Unable to get groups from resource", groups);
assertTrue("There should be only 1 group on each resource", groups.size() == 1);
//get group attributes for all 1st level groups on resource
List<Attribute> grpAttr = new ArrayList<Attribute>();
for (int n = 0; n < groups.size(); n++) {
grpAttr.addAll(groups.get(n).getAttributes());
}
assertNotNull("Unable to get group attributes from resource", grpAttr);
assertTrue("There should be 1 group on each resource", grpAttr.size() == 1);
assertNotNull("Group attribute shouldn't be null", grpAttr.get(0));
assertTrue("Group should contain our required attribute", grpAttr.contains(reqGrpAttr));
// 1st are SUBGROUPS - 2nd are GROUP-MEMBERS
for (int x = 0; x < groups.size(); x++) {
List<ServiceAttributes> grpElem = new ArrayList<ServiceAttributes>();
grpElem = groups.get(x).getChildElements();
assertNotNull("Unable to get group child elements", grpElem);
assertTrue("There should be 2 group child elements", grpElem.size() == 2);
//get members from group/subgroup
List<ServiceAttributes> grpMembers = new ArrayList<ServiceAttributes>();
grpMembers.addAll(grpElem.get(1).getChildElements());
assertNotNull("Unable to get members from group/subgroup", grpMembers);
assertTrue("There should be only one member", grpMembers.size() == 1);
//assertTrue("Member in group should be also on resource",members.contains(grpMembers.get(0)));
// unable to test that, objects are uncomparable
//get member attributes from group/subgroup
List<Attribute> grpMemAttr = new ArrayList<Attribute>();
for (int n = 0; n < grpMembers.size(); n++) {
grpMemAttr.addAll(grpMembers.get(n).getAttributes());
}
assertNotNull("Unable to get members attributes from group", grpMemAttr);
assertTrue("There should be 1 member from each group", grpMemAttr.size() == 1);
assertNotNull("1st member attribute shouldn't be null", grpMemAttr.get(0));
//get all subgroups from group on resource
List<ServiceAttributes> grpGroups = new ArrayList<ServiceAttributes>();
grpGroups.addAll(grpElem.get(0).getChildElements());
assertNotNull("Unable to get subgroups from group/subgroup", grpGroups);
assertTrue("There shouldn't be any subgroups", grpGroups.size() == 0);
// no subgroup => no reason to get their attributes, members and subgroups
}
// end of all groups on resource
}
// end of all resource
}
use of cz.metacentrum.perun.core.api.ServiceAttributes in project perun by CESNET.
the class ServicesManagerEntryIntegrationTest method getHierarchicalData.
@Test
public void getHierarchicalData() throws Exception {
System.out.println(CLASS_NAME + "getHierarchicalData");
vo = setUpVo();
facility = setUpFacility();
resource = setUpResource();
service = setUpService();
member = setUpMember();
group = setUpGroup();
perun.getGroupsManager().addMember(sess, group, member);
perun.getResourcesManager().assignGroupToResource(sess, group, resource);
// set element's name/id as required attributes to get some attributes for every element
Attribute reqFacAttr;
reqFacAttr = perun.getAttributesManager().getAttribute(sess, facility, "urn:perun:facility:attribute-def:core:name");
perun.getServicesManager().addRequiredAttribute(sess, service, reqFacAttr);
Attribute reqResAttr;
reqResAttr = perun.getAttributesManager().getAttribute(sess, resource, "urn:perun:resource:attribute-def:core:name");
perun.getServicesManager().addRequiredAttribute(sess, service, reqResAttr);
Attribute reqMemAttr;
reqMemAttr = perun.getAttributesManager().getAttribute(sess, member, "urn:perun:member:attribute-def:core:id");
perun.getServicesManager().addRequiredAttribute(sess, service, reqMemAttr);
// finally assign service
perun.getResourcesManager().assignService(sess, resource, service);
// create second (but same) resource
resource.setName("HierarchDataResource");
resource = perun.getResourcesManager().createResource(sess, resource, vo, facility);
perun.getResourcesManager().assignGroupToResource(sess, group, resource);
perun.getResourcesManager().assignService(sess, resource, service);
// get it's required attribute with value for testing purpose
Attribute reqResAttr2 = perun.getAttributesManager().getAttribute(sess, resource, "urn:perun:resource:attribute-def:core:name");
//create third resource but without service
resource.setName("HierarchDataResource2");
resource = perun.getResourcesManager().createResource(sess, resource, vo, facility);
// get it's required attribute with value for testing purpose
Attribute reqResAttr3 = perun.getAttributesManager().getAttribute(sess, resource, "urn:perun:resource:attribute-def:core:name");
/*
* expected returned structure is:
*
* facility(+attributes) - resource1(+attributes) - member(+attributes)
* - resource2(+attributes) - member(+attributes)
* - (third resource not returned = without service)
*
* etc...
*
*/
// get data for facility and service
// = should be one node (facility)
List<ServiceAttributes> facilities = new ArrayList<ServiceAttributes>();
facilities.add(perun.getServicesManager().getHierarchicalData(sess, service, facility));
assertNotNull("Unable to get hierarchical data", facilities);
assertTrue("Only 1 facility shoud be returned", facilities.size() == 1);
assertNotNull("returned facility shouldn't be null", facilities.get(0));
// get all required facility attributes
// = should be 1 required attribute for 1 facility
List<Attribute> facAttr = new ArrayList<Attribute>();
facAttr = facilities.get(0).getAttributes();
assertNotNull("Unable to get facility attrbutes required by service", facAttr);
assertTrue("Only 1 facility attribute should be returned", facAttr.size() == 1);
assertTrue("Our facility required attribute not returned", facAttr.contains(reqFacAttr));
// get all facility resources
// = should be 2 resources for 1 facility (3rd resource is without proper service)
List<ServiceAttributes> resources = new ArrayList<ServiceAttributes>();
resources = facilities.get(0).getChildElements();
assertNotNull("Unable to get facility resources", resources);
assertTrue("Two resource should be returned", resources.size() == 2);
assertNotNull("Our 1st resource shouldn't be null", resources.get(0));
assertNotNull("Our 2nd resource shouldn't be null", resources.get(1));
// get all required attributes for all resources on facility
// should be 1 attribute per resource = total 2 for 2 resource
List<Attribute> resAttr = new ArrayList<Attribute>();
for (int i = 0; i < resources.size(); i++) {
resAttr.addAll(resources.get(i).getAttributes());
}
assertNotNull("Unable to get required resource attrbutes", resAttr);
assertTrue("Two required resource attributes should be returned for 2 resources", resAttr.size() == 2);
assertTrue("Our 1st resource required attribute not returned", resAttr.contains(reqResAttr));
assertTrue("Our 2nd resource required attribute not returned", resAttr.contains(reqResAttr2));
assertFalse("Wrong resource returned with the others - resource without service", resAttr.contains(reqResAttr3));
// get all members from all resources on facility
// = we will get same attribute twice because member is on both resources
List<ServiceAttributes> members = new ArrayList<ServiceAttributes>();
for (int i = 0; i < resources.size(); i++) {
members.addAll(resources.get(i).getChildElements());
}
assertNotNull("Unable to get members from resource", members);
assertTrue("There should be 1 member from each resource (all same)", members.size() == resources.size());
assertNotNull("1st member shouldn't be null", members.get(0));
assertNotNull("2nd member shouldn't be null", members.get(1));
// get all required attributes for all members at all resources on facility
// = there should be two same attributes, from same member on 2 resources
List<Attribute> memAttr = new ArrayList<Attribute>();
for (int i = 0; i < members.size(); i++) {
memAttr.addAll(members.get(i).getAttributes());
}
assertNotNull("Unable to get member attrbutes required for service", memAttr);
assertTrue("Only one member attribute should be returned for each member", memAttr.size() == members.size());
assertEquals("Wrong attribute returned for 1st member", memAttr.get(0), reqMemAttr);
assertEquals("Wrong attribute returned for 2nd member", memAttr.get(1), reqMemAttr);
assertEquals("Both attributes (members) should be same", memAttr.get(0), memAttr.get(1));
}
use of cz.metacentrum.perun.core.api.ServiceAttributes in project perun by CESNET.
the class ServicesManagerBlImpl method getData.
private ServiceAttributes getData(PerunSession sess, Service service, Facility facility, Resource resource, Group group, Map<Member, ServiceAttributes> memberAttributes) throws InternalErrorException {
ServiceAttributes groupServiceAttributes = new ServiceAttributes();
try {
groupServiceAttributes.addAttributes(getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, resource, group, true));
} catch (WrongAttributeAssignmentException ex) {
throw new InternalErrorException(ex);
}
ServiceAttributes groupsSubGroupsElement = new ServiceAttributes();
// FIXME Do not get subgroups of the members group
if (!group.getName().equals(VosManager.MEMBERS_GROUP)) {
List<Group> subGroups = getPerunBl().getGroupsManagerBl().getSubGroups(sess, group);
for (Group subGroup : subGroups) {
groupsSubGroupsElement.addChildElement(getData(sess, service, facility, resource, subGroup, memberAttributes));
}
}
ServiceAttributes groupsMembersElement = new ServiceAttributes();
//Invalid and disabled are not allowed here
List<Member> members = getPerunBl().getGroupsManagerBl().getGroupMembersExceptInvalidAndDisabled(sess, group);
for (Member member : members) {
groupsMembersElement.addChildElement(memberAttributes.get(member));
}
groupServiceAttributes.addChildElement(groupsSubGroupsElement);
groupServiceAttributes.addChildElement(groupsMembersElement);
return groupServiceAttributes;
}
use of cz.metacentrum.perun.core.api.ServiceAttributes in project perun by CESNET.
the class ServicesManagerBlImpl method getDataWithGroups.
public ServiceAttributes getDataWithGroups(PerunSession sess, Service service, Facility facility) throws InternalErrorException {
ServiceAttributes serviceAttributes = new ServiceAttributes();
serviceAttributes.addAttributes(getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, facility));
List<Resource> resources = getPerunBl().getFacilitiesManagerBl().getAssignedResources(sess, facility);
resources.retainAll(getAssignedResources(sess, service));
for (Resource resource : resources) {
ServiceAttributes resourceServiceAttributes = getDataWithGroups(sess, service, facility, resource);
serviceAttributes.addChildElement(resourceServiceAttributes);
}
return serviceAttributes;
}
use of cz.metacentrum.perun.core.api.ServiceAttributes in project perun by CESNET.
the class ServicesManagerBlImpl method getDataWithVos.
public ServiceAttributes getDataWithVos(PerunSession sess, Service service, Facility facility) throws InternalErrorException, VoNotExistsException {
ServiceAttributes serviceAttributes = new ServiceAttributes();
serviceAttributes.addAttributes(getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, facility));
//Get resources only for facility and service
List<Resource> resources = getPerunBl().getFacilitiesManagerBl().getAssignedResources(sess, facility);
resources.retainAll(getAssignedResources(sess, service));
//Get all vos for these resources
Set<Integer> vosIds = new HashSet<>();
for (Resource resource : resources) {
vosIds.add(resource.getVoId());
}
List<Vo> vos = new ArrayList<>();
for (Integer voId : vosIds) {
vos.add(getPerunBl().getVosManagerBl().getVoById(sess, voId));
}
for (Vo vo : vos) {
List<Resource> voResources = getPerunBl().getResourcesManagerBl().getResources(sess, vo);
voResources.retainAll(resources);
ServiceAttributes voServiceAttributes = getDataWithVo(sess, service, facility, vo, voResources);
serviceAttributes.addChildElement(voServiceAttributes);
}
return serviceAttributes;
}
Aggregations