use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.
the class ModulesUtilsBlImpl method getFreeGID.
@Override
public Integer getFreeGID(PerunSessionImpl sess, Attribute attribute) throws AttributeNotExistsException, WrongAttributeAssignmentException {
Utils.notNull(attribute, "attribute");
String gidNamespace = attribute.getFriendlyNameParameter();
Attribute gidRangesAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, gidNamespace, A_E_namespace_GIDRanges);
if (gidRangesAttribute.getValue() == null)
return 0;
Map<Integer, Integer> gidRanges;
try {
gidRanges = checkAndConvertIDRanges(gidRangesAttribute);
} catch (WrongAttributeValueException ex) {
throw new InternalErrorException("Value in GID ranges attribute where we are looking for free gid is not in correct format " + gidRangesAttribute, ex);
}
if (gidRanges.isEmpty())
return 0;
List<Integer> allMinimums = gidRanges.keySet().stream().sorted().collect(Collectors.toList());
List<Integer> allGids = new ArrayList<>();
Attribute usedGids = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, gidNamespace, A_E_usedGids);
// return the minimum from all ranges
if (usedGids.getValue() == null)
return allMinimums.get(0);
else {
Map<String, String> usedGidsValue = usedGids.valueAsMap();
Set<String> keys = usedGidsValue.keySet();
for (String key : keys) {
allGids.add(Integer.parseInt(usedGidsValue.get(key)));
}
}
for (Integer minimum : allMinimums) {
Integer maximum = gidRanges.get(minimum);
for (int i = minimum; i <= maximum; i++) {
if (!allGids.contains(i)) {
return i;
}
}
}
return null;
}
use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.
the class ModulesUtilsBlImpl method findCollisionResourcesWithSameGid.
public List<Resource> findCollisionResourcesWithSameGid(PerunSessionImpl sess, Resource resource, String namespace) throws WrongAttributeAssignmentException, AttributeNotExistsException {
Utils.notNull(sess, "perunSessionImpl");
Utils.notNull(resource, "resource");
Utils.notNull(namespace, "namespace");
Attribute resourceUnixGid = getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, A_R_unixGID_namespace + ":" + namespace);
List<Resource> resourcesWithSameGid = getPerunBl().getResourcesManagerBl().getResourcesByAttribute(sess, resourceUnixGid);
resourcesWithSameGid.remove(resource);
return resourcesWithSameGid;
}
use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.
the class ModulesUtilsBlImpl method findCollisionResourcesWithSameGroupName.
public List<Resource> findCollisionResourcesWithSameGroupName(PerunSessionImpl sess, Resource resource, String namespace) throws WrongAttributeAssignmentException, AttributeNotExistsException {
Utils.notNull(sess, "perunSessionImpl");
Utils.notNull(resource, "resource");
Attribute resourceUnixGroupName = getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, A_R_unixGroupName_namespace + ":" + namespace);
List<Resource> resourcesWithSameUnixGroupName = getPerunBl().getResourcesManagerBl().getResourcesByAttribute(sess, resourceUnixGroupName);
resourcesWithSameUnixGroupName.remove(resource);
return resourcesWithSameUnixGroupName;
}
use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.
the class ModulesUtilsBlImpl method getCommonGIDOfGroupsWithSameNameInSameNamespace.
@Override
public Integer getCommonGIDOfGroupsWithSameNameInSameNamespace(PerunSessionImpl sess, List<Group> groupsWithSameGroupNameInSameNamespace, String gidNamespace, Integer commonGID) throws WrongAttributeAssignmentException {
// If there are no groups, return commonGID from param (it can be null)
if (groupsWithSameGroupNameInSameNamespace == null || groupsWithSameGroupNameInSameNamespace.isEmpty())
return commonGID;
Utils.notNull(gidNamespace, "gidNamespace");
// only for more verbose exception messages
Group commonGIDGroup = null;
for (Group g : groupsWithSameGroupNameInSameNamespace) {
try {
Attribute attr = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, g, A_G_unixGID_namespace + ":" + gidNamespace);
if (attr.getValue() != null) {
if (commonGID == null) {
commonGIDGroup = g;
commonGID = (Integer) attr.getValue();
} else {
if (!commonGID.equals(attr.getValue()))
throw new ConsistencyErrorException("There are at least 1 groups/resources with same GroupName in same namespace but with different GID in same namespaces. Conflict found: " + g + "(gid=" + attr.getValue() + ") and " + commonGIDGroup + "(gid=" + commonGID + ")");
}
}
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
}
}
return commonGID;
}
use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.
the class ModulesUtilsBlImpl method getCommonGIDOfResourcesWithSameNameInSameNamespace.
@Override
public Integer getCommonGIDOfResourcesWithSameNameInSameNamespace(PerunSessionImpl sess, List<Resource> resourcesWithSameGroupNameInSameNamespace, String gidNamespace, Integer commonGID) throws WrongAttributeAssignmentException {
// If there are no resources, return commonGID from param (it can be null)
if (resourcesWithSameGroupNameInSameNamespace == null || resourcesWithSameGroupNameInSameNamespace.isEmpty())
return commonGID;
Utils.notNull(gidNamespace, "gidNamespace");
// only for more verbose exception messages
Resource commonGIDResource = null;
for (Resource r : resourcesWithSameGroupNameInSameNamespace) {
try {
Attribute attr = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, r, A_R_unixGID_namespace + ":" + gidNamespace);
if (attr.getValue() != null) {
if (commonGID == null) {
commonGIDResource = r;
commonGID = (Integer) attr.getValue();
} else {
if (!commonGID.equals(attr.getValue()))
throw new ConsistencyErrorException("There are at least 1 groups/resources with same GroupName in same namespace but with different GID in same namespaces. Conflict found: " + r + "(gid=" + attr.getValue() + ") and " + commonGIDResource + "(gid=" + commonGID + ")");
}
}
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
}
}
return commonGID;
}
Aggregations