Search in sources :

Example 21 with JobConfiguration

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

the class ValidationController method runValidationNotificationsTask.

@RequestMapping(value = "/sendNotifications", method = { RequestMethod.PUT, RequestMethod.POST })
@PreAuthorize("hasRole('ALL') or hasRole('M_dhis-web-app-management')")
@ResponseBody
public WebMessage runValidationNotificationsTask() {
    JobConfiguration validationResultNotification = new JobConfiguration("validation result notification from validation controller", JobType.VALIDATION_RESULTS_NOTIFICATION, "", null);
    validationResultNotification.setInMemoryJob(true);
    validationResultNotification.setUid(CodeGenerator.generateUid());
    schedulingManager.executeNow(validationResultNotification);
    return ok("Initiated validation result notification");
}
Also used : JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 22 with JobConfiguration

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

the class SchedulerStart method checkLeaderElectionJobConfiguration.

private void checkLeaderElectionJobConfiguration(List<JobConfiguration> jobConfigurations) {
    Optional<JobConfiguration> maybeLeaderElection = jobConfigurations.stream().filter(configuration -> configuration.getName().equals(SystemJob.LEADER_ELECTION.name)).findFirst();
    if (maybeLeaderElection.isPresent()) {
        JobConfiguration leaderElection = maybeLeaderElection.get();
        leaderElection.setCronExpression(format(LEADER_JOB_CRON_FORMAT, leaderElectionTime));
        leaderElection.setEnabled(redisEnabled);
        jobConfigurationService.updateJobConfiguration(leaderElection);
    }
}
Also used : REMOVE_USED_OR_EXPIRED_RESERVED_VALUES(org.hisp.dhis.scheduling.JobType.REMOVE_USED_OR_EXPIRED_RESERVED_VALUES) SchedulingManager(org.hisp.dhis.scheduling.SchedulingManager) JobStatus(org.hisp.dhis.scheduling.JobStatus) AbstractStartupRoutine(org.hisp.dhis.system.startup.AbstractStartupRoutine) Date(java.util.Date) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) FILE_RESOURCE_CLEANUP(org.hisp.dhis.scheduling.JobType.FILE_RESOURCE_CLEANUP) MessageService(org.hisp.dhis.message.MessageService) FAILED(org.hisp.dhis.scheduling.JobStatus.FAILED) String.format(java.lang.String.format) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) SCHEDULED(org.hisp.dhis.scheduling.JobStatus.SCHEDULED) JobConfigurationService(org.hisp.dhis.scheduling.JobConfigurationService) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) JobType(org.hisp.dhis.scheduling.JobType) Optional(java.util.Optional) SettingKey(org.hisp.dhis.setting.SettingKey) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) SystemSettingManager(org.hisp.dhis.setting.SystemSettingManager) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration)

Example 23 with JobConfiguration

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

the class SchedulerStart method addDefaultJobs.

private void addDefaultJobs(List<JobConfiguration> jobConfigurations) {
    log.info("Setting up default jobs.");
    addDefaultJob(SystemJob.FILE_RESOURCE, jobConfigurations);
    addDefaultJob(SystemJob.DATA_STATISTICS, jobConfigurations, config -> portJob(config, SettingKey.LAST_SUCCESSFUL_DATA_STATISTICS));
    addDefaultJob(SystemJob.VALIDATION_RESULTS_NOTIFICATION, jobConfigurations);
    addDefaultJob(SystemJob.CREDENTIALS_EXPIRY_ALERT, jobConfigurations);
    addDefaultJob(SystemJob.ACCOUNT_EXPIRY_ALERT, jobConfigurations);
    addDefaultJob(SystemJob.DATA_SET_NOTIFICATION, jobConfigurations);
    addDefaultJob(SystemJob.REMOVE_EXPIRED_OR_USED_RESERVED_VALUES, jobConfigurations);
    addDefaultJob(SystemJob.SYSTEM_VERSION_UPDATE_CHECK, jobConfigurations);
    if (redisEnabled && verifyNoJobExist(SystemJob.LEADER_ELECTION.name, jobConfigurations)) {
        JobConfiguration leaderElectionJobConfiguration = new JobConfiguration(SystemJob.LEADER_ELECTION.name, SystemJob.LEADER_ELECTION.type, format(SystemJob.LEADER_ELECTION.cron, leaderElectionTime), null);
        leaderElectionJobConfiguration.setLeaderOnlyJob(false);
        leaderElectionJobConfiguration.setUid(SystemJob.LEADER_ELECTION.uid);
        addAndScheduleJob(leaderElectionJobConfiguration);
    } else {
        checkLeaderElectionJobConfiguration(jobConfigurations);
    }
}
Also used : JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration)

Example 24 with JobConfiguration

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

the class TrackerTrigramIndexingJobTest method testRunJobWithNonIndexableAttributesInJobParameters.

@Test
public void testRunJobWithNonIndexableAttributesInJobParameters() {
    when(trackedEntityAttributeService.getAllTrigramIndexableTrackedEntityAttributes()).thenReturn(Collections.singleton(new TrackedEntityAttribute()));
    JobConfiguration jobConfiguration = new JobConfiguration();
    TrackerTrigramIndexJobParameters jp = new TrackerTrigramIndexJobParameters();
    jp.setAttributes(Collections.singleton("aaaa"));
    jobConfiguration.setJobParameters(jp);
    job.execute(jobConfiguration, NoopJobProgress.INSTANCE);
    verify(trackedEntityAttributeTableManager, never()).createTrigramIndex(any());
}
Also used : TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackerTrigramIndexJobParameters(org.hisp.dhis.scheduling.parameters.TrackerTrigramIndexJobParameters) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) Test(org.junit.jupiter.api.Test)

Example 25 with JobConfiguration

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

the class TrackerTrigramIndexingJobTest method testRunJobWithoutAnyAttributesInJobParametersAndWithoutAnyObsolete.

@Test
public void testRunJobWithoutAnyAttributesInJobParametersAndWithoutAnyObsolete() {
    JobConfiguration jobConfiguration = new JobConfiguration();
    TrackerTrigramIndexJobParameters jp = new TrackerTrigramIndexJobParameters();
    jobConfiguration.setJobParameters(jp);
    job.execute(jobConfiguration, NoopJobProgress.INSTANCE);
    verify(trackedEntityAttributeTableManager, never()).createTrigramIndex(any());
    verify(trackedEntityAttributeTableManager, never()).dropTrigramIndex(any());
}
Also used : TrackerTrigramIndexJobParameters(org.hisp.dhis.scheduling.parameters.TrackerTrigramIndexJobParameters) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) Test(org.junit.jupiter.api.Test)

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