use of org.hisp.dhis.scheduling.parameters.MetadataSyncJobParameters in project dhis2-core by dhis2.
the class V2_33_5__Update_job_parameters_with_system_setting_values method migrate.
@Override
public void migrate(final Context context) throws Exception {
// 1. Fetch data from SystemSettings if present
int trackerPageSize = 0;
int eventPageSize = 0;
int dataValuesPageSize = 0;
String sql = "SELECT value FROM systemsetting WHERE name = '" + TRACKER_PROGRAM_SYNC_PAGE_SIZE + "';";
try (Statement stmt = context.getConnection().createStatement();
ResultSet rs = stmt.executeQuery(sql)) {
if (rs.next()) {
trackerPageSize = (Integer) SerializationUtils.deserialize(rs.getBytes("value"));
}
}
sql = "SELECT value FROM systemsetting WHERE name = '" + EVENT_PROGRAM_SYNC_PAGE_SIZE + "';";
try (Statement stmt = context.getConnection().createStatement();
ResultSet rs = stmt.executeQuery(sql)) {
if (rs.next()) {
eventPageSize = (Integer) SerializationUtils.deserialize(rs.getBytes("value"));
}
}
sql = "SELECT value FROM systemsetting WHERE name = '" + DATA_VALUES_SYNC_PAGE_SIZE + "';";
try (Statement stmt = context.getConnection().createStatement();
ResultSet rs = stmt.executeQuery(sql)) {
if (rs.next()) {
dataValuesPageSize = (Integer) SerializationUtils.deserialize(rs.getBytes("value"));
}
}
log.info("Following values were found in SystemSettings: trackerPageSize: " + trackerPageSize + ", eventPageSize: " + eventPageSize + ", dataValuePageSize: " + dataValuesPageSize);
// 2. Update jobParameters with data from SystemSettings
if (trackerPageSize > 0 || eventPageSize > 0 || dataValuesPageSize > 0) {
Map<Integer, JobParameters> updatedJobParameters = new HashMap<>();
ObjectMapper mapper = new ObjectMapper();
mapper.activateDefaultTyping(BasicPolymorphicTypeValidator.builder().allowIfBaseType(JobParameters.class).build());
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
JavaType resultingJavaType = mapper.getTypeFactory().constructType(JobParameters.class);
ObjectReader reader = mapper.readerFor(resultingJavaType);
ObjectWriter writer = mapper.writerFor(resultingJavaType);
if (trackerPageSize > 0) {
sql = "SELECT jobconfigurationid, jsonbjobparameters FROM jobconfiguration " + "WHERE jobtype = '" + JobType.TRACKER_PROGRAMS_DATA_SYNC.name() + "';";
try (Statement stmt = context.getConnection().createStatement();
ResultSet rs = stmt.executeQuery(sql)) {
while (rs.next()) {
TrackerProgramsDataSynchronizationJobParameters jobparams = reader.readValue(rs.getString("jsonbjobparameters"));
jobparams.setPageSize(trackerPageSize);
updatedJobParameters.put(rs.getInt("jobconfigurationid"), jobparams);
}
}
}
if (eventPageSize > 0) {
sql = "SELECT jobconfigurationid, jsonbjobparameters FROM jobconfiguration " + "WHERE jobtype = '" + JobType.EVENT_PROGRAMS_DATA_SYNC.name() + "';";
try (Statement stmt = context.getConnection().createStatement();
ResultSet rs = stmt.executeQuery(sql)) {
while (rs.next()) {
EventProgramsDataSynchronizationJobParameters jobparams = reader.readValue(rs.getString("jsonbjobparameters"));
jobparams.setPageSize(eventPageSize);
updatedJobParameters.put(rs.getInt("jobconfigurationid"), jobparams);
}
}
}
sql = "SELECT jobconfigurationid, jsonbjobparameters FROM jobconfiguration " + "WHERE jobtype = '" + JobType.META_DATA_SYNC.name() + "';";
try (Statement stmt = context.getConnection().createStatement();
ResultSet rs = stmt.executeQuery(sql)) {
while (rs.next()) {
MetadataSyncJobParameters jobparams = reader.readValue(rs.getString("jsonbjobparameters"));
if (trackerPageSize > 0) {
jobparams.setTrackerProgramPageSize(trackerPageSize);
}
if (eventPageSize > 0) {
jobparams.setEventProgramPageSize(eventPageSize);
}
if (dataValuesPageSize > 0) {
jobparams.setDataValuesPageSize(dataValuesPageSize);
}
updatedJobParameters.put(rs.getInt("jobconfigurationid"), jobparams);
}
}
for (Map.Entry<Integer, JobParameters> jobParams : updatedJobParameters.entrySet()) {
try (PreparedStatement ps = context.getConnection().prepareStatement("UPDATE jobconfiguration SET jsonbjobparameters = ? where jobconfigurationid = ?;")) {
PGobject pg = new PGobject();
pg.setType("jsonb");
pg.setValue(writer.writeValueAsString(jobParams.getValue()));
ps.setObject(1, pg);
ps.setInt(2, jobParams.getKey());
ps.execute();
}
}
}
// 3. Remove entries from systemsetting table
try (Statement stmt = context.getConnection().createStatement()) {
stmt.executeUpdate("DELETE FROM systemsetting WHERE name IN ('" + TRACKER_PROGRAM_SYNC_PAGE_SIZE + "', '" + EVENT_PROGRAM_SYNC_PAGE_SIZE + "', '" + DATA_VALUES_SYNC_PAGE_SIZE + "');");
}
}
use of org.hisp.dhis.scheduling.parameters.MetadataSyncJobParameters 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);
}
}
use of org.hisp.dhis.scheduling.parameters.MetadataSyncJobParameters in project dhis2-core by dhis2.
the class V2_35_2__Update_data_sync_job_parameters_with_system_setting_value method fetchDatavaluesPageSizeFromMetadataSyncJobConfiguration.
private int fetchDatavaluesPageSizeFromMetadataSyncJobConfiguration(final Context context) throws SQLException, JsonProcessingException {
int dataValuesPageSize = 0;
String sql = "SELECT jobconfigurationid, jsonbjobparameters FROM jobconfiguration " + "WHERE jobtype = '" + JobType.META_DATA_SYNC.name() + "';";
try (Statement stmt = context.getConnection().createStatement();
ResultSet rs = stmt.executeQuery(sql)) {
if (rs.next()) {
MetadataSyncJobParameters jobparams = reader.readValue(rs.getString("jsonbjobparameters"));
dataValuesPageSize = jobparams.getDataValuesPageSize();
log.info("Value found in Metadata sync job configuration: dataValuePageSize: " + dataValuesPageSize);
}
}
return dataValuesPageSize;
}
Aggregations