Skip to content

Commit 00f00c3

Browse files
author
EmmanuelDuru
committed
Upgrade ES 5 (first step; doesn't work yet)
1 parent 60fb663 commit 00f00c3

22 files changed

+317
-142
lines changed

elasticsearch-mapping/pom.xml

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,27 @@
1616
<groupId>org.elasticsearch</groupId>
1717
<artifactId>elasticsearch</artifactId>
1818
</dependency>
19+
<dependency>
20+
<groupId>org.elasticsearch.client</groupId>
21+
<artifactId>transport</artifactId>
22+
</dependency>
23+
<dependency>
24+
<groupId>org.elasticsearch.plugin</groupId>
25+
<artifactId>transport-netty4-client</artifactId>
26+
</dependency>
1927
<dependency>
2028
<groupId>com.floragunn</groupId>
2129
<artifactId>search-guard-ssl</artifactId>
2230
<version>${search-guard.version}</version>
2331
</dependency>
32+
<dependency>
33+
<groupId>com.google.guava</groupId>
34+
<artifactId>guava</artifactId>
35+
</dependency>
2436
<dependency>
25-
<groupId>net.java.dev.jna</groupId>
26-
<artifactId>jna</artifactId>
37+
<groupId>org.projectlombok</groupId>
38+
<artifactId>lombok</artifactId>
39+
<version>${lombok.version}</version>
2740
</dependency>
2841
<dependency>
2942
<groupId>com.fasterxml.jackson.core</groupId>
@@ -71,5 +84,43 @@
7184
<artifactId>commons-beanutils</artifactId>
7285
<version>${commons-beanutils.version}</version>
7386
</dependency>
87+
<!-- Logging -->
88+
<dependency>
89+
<groupId>org.apache.logging.log4j</groupId>
90+
<artifactId>log4j-api</artifactId>
91+
<version>${log4j.version}</version>
92+
</dependency>
93+
<dependency>
94+
<groupId>org.apache.logging.log4j</groupId>
95+
<artifactId>log4j-core</artifactId>
96+
<version>${log4j.version}</version>
97+
</dependency>
98+
<dependency>
99+
<groupId>org.apache.logging.log4j</groupId>
100+
<artifactId>log4j-slf4j-impl</artifactId>
101+
<version>${log4j.version}</version>
102+
</dependency>
103+
<dependency>
104+
<groupId>org.slf4j</groupId>
105+
<artifactId>slf4j-api</artifactId>
106+
<version>${slf4j.version}</version>
107+
</dependency>
108+
<dependency>
109+
<groupId>org.slf4j</groupId>
110+
<artifactId>slf4j-ext</artifactId>
111+
<version>${slf4j.version}</version>
112+
</dependency>
113+
<dependency>
114+
<groupId>org.elasticsearch.test</groupId>
115+
<artifactId>framework</artifactId>
116+
<version>${elasticsearch.version}</version>
117+
<scope>test</scope>
118+
<exclusions>
119+
<exclusion>
120+
<groupId>com.carrotsearch.randomizedtesting</groupId>
121+
<artifactId>randomizedtesting-runner</artifactId>
122+
</exclusion>
123+
</exclusions>
124+
</dependency>
74125
</dependencies>
75126
</project>

elasticsearch-mapping/src/main/java/org/elasticsearch/mapping/ElasticSearchClient.java

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,29 @@
1010
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
1111
import org.elasticsearch.client.Client;
1212
import org.elasticsearch.client.transport.TransportClient;
13-
import org.elasticsearch.common.logging.ESLogger;
14-
import org.elasticsearch.common.logging.Loggers;
1513
import org.elasticsearch.common.settings.Settings;
1614
import org.elasticsearch.common.transport.InetSocketTransportAddress;
1715
import org.elasticsearch.common.unit.TimeValue;
18-
import org.elasticsearch.node.Node;
19-
import org.elasticsearch.node.NodeBuilder;
16+
import org.elasticsearch.transport.client.PreBuiltTransportClient;
2017
import org.elasticsearch.util.AddressParserUtil;
2118
import org.springframework.beans.factory.annotation.Value;
2219
import org.springframework.stereotype.Component;
2320

2421
import com.floragunn.searchguard.ssl.SearchGuardSSLPlugin;
2522
import com.floragunn.searchguard.ssl.util.SSLConfigConstants;
2623

24+
import lombok.extern.slf4j.Slf4j;
25+
2726
/**
2827
* Prepare the node to work with elastic search.
2928
*
3029
* @author luc boutier
3130
*/
3231
@Component
32+
@Slf4j
3333
public class ElasticSearchClient {
3434

35-
private static final ESLogger LOGGER = Loggers.getLogger(MappingBuilder.class);
36-
37-
private Node node;
35+
// private Node node;
3836
private boolean isClient;
3937
private boolean isTransportClient;
4038
private List<InetSocketTransportAddress> adresses;
@@ -52,7 +50,7 @@ public class ElasticSearchClient {
5250
public void initialize() {
5351
if (this.isClient && this.isTransportClient) {
5452
// when these both option are set, we use a transport client
55-
Settings.Builder settingsBuilder = Settings.settingsBuilder()
53+
Settings.Builder settingsBuilder = Settings.builder()
5654
.put("cluster.name", this.clusterName);
5755
if (transportSSL) {
5856
settingsBuilder = settingsBuilder
@@ -62,36 +60,41 @@ public void initialize() {
6260
.put(SSLConfigConstants.SEARCHGUARD_SSL_TRANSPORT_TRUSTSTORE_PASSWORD, this.truststorePassword);
6361
}
6462
Settings settings = settingsBuilder.build();
65-
TransportClient.Builder transportClientBuilder = TransportClient.builder().settings(settings);
66-
if (transportSSL) {
67-
transportClientBuilder = transportClientBuilder.addPlugin(SearchGuardSSLPlugin.class);
63+
TransportClient transportClient;
64+
if (!transportSSL) {
65+
transportClient = new PreBuiltTransportClient(settings);
66+
} else {
67+
transportClient = new PreBuiltTransportClient(settings, SearchGuardSSLPlugin.class);
6868
}
69-
TransportClient transportClient = transportClientBuilder.build();
7069
for (InetSocketTransportAddress add : adresses) {
7170
transportClient.addTransportAddress(add);
7271
}
7372
this.client = transportClient;
74-
} else {
73+
} else {
74+
/************************
7575
// when only 'client' option is set, a node without data is initialized and joins the cluster
7676
this.node = NodeBuilder.nodeBuilder().client(this.isClient).clusterName(this.clusterName).local(this.isLocal).node();
7777
this.client = node.client();
78-
}
78+
***************************/
79+
}
7980

8081
// if (this.resetData) { // removes all indices from elastic search. For Integration testing only.
8182
// this.node.client().admin().indices().prepareDelete().execute().actionGet();
8283
// }
83-
LOGGER.info("Initialized ElasticSearch client for cluster <" + this.clusterName + ">");
84+
log.info("Initialized ElasticSearch client for cluster <" + this.clusterName + ">");
8485
}
8586

8687
@PreDestroy
8788
public void close() {
8889
if (client != null) {
8990
client.close();
9091
}
92+
/***
9193
if (node != null) {
9294
node.close();
9395
}
94-
LOGGER.info("Closed ElasticSearch client for cluster <" + this.clusterName + ">");
96+
****/
97+
log.info("Closed ElasticSearch client for cluster <" + this.clusterName + ">");
9598
}
9699

97100
/**
@@ -103,6 +106,15 @@ public Client getClient() {
103106
return this.client;
104107
}
105108

109+
/**
110+
* Set client (for tests)
111+
*
112+
* @param client ES client
113+
*/
114+
public void setClient (Client client) {
115+
this.client = client;
116+
}
117+
106118
/**
107119
* Wait for green status for the given indices.
108120
*
@@ -115,14 +127,14 @@ public ClusterHealthResponse waitForGreenStatus(String... indices) {
115127
builder.setWaitForGreenStatus();
116128
builder.setTimeout(TimeValue.timeValueSeconds(30));
117129
ClusterHealthResponse response = builder.execute().actionGet();
118-
LOGGER.debug("getStatus : {}", response.getStatus());
119-
LOGGER.debug("getActivePrimaryShards : {}", response.getActivePrimaryShards());
120-
LOGGER.debug("getActiveShards : {}", response.getActiveShards());
121-
LOGGER.debug("getInitializingShards : {}", response.getInitializingShards());
122-
LOGGER.debug("getNumberOfDataNodes : {}", response.getNumberOfDataNodes());
123-
LOGGER.debug("getNumberOfNodes : {}", response.getNumberOfNodes());
124-
LOGGER.debug("getRelocatingShards : {}", response.getRelocatingShards());
125-
LOGGER.debug("getUnassignedShards : {}", response.getUnassignedShards());
130+
log.debug("getStatus : {}", response.getStatus());
131+
log.debug("getActivePrimaryShards : {}", response.getActivePrimaryShards());
132+
log.debug("getActiveShards : {}", response.getActiveShards());
133+
log.debug("getInitializingShards : {}", response.getInitializingShards());
134+
log.debug("getNumberOfDataNodes : {}", response.getNumberOfDataNodes());
135+
log.debug("getNumberOfNodes : {}", response.getNumberOfNodes());
136+
log.debug("getRelocatingShards : {}", response.getRelocatingShards());
137+
log.debug("getUnassignedShards : {}", response.getUnassignedShards());
126138
//LOGGER.debug("getAllValidationFailures : {}", response.getAllValidationFailures());
127139
return response;
128140
}

elasticsearch-mapping/src/main/java/org/elasticsearch/mapping/FieldsMappingBuilder.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@
1414

1515
import org.elasticsearch.annotation.*;
1616
import org.elasticsearch.annotation.query.*;
17-
import org.elasticsearch.common.logging.ESLogger;
18-
import org.elasticsearch.common.logging.Loggers;
1917
import org.elasticsearch.mapping.parser.*;
2018
import org.elasticsearch.util.MapUtil;
2119
import org.springframework.util.ClassUtils;
2220

21+
import lombok.extern.slf4j.Slf4j;
22+
2323
/**
2424
* Process fields in a class to fill-in the properties entry in the class definition map.
2525
*
2626
*/
27+
@Slf4j
2728
public class FieldsMappingBuilder {
28-
private static final ESLogger LOGGER = Loggers.getLogger(MappingBuilder.class);
2929

3030
/**
3131
* Parse fields from the given class to add properties mapping.
@@ -128,7 +128,7 @@ private void processIdAnnotation(Map<String, Object> classDefinitionMap, String
128128
Id id = indexable.getAnnotation(Id.class);
129129
if (id != null) {
130130
if (classDefinitionMap.containsKey("_id")) {
131-
LOGGER.warn("An Id annotation is defined on field <" + esFieldName + "> of <" + indexable.getDeclaringClassName()
131+
log.warn("An Id annotation is defined on field <" + esFieldName + "> of <" + indexable.getDeclaringClassName()
132132
+ "> but an id has already be defined for <" + ((Map<String, Object>) classDefinitionMap.get("_id")).get("path") + ">");
133133
} else {
134134
classDefinitionMap.put("_id", MapUtil.getMap(new String[] { "path", "index", "store" }, new Object[] { esFieldName, id.index(), id.store() }));
@@ -141,7 +141,7 @@ private void processRoutingAnnotation(Map<String, Object> classDefinitionMap, St
141141
Routing routing = indexable.getAnnotation(Routing.class);
142142
if (routing != null) {
143143
if (classDefinitionMap.containsKey("_routing")) {
144-
LOGGER.warn("A Routing annotation is defined on field <" + esFieldName + "> of <" + indexable.getDeclaringClassName()
144+
log.warn("A Routing annotation is defined on field <" + esFieldName + "> of <" + indexable.getDeclaringClassName()
145145
+ "> but a routing has already be defined for <" + ((Map<String, Object>) classDefinitionMap.get("_routing")).get("path") + ">");
146146
} else {
147147
Map<String, Object> routingDef = new HashMap<String, Object>();
@@ -157,7 +157,7 @@ private void processBoostAnnotation(Map<String, Object> classDefinitionMap, Stri
157157
Boost boost = indexable.getAnnotation(Boost.class);
158158
if (boost != null) {
159159
if (classDefinitionMap.containsKey("_boost")) {
160-
LOGGER.warn("A Boost annotation is defined on field <" + esFieldName + "> of <" + indexable.getDeclaringClassName()
160+
log.warn("A Boost annotation is defined on field <" + esFieldName + "> of <" + indexable.getDeclaringClassName()
161161
+ "> but a boost has already be defined for <" + ((Map<String, Object>) classDefinitionMap.get("_boost")).get("name") + ">");
162162
} else {
163163
Map<String, Object> boostDef = new HashMap<String, Object>();
@@ -173,7 +173,7 @@ private void processTimeStampAnnotation(Map<String, Object> classDefinitionMap,
173173
TimeStamp timeStamp = indexable.getAnnotation(TimeStamp.class);
174174
if (timeStamp != null) {
175175
if (classDefinitionMap.containsKey("_timestamp")) {
176-
LOGGER.warn("A TimeStamp annotation is defined on field <" + esFieldName + "> of <" + indexable.getDeclaringClassName()
176+
log.warn("A TimeStamp annotation is defined on field <" + esFieldName + "> of <" + indexable.getDeclaringClassName()
177177
+ "> but a boost has already be defined for <" + ((Map<String, Object>) classDefinitionMap.get("_timestamp")).get("name") + ">");
178178
} else {
179179
Map<String, Object> timeStampDefinition = new HashMap<String, Object>();
@@ -285,7 +285,7 @@ private void processFacetAnnotation(List<IFacetBuilderHelper> classFacets, List<
285285
classFacets.add(facetBuilderHelper);
286286
if (classFilters.contains(facetBuilderHelper)) {
287287
classFilters.remove(facetBuilderHelper);
288-
LOGGER.warn("Field <" + esFieldName + "> already had a filter that will be replaced by the defined facet. Only a single one is allowed.");
288+
log.warn("Field <" + esFieldName + "> already had a filter that will be replaced by the defined facet. Only a single one is allowed.");
289289
}
290290
classFilters.add(facetBuilderHelper);
291291
}
@@ -326,7 +326,7 @@ private void addAggregation(TermsFacet termsFacet, Indexable indexable, String e
326326
classFacets.add(facetBuilderHelper);
327327
if (classFilters.contains(facetBuilderHelper)) {
328328
classFilters.remove(facetBuilderHelper);
329-
LOGGER.warn("Field <" + esFieldName + "> already had a filter that will be replaced by the defined facet. Only a single one is allowed.");
329+
log.warn("Field <" + esFieldName + "> already had a filter that will be replaced by the defined facet. Only a single one is allowed.");
330330
}
331331
classFilters.add(facetBuilderHelper);
332332
}
@@ -426,7 +426,7 @@ private List<Indexable> getIndexables(Class<?> clazz) throws IntrospectionExcept
426426
PropertyDescriptor propertyDescriptor = pdMap.get(pdName);
427427

428428
if (propertyDescriptor == null || propertyDescriptor.getReadMethod() == null || propertyDescriptor.getWriteMethod() == null) {
429-
LOGGER.debug("Field <" + field.getName() + "> of class <" + clazz.getName() + "> has no proper setter/getter and won't be persisted.");
429+
log.debug("Field <" + field.getName() + "> of class <" + clazz.getName() + "> has no proper setter/getter and won't be persisted.");
430430
} else {
431431
fdMap.put(pdName, field);
432432
}

0 commit comments

Comments
 (0)