@@ -2534,49 +2534,51 @@ |
// archive management |
new Thread(() -> { |
if (Config.isArchiveEnabled()) { |
- try { |
- // close log before archiving. |
- LOG.close(); |
- // copy back the files to the workspace to make them |
- // a part o fthe archive |
- File req = new File(getResultsDir(), REQUEST_FILE); |
- if (req.exists()) { |
- FileUtils.copyFileToDirectory(req, getWorkspaceDir()); |
+ if ((Config.getBoolean("csip.archive.failedonly") && serviceError != null) |
+ || !Config.getBoolean("csip.archive.failedonly")) { |
+ try { |
+ long st = System.currentTimeMillis(); |
+ // close log before archiving. |
+ LOG.close(); |
+ // copy back the files to the workspace to make them |
+ // a part o fthe archive |
+ File req = new File(getResultsDir(), REQUEST_FILE); |
+ if (req.exists()) { |
+ FileUtils.copyFileToDirectory(req, getWorkspaceDir()); |
+ } |
+ File res = new File(getResultsDir(), RESPONSE_FILE); |
+ if (res.exists()) { |
+ FileUtils.copyFileToDirectory(res, getWorkspaceDir()); |
+ } |
+ File log = new File(getResultsDir(), LOG_FILE); |
+ if (log.exists()) { |
+ FileUtils.copyFileToDirectory(log, getWorkspaceDir()); |
+ } |
+ File archive = ZipFiles.zip(getWorkspaceDir()); |
+ // move it from session store to archive store. |
+ // turn session into archive |
+ DateFormat df = Dates.newISOFormat(tz); |
+ Date now = new Date(); |
+ Date expDate = Dates.futureDate(now, Dates.getDurationSec("csip.archive.ttl")); |
+ ModelArchive ma = new ModelArchive(df.format(now), df.format(expDate), req_url, ms.getStatus(), ms.getReqIP()); |
+ Config.getArchiveStore().archiveSession(suid, ma, archive); |
+ FileUtils.deleteQuietly(archive); |
+ long en = System.currentTimeMillis(); |
+ LOG.info("Archived " + suid + " in " + (en - st) + " ms."); |
+ Config.getAccessLogStore().log(suid, ms.getService(), ms.getReqIP(), Services.LOCAL_IP_ADDR, ms.getTstamp(), "Archived", -1); |
+ } catch (Exception ex) { |
+ LOG.log(Level.SEVERE, null, ex); |
} |
- File res = new File(getResultsDir(), RESPONSE_FILE); |
- if (res.exists()) { |
- FileUtils.copyFileToDirectory(res, getWorkspaceDir()); |
- } |
- File log = new File(getResultsDir(), LOG_FILE); |
- if (log.exists()) { |
- FileUtils.copyFileToDirectory(log, getWorkspaceDir()); |
- } |
- File archive = ZipFiles.zip(getWorkspaceDir()); |
- // move it from session store to archive store. |
- // turn session into archive |
- DateFormat df = Dates.newISOFormat(tz); |
- Date now = new Date(); |
- Date expDate = Dates.futureDate(now, Dates.getDurationSec("csip.archive.ttl")); |
- ModelArchive ma = new ModelArchive(df.format(now), df.format(expDate), req_url, ms.getStatus(), ms.getReqIP()); |
- Config.getArchiveStore().archiveSession(suid, ma, archive); |
- FileUtils.deleteQuietly(archive); |
- LOG.info("Archived : " + suid); |
- Config.getAccessLogStore().log(suid, ms.getService(), ms.getReqIP(), Services.LOCAL_IP_ADDR, ms.getTstamp(), "Archived", -1); |
- } catch (Exception ex) { |
- LOG.log(Level.SEVERE, null, ex); |
} |
} |
+ // remove the workspace right away |
+ // keep the results, let the Sweeper remove it after ttl |
if (!Config.getBoolean("csip.keepworkspace", false)) { |
FileUtils.deleteQuietly(getWorkspaceDir()); |
} |
- }).start(); |
- |
- // workspace might be gone from here on forward. |
- // copy/save and cleanup |
- // to this in a thread |
- new Thread(() -> { |
+ |
+ // separate therad |
Sweeper r = new Sweeper(ws, hasResultsDir() ? getResultsDir() : null, suid); |
- |
if (ms.getStatus().equals(FAILED)) { |
keepResults = Dates.getDurationSec("csip.session.ttl.failed"); |
} else if (ms.getStatus().equals(CANCELED)) { |
@@ -2588,6 +2590,12 @@ |
r.run(); |
} |
}).start(); |
+ |
+ // workspace might be gone from here on forward. |
+ // copy/save and cleanup |
+ // to this in a thread |
+// new Thread(() -> { |
+// }).start(); |
} catch (Exception ex) { |
LOG.log(Level.SEVERE, null, ex); |
} |