Search in sources :

Example 31 with SyncerExecutor

use of org.olat.core.util.coordinate.SyncerExecutor in project OpenOLAT by OpenOLAT.

the class ProjectBrokerManagerImpl method signOutFormAllCandidateList.

public void signOutFormAllCandidateList(final List<Identity> chosenIdentities, final Long projectBrokerId) {
    OLATResourceable projectBrokerOres = OresHelper.createOLATResourceableInstance(this.getClass(), projectBrokerId);
    CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(projectBrokerOres, new SyncerExecutor() {

        public void execute() {
            ProjectBroker projectBroker = getOrLoadProjectBoker(projectBrokerId);
            for (Iterator<Project> iterator = projectBroker.getProjects().iterator(); iterator.hasNext(); ) {
                Project project = iterator.next();
                // loop over all identities
                for (Iterator<Identity> iterator2 = chosenIdentities.iterator(); iterator2.hasNext(); ) {
                    Identity identity = iterator2.next();
                    securityManager.removeIdentityFromSecurityGroup(identity, project.getCandidateGroup());
                    logAudit("ProjectBroker: AutoSignOut: identity=" + identity + " from project=" + project);
                }
            }
        }
    });
}
Also used : Project(org.olat.course.nodes.projectbroker.datamodel.Project) ProjectBroker(org.olat.course.nodes.projectbroker.datamodel.ProjectBroker) OLATResourceable(org.olat.core.id.OLATResourceable) Iterator(java.util.Iterator) SyncerExecutor(org.olat.core.util.coordinate.SyncerExecutor) Identity(org.olat.core.id.Identity)

Example 32 with SyncerExecutor

use of org.olat.core.util.coordinate.SyncerExecutor in project OpenOLAT by OpenOLAT.

the class CollaborationTools method createOrUpdateProperty.

/**
 * creates the property if non-existing, or updates the existing property to
 * the supplied values. Real changes are made persistent immediately.
 *
 * @param selectedTool
 * @param toolValue
 */
private void createOrUpdateProperty(final String selectedTool, final boolean toolValue) {
    Boolean cv = cacheToolStates.get(selectedTool);
    if (cv != null && cv.booleanValue() == toolValue) {
        // nice, cache saved a needless update
        return;
    }
    // handle Boolean Values via String Field in Property DB Table
    final String toolValueStr = toolValue ? TRUE : FALSE;
    final PropertyManager pm = PropertyManager.getInstance();
    coordinatorManager.getCoordinator().getSyncer().doInSync(ores, new SyncerExecutor() {

        @Override
        public void execute() {
            // was: synchronized (CollaborationTools.class) {
            Property property = getPropertyOf(selectedTool);
            if (property == null) {
                // not existing -> create it
                property = pm.createPropertyInstance(null, null, ores, PROP_CAT_BG_COLLABTOOLS, selectedTool, null, null, toolValueStr, null);
            } else {
                // if existing -> update to desired value
                property.setStringValue(toolValueStr);
            }
            // create a room if needed
            if (toolValue && TOOL_OPENMEETINGS.equals(selectedTool)) {
                openOpenMeetingsRoom();
            }
            // property becomes persistent
            pm.saveProperty(property);
        }
    });
    this.dirty = true;
    cacheToolStates.put(selectedTool, Boolean.valueOf(toolValue));
}
Also used : PropertyManager(org.olat.properties.PropertyManager) NarrowedPropertyManager(org.olat.properties.NarrowedPropertyManager) SyncerExecutor(org.olat.core.util.coordinate.SyncerExecutor) Property(org.olat.properties.Property)

Example 33 with SyncerExecutor

use of org.olat.core.util.coordinate.SyncerExecutor in project OpenOLAT by OpenOLAT.

the class ClusterAdminControllerCluster method event.

@Override
protected void event(UserRequest ureq, Component source, Event event) {
    if (source == syncLong) {
        // sync on a olatresourceable and hold the lock for 5 seconds.
        CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(ORES_TEST, new SyncerExecutor() {

            public void execute() {
                sleep(5000);
            }
        });
        // the runnable is executed within the same thread->
        getWindowControl().setInfo("done syncing on the test olatresourceable for 5 seconds");
    } else if (source == syncShort) {
        // sync on a olatresourceable and hold the lock for 1 second.
        CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(ORES_TEST, new SyncerExecutor() {

            public void execute() {
                sleep(1000);
            }
        });
        // the runnable is executed within the same thread->
        getWindowControl().setInfo("done syncing on the test olatresourceable for 1 second");
    } else if (source == testPerf) {
        // send 1000 (short) messages over the cluster bus
        int cnt = 1000;
        long start = System.nanoTime();
        for (int i = 0; i < cnt; i++) {
            clusBus.fireEventToListenersOf(new MultiUserEvent("jms-perf-test-" + i + " of " + cnt), ORES_TEST);
        }
        long stop = System.nanoTime();
        long dur = stop - start;
        double inmilis = dur / 1000000;
        double avg = dur / cnt;
        double avgmilis = avg / 1000000;
        getWindowControl().setInfo("sending " + cnt + " messages took " + inmilis + " ms, avg per messages was " + avg + " ns = " + avgmilis + " ms");
    } else if (source == testCachePut) {
        CacheWrapper<String, String> cw = CoordinatorManager.getInstance().getCoordinator().getCacher().getCache(this.getClass().getSimpleName(), "cachetest");
        // we explicitly use put and not putSilent to show that a put invalidates (and thus removes) this key of this cache in all other cluster nodes.
        cw.update("akey", "hello");
        updateCacheInfo();
    } else if (source == testCachePut2) {
        // we explicitly use put and not putSilent to show that a put invalidates (and thus removes) this key of this cache in all other cluster nodes.
        CacheWrapper<String, String> cw = CoordinatorManager.getInstance().getCoordinator().getCacher().getCache(this.getClass().getSimpleName(), "cachetest");
        cw.update("akey", "world");
        updateCacheInfo();
    } else if (source == testSFUPerf) {
        // acquire a sync 1000x times (does internally a select-for-update on the database)
        int cnt = 1000;
        long start = System.nanoTime();
        for (int i = 0; i < cnt; i++) {
            CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(ORES_TEST, new SyncerExecutor() {

                public void execute() {
                // empty
                }
            });
        }
        long stop = System.nanoTime();
        long dur = stop - start;
        double inmilis = dur / 1000000;
        double avg = dur / cnt;
        double avgmilis = avg / 1000000;
        getWindowControl().setInfo("acquiring " + cnt + " locks for syncing (using db's \"select for update\") took " + inmilis + " ms, avg per messages was " + avg + " ns = " + avgmilis + " ms");
    } else if (source == releaseAllLocksFor) {
        // let a user search pop up
        usc = new UserSearchController(ureq, getWindowControl(), true);
        listenTo(usc);
        getWindowControl().pushAsModalDialog(usc.getInitialComponent());
    } else if ((source == nodeInfoVc) && (event.getCommand().equals("switchToNode"))) {
        String nodeIdStr = ureq.getHttpReq().getParameter("nodeId");
        if (nodeIdStr.length() == 1) {
            nodeIdStr = "0" + nodeIdStr;
        }
        Cookie[] cookies = ureq.getHttpReq().getCookies();
        for (int i = 0; i < cookies.length; i++) {
            Cookie cookie = cookies[i];
            if ("JSESSIONID".equals(cookie.getName())) {
                String redirectedButInvalidSessionId = cookie.getValue();
                redirectedButInvalidSessionId = redirectedButInvalidSessionId.substring(0, redirectedButInvalidSessionId.length() - 2) + nodeIdStr;
                logInfo("redirecting session to node " + nodeIdStr + ", new sessionid=" + redirectedButInvalidSessionId, null);
                cookie.setValue(redirectedButInvalidSessionId);
                replaceCookie(ureq.getHttpReq(), ureq.getHttpResp(), cookie);
                // OLAT-5165: make sure we can always bypass the dmz reject mechanism (for 5min that is)
                Cookie newCookie = new Cookie("bypassdmzreject", String.valueOf(System.currentTimeMillis()));
                // 5min lifetime
                newCookie.setMaxAge(5 * 60);
                newCookie.setPath(WebappHelper.getServletContextPath());
                newCookie.setSecure(ureq.getHttpReq().isSecure());
                newCookie.setComment("cookie allowing olat admin users to bypass dmz rejects");
                ureq.getHttpResp().addCookie(newCookie);
                OncePanel oncePanel = new OncePanel("refresh");
                oncePanel.setContent(createVelocityContainer("refresh"));
                mainVc.put("refresh", oncePanel);
                break;
            }
        }
    } else if (source == toggleStartStop) {
        clusBus.resetStats();
        updatePerfInfos();
    } else if (source == resetStats) {
        clusBus.resetStats();
        updatePerfInfos();
    }
}
Also used : Cookie(javax.servlet.http.Cookie) CacheWrapper(org.olat.core.util.cache.CacheWrapper) OncePanel(org.olat.core.gui.components.panel.OncePanel) SyncerExecutor(org.olat.core.util.coordinate.SyncerExecutor) UserSearchController(org.olat.admin.user.UserSearchController) MultiUserEvent(org.olat.core.util.event.MultiUserEvent)

Example 34 with SyncerExecutor

use of org.olat.core.util.coordinate.SyncerExecutor in project OpenOLAT by OpenOLAT.

the class DENManager method doEnroll.

/**
 * Enrolls an user into a specific calendar event
 * @param identity
 * @param event
 * @param course
 * @param courseNode
 * @param allowOverfill
 * @return status
 */
public DENStatus doEnroll(final Identity identity, final KalendarEvent event, final OLATResourceable ores, final DENCourseNode courseNode, final boolean allowOverfill) {
    final DENStatus status = new DENStatus();
    ICourse course = CourseFactory.loadCourse(ores);
    CalendarManager calManager = CoreSpringFactory.getImpl(CalendarManager.class);
    final Kalendar cal = calManager.getCourseCalendar(course).getKalendar();
    OLATResourceable calRes = calManager.getOresHelperFor(cal);
    // reload calendar events
    final List<KalendarEvent> denEvents = getDENEvents(ores.getResourceableId(), courseNode.getIdent());
    CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(calRes, new SyncerExecutor() {

        public void execute() {
            boolean error = false;
            // try to find choosen calendar event in the reloaded event list
            KalendarEvent reloadEvent = event;
            for (Iterator<KalendarEvent> iterator = denEvents.iterator(); iterator.hasNext(); ) {
                KalendarEvent kalendarEvent = iterator.next();
                if (event.getID().equals(kalendarEvent.getID())) {
                    reloadEvent = kalendarEvent;
                    break;
                } else if (!iterator.hasNext()) {
                    // cannot find reloaded calendar event
                    status.setEnrolled(false);
                    status.setErrorMessage(DENStatus.ERROR_GENERAL);
                    error = true;
                }
            }
            Collection<KalendarEvent> collEvents = cal.getEvents();
            // check if date is already full
            if (!error && !allowOverfill && isDateFull(reloadEvent)) {
                status.setEnrolled(false);
                status.setErrorMessage(DENStatus.ERROR_FULL);
                error = true;
            }
            // check if identity is already enrolled
            if (!error && isAlreadyEnrolled(identity, collEvents, courseNode)) {
                status.setEnrolled(false);
                status.setErrorMessage(DENStatus.ERROR_ALREADY_ENROLLED);
                error = true;
            }
            // enroll in event
            if (!error) {
                if (reloadEvent.getParticipants() != null && reloadEvent.getParticipants().length > 0) {
                    int currLength = reloadEvent.getParticipants().length;
                    // one to add
                    String[] partsNew = new String[currLength + 1];
                    String[] partsOld = reloadEvent.getParticipants();
                    for (int i = 0; i < partsOld.length; i++) {
                        partsNew[i] = partsOld[i];
                    }
                    partsNew[partsNew.length - 1] = identity.getName();
                    reloadEvent.setParticipants(partsNew);
                } else {
                    String[] partsNew = new String[] { identity.getName() };
                    reloadEvent.setParticipants(partsNew);
                }
                // save calendar event
                boolean successfullyDone = calManager.updateEventAlreadyInSync(cal, reloadEvent);
                if (!successfullyDone) {
                    status.setEnrolled(false);
                    status.setErrorMessage(DENStatus.ERROR_PERSISTING);
                }
                status.setEnrolled(true);
            }
        }
    });
    // success
    return status;
}
Also used : CalendarManager(org.olat.commons.calendar.CalendarManager) Kalendar(org.olat.commons.calendar.model.Kalendar) OLATResourceable(org.olat.core.id.OLATResourceable) Iterator(java.util.Iterator) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) Collection(java.util.Collection) ICourse(org.olat.course.ICourse) SyncerExecutor(org.olat.core.util.coordinate.SyncerExecutor)

Example 35 with SyncerExecutor

use of org.olat.core.util.coordinate.SyncerExecutor in project OpenOLAT by OpenOLAT.

the class ChecklistManager method updateCheckpoint.

/**
 * Update checkpoint
 * @param checkpoint
 */
public void updateCheckpoint(final Checkpoint cp) {
    OLATResourceable ores = OresHelper.createOLATResourceableInstance(Checkpoint.class, cp.getKey());
    CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(ores, new SyncerExecutor() {

        public void execute() {
            cp.setLastModified(new Date());
            DBFactory.getInstance().updateObject(cp);
        }
    });
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) SyncerExecutor(org.olat.core.util.coordinate.SyncerExecutor) Date(java.util.Date)

Aggregations

SyncerExecutor (org.olat.core.util.coordinate.SyncerExecutor)48 OLATResourceable (org.olat.core.id.OLATResourceable)30 ICourse (org.olat.course.ICourse)12 Property (org.olat.properties.Property)12 Project (org.olat.course.nodes.projectbroker.datamodel.Project)8 CoursePropertyManager (org.olat.course.properties.CoursePropertyManager)8 Identity (org.olat.core.id.Identity)6 MultiUserEvent (org.olat.core.util.event.MultiUserEvent)6 AssessmentChangedEvent (org.olat.course.assessment.AssessmentChangedEvent)6 Date (java.util.Date)4 Iterator (java.util.Iterator)4 Test (org.junit.Test)4 UserNodeAuditManager (org.olat.course.auditing.UserNodeAuditManager)4 ProjectBroker (org.olat.course.nodes.projectbroker.datamodel.ProjectBroker)4 PropertyManager (org.olat.properties.PropertyManager)4 OLATResource (org.olat.resource.OLATResource)4 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 CountDownLatch (java.util.concurrent.CountDownLatch)2