Search in sources :

Example 6 with Facility

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

the class urn_perun_resource_attribute_def_def_shells method checkAttributeValue.

@Override
public /**
	 * Checks the attribute with all available shells from resource's facility
	 */
void checkAttributeValue(PerunSessionImpl perunSession, Resource resource, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
    List<String> shells = (List<String>) attribute.getValue();
    if (shells == null) {
        throw new WrongAttributeValueException(attribute, "Attribute was not filled, therefore there is nothing to be checked.");
    }
    if (!shells.isEmpty()) {
        for (String st : shells) {
            perunSession.getPerunBl().getModulesUtilsBl().checkFormatOfShell(st, attribute);
        }
    }
    Facility facility = perunSession.getPerunBl().getResourcesManagerBl().getFacility(perunSession, resource);
    Attribute allShellsPerFacility;
    try {
        allShellsPerFacility = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, facility, A_F_shells);
    } catch (AttributeNotExistsException ex) {
        throw new InternalErrorException("Attribute with list of shells from facility " + facility.getId() + " could not obtained.", ex);
    }
    if (allShellsPerFacility.getValue() == null) {
        throw new WrongReferenceAttributeValueException(attribute, allShellsPerFacility);
    } else {
        if (!((List<String>) allShellsPerFacility.getValue()).containsAll(shells)) {
            throw new WrongAttributeValueException(attribute, "Some shells from specified resource are not at home facility " + facility.getId());
        }
    }
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) ArrayList(java.util.ArrayList) List(java.util.List) Facility(cz.metacentrum.perun.core.api.Facility) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 7 with Facility

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

the class urn_perun_resource_attribute_def_def_unixGroupName_namespace method changedAttributeHook.

@Override
public void changedAttributeHook(PerunSessionImpl session, Resource resource, Attribute attribute) throws InternalErrorException, WrongReferenceAttributeValueException {
    //Need to know if this is remove or set, if value is null, its remove, otherway it is set
    String groupNameNamespace = attribute.getFriendlyNameParameter();
    try {
        if (attribute.getValue() == null) {
        //This is ok, for now no changes for removing some GroupName of this Resource
        } else {
            //First need to find facility for the group
            Facility facilityOfResource = session.getPerunBl().getResourcesManagerBl().getFacility(session, resource);
            String gidNamespace = null;
            //If facility has the same namespace of GroupName like attribute unixGroupName-namespace, then prepare gidNamespace
            Attribute facilityGroupNameNamespace = session.getPerunBl().getAttributesManagerBl().getAttribute(session, facilityOfResource, A_F_unixGroupName_namespace);
            if (facilityGroupNameNamespace.getValue() != null) {
                if (groupNameNamespace.equals(facilityGroupNameNamespace.getValue())) {
                    Attribute facilityGIDNamespace = session.getPerunBl().getAttributesManagerBl().getAttribute(session, facilityOfResource, A_F_unixGID_namespace);
                    if (facilityGIDNamespace.getValue() != null) {
                        gidNamespace = (String) facilityGIDNamespace.getValue();
                    }
                }
            }
            //If there is any gidNamespace which is need to be set, do it there
            if (gidNamespace != null) {
                Attribute resourceUnixGIDNamespace = session.getPerunBl().getAttributesManagerBl().getAttribute(session, resource, A_R_unixGID_namespace + ":" + gidNamespace);
                if (resourceUnixGIDNamespace.getValue() == null) {
                    resourceUnixGIDNamespace = session.getPerunBl().getAttributesManagerBl().fillAttribute(session, resource, resourceUnixGIDNamespace);
                    if (resourceUnixGIDNamespace.getValue() == null)
                        throw new WrongReferenceAttributeValueException(attribute, resourceUnixGIDNamespace);
                    try {
                        session.getPerunBl().getAttributesManagerBl().setAttribute(session, resource, resourceUnixGIDNamespace);
                    } catch (WrongAttributeValueException ex) {
                        throw new WrongReferenceAttributeValueException(attribute, resourceUnixGIDNamespace, ex);
                    }
                } else {
                    try {
                        session.getPerunBl().getAttributesManagerBl().checkAttributeValue(session, resource, resourceUnixGIDNamespace);
                    } catch (WrongAttributeValueException ex) {
                        throw new WrongReferenceAttributeValueException(attribute, resourceUnixGIDNamespace, ex);
                    }
                }
            }
        }
    } catch (WrongAttributeAssignmentException ex) {
        //TODO: need to add WrongAttributeAssignmentException to header of modules methods
        throw new InternalErrorException(ex);
    } catch (AttributeNotExistsException ex) {
        throw new ConsistencyErrorException(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) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) 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 8 with Facility

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

the class urn_perun_resource_attribute_def_def_shells method fillAttribute.

@Override
public /**
	 * Fills the list of shells at the specified resource from facility
	 */
Attribute fillAttribute(PerunSessionImpl perunSession, Resource resource, AttributeDefinition attribute) throws InternalErrorException, WrongAttributeAssignmentException {
    Attribute atr = new Attribute(attribute);
    Facility facility = perunSession.getPerunBl().getResourcesManagerBl().getFacility(perunSession, resource);
    Attribute allShellsPerFacility;
    try {
        allShellsPerFacility = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, facility, A_F_shells);
    } catch (AttributeNotExistsException ex) {
        throw new InternalErrorException("Attribute with list of shells from facility " + facility.getId() + " could not obtained.", ex);
    }
    atr.setValue((List<String>) allShellsPerFacility.getValue());
    return atr;
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) Facility(cz.metacentrum.perun.core.api.Facility) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 9 with Facility

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

the class AttributesManagerEntryIntegrationTest method setFacilityAttributeWhenFacilityNotExists.

@Test(expected = FacilityNotExistsException.class)
public void setFacilityAttributeWhenFacilityNotExists() throws Exception {
    System.out.println(CLASS_NAME + "setFacilityAttributeWhenFacilityNotExists");
    attributes = setUpFacilityAttribute();
    attributesManager.setAttribute(sess, new Facility(), attributes.get(0));
// shouldn't find facility
}
Also used : Facility(cz.metacentrum.perun.core.api.Facility) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 10 with Facility

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

the class AttributesManagerEntryIntegrationTest method removeFacilityUserAttributesWhenFacilityNotExists.

@Test(expected = FacilityNotExistsException.class)
public void removeFacilityUserAttributesWhenFacilityNotExists() throws Exception {
    System.out.println(CLASS_NAME + "removeFacilityUserAttributesWhenFacilityNotExists");
    attributes = setUpFacilityUserAttribute();
    vo = setUpVo();
    member = setUpMember();
    User user = perun.getUsersManager().getUserByMember(sess, member);
    attributesManager.removeAttributes(sess, new Facility(), user, attributes);
// shouldn't find facility
}
Also used : User(cz.metacentrum.perun.core.api.User) Facility(cz.metacentrum.perun.core.api.Facility) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Aggregations

Facility (cz.metacentrum.perun.core.api.Facility)188 Test (org.junit.Test)95 User (cz.metacentrum.perun.core.api.User)81 Attribute (cz.metacentrum.perun.core.api.Attribute)75 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)61 Resource (cz.metacentrum.perun.core.api.Resource)52 BanOnFacility (cz.metacentrum.perun.core.api.BanOnFacility)51 ArrayList (java.util.ArrayList)48 Group (cz.metacentrum.perun.core.api.Group)24 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)23 Member (cz.metacentrum.perun.core.api.Member)22 PerunSession (cz.metacentrum.perun.core.api.PerunSession)20 RichFacility (cz.metacentrum.perun.core.api.RichFacility)20 Host (cz.metacentrum.perun.core.api.Host)19 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)18 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)17 RichUser (cz.metacentrum.perun.core.api.RichUser)16 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)15 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)14 Vo (cz.metacentrum.perun.core.api.Vo)13