use of cz.metacentrum.perun.core.api.Resource in project perun by CESNET.
the class ServicesManagerBlImpl method getFlatData.
public ServiceAttributes getFlatData(PerunSession sess, Service service, Facility facility) throws InternalErrorException {
ServiceAttributes serviceAttributes = new ServiceAttributes();
serviceAttributes.addAttributes(getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, facility));
ServiceAttributes allResourcesServiceAttributes = new ServiceAttributes();
List<Resource> facilityResources = getPerunBl().getFacilitiesManagerBl().getAssignedResources(sess, facility);
facilityResources.retainAll(getAssignedResources(sess, service));
for (Resource resource : facilityResources) {
ServiceAttributes resourceServiceAttributes = new ServiceAttributes();
resourceServiceAttributes.addAttributes(getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, resource));
allResourcesServiceAttributes.addChildElement(resourceServiceAttributes);
}
ServiceAttributes allUsersServiceAttributes = new ServiceAttributes();
List<User> facilityUsers = getPerunBl().getFacilitiesManagerBl().getAllowedUsers(sess, facility, null, service);
// get attributes for all users at once !
HashMap<User, List<Attribute>> userFacilityAttributes = getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, facility, facilityUsers);
HashMap<User, List<Attribute>> userAttributes = getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, facilityUsers);
for (User user : facilityUsers) {
ServiceAttributes userServiceAttributes = new ServiceAttributes();
// Depending on a service requirements we might get null user or user-facility attributes
if (userAttributes.get(user) != null)
userServiceAttributes.addAttributes(userAttributes.get(user));
if (userFacilityAttributes.get(user) != null)
userServiceAttributes.addAttributes(userFacilityAttributes.get(user));
allUsersServiceAttributes.addChildElement(userServiceAttributes);
}
serviceAttributes.addChildElement(allResourcesServiceAttributes);
serviceAttributes.addChildElement(allUsersServiceAttributes);
return serviceAttributes;
}
use of cz.metacentrum.perun.core.api.Resource in project perun by CESNET.
the class ServicesManagerBlImpl method getHierarchicalData.
public ServiceAttributes getHierarchicalData(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 = getData(sess, service, facility, resource);
serviceAttributes.addChildElement(resourceServiceAttributes);
}
return serviceAttributes;
}
use of cz.metacentrum.perun.core.api.Resource in project perun by CESNET.
the class VosManagerBlImpl method getVosByPerunBean.
public List<Vo> getVosByPerunBean(PerunSession sess, PerunBean perunBean) throws InternalErrorException, VoNotExistsException {
List<Vo> vos = new ArrayList<Vo>();
//All possible useful objects
Vo vo = null;
Facility facility = null;
Group group = null;
Member member = null;
User user = null;
Host host = null;
Resource resource = null;
if (perunBean != null) {
if (perunBean instanceof Vo)
vo = (Vo) perunBean;
else if (perunBean instanceof Facility)
facility = (Facility) perunBean;
else if (perunBean instanceof Group)
group = (Group) perunBean;
else if (perunBean instanceof Member)
member = (Member) perunBean;
else if (perunBean instanceof User)
user = (User) perunBean;
else if (perunBean instanceof Host)
host = (Host) perunBean;
else if (perunBean instanceof Resource)
resource = (Resource) perunBean;
else {
throw new InternalErrorException("There is unrecognized object in primaryHolder of aidingAttr.");
}
} else {
throw new InternalErrorException("Aiding attribtue must have primaryHolder which is not null.");
}
if (group != null) {
vos.add(getPerunBl().getVosManagerBl().getVoById(sess, group.getVoId()));
} else if (member != null) {
vos.add(getPerunBl().getMembersManagerBl().getMemberVo(sess, member));
} else if (resource != null) {
vos.add(getPerunBl().getVosManagerBl().getVoById(sess, resource.getVoId()));
} else if (user != null) {
vos.addAll(getPerunBl().getUsersManagerBl().getVosWhereUserIsMember(sess, user));
} else if (host != null) {
facility = getPerunBl().getFacilitiesManagerBl().getFacilityForHost(sess, host);
vos.addAll(getPerunBl().getFacilitiesManagerBl().getAllowedVos(sess, facility));
} else if (facility != null) {
vos.addAll(getPerunBl().getFacilitiesManagerBl().getAllowedVos(sess, facility));
} else if (vo != null) {
vos.add(vo);
}
vos = new ArrayList<Vo>(new HashSet<Vo>(vos));
return vos;
}
use of cz.metacentrum.perun.core.api.Resource in project perun by CESNET.
the class urn_perun_group_attribute_def_def_unixGID_namespace method fillAttribute.
public Attribute fillAttribute(PerunSessionImpl sess, Group group, AttributeDefinition attributeDefinition) throws InternalErrorException, WrongAttributeAssignmentException {
Attribute attribute = new Attribute(attributeDefinition);
String gidNamespace = attribute.getFriendlyNameParameter();
//First check if generating is needed (if fill make a sense)
//Get All Facilities from group
Set<Facility> facilitiesOfGroup = new HashSet<Facility>();
List<Resource> resourcesOfGroup = sess.getPerunBl().getResourcesManagerBl().getAssignedResources(sess, group);
for (Resource r : resourcesOfGroup) {
facilitiesOfGroup.add(sess.getPerunBl().getResourcesManagerBl().getFacility(sess, r));
}
//Prepare list of gid namespaces of all facilities which have the same groupName namespace like this unixGroupName namespace
Set<String> groupNameNamespaces;
try {
groupNameNamespaces = sess.getPerunBl().getModulesUtilsBl().getSetOfGroupNameNamespacesWhereFacilitiesHasTheSameGIDNamespace(sess, new ArrayList<Facility>(facilitiesOfGroup), attribute);
} catch (WrongReferenceAttributeValueException ex) {
//TODO: need to add WrongAttributeAssignmentException to header of modules methods
throw new InternalErrorException(ex);
}
//If this group has GroupName-namespace attribute with notNull value in any namespace from groupNameNamespaces, continue, else return attribute with null value
try {
if (!sess.getPerunBl().getModulesUtilsBl().isGroupUnixGIDNamespaceFillable(sess, group, attribute))
return attribute;
} catch (WrongReferenceAttributeValueException ex) {
throw new ConsistencyErrorException(ex);
}
//After check I get all GroupNames of this group (for any namespaces)
List<Attribute> groupNamesOfGroup = sess.getPerunBl().getAttributesManagerBl().getAllAttributesStartWithNameWithoutNullValue(sess, group, A_G_unixGroupName_namespace + ":");
//If there exist some groupName of this group
if (!groupNamesOfGroup.isEmpty()) {
//Get All Groups and Resources with some same GroupName in the same Namespace
Set<Group> groupsWithSameGroupNameInSameNamespace = new HashSet<Group>();
Set<Resource> resourcesWithSameGroupNameInSameNamespace = new HashSet<Resource>();
for (Attribute attr : groupNamesOfGroup) {
Attribute groupNameOfResource;
try {
groupNameOfResource = new Attribute(sess.getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, A_R_unixGroupName_namespace + ":" + attr.getFriendlyNameParameter()));
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException("AttributeDefinition for resource_def_unixGroupName-namespace:" + attr.getFriendlyNameParameter() + " must exists", ex);
}
groupNameOfResource.setValue(attr.getValue());
//Get all resources and groups with some GroupName same with same Namespace
groupsWithSameGroupNameInSameNamespace.addAll(sess.getPerunBl().getGroupsManagerBl().getGroupsByAttribute(sess, attr));
resourcesWithSameGroupNameInSameNamespace.addAll(sess.getPerunBl().getResourcesManagerBl().getResourcesByAttribute(sess, groupNameOfResource));
}
//Prepare variable for commonGID
Integer commonGID = null;
//Test if exists common GID for this group and other groups and resources
commonGID = sess.getPerunBl().getModulesUtilsBl().getCommonGIDOfGroupsWithSameNameInSameNamespace(sess, new ArrayList(groupsWithSameGroupNameInSameNamespace), gidNamespace, commonGID);
commonGID = sess.getPerunBl().getModulesUtilsBl().getCommonGIDOfResourcesWithSameNameInSameNamespace(sess, new ArrayList(resourcesWithSameGroupNameInSameNamespace), gidNamespace, commonGID);
//If commonGID exists, set it
if (commonGID != null) {
attribute.setValue(commonGID);
return attribute;
}
}
//If commonGID not exists, try to set new one
try {
Integer freeGID = sess.getPerunBl().getModulesUtilsBl().getFreeGID(sess, attribute);
if (freeGID == null) {
//free GID not found
log.warn("Free unix gid not found for group:[" + group + "] in unix group namespace " + gidNamespace);
} else if (freeGID > 0 || freeGID < 0) {
//free GID found
attribute.setValue(freeGID);
}
return attribute;
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
}
}
use of cz.metacentrum.perun.core.api.Resource in project perun by CESNET.
the class urn_perun_user_facility_attribute_def_virt_defaultUnixGID method getAttributeValue.
@Override
public Attribute getAttributeValue(PerunSessionImpl sess, Facility facility, User user, AttributeDefinition attributeDefinition) throws InternalErrorException {
Attribute attr = new Attribute(attributeDefinition);
try {
//first phase: if attribute UF:D:defaultUnixGID is set, it has top priority
Attribute defaultUnixGID = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, user, AttributesManager.NS_USER_FACILITY_ATTR_DEF + ":defaultUnixGID");
if (defaultUnixGID.getValue() != null) {
Utils.copyAttributeToVirtualAttributeWithValue(defaultUnixGID, attr);
return attr;
}
//second phase: UF:D:defaultUnixGID is not set, module will select unix group name from preffered list
String namespace = (String) sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, AttributesManager.NS_FACILITY_ATTR_DEF + ":unixGID-namespace").getValue();
if (namespace == null) {
return attr;
}
Attribute userPreferredGroupNames = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, user, AttributesManager.NS_USER_ATTR_DEF + ":preferredUnixGroupName-namespace:" + namespace);
List<Resource> resources = sess.getPerunBl().getUsersManagerBl().getAllowedResources(sess, facility, user);
if (userPreferredGroupNames.getValue() != null) {
Map<String, Resource> resourcesWithName = new HashMap<>();
for (Resource resource : resources) {
String groupNameForTest = (String) sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, AttributesManager.NS_RESOURCE_ATTR_DEF + ":unixGroupName-namespace:" + namespace).getValue();
if (groupNameForTest != null) {
resourcesWithName.put(groupNameForTest, resource);
}
}
List<Member> userMembers = sess.getPerunBl().getMembersManagerBl().getMembersByUser(sess, user);
Map<String, Group> groupsWithName = new HashMap<>();
for (Resource resource : resources) {
List<Group> groupsFromResource = sess.getPerunBl().getGroupsManagerBl().getAssignedGroupsToResource(sess, resource);
for (Group group : groupsFromResource) {
List<Member> groupMembers = sess.getPerunBl().getGroupsManagerBl().getGroupMembers(sess, group);
groupMembers.retainAll(userMembers);
if (!groupMembers.isEmpty()) {
String groupNamesForTest = (String) sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, group, AttributesManager.NS_GROUP_ATTR_DEF + ":unixGroupName-namespace:" + namespace).getValue();
if (groupNamesForTest != null) {
groupsWithName.put(groupNamesForTest, group);
}
}
}
}
for (String pGroupName : (List<String>) userPreferredGroupNames.getValue()) {
if (resourcesWithName.containsKey(pGroupName)) {
Resource resource = resourcesWithName.get(pGroupName);
Attribute resourceUnixGID = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, AttributesManager.NS_RESOURCE_ATTR_DEF + ":unixGID-namespace:" + namespace);
if (resourceUnixGID.getValue() != null) {
Utils.copyAttributeToViAttributeWithoutValue(userPreferredGroupNames, attr);
attr.setValue(resourceUnixGID.getValue());
return attr;
}
}
if (groupsWithName.containsKey(pGroupName)) {
Group group = groupsWithName.get(pGroupName);
Attribute groupUnixGID = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, group, AttributesManager.NS_GROUP_ATTR_DEF + ":unixGID-namespace:" + namespace);
if (groupUnixGID.getValue() != null) {
Utils.copyAttributeToViAttributeWithoutValue(userPreferredGroupNames, attr);
attr.setValue(groupUnixGID.getValue());
return attr;
}
}
}
}
//third phase: Preferred unix name is not on the facility and it is choosen basicDefaultGID
Attribute basicGid = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, user, AttributesManager.NS_USER_FACILITY_ATTR_DEF + ":basicDefaultGID");
Utils.copyAttributeToVirtualAttributeWithValue(basicGid, attr);
return attr;
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
} catch (WrongAttributeAssignmentException ex) {
throw new InternalErrorException(ex);
}
}
Aggregations