6177036d by Adam Heath

Add a servlet-based implementation of the health checks.

1 parent 17a12c6d
1 <?xml version="1.0" encoding="UTF-8" ?> 1 <?xml version="1.0" encoding="UTF-8" ?>
2 <!-- No copyright or license for configuration file, details here are not considered a creative work. --> 2 <!-- No copyright or license for configuration file, details here are not considered a creative work. -->
3 <moqui-conf xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://moqui.org/xsd/moqui-conf-3.xsd"> 3 <moqui-conf xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://moqui.org/xsd/moqui-conf-3.xsd">
4 <screen-facade> 4 <webapp-list>
5 <screen location="component://webroot/screen/webroot.xml"> 5 <webapp name="webroot">
6 <subscreens-item name="oci-healthchecks" menu-title="OCI - Healthchecks" menu-include="false" 6 <servlet name="OciHealthCheckServlet" class="org.moqui.oci.HealthCheckServlet" load-on-startup="1">
7 location="component://moqui-oci-healthchecks/screen/MoquiOciHealthchecksRoot.xml"/> 7 <url-pattern>/oci/healthchecks/*</url-pattern>
8 </screen> 8 </servlet>
9 </screen-facade> 9 </webapp>
10 </webapp-list>
10 </moqui-conf> 11 </moqui-conf>
......
1 /*
2 * This software is in the public domain under CC0 1.0 Universal plus a
3 * Grant of Patent License.
4 *
5 * To the extent possible under law, the author(s) have dedicated all
6 * copyright and related and neighboring rights to this software to the
7 * public domain worldwide. This software is distributed without any
8 * warranty.
9 *
10 * You should have received a copy of the CC0 Public Domain Dedication
11 * along with this software (see the LICENSE.md file). If not, see
12 * <http://creativecommons.org/publicdomain/zero/1.0/>.
13 */
14
15 apply plugin: 'groovy'
16 apply plugin: 'java-library'
17
18 sourceCompatibility = '1.11'
19 targetCompatibility = '1.11'
20 def moquiDir = projectDir.parentFile.parentFile.parentFile
21 def frameworkDir = file(moquiDir.absolutePath + '/framework')
22 def componentNode = parseComponent(project)
23 version = componentNode.'@version'
24
25 // maybe in the future: repositories { mavenCentral() }
26 repositories {
27 flatDir name: 'localLib', dirs: frameworkDir.absolutePath + '/lib'
28 flatDir name: 'librepo', dirs: projectDir.absolutePath + '/librepo'
29 mavenCentral()
30 }
31
32 // Log4J has annotation processors, disable to avoid warning
33 tasks.withType(JavaCompile) { options.compilerArgs << "-proc:none" }
34 tasks.withType(GroovyCompile) { options.compilerArgs << "-proc:none" }
35
36 dependencies {
37 implementation project(':framework')
38 //implementation 'org.keycloak:keycloak-servlet-filter-adapter:21.0.1'
39 //implementation 'org.keycloak:keycloak-admin-client:21.0.1'
40 //api 'javax.servlet:javax.servlet-api:4.0.1'
41 }
42
43 task cleanLib(type: Delete) { delete fileTree(dir: projectDir.absolutePath+'/lib', include: '*') }
44
45 // by default the Java plugin runs test on build, change to not do that (only run test if explicit task)
46 // no longer workds as of gradle 4.8 or possibly earlier, use clear() instead: check.dependsOn.remove(test)
47 check.dependsOn.clear()
48
49 jar {
50 destinationDir = file(projectDir.absolutePath + '/lib')
51 baseName = componentNode.'@name'
52 }
53
54 task copyDependencies { doLast {
55 copy { from (configurations.runtimeClasspath - project(':framework').configurations.runtimeClasspath - project(':framework').jar.archivePath)
56 into file(projectDir.absolutePath + '/lib') }
57 } }
58 copyDependencies.dependsOn cleanLib
59 jar.dependsOn copyDependencies
60
1 /*
2 * This software is in the public domain under CC0 1.0 Universal plus a
3 * Grant of Patent License.
4 *
5 * To the extent possible under law, the author(s) have dedicated all
6 * copyright and related and neighboring rights to this software to the
7 * public domain worldwide. This software is distributed without any
8 * warranty.
9 *
10 * You should have received a copy of the CC0 Public Domain Dedication
11 * along with this software (see the LICENSE.md file). If not, see
12 * <http://creativecommons.org/publicdomain/zero/1.0/>.
13 */
14
15 package org.moqui.oci
16
17 import groovy.transform.CompileStatic
18
19 import java.io.IOException
20 import javax.servlet.ServletException
21 import javax.servlet.http.HttpServlet
22 import javax.servlet.http.HttpServletRequest
23 import javax.servlet.http.HttpServletResponse
24
25 import org.moqui.context.ExecutionContext
26
27 import org.slf4j.Logger
28 import org.slf4j.LoggerFactory
29
30 @CompileStatic
31 public class HealthCheckServlet extends HttpServlet {
32 protected final static Logger logger = LoggerFactory.getLogger(HealthCheckServlet.class)
33
34 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
35 String pathInfo = request.getPathInfo()
36 switch (pathInfo) {
37 case "/start":
38 response.setStatus(HttpServletResponse.SC_OK)
39 break
40 case "/ready":
41 response.setStatus(HttpServletResponse.SC_OK)
42 break
43 case "/live":
44 response.setStatus(HttpServletResponse.SC_OK)
45 break
46
47 default:
48 response.setStatus(HttpServletResponse.SC_NOT_FOUND)
49 break
50 }
51 }
52 }