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. ");
}
}
}
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 ");
}
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;
}
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));
}
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);
}
Aggregations