[tomcat] branch 9.0.x updated: Implement checkContainersAvailable flag

2020-09-11 Thread remm
This is an automated email from the ASF dual-hosted git repository.

remm pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/9.0.x by this push:
 new 6916632  Implement checkContainersAvailable flag
6916632 is described below

commit 6916632c4083521c217e600620ad7faf948ba23f
Author: remm 
AuthorDate: Fri Sep 11 15:54:57 2020 +0200

Implement checkContainersAvailable flag
---
 java/org/apache/catalina/valves/HealthCheckValve.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/java/org/apache/catalina/valves/HealthCheckValve.java 
b/java/org/apache/catalina/valves/HealthCheckValve.java
index 5b75fd6..91b33e9 100644
--- a/java/org/apache/catalina/valves/HealthCheckValve.java
+++ b/java/org/apache/catalina/valves/HealthCheckValve.java
@@ -96,7 +96,7 @@ public class HealthCheckValve extends ValveBase {
 context ? request.getRequestPathMB() : 
request.getDecodedRequestURIMB();
 if (urlMB.equals(path)) {
 response.setContentType("application/json");
-if (isAvailable(getContainer())) {
+if (!checkContainersAvailable || (checkContainersAvailable && 
isAvailable(getContainer( {
 response.getOutputStream().print(UP);
 } else {
 response.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE);


-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[tomcat] branch master updated: Implement checkContainersAvailable flag

2020-09-11 Thread remm
This is an automated email from the ASF dual-hosted git repository.

remm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/master by this push:
 new 120bf9d  Implement checkContainersAvailable flag
120bf9d is described below

commit 120bf9d788a9959edae5417e3fea5b8cefffca02
Author: remm 
AuthorDate: Fri Sep 11 15:54:57 2020 +0200

Implement checkContainersAvailable flag
---
 java/org/apache/catalina/valves/HealthCheckValve.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/java/org/apache/catalina/valves/HealthCheckValve.java 
b/java/org/apache/catalina/valves/HealthCheckValve.java
index c111b3b..3dd9bec 100644
--- a/java/org/apache/catalina/valves/HealthCheckValve.java
+++ b/java/org/apache/catalina/valves/HealthCheckValve.java
@@ -96,7 +96,7 @@ public class HealthCheckValve extends ValveBase {
 context ? request.getRequestPathMB() : 
request.getDecodedRequestURIMB();
 if (urlMB.equals(path)) {
 response.setContentType("application/json");
-if (isAvailable(getContainer())) {
+if (!checkContainersAvailable || (checkContainersAvailable && 
isAvailable(getContainer( {
 response.getOutputStream().print(UP);
 } else {
 response.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE);


-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



Re: [tomcat] branch master updated: Improve the quality of the health check

2020-09-11 Thread Rémy Maucherat
On Fri, Sep 11, 2020 at 2:28 PM Martin Grigorov 
wrote:

> Hi Remy,
>
> I'm not sure whether GitHub notified you about my comment on this commit:
>
> https://github.com/apache/tomcat/commit/2ff7bba79946a3716b136b0752c9fe7126b50499#r42227542
>

I think you're supposed to use the mailing list for that since it's not a
PR.

Rémy


Re: [tomcat] branch master updated: Improve the quality of the health check

2020-09-11 Thread Martin Grigorov
Hi Remy,

I'm not sure whether GitHub notified you about my comment on this commit:
https://github.com/apache/tomcat/commit/2ff7bba79946a3716b136b0752c9fe7126b50499#r42227542

On Fri, Sep 11, 2020 at 2:27 PM  wrote:

> This is an automated email from the ASF dual-hosted git repository.
>
> remm pushed a commit to branch master
> in repository https://gitbox.apache.org/repos/asf/tomcat.git
>
>
> The following commit(s) were added to refs/heads/master by this push:
>  new 2ff7bba  Improve the quality of the health check
> 2ff7bba is described below
>
> commit 2ff7bba79946a3716b136b0752c9fe7126b50499
> Author: remm 
> AuthorDate: Fri Sep 11 13:26:44 2020 +0200
>
> Improve the quality of the health check
>
> The valve will check if its associated container and all its children
> are available. Will return down if any is not available.
> ---
>  .../apache/catalina/valves/HealthCheckValve.java   | 43
> +-
>  webapps/docs/changelog.xml |  8 
>  webapps/docs/config/valve.xml  | 15 +---
>  3 files changed, 60 insertions(+), 6 deletions(-)
>
> diff --git a/java/org/apache/catalina/valves/HealthCheckValve.java
> b/java/org/apache/catalina/valves/HealthCheckValve.java
> index be9c487..c111b3b 100644
> --- a/java/org/apache/catalina/valves/HealthCheckValve.java
> +++ b/java/org/apache/catalina/valves/HealthCheckValve.java
> @@ -19,11 +19,14 @@ package org.apache.catalina.valves;
>  import java.io.IOException;
>
>  import jakarta.servlet.ServletException;
> +import jakarta.servlet.http.HttpServletResponse;
>
> +import org.apache.catalina.Container;
>  import org.apache.catalina.Context;
>  import org.apache.catalina.LifecycleException;
>  import org.apache.catalina.connector.Request;
>  import org.apache.catalina.connector.Response;
> +import org.apache.catalina.util.LifecycleBase;
>  import org.apache.tomcat.util.buf.MessageBytes;
>
>
> @@ -38,6 +41,12 @@ public class HealthCheckValve extends ValveBase {
>  "  \"checks\": []\n" +
>  "}";
>
> +private static final String DOWN =
> +"{\n" +
> +"  \"status\": \"DOWN\",\n" +
> +"  \"checks\": []\n" +
> +"}";
> +
>  private String path = "/health";
>
>  /**
> @@ -45,6 +54,11 @@ public class HealthCheckValve extends ValveBase {
>   */
>  protected boolean context = false;
>
> +/**
> + * Check if all child containers are available.
> + */
> +protected boolean checkContainersAvailable = true;
> +
>  public HealthCheckValve() {
>  super(true);
>  }
> @@ -57,6 +71,14 @@ public class HealthCheckValve extends ValveBase {
>  this.path = path;
>  }
>
> +public boolean getCheckContainersAvailable() {
> +return this.checkContainersAvailable;
> +}
> +
> +public void setCheckContainersAvailable(boolean
> checkContainersAvailable) {
> +this.checkContainersAvailable = checkContainersAvailable;
> +}
> +
>  @Override
>  protected synchronized void startInternal() throws LifecycleException
> {
>  super.startInternal();
> @@ -74,9 +96,28 @@ public class HealthCheckValve extends ValveBase {
>  context ? request.getRequestPathMB() :
> request.getDecodedRequestURIMB();
>  if (urlMB.equals(path)) {
>  response.setContentType("application/json");
> -response.getOutputStream().print(UP);
> +if (isAvailable(getContainer())) {
> +response.getOutputStream().print(UP);
> +} else {
> +
> response.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
> +response.getOutputStream().print(DOWN);
> +}
>  } else {
>  getNext().invoke(request, response);
>  }
>  }
> +
> +protected boolean isAvailable(Container container) {
> +for (Container child : container.findChildren()) {
> +if (!isAvailable(child)) {
> +return false;
> +}
> +}
> +if (container instanceof LifecycleBase) {
> +return ((LifecycleBase) container).getState().isAvailable();
> +} else {
> +return true;
> +}
> +}
> +
>  }
> diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
> index 737bf79..d8695c1 100644
> --- a/webapps/docs/changelog.xml
> +++ b/webapps/docs/changelog.xml
> @@ -45,6 +45,14 @@
>issues do not "pop up" wrt. others).
>  -->
>  
> +  
> +
> +  
> +The health check valve will now check the state of its associated
> +containers to report availability. (remm)
> +  
> +
> +  
>  
>  
>
> diff --git a/webapps/docs/config/valve.xml b/webapps/docs/config/valve.xml
> index 557ee32..3111fce 100644
> --- a/webapps/docs/config/valve.xml
> +++ b/webapps/docs/config/valve.xml
> @@ -2236,10 +2236,7 @@
>
>
>  The Health Check Valve responds to
> -cloud 

[GitHub] [tomcat] martin-g commented on a change in pull request #352: Optimizing Resource Lookup using Bloom Filter

2020-09-11 Thread GitBox


martin-g commented on a change in pull request #352:
URL: https://github.com/apache/tomcat/pull/352#discussion_r486993681



##
File path: java/org/apache/catalina/webresources/JarContents.java
##
@@ -0,0 +1,122 @@
+package org.apache.catalina.webresources;
+
+import java.util.BitSet;
+import java.util.Enumeration;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+/**
+ * This class represents the contents of a jar by determining whether a given
+ * resource might be in the cache, based on a bloom filter. This is not 
a
+ * general-purpose bloom filter because it contains logic to strip out
+ * characters from the beginning of the key.
+ *
+ * The hash methods are simple but good enough for this purpose.
+ */
+public final class JarContents {
+private final BitSet bits1;
+private final BitSet bits2;
+/**
+ * Constant used by a typical hashing method.
+ */
+private static final int HASH_PRIME_1 = 31;
+
+/**
+ * Constant used by a typical hashing method.
+ */
+private static final int HASH_PRIME_2 = 17;
+
+/**
+ * Size of the fixed-length bit table. Larger reduces false positives,
+ * smaller saves memory.
+ */
+private static final int TABLE_SIZE = 2048;
+
+/**
+ * Parses the passed-in jar and populates the bit array.
+ *
+ * @param jar
+ */
+public JarContents(JarFile jar) {
+Enumeration entries = jar.entries();
+bits1 = new BitSet(TABLE_SIZE);
+bits2 = new BitSet(TABLE_SIZE);
+
+// Enumerations. When will they update this API?!
+while (entries.hasMoreElements()) {
+JarEntry entry = entries.nextElement();
+String name = entry.getName();
+int startPos = 0;
+
+// If the path starts with a slash, that's not useful information.
+// Skipping it increases the significance of our key by
+// removing an insignificant character.
+boolean precedingSlash = name.charAt(0) == '/';
+if (precedingSlash) {
+startPos = 1;
+}
+
+// Find the correct table slot
+int pathHash1 = hashcode(name, startPos,HASH_PRIME_1);

Review comment:
   missing space before the third argument





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[GitHub] [tomcat] martin-g commented on a change in pull request #352: Optimizing Resource Lookup using Bloom Filter

2020-09-11 Thread GitBox


martin-g commented on a change in pull request #352:
URL: https://github.com/apache/tomcat/pull/352#discussion_r486991509



##
File path: java/org/apache/catalina/webresources/AbstractArchiveResourceSet.java
##
@@ -211,6 +216,46 @@ public final WebResource getResource(String path) {
 String webAppMount = getWebAppMount();
 WebResourceRoot root = getRoot();
 
+
+/*
+ * This initializes (when necessary) and checks the jarContents, which
+ * is a highly efficient index of the files stored in the jar. If
+ * jarContents reports that this resource definitely does not contain
+ * the path, we can end this method and move on to the next jar.
+ *
+ * Note: the initialization is thread-safe because multiple 
simultaneous
+ * threads will create a complete and valid copy, then set the shared
+ * pointer. This guarantees the shared pointer will always go to a
+ * valid object. The cost of multiple copies is small since only one of
+ * them will be long-lived.
+ */
+try {
+if ((root.getContext() != null) && (root.getContext().getParent()) 
!= null &&
+(((Host) 
root.getContext().getParent()).getFastClasspathScanning())) {
+
+if (jarContents == null ||
+((System.currentTimeMillis() - prevJarOpenTime > 
jarRefreshTime) &&
+!openJarFile().equals(jar))) {

Review comment:
   This will still leak an `opening` of the same jar. If the `equals()` 
returns `true` then it won't enter the body of the `if` and `closeJarFile()` 
won't be called.





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[tomcat] branch 8.5.x updated: Fix intermittent test failure

2020-09-11 Thread markt
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/8.5.x by this push:
 new f1c4117  Fix intermittent test failure
f1c4117 is described below

commit f1c411771bd4c307f26f381e84791fc4e3b08560
Author: Mark Thomas 
AuthorDate: Fri Sep 11 12:42:41 2020 +0100

Fix intermittent test failure
---
 test/org/apache/coyote/http2/TestHttp2Limits.java | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/test/org/apache/coyote/http2/TestHttp2Limits.java 
b/test/org/apache/coyote/http2/TestHttp2Limits.java
index 327bfde..1ef8a29 100644
--- a/test/org/apache/coyote/http2/TestHttp2Limits.java
+++ b/test/org/apache/coyote/http2/TestHttp2Limits.java
@@ -526,6 +526,13 @@ public class TestHttp2Limits extends Http2TestBase {
 // NIO2 can sometimes send window updates depending timing
 skipWindowSizeFrames();
 
+// Async I/O can sometimes result in a stream closed reset before
+// the enhance your calm reset
+if ("3-RST-[5]\n".equals(output.getTrace())) {
+output.clearTrace();
+parser.readFrame(true);
+}
+
 Assert.assertEquals("3-RST-[11]\n", output.getTrace());
 break;
 }


-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[tomcat] branch 9.0.x updated: Fix intermittent test failure

2020-09-11 Thread markt
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/9.0.x by this push:
 new bbee5db  Fix intermittent test failure
bbee5db is described below

commit bbee5db0b839bfc568476f7859fce0413223cfd4
Author: Mark Thomas 
AuthorDate: Fri Sep 11 12:42:41 2020 +0100

Fix intermittent test failure
---
 test/org/apache/coyote/http2/TestHttp2Limits.java | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/test/org/apache/coyote/http2/TestHttp2Limits.java 
b/test/org/apache/coyote/http2/TestHttp2Limits.java
index 327bfde..1ef8a29 100644
--- a/test/org/apache/coyote/http2/TestHttp2Limits.java
+++ b/test/org/apache/coyote/http2/TestHttp2Limits.java
@@ -526,6 +526,13 @@ public class TestHttp2Limits extends Http2TestBase {
 // NIO2 can sometimes send window updates depending timing
 skipWindowSizeFrames();
 
+// Async I/O can sometimes result in a stream closed reset before
+// the enhance your calm reset
+if ("3-RST-[5]\n".equals(output.getTrace())) {
+output.clearTrace();
+parser.readFrame(true);
+}
+
 Assert.assertEquals("3-RST-[11]\n", output.getTrace());
 break;
 }


-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[tomcat] branch master updated: Fix intermittent test failure

2020-09-11 Thread markt
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/master by this push:
 new 6019533  Fix intermittent test failure
6019533 is described below

commit 6019533e651494c05dc879052ab69199af50a035
Author: Mark Thomas 
AuthorDate: Fri Sep 11 12:42:41 2020 +0100

Fix intermittent test failure
---
 test/org/apache/coyote/http2/TestHttp2Limits.java | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/test/org/apache/coyote/http2/TestHttp2Limits.java 
b/test/org/apache/coyote/http2/TestHttp2Limits.java
index 1e9644d..1be65cb 100644
--- a/test/org/apache/coyote/http2/TestHttp2Limits.java
+++ b/test/org/apache/coyote/http2/TestHttp2Limits.java
@@ -526,6 +526,13 @@ public class TestHttp2Limits extends Http2TestBase {
 // NIO2 can sometimes send window updates depending timing
 skipWindowSizeFrames();
 
+// Async I/O can sometimes result in a stream closed reset before
+// the enhance your calm reset
+if ("3-RST-[5]\n".equals(output.getTrace())) {
+output.clearTrace();
+parser.readFrame(true);
+}
+
 Assert.assertEquals("3-RST-[11]\n", output.getTrace());
 break;
 }


-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[tomcat] branch 9.0.x updated: Improve the quality of the health check

2020-09-11 Thread remm
This is an automated email from the ASF dual-hosted git repository.

remm pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/9.0.x by this push:
 new 79c5de4  Improve the quality of the health check
79c5de4 is described below

commit 79c5de4deee98c2a8c5d6f6674db9fbee88f52d8
Author: remm 
AuthorDate: Fri Sep 11 13:26:44 2020 +0200

Improve the quality of the health check

The valve will check if its associated container and all its children
are available. Will return down if any is not available.
---
 .../apache/catalina/valves/HealthCheckValve.java   | 43 +-
 webapps/docs/changelog.xml |  8 
 webapps/docs/config/valve.xml  | 15 +---
 3 files changed, 60 insertions(+), 6 deletions(-)

diff --git a/java/org/apache/catalina/valves/HealthCheckValve.java 
b/java/org/apache/catalina/valves/HealthCheckValve.java
index fb4a8e2..5b75fd6 100644
--- a/java/org/apache/catalina/valves/HealthCheckValve.java
+++ b/java/org/apache/catalina/valves/HealthCheckValve.java
@@ -19,11 +19,14 @@ package org.apache.catalina.valves;
 import java.io.IOException;
 
 import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletResponse;
 
+import org.apache.catalina.Container;
 import org.apache.catalina.Context;
 import org.apache.catalina.LifecycleException;
 import org.apache.catalina.connector.Request;
 import org.apache.catalina.connector.Response;
+import org.apache.catalina.util.LifecycleBase;
 import org.apache.tomcat.util.buf.MessageBytes;
 
 
@@ -38,6 +41,12 @@ public class HealthCheckValve extends ValveBase {
 "  \"checks\": []\n" +
 "}";
 
+private static final String DOWN =
+"{\n" +
+"  \"status\": \"DOWN\",\n" +
+"  \"checks\": []\n" +
+"}";
+
 private String path = "/health";
 
 /**
@@ -45,6 +54,11 @@ public class HealthCheckValve extends ValveBase {
  */
 protected boolean context = false;
 
+/**
+ * Check if all child containers are available.
+ */
+protected boolean checkContainersAvailable = true;
+
 public HealthCheckValve() {
 super(true);
 }
@@ -57,6 +71,14 @@ public class HealthCheckValve extends ValveBase {
 this.path = path;
 }
 
+public boolean getCheckContainersAvailable() {
+return this.checkContainersAvailable;
+}
+
+public void setCheckContainersAvailable(boolean checkContainersAvailable) {
+this.checkContainersAvailable = checkContainersAvailable;
+}
+
 @Override
 protected synchronized void startInternal() throws LifecycleException {
 super.startInternal();
@@ -74,9 +96,28 @@ public class HealthCheckValve extends ValveBase {
 context ? request.getRequestPathMB() : 
request.getDecodedRequestURIMB();
 if (urlMB.equals(path)) {
 response.setContentType("application/json");
-response.getOutputStream().print(UP);
+if (isAvailable(getContainer())) {
+response.getOutputStream().print(UP);
+} else {
+response.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
+response.getOutputStream().print(DOWN);
+}
 } else {
 getNext().invoke(request, response);
 }
 }
+
+protected boolean isAvailable(Container container) {
+for (Container child : container.findChildren()) {
+if (!isAvailable(child)) {
+return false;
+}
+}
+if (container instanceof LifecycleBase) {
+return ((LifecycleBase) container).getState().isAvailable();
+} else {
+return true;
+}
+}
+
 }
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index cb6b9c6..fad0a39 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -45,6 +45,14 @@
   issues do not "pop up" wrt. others).
 -->
 
+  
+
+  
+The health check valve will now check the state of its associated
+containers to report availability. (remm)
+  
+
+  
 
 
   
diff --git a/webapps/docs/config/valve.xml b/webapps/docs/config/valve.xml
index aac0d5a..0a6b0c3 100644
--- a/webapps/docs/config/valve.xml
+++ b/webapps/docs/config/valve.xml
@@ -2232,10 +2232,7 @@
   
 
 The Health Check Valve responds to
-cloud orchestrators health checks. Note that it checks
-that a context is mapped (so that an application is deployed),
-for example if you don't have a ROOT context but demo-1.0
-you have to check for /demo-1.0/health
+cloud orchestrators health checks.
   
 
   
@@ -2251,10 +2248,18 @@
   
 
   
-Path by the cloud orchestrators health check logic.
+Path by the cloud orchestrators health check logic. If the valve
+is associated 

[tomcat] branch master updated: Improve the quality of the health check

2020-09-11 Thread remm
This is an automated email from the ASF dual-hosted git repository.

remm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/master by this push:
 new 2ff7bba  Improve the quality of the health check
2ff7bba is described below

commit 2ff7bba79946a3716b136b0752c9fe7126b50499
Author: remm 
AuthorDate: Fri Sep 11 13:26:44 2020 +0200

Improve the quality of the health check

The valve will check if its associated container and all its children
are available. Will return down if any is not available.
---
 .../apache/catalina/valves/HealthCheckValve.java   | 43 +-
 webapps/docs/changelog.xml |  8 
 webapps/docs/config/valve.xml  | 15 +---
 3 files changed, 60 insertions(+), 6 deletions(-)

diff --git a/java/org/apache/catalina/valves/HealthCheckValve.java 
b/java/org/apache/catalina/valves/HealthCheckValve.java
index be9c487..c111b3b 100644
--- a/java/org/apache/catalina/valves/HealthCheckValve.java
+++ b/java/org/apache/catalina/valves/HealthCheckValve.java
@@ -19,11 +19,14 @@ package org.apache.catalina.valves;
 import java.io.IOException;
 
 import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletResponse;
 
+import org.apache.catalina.Container;
 import org.apache.catalina.Context;
 import org.apache.catalina.LifecycleException;
 import org.apache.catalina.connector.Request;
 import org.apache.catalina.connector.Response;
+import org.apache.catalina.util.LifecycleBase;
 import org.apache.tomcat.util.buf.MessageBytes;
 
 
@@ -38,6 +41,12 @@ public class HealthCheckValve extends ValveBase {
 "  \"checks\": []\n" +
 "}";
 
+private static final String DOWN =
+"{\n" +
+"  \"status\": \"DOWN\",\n" +
+"  \"checks\": []\n" +
+"}";
+
 private String path = "/health";
 
 /**
@@ -45,6 +54,11 @@ public class HealthCheckValve extends ValveBase {
  */
 protected boolean context = false;
 
+/**
+ * Check if all child containers are available.
+ */
+protected boolean checkContainersAvailable = true;
+
 public HealthCheckValve() {
 super(true);
 }
@@ -57,6 +71,14 @@ public class HealthCheckValve extends ValveBase {
 this.path = path;
 }
 
+public boolean getCheckContainersAvailable() {
+return this.checkContainersAvailable;
+}
+
+public void setCheckContainersAvailable(boolean checkContainersAvailable) {
+this.checkContainersAvailable = checkContainersAvailable;
+}
+
 @Override
 protected synchronized void startInternal() throws LifecycleException {
 super.startInternal();
@@ -74,9 +96,28 @@ public class HealthCheckValve extends ValveBase {
 context ? request.getRequestPathMB() : 
request.getDecodedRequestURIMB();
 if (urlMB.equals(path)) {
 response.setContentType("application/json");
-response.getOutputStream().print(UP);
+if (isAvailable(getContainer())) {
+response.getOutputStream().print(UP);
+} else {
+response.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
+response.getOutputStream().print(DOWN);
+}
 } else {
 getNext().invoke(request, response);
 }
 }
+
+protected boolean isAvailable(Container container) {
+for (Container child : container.findChildren()) {
+if (!isAvailable(child)) {
+return false;
+}
+}
+if (container instanceof LifecycleBase) {
+return ((LifecycleBase) container).getState().isAvailable();
+} else {
+return true;
+}
+}
+
 }
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 737bf79..d8695c1 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -45,6 +45,14 @@
   issues do not "pop up" wrt. others).
 -->
 
+  
+
+  
+The health check valve will now check the state of its associated
+containers to report availability. (remm)
+  
+
+  
 
 
   
diff --git a/webapps/docs/config/valve.xml b/webapps/docs/config/valve.xml
index 557ee32..3111fce 100644
--- a/webapps/docs/config/valve.xml
+++ b/webapps/docs/config/valve.xml
@@ -2236,10 +2236,7 @@
   
 
 The Health Check Valve responds to
-cloud orchestrators health checks. Note that it checks
-that a context is mapped (so that an application is deployed),
-for example if you don't have a ROOT context but demo-1.0
-you have to check for /demo-1.0/health
+cloud orchestrators health checks.
   
 
   
@@ -2255,10 +2252,18 @@
   
 
   
-Path by the cloud orchestrators health check logic.
+Path by the cloud orchestrators health check logic. If the valve
+is 

[GitHub] [tomcat] rmaucher commented on a change in pull request #354: Optimize Server startup time using multi-threading for annotation scanning

2020-09-11 Thread GitBox


rmaucher commented on a change in pull request #354:
URL: https://github.com/apache/tomcat/pull/354#discussion_r486924037



##
File path: java/org/apache/catalina/startup/LocalStrings_fr.properties
##
@@ -69,6 +69,7 @@ contextConfig.missingRealm=Aucun royaume (realm) n'a été 
configuré pour réal
 contextConfig.processAnnotationsDir.debug=Balayage du répertoire pour trouver 
des fichiers de classe avec annotations [{0}]
 contextConfig.processAnnotationsJar.debug=Analyse du fichier jars pour des 
classes annotées avec [{0}]
 contextConfig.processAnnotationsWebDir.debug=Balayage du répertoire 
d''applications web, pour fichiers de classe avec annotations [{0}]
+contextConfig.processAnnotationsInParallelFailure=exécution parallèle a échoué

Review comment:
   Yes, the translation is meh. As a rule, I'd say never commit any 
localization IMO, just let others handle in with poeditor later.





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[GitHub] [tomcat] martin-g commented on a change in pull request #354: Optimize Server startup time using multi-threading for annotation scanning

2020-09-11 Thread GitBox


martin-g commented on a change in pull request #354:
URL: https://github.com/apache/tomcat/pull/354#discussion_r486875285



##
File path: java/org/apache/catalina/startup/ContextConfig.java
##
@@ -2136,26 +2146,98 @@ protected InputSource getWebXmlSource(String filename, 
boolean global) {
 }
 
 protected void processAnnotations(Set fragments,
-boolean handlesTypesOnly, Map 
javaClassCache) {
-for(WebXml fragment : fragments) {
-// Only need to scan for @HandlesTypes matches if any of the
-// following are true:
-// - it has already been determined only @HandlesTypes is required
-//   (e.g. main web.xml has metadata-complete="true"
-// - this fragment is for a container JAR (Servlet 3.1 section 8.1)
-// - this fragment has metadata-complete="true"
-boolean htOnly = handlesTypesOnly || !fragment.getWebappJar() ||
-fragment.isMetadataComplete();
-
-WebXml annotations = new WebXml();
-// no impact on distributable
-annotations.setDistributable(true);
-URL url = fragment.getURL();
-processAnnotationsUrl(url, annotations, htOnly, javaClassCache);
-Set set = new HashSet<>();
-set.add(annotations);
-// Merge annotations into fragment - fragment takes priority
-fragment.merge(set);
+boolean handlesTypesOnly, Map 
javaClassCache) {
+
+if (context.getParent() instanceof Host && ((Host) 
context.getParent()).isParallelAnnotationScanning()) {
+processAnnotationsInParallel(fragments, handlesTypesOnly, 
javaClassCache);
+return;
+}
+
+for (WebXml fragment : fragments) {
+scanWebXmlFragment(handlesTypesOnly, fragment, javaClassCache);
+}
+}
+
+private void scanWebXmlFragment(boolean handlesTypesOnly, WebXml fragment, 
Map javaClassCache) {
+
+// Only need to scan for @HandlesTypes matches if any of the
+// following are true:
+// - it has already been determined only @HandlesTypes is required
+//   (e.g. main web.xml has metadata-complete="true"
+// - this fragment is for a container JAR (Servlet 3.1 section 8.1)
+// - this fragment has metadata-complete="true"
+boolean htOnly = handlesTypesOnly || !fragment.getWebappJar() ||
+fragment.isMetadataComplete();
+
+WebXml annotations = new WebXml();
+// no impact on distributable
+annotations.setDistributable(true);
+URL url = fragment.getURL();
+processAnnotationsUrl(url, annotations, htOnly, javaClassCache);
+Set set = new HashSet<>();
+set.add(annotations);
+// Merge annotations into fragment - fragment takes priority
+fragment.merge(set);
+}
+
+/**
+ * Executable task to scan a segment for annotations. Each task does the
+ * same work as the for loop inside processAnnotations();
+ *
+ * @author Engebretson, John
+ * @author Kamnani, Jatin
+ */
+private class AnnotationScanTask implements Callable {

Review comment:
   Why `Callable` ? 
   You can use `Runnable` 





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[GitHub] [tomcat] martin-g commented on a change in pull request #354: Optimize Server startup time using multi-threading for annotation scanning

2020-09-11 Thread GitBox


martin-g commented on a change in pull request #354:
URL: https://github.com/apache/tomcat/pull/354#discussion_r486872606



##
File path: java/org/apache/catalina/startup/ContextConfig.java
##
@@ -2136,26 +2146,98 @@ protected InputSource getWebXmlSource(String filename, 
boolean global) {
 }
 
 protected void processAnnotations(Set fragments,
-boolean handlesTypesOnly, Map 
javaClassCache) {
-for(WebXml fragment : fragments) {
-// Only need to scan for @HandlesTypes matches if any of the
-// following are true:
-// - it has already been determined only @HandlesTypes is required
-//   (e.g. main web.xml has metadata-complete="true"
-// - this fragment is for a container JAR (Servlet 3.1 section 8.1)
-// - this fragment has metadata-complete="true"
-boolean htOnly = handlesTypesOnly || !fragment.getWebappJar() ||
-fragment.isMetadataComplete();
-
-WebXml annotations = new WebXml();
-// no impact on distributable
-annotations.setDistributable(true);
-URL url = fragment.getURL();
-processAnnotationsUrl(url, annotations, htOnly, javaClassCache);
-Set set = new HashSet<>();
-set.add(annotations);
-// Merge annotations into fragment - fragment takes priority
-fragment.merge(set);
+boolean handlesTypesOnly, Map 
javaClassCache) {
+
+if (context.getParent() instanceof Host && ((Host) 
context.getParent()).isParallelAnnotationScanning()) {
+processAnnotationsInParallel(fragments, handlesTypesOnly, 
javaClassCache);
+return;
+}
+
+for (WebXml fragment : fragments) {
+scanWebXmlFragment(handlesTypesOnly, fragment, javaClassCache);
+}
+}
+
+private void scanWebXmlFragment(boolean handlesTypesOnly, WebXml fragment, 
Map javaClassCache) {
+
+// Only need to scan for @HandlesTypes matches if any of the
+// following are true:
+// - it has already been determined only @HandlesTypes is required
+//   (e.g. main web.xml has metadata-complete="true"
+// - this fragment is for a container JAR (Servlet 3.1 section 8.1)
+// - this fragment has metadata-complete="true"
+boolean htOnly = handlesTypesOnly || !fragment.getWebappJar() ||
+fragment.isMetadataComplete();
+
+WebXml annotations = new WebXml();
+// no impact on distributable
+annotations.setDistributable(true);
+URL url = fragment.getURL();
+processAnnotationsUrl(url, annotations, htOnly, javaClassCache);
+Set set = new HashSet<>();
+set.add(annotations);
+// Merge annotations into fragment - fragment takes priority
+fragment.merge(set);
+}
+
+/**
+ * Executable task to scan a segment for annotations. Each task does the
+ * same work as the for loop inside processAnnotations();
+ *
+ * @author Engebretson, John
+ * @author Kamnani, Jatin
+ */
+private class AnnotationScanTask implements Callable {
+private final WebXml fragment;
+private final boolean handlesTypesOnly;
+private Map javaClassCache;
+
+private AnnotationScanTask(WebXml fragment, boolean handlesTypesOnly, 
Map javaClassCache) {
+this.fragment = fragment;
+this.handlesTypesOnly = handlesTypesOnly;
+this.javaClassCache = javaClassCache;
+}
+
+@Override
+public Void call() {
+scanWebXmlFragment(handlesTypesOnly, fragment, javaClassCache);
+
+return null;
+}
+
+}
+
+/**
+ * Parallelized version of processAnnotationsInParallel(). Constructs 
tasks,
+ * submits them as they're created, then waits for completion.
+ *
+ * @param fragmentsSet of parallelizable scans
+ * @param handlesTypesOnly Important parameter for the underlying scan
+ */
+protected void processAnnotationsInParallel(Set fragments, boolean 
handlesTypesOnly,
+Map javaClassCache) {
+
+
+Server s = getServer();
+ExecutorService pool = null;
+try {
+pool = s.getUtilityExecutor();
+List> futures = new ArrayList<>(fragments.size());
+for (WebXml fragment : fragments) {
+Callable task = new AnnotationScanTask(fragment, 
handlesTypesOnly, javaClassCache);
+futures.add(pool.submit(task));
+}
+try {
+for (Future future : futures) {
+future.get();
+}
+} catch (Exception e) {
+throw new 
RuntimeException(sm.getString("contextConfig.processAnnotationsInParallelFailure"),
 e);
+}
+} finally {
+if (pool != 

[GitHub] [tomcat] martin-g commented on a change in pull request #354: Optimize Server startup time using multi-threading for annotation scanning

2020-09-11 Thread GitBox


martin-g commented on a change in pull request #354:
URL: https://github.com/apache/tomcat/pull/354#discussion_r486870063



##
File path: java/org/apache/catalina/startup/LocalStrings_fr.properties
##
@@ -69,6 +69,7 @@ contextConfig.missingRealm=Aucun royaume (realm) n'a été 
configuré pour réal
 contextConfig.processAnnotationsDir.debug=Balayage du répertoire pour trouver 
des fichiers de classe avec annotations [{0}]
 contextConfig.processAnnotationsJar.debug=Analyse du fichier jars pour des 
classes annotées avec [{0}]
 contextConfig.processAnnotationsWebDir.debug=Balayage du répertoire 
d''applications web, pour fichiers de classe avec annotations [{0}]
+contextConfig.processAnnotationsInParallelFailure=exécution parallèle a échoué

Review comment:
   Should `exécution` be capital cased like the other messages ?





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



Re: [VOTE] Release Apache Tomcat 8.5.58

2020-09-11 Thread Martin Grigorov
On Fri, Sep 11, 2020 at 1:10 AM Mark Thomas  wrote:

> The proposed Apache Tomcat 8.5.58 release is now available for voting.
>
> The notable changes compared to the 8.5.57 release are:
>
> - For requests containing the Expect: 100-continue header, optional
>   support has been added to delay sending an intermediate 100 status
>   response until the servlet reads the request body, allowing the
>   servlet the opportunity to respond without asking for the request
>   body. Based on a pull request by malaysf.
>
> - Add support for a read idle timeout and a write idle timeout to the
>   WebSocket session via custom properties in the user properties
>   instance associated with the session. Based on a pull request by
>   sakshamverma.
>
> - Update the packaged version of the Tomcat Native Library to 1.2.25
>
> Along with lots of other bug fixes and improvements.
>
> For full details, see the changelog:
> https://ci.apache.org/projects/tomcat/tomcat85/docs/changelog.html
>
> It can be obtained from:
> https://dist.apache.org/repos/dist/dev/tomcat/tomcat-8/v8.5.58/
>
> The Maven staging repo is:
> https://repository.apache.org/content/repositories/orgapachetomcat-1278/
>
> The tag is:
> https://github.com/apache/tomcat/tree/8.5.58
> 2fe65bc24e48ee5ea079937e6a73576339f871ce
>
> The proposed 8.5.58 release is:
> [ ] Broken - do not release
> [ X ] Stable - go ahead and release as 8.5.58
>

Tested with Apache Wicket 9.x examples app.

Regards,
Martin


>
> -
> To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: dev-h...@tomcat.apache.org
>
>


Re: [VOTE] Release Apache Tomcat 9.0.38

2020-09-11 Thread Mark Thomas
On 10/09/2020 10:03, Mark Thomas wrote:

> The proposed 9.0.38 release is:
> [ ] Broken - do not release
> [X] Stable - go ahead and release as 9.0.38

Unit tests pass for NIO, NIO2 and APR/Native with Tomcat Native 1.2.25
on Windows, MacOS and Linux.

Mark

-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



Re: [VOTE] Release Apache Tomcat 8.5.58

2020-09-11 Thread Mark Thomas
On 10/09/2020 23:10, Mark Thomas wrote:

> The proposed 8.5.58 release is:
> [ ] Broken - do not release
> [X] Stable - go ahead and release as 8.5.58

Unit tests pass for NIO, NIO2 and APR/Native with Tomcat Native 1.2.25
on Windows, MacOS and Linux.

Mark

-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



Re: [VOTE] Release Apache Tomcat 9.0.38

2020-09-11 Thread Martin Grigorov
On Thu, Sep 10, 2020 at 12:03 PM Mark Thomas  wrote:

> The proposed Apache Tomcat 9.0.38 release is now available for voting.
>
> The notable changes compared to the 9.0.37 release are:
>
> - For requests containing the Expect: 100-continue header, optional
>   support has been added to delay sending an intermediate 100 status
>   response until the servlet reads the request body, allowing the
>   servlet the opportunity to respond without asking for the request
>   body. Based on a pull request by malaysf.
>
> - Add support for a read idle timeout and a write idle timeout to the
>   WebSocket session via custom properties in the user properties
>   instance associated with the session. Based on a pull request by
>   sakshamverma.
>
> - Update the packaged version of the Tomcat Native Library to 1.2.25
>
> Along with lots of other bug fixes and improvements.
>
> For full details, see the changelog:
> https://ci.apache.org/projects/tomcat/tomcat9/docs/changelog.html
>
> It can be obtained from:
> https://dist.apache.org/repos/dist/dev/tomcat/tomcat-9/v9.0.38/
> The Maven staging repo is:
> https://repository.apache.org/content/repositories/orgapachetomcat-1277/
> The tag is:
> https://github.com/apache/tomcat/tree/9.0.38
> 48b6a87171e502cc0becbb4c96e2266de4e805e7
>
> The proposed 9.0.38 release is:
> [ ] Broken - do not release
> [ X ] Stable - go ahead and release as 9.0.38
>

Tested with Apache Wicket 9.x examples app.

Regards,
Martin


>
> -
> To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: dev-h...@tomcat.apache.org
>
>


Re: [VOTE] Release Apache Tomcat 10.0.0-M8

2020-09-11 Thread Martin Grigorov
On Wed, Sep 9, 2020 at 5:57 PM Mark Thomas  wrote:

> The proposed Apache Tomcat 10.0.0-M8 release is now available for
> voting.
>
> Apache Tomcat 10.x implements Jakarta EE 9 and, as such, the primary
> package for all the specification APIs has changed from javax.* to
> jakarta.*
> Applications that run on Tomcat 9 will not run on Tomcat 10 without
> changes.
>
> The notable changes compared to 10.0.0-M7 are:
>
> - For requests containing the Expect: 100-continue header, optional
>   support has been added to delay sending an intermediate 100 status
>   response until the servlet reads the request body, allowing the
>   servlet the opportunity to respond without asking for the request
>   body. Based on a pull request by malaysf.
>
> - Add support for a read idle timeout and a write idle timeout to the
>   WebSocket session via custom properties in the user properties
>   instance associated with the session. Based on a pull request by
>   sakshamverma.
>
> - Update the packaged version of the Tomcat Native Library to 1.2.25
>
> Along with lots of other bug fixes and improvements.
>
>
> For full details, see the changelog:
> https://ci.apache.org/projects/tomcat/tomcat10/docs/changelog.html
>
> It can be obtained from:
> https://dist.apache.org/repos/dist/dev/tomcat/tomcat-10/v10.0.0-M8/
> The Maven staging repo is:
>
> https://repository.apache.org/content/repositories/orgapachetomcatrepo-1276/
> The tag is:
> https://github.com/apache/tomcat/tree/10.0.0-M8
> b3f5e0d88336d81a61a767fc10ab06930c9587ee
>
> The proposed 10.0.0-M8 release is:
> [ ] Broken - do not release
> [ X ] Alpha  - go ahead and release as 10.0.0-M8
>

Tested with Apache Wicket examples app (migrated
with tomcat-jakartaee-migration tool).

Regards,
Martin


>
> -
> To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: dev-h...@tomcat.apache.org
>
>


[GitHub] [tomcat] martin-g commented on pull request #356: Micro optimization: replace "".equals(a) with a.isEmpty()

2020-09-11 Thread GitBox


martin-g commented on pull request #356:
URL: https://github.com/apache/tomcat/pull/356#issuecomment-690909792


   > It would be great just to fix all these problems at once
   
   I prefer to make one kind of change at a time. It is easier to detect 
regressions and impact this way.



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[GitHub] [tomcat] stokito commented on pull request #356: Micro optimization: replace "".equals(a) with a.isEmpty()

2020-09-11 Thread GitBox


stokito commented on pull request #356:
URL: https://github.com/apache/tomcat/pull/356#issuecomment-690906236


   In fact Tomcat has hundreds of such places where simple, safe, and more 
readable optimizations can be applied. Just open sources in IntelliJ, open 
Settings/Editor/Inspections/Java/Performarmance and enable all and then run 
Analyze.
   Most hot places are unefficient working with maps like containsKey() then 
get() call and collections ans StringBuilder without initial capacity.
   It would be great just to fix all these problems at once and this will give 
a real impact on performance



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org