activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject [activemq-artemis] branch master updated: ARTEMIS-2596 Move tmp web dir for a safe clean up
Date Tue, 16 Jun 2020 19:31:17 GMT
This is an automated email from the ASF dual-hosted git repository.

clebertsuconic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git


The following commit(s) were added to refs/heads/master by this push:
     new 819f183  ARTEMIS-2596 Move tmp web dir for a safe clean up
     new 91fc0c9  This closes #3187
819f183 is described below

commit 819f1834f5342bd4d425d4c2ff83f3b0bbaef373
Author: brusdev <bruscinodf@gmail.com>
AuthorDate: Tue Jun 16 19:20:07 2020 +0200

    ARTEMIS-2596 Move tmp web dir for a safe clean up
---
 .../artemis/component/WebServerComponent.java      | 38 ++++++++++------------
 .../activemq/cli/test/WebServerComponentTest.java  |  7 ++--
 2 files changed, 20 insertions(+), 25 deletions(-)

diff --git a/artemis-web/src/main/java/org/apache/activemq/artemis/component/WebServerComponent.java
b/artemis-web/src/main/java/org/apache/activemq/artemis/component/WebServerComponent.java
index 701ebd3..e21191c 100644
--- a/artemis-web/src/main/java/org/apache/activemq/artemis/component/WebServerComponent.java
+++ b/artemis-web/src/main/java/org/apache/activemq/artemis/component/WebServerComponent.java
@@ -19,6 +19,7 @@ package org.apache.activemq.artemis.component;
 import java.io.File;
 import java.io.IOException;
 import java.net.URI;
+import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.ArrayList;
@@ -48,7 +49,6 @@ import org.eclipse.jetty.server.handler.ResourceHandler;
 import org.eclipse.jetty.servlet.FilterHolder;
 import org.eclipse.jetty.util.ssl.SslContextFactory;
 import org.eclipse.jetty.webapp.WebAppContext;
-import org.eclipse.jetty.webapp.WebInfConfiguration;
 import org.jboss.logging.Logger;
 
 import javax.servlet.DispatcherType;
@@ -65,6 +65,7 @@ public class WebServerComponent implements ExternalComponent {
    private List<WebAppContext> webContexts;
    private ServerConnector connector;
    private Path artemisHomePath;
+   private Path temporaryWarDir;
 
    @Override
    public void configure(ComponentDTO config, String artemisInstance, String artemisHome)
throws Exception {
@@ -133,6 +134,11 @@ public class WebServerComponent implements ExternalComponent {
       Path homeWarDir = artemisHomePath.resolve(webServerConfig.path).toAbsolutePath();
       Path instanceWarDir = Paths.get(artemisInstance != null ? artemisInstance : ".").resolve(webServerConfig.path).toAbsolutePath();
 
+      temporaryWarDir = Paths.get(artemisInstance != null ? artemisInstance : ".").resolve("tmp").resolve("webapps").toAbsolutePath();
+      if (!Files.exists(temporaryWarDir)) {
+         Files.createDirectories(temporaryWarDir);
+      }
+
       if (webServerConfig.apps != null && webServerConfig.apps.size() > 0) {
          webContexts = new ArrayList<>();
          for (AppDTO app : webServerConfig.apps) {
@@ -283,27 +289,16 @@ public class WebServerComponent implements ExternalComponent {
          //there is no webapp to be deployed (as in some tests)
          return;
       }
-      List<File> temporaryFiles = new ArrayList<>();
 
-      for (WebAppContext context : webContexts) {
-         WebInfConfiguration config = new WebInfConfiguration();
-         try {
-            config.resolveTempDirectory(context);
-            File webTmpBase = context.getTempDirectory().getParentFile();
-            if (webTmpBase.exists()) {
-               webTmpBase.listFiles((f) -> {
-                  temporaryFiles.add(f);
-                  return false;
-               });
-            }
-            if (temporaryFiles.size() > 0) {
-               WebTmpCleaner.cleanupTmpFiles(getLibFolder(), temporaryFiles, true);
-            }
-            //all web contexts share a same base dir. So we only do it once.
-            break;
-         } catch (Exception e) {
-            logger.warn("Failed to get base dir for tmp web files", e);
+      try {
+         List<File> temporaryFiles = new ArrayList<>();
+         Files.newDirectoryStream(temporaryWarDir).forEach(path -> temporaryFiles.add(path.toFile()));
+
+         if (temporaryFiles.size() > 0) {
+            WebTmpCleaner.cleanupTmpFiles(getLibFolder(), temporaryFiles, true);
          }
+      } catch (Exception e) {
+         logger.warn("Failed to get base dir for tmp web files", e);
       }
    }
 
@@ -343,6 +338,9 @@ public class WebServerComponent implements ExternalComponent {
       webapp.addFilter(new FilterHolder(AuthenticationFilter.class), "/auth/login/*", EnumSet.of(DispatcherType.REQUEST));
 
       webapp.setWar(warDirectory.resolve(warFile).toString());
+
+      webapp.setAttribute("org.eclipse.jetty.webapp.basetempdir", temporaryWarDir.toFile().getAbsolutePath());
+
       handlers.addHandler(webapp);
       return webapp;
    }
diff --git a/artemis-web/src/test/java/org/apache/activemq/cli/test/WebServerComponentTest.java
b/artemis-web/src/test/java/org/apache/activemq/cli/test/WebServerComponentTest.java
index e73d2c2..23763a3 100644
--- a/artemis-web/src/test/java/org/apache/activemq/cli/test/WebServerComponentTest.java
+++ b/artemis-web/src/test/java/org/apache/activemq/cli/test/WebServerComponentTest.java
@@ -408,20 +408,17 @@ public class WebServerComponentTest extends Assert {
       //create some garbage
       List<WebAppContext> contexts = webServerComponent.getWebContexts();
 
-      File targetDir = new File("./target");
-      File workDir = new File(targetDir, "web-work");
-      workDir.mkdir();
-
       WebInfConfiguration cfg = new WebInfConfiguration();
       assertEquals(1, contexts.size());
       WebAppContext ctxt = contexts.get(0);
       List<File> garbage = new ArrayList<>();
 
-      ctxt.setAttribute("javax.servlet.context.tempdir", new File(workDir, "jetty-context0"));
 
       cfg.resolveTempDirectory(ctxt);
+
       File tmpdir = ctxt.getTempDirectory();
       File testDir = tmpdir.getParentFile();
+
       createGarbagesInDir(testDir, garbage);
 
       assertTrue(garbage.size() > 0);


Mime
View raw message