Search in sources :

Example 76 with WrongReferenceAttributeValueException

use of cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException in project perun by CESNET.

the class urn_perun_resource_attribute_def_def_accountExpirationTime method checkAttributeValue.

public void checkAttributeValue(PerunSessionImpl perunSession, Resource resource, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
    Integer accExpTime = (Integer) attribute.getValue();
    if (accExpTime == null) {
        throw new WrongAttributeValueException("Attribute value shouldnt be null");
    }
    Facility fac = perunSession.getPerunBl().getResourcesManagerBl().getFacility(perunSession, resource);
    Integer facilityAccExpTime = null;
    try {
        //FIXME this can't work (different namespace!!)
        facilityAccExpTime = (Integer) perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, fac, attribute.getName()).getValue();
    } catch (AttributeNotExistsException ex) {
        throw new InternalErrorException(ex);
    }
    if (facilityAccExpTime == null) {
        throw new WrongReferenceAttributeValueException("cant determine attribute value on underlying facility");
    }
    if (facilityAccExpTime < accExpTime) {
        throw new WrongAttributeValueException("value can be higher than same facility attribute");
    }
}
Also used : WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) Facility(cz.metacentrum.perun.core.api.Facility) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 77 with WrongReferenceAttributeValueException

use of cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException in project perun by CESNET.

the class urn_perun_resource_attribute_def_def_defaultFilesQuota method checkAttributeValue.

@Override
public void checkAttributeValue(PerunSessionImpl perunSession, Resource resource, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
    Attribute attrDefaultFilesLimit = null;
    Integer defaultFilesQuota = null;
    Integer defaultFilesLimit = null;
    //Get DefaultFilesLimit attribute
    try {
        attrDefaultFilesLimit = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, resource, A_R_defaultFilesLimit);
    } catch (AttributeNotExistsException ex) {
        throw new ConsistencyErrorException("Attribute with defaultFilesLimit from resource " + resource.getId() + " could not obtained.", ex);
    }
    //Get defaultFilesQuota value
    if (attribute.getValue() != null) {
        defaultFilesQuota = (Integer) attribute.getValue();
    }
    if (defaultFilesQuota != null && defaultFilesQuota < 0)
        throw new WrongAttributeValueException(attribute, resource, attribute + " cannot be less than 0.");
    //Get defaultFilesLimit value
    if (attrDefaultFilesLimit != null && attrDefaultFilesLimit.getValue() != null) {
        defaultFilesLimit = (Integer) attrDefaultFilesLimit.getValue();
    }
    if (defaultFilesLimit != null && defaultFilesLimit < 0)
        throw new ConsistencyErrorException(attrDefaultFilesLimit + " cannot be less than 0.");
    //Compare DefaultFilesQuota with DefaultFilesLimit
    if (defaultFilesQuota == null || defaultFilesQuota == 0) {
        if (defaultFilesLimit != null && defaultFilesLimit != 0)
            throw new WrongReferenceAttributeValueException(attribute, attrDefaultFilesLimit, resource, null, resource, null, "Try to set unlimited quota, but limit is still " + defaultFilesLimit);
    } else if (defaultFilesLimit != null && defaultFilesLimit != 0) {
        if (defaultFilesLimit < defaultFilesQuota)
            throw new WrongReferenceAttributeValueException(attribute, attrDefaultFilesLimit, resource, null, resource, null, attribute + " must be less than or equals " + attrDefaultFilesLimit);
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 78 with WrongReferenceAttributeValueException

use of cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException 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);
    }
}
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) Resource(cz.metacentrum.perun.core.api.Resource) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) Facility(cz.metacentrum.perun.core.api.Facility) HashSet(java.util.HashSet)

Example 79 with WrongReferenceAttributeValueException

use of cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException in project perun by CESNET.

the class urn_perun_facility_attribute_def_virt_maxGID method getAttributeValue.

public Attribute getAttributeValue(PerunSessionImpl sess, Facility facility, AttributeDefinition attributeDefinition) throws InternalErrorException {
    Attribute attribute = new Attribute(attributeDefinition);
    try {
        Attribute gidNamespaceAttribute = getUnixGIDNamespaceAttribute(sess, facility);
        if (gidNamespaceAttribute.getValue() == null)
            return attribute;
        Attribute namespaceMaxGidAttribute = getNamespaceMaxGidAttribute(sess, (String) gidNamespaceAttribute.getValue());
        attribute = Utils.copyAttributeToVirtualAttributeWithValue(namespaceMaxGidAttribute, attribute);
        return attribute;
    } catch (WrongReferenceAttributeValueException ex) {
        return attribute;
    }
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)

Example 80 with WrongReferenceAttributeValueException

use of cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException in project perun by CESNET.

the class urn_perun_group_resource_attribute_def_def_isSystemUnixGroup method checkAttributeValue.

public void checkAttributeValue(PerunSessionImpl sess, Resource resource, Group group, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
    Integer isSystemUnixGroup = (Integer) attribute.getValue();
    //isSystemUnixGroup can be null. It is equivalent to 0.
    if (isSystemUnixGroup == null)
        return;
    if (isSystemUnixGroup != 0 && isSystemUnixGroup != 1)
        throw new WrongAttributeValueException(attribute, "Attribute isSystemUnixGroup should not other number than 0 or 1.");
    Attribute sysUnixGroupName = new Attribute();
    Attribute sysUnixGID = new Attribute();
    if (isSystemUnixGroup == 1) {
        try {
            sysUnixGroupName = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, group, A_GR_systemUnixGroupName);
            sysUnixGID = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, group, A_GR_systemUnixGID);
        } catch (AttributeNotExistsException ex) {
            //if any of these attributes not exist, its wrong
            throw new ConsistencyErrorException("Attributes sysUnixGroupName or sysUnixGID not exist.", ex);
        }
        try {
            sess.getPerunBl().getAttributesManagerBl().checkAttributeValue(sess, resource, group, sysUnixGroupName);
        } catch (WrongAttributeValueException ex) {
            throw new WrongReferenceAttributeValueException("Bad value in sysUnixGroupName attribute.", ex);
        }
        try {
            sess.getPerunBl().getAttributesManagerBl().checkAttributeValue(sess, resource, group, sysUnixGID);
        } catch (WrongAttributeValueException ex) {
            throw new WrongReferenceAttributeValueException("Bad value in sysUnixGID.", ex);
        }
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Aggregations

WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)109 Attribute (cz.metacentrum.perun.core.api.Attribute)101 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)83 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)70 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)64 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)62 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)51 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)27 Resource (cz.metacentrum.perun.core.api.Resource)13 ArrayList (java.util.ArrayList)13 Facility (cz.metacentrum.perun.core.api.Facility)12 Matcher (java.util.regex.Matcher)12 User (cz.metacentrum.perun.core.api.User)11 Group (cz.metacentrum.perun.core.api.Group)9 BigDecimal (java.math.BigDecimal)6 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)5 List (java.util.List)5 Pattern (java.util.regex.Pattern)5 Pair (cz.metacentrum.perun.core.api.Pair)3 LinkedHashMap (java.util.LinkedHashMap)3