Search in sources :

Example 91 with Attribute

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;
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 92 with Attribute

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;
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) Resource(cz.metacentrum.perun.core.api.Resource)

Example 93 with Attribute

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;
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) Resource(cz.metacentrum.perun.core.api.Resource)

Example 94 with Attribute

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;
}
Also used : Group(cz.metacentrum.perun.core.api.Group) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)

Example 95 with Attribute

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;
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) Resource(cz.metacentrum.perun.core.api.Resource)

Aggregations

Attribute (cz.metacentrum.perun.core.api.Attribute)1689 Test (org.junit.Test)615 ArrayList (java.util.ArrayList)492 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)489 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)478 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)313 User (cz.metacentrum.perun.core.api.User)301 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)280 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)231 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)221 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)218 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)197 Facility (cz.metacentrum.perun.core.api.Facility)190 Resource (cz.metacentrum.perun.core.api.Resource)187 PerunSessionImpl (cz.metacentrum.perun.core.impl.PerunSessionImpl)180 List (java.util.List)177 LinkedHashMap (java.util.LinkedHashMap)158 Before (org.junit.Before)156 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)145 Method (java.lang.reflect.Method)140