You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2012/03/01 08:55:06 UTC

svn commit: r1295448 - in /openejb/trunk/openejb/arquillian-tomee: arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/ arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/ arquillian-tomee-webapp-remote/src/...

Author: rmannibucau
Date: Thu Mar  1 07:55:05 2012
New Revision: 1295448

URL: http://svn.apache.org/viewvc?rev=1295448&view=rev
Log:
trying the retry once pattern for tomee remote arquillian adapter

Modified:
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Setup.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/RemoteTomEEContainer.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/TomEEWebappContainer.java

Modified: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Setup.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Setup.java?rev=1295448&r1=1295447&r2=1295448&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Setup.java (original)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Setup.java Thu Mar  1 07:55:05 2012
@@ -39,6 +39,10 @@ import java.util.Map;
  * @version $Rev$ $Date$
  */
 public class Setup {
+    public static final int DEFAULT_HTTP_PORT = 8080;
+    public static final int DEFAULT_STOP_PORT = 8005;
+    public static final int DEFAULT_AJP_PORT = 8009;
+
     public static void exportProperties(File openejbHome, TomEEConfiguration c) {
         System.setProperty("tomee.http.port", String.valueOf(c.getHttpPort()));
         System.setProperty("tomee.ajp.port", String.valueOf(c.getAjpPort()));
@@ -51,11 +55,11 @@ public class Setup {
         System.setProperty("openejb.home", openejbHome.getAbsolutePath());
     }
 
-    public static void updateServerXml(File openejbHome, TomEEConfiguration c) throws IOException {
+    public static void updateServerXml(File openejbHome, TomEEConfiguration c, int http, int stop, int ajp) throws IOException {
         final Map<String, String> replacements = new HashMap<String, String>();
-        replacements.put("8080", String.valueOf(c.getHttpPort()));
-        replacements.put("8005", String.valueOf(c.getStopPort()));
-        replacements.put("8009", String.valueOf(c.getAjpPort()));
+        replacements.put(Integer.toString(http), String.valueOf(c.getHttpPort()));
+        replacements.put(Integer.toString(stop), String.valueOf(c.getStopPort()));
+        replacements.put(Integer.toString(ajp), String.valueOf(c.getAjpPort()));
         final String s = File.separator;
         replace(replacements, new File(openejbHome, "conf" + s + "server.xml"));
     }

Modified: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java?rev=1295448&r1=1295447&r2=1295448&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java (original)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java Thu Mar  1 07:55:05 2012
@@ -54,6 +54,10 @@ public abstract class TomEEContainer<Con
     protected Map<String, File> moduleIds = new HashMap<String, File>();
     private final Options options;
 
+    protected int previousHttpPort;
+    protected int previousStopPort;
+    protected int previousAjpPort;
+
     protected TomEEContainer() {
         this.options = new Options(System.getProperties());
     }
@@ -65,10 +69,12 @@ public abstract class TomEEContainer<Con
 
         if (prefixes == null) return;
 
+        previousHttpPort = configuration.getHttpPort();
         if (configuration.getHttpPort() <= 0) {
             configuration.setHttpPort(NetworkUtil.getNextAvailablePort());
         }
 
+        previousStopPort = configuration.getStopPort();
         if (configuration.getStopPort() <= 0) {
             configuration.setStopPort(NetworkUtil.getNextAvailablePort());
             if (configuration.getHttpPort() == configuration.getStopPort()) {
@@ -77,6 +83,7 @@ public abstract class TomEEContainer<Con
         }
 
         // only for remote cases
+        previousAjpPort = configuration.getAjpPort();
         if (configuration.getAjpPort() <= 0) {
             configuration.setAjpPort(NetworkUtil.getNextAvailablePort());
             if (configuration.getAjpPort() == configuration.getStopPort() || configuration.getAjpPort() == configuration.getHttpPort()) {
@@ -105,6 +112,21 @@ public abstract class TomEEContainer<Con
         }
     }
 
+    protected void resetPortsToOriginal(Configuration configuration) {
+        int http = configuration.getHttpPort();
+        configuration.setHttpPort(previousHttpPort);
+        int stop = configuration.getStopPort();
+        configuration.setStopPort(previousStopPort);
+        int ajp = configuration.getAjpPort();
+        configuration.setAjpPort(previousAjpPort);
+
+        // keep this port to be able to re-update the modified config
+        // => it means we can try it only once
+        previousHttpPort = http;
+        previousStopPort = stop;
+        previousAjpPort = ajp;
+    }
+
     public abstract void start() throws LifecycleException;
 
     public void stop() throws LifecycleException {

Modified: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/RemoteTomEEContainer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/RemoteTomEEContainer.java?rev=1295448&r1=1295447&r2=1295448&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/RemoteTomEEContainer.java (original)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/RemoteTomEEContainer.java Thu Mar  1 07:55:05 2012
@@ -23,6 +23,7 @@ import org.apache.openejb.config.RemoteS
 import org.jboss.arquillian.container.spi.client.container.LifecycleException;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.Map;
 import java.util.TreeMap;
 import java.util.logging.Logger;
@@ -62,46 +63,60 @@ public class RemoteTomEEContainer extend
 
         try {
 
-            final File workingDirectory = new File(configuration.getDir());
+            configure(Setup.DEFAULT_HTTP_PORT, Setup.DEFAULT_STOP_PORT, Setup.DEFAULT_AJP_PORT);
 
-            if (workingDirectory.exists()) {
+            container = new RemoteServer();
 
-                Files.assertDir(workingDirectory);
+            if (Setup.isRunning(configuration.getHttpPort())) {
+                // try to reconfigure it
+                // if it was using random ports
+                // it can simply be a conflict
+                resetPortsToOriginal(configuration);
+                setup(configuration);
+                configure(previousHttpPort, previousStopPort, previousAjpPort);
+            }
 
-            } else {
+            container.start();
+        } catch (Exception e) {
+            throw new LifecycleException("Unable to start remote container", e);
+        }
+    }
 
-                Files.mkdir(workingDirectory);
-                Files.deleteOnExit(workingDirectory);
-            }
+    private void configure(int http, int stop, int ajp) throws LifecycleException, IOException {
+        final File workingDirectory = new File(configuration.getDir());
 
-            Files.readable(workingDirectory);
-            Files.writable(workingDirectory);
+        if (workingDirectory.exists()) {
 
-            File openejbHome = Setup.findHome(workingDirectory);
+            Files.assertDir(workingDirectory);
 
-            if (openejbHome == null) {
-                openejbHome = Setup.downloadAndUnpack(workingDirectory, configuration.getArtifactName());
-            }
+        } else {
 
-            Files.assertDir(openejbHome);
-            Files.readable(openejbHome);
-            Files.writable(openejbHome);
-
-            Setup.updateServerXml(openejbHome, configuration);
-
-            Setup.exportProperties(openejbHome, configuration);
-
-            if (false) {
-                Map<Object, Object> map = new TreeMap(System.getProperties());
-                for (Map.Entry<Object, Object> entry : map.entrySet()) {
-                    System.out.printf("%s = %s\n", entry.getKey(), entry.getValue());
-                }
-            }
+            Files.mkdir(workingDirectory);
+            Files.deleteOnExit(workingDirectory);
+        }
 
-            container = new RemoteServer();
-            container.start();
-        } catch (Exception e) {
-            throw new LifecycleException("Unable to start remote container", e);
+        Files.readable(workingDirectory);
+        Files.writable(workingDirectory);
+
+        File openejbHome = Setup.findHome(workingDirectory);
+
+        if (openejbHome == null) {
+            openejbHome = Setup.downloadAndUnpack(workingDirectory, configuration.getArtifactName());
+        }
+
+        Files.assertDir(openejbHome);
+        Files.readable(openejbHome);
+        Files.writable(openejbHome);
+
+        Setup.updateServerXml(openejbHome, configuration, http, stop, ajp);
+
+        Setup.exportProperties(openejbHome, configuration);
+
+        if (false) {
+            Map<Object, Object> map = new TreeMap(System.getProperties());
+            for (Map.Entry<Object, Object> entry : map.entrySet()) {
+                System.out.printf("%s = %s\n", entry.getKey(), entry.getValue());
+            }
         }
     }
 

Modified: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/TomEEWebappContainer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/TomEEWebappContainer.java?rev=1295448&r1=1295447&r2=1295448&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/TomEEWebappContainer.java (original)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/main/java/org/apache/tomee/arquillian/webapp/TomEEWebappContainer.java Thu Mar  1 07:55:05 2012
@@ -108,7 +108,7 @@ public class TomEEWebappContainer extend
             Files.readable(openejbHome);
             Files.writable(openejbHome);
 
-            Setup.updateServerXml(openejbHome, configuration);
+            Setup.updateServerXml(openejbHome, configuration, Setup.DEFAULT_HTTP_PORT, Setup.DEFAULT_STOP_PORT, Setup.DEFAULT_AJP_PORT);
             Setup.exportProperties(openejbHome, configuration);
 
             final URL logging = Thread.currentThread().getContextClassLoader().getResource("default.remote.logging.properties");