Search in sources :

Example 1 with MetadataRetryContext

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

the class MetadataSyncPreProcessor method handleAggregateImportSummary.

//----------------------------------------------------------------------------------------
// Private Methods
//----------------------------------------------------------------------------------------
private void handleAggregateImportSummary(ImportSummary importSummary, MetadataRetryContext context) {
    if (importSummary != null) {
        ImportStatus status = importSummary.getStatus();
        if (ImportStatus.ERROR.equals(status) || ImportStatus.WARNING.equals(status)) {
            log.error("Import Summary description: " + importSummary.getDescription());
            context.updateRetryContext(MetadataSyncTask.DATA_PUSH_SUMMARY, importSummary.getDescription(), null, null);
            throw new MetadataSyncServiceException("The Data Push was not successful. ");
        }
    }
}
Also used : MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) ImportStatus(org.hisp.dhis.dxf2.importsummary.ImportStatus)

Example 2 with MetadataRetryContext

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

the class MetadataSyncTask method runSyncTask.

public synchronized void runSyncTask(MetadataRetryContext context) throws MetadataSyncServiceException, DhisVersionMismatchException {
    metadataSyncPreProcessor.setUp(context);
    metadataSyncPreProcessor.handleAggregateDataPush(context);
    metadataSyncPreProcessor.handleEventDataPush(context);
    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;
            }
            systemSettingManager.saveSystemSetting(SettingKey.LAST_SUCCESSFUL_METADATA_SYNC, dataVersion.getImportDate());
            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 3 with MetadataRetryContext

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

the class MetadataSyncPreProcessor method handleEventDataPush.

public ImportSummaries handleEventDataPush(MetadataRetryContext context) {
    log.debug("Entering event data push");
    ImportSummaries importSummary = null;
    AvailabilityStatus remoteServerAvailable = synchronizationManager.isRemoteServerAvailable();
    if (!remoteServerAvailable.isAvailable()) {
        String message = remoteServerAvailable.getMessage();
        log.error(message);
        context.updateRetryContext(MetadataSyncTask.EVENT_PUSH_SUMMARY, remoteServerAvailable.getMessage(), null, null);
        throw new MetadataSyncServiceException(message);
    }
    try {
        importSummary = synchronizationManager.executeEventPush();
        handleEventImportSummary(importSummary, context);
    } catch (Exception ex) {
        log.error("Exception happened while trying to do event data push " + ex.getMessage(), ex);
        if (ex instanceof MetadataSyncServiceException) {
            throw (MetadataSyncServiceException) ex;
        }
        context.updateRetryContext(MetadataSyncTask.EVENT_PUSH_SUMMARY, ex.getMessage(), null, null);
        throw new MetadataSyncServiceException(ex.getMessage(), ex);
    }
    log.debug("Exiting event data push");
    return importSummary;
}
Also used : MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) AvailabilityStatus(org.hisp.dhis.dxf2.synch.AvailabilityStatus) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) MetadataVersionServiceException(org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)

Example 4 with MetadataRetryContext

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

the class MetadataSyncTaskTest method testShouldAbortIfDHISVersionMismatch.

@Test(expected = DhisVersionMismatchException.class)
public void testShouldAbortIfDHISVersionMismatch() throws Exception {
    metadataVersions.add(metadataVersion);
    when(metadataSyncPreProcessor.handleCurrentMetadataVersion(metadataRetryContext)).thenReturn(metadataVersion);
    when(metadataSyncPreProcessor.handleMetadataVersionsList(metadataRetryContext, metadataVersion)).thenReturn(metadataVersions);
    when(metadataSyncService.doMetadataSync(any(MetadataSyncParams.class))).thenThrow(new DhisVersionMismatchException(""));
    when(metadataSyncService.isSyncRequired(any(MetadataSyncParams.class))).thenReturn(true);
    metadataSyncTask.runSyncTask(metadataRetryContext);
    verify(metadataSyncPreProcessor, times(1)).setUp(metadataRetryContext);
    verify(metadataSyncPreProcessor, times(1)).handleAggregateDataPush(metadataRetryContext);
    verify(metadataSyncPreProcessor, times(1)).handleEventDataPush(metadataRetryContext);
    verify(metadataSyncPreProcessor, times(1)).handleCurrentMetadataVersion(metadataRetryContext);
    verify(metadataSyncPreProcessor, times(1)).handleMetadataVersionsList(metadataRetryContext, metadataVersion);
    verify(metadataSyncService, times(1)).doMetadataSync(any(MetadataSyncParams.class));
}
Also used : MetadataSyncParams(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams) DhisVersionMismatchException(org.hisp.dhis.dxf2.metadata.sync.exception.DhisVersionMismatchException) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 5 with MetadataRetryContext

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

the class MetadataSyncTaskTest method testHandleMetadataSyncIsThrowingException.

@Test(expected = MetadataSyncServiceException.class)
public void testHandleMetadataSyncIsThrowingException() throws Exception {
    when(metadataSyncService.doMetadataSync(any(MetadataSyncParams.class))).thenThrow(new MetadataSyncServiceException(""));
    when(metadataSyncPreProcessor.handleCurrentMetadataVersion(metadataRetryContext)).thenReturn(metadataVersion);
    when(metadataSyncPreProcessor.handleMetadataVersionsList(metadataRetryContext, metadataVersion)).thenReturn(metadataVersions);
    doNothing().when(metadataRetryContext).updateRetryContext(any(String.class), any(String.class), eq(metadataVersion));
    when(metadataSyncService.isSyncRequired(any(MetadataSyncParams.class))).thenReturn(true);
    metadataSyncTask.runSyncTask(metadataRetryContext);
    verify(metadataSyncPreProcessor).setUp(metadataRetryContext);
    verify(metadataSyncPreProcessor).handleAggregateDataPush(metadataRetryContext);
    verify(metadataSyncPreProcessor).handleEventDataPush(metadataRetryContext);
    verify(metadataSyncPreProcessor).handleCurrentMetadataVersion(metadataRetryContext);
    verify(metadataSyncPreProcessor).handleMetadataVersionsList(metadataRetryContext, metadataVersion);
    verify(metadataSyncService).doMetadataSync(any(MetadataSyncParams.class));
    verify(metadataSyncPostProcessor, never()).handleSyncNotificationsAndAbortStatus(metadataSyncSummary, metadataRetryContext, metadataVersion);
}
Also used : MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException) MetadataSyncParams(org.hisp.dhis.dxf2.metadata.sync.MetadataSyncParams) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

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