Displaying differences for changeset
 
display as  

src/csip/Config.java

@@ -105,7 +105,7 @@
         /* 
          The CSIP version
          */
-        put("csip.version", "$version: 2.1.18 eb62ecc0fa3a 2016-04-04 od, built at 2016-04-05 09:59 by od$");
+        put("csip.version", "$version: 2.1.19 ef68eeef9b91 2016-04-05 od, built at 2016-04-07 10:04 by od$");
 
         /*
          * The runtime architecture. 
@@ -185,6 +185,11 @@
            see duration string examples: https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html#parse-java.lang.CharSequence-.
          */
         put("csip.archive.ttl", "P1D");  //  one day.
+        
+        /* 
+         If the archive is enabled, only archive failed runs, default: false
+         */
+        put("csip.archive.failedonly", "false");
 
         // logger
         /*

src/csip/ModelDataService.java

@@ -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);
                 }