Search in sources :

Example 21 with MetadataRetryContext

use of org.hisp.dhis.dxf2.metadata.jobs.MetadataRetryContext in project dhis2-core by dhis2.

the class MetadataSyncJob method handleMetadataSync.

// ----------------------------------------------------------------------------------------
// Private Methods
// ----------------------------------------------------------------------------------------
private MetadataSyncSummary handleMetadataSync(MetadataRetryContext context, MetadataVersion dataVersion) throws DhisVersionMismatchException {
    MetadataSyncParams syncParams = new MetadataSyncParams(new MetadataImportParams(), dataVersion);
    MetadataSyncSummary metadataSyncSummary = null;
    try {
        metadataSyncSummary = metadataSyncService.doMetadataSync(syncParams);
    } catch (MetadataSyncServiceException e) {
        log.error("Exception happened  while trying to do metadata sync  " + e.getMessage(), e);
        context.updateRetryContext(METADATA_SYNC, e.getMessage(), dataVersion);
        throw e;
    } catch (DhisVersionMismatchException e) {
        context.updateRetryContext(METADATA_SYNC, e.getMessage(), dataVersion);
        throw e;
    }
    return metadataSyncSummary;
}
Also used : MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) MetadataSyncParams(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams) MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) DhisVersionMismatchException(org.hisp.dhis.dxf2.metadata.sync.exception.DhisVersionMismatchException) MetadataSyncSummary(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary)

Example 22 with MetadataRetryContext

use of org.hisp.dhis.dxf2.metadata.jobs.MetadataRetryContext in project dhis2-core by dhis2.

the class MetadataSyncJob method execute.

@Override
public void execute(JobConfiguration jobConfiguration, JobProgress progress) {
    log.info("Metadata Sync cron Job started");
    try {
        MetadataSyncJobParameters jobParameters = (MetadataSyncJobParameters) jobConfiguration.getJobParameters();
        retryTemplate.execute(retryContext -> {
            metadataRetryContext.setRetryContext(retryContext);
            clearFailedVersionSettings();
            runSyncTask(metadataRetryContext, jobParameters);
            return null;
        }, retryContext -> {
            log.info("Metadata Sync failed! Sending mail to Admin");
            updateMetadataVersionFailureDetails(metadataRetryContext);
            metadataSyncPostProcessor.sendFailureMailToAdmin(metadataRetryContext);
            return null;
        });
    } catch (Exception e) {
        String customMessage = "Exception occurred while executing metadata sync task." + e.getMessage();
        log.error(customMessage, e);
    }
}
Also used : MetadataSyncJobParameters(org.hisp.dhis.scheduling.parameters.MetadataSyncJobParameters) DhisVersionMismatchException(org.hisp.dhis.dxf2.metadata.sync.exception.DhisVersionMismatchException) MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException)

Example 23 with MetadataRetryContext

use of org.hisp.dhis.dxf2.metadata.jobs.MetadataRetryContext in project dhis2-core by dhis2.

the class MetadataSyncJob method runSyncTask.

synchronized void runSyncTask(MetadataRetryContext context, MetadataSyncJobParameters jobParameters) throws MetadataSyncServiceException, DhisVersionMismatchException {
    metadataSyncPreProcessor.setUp(context);
    metadataSyncPreProcessor.handleDataValuePush(context, jobParameters);
    metadataSyncPreProcessor.handleEventProgramsDataPush(context, jobParameters);
    metadataSyncPreProcessor.handleCompleteDataSetRegistrationDataPush(context);
    metadataSyncPreProcessor.handleTrackerProgramsDataPush(context, jobParameters);
    MetadataVersion metadataVersion = metadataSyncPreProcessor.handleCurrentMetadataVersion(context);
    List<MetadataVersion> metadataVersionList = metadataSyncPreProcessor.handleMetadataVersionsList(context, metadataVersion);
    if (metadataVersionList != null) {
        for (MetadataVersion dataVersion : metadataVersionList) {
            MetadataSyncParams syncParams = new MetadataSyncParams(new MetadataImportParams(), dataVersion);
            boolean isSyncRequired = metadataSyncService.isSyncRequired(syncParams);
            MetadataSyncSummary metadataSyncSummary = null;
            if (isSyncRequired) {
                metadataSyncSummary = handleMetadataSync(context, dataVersion);
            } else {
                metadataSyncPostProcessor.handleVersionAlreadyExists(context, dataVersion);
                break;
            }
            boolean abortStatus = metadataSyncPostProcessor.handleSyncNotificationsAndAbortStatus(metadataSyncSummary, context, dataVersion);
            if (abortStatus) {
                break;
            }
            clearFailedVersionSettings();
        }
    }
    log.info("Metadata sync cron job ended ");
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) MetadataSyncParams(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams) MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) MetadataSyncSummary(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary)

Example 24 with MetadataRetryContext

use of org.hisp.dhis.dxf2.metadata.jobs.MetadataRetryContext in project dhis2-core by dhis2.

the class MetadataSyncPreProcessor method handleMetadataVersionsList.

public List<MetadataVersion> handleMetadataVersionsList(MetadataRetryContext context, MetadataVersion metadataVersion) {
    log.debug("Fetching the list of remote versions");
    List<MetadataVersion> metadataVersionList;
    try {
        metadataVersionList = metadataVersionDelegate.getMetaDataDifference(metadataVersion);
        if (metadataVersion == null) {
            log.info("There is no initial version in the system");
        }
        if (isRemoteVersionEmpty(metadataVersion, metadataVersionList)) {
            log.info("There are no metadata versions created in the remote instance.");
            return metadataVersionList;
        }
        if (isUsingLatestVersion(metadataVersion, metadataVersionList)) {
            log.info("Your instance is already using the latest version:" + metadataVersion);
            return metadataVersionList;
        }
        MetadataVersion latestVersion = getLatestVersion(metadataVersionList);
        assert latestVersion != null;
        systemSettingManager.saveSystemSetting(SettingKey.REMOTE_METADATA_VERSION, latestVersion.getName());
        log.info("Remote system is at version: " + latestVersion.getName());
    } catch (MetadataVersionServiceException e) {
        String message = setVersionListErrorInfoInContext(context, metadataVersion, e);
        throw new MetadataSyncServiceException(message, e);
    } catch (Exception ex) {
        if (ex instanceof MetadataSyncServiceException) {
            log.error(ex.getMessage(), ex);
            throw ex;
        }
        String message = setVersionListErrorInfoInContext(context, metadataVersion, ex);
        log.error(message, ex);
        throw new MetadataSyncServiceException(message, ex);
    }
    return metadataVersionList;
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) MetadataVersionServiceException(org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException) MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) MetadataVersionServiceException(org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)

Example 25 with MetadataRetryContext

use of org.hisp.dhis.dxf2.metadata.jobs.MetadataRetryContext in project dhis2-core by dhis2.

the class MetadataSyncPreProcessor method handleCurrentMetadataVersion.

public MetadataVersion handleCurrentMetadataVersion(MetadataRetryContext context) {
    log.debug("Getting the current version of the system");
    MetadataVersion metadataVersion;
    try {
        metadataVersion = metadataVersionService.getCurrentVersion();
        log.info("Current Metadata Version of the system: " + metadataVersion);
    } catch (MetadataVersionServiceException ex) {
        context.updateRetryContext(MetadataSyncJob.GET_METADATAVERSION, ex.getMessage(), null, null);
        throw new MetadataSyncServiceException(ex.getMessage(), ex);
    }
    return metadataVersion;
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) MetadataVersionServiceException(org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException) MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException)

Aggregations

Test (org.junit.jupiter.api.Test)15 MetadataRetryContext (org.hisp.dhis.dxf2.metadata.jobs.MetadataRetryContext)13 MetadataSyncServiceException (org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException)12 AvailabilityStatus (org.hisp.dhis.dxf2.synch.AvailabilityStatus)11 MetadataVersion (org.hisp.dhis.metadata.version.MetadataVersion)10 MetadataSyncParams (org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams)8 Date (java.util.Date)6 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)6 DhisSpringTest (org.hisp.dhis.DhisSpringTest)5 IntegrationTest (org.hisp.dhis.IntegrationTest)5 ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)5 DhisVersionMismatchException (org.hisp.dhis.dxf2.metadata.sync.exception.DhisVersionMismatchException)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)4 MetadataSyncSummary (org.hisp.dhis.dxf2.metadata.sync.MetadataSyncSummary)4 MetadataVersionServiceException (org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)4 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)3 MetadataRetryContext (org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext)3 ImportStatus (org.hisp.dhis.dxf2.importsummary.ImportStatus)1