Skip to content

Commit 0b59e22

Browse files
committed
Update Java and Elasticsearch versions (RPB-266)
- We need Java 11 for using the latest Metafacture release - Elasticsearch 1.x.x does not support Java 11, Elasticsearch 2.x.x does not support dots in field names, 5.6.16 does both
1 parent bc968bb commit 0b59e22

File tree

6 files changed

+59
-27
lines changed

6 files changed

+59
-27
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,19 @@ sh transformAndIndex.sh
188188

189189
Start the web application:
190190

191+
### Test mode
192+
191193
```
192194
sbt run
193195
```
194196

197+
### Prod mode
198+
199+
```
200+
sbt stage
201+
./target/universal/stage/bin/rpb -no-version-check
202+
```
203+
195204
http://localhost:9000
196205

197206
## Java development

app/controllers/nwbib/Application.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.io.UnsupportedEncodingException;
1010
import java.net.URL;
1111
import java.net.URLEncoder;
12+
import java.nio.charset.Charset;
1213
import java.nio.file.Files;
1314
import java.nio.file.Paths;
1415
import java.text.Collator;
@@ -32,10 +33,9 @@
3233
import java.util.stream.StreamSupport;
3334

3435
import org.antlr.runtime.RecognitionException;
36+
import org.apache.commons.io.IOUtils;
3537
import org.apache.commons.lang3.tuple.Pair;
36-
import org.elasticsearch.common.base.Charsets;
3738
import org.elasticsearch.common.geo.GeoPoint;
38-
import org.elasticsearch.common.io.Streams;
3939

4040
import com.fasterxml.jackson.databind.JsonNode;
4141
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -76,6 +76,8 @@
7676
*/
7777
public class Application extends Controller {
7878

79+
private static final String UTF_8 = "UTF-8";
80+
7981
static final int MAX_FACETS = 150;
8082

8183
private static final String STARRED = "starred";
@@ -150,7 +152,7 @@ public static Result advanced() {
150152
*/
151153
public static String currentUri() {
152154
try {
153-
return URLEncoder.encode(request().host() + request().uri(), "UTF-8");
155+
return URLEncoder.encode(request().host() + request().uri(), UTF_8);
154156
} catch (UnsupportedEncodingException e) {
155157
Logger.error("Could not get current URI", e);
156158
}
@@ -349,7 +351,7 @@ public static Result register(final String t) {
349351
public static Result journals() throws IOException {
350352
try (InputStream stream = Play.application().classloader()
351353
.getResourceAsStream("nwbib-journals.csv")) {
352-
String csv = new String(Streams.copyToByteArray(stream), Charsets.UTF_8);
354+
String csv = IOUtils.toString(stream, UTF_8);
353355
List<String> lines = Arrays.asList(csv.split("\n"));
354356
List<HashMap<String, String>> maps = lines.stream()
355357
.filter(line -> line.split("\",\"").length == 2).map(line -> {
@@ -978,7 +980,7 @@ private static Promise<Result> transformAndIndex(String id, JsonNode jsonBody)
978980
throws IOException, FileNotFoundException, RecognitionException, UnsupportedEncodingException {
979981
File input = new File("conf/output/test-output-strapi.json");
980982
File output = new File("conf/output/test-output-0.json");
981-
Files.write(Paths.get(input.getAbsolutePath()), jsonBody.toString().getBytes(Charsets.UTF_8));
983+
Files.write(Paths.get(input.getAbsolutePath()), jsonBody.toString().getBytes(Charset.forName(UTF_8)));
982984
ETL.main(new String[] {"conf/rpb-test-titel-to-lobid.flux"});
983985
String result = Files.readAllLines(Paths.get(output.getAbsolutePath())).stream().collect(Collectors.joining("\n"));
984986
Cache.remove(String.format("/%s", id));
@@ -988,6 +990,6 @@ private static Promise<Result> transformAndIndex(String id, JsonNode jsonBody)
988990

989991
private static String elasticsearchUrl(String id) throws UnsupportedEncodingException {
990992
return "http://weywot3:9200/resources-rpb-test/resource/"
991-
+ URLEncoder.encode("https://lobid.org/resources/" + id, "UTF-8");
993+
+ URLEncoder.encode("https://lobid.org/resources/" + id, UTF_8);
992994
}
993995
}

app/controllers/nwbib/Classification.java

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.text.Collator;
1414
import java.util.ArrayList;
1515
import java.util.Arrays;
16+
import java.util.Collection;
1617
import java.util.Collections;
1718
import java.util.Comparator;
1819
import java.util.HashMap;
@@ -42,14 +43,17 @@
4243
import org.elasticsearch.action.search.SearchResponse;
4344
import org.elasticsearch.action.search.SearchType;
4445
import org.elasticsearch.client.Client;
45-
import org.elasticsearch.common.settings.ImmutableSettings;
4646
import org.elasticsearch.common.settings.Settings;
47+
import org.elasticsearch.common.xcontent.XContentType;
4748
import org.elasticsearch.index.query.MatchAllQueryBuilder;
4849
import org.elasticsearch.index.query.QueryBuilder;
4950
import org.elasticsearch.index.query.QueryBuilders;
51+
import org.elasticsearch.node.InternalSettingsPreparer;
5052
import org.elasticsearch.node.Node;
51-
import org.elasticsearch.node.NodeBuilder;
53+
import org.elasticsearch.node.NodeValidationException;
54+
import org.elasticsearch.plugins.Plugin;
5255
import org.elasticsearch.search.SearchHit;
56+
import org.elasticsearch.transport.Netty4Plugin;
5357

5458
import com.fasterxml.jackson.databind.JsonNode;
5559
import com.github.jsonldjava.core.JsonLdError;
@@ -194,6 +198,12 @@ public static Comparator<JsonNode> comparator(Function<JsonNode, String> fun) {
194198
.compare(fun.apply(o1), fun.apply(o2));
195199
}
196200

201+
private static class EmbeddedNode extends Node {
202+
public EmbeddedNode(Settings preparedSettings, Collection<Class<? extends Plugin>> classpathPlugins) {
203+
super(InternalSettingsPreparer.prepareEnvironment(preparedSettings, null), classpathPlugins);
204+
}
205+
}
206+
197207
private Classification() {
198208
/* Use via static functions, no instantiation. */
199209
}
@@ -237,7 +247,7 @@ public static List<String> toJsonLd(final URL turtleUrl) {
237247
public static JsonNode ids(String q, String t) {
238248
QueryBuilder queryBuilder = QueryBuilders.boolQuery()
239249
.must(QueryBuilders.idsQuery(Type.NWBIB.elasticsearchType,
240-
Type.SPATIAL.elasticsearchType).ids(q));
250+
Type.SPATIAL.elasticsearchType).addIds(q));
241251
SearchRequestBuilder requestBuilder = client.prepareSearch(INDEX)
242252
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH).setQuery(queryBuilder);
243253
if (t.isEmpty()) {
@@ -473,16 +483,21 @@ public static String shortId(String uri) {
473483

474484
/** Start up the embedded Elasticsearch classification index. */
475485
public static void indexStartup() {
476-
Settings clientSettings = ImmutableSettings.settingsBuilder()
477-
.put("path.home", new File(".").getAbsolutePath())
478-
.put("http.port",
479-
play.Play.application().isTest() ? "8855"
480-
: CONFIG.getString("index.es.port.http"))
481-
.put("transport.tcp.port", play.Play.application().isTest() ? "8856"
482-
: CONFIG.getString("index.es.port.tcp"))
483-
.build();
484-
node =
485-
NodeBuilder.nodeBuilder().settings(clientSettings).local(true).node();
486+
boolean isTest = play.Play.application().isTest();
487+
String httpPort = isTest ? "8855" : CONFIG.getString("index.es.port.http");
488+
String tcpPort = isTest ? "8856" : CONFIG.getString("index.es.port.tcp");
489+
node = new EmbeddedNode(Settings.builder().put("transport.type", "netty4")//
490+
.put("http.type", "netty4")//
491+
.put("http.enabled", "true")//
492+
.put("path.home", new File(".").getAbsolutePath())//
493+
.put("http.port", httpPort)//
494+
.put("transport.tcp.port", tcpPort)//
495+
.build(), Arrays.asList(Netty4Plugin.class));
496+
try {
497+
node.start();
498+
} catch (NodeValidationException e) {
499+
e.printStackTrace();
500+
}
486501
client = node.client();
487502
client.admin().cluster().prepareHealth().setWaitForYellowStatus().execute()
488503
.actionGet();
@@ -502,8 +517,8 @@ private static void indexData(String dataUrl, Type type) {
502517
List<String> jsonLd = toJsonLd(new URL(dataUrl));
503518
for (String concept : jsonLd) {
504519
String id = Json.parse(concept).findValue("@id").textValue();
505-
IndexRequestBuilder indexRequest = client
506-
.prepareIndex(INDEX, type.elasticsearchType, id).setSource(concept);
520+
IndexRequestBuilder indexRequest = client.prepareIndex(INDEX, type.elasticsearchType, id)
521+
.setSource(concept.getBytes(), XContentType.JSON);
507522
bulkRequest.add(indexRequest);
508523
}
509524
} catch (MalformedURLException e) {
@@ -517,7 +532,11 @@ private static void indexData(String dataUrl, Type type) {
517532

518533
/** Shut down the embedded Elasticsearch classification index. */
519534
public static void indexShutdown() {
520-
node.close();
535+
try {
536+
node.close();
537+
} catch (IOException e) {
538+
e.printStackTrace();
539+
}
521540
}
522541

523542
/**

app/controllers/nwbib/Lobid.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
import java.util.stream.StreamSupport;
2121

2222
import org.apache.commons.lang3.tuple.Pair;
23-
import org.elasticsearch.common.collect.Lists;
2423

2524
import com.fasterxml.jackson.databind.JsonNode;
2625
import com.google.common.collect.ImmutableMap;
26+
import com.google.common.collect.Lists;
2727
import com.google.common.html.HtmlEscapers;
2828

2929
import controllers.nwbib.Classification.Type;

build.sbt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name := "rpb"
22

33
version := "0.1.0-SNAPSHOT"
44

5-
scalaVersion := "2.11.11"
5+
scalaVersion := "2.11.12"
66

77
resolvers += Resolver.mavenLocal
88

@@ -21,7 +21,9 @@ libraryDependencies ++= Seq(
2121
"org.metafacture" % "metafacture-csv" % "6.2.0",
2222
"org.metafacture" % "metafacture-linkeddata" % "6.2.0",
2323
"org.metafacture" % "metafix" % "1.2.0",
24-
"org.elasticsearch" % "elasticsearch" % "1.7.5" withSources(),
24+
"org.elasticsearch" % "elasticsearch" % "5.6.16" withSources(),
25+
"org.elasticsearch.plugin" % "transport-netty4-client" % "5.6.16" withSources(),
26+
"com.sun.xml.bind" % "jaxb-impl" % "2.3.3" withSources(),
2527
"com.github.jsonld-java" % "jsonld-java" % "0.5.0",
2628
"org.apache.commons" % "commons-rdf-jena" % "0.5.0",
2729
"org.apache.commons" % "commons-csv" % "1.6",
@@ -43,7 +45,7 @@ dependencyOverrides ++= Set(
4345

4446
lazy val root = (project in file(".")).enablePlugins(PlayJava)
4547

46-
javacOptions ++= Seq("-source", "1.8", "-target", "1.8")
48+
javacOptions ++= Seq("-source", "11", "-target", "11")
4749

4850
import com.typesafe.sbteclipse.core.EclipsePlugin.EclipseKeys
4951

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=0.13.16
1+
sbt.version=0.13.18

0 commit comments

Comments
 (0)