use of cz.metacentrum.perun.core.api.ExtSource in project perun by CESNET.
the class UsersManagerEntryIntegrationTest method setUpUserExtSource.
private void setUpUserExtSource() throws Exception {
ExtSource externalSource = perun.getExtSourcesManager().getExtSourceByName(sess, extSourceName);
// gets real external source object from database
userExtSource.setExtSource(externalSource);
// put real external source into user's external source
userExtSource.setLogin(extLogin);
// set users login in his ext source
assertNotNull(usersManager.addUserExtSource(sess, user, userExtSource));
// create new user ext source in database
}
use of cz.metacentrum.perun.core.api.ExtSource in project perun by CESNET.
the class urn_perun_group_resource_attribute_def_def_isUnixGroupIntegrationtest method setUpVo.
private Vo setUpVo() throws Exception {
Vo newVo = new Vo(0, "IsUnixGroupTestVo", "IUGTestVo");
Vo returnedVo = perun.getVosManager().createVo(sess, newVo);
// create test VO in database
assertNotNull("unable to create testing Vo", returnedVo);
assertEquals("both VOs should be the same", newVo, returnedVo);
ExtSource es = perun.getExtSourcesManager().getExtSourceByName(sess, extSourceName);
// get real external source from DB
perun.getExtSourcesManager().addExtSource(sess, returnedVo, es);
return returnedVo;
}
use of cz.metacentrum.perun.core.api.ExtSource in project perun by CESNET.
the class ExtSourcesManagerImpl method updateExtSource.
@Override
public void updateExtSource(PerunSession sess, ExtSource extSource, Map<String, String> attributes) throws ExtSourceNotExistsException, InternalErrorException {
ExtSource extSourceDb;
extSourceDb = this.getExtSourceById(sess, extSource.getId());
// Check the name
if (!extSourceDb.getName().equals(extSource.getName())) {
try {
jdbc.update("update ext_sources set name=? ,modified_by=?, modified_by_uid=?, modified_at=" + Compatibility.getSysdate() + " where id=?", extSource.getName(), sess.getPerunPrincipal().getActor(), sess.getPerunPrincipal().getUserId(), extSource.getId());
} catch (RuntimeException e) {
throw new InternalErrorException(e);
}
}
// Check the type
if (!extSourceDb.getType().equals(extSource.getType())) {
try {
jdbc.update("update ext_sources set type=?, modified_by=?, modified_by_uid=?, modified_at=" + Compatibility.getSysdate() + " where id=?", extSource.getType(), sess.getPerunPrincipal().getActor(), sess.getPerunPrincipal().getUserId(), extSource.getId());
} catch (RuntimeException e) {
throw new InternalErrorException(e);
}
}
// Check the attributes
if (!getAttributes(extSourceDb).equals(attributes)) {
log.debug("There is a change in attributes for {}", extSource);
try {
// Firstly delete all attributes, then store new ones
jdbc.update("delete from ext_sources_attributes where ext_sources_id=?", extSource.getId());
for (String attrName : attributes.keySet()) {
jdbc.update("insert into ext_sources_attributes (ext_sources_id, attr_name, attr_value, created_by, created_at, modified_by, modified_at, created_by_uid, modified_by_uid) " + "values (?,?,?,?," + Compatibility.getSysdate() + ",?," + Compatibility.getSysdate() + ",?,?)", extSource.getId(), attrName, attributes.get(attrName), sess.getPerunPrincipal().getActor(), sess.getPerunPrincipal().getActor(), sess.getPerunPrincipal().getUserId(), sess.getPerunPrincipal().getUserId());
}
} catch (RuntimeException e) {
throw new InternalErrorException(e);
}
}
}
use of cz.metacentrum.perun.core.api.ExtSource in project perun by CESNET.
the class ExtSourcesManagerImpl method loadExtSourcesDefinitions.
/**
* Loads the extSources definitions from the XML configuration file.
* All data from the extSouces XML file are synchronized with the DB.
*
* @throws InternalErrorException
*/
public void loadExtSourcesDefinitions(PerunSession sess) {
try {
// Load the XML file
BufferedInputStream is = new BufferedInputStream(new FileInputStream(ExtSourcesManager.CONFIGURATIONFILE));
if (is == null) {
throw new InternalErrorException("Cannot load configuration file " + ExtSourcesManager.CONFIGURATIONFILE);
}
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(is);
doc.getDocumentElement().normalize();
// Check if the root element is "extSources"
if (!doc.getDocumentElement().getNodeName().equals("extSources")) {
throw new InternalErrorException("perun-extSources.xml doesn't contain extSources as root element");
}
// Get all defined extSources
NodeList extSourcesNodes = doc.getElementsByTagName("extSource");
for (int extSourceSeq = 0; extSourceSeq < extSourcesNodes.getLength(); extSourceSeq++) {
// Get each extSource
Node extSourceNode = extSourcesNodes.item(extSourceSeq);
if (extSourceNode.getNodeType() == Node.ELEMENT_NODE) {
Element extSourceElement = (Element) extSourceNode;
// Get extSource name
String extSourceName = extSourceElement.getElementsByTagName("name").item(0).getChildNodes().item(0).getNodeValue();
if (extSourceName == null) {
throw new InternalErrorException("extSource doesn't have defined name");
}
// Get extSource type
String extSourceType = extSourceElement.getElementsByTagName("type").item(0).getChildNodes().item(0).getNodeValue();
if (extSourceType == null) {
throw new InternalErrorException("extSource " + extSourceName + " doesn't have defined type");
}
// Get all extSource attributes
NodeList attributeNodes = extSourceElement.getElementsByTagName("attribute");
Map<String, String> attributes = new HashMap<String, String>();
for (int attributeSeq = 0; attributeSeq < attributeNodes.getLength(); attributeSeq++) {
Element elem = (Element) attributeNodes.item(attributeSeq);
if (elem.getNodeType() == Node.ELEMENT_NODE) {
String attrName = elem.getAttribute("name");
String attrValue = null;
if (elem.getChildNodes() != null && elem.getChildNodes().item(0) != null) {
attrValue = elem.getChildNodes().item(0).getNodeValue();
}
attributes.put(attrName, attrValue);
}
}
// Check if the extSource
try {
ExtSource extSource;
try {
extSource = this.getExtSourceByName(sess, extSourceName);
extSource.setName(extSourceName);
extSource.setType(extSourceType);
// ExtSource exists, so check values and potentionally update it
self.updateExtSource(sess, extSource, attributes);
} catch (ExtSourceNotExistsException e) {
// ExtSource doesn't exist, so create it
extSource = new ExtSource();
extSource.setName(extSourceName);
extSource.setType(extSourceType);
extSource = self.createExtSource(sess, extSource, attributes);
}
} catch (RuntimeException e) {
throw new InternalErrorException(e);
}
}
}
} catch (FileNotFoundException e) {
log.warn("No external source configuration file found.");
} catch (Exception e) {
log.error("Cannot initialize ExtSourceManager.");
throw new InternalErrorRuntimeException(e);
}
}
use of cz.metacentrum.perun.core.api.ExtSource in project perun by CESNET.
the class AttributesManagerEntryIntegrationTest method setUpWorld.
/**
* How the world look: "->" means "have a binding, connection with"
*
* vo1 -> member1OfUser1, member2OfUser2, member1OfUser3 && group1InVo1, group2InVo1, membersGroupOfVo1 && resource1InVo1, resource2InVo1
* vo2 -> member2OfUser1, member1OfUser2, member2OfUser3 && group1InVo2, group2InVo2, membersGroupOfVo2 && resource1InVo2, resource2InVo2
*
* user1 -> member1OfUser1, member2OfUser1 && userExtSource1
* user2 -> member1OfUser2, member2OfUser2 && userExtSource2
* user3 -> member1OfUser3, member2OfUser3 && userExtSource3
*
* member1OfUser1 IS allowed
* member2OfUser1 IS disallowed
* member1OfUser2 IS allowed
* member2OfUser2 IS disallowed
* member1OfUser3 IS allowed
* member2OfUser3 IS allowed
*
* group1InVo1 -> member1OfUser1, member2OfUser2, member1OfUser3
* group2InVo1 -> member1OfUser1, member2OfUser2
* group1InVo2 -> member2OfUser1, member1OfUser2
* group2InVo2 -> member2OfUser1, member1OfUser2, member2OfUser3
*
* facility1 -> host1OnFacility1, host2OnFacility1
* facility2 -> host1OnFacility2, host2OnFacility2
* facility3 -> host1OnFacility3, host2OnFacility3
*
* resource1InVo1 -> facility1 && group1InVo1, group2InVo1
* resource2InVo1 -> facility2 && group2InVo1
* resource1InVo2 -> facility2 && group1InVo2, group2InVo2
* resource2InVo2 -> facility3 && group2InVo2
*/
public void setUpWorld() throws Exception {
//Create VO
vo1 = perun.getVosManagerBl().createVo(sess, new Vo(0, "vo1Test", "v1T"));
vo2 = perun.getVosManagerBl().createVo(sess, new Vo(0, "vo2Test", "v2T"));
//Create Groups(members groups in vos), Members and Users from Candidates
Candidate can1 = new Candidate();
can1.setFirstName("user1");
can1.setId(0);
can1.setMiddleName("");
can1.setLastName("Test");
can1.setTitleBefore("");
can1.setTitleAfter("");
UserExtSource userExtSource1 = new UserExtSource(new ExtSource(0, "testExtSource", "cz.metacentrum.perun.core.impl.ExtSourceInternal"), "user1TestLogin");
UserExtSource userExtSource2 = new UserExtSource(new ExtSource(0, "testExtSource", "cz.metacentrum.perun.core.impl.ExtSourceInternal"), "user2TestLogin");
UserExtSource userExtSource3 = new UserExtSource(new ExtSource(0, "testExtSource", "cz.metacentrum.perun.core.impl.ExtSourceInternal"), "user3TestLogin");
can1.setUserExtSource(userExtSource1);
can1.setAttributes(new HashMap<String, String>());
member1OfUser1 = perun.getMembersManagerBl().createMemberSync(sess, vo1, can1);
user1 = perun.getUsersManagerBl().getUserByMember(sess, member1OfUser1);
member2OfUser1 = perun.getMembersManagerBl().createMember(sess, vo2, user1);
can1.setFirstName("user2");
can1.setUserExtSource(userExtSource2);
member1OfUser2 = perun.getMembersManagerBl().createMemberSync(sess, vo2, can1);
user2 = perun.getUsersManagerBl().getUserByMember(sess, member1OfUser2);
member2OfUser2 = perun.getMembersManagerBl().createMember(sess, vo1, user2);
can1.setFirstName("user3");
can1.setUserExtSource(userExtSource3);
member1OfUser3 = perun.getMembersManagerBl().createMemberSync(sess, vo1, can1);
user3 = perun.getUsersManagerBl().getUserByMember(sess, member1OfUser3);
member2OfUser3 = perun.getMembersManagerBl().createMember(sess, vo2, user3);
//Validate members
member1OfUser1 = perun.getMembersManagerBl().validateMember(sess, member1OfUser1);
member2OfUser1 = perun.getMembersManagerBl().validateMember(sess, member2OfUser1);
member1OfUser2 = perun.getMembersManagerBl().validateMember(sess, member1OfUser2);
member2OfUser2 = perun.getMembersManagerBl().validateMember(sess, member2OfUser2);
member1OfUser3 = perun.getMembersManagerBl().validateMember(sess, member1OfUser3);
member2OfUser3 = perun.getMembersManagerBl().validateMember(sess, member2OfUser3);
//Invalidate some members to Disallowed them
perun.getMembersManagerBl().invalidateMember(sess, member2OfUser1);
perun.getMembersManagerBl().invalidateMember(sess, member2OfUser2);
//Create groups and add members to them
membersGroupOfVo1 = perun.getGroupsManagerBl().getGroupByName(sess, vo1, VosManager.MEMBERS_GROUP);
membersGroupOfVo2 = perun.getGroupsManagerBl().getGroupByName(sess, vo2, VosManager.MEMBERS_GROUP);
group1InVo1 = perun.getGroupsManagerBl().createGroup(sess, vo1, new Group("testGroup1InVo1", ""));
group2InVo1 = perun.getGroupsManagerBl().createGroup(sess, vo1, new Group("testGroup2InVo1", ""));
group1InVo2 = perun.getGroupsManagerBl().createGroup(sess, vo2, new Group("testGroup1InVo2", ""));
group2InVo2 = perun.getGroupsManagerBl().createGroup(sess, vo2, new Group("testGroup2InVo2", ""));
perun.getGroupsManagerBl().addMember(sess, group1InVo1, member1OfUser1);
perun.getGroupsManagerBl().addMember(sess, group2InVo1, member1OfUser1);
perun.getGroupsManagerBl().addMember(sess, group1InVo1, member2OfUser2);
perun.getGroupsManagerBl().addMember(sess, group2InVo1, member2OfUser2);
perun.getGroupsManagerBl().addMember(sess, group1InVo2, member2OfUser1);
perun.getGroupsManagerBl().addMember(sess, group2InVo2, member2OfUser1);
perun.getGroupsManagerBl().addMember(sess, group1InVo2, member1OfUser2);
perun.getGroupsManagerBl().addMember(sess, group2InVo2, member1OfUser2);
perun.getGroupsManagerBl().addMember(sess, group1InVo1, member1OfUser3);
perun.getGroupsManagerBl().addMember(sess, group2InVo2, member2OfUser3);
//Create Facility
facility1 = perun.getFacilitiesManagerBl().createFacility(sess, new Facility(0, "testFacility1"));
facility2 = perun.getFacilitiesManagerBl().createFacility(sess, new Facility(0, "testFacility2"));
facility3 = perun.getFacilitiesManagerBl().createFacility(sess, new Facility(0, "testFacility3"));
//Create Host on Facilities
host1OnFacility1 = perun.getFacilitiesManagerBl().addHost(sess, new Host(0, "testHost1OnFacility1"), facility1);
host2OnFacility1 = perun.getFacilitiesManagerBl().addHost(sess, new Host(0, "testHost2OnFacility1"), facility1);
host1OnFacility2 = perun.getFacilitiesManagerBl().addHost(sess, new Host(0, "testHost1OnFacility2"), facility2);
host2OnFacility2 = perun.getFacilitiesManagerBl().addHost(sess, new Host(0, "testHost2OnFacility2"), facility2);
host1OnFacility3 = perun.getFacilitiesManagerBl().addHost(sess, new Host(0, "testHost1OnFacility3"), facility3);
host2OnFacility3 = perun.getFacilitiesManagerBl().addHost(sess, new Host(0, "testHost2OnFacility3"), facility3);
//Create resources and assing group to them
resource1InVo1 = perun.getResourcesManagerBl().createResource(sess, new Resource(0, "testResource1InVo1", "", facility1.getId(), vo1.getId()), vo1, facility1);
resource2InVo1 = perun.getResourcesManagerBl().createResource(sess, new Resource(0, "testResource2InVo1", "", facility2.getId(), vo1.getId()), vo1, facility2);
resource1InVo2 = perun.getResourcesManagerBl().createResource(sess, new Resource(0, "testResource1InVo2", "", facility2.getId(), vo2.getId()), vo2, facility2);
resource2InVo2 = perun.getResourcesManagerBl().createResource(sess, new Resource(0, "testResource2InVo2", "", facility3.getId(), vo2.getId()), vo2, facility3);
perun.getResourcesManagerBl().assignGroupToResource(sess, group1InVo1, resource1InVo1);
perun.getResourcesManagerBl().assignGroupToResource(sess, group2InVo1, resource1InVo1);
perun.getResourcesManagerBl().assignGroupToResource(sess, group2InVo1, resource2InVo1);
perun.getResourcesManagerBl().assignGroupToResource(sess, group1InVo2, resource1InVo2);
perun.getResourcesManagerBl().assignGroupToResource(sess, group2InVo2, resource1InVo2);
perun.getResourcesManagerBl().assignGroupToResource(sess, group2InVo2, resource2InVo2);
}
Aggregations