use of cz.metacentrum.perun.core.api.PerunClient in project perun by CESNET.
the class RegistrarBaseIntegrationTest method setupTest.
@Before
public void setupTest() throws Exception {
if (vo == null || session == null) {
session = perun.getPerunSession(new PerunPrincipal("perunTests", ExtSourcesManager.EXTSOURCE_NAME_INTERNAL, ExtSourcesManager.EXTSOURCE_INTERNAL), new PerunClient());
// create test VO
vo = new Vo(0, "registrarTestVO", "regTestVO");
vo = perun.getVosManagerBl().createVo(session, vo);
}
}
use of cz.metacentrum.perun.core.api.PerunClient in project perun by CESNET.
the class PerunBlImpl method getPerunSession.
/**
* This method is used only internally.
*/
private PerunSession getPerunSession() {
PerunPrincipal principal = new PerunPrincipal(INTERNALPRINCIPAL, ExtSourcesManager.EXTSOURCE_NAME_INTERNAL, ExtSourcesManager.EXTSOURCE_INTERNAL);
PerunClient client = new PerunClient();
return new PerunSessionImpl(this, principal, client);
}
use of cz.metacentrum.perun.core.api.PerunClient in project perun by CESNET.
the class EventProcessor method createTaskFromEvent.
/**
* Creates Task from Event data. Tries to resolve Service and Facility pairs from Event.
* Events for non existing entities are discarded.
*
* @param event Event to parse
* @throws ServiceNotExistsException When Service from Event doesn't exists anymore
* @throws InvalidEventMessageException When Message has invalid format.
* @throws InternalErrorException When implementation fails
* @throws PrivilegeException When dispatcher lack privileges to call core methods
*/
private void createTaskFromEvent(Event event) throws ServiceNotExistsException, InvalidEventMessageException, PrivilegeException {
Map<Facility, Set<Service>> resolvedServices = eventServiceResolver.resolveEvent(event.getData());
for (Entry<Facility, Set<Service>> map : resolvedServices.entrySet()) {
Facility facility = map.getKey();
for (Service service : map.getValue()) {
if (!service.isEnabled()) {
log.debug("Service not enabled: {}.", service);
continue;
}
if (((PerunBl) perun).getServicesManagerBl().isServiceBlockedOnFacility(service, facility)) {
log.debug("Service blocked on Facility: {} , {}.", service, facility);
continue;
}
// Check if all destinations are not blocked
try {
// init session
try {
if (sess == null) {
sess = perun.getPerunSession(new PerunPrincipal(dispatcherProperties.getProperty("perun.principal.name"), dispatcherProperties.getProperty("perun.principal.extSourceName"), dispatcherProperties.getProperty("perun.principal.extSourceType")), new PerunClient());
}
} catch (InternalErrorException e1) {
log.error("Error establishing perun session to create Task from Event: ", e1);
continue;
}
List<Destination> destinations = perun.getServicesManager().getDestinations(sess, service, facility);
if (destinations != null && !destinations.isEmpty()) {
Iterator<Destination> iter = destinations.iterator();
while (iter.hasNext()) {
Destination dest = iter.next();
if (((PerunBl) perun).getServicesManagerBl().isServiceBlockedOnDestination(service, dest.getId())) {
iter.remove();
}
}
if (destinations.isEmpty()) {
// All service destinations were blocked -> Task is denied to be sent to engine just like
// when service is blocked globally in Perun or on facility as a whole.
log.debug("{} blocked on all destinations on {}.", service, facility);
continue;
}
}
} catch (ServiceNotExistsException e) {
log.error("Service not exist: {}.", service);
} catch (FacilityNotExistsException e) {
log.error("Facility not exist: {}.", facility);
} catch (InternalErrorException | PrivilegeException e) {
log.error("{}", e);
}
// check for presence of task for this <Service, Facility> pair
// NOTE: this must be atomic enough to not create duplicate
// tasks in schedulingPool (are we running in parallel
// here?)
boolean isForced = determineForcedPropagation(event);
Task task = schedulingPool.getTask(facility, service);
if (task != null) {
// there already is a task in schedulingPool
// signal that task needs to regenerate data and be forced next time
task.setDestinations(null);
task.setSourceUpdated(true);
if (isForced)
task.setPropagationForced(true);
task.setRecurrence(0);
log.debug("[{}] Task is already in pool. Re-setting source updated and forced flags, {}.", task.getId(), task);
} else {
// no such task yet, create one
task = new Task();
task.setFacility(facility);
task.setService(service);
task.setStatus(TaskStatus.WAITING);
task.setRecurrence(0);
task.setDelay(service.getDelay());
task.setSchedule(LocalDateTime.now());
task.setSourceUpdated(false);
task.setPropagationForced(isForced);
try {
schedulingPool.addToPool(task);
log.debug("[{}] New Task added to pool. {}.", task.getId(), task);
} catch (TaskStoreException e) {
log.error("[{}] Could not add Task to pool. Task {} will be lost: {}", task.getId(), task, e);
}
schedulingPool.scheduleTask(task, -1);
}
}
}
}
use of cz.metacentrum.perun.core.api.PerunClient in project perun by CESNET.
the class AuditerListener method run.
// ----- methods -------------------------------------
@Override
public void run() {
boolean whichOfTwoRules = false;
try {
try {
if (sess == null) {
sess = perun.getPerunSession(new PerunPrincipal(dispatcherProperties.getProperty("perun.principal.name"), dispatcherProperties.getProperty("perun.principal.extSourceName"), dispatcherProperties.getProperty("perun.principal.extSourceType")), new PerunClient());
}
} catch (InternalErrorException e1) {
log.error("Error establishing perun session in AuditerListener.", e1);
// we can't continue without session
stop();
}
while (!shouldStop()) {
try {
for (AuditEvent message : perun.getAuditMessagesManager().pollConsumerEvents(sess, "dispatcher")) {
// create event for each message
Event event = new Event();
event.setTimeStamp(System.currentTimeMillis());
if (whichOfTwoRules) {
event.setHeader("portishead");
whichOfTwoRules = false;
} else {
event.setHeader("clockworkorange");
whichOfTwoRules = true;
}
event.setData(message);
// pass event to queue for further processing
eventQueue.put(event);
}
Thread.sleep(1000);
} catch (InternalErrorException | PrivilegeException ex) {
log.error("AuditerListener couldn't get AuditEvents.", ex);
Thread.sleep(1000);
}
}
log.debug("AuditerListener has stopped.");
} catch (InterruptedException e) {
log.error("Error in AuditerListener: {}" + e);
throw new RuntimeException("Somebody has interrupted us...", e);
}
}
use of cz.metacentrum.perun.core.api.PerunClient in project perun by CESNET.
the class UsersManagerBlImplTest method setUp.
@Before
public void setUp() throws Exception {
candidate = new Candidate();
candidate.setFirstName("some");
candidate.setId(0);
candidate.setMiddleName("");
candidate.setLastName("testingUser");
candidate.setTitleBefore("");
candidate.setTitleAfter("");
ues = new UserExtSource(extSource, "extLogin");
candidate.setUserExtSource(ues);
candidate.setAttributes(new HashMap<>());
sess = perun.getPerunSession(new PerunPrincipal("perunTests", ExtSourcesManager.EXTSOURCE_NAME_INTERNAL, ExtSourcesManager.EXTSOURCE_INTERNAL), new PerunClient());
vo = new Vo(0, "UsersBlImplTestVo", "UsrMgrBlImplTestVo");
vo = perun.getVosManagerBl().createVo(sess, vo);
member = perun.getMembersManagerBl().createMemberSync(sess, vo, candidate);
group = new Group("testGroup", "testGroup");
group = perun.getGroupsManagerBl().createGroup(sess, vo, group);
perun.getGroupsManagerBl().addMember(sess, group, member);
facility = new Facility(0, "testFac");
facility = perun.getFacilitiesManagerBl().createFacility(sess, facility);
resource = new Resource(0, "testRes", null, facility.getId(), vo.getId());
resource = perun.getResourcesManagerBl().createResource(sess, resource, vo, facility);
perun.getResourcesManagerBl().assignGroupToResource(sess, group, resource, false, false, false);
// second branch
vo2 = new Vo(0, "FacilitiesManagerBlImplTestVo2", "FacMgrBlImplTestVo2");
vo2 = perun.getVosManagerBl().createVo(sess, vo2);
member2 = perun.getMembersManagerBl().createMemberSync(sess, vo2, candidate);
group2 = new Group("testGroup", "testGroup");
group2 = perun.getGroupsManagerBl().createGroup(sess, vo2, group2);
perun.getGroupsManagerBl().addMember(sess, group2, member2);
resource2 = new Resource(0, "testRes2", null, facility.getId(), vo2.getId());
resource2 = perun.getResourcesManagerBl().createResource(sess, resource2, vo2, facility);
// third branch
facility2 = new Facility(0, "testFac2");
facility2 = perun.getFacilitiesManagerBl().createFacility(sess, facility2);
resource3 = new Resource(0, "testRes3", null, facility2.getId(), vo2.getId());
resource3 = perun.getResourcesManagerBl().createResource(sess, resource3, vo2, facility2);
perun.getResourcesManagerBl().assignGroupToResources(sess, group2, Arrays.asList(resource2, resource3), false, false, false);
user = perun.getUsersManagerBl().getUserByMember(sess, member);
}
Aggregations