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());
}
}
}
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);
}
}
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;
}
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
}
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
}
Aggregations