Search in sources :

Example 41 with JobConfiguration

use of org.hisp.dhis.scheduling.JobConfiguration in project dhis2-core by dhis2.

the class TrackerRuleEngineMessageManager method consume.

@JmsListener(destination = Topics.TRACKER_IMPORT_RULE_ENGINE_TOPIC_NAME, containerFactory = "jmsQueueListenerContainerFactory")
public void consume(TextMessage message) throws JMSException, IOException {
    TrackerSideEffectDataBundle bundle = toBundle(message);
    if (bundle == null) {
        return;
    }
    JobConfiguration jobConfiguration = new JobConfiguration("", JobType.TRACKER_IMPORT_RULE_ENGINE_JOB, bundle.getAccessedBy(), true);
    bundle.setJobConfiguration(jobConfiguration);
    TrackerRuleEngineThread notificationThread = trackerRuleEngineThreadObjectFactory.getObject();
    notificationThread.setSideEffectDataBundle(bundle);
    executeJob(notificationThread);
}
Also used : JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) JmsListener(org.springframework.jms.annotation.JmsListener)

Example 42 with JobConfiguration

use of org.hisp.dhis.scheduling.JobConfiguration in project dhis2-core by dhis2.

the class NotificationMap method add.

public void add(JobConfiguration configuration, Notification notification) {
    String jobId = configuration.getUid();
    if (jobId == null) {
        return;
    }
    JobType jobType = configuration.getJobType();
    Deque<String> notifications = notificationsJobIdOrder.get(jobType);
    if (notifications.size() > MAX_POOL_TYPE_SIZE) {
        notificationsWithType.get(jobType).remove(notifications.removeLast());
    }
    notifications.addFirst(jobId);
    notificationsWithType.get(jobType).computeIfAbsent(jobId, key -> new ConcurrentLinkedDeque<>()).addFirst(notification);
}
Also used : EnumMap(java.util.EnumMap) Map(java.util.Map) JobType(org.hisp.dhis.scheduling.JobType) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Collections.unmodifiableMap(java.util.Collections.unmodifiableMap) Deque(java.util.Deque) LinkedList(java.util.LinkedList) Arrays.stream(java.util.Arrays.stream) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) JobType(org.hisp.dhis.scheduling.JobType) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque)

Example 43 with JobConfiguration

use of org.hisp.dhis.scheduling.JobConfiguration in project dhis2-core by dhis2.

the class RedisLeaderManager method electLeader.

@Override
public void electLeader() {
    log.debug("Election attempt by nodeId:" + this.nodeUuid);
    redisTemplate.opsForValue().setIfAbsent(KEY, nodeUuid, timeToLiveSeconds, TimeUnit.SECONDS);
    redisTemplate.opsForValue().setIfAbsent(NODE_ID_KEY, nodeId, timeToLiveSeconds, TimeUnit.SECONDS);
    if (isLeader()) {
        renewLeader();
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.SECOND, (int) (this.timeToLiveSeconds / 2));
        log.debug("Next leader renewal job nodeId:%s set at %s", this.nodeUuid, calendar.getTime().toString());
        JobConfiguration leaderRenewalJobConfiguration = new JobConfiguration(CLUSTER_LEADER_RENEWAL, JobType.LEADER_RENEWAL, null, true);
        leaderRenewalJobConfiguration.setLeaderOnlyJob(true);
        schedulingManager.scheduleWithStartTime(leaderRenewalJobConfiguration, calendar.getTime());
    }
}
Also used : Calendar(java.util.Calendar) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration)

Example 44 with JobConfiguration

use of org.hisp.dhis.scheduling.JobConfiguration in project dhis2-core by dhis2.

the class NotifierTest method testInsertingNotificationsInSameJobConcurrently.

@Test
void testInsertingNotificationsInSameJobConcurrently() throws InterruptedException {
    ExecutorService e = Executors.newFixedThreadPool(5);
    JobConfiguration jobConfig = createJobConfig(-1);
    notifier.notify(jobConfig, "somethingid");
    IntStream.range(0, 100).forEach(i -> e.execute(() -> notifier.notify(jobConfig, "somethingid" + i)));
    IntStream.range(0, 100).forEach(i -> {
        for (Notification notification : notifier.getNotificationsByJobType(METADATA_IMPORT).get(jobConfig.getUid())) {
            // Iterate over notifications when new notification are added
            assertNotNull(notification.getUid());
        }
    });
    awaitTermination(e);
    assertEquals(101, notifier.getNotificationsByJobType(METADATA_IMPORT).get(jobConfig.getUid()).size());
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 45 with JobConfiguration

use of org.hisp.dhis.scheduling.JobConfiguration in project dhis2-core by dhis2.

the class NotifierTest method createJobConfig.

private JobConfiguration createJobConfig(int i) {
    JobConfiguration jobConfig = new JobConfiguration(null, METADATA_IMPORT, user.getUid(), false);
    jobConfig.setUid("jobId" + i);
    return jobConfig;
}
Also used : JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration)

Aggregations

JobConfiguration (org.hisp.dhis.scheduling.JobConfiguration)55 Test (org.junit.jupiter.api.Test)23 ErrorReport (org.hisp.dhis.feedback.ErrorReport)10 List (java.util.List)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 ArrayList (java.util.ArrayList)5 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 InputStream (java.io.InputStream)4 IdScheme (org.hisp.dhis.common.IdScheme)4 CachingMap (org.hisp.dhis.commons.collection.CachingMap)4 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)4 ImportStrategy (org.hisp.dhis.importexport.ImportStrategy)4 Collections (java.util.Collections)3 HashMap (java.util.HashMap)3 IdSchemes (org.hisp.dhis.common.IdSchemes)3 IdentifiableObjectManager (org.hisp.dhis.common.IdentifiableObjectManager)3 TrackerTrigramIndexJobParameters (org.hisp.dhis.scheduling.parameters.TrackerTrigramIndexJobParameters)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3