Skip to content

Commit ff94e76

Browse files
josegar74davidblasbydavid-blasby
authored
Allow to configure the Elasticsearch connection in environment variables (#8585)
* Allow to configure the Elasticsearch connection in environment variables * Allow to configure the Elasticsearch connection in environment variables - documentation updates * remove es.url and use the components instead (#111) Co-authored-by: david.blasby <david.blasby@geocat.net> --------- Co-authored-by: davidblasby <48937730+davidblasby@users.noreply.github.com> Co-authored-by: david.blasby <david.blasby@geocat.net>
1 parent ff83ede commit ff94e76

11 files changed

Lines changed: 55 additions & 30 deletions

File tree

core/src/test/resources/WEB-INF/config.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ usersavedselection.watchlist.searchurl=catalog.search#/search?_uuid={{filter}}
88
usersavedselection.watchlist.recordurl=api/records/{{index:uuid}}
99

1010

11-
es.url=http://localhost:9200
11+
1212
es.port=9200
1313
es.host=localhost
1414
es.protocol=http

docs/manual/docs/install-guide/installing-index.md

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,32 @@ Older version may be supported but are untested.
108108

109109
## Configure GeoNetwork connection to Elasticsearch
110110

111-
1. Update Elasticsearch connection details in ```WEB-INF/config.properties```:
112-
113-
``` properties
114-
es.protocol=http
115-
es.port=9200
116-
es.host=localhost
117-
es.url=${es.protocol}://${es.host}:${es.port}
118-
es.username=
119-
es.password=
120-
```
111+
By default, GeoNetwork expects Elasticsearch to be running at <http://localhost:9200> without authentication. If your Elasticsearch server is on a different host or port or requires authentication, you will need to configure connection details using either of these methods:
112+
113+
* Define the connection details in Java properties.
114+
115+
```shell
116+
export JAVA_OPTS="$JAVA_OPTS -Des.protocol=http -Des.port=9200 -Des.host=localhost -Des.protocol=http -Des.username= -Des.password="
117+
```
118+
119+
* Define the connection details in environment variables.
120+
121+
```shell
122+
export GEONETWORK_ES_HOST=localhost
123+
export GEONETWORK_ES_PROTOCOL=http
124+
export GEONETWORK_ES_PORT=9200
125+
export GEONETWORK_ES_USERNAME=
126+
export GEONETWORK_ES_PASSWORD=
127+
```
128+
129+
* Edit the values in ```WEB-INF/config.properties``` (not recommended):
130+
131+
```properties
132+
es.protocol=#{systemEnvironment['GEONETWORK_ES_PROTOCOL']?:'http'}
133+
es.port=#{systemEnvironment['GEONETWORK_ES_PORT']?:9200}
134+
es.host=#{systemEnvironment['GEONETWORK_ES_HOST']?:'localhost'}
135+
es.username=#{systemEnvironment['GEONETWORK_ES_USERNAME']?:''}
136+
es.password=#{systemEnvironment['GEONETWORK_ES_PASSWORD']?:''}
137+
```
121138

122-
2. Restart the application:
139+
Once the configuration is complete, you will need to restart the application.

docs/manual/docs/tutorials/introduction/deployment/deploy.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ Once you have Tomcat installed on your system, locate the webapps folder and pla
3030
Open the file /geonetwork/WEB-INF/config.properties and alter the elasticsearch connection
3131

3232
``` bash
33-
$ es.url=http://localhost:9200
33+
es.protocol=http
34+
es.host=localhost
35+
es.port=9200
3436
```
3537

3638
Then (re)start Jetty/Tomcat.

harvesters/src/test/resources/WEB-INF/config.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ usersavedselection.watchlist.searchurl=catalog.search#/search?_uuid={{filter}}
77
# Define the link to each record sent by email by the watchlist notifier
88
usersavedselection.watchlist.recordurl=api/records/{{index:uuid}}
99

10-
es.url=http://localhost:9200
1110
es.port=9200
1211
es.host=localhost
1312
es.protocol=http

index/src/main/java/org/fao/geonet/index/es/EsRestClient.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public class EsRestClient implements InitializingBean {
8181

8282
private ElasticsearchAsyncClient asyncClient;
8383

84-
@Value("${es.url}")
84+
8585
private String serverUrl;
8686

8787
@Value("${es.protocol}")
@@ -127,10 +127,18 @@ public void setDashboardAppUrl(String dashboardAppUrl) {
127127

128128
@Override
129129
public void afterPropertiesSet() throws Exception {
130+
if (StringUtils.isBlank(serverProtocol) || StringUtils.isBlank(serverHost) || StringUtils.isBlank(serverPort)) {
131+
Log.error("geonetwork.index", String.format(
132+
"Elasticsearch URL defined by serverProtocol='%s', serverHost='%s', serverPort='%s' is missing. "
133+
+ "Check configuration.", this.serverProtocol,this.serverHost,this.serverPort));
134+
}
135+
136+
//build server URL
137+
serverUrl = serverProtocol + "://" + serverHost + ":" + serverPort;
130138
if (StringUtils.isNotEmpty(serverUrl)) {
131139
RestClientBuilder builder = RestClient.builder(new HttpHost(serverHost, Integer.parseInt(serverPort), serverProtocol));
132140

133-
if (serverUrl.startsWith("https://")) {
141+
if (serverProtocol.startsWith("https")) {
134142
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(
135143
null, new TrustStrategy() {
136144
public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {

pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1604,7 +1604,6 @@
16041604
<es.protocol>http</es.protocol>
16051605
<es.port>9200</es.port>
16061606
<es.host>localhost</es.host>
1607-
<es.url>${es.protocol}://${es.host}:${es.port}</es.url>
16081607
<es.index.features>gn-features</es.index.features>
16091608
<es.index.features.type>features</es.index.features.type>
16101609
<es.index.records>gn-records</es.index.records>

schemas-test/src/main/webapp/WEB-INF/config.properties

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ usersavedselection.watchlist.searchurl=catalog.search#/search?_uuid={{filter}}
77
# Define the link to each record sent by email by the watchlist notifier
88
usersavedselection.watchlist.recordurl=api/records/{{index:uuid}}
99

10-
11-
es.url=http://localhost:9200
10+
es.protocol=http
11+
es.host=localhost
12+
es.port=9200
1213
es.index.features=features
1314
es.index.records=records
1415
es.index.searchlogs=searchlogs

services/src/main/webapp/WEB-INF/config.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ usersavedselection.watchlist.searchurl=catalog.search#/search?_uuid={{filter}}
77
# Define the link to each record sent by email by the watchlist notifier
88
usersavedselection.watchlist.recordurl=api/records/{{index:uuid}}
99

10+
es.protocol=http
11+
es.host=localhost
1012
es.port=9200
11-
es.url=http://localhost:9200
1213
es.index.features=features
1314
es.index.records=records
1415
es.index.searchlogs=searchlogs

services/src/test/resources/WEB-INF/config.properties

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ usersavedselection.watchlist.searchurl=catalog.search#/search?_uuid={{filter}}
77
# Define the link to each record sent by email by the watchlist notifier
88
usersavedselection.watchlist.recordurl=api/records/{{index:uuid}}
99

10-
es.url=http://localhost:9200
11-
es.port=9200
10+
es.port=9200
1211
es.host=localhost
1312
es.protocol=http
1413
es.index.features=features

web/src/main/webResources/WEB-INF/config.properties

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ usersavedselection.watchlist.searchurl=catalog.search#/search?_uuid={{filter}}
1111
# Define the link to each record sent by email by the watchlist notifier
1212
usersavedselection.watchlist.recordurl=api/records/{{index:uuid}}
1313

14-
es.protocol=${es.protocol}
15-
es.port=${es.port}
16-
es.host=${es.host}
17-
es.url=\${es.protocol}://\${es.host}:\${es.port}
18-
es.username=${es.username}
19-
es.password=${es.password}
14+
es.protocol=#{systemEnvironment['GEONETWORK_ES_PROTOCOL']?:'${es.protocol}'}
15+
es.port=#{systemEnvironment['GEONETWORK_ES_PORT']?:${es.port}}
16+
es.host=#{systemEnvironment['GEONETWORK_ES_HOST']?:'${es.host}'}
17+
es.username=#{systemEnvironment['GEONETWORK_ES_USERNAME']?:'${es.username}'}
18+
es.password=#{systemEnvironment['GEONETWORK_ES_PASSWORD']?:'${es.password}'}
2019
es.index.features=${es.index.features}
2120
es.index.features.type=${es.index.features.type}
2221
# Define the number of decimals to apply when converting geometries to GeoJSON
@@ -33,7 +32,7 @@ es.index.records_public=${es.index.records_public}
3332
es.index.searchlogs=${es.index.searchlogs}
3433
es.index.searchlogs.type=${es.index.searchlogs.type}
3534

36-
kb.url=${kb.url}
35+
kb.url=#{systemEnvironment['GEONETWORK_KIBANA_URL']?:'${kb.url}'}
3736

3837
es.index.checker.interval=0/5 * * * * ?
3938

0 commit comments

Comments
 (0)