|
|
@ -38,10 +38,14 @@ public class ArchivalServiceImpl implements ArchivalService {
|
|
|
|
private ArchivalDAO archivalDAO;
|
|
|
|
private ArchivalDAO archivalDAO;
|
|
|
|
private DataDeletionDAO dataDeletionDAO;
|
|
|
|
private DataDeletionDAO dataDeletionDAO;
|
|
|
|
|
|
|
|
|
|
|
|
private static int ITERATION_COUNT =
|
|
|
|
private static final int EXECUTION_BATCH_SIZE =
|
|
|
|
DeviceConfigurationManager.getInstance().getDeviceManagementConfig().getArchivalConfiguration()
|
|
|
|
DeviceConfigurationManager.getInstance().getDeviceManagementConfig().getArchivalConfiguration()
|
|
|
|
.getArchivalTaskConfiguration().getBatchSize();
|
|
|
|
.getArchivalTaskConfiguration().getBatchSize();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final boolean ARCHIVE_PENDING_OPERATIONS =
|
|
|
|
|
|
|
|
DeviceConfigurationManager.getInstance().getDeviceManagementConfig().getArchivalConfiguration()
|
|
|
|
|
|
|
|
.getArchivalTaskConfiguration().isArchivePendingOperations();
|
|
|
|
|
|
|
|
|
|
|
|
private String[] NOT_IN_PROGRESS_OPS = new String[]{"COMPLETED", "ERROR", "REPEATED"};
|
|
|
|
private String[] NOT_IN_PROGRESS_OPS = new String[]{"COMPLETED", "ERROR", "REPEATED"};
|
|
|
|
private String[] NOT_PENDING_OPS = new String[]{"COMPLETED", "ERROR", "REPEATED", "IN_PROGRESS"};
|
|
|
|
private String[] NOT_PENDING_OPS = new String[]{"COMPLETED", "ERROR", "REPEATED", "IN_PROGRESS"};
|
|
|
|
private String[] NOT_PENDING_IN_PROGRESS_OPS = new String[]{"COMPLETED", "ERROR", "REPEATED"};
|
|
|
|
private String[] NOT_PENDING_IN_PROGRESS_OPS = new String[]{"COMPLETED", "ERROR", "REPEATED"};
|
|
|
@ -54,7 +58,7 @@ public class ArchivalServiceImpl implements ArchivalService {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void archiveTransactionalRecords() throws ArchivalException {
|
|
|
|
public void archiveTransactionalRecords() throws ArchivalException {
|
|
|
|
List<Integer> allOperations;
|
|
|
|
List<Integer> allOperations;
|
|
|
|
List<Integer> pendingAndIPOperations;
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ArchivalSourceDAOFactory.openConnection();
|
|
|
|
ArchivalSourceDAOFactory.openConnection();
|
|
|
|
ArchivalDestinationDAOFactory.openConnection();
|
|
|
|
ArchivalDestinationDAOFactory.openConnection();
|
|
|
@ -67,7 +71,7 @@ public class ArchivalServiceImpl implements ArchivalService {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Fetching All Pending Operations");
|
|
|
|
log.debug("Fetching All Pending Operations");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pendingAndIPOperations = archivalDAO.getPendingAndInProgressOperations();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (ArchivalDAOException e) {
|
|
|
|
} catch (ArchivalDAOException e) {
|
|
|
|
// rollbackTransactions();
|
|
|
|
// rollbackTransactions();
|
|
|
@ -83,19 +87,35 @@ public class ArchivalServiceImpl implements ArchivalService {
|
|
|
|
ArchivalDestinationDAOFactory.closeConnection();
|
|
|
|
ArchivalDestinationDAOFactory.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
log.info(allOperations.size() + " All Operations. " + pendingAndIPOperations.size() +
|
|
|
|
List<Integer> candidates = allOperations;
|
|
|
|
" P&IP Operations");
|
|
|
|
log.info(allOperations.size() + " All Operations.");
|
|
|
|
//Get the diff of operations
|
|
|
|
|
|
|
|
Set<Integer> setA = new HashSet<>(allOperations);
|
|
|
|
|
|
|
|
Set<Integer> setB = new HashSet<>(pendingAndIPOperations);
|
|
|
|
|
|
|
|
setA.removeAll(setB);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Integer> candidates = new ArrayList<>();
|
|
|
|
if (!ARCHIVE_PENDING_OPERATIONS) {
|
|
|
|
candidates.addAll(setA);
|
|
|
|
try {
|
|
|
|
|
|
|
|
ArchivalSourceDAOFactory.openConnection();
|
|
|
|
|
|
|
|
ArchivalDestinationDAOFactory.openConnection();
|
|
|
|
|
|
|
|
List<Integer> pendingAndIPOperations = archivalDAO.getPendingAndInProgressOperations();
|
|
|
|
|
|
|
|
log.info(pendingAndIPOperations.size() +" P&IP Operations");
|
|
|
|
|
|
|
|
// Get the diff of operations
|
|
|
|
|
|
|
|
candidates.removeAll(pendingAndIPOperations);
|
|
|
|
|
|
|
|
} catch (ArchivalDAOException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while retrieving the pending operations";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new ArchivalException(msg, e);
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
String msg = "An error occurred while connecting to the archival database";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new ArchivalException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
ArchivalSourceDAOFactory.closeConnection();
|
|
|
|
|
|
|
|
ArchivalDestinationDAOFactory.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int total = candidates.size();
|
|
|
|
int total = candidates.size();
|
|
|
|
int batches = calculateNumberOfBatches(total);
|
|
|
|
int batches = calculateNumberOfBatches(total);
|
|
|
|
int batchSize = ITERATION_COUNT;
|
|
|
|
log.info(total + " Operations ready for archiving. " + batches + " iterations to be done.");
|
|
|
|
|
|
|
|
int batchSize = EXECUTION_BATCH_SIZE;
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug(total + " Operations ready for archiving. " + batches + " iterations to be done.");
|
|
|
|
log.debug(total + " Operations ready for archiving. " + batches + " iterations to be done.");
|
|
|
|
log.debug(batchSize + " is the batch size");
|
|
|
|
log.debug(batchSize + " is the batch size");
|
|
|
@ -278,7 +298,7 @@ public class ArchivalServiceImpl implements ArchivalService {
|
|
|
|
|
|
|
|
|
|
|
|
private int calculateNumberOfBatches(int total) {
|
|
|
|
private int calculateNumberOfBatches(int total) {
|
|
|
|
int batches = 0;
|
|
|
|
int batches = 0;
|
|
|
|
int batchSize = ITERATION_COUNT;
|
|
|
|
int batchSize = EXECUTION_BATCH_SIZE;
|
|
|
|
if ((total % batchSize) > 0) {
|
|
|
|
if ((total % batchSize) > 0) {
|
|
|
|
batches = (total / batchSize) + 1;
|
|
|
|
batches = (total / batchSize) + 1;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|