You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ad...@apache.org on 2018/08/27 12:18:18 UTC
[1/8] james-project git commit: MAILBOX-338 Correct dashboard for
gauges
Repository: james-project
Updated Branches:
refs/heads/master 9d3211cb5 -> 3b648e90f
MAILBOX-338 Correct dashboard for gauges
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/0fead0d3
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/0fead0d3
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/0fead0d3
Branch: refs/heads/master
Commit: 0fead0d3e9722e493e7369b72f7d596d7667cf53
Parents: 9d3211c
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Aug 27 14:51:36 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Mon Aug 27 14:51:36 2018 +0700
----------------------------------------------------------------------
grafana-reporting/Tika-1522226794419.json | 807 ++++++++++++++++++++++++-
1 file changed, 784 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/0fead0d3/grafana-reporting/Tika-1522226794419.json
----------------------------------------------------------------------
diff --git a/grafana-reporting/Tika-1522226794419.json b/grafana-reporting/Tika-1522226794419.json
index 76112b6..4159f5b 100644
--- a/grafana-reporting/Tika-1522226794419.json
+++ b/grafana-reporting/Tika-1522226794419.json
@@ -51,13 +51,13 @@
"fill": 1,
"id": 8,
"legend": {
- "avg": false,
+ "avg": true,
"current": false,
"max": false,
"min": false,
"show": true,
"total": false,
- "values": false
+ "values": true
},
"lines": true,
"linewidth": 1,
@@ -67,8 +67,13 @@
"pointradius": 5,
"points": false,
"renderer": "flot",
- "seriesOverrides": [],
- "span": 12,
+ "seriesOverrides": [
+ {
+ "alias": "Derivative Max count",
+ "yaxis": 2
+ }
+ ],
+ "span": 6,
"stack": false,
"steppedLine": false,
"targets": [
@@ -95,6 +100,14 @@
"pipelineAgg": "3",
"settings": {},
"type": "max"
+ },
+ {
+ "field": "1",
+ "id": "3",
+ "meta": {},
+ "pipelineAgg": "1",
+ "settings": {},
+ "type": "derivative"
}
],
"query": "name:tikaTextExtraction",
@@ -128,7 +141,7 @@
"show": true
},
{
- "format": "short",
+ "format": "opm",
"label": null,
"logBase": 1,
"max": null,
@@ -136,19 +149,7 @@
"show": true
}
]
- }
- ],
- "repeat": null,
- "repeatIteration": null,
- "repeatRowId": null,
- "showTitle": false,
- "title": "Dashboard Row",
- "titleSize": "h6"
- },
- {
- "collapse": false,
- "height": 553,
- "panels": [
+ },
{
"aliasColors": {},
"bars": false,
@@ -156,13 +157,13 @@
"fill": 1,
"id": 9,
"legend": {
- "avg": false,
+ "avg": true,
"current": false,
- "max": false,
+ "max": true,
"min": false,
"show": true,
"total": false,
- "values": false
+ "values": true
},
"lines": true,
"linewidth": 1,
@@ -173,7 +174,7 @@
"points": false,
"renderer": "flot",
"seriesOverrides": [],
- "span": 12,
+ "span": 6,
"stack": false,
"steppedLine": false,
"targets": [
@@ -269,6 +270,766 @@
"showTitle": false,
"title": "Dashboard Row",
"titleSize": "h6"
+ },
+ {
+ "collapse": false,
+ "height": 303,
+ "panels": [
+ {
+ "aliasColors": {},
+ "bars": false,
+ "datasource": "${DS_JAMES_ES}",
+ "fill": 1,
+ "id": 10,
+ "legend": {
+ "avg": false,
+ "current": false,
+ "max": false,
+ "min": false,
+ "show": true,
+ "total": false,
+ "values": false
+ },
+ "lines": true,
+ "linewidth": 1,
+ "links": [],
+ "nullPointMode": "null",
+ "percentage": false,
+ "pointradius": 5,
+ "points": false,
+ "renderer": "flot",
+ "seriesOverrides": [
+ {
+ "alias": "Derivative Max count",
+ "yaxis": 2
+ }
+ ],
+ "span": 3,
+ "stack": false,
+ "steppedLine": false,
+ "targets": [
+ {
+ "bucketAggs": [
+ {
+ "field": "@timestamp",
+ "id": "2",
+ "settings": {
+ "interval": "auto",
+ "min_doc_count": 0,
+ "trimEdges": 0
+ },
+ "type": "date_histogram"
+ }
+ ],
+ "dsType": "elasticsearch",
+ "hide": false,
+ "metrics": [
+ {
+ "field": "value",
+ "id": "1",
+ "meta": {},
+ "pipelineAgg": "3",
+ "settings": {},
+ "type": "max"
+ }
+ ],
+ "query": "name:textExtractor.cache.hit.rate",
+ "refId": "A",
+ "timeField": "@timestamp"
+ }
+ ],
+ "thresholds": [],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Cache hit rate",
+ "tooltip": {
+ "shared": true,
+ "sort": 0,
+ "value_type": "individual"
+ },
+ "type": "graph",
+ "xaxis": {
+ "mode": "time",
+ "name": null,
+ "show": true,
+ "values": []
+ },
+ "yaxes": [
+ {
+ "format": "none",
+ "label": null,
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": true
+ },
+ {
+ "format": "opm",
+ "label": null,
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": true
+ }
+ ]
+ },
+ {
+ "aliasColors": {},
+ "bars": false,
+ "datasource": "${DS_JAMES_ES}",
+ "fill": 1,
+ "id": 11,
+ "legend": {
+ "avg": false,
+ "current": false,
+ "max": false,
+ "min": false,
+ "show": true,
+ "total": false,
+ "values": false
+ },
+ "lines": true,
+ "linewidth": 1,
+ "links": [],
+ "nullPointMode": "null",
+ "percentage": false,
+ "pointradius": 5,
+ "points": false,
+ "renderer": "flot",
+ "seriesOverrides": [
+ {
+ "alias": "Derivative Max count",
+ "yaxis": 2
+ }
+ ],
+ "span": 3,
+ "stack": false,
+ "steppedLine": false,
+ "targets": [
+ {
+ "bucketAggs": [
+ {
+ "field": "@timestamp",
+ "id": "2",
+ "settings": {
+ "interval": "auto",
+ "min_doc_count": 0,
+ "trimEdges": 0
+ },
+ "type": "date_histogram"
+ }
+ ],
+ "dsType": "elasticsearch",
+ "hide": false,
+ "metrics": [
+ {
+ "field": "value",
+ "id": "1",
+ "meta": {},
+ "pipelineAgg": "3",
+ "settings": {},
+ "type": "max"
+ }
+ ],
+ "query": "name:textExtractor.cache.size",
+ "refId": "A",
+ "timeField": "@timestamp"
+ }
+ ],
+ "thresholds": [],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Cache Size",
+ "tooltip": {
+ "shared": true,
+ "sort": 0,
+ "value_type": "individual"
+ },
+ "type": "graph",
+ "xaxis": {
+ "mode": "time",
+ "name": null,
+ "show": true,
+ "values": []
+ },
+ "yaxes": [
+ {
+ "format": "none",
+ "label": null,
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": true
+ },
+ {
+ "format": "opm",
+ "label": null,
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": true
+ }
+ ]
+ },
+ {
+ "aliasColors": {},
+ "bars": false,
+ "datasource": "${DS_JAMES_ES}",
+ "fill": 1,
+ "id": 12,
+ "legend": {
+ "avg": false,
+ "current": false,
+ "max": false,
+ "min": false,
+ "show": true,
+ "total": false,
+ "values": false
+ },
+ "lines": true,
+ "linewidth": 1,
+ "links": [],
+ "nullPointMode": "null",
+ "percentage": false,
+ "pointradius": 5,
+ "points": false,
+ "renderer": "flot",
+ "seriesOverrides": [
+ {
+ "alias": "Derivative Max count",
+ "yaxis": 2
+ }
+ ],
+ "span": 3,
+ "stack": false,
+ "steppedLine": false,
+ "targets": [
+ {
+ "bucketAggs": [
+ {
+ "field": "@timestamp",
+ "id": "2",
+ "settings": {
+ "interval": "auto",
+ "min_doc_count": 0,
+ "trimEdges": 0
+ },
+ "type": "date_histogram"
+ }
+ ],
+ "dsType": "elasticsearch",
+ "hide": false,
+ "metrics": [
+ {
+ "field": "count",
+ "id": "1",
+ "meta": {},
+ "pipelineAgg": "3",
+ "settings": {},
+ "type": "max"
+ }
+ ],
+ "query": "name:textExtractor.cache.weight",
+ "refId": "A",
+ "timeField": "@timestamp"
+ }
+ ],
+ "thresholds": [],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Cache weight",
+ "tooltip": {
+ "shared": true,
+ "sort": 0,
+ "value_type": "individual"
+ },
+ "type": "graph",
+ "xaxis": {
+ "mode": "time",
+ "name": null,
+ "show": true,
+ "values": []
+ },
+ "yaxes": [
+ {
+ "format": "bytes",
+ "label": null,
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": true
+ },
+ {
+ "format": "opm",
+ "label": null,
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": true
+ }
+ ]
+ },
+ {
+ "aliasColors": {},
+ "bars": false,
+ "datasource": "${DS_JAMES_ES}",
+ "fill": 1,
+ "id": 14,
+ "legend": {
+ "avg": false,
+ "current": false,
+ "max": false,
+ "min": false,
+ "show": true,
+ "total": false,
+ "values": false
+ },
+ "lines": true,
+ "linewidth": 1,
+ "links": [],
+ "nullPointMode": "null",
+ "percentage": false,
+ "pointradius": 5,
+ "points": false,
+ "renderer": "flot",
+ "seriesOverrides": [
+ {
+ "alias": "Derivative Max count",
+ "yaxis": 2
+ }
+ ],
+ "span": 3,
+ "stack": false,
+ "steppedLine": false,
+ "targets": [
+ {
+ "alias": "hits",
+ "bucketAggs": [
+ {
+ "field": "@timestamp",
+ "id": "2",
+ "settings": {
+ "interval": "auto",
+ "min_doc_count": 0,
+ "trimEdges": 0
+ },
+ "type": "date_histogram"
+ }
+ ],
+ "dsType": "elasticsearch",
+ "hide": false,
+ "metrics": [
+ {
+ "field": "value",
+ "id": "1",
+ "meta": {},
+ "pipelineAgg": "3",
+ "settings": {},
+ "type": "max"
+ },
+ {
+ "field": "1",
+ "id": "3",
+ "meta": {},
+ "pipelineAgg": "1",
+ "settings": {},
+ "type": "derivative"
+ }
+ ],
+ "query": "name:textExtractor.cache.hit.count",
+ "refId": "A",
+ "timeField": "@timestamp"
+ },
+ {
+ "alias": "misses",
+ "bucketAggs": [
+ {
+ "field": "@timestamp",
+ "id": "2",
+ "settings": {
+ "interval": "auto",
+ "min_doc_count": 0,
+ "trimEdges": 0
+ },
+ "type": "date_histogram"
+ }
+ ],
+ "dsType": "elasticsearch",
+ "hide": false,
+ "metrics": [
+ {
+ "field": "count",
+ "id": "1",
+ "meta": {},
+ "pipelineAgg": "3",
+ "settings": {},
+ "type": "max"
+ },
+ {
+ "field": "1",
+ "id": "3",
+ "meta": {},
+ "pipelineAgg": "1",
+ "settings": {},
+ "type": "derivative"
+ }
+ ],
+ "query": "name:textExtractor.cache.miss.count",
+ "refId": "B",
+ "timeField": "@timestamp"
+ }
+ ],
+ "thresholds": [],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Cache hits / miss",
+ "tooltip": {
+ "shared": true,
+ "sort": 0,
+ "value_type": "individual"
+ },
+ "type": "graph",
+ "xaxis": {
+ "mode": "time",
+ "name": null,
+ "show": true,
+ "values": []
+ },
+ "yaxes": [
+ {
+ "format": "none",
+ "label": null,
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": true
+ },
+ {
+ "format": "opm",
+ "label": null,
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": true
+ }
+ ]
+ }
+ ],
+ "repeat": null,
+ "repeatIteration": null,
+ "repeatRowId": null,
+ "showTitle": false,
+ "title": "Dashboard Row",
+ "titleSize": "h6"
+ },
+ {
+ "collapse": false,
+ "height": 244,
+ "panels": [
+ {
+ "aliasColors": {},
+ "bars": false,
+ "datasource": "${DS_JAMES_ES}",
+ "fill": 1,
+ "id": 13,
+ "legend": {
+ "avg": false,
+ "current": false,
+ "max": false,
+ "min": false,
+ "show": true,
+ "total": false,
+ "values": false
+ },
+ "lines": true,
+ "linewidth": 1,
+ "links": [],
+ "nullPointMode": "null",
+ "percentage": false,
+ "pointradius": 5,
+ "points": false,
+ "renderer": "flot",
+ "seriesOverrides": [
+ {
+ "alias": "Derivative Max count",
+ "yaxis": 2
+ }
+ ],
+ "span": 3,
+ "stack": false,
+ "steppedLine": false,
+ "targets": [
+ {
+ "alias": "hits",
+ "bucketAggs": [
+ {
+ "field": "@timestamp",
+ "id": "2",
+ "settings": {
+ "interval": "auto",
+ "min_doc_count": 0,
+ "trimEdges": 0
+ },
+ "type": "date_histogram"
+ }
+ ],
+ "dsType": "elasticsearch",
+ "hide": false,
+ "metrics": [
+ {
+ "field": "value",
+ "id": "1",
+ "meta": {},
+ "pipelineAgg": "3",
+ "settings": {},
+ "type": "max"
+ }
+ ],
+ "query": "name:textExtractor.cache.eviction.count",
+ "refId": "A",
+ "timeField": "@timestamp"
+ }
+ ],
+ "thresholds": [],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Cache eviction count",
+ "tooltip": {
+ "shared": true,
+ "sort": 0,
+ "value_type": "individual"
+ },
+ "type": "graph",
+ "xaxis": {
+ "mode": "time",
+ "name": null,
+ "show": true,
+ "values": []
+ },
+ "yaxes": [
+ {
+ "format": "bytes",
+ "label": null,
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": true
+ },
+ {
+ "format": "opm",
+ "label": null,
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": true
+ }
+ ]
+ },
+ {
+ "aliasColors": {},
+ "bars": false,
+ "datasource": "${DS_JAMES_ES}",
+ "fill": 1,
+ "id": 15,
+ "legend": {
+ "avg": false,
+ "current": false,
+ "max": false,
+ "min": false,
+ "show": true,
+ "total": false,
+ "values": false
+ },
+ "lines": true,
+ "linewidth": 1,
+ "links": [],
+ "nullPointMode": "null",
+ "percentage": false,
+ "pointradius": 5,
+ "points": false,
+ "renderer": "flot",
+ "seriesOverrides": [
+ {
+ "alias": "Derivative Max count",
+ "yaxis": 2
+ }
+ ],
+ "span": 3,
+ "stack": false,
+ "steppedLine": false,
+ "targets": [
+ {
+ "alias": "hits",
+ "bucketAggs": [
+ {
+ "field": "@timestamp",
+ "id": "2",
+ "settings": {
+ "interval": "auto",
+ "min_doc_count": 0,
+ "trimEdges": 0
+ },
+ "type": "date_histogram"
+ }
+ ],
+ "dsType": "elasticsearch",
+ "hide": false,
+ "metrics": [
+ {
+ "field": "value",
+ "id": "1",
+ "meta": {},
+ "pipelineAgg": "3",
+ "settings": {},
+ "type": "max"
+ }
+ ],
+ "query": "name:textExtractor.cache.load.count",
+ "refId": "A",
+ "timeField": "@timestamp"
+ }
+ ],
+ "thresholds": [],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Cache load count",
+ "tooltip": {
+ "shared": true,
+ "sort": 0,
+ "value_type": "individual"
+ },
+ "type": "graph",
+ "xaxis": {
+ "mode": "time",
+ "name": null,
+ "show": true,
+ "values": []
+ },
+ "yaxes": [
+ {
+ "format": "bytes",
+ "label": null,
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": true
+ },
+ {
+ "format": "opm",
+ "label": null,
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": true
+ }
+ ]
+ },
+ {
+ "aliasColors": {},
+ "bars": false,
+ "datasource": "${DS_JAMES_ES}",
+ "fill": 1,
+ "id": 16,
+ "legend": {
+ "avg": false,
+ "current": false,
+ "max": false,
+ "min": false,
+ "show": true,
+ "total": false,
+ "values": false
+ },
+ "lines": true,
+ "linewidth": 1,
+ "links": [],
+ "nullPointMode": "null",
+ "percentage": false,
+ "pointradius": 5,
+ "points": false,
+ "renderer": "flot",
+ "seriesOverrides": [
+ {
+ "alias": "Derivative Max count",
+ "yaxis": 2
+ }
+ ],
+ "span": 3,
+ "stack": false,
+ "steppedLine": false,
+ "targets": [
+ {
+ "alias": "hits",
+ "bucketAggs": [
+ {
+ "field": "@timestamp",
+ "id": "2",
+ "settings": {
+ "interval": "auto",
+ "min_doc_count": 0,
+ "trimEdges": 0
+ },
+ "type": "date_histogram"
+ }
+ ],
+ "dsType": "elasticsearch",
+ "hide": false,
+ "metrics": [
+ {
+ "field": "value",
+ "id": "1",
+ "meta": {},
+ "pipelineAgg": "3",
+ "settings": {},
+ "type": "max"
+ }
+ ],
+ "query": "name:textExtractor.cache.load.exception.rate",
+ "refId": "A",
+ "timeField": "@timestamp"
+ }
+ ],
+ "thresholds": [],
+ "timeFrom": null,
+ "timeShift": null,
+ "title": "Cache load exception rate",
+ "tooltip": {
+ "shared": true,
+ "sort": 0,
+ "value_type": "individual"
+ },
+ "type": "graph",
+ "xaxis": {
+ "mode": "time",
+ "name": null,
+ "show": true,
+ "values": []
+ },
+ "yaxes": [
+ {
+ "format": "bytes",
+ "label": null,
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": true
+ },
+ {
+ "format": "opm",
+ "label": null,
+ "logBase": 1,
+ "max": null,
+ "min": null,
+ "show": true
+ }
+ ]
+ }
+ ],
+ "repeat": null,
+ "repeatIteration": null,
+ "repeatRowId": null,
+ "showTitle": false,
+ "title": "Dashboard Row",
+ "titleSize": "h6"
}
],
"schemaVersion": 14,
@@ -308,5 +1069,5 @@
},
"timezone": "browser",
"title": "Tika",
- "version": 7
+ "version": 22
}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[7/8] james-project git commit: JAMES-2526 Add a Guice lifecycle
health check
Posted by ad...@apache.org.
JAMES-2526 Add a Guice lifecycle health check
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/26557639
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/26557639
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/26557639
Branch: refs/heads/master
Commit: 265576395a1486ef5dec64f84851513a1286e082
Parents: 1091636
Author: Benoit Tellier <bt...@linagora.com>
Authored: Thu Aug 23 09:11:33 2018 +0000
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Mon Aug 27 14:18:07 2018 +0200
----------------------------------------------------------------------
.../apache/james/GuiceLifecycleHealthCheck.java | 49 ++++++++
.../james/modules/IsStartedProbeModule.java | 3 +
.../james/GuiceLifecycleHeathCheckTest.java | 118 +++++++++++++++++++
3 files changed, 170 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/26557639/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceLifecycleHealthCheck.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceLifecycleHealthCheck.java b/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceLifecycleHealthCheck.java
new file mode 100644
index 0000000..b7a6fe4
--- /dev/null
+++ b/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceLifecycleHealthCheck.java
@@ -0,0 +1,49 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james;
+
+import javax.inject.Inject;
+
+import org.apache.james.core.healthcheck.ComponentName;
+import org.apache.james.core.healthcheck.HealthCheck;
+import org.apache.james.core.healthcheck.Result;
+
+public class GuiceLifecycleHealthCheck implements HealthCheck {
+ private final IsStartedProbe probe;
+
+ @Inject
+ public GuiceLifecycleHealthCheck(IsStartedProbe probe) {
+ this.probe = probe;
+ }
+
+ @Override
+ public ComponentName componentName() {
+ return new ComponentName("Guice application lifecycle");
+ }
+
+ @Override
+ public Result check() {
+ if (probe.isStarted()) {
+ return Result.healthy(componentName());
+ } else {
+ return Result.unhealthy(componentName(), "James server is not started.");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/26557639/server/container/guice/guice-common/src/main/java/org/apache/james/modules/IsStartedProbeModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/IsStartedProbeModule.java b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/IsStartedProbeModule.java
index 6fd539b..fe3eef5 100644
--- a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/IsStartedProbeModule.java
+++ b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/IsStartedProbeModule.java
@@ -19,7 +19,9 @@
package org.apache.james.modules;
+import org.apache.james.GuiceLifecycleHealthCheck;
import org.apache.james.IsStartedProbe;
+import org.apache.james.core.healthcheck.HealthCheck;
import org.apache.james.utils.GuiceProbe;
import com.google.inject.AbstractModule;
@@ -37,5 +39,6 @@ public class IsStartedProbeModule extends AbstractModule {
bind(IsStartedProbe.class).toInstance(probe);
Multibinder.newSetBinder(binder(), GuiceProbe.class).addBinding().toInstance(probe);
+ Multibinder.newSetBinder(binder(), HealthCheck.class).addBinding().to(GuiceLifecycleHealthCheck.class);
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/26557639/server/container/guice/memory-guice/src/test/java/org/apache/james/GuiceLifecycleHeathCheckTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/memory-guice/src/test/java/org/apache/james/GuiceLifecycleHeathCheckTest.java b/server/container/guice/memory-guice/src/test/java/org/apache/james/GuiceLifecycleHeathCheckTest.java
new file mode 100644
index 0000000..a0ea030
--- /dev/null
+++ b/server/container/guice/memory-guice/src/test/java/org/apache/james/GuiceLifecycleHeathCheckTest.java
@@ -0,0 +1,118 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james;
+
+import static io.restassured.RestAssured.when;
+import static io.restassured.config.EncoderConfig.encoderConfig;
+import static io.restassured.config.RestAssuredConfig.newConfig;
+
+import java.nio.charset.StandardCharsets;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CountDownLatch;
+
+import org.apache.james.task.Task;
+import org.apache.james.utils.WebAdminGuiceProbe;
+import org.apache.james.webadmin.WebAdminConfiguration;
+import org.eclipse.jetty.http.HttpStatus;
+import org.junit.After;
+import org.junit.Rule;
+import org.junit.Test;
+
+import com.google.inject.multibindings.Multibinder;
+
+import io.restassured.RestAssured;
+import io.restassured.builder.RequestSpecBuilder;
+import io.restassured.http.ContentType;
+
+public class GuiceLifecycleHeathCheckTest {
+ private void configureRequestSpecification() {
+ WebAdminGuiceProbe webAdminGuiceProbe = guiceJamesServer.getProbe(WebAdminGuiceProbe.class);
+
+ RestAssured.requestSpecification = new RequestSpecBuilder()
+ .setContentType(ContentType.JSON)
+ .setAccept(ContentType.JSON)
+ .setConfig(newConfig().encoderConfig(encoderConfig().defaultContentCharset(StandardCharsets.UTF_8)))
+ .setPort(webAdminGuiceProbe.getWebAdminPort().getValue())
+ .build();
+ }
+
+ @Rule
+ public MemoryJmapTestRule memoryJmap = new MemoryJmapTestRule();
+ private GuiceJamesServer guiceJamesServer;
+
+ @After
+ public void cleanUp() {
+ if (guiceJamesServer != null) {
+ guiceJamesServer.stop();
+ }
+ }
+
+ @Test
+ public void startedJamesServerShouldBeHealthy() throws Exception {
+ guiceJamesServer = memoryJmap.jmapServer()
+ .overrideWith(binder -> binder.bind(WebAdminConfiguration.class)
+ .toInstance(WebAdminConfiguration.TEST_CONFIGURATION));
+
+
+ guiceJamesServer.start();
+ configureRequestSpecification();
+
+ when()
+ .get("/healthcheck")
+ .then()
+ .statusCode(HttpStatus.OK_200);
+ }
+
+ @Test
+ public void stoppingJamesServerShouldBeUnhealthy() throws Exception {
+ CountDownLatch latch = new CountDownLatch(1);
+ CleanupTasksPerformer.CleanupTask awaitCleanupTask = () -> {
+ try {
+ latch.await();
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ return Task.Result.COMPLETED;
+ };
+ CompletableFuture<Void> stopCompletedFuture = CompletableFuture.completedFuture(null);
+
+ try {
+ guiceJamesServer = memoryJmap.jmapServer(
+ binder -> Multibinder.newSetBinder(binder, CleanupTasksPerformer.CleanupTask.class)
+ .addBinding()
+ .toInstance(awaitCleanupTask))
+ .overrideWith(binder -> binder.bind(WebAdminConfiguration.class)
+ .toInstance(WebAdminConfiguration.TEST_CONFIGURATION));
+
+ guiceJamesServer.start();
+ configureRequestSpecification();
+
+ stopCompletedFuture = CompletableFuture.runAsync(() -> guiceJamesServer.stop());
+
+ when()
+ .get("/healthcheck")
+ .then()
+ .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500);
+ } finally {
+ latch.countDown();
+ stopCompletedFuture.join();
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[6/8] james-project git commit: JAMES-2526 Bind health check routes
in Guice
Posted by ad...@apache.org.
JAMES-2526 Bind health check routes in Guice
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/07850163
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/07850163
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/07850163
Branch: refs/heads/master
Commit: 07850163215bb85983995dd481354d355f8510ad
Parents: c9cbe2c
Author: Antoine Duprat <ad...@linagora.com>
Authored: Wed Aug 22 16:07:12 2018 +0200
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Mon Aug 27 14:18:06 2018 +0200
----------------------------------------------------------------------
.../modules/server/HealthCheckRoutesModule.java | 40 ++++++++++++++++++++
.../modules/server/WebAdminServerModule.java | 1 +
.../WebAdminServerIntegrationTest.java | 10 ++++-
3 files changed, 50 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/07850163/server/container/guice/protocols/webadmin/src/main/java/org/apache/james/modules/server/HealthCheckRoutesModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/protocols/webadmin/src/main/java/org/apache/james/modules/server/HealthCheckRoutesModule.java b/server/container/guice/protocols/webadmin/src/main/java/org/apache/james/modules/server/HealthCheckRoutesModule.java
new file mode 100644
index 0000000..8ebd5b1
--- /dev/null
+++ b/server/container/guice/protocols/webadmin/src/main/java/org/apache/james/modules/server/HealthCheckRoutesModule.java
@@ -0,0 +1,40 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.modules.server;
+
+import org.apache.james.core.healthcheck.HealthCheck;
+import org.apache.james.webadmin.Routes;
+import org.apache.james.webadmin.routes.HealthCheckRoutes;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Scopes;
+import com.google.inject.multibindings.Multibinder;
+
+public class HealthCheckRoutesModule extends AbstractModule {
+ @Override
+ protected void configure() {
+ bind(HealthCheckRoutes.class).in(Scopes.SINGLETON);
+
+ Multibinder<Routes> routesMultibinder = Multibinder.newSetBinder(binder(), Routes.class);
+ routesMultibinder.addBinding().to(HealthCheckRoutes.class);
+
+ Multibinder.newSetBinder(binder(), HealthCheck.class);
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/07850163/server/container/guice/protocols/webadmin/src/main/java/org/apache/james/modules/server/WebAdminServerModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/protocols/webadmin/src/main/java/org/apache/james/modules/server/WebAdminServerModule.java b/server/container/guice/protocols/webadmin/src/main/java/org/apache/james/modules/server/WebAdminServerModule.java
index d0bb7f6..ab0c93b 100644
--- a/server/container/guice/protocols/webadmin/src/main/java/org/apache/james/modules/server/WebAdminServerModule.java
+++ b/server/container/guice/protocols/webadmin/src/main/java/org/apache/james/modules/server/WebAdminServerModule.java
@@ -70,6 +70,7 @@ public class WebAdminServerModule extends AbstractModule {
@Override
protected void configure() {
install(new TaskRoutesModule());
+ install(new HealthCheckRoutesModule());
bind(JsonTransformer.class).in(Scopes.SINGLETON);
bind(WebAdminServer.class).in(Scopes.SINGLETON);
http://git-wip-us.apache.org/repos/asf/james-project/blob/07850163/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/WebAdminServerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/WebAdminServerIntegrationTest.java b/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/WebAdminServerIntegrationTest.java
index 07c63d0..6374bdf 100644
--- a/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/WebAdminServerIntegrationTest.java
+++ b/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/WebAdminServerIntegrationTest.java
@@ -41,6 +41,7 @@ import org.apache.james.utils.DataProbeImpl;
import org.apache.james.utils.WebAdminGuiceProbe;
import org.apache.james.webadmin.WebAdminUtils;
import org.apache.james.webadmin.routes.DomainsRoutes;
+import org.apache.james.webadmin.routes.HealthCheckRoutes;
import org.apache.james.webadmin.routes.MailQueueRoutes;
import org.apache.james.webadmin.routes.MailRepositoriesRoutes;
import org.apache.james.webadmin.routes.UserMailboxesRoutes;
@@ -328,4 +329,11 @@ public class WebAdminServerIntegrationTest {
.body(containsString("\"tags\":[\"Address Groups\"]"));
}
-}
+ @Test
+ public void validateHealthChecksShouldReturnOk() throws Exception {
+ when()
+ .get(HealthCheckRoutes.HEALTHCHECK)
+ .then()
+ .statusCode(HttpStatus.OK_200);
+ }
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[4/8] james-project git commit: JAMES-2526 Define the health check API
Posted by ad...@apache.org.
JAMES-2526 Define the health check API
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/f30ffeb7
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/f30ffeb7
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/f30ffeb7
Branch: refs/heads/master
Commit: f30ffeb729960319f03838fbc941736c698f1d56
Parents: 70f5318
Author: Antoine Duprat <ad...@linagora.com>
Authored: Wed Aug 22 14:48:10 2018 +0200
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Mon Aug 27 14:18:06 2018 +0200
----------------------------------------------------------------------
.../james/core/healthcheck/ComponentName.java | 32 ++++
.../james/core/healthcheck/HealthCheck.java | 25 +++
.../apache/james/core/healthcheck/Result.java | 78 ++++++++
.../james/core/healthcheck/ResultStatus.java | 23 +++
.../james/core/healthcheck/ResultTest.java | 183 +++++++++++++++++++
5 files changed, 341 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/f30ffeb7/core/src/main/java/org/apache/james/core/healthcheck/ComponentName.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/james/core/healthcheck/ComponentName.java b/core/src/main/java/org/apache/james/core/healthcheck/ComponentName.java
new file mode 100644
index 0000000..ecb248a
--- /dev/null
+++ b/core/src/main/java/org/apache/james/core/healthcheck/ComponentName.java
@@ -0,0 +1,32 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.core.healthcheck;
+
+public class ComponentName {
+ private final String name;
+
+ public ComponentName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f30ffeb7/core/src/main/java/org/apache/james/core/healthcheck/HealthCheck.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/james/core/healthcheck/HealthCheck.java b/core/src/main/java/org/apache/james/core/healthcheck/HealthCheck.java
new file mode 100644
index 0000000..f7659b0
--- /dev/null
+++ b/core/src/main/java/org/apache/james/core/healthcheck/HealthCheck.java
@@ -0,0 +1,25 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+package org.apache.james.core.healthcheck;
+
+public interface HealthCheck {
+ ComponentName componentName();
+
+ Result check();
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f30ffeb7/core/src/main/java/org/apache/james/core/healthcheck/Result.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/james/core/healthcheck/Result.java b/core/src/main/java/org/apache/james/core/healthcheck/Result.java
new file mode 100644
index 0000000..fe9657a
--- /dev/null
+++ b/core/src/main/java/org/apache/james/core/healthcheck/Result.java
@@ -0,0 +1,78 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+package org.apache.james.core.healthcheck;
+
+import java.util.Optional;
+
+public class Result {
+
+ public static Result healthy(ComponentName componentName) {
+ return new Result(componentName, ResultStatus.HEALTHY, Optional.empty());
+ }
+
+ public static Result unhealthy(ComponentName componentName, String cause) {
+ return new Result(componentName, ResultStatus.UNHEALTHY, Optional.of(cause));
+ }
+
+ public static Result unhealthy(ComponentName componentName) {
+ return new Result(componentName, ResultStatus.UNHEALTHY, Optional.empty());
+ }
+
+ public static Result degraded(ComponentName componentName, String cause) {
+ return new Result(componentName, ResultStatus.DEGRADED, Optional.of(cause));
+ }
+
+ public static Result degraded(ComponentName componentName) {
+ return new Result(componentName, ResultStatus.DEGRADED, Optional.empty());
+ }
+
+ private final ComponentName componentName;
+ private final ResultStatus status;
+ private final Optional<String> cause;
+
+ private Result(ComponentName componentName, ResultStatus status, Optional<String> cause) {
+ this.componentName = componentName;
+ this.status = status;
+ this.cause = cause;
+ }
+
+ public ComponentName getComponentName() {
+ return componentName;
+ }
+
+ public ResultStatus getStatus() {
+ return status;
+ }
+
+ public boolean isHealthy() {
+ return status == ResultStatus.HEALTHY;
+ }
+
+ public boolean isDegraded() {
+ return status == ResultStatus.DEGRADED;
+ }
+
+ public boolean isUnHealthy() {
+ return status == ResultStatus.UNHEALTHY;
+ }
+
+ public Optional<String> getCause() {
+ return cause;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/f30ffeb7/core/src/main/java/org/apache/james/core/healthcheck/ResultStatus.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/james/core/healthcheck/ResultStatus.java b/core/src/main/java/org/apache/james/core/healthcheck/ResultStatus.java
new file mode 100644
index 0000000..89109e9
--- /dev/null
+++ b/core/src/main/java/org/apache/james/core/healthcheck/ResultStatus.java
@@ -0,0 +1,23 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+package org.apache.james.core.healthcheck;
+
+public enum ResultStatus {
+ HEALTHY, DEGRADED, UNHEALTHY;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/f30ffeb7/core/src/test/java/org/apache/james/core/healthcheck/ResultTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/james/core/healthcheck/ResultTest.java b/core/src/test/java/org/apache/james/core/healthcheck/ResultTest.java
new file mode 100644
index 0000000..ece974a
--- /dev/null
+++ b/core/src/test/java/org/apache/james/core/healthcheck/ResultTest.java
@@ -0,0 +1,183 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+package org.apache.james.core.healthcheck;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.junit.jupiter.api.Test;
+
+public class ResultTest {
+
+ private static final ComponentName COMPONENT_NAME = new ComponentName("component");
+
+ @Test
+ public void componentNameShouldBeKeptWhenHealthy() {
+ Result result = Result.healthy(COMPONENT_NAME);
+
+ assertThat(result.getComponentName()).isEqualTo(COMPONENT_NAME);
+ }
+
+ @Test
+ public void componentNameShouldBeKeptWhenUnhealthy() {
+ Result result = Result.unhealthy(COMPONENT_NAME);
+
+ assertThat(result.getComponentName()).isEqualTo(COMPONENT_NAME);
+ }
+
+ @Test
+ public void componentNameShouldBeKeptWhenDegraded() {
+ Result result = Result.degraded(COMPONENT_NAME);
+
+ assertThat(result.getComponentName()).isEqualTo(COMPONENT_NAME);
+ }
+
+ @Test
+ public void statusShouldBeHealthyWhenHealthy() {
+ Result result = Result.healthy(COMPONENT_NAME);
+
+ assertThat(result.getStatus()).isEqualTo(ResultStatus.HEALTHY);
+ }
+
+ @Test
+ public void causeShouldBeEmptyWhenHealthy() {
+ Result result = Result.healthy(COMPONENT_NAME);
+
+ assertThat(result.getCause()).isEmpty();
+ }
+
+ @Test
+ public void isHealthyShouldBeTrueWhenHealthy() {
+ Result result = Result.healthy(COMPONENT_NAME);
+
+ assertThat(result.isHealthy()).isTrue();
+ }
+
+ @Test
+ public void isDegradedShouldBeFalseWhenHealthy() {
+ Result result = Result.healthy(COMPONENT_NAME);
+
+ assertThat(result.isDegraded()).isFalse();
+ }
+
+ @Test
+ public void isUnhealthyShouldBeFalseWhenHealthy() {
+ Result result = Result.healthy(COMPONENT_NAME);
+
+ assertThat(result.isUnHealthy()).isFalse();
+ }
+
+ @Test
+ public void statusShouldBeDegradedWhenDegraded() {
+ Result result = Result.degraded(COMPONENT_NAME, "cause");
+
+ assertThat(result.getStatus()).isEqualTo(ResultStatus.DEGRADED);
+ }
+
+ @Test
+ public void causeMayBeEmptyWhenDegraded() {
+ Result result = Result.degraded(COMPONENT_NAME);
+
+ assertThat(result.getCause()).isEmpty();
+ }
+
+ @Test
+ public void degradedShouldThrowWhenNullCause() {
+ assertThatThrownBy(() -> Result.degraded(COMPONENT_NAME, null))
+ .isInstanceOf(NullPointerException.class);
+ }
+
+ @Test
+ public void causeShouldBeKeptWhenNotDegraded() {
+ String cause = "cause";
+ Result result = Result.degraded(COMPONENT_NAME, cause);
+
+ assertThat(result.getCause()).contains(cause);
+ }
+
+ @Test
+ public void isHealthyShouldBeFalseWhenDegraded() {
+ Result result = Result.degraded(COMPONENT_NAME);
+
+ assertThat(result.isHealthy()).isFalse();
+ }
+
+ @Test
+ public void isDegradedShouldBeFalseWhenDegraded() {
+ Result result = Result.degraded(COMPONENT_NAME);
+
+ assertThat(result.isDegraded()).isTrue();
+ }
+
+ @Test
+ public void isUnhealthyShouldBeTrueWhenDegraded() {
+ Result result = Result.degraded(COMPONENT_NAME);
+
+ assertThat(result.isUnHealthy()).isFalse();
+ }
+
+ @Test
+ public void statusShouldBeUnhealthyWhenUnhealthy() {
+ Result result = Result.unhealthy(COMPONENT_NAME, "cause");
+
+ assertThat(result.getStatus()).isEqualTo(ResultStatus.UNHEALTHY);
+ }
+
+ @Test
+ public void causeMayBeEmptyWhenUnhealthy() {
+ Result result = Result.unhealthy(COMPONENT_NAME);
+
+ assertThat(result.getCause()).isEmpty();
+ }
+
+ @Test
+ public void causeShouldBeKeptWhenNotEmpty() {
+ String cause = "cause";
+ Result result = Result.unhealthy(COMPONENT_NAME, cause);
+
+ assertThat(result.getCause()).contains(cause);
+ }
+
+ @Test
+ public void isHealthyShouldBeFalseWhenUnhealthy() {
+ Result result = Result.unhealthy(COMPONENT_NAME);
+
+ assertThat(result.isHealthy()).isFalse();
+ }
+
+ @Test
+ public void isDegradedShouldBeFalseWhenUnhealthy() {
+ Result result = Result.unhealthy(COMPONENT_NAME);
+
+ assertThat(result.isDegraded()).isFalse();
+ }
+
+ @Test
+ public void isUnhealthyShouldBeTrueWhenUnhealthy() {
+ Result result = Result.unhealthy(COMPONENT_NAME);
+
+ assertThat(result.isUnHealthy()).isTrue();
+ }
+
+ @Test
+ public void unhealthyShouldThrowWhenNullCause() {
+ assertThatThrownBy(() -> Result.unhealthy(COMPONENT_NAME, null))
+ .isInstanceOf(NullPointerException.class);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[3/8] james-project git commit: JAMES-2520 Use a probe to wrap
started server state
Posted by ad...@apache.org.
JAMES-2520 Use a probe to wrap started server state
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/10916363
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/10916363
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/10916363
Branch: refs/heads/master
Commit: 1091636363280d7f881cb3961982f92e8b60d511
Parents: 0785016
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Aug 13 16:21:32 2018 +0700
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Mon Aug 27 14:18:06 2018 +0200
----------------------------------------------------------------------
.../smtp/host/CassandraJamesSmtpHostSystem.java | 2 +-
.../apache/james/CassandraJamesServerMain.java | 7 +++-
.../org/apache/james/CassandraJmapTestRule.java | 2 +-
.../james/JamesCapabilitiesServerTest.java | 2 +-
.../james/CassandraLdapJamesServerMain.java | 7 +++-
.../apache/james/CassandraLdapJmapTestRule.java | 2 +-
.../java/org/apache/james/GuiceJamesServer.java | 31 ++++++++------
.../java/org/apache/james/IsStartedProbe.java | 43 ++++++++++++++++++++
.../james/modules/IsStartedProbeModule.java | 41 +++++++++++++++++++
.../org/apache/james/JPAJamesServerMain.java | 7 +++-
.../org/apache/james/JPAJamesServerTest.java | 2 +-
.../JPAJamesServerWithSqlValidationTest.java | 2 +-
.../james/JamesCapabilitiesServerTest.java | 2 +-
.../org/apache/james/JPAJamesServerMain.java | 7 +++-
.../org/apache/james/JPAJamesServerTest.java | 2 +-
.../org/apache/james/JPAJamesServerTest.java | 2 +-
.../org/apache/james/MemoryJamesServerMain.java | 7 +++-
.../org/apache/james/MemoryJmapTestRule.java | 2 +-
.../james/mailets/TemporaryJamesServer.java | 2 +-
.../jmap/cassandra/CassandraJmapExtension.java | 2 +-
.../cassandra/cucumber/CassandraStepdefs.java | 2 +-
.../james/jmap/memory/MemoryJmapExtension.java | 2 +-
.../jmap/memory/cucumber/MemoryStepdefs.java | 2 +-
23 files changed, 143 insertions(+), 37 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/10916363/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/host/CassandraJamesSmtpHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/host/CassandraJamesSmtpHostSystem.java b/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/host/CassandraJamesSmtpHostSystem.java
index c640aaa..11c01fe 100644
--- a/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/host/CassandraJamesSmtpHostSystem.java
+++ b/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/host/CassandraJamesSmtpHostSystem.java
@@ -113,7 +113,7 @@ public class CassandraJamesSmtpHostSystem extends ExternalSessionFactory impleme
.configurationFromClasspath()
.build();
- return new GuiceJamesServer(configuration)
+ return GuiceJamesServer.forConfiguration(configuration)
.combineWith(
CassandraJamesServerMain.CASSANDRA_SERVER_CORE_MODULE,
SMTP_PROTOCOL_MODULE,
http://git-wip-us.apache.org/repos/asf/james-project/blob/10916363/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java
index 240cf8a..4a97ab3 100644
--- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java
+++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java
@@ -115,8 +115,11 @@ public class CassandraJamesServerMain {
PLUGINS);
public static void main(String[] args) throws Exception {
- Configuration configuration = Configuration.builder().useWorkingDirectoryEnvProperty().build();
- GuiceJamesServer server = new GuiceJamesServer(configuration)
+ Configuration configuration = Configuration.builder()
+ .useWorkingDirectoryEnvProperty()
+ .build();
+
+ GuiceJamesServer server = GuiceJamesServer.forConfiguration(configuration)
.combineWith(ALL_BUT_JMX_CASSANDRA_MODULE, new JMXServerModule());
server.start();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/10916363/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJmapTestRule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJmapTestRule.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJmapTestRule.java
index 13c49e3..962f6a6 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJmapTestRule.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJmapTestRule.java
@@ -61,7 +61,7 @@ public class CassandraJmapTestRule implements TestRule {
.configurationFromClasspath()
.build();
- return new GuiceJamesServer(configuration)
+ return GuiceJamesServer.forConfiguration(configuration)
.combineWith(ALL_BUT_JMX_CASSANDRA_MODULE)
.overrideWith(binder -> binder.bind(TextExtractor.class).to(PDFTextExtractor.class))
.overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES))
http://git-wip-us.apache.org/repos/asf/james-project/blob/10916363/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
index c55e634..5e60808 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
@@ -67,7 +67,7 @@ public class JamesCapabilitiesServerTest {
.configurationFromClasspath()
.build();
- return new GuiceJamesServer(configuration)
+ return GuiceJamesServer.forConfiguration(configuration)
.combineWith(ALL_BUT_JMX_CASSANDRA_MODULE)
.overrideWith((binder) -> binder.bind(PersistenceAdapter.class).to(MemoryPersistenceAdapter.class))
.overrideWith(new TestElasticSearchModule(embeddedElasticSearch),
http://git-wip-us.apache.org/repos/asf/james-project/blob/10916363/server/container/guice/cassandra-ldap-guice/src/main/java/org/apache/james/CassandraLdapJamesServerMain.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-ldap-guice/src/main/java/org/apache/james/CassandraLdapJamesServerMain.java b/server/container/guice/cassandra-ldap-guice/src/main/java/org/apache/james/CassandraLdapJamesServerMain.java
index 488ac6f..25c9f64 100644
--- a/server/container/guice/cassandra-ldap-guice/src/main/java/org/apache/james/CassandraLdapJamesServerMain.java
+++ b/server/container/guice/cassandra-ldap-guice/src/main/java/org/apache/james/CassandraLdapJamesServerMain.java
@@ -34,8 +34,11 @@ public class CassandraLdapJamesServerMain {
.with(new LdapUsersRepositoryModule());
public static void main(String[] args) throws Exception {
- Configuration configuration = Configuration.builder().useWorkingDirectoryEnvProperty().build();
- GuiceJamesServer server = new GuiceJamesServer(configuration)
+ Configuration configuration = Configuration.builder()
+ .useWorkingDirectoryEnvProperty()
+ .build();
+
+ GuiceJamesServer server = GuiceJamesServer.forConfiguration(configuration)
.combineWith(cassandraLdapServerModule, new JMXServerModule());
server.start();
http://git-wip-us.apache.org/repos/asf/james-project/blob/10916363/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJmapTestRule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJmapTestRule.java b/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJmapTestRule.java
index b4b8fd0..58da40a 100644
--- a/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJmapTestRule.java
+++ b/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJmapTestRule.java
@@ -58,7 +58,7 @@ public class CassandraLdapJmapTestRule implements TestRule {
.configurationFromClasspath()
.build();
- return new GuiceJamesServer(configuration)
+ return GuiceJamesServer.forConfiguration(configuration)
.combineWith(CassandraLdapJamesServerMain.cassandraLdapServerModule)
.overrideWith(new TestJMAPServerModule(LIMIT_TO_3_MESSAGES))
.overrideWith(guiceModuleTestRule.getModule())
http://git-wip-us.apache.org/repos/asf/james-project/blob/10916363/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceJamesServer.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceJamesServer.java b/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceJamesServer.java
index b43996c..fa37195 100644
--- a/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceJamesServer.java
+++ b/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceJamesServer.java
@@ -25,6 +25,7 @@ import java.util.Optional;
import javax.annotation.PreDestroy;
import org.apache.james.modules.CommonServicesModule;
+import org.apache.james.modules.IsStartedProbeModule;
import org.apache.james.modules.MailetProcessingModule;
import org.apache.james.onami.lifecycle.Stager;
import org.apache.james.server.core.configuration.Configuration;
@@ -43,31 +44,37 @@ import com.google.inject.util.Modules;
public class GuiceJamesServer {
protected final Module module;
+ private final IsStartedProbe isStartedProbe;
private Stager<PreDestroy> preDestroy;
private GuiceProbeProvider guiceProbeProvider;
private CleanupTasksPerformer cleanupTasksPerformer;
- private boolean isStarted = false;
- public GuiceJamesServer(Configuration configuration) {
- this(Modules.combine(
- new CommonServicesModule(configuration),
- new MailetProcessingModule()));
+ public static GuiceJamesServer forConfiguration(Configuration configuration) {
+ IsStartedProbe isStartedProbe = new IsStartedProbe();
+
+ return new GuiceJamesServer(
+ isStartedProbe,
+ Modules.combine(
+ new IsStartedProbeModule(isStartedProbe),
+ new CommonServicesModule(configuration),
+ new MailetProcessingModule()));
}
- protected GuiceJamesServer(Module module) {
+ protected GuiceJamesServer(IsStartedProbe isStartedProbe, Module module) {
+ this.isStartedProbe = isStartedProbe;
this.module = module;
}
public GuiceJamesServer combineWith(Module... modules) {
- return new GuiceJamesServer(Modules.combine(Iterables.concat(Arrays.asList(module), Arrays.asList(modules))));
+ return new GuiceJamesServer(isStartedProbe, Modules.combine(Iterables.concat(Arrays.asList(module), Arrays.asList(modules))));
}
public GuiceJamesServer overrideWith(Module... overrides) {
- return new GuiceJamesServer(Modules.override(module).with(overrides));
+ return new GuiceJamesServer(isStartedProbe, Modules.override(module).with(overrides));
}
public GuiceJamesServer overrideWith(List<Module> overrides) {
- return new GuiceJamesServer(Modules.override(module).with(overrides));
+ return new GuiceJamesServer(isStartedProbe, Modules.override(module).with(overrides));
}
public void start() throws Exception {
@@ -76,19 +83,19 @@ public class GuiceJamesServer {
injector.getInstance(ConfigurationsPerformer.class).initModules();
guiceProbeProvider = injector.getInstance(GuiceProbeProvider.class);
cleanupTasksPerformer = injector.getInstance(CleanupTasksPerformer.class);
- isStarted = true;
+ isStartedProbe.notifyStarted();
}
public void stop() {
+ isStartedProbe.notifyStoped();
Optional.ofNullable(cleanupTasksPerformer).ifPresent(CleanupTasksPerformer::clean);
if (preDestroy != null) {
preDestroy.stage();
- isStarted = false;
}
}
public boolean isStarted() {
- return isStarted;
+ return isStartedProbe.isStarted();
}
public <T extends GuiceProbe> T getProbe(Class<T> probe) {
http://git-wip-us.apache.org/repos/asf/james-project/blob/10916363/server/container/guice/guice-common/src/main/java/org/apache/james/IsStartedProbe.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/IsStartedProbe.java b/server/container/guice/guice-common/src/main/java/org/apache/james/IsStartedProbe.java
new file mode 100644
index 0000000..5cc4194
--- /dev/null
+++ b/server/container/guice/guice-common/src/main/java/org/apache/james/IsStartedProbe.java
@@ -0,0 +1,43 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james;
+
+import org.apache.james.utils.GuiceProbe;
+
+public class IsStartedProbe implements GuiceProbe {
+
+ private boolean isStarted;
+
+ public IsStartedProbe() {
+ isStarted = false;
+ }
+
+ public void notifyStarted() {
+ isStarted = true;
+ }
+
+ public void notifyStoped() {
+ isStarted = false;
+ }
+
+ public boolean isStarted() {
+ return isStarted;
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/10916363/server/container/guice/guice-common/src/main/java/org/apache/james/modules/IsStartedProbeModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/IsStartedProbeModule.java b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/IsStartedProbeModule.java
new file mode 100644
index 0000000..6fd539b
--- /dev/null
+++ b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/IsStartedProbeModule.java
@@ -0,0 +1,41 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.modules;
+
+import org.apache.james.IsStartedProbe;
+import org.apache.james.utils.GuiceProbe;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.multibindings.Multibinder;
+
+public class IsStartedProbeModule extends AbstractModule {
+ private final IsStartedProbe probe;
+
+ public IsStartedProbeModule(IsStartedProbe probe) {
+ this.probe = probe;
+ }
+
+ @Override
+ protected void configure() {
+ bind(IsStartedProbe.class).toInstance(probe);
+
+ Multibinder.newSetBinder(binder(), GuiceProbe.class).addBinding().toInstance(probe);
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/10916363/server/container/guice/jpa-guice/src/main/java/org/apache/james/JPAJamesServerMain.java
----------------------------------------------------------------------
diff --git a/server/container/guice/jpa-guice/src/main/java/org/apache/james/JPAJamesServerMain.java b/server/container/guice/jpa-guice/src/main/java/org/apache/james/JPAJamesServerMain.java
index bd5f5cb..76580f5 100644
--- a/server/container/guice/jpa-guice/src/main/java/org/apache/james/JPAJamesServerMain.java
+++ b/server/container/guice/jpa-guice/src/main/java/org/apache/james/JPAJamesServerMain.java
@@ -84,8 +84,11 @@ public class JPAJamesServerMain {
new SpamAssassinListenerModule());
public static void main(String[] args) throws Exception {
- Configuration configuration = Configuration.builder().useWorkingDirectoryEnvProperty().build();
- GuiceJamesServer server = new GuiceJamesServer(configuration)
+ Configuration configuration = Configuration.builder()
+ .useWorkingDirectoryEnvProperty()
+ .build();
+
+ GuiceJamesServer server = GuiceJamesServer.forConfiguration(configuration)
.combineWith(JPA_SERVER_MODULE, PROTOCOLS,
new JMXServerModule(),
new LuceneSearchMailboxModule());
http://git-wip-us.apache.org/repos/asf/james-project/blob/10916363/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerTest.java b/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerTest.java
index 220bfe1..b4acca6 100644
--- a/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerTest.java
+++ b/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerTest.java
@@ -66,7 +66,7 @@ public class JPAJamesServerTest extends AbstractJamesServerTest {
.configurationFromClasspath()
.build();
- return new GuiceJamesServer(configuration)
+ return GuiceJamesServer.forConfiguration(configuration)
.combineWith(JPAJamesServerMain.JPA_SERVER_MODULE, JPAJamesServerMain.PROTOCOLS)
.overrideWith(new TestJPAConfigurationModule(), DOMAIN_LIST_CONFIGURATION_MODULE);
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/10916363/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerWithSqlValidationTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerWithSqlValidationTest.java b/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerWithSqlValidationTest.java
index 7a86bbc..7739338 100644
--- a/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerWithSqlValidationTest.java
+++ b/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerWithSqlValidationTest.java
@@ -32,7 +32,7 @@ public class JPAJamesServerWithSqlValidationTest extends JPAJamesServerTest {
.configurationFromClasspath()
.build();
- return new GuiceJamesServer(configuration)
+ return GuiceJamesServer.forConfiguration(configuration)
.combineWith(JPAJamesServerMain.JPA_SERVER_MODULE, JPAJamesServerMain.PROTOCOLS)
.overrideWith(new TestJPAConfigurationModuleWithSqlValidation(), DOMAIN_LIST_CONFIGURATION_MODULE);
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/10916363/server/container/guice/jpa-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/jpa-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java b/server/container/guice/jpa-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
index b513fe8..12db521 100644
--- a/server/container/guice/jpa-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
+++ b/server/container/guice/jpa-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
@@ -54,7 +54,7 @@ public class JamesCapabilitiesServerTest {
.configurationFromClasspath()
.build();
- return new GuiceJamesServer(configuration)
+ return GuiceJamesServer.forConfiguration(configuration)
.combineWith(JPAJamesServerMain.JPA_SERVER_MODULE)
.overrideWith(
new TestJPAConfigurationModule(),
http://git-wip-us.apache.org/repos/asf/james-project/blob/10916363/server/container/guice/jpa-smtp-common/src/main/java/org/apache/james/JPAJamesServerMain.java
----------------------------------------------------------------------
diff --git a/server/container/guice/jpa-smtp-common/src/main/java/org/apache/james/JPAJamesServerMain.java b/server/container/guice/jpa-smtp-common/src/main/java/org/apache/james/JPAJamesServerMain.java
index 7defa50..af19662 100644
--- a/server/container/guice/jpa-smtp-common/src/main/java/org/apache/james/JPAJamesServerMain.java
+++ b/server/container/guice/jpa-smtp-common/src/main/java/org/apache/james/JPAJamesServerMain.java
@@ -57,8 +57,11 @@ public class JPAJamesServerMain {
new ElasticSearchMetricReporterModule());
public static void main(String[] args) throws Exception {
- Configuration configuration = Configuration.builder().useWorkingDirectoryEnvProperty().build();
- GuiceJamesServer server = new GuiceJamesServer(configuration)
+ Configuration configuration = Configuration.builder()
+ .useWorkingDirectoryEnvProperty()
+ .build();
+
+ GuiceJamesServer server = GuiceJamesServer.forConfiguration(configuration)
.combineWith(JPA_SERVER_MODULE, PROTOCOLS);
server.start();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/10916363/server/container/guice/jpa-smtp-mariadb/src/test/java/org/apache/james/JPAJamesServerTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/jpa-smtp-mariadb/src/test/java/org/apache/james/JPAJamesServerTest.java b/server/container/guice/jpa-smtp-mariadb/src/test/java/org/apache/james/JPAJamesServerTest.java
index bf781ce..d8f7fde 100644
--- a/server/container/guice/jpa-smtp-mariadb/src/test/java/org/apache/james/JPAJamesServerTest.java
+++ b/server/container/guice/jpa-smtp-mariadb/src/test/java/org/apache/james/JPAJamesServerTest.java
@@ -73,7 +73,7 @@ public class JPAJamesServerTest {
.configurationFromClasspath()
.build();
- return new GuiceJamesServer(configuration)
+ return GuiceJamesServer.forConfiguration(configuration)
.combineWith(JPAJamesServerMain.JPA_SERVER_MODULE, JPAJamesServerMain.PROTOCOLS)
.overrideWith(
new TestJPAConfigurationModule(mariaDBUrl),
http://git-wip-us.apache.org/repos/asf/james-project/blob/10916363/server/container/guice/jpa-smtp/src/test/java/org/apache/james/JPAJamesServerTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/jpa-smtp/src/test/java/org/apache/james/JPAJamesServerTest.java b/server/container/guice/jpa-smtp/src/test/java/org/apache/james/JPAJamesServerTest.java
index 87962dd..7e192fe 100644
--- a/server/container/guice/jpa-smtp/src/test/java/org/apache/james/JPAJamesServerTest.java
+++ b/server/container/guice/jpa-smtp/src/test/java/org/apache/james/JPAJamesServerTest.java
@@ -62,7 +62,7 @@ public class JPAJamesServerTest {
.configurationFromClasspath()
.build();
- return new GuiceJamesServer(configuration)
+ return GuiceJamesServer.forConfiguration(configuration)
.combineWith(JPAJamesServerMain.JPA_SERVER_MODULE, JPAJamesServerMain.PROTOCOLS)
.overrideWith(
new TestJPAConfigurationModule(),
http://git-wip-us.apache.org/repos/asf/james-project/blob/10916363/server/container/guice/memory-guice/src/main/java/org/apache/james/MemoryJamesServerMain.java
----------------------------------------------------------------------
diff --git a/server/container/guice/memory-guice/src/main/java/org/apache/james/MemoryJamesServerMain.java b/server/container/guice/memory-guice/src/main/java/org/apache/james/MemoryJamesServerMain.java
index 7c5b961..18a3f2f 100644
--- a/server/container/guice/memory-guice/src/main/java/org/apache/james/MemoryJamesServerMain.java
+++ b/server/container/guice/memory-guice/src/main/java/org/apache/james/MemoryJamesServerMain.java
@@ -102,8 +102,11 @@ public class MemoryJamesServerMain {
WEBADMIN);
public static void main(String[] args) throws Exception {
- Configuration configuration = Configuration.builder().useWorkingDirectoryEnvProperty().build();
- new GuiceJamesServer(configuration)
+ Configuration configuration = Configuration.builder()
+ .useWorkingDirectoryEnvProperty()
+ .build();
+
+ GuiceJamesServer.forConfiguration(configuration)
.combineWith(IN_MEMORY_SERVER_AGGREGATE_MODULE, new JMXServerModule())
.start();
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/10916363/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJmapTestRule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJmapTestRule.java b/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJmapTestRule.java
index b1ac91e..d3d4588 100644
--- a/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJmapTestRule.java
+++ b/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJmapTestRule.java
@@ -47,7 +47,7 @@ public class MemoryJmapTestRule implements TestRule {
.workingDirectory(temporaryFolder.newFolder())
.configurationFromClasspath()
.build();
- return new GuiceJamesServer(configuration)
+ return GuiceJamesServer.forConfiguration(configuration)
.combineWith(MemoryJamesServerMain.IN_MEMORY_SERVER_AGGREGATE_MODULE)
.overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES))
.overrideWith(binder -> binder.bind(PersistenceAdapter.class).to(MemoryPersistenceAdapter.class))
http://git-wip-us.apache.org/repos/asf/james-project/blob/10916363/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/TemporaryJamesServer.java
----------------------------------------------------------------------
diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/TemporaryJamesServer.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/TemporaryJamesServer.java
index 3337ef8..a1a7905 100644
--- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/TemporaryJamesServer.java
+++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/TemporaryJamesServer.java
@@ -145,7 +145,7 @@ public class TemporaryJamesServer {
Configuration configuration = Configuration.builder().workingDirectory(workingDir).build();
copyResources(Paths.get(workingDir, "conf"));
- jamesServer = new GuiceJamesServer(configuration)
+ jamesServer = GuiceJamesServer.forConfiguration(configuration)
.combineWith(serverBaseModule)
.overrideWith((binder) -> binder.bind(PersistenceAdapter.class).to(MemoryPersistenceAdapter.class))
.overrideWith(additionalModules)
http://git-wip-us.apache.org/repos/asf/james-project/blob/10916363/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraJmapExtension.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraJmapExtension.java b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraJmapExtension.java
index 4c20a0f..e6095b2 100644
--- a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraJmapExtension.java
+++ b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraJmapExtension.java
@@ -69,7 +69,7 @@ public class CassandraJmapExtension implements BeforeAllCallback, AfterAllCallba
.configurationFromClasspath()
.build();
return new JamesWithSpamAssassin(
- new GuiceJamesServer(configuration)
+ GuiceJamesServer.forConfiguration(configuration)
.combineWith(ALL_BUT_JMX_CASSANDRA_MODULE)
.overrideWith(binder -> binder.bind(TextExtractor.class).to(PDFTextExtractor.class))
.overrideWith(new TestJMAPServerModule(LIMIT_TO_20_MESSAGES))
http://git-wip-us.apache.org/repos/asf/james-project/blob/10916363/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java
index d67daa7..633c1e3 100644
--- a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java
+++ b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java
@@ -75,7 +75,7 @@ public class CassandraStepdefs {
.configurationFromClasspath()
.build();
- mainStepdefs.jmapServer = new GuiceJamesServer(configuration)
+ mainStepdefs.jmapServer = GuiceJamesServer.forConfiguration(configuration)
.combineWith(ALL_BUT_JMX_CASSANDRA_MODULE)
.overrideWith(new TestJMAPServerModule(10))
.overrideWith(new TestESMetricReporterModule())
http://git-wip-us.apache.org/repos/asf/james-project/blob/10916363/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemoryJmapExtension.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemoryJmapExtension.java b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemoryJmapExtension.java
index 7ff67b6..907c0bc 100644
--- a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemoryJmapExtension.java
+++ b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemoryJmapExtension.java
@@ -63,7 +63,7 @@ public class MemoryJmapExtension implements BeforeEachCallback, AfterEachCallbac
.build();
return new JamesWithSpamAssassin(
- new GuiceJamesServer(configuration)
+ GuiceJamesServer.forConfiguration(configuration)
.combineWith(MemoryJamesServerMain.IN_MEMORY_SERVER_AGGREGATE_MODULE)
.overrideWith(new TestJMAPServerModule(LIMIT_TO_20_MESSAGES))
.overrideWith(binder -> binder.bind(PersistenceAdapter.class).to(MemoryPersistenceAdapter.class))
http://git-wip-us.apache.org/repos/asf/james-project/blob/10916363/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryStepdefs.java b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryStepdefs.java
index 6e9ef3c..da4e493 100644
--- a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryStepdefs.java
+++ b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemoryStepdefs.java
@@ -61,7 +61,7 @@ public class MemoryStepdefs {
.build();
mainStepdefs.messageIdFactory = new InMemoryMessageId.Factory();
- mainStepdefs.jmapServer = new GuiceJamesServer(configuration)
+ mainStepdefs.jmapServer = GuiceJamesServer.forConfiguration(configuration)
.combineWith(MemoryJamesServerMain.IN_MEMORY_SERVER_AGGREGATE_MODULE)
.overrideWith(new TestJMAPServerModule(LIMIT_TO_3_MESSAGES),
(binder) -> binder.bind(MessageId.Factory.class).toInstance(mainStepdefs.messageIdFactory))
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[8/8] james-project git commit: JAMES-2526 Add health check endpoint
documentation
Posted by ad...@apache.org.
JAMES-2526 Add health check endpoint documentation
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/3b648e90
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/3b648e90
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/3b648e90
Branch: refs/heads/master
Commit: 3b648e90fd53434731df4425ede14f9d46ca9549
Parents: 2655763
Author: Antoine Duprat <ad...@linagora.com>
Authored: Thu Aug 23 11:35:16 2018 +0200
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Mon Aug 27 14:18:07 2018 +0200
----------------------------------------------------------------------
src/site/markdown/server/manage-webadmin.md | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/3b648e90/src/site/markdown/server/manage-webadmin.md
----------------------------------------------------------------------
diff --git a/src/site/markdown/server/manage-webadmin.md b/src/site/markdown/server/manage-webadmin.md
index 8dd14c4..2e869c2 100644
--- a/src/site/markdown/server/manage-webadmin.md
+++ b/src/site/markdown/server/manage-webadmin.md
@@ -6,6 +6,8 @@ The web administration supports for now the CRUD operations on the domains, the
**WARNING**: This API allow authentication only via the use of JWT. If not configured with JWT, an administrator should ensure an attacker can not use this API.
+By the way, some endpoints are not filtered by authentication. Those endpoints are not related to data stored in James, for example: Swagger documentation & James health checks.
+
Please also note **webadmin** is only enabled with **Guice**. You can not use it when using James with **Spring**, as the required injections are not implemented.
In case of any error, the system will return an error message which is json format like this:
@@ -24,6 +26,7 @@ as exposed above). To avoid information duplication, this is ommited on endpoint
## Navigation menu
+ - [HealthCheck](#HealthCheck)
- [Administrating domains](#Administrating_domains)
- [Administrating users](#Administrating_users)
- [Administrating user mailboxes](#Administrating_user_mailboxes)
@@ -40,6 +43,21 @@ as exposed above). To avoid information duplication, this is ommited on endpoint
- [Administrating Sieve quotas](#Administrating_Sieve_quotas)
- [Task management](#Task_management)
+## HealthCheck
+
+This endpoint is simple for now and is just returning the http status code corresponding to the state of checks (see below).
+The user has to check in the logs in order to have more information about failing checks.
+
+```
+curl -XGET http://ip:port/healthcheck
+```
+
+Response codes:
+
+ - 200: All checks have answered with a Healthy status
+ - 500: At least one check have answered with a Unhealthy or Degraded status
+
+
## Administrating domains
- [Create a domain](#Create_a_domain)
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[5/8] james-project git commit: JAMES-2526 Introduce health checks
routes in WebAdmin
Posted by ad...@apache.org.
JAMES-2526 Introduce health checks routes in WebAdmin
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/c9cbe2c3
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/c9cbe2c3
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/c9cbe2c3
Branch: refs/heads/master
Commit: c9cbe2c3554dc5d1474185ccf04f4150bd1d5c13
Parents: f30ffeb
Author: Antoine Duprat <ad...@linagora.com>
Authored: Wed Aug 22 15:34:24 2018 +0200
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Mon Aug 27 14:18:06 2018 +0200
----------------------------------------------------------------------
server/protocols/webadmin/webadmin-core/pom.xml | 4 +
.../webadmin/routes/HealthCheckRoutes.java | 118 ++++++++++++++++
.../webadmin/routes/HealthCheckRoutesTest.java | 135 +++++++++++++++++++
3 files changed, 257 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/c9cbe2c3/server/protocols/webadmin/webadmin-core/pom.xml
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-core/pom.xml b/server/protocols/webadmin/webadmin-core/pom.xml
index 6d27db4..3641203 100644
--- a/server/protocols/webadmin/webadmin-core/pom.xml
+++ b/server/protocols/webadmin/webadmin-core/pom.xml
@@ -35,6 +35,10 @@
<dependencies>
<dependency>
<groupId>${james.groupId}</groupId>
+ <artifactId>james-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>${james.groupId}</groupId>
<artifactId>james-server-jwt</artifactId>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/james-project/blob/c9cbe2c3/server/protocols/webadmin/webadmin-core/src/main/java/org/apache/james/webadmin/routes/HealthCheckRoutes.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-core/src/main/java/org/apache/james/webadmin/routes/HealthCheckRoutes.java b/server/protocols/webadmin/webadmin-core/src/main/java/org/apache/james/webadmin/routes/HealthCheckRoutes.java
new file mode 100644
index 0000000..d9c7e67
--- /dev/null
+++ b/server/protocols/webadmin/webadmin-core/src/main/java/org/apache/james/webadmin/routes/HealthCheckRoutes.java
@@ -0,0 +1,118 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.webadmin.routes;
+
+import java.util.List;
+import java.util.Set;
+
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+import org.apache.james.core.healthcheck.HealthCheck;
+import org.apache.james.core.healthcheck.Result;
+import org.apache.james.webadmin.Routes;
+import org.eclipse.jetty.http.HttpStatus;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.github.steveash.guavate.Guavate;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import spark.Service;
+
+@Api(tags = "Healthchecks")
+@Path(HealthCheckRoutes.HEALTHCHECK)
+public class HealthCheckRoutes implements Routes {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(HealthCheckRoutes.class);
+
+ public static final String HEALTHCHECK = "/healthcheck";
+
+
+ private final Set<HealthCheck> healthChecks;
+ private Service service;
+
+ @Inject
+ public HealthCheckRoutes(Set<HealthCheck> healthChecks) {
+ this.healthChecks = healthChecks;
+ }
+
+ @Override
+ public void define(Service service) {
+ this.service = service;
+
+ validateHealthchecks();
+ }
+
+ @GET
+ @ApiOperation(value = "Validate all health checks")
+ @ApiResponses(value = {
+ @ApiResponse(code = HttpStatus.OK_200, message = "OK"),
+ @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500,
+ message = "Internal server error - When one check has failed.")
+ })
+ public void validateHealthchecks() {
+ service.get(HEALTHCHECK,
+ (request, response) -> {
+ List<Result> anyUnhealthyOrDegraded = retrieveUnhealthyOrDegradedHealthChecks();
+
+ anyUnhealthyOrDegraded.forEach(this::logFailedCheck);
+ response.status(getCorrespondingStatusCode(anyUnhealthyOrDegraded));
+ return response;
+ });
+ }
+
+ private int getCorrespondingStatusCode(List<Result> anyUnhealthy) {
+ if (anyUnhealthy.isEmpty()) {
+ return HttpStatus.OK_200;
+ } else {
+ return HttpStatus.INTERNAL_SERVER_ERROR_500;
+ }
+ }
+
+ private void logFailedCheck(Result result) {
+ switch (result.getStatus()) {
+ case UNHEALTHY:
+ LOGGER.error("HealthCheck failed for {} : {}",
+ result.getComponentName().getName(),
+ result.getCause().orElse(""));
+ break;
+ case DEGRADED:
+ LOGGER.warn("HealthCheck is unstable for {} : {}",
+ result.getComponentName().getName(),
+ result.getCause().orElse(""));
+ break;
+ case HEALTHY:
+ // Here only to fix a warning, such cases are already filtered
+ break;
+ }
+ }
+
+ private List<Result> retrieveUnhealthyOrDegradedHealthChecks() {
+ return healthChecks.stream()
+ .map(HealthCheck::check)
+ .filter(result -> result.isUnHealthy() || result.isDegraded())
+ .collect(Guavate.toImmutableList());
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/c9cbe2c3/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/routes/HealthCheckRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/routes/HealthCheckRoutesTest.java b/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/routes/HealthCheckRoutesTest.java
new file mode 100644
index 0000000..e0d5b83
--- /dev/null
+++ b/server/protocols/webadmin/webadmin-core/src/test/java/org/apache/james/webadmin/routes/HealthCheckRoutesTest.java
@@ -0,0 +1,135 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.webadmin.routes;
+
+import static io.restassured.RestAssured.when;
+import static org.apache.james.webadmin.WebAdminServer.NO_CONFIGURATION;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.james.core.healthcheck.ComponentName;
+import org.apache.james.core.healthcheck.HealthCheck;
+import org.apache.james.core.healthcheck.Result;
+import org.apache.james.metrics.logger.DefaultMetricFactory;
+import org.apache.james.webadmin.WebAdminServer;
+import org.apache.james.webadmin.WebAdminUtils;
+import org.eclipse.jetty.http.HttpStatus;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import io.restassured.RestAssured;
+
+public class HealthCheckRoutesTest {
+
+ private static final ComponentName COMPONENT_NAME_1 = new ComponentName("component-1");
+ private static final ComponentName COMPONENT_NAME_2 = new ComponentName("component-2");
+
+ private static HealthCheck healthCheck(Result result) {
+ return new HealthCheck() {
+ @Override
+ public ComponentName componentName() {
+ return result.getComponentName();
+ }
+
+ @Override
+ public Result check() {
+ return result;
+ }
+ };
+ }
+
+ private WebAdminServer webAdminServer;
+ private Set<HealthCheck> healthChecks;
+
+ @Before
+ public void setUp() throws Exception {
+ healthChecks = new HashSet<>();
+
+ webAdminServer = WebAdminUtils.createWebAdminServer(
+ new DefaultMetricFactory(),
+ new HealthCheckRoutes(healthChecks));
+
+ webAdminServer.configure(NO_CONFIGURATION);
+ webAdminServer.await();
+
+ RestAssured.requestSpecification = WebAdminUtils.buildRequestSpecification(webAdminServer)
+ .setBasePath(HealthCheckRoutes.HEALTHCHECK)
+ .build();
+ }
+
+ @After
+ public void tearDown() {
+ webAdminServer.destroy();
+ }
+
+ @Test
+ public void validateHealthchecksShouldReturnOkWhenNoHealthChecks() {
+ when()
+ .get()
+ .then()
+ .statusCode(HttpStatus.OK_200);
+ }
+
+ @Test
+ public void validateHealthchecksShouldReturnOkWhenHealthChecksAreHealthy() {
+ healthChecks.add(healthCheck(Result.healthy(COMPONENT_NAME_1)));
+ healthChecks.add(healthCheck(Result.healthy(COMPONENT_NAME_2)));
+
+ when()
+ .get()
+ .then()
+ .statusCode(HttpStatus.OK_200);
+ }
+
+ @Test
+ public void validateHealthchecksShouldReturnInternalErrorWhenOneHealthCheckIsUnhealthy() {
+ healthChecks.add(healthCheck(Result.unhealthy(COMPONENT_NAME_1, "cause")));
+ healthChecks.add(healthCheck(Result.healthy(COMPONENT_NAME_2)));
+
+ when()
+ .get()
+ .then()
+ .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500);
+ }
+
+ @Test
+ public void validateHealthchecksShouldReturnInternalErrorWhenAllHealthChecksAreUnhealthy() {
+ healthChecks.add(healthCheck(Result.unhealthy(COMPONENT_NAME_1, "cause")));
+ healthChecks.add(healthCheck(Result.unhealthy(COMPONENT_NAME_2)));
+
+ when()
+ .get()
+ .then()
+ .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500);
+ }
+
+ @Test
+ public void validateHealthchecksShouldReturnInternalErrorWhenOneHealthCheckIsDegraded() {
+ healthChecks.add(healthCheck(Result.degraded(COMPONENT_NAME_1, "cause")));
+ healthChecks.add(healthCheck(Result.healthy(COMPONENT_NAME_2)));
+
+ when()
+ .get()
+ .then()
+ .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500);
+ }
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[2/8] james-project git commit: JAMES-2531 Try running raw Cassandra
image
Posted by ad...@apache.org.
JAMES-2531 Try running raw Cassandra image
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/70f53180
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/70f53180
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/70f53180
Branch: refs/heads/master
Commit: 70f53180e7e335405318f3d75707d11634bc4664
Parents: 0fead0d
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Aug 27 10:17:31 2018 +0700
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Mon Aug 27 14:16:05 2018 +0200
----------------------------------------------------------------------
.../james/backends/cassandra/DockerCassandra.java | 16 +---------------
1 file changed, 1 insertion(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/70f53180/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/DockerCassandra.java
----------------------------------------------------------------------
diff --git a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/DockerCassandra.java b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/DockerCassandra.java
index b4b0e43..3a26572 100644
--- a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/DockerCassandra.java
+++ b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/DockerCassandra.java
@@ -25,7 +25,6 @@ import org.slf4j.LoggerFactory;
import org.testcontainers.DockerClientFactory;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.output.OutputFrame;
-import org.testcontainers.images.builder.ImageFromDockerfile;
import org.testcontainers.shaded.com.google.common.collect.ImmutableMap;
import com.github.dockerjava.api.DockerClient;
@@ -35,8 +34,6 @@ public class DockerCassandra {
private static final Logger logger = LoggerFactory.getLogger(DockerCassandra.class);
private static final int CASSANDRA_PORT = 9042;
- private static final String CASSANDRA_CONFIG_DIR = "$CASSANDRA_CONFIG";
- private static final String JVM_OPTIONS = CASSANDRA_CONFIG_DIR + "/jvm.options";
private final GenericContainer<?> cassandraContainer;
private final DockerClient client;
@@ -44,19 +41,8 @@ public class DockerCassandra {
@SuppressWarnings("resource")
public DockerCassandra() {
client = DockerClientFactory.instance().client();
- boolean deleteOnExit = false;
- int cassandraMemory = 1200;
- long cassandraContainerMemory = Float.valueOf(cassandraMemory * 1.5f * 1024 * 1024L).longValue();
- cassandraContainer = new GenericContainer<>(
- new ImageFromDockerfile("cassandra_3_11_3", deleteOnExit)
- .withDockerfileFromBuilder(builder ->
- builder
- .from("cassandra:3.11.3")
- .run("echo \"-Xms" + cassandraMemory + "M\" >> " + JVM_OPTIONS)
- .run("echo \"-Xmx" + cassandraMemory + "M\" >> " + JVM_OPTIONS)
- .build()))
+ cassandraContainer = new GenericContainer<>("cassandra:3.11.3")
.withCreateContainerCmdModifier(cmd -> cmd.getHostConfig().withTmpFs(ImmutableMap.of("/var/lib/cassandra", "rw,noexec,nosuid,size=200m")))
- .withCreateContainerCmdModifier(cmd -> cmd.withMemory(cassandraContainerMemory))
.withExposedPorts(CASSANDRA_PORT)
.withLogConsumer(DockerCassandra::displayDockerLog);
cassandraContainer
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org