Search in sources :

Example 1 with JobConfiguration

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

the class SchedulerStart method addDefaultJob.

private void addDefaultJob(SystemJob job, List<JobConfiguration> jobConfigurations, Consumer<JobConfiguration> init) {
    if (verifyNoJobExist(job.name, jobConfigurations)) {
        JobConfiguration configuration = new JobConfiguration(job.name, job.type, job.cron, null);
        if (init != null)
            init.accept(configuration);
        configuration.setUid(job.uid);
        configuration.setLeaderOnlyJob(true);
        addAndScheduleJob(configuration);
    }
}
Also used : JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration)

Example 2 with JobConfiguration

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

the class TrackerTrigramIndexingJobTest method testRunJobWithoutAnyAttributesInJobParametersButWithObsoleteIndexes.

@Test
public void testRunJobWithoutAnyAttributesInJobParametersButWithObsoleteIndexes() {
    when(trackedEntityAttributeTableManager.getAttributeIdsWithTrigramIndexCreated()).thenReturn(Arrays.asList(12l, 13l));
    JobConfiguration jobConfiguration = new JobConfiguration();
    TrackerTrigramIndexJobParameters jp = new TrackerTrigramIndexJobParameters();
    jobConfiguration.setJobParameters(jp);
    job.execute(jobConfiguration, NoopJobProgress.INSTANCE);
    verify(trackedEntityAttributeTableManager, never()).createTrigramIndex(any());
    verify(trackedEntityAttributeTableManager, times(2)).dropTrigramIndex(any());
}
Also used : TrackerTrigramIndexJobParameters(org.hisp.dhis.scheduling.parameters.TrackerTrigramIndexJobParameters) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) Test(org.junit.jupiter.api.Test)

Example 3 with JobConfiguration

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

the class JobConfigurationObjectBundleHook method validateNoErrors.

private void validateNoErrors(final JobConfiguration jobConfiguration, Consumer<ErrorReport> addReports) {
    // Check whether jobConfiguration already exists
    JobConfiguration persistedJobConfiguration = jobConfigurationService.getJobConfigurationByUid(jobConfiguration.getUid());
    final JobConfiguration tempJobConfiguration = validatePersistedAndPrepareTempJobConfiguration(addReports, jobConfiguration, persistedJobConfiguration);
    setDefaultJobParameters(tempJobConfiguration);
    validateJobConfigurationCronOrFixedDelay(addReports, tempJobConfiguration);
    validateCronExpressionWithinJobType(addReports, tempJobConfiguration);
    if (tempJobConfiguration.getJobParameters() != null) {
        tempJobConfiguration.getJobParameters().validate().ifPresent(addReports);
    } else {
        if (tempJobConfiguration.getJobType().hasJobParameters()) {
            addReports.accept(new ErrorReport(this.getClass(), ErrorCode.E4029, tempJobConfiguration.getJobType()));
        }
    }
    validateJob(addReports, tempJobConfiguration, persistedJobConfiguration);
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration)

Example 4 with JobConfiguration

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

the class SchedulerStart method execute.

@Override
public void execute() throws Exception {
    Date now = new Date();
    List<String> unexecutedJobs = new ArrayList<>();
    List<JobConfiguration> jobConfigurations = jobConfigurationService.getAllJobConfigurations();
    addDefaultJobs(jobConfigurations);
    jobConfigurations.forEach((jobConfig -> {
        if (jobConfig.isEnabled()) {
            Date oldExecutionTime = jobConfig.getNextExecutionTime();
            jobConfig.setNextExecutionTime(null);
            jobConfig.setJobStatus(SCHEDULED);
            jobConfigurationService.updateJobConfiguration(jobConfig);
            if (jobConfig.getLastExecutedStatus() == FAILED || (oldExecutionTime != null && oldExecutionTime.compareTo(now) < 0)) {
                unexecutedJobs.add("\nJob [" + jobConfig.getUid() + ", " + jobConfig.getName() + "] has status failed or was scheduled in server downtime. Actual execution time was supposed to be: " + oldExecutionTime);
            }
            schedulingManager.schedule(jobConfig);
        }
    }));
    if (!unexecutedJobs.isEmpty()) {
        StringBuilder jobs = new StringBuilder();
        for (String unexecutedJob : unexecutedJobs) {
            jobs.append(unexecutedJob).append("\n");
        }
        messageService.sendSystemErrorNotification("Scheduler startup", new Exception("Scheduler started with one or more unexecuted jobs:\n" + jobs));
    }
}
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) ArrayList(java.util.ArrayList) Date(java.util.Date) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration)

Example 5 with JobConfiguration

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

the class DefaultMetadataImportService method getParamsFromMap.

@Override
@Transactional(readOnly = true)
public MetadataImportParams getParamsFromMap(Map<String, List<String>> parameters) {
    MetadataImportParams params = new MetadataImportParams();
    if (params.getUser() == null) {
        params.setUser(currentUserService.getCurrentUser());
    }
    params.setSkipSharing(getBooleanWithDefault(parameters, "skipSharing", false));
    params.setSkipTranslation(getBooleanWithDefault(parameters, "skipTranslation", false));
    params.setSkipValidation(getBooleanWithDefault(parameters, "skipValidation", false));
    params.setUserOverrideMode(getEnumWithDefault(UserOverrideMode.class, parameters, "userOverrideMode", UserOverrideMode.NONE));
    params.setImportMode(getEnumWithDefault(ObjectBundleMode.class, parameters, "importMode", ObjectBundleMode.COMMIT));
    params.setPreheatMode(getEnumWithDefault(PreheatMode.class, parameters, "preheatMode", PreheatMode.REFERENCE));
    params.setIdentifier(getEnumWithDefault(PreheatIdentifier.class, parameters, "identifier", PreheatIdentifier.UID));
    params.setImportStrategy(getEnumWithDefault(ImportStrategy.class, parameters, "importStrategy", ImportStrategy.CREATE_AND_UPDATE));
    params.setAtomicMode(getEnumWithDefault(AtomicMode.class, parameters, "atomicMode", AtomicMode.ALL));
    params.setMergeMode(getEnumWithDefault(MergeMode.class, parameters, "mergeMode", MergeMode.REPLACE));
    params.setFlushMode(getEnumWithDefault(FlushMode.class, parameters, "flushMode", FlushMode.AUTO));
    params.setImportReportMode(getEnumWithDefault(ImportReportMode.class, parameters, "importReportMode", ImportReportMode.ERRORS));
    params.setFirstRowIsHeader(getBooleanWithDefault(parameters, "firstRowIsHeader", true));
    if (getBooleanWithDefault(parameters, "async", false)) {
        JobConfiguration jobId = new JobConfiguration("metadataImport", JobType.METADATA_IMPORT, params.getUser().getUid(), true);
        notifier.clear(jobId);
        params.setId(jobId);
    }
    if (params.getUserOverrideMode() == UserOverrideMode.SELECTED) {
        User overrideUser = null;
        if (parameters.containsKey("overrideUser")) {
            List<String> overrideUsers = parameters.get("overrideUser");
            overrideUser = manager.get(User.class, overrideUsers.get(0));
        }
        if (overrideUser == null) {
            throw new MetadataImportException("UserOverrideMode.SELECTED is enabled, but overrideUser parameter does not point to a valid user.");
        } else {
            params.setOverrideUser(overrideUser);
        }
    }
    return params;
}
Also used : User(org.hisp.dhis.user.User) ObjectBundleMode(org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleMode) PreheatIdentifier(org.hisp.dhis.preheat.PreheatIdentifier) ImportStrategy(org.hisp.dhis.importexport.ImportStrategy) MergeMode(org.hisp.dhis.common.MergeMode) ImportReportMode(org.hisp.dhis.dxf2.metadata.feedback.ImportReportMode) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) PreheatMode(org.hisp.dhis.preheat.PreheatMode) Transactional(org.springframework.transaction.annotation.Transactional)

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