Skip to content

Commit 75a1c62

Browse files
committed
Make source compatible with change jprante/elasticsearch-jdbc#655 (still unmerged so compilation will fail).
1 parent c0a9b11 commit 75a1c62

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

Diff for: pom.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.feaster83.elasticsearch-river-jdbc</groupId>
88
<artifactId>rebuild_strategy</artifactId>
9-
<version>1.7.0.1-SNAPSHOT</version>
9+
<version>1.7.2.0-SNAPSHOT</version>
1010
<packaging>jar</packaging>
1111

1212
<developers>
@@ -52,7 +52,7 @@
5252
<dependency>
5353
<groupId>org.xbib.elasticsearch.importer</groupId>
5454
<artifactId>elasticsearch-jdbc</artifactId>
55-
<version>1.7.0.1</version>
55+
<version>1.7.2.0</version>
5656
</dependency>
5757
<dependency>
5858
<groupId>junit</groupId>
@@ -62,4 +62,4 @@
6262
</dependency>
6363
</dependencies>
6464

65-
</project>
65+
</project>

Diff for: src/main/java/org/xbib/elasticsearch/jdbc/strategy/standard/RebuildSink.java

+12-17
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.elasticsearch.common.lang3.StringUtils;
2828
import org.elasticsearch.common.unit.TimeValue;
2929
import org.xbib.elasticsearch.common.util.IndexableObject;
30+
import org.xbib.elasticsearch.support.client.Ingest;
3031

3132
import java.io.File;
3233
import java.io.IOException;
@@ -98,14 +99,8 @@ public RebuildSink<C> setContext(StandardContext context) {
9899

99100
@Override
100101
public synchronized void beforeFetch() throws IOException {
101-
if (ingest == null) {
102-
if (context.getIngestFactory() != null) {
103-
ingest = context.getIngestFactory().create();
104-
ingest.setMetric(getMetric());
105-
} else {
106-
logger.warn("no ingest factory found");
107-
}
108-
}
102+
Ingest ingest = context.getOrCreateIngest(getMetric());
103+
109104
if (ingest == null) {
110105
logger.warn("no ingest found");
111106
return;
@@ -120,6 +115,7 @@ public synchronized void beforeFetch() throws IOException {
120115
}
121116

122117
private void createIndex() throws IOException {
118+
Ingest ingest = context.getOrCreateIngest(getMetric());
123119
rebuild_index = generateNewIndexName();
124120
index = rebuild_index;
125121

@@ -153,11 +149,11 @@ private String generateNewIndexName() {
153149

154150
@Override
155151
public synchronized void afterFetch() throws IOException {
156-
if (ingest == null) {
157-
ingest = context.getIngestFactory().create();
158-
}
152+
Ingest ingest = context.getIngest();
159153

160-
flushIngest();
154+
if(ingest == null) {
155+
return;
156+
}
161157

162158
ingest.stopBulk(rebuild_index);
163159
ingest.refreshIndex(rebuild_index);
@@ -177,11 +173,6 @@ public synchronized void afterFetch() throws IOException {
177173
allExistingIndices.remove(rebuild_index);
178174

179175
removeOldIndices(allExistingIndices);
180-
181-
if (ingest != null) {
182-
ingest.shutdown();
183-
}
184-
ingest = null;
185176
}
186177

187178
@Override
@@ -218,6 +209,7 @@ public int compare(DateTime o1, DateTime o2) {
218209
}
219210

220211
private List<String> getAllExistingIndices() {
212+
Ingest ingest = context.getIngest();
221213
try {
222214
GetIndexResponse indexResponse = ingest.client().admin().indices().prepareGetIndex().addIndices(index_prefix + "*").execute().get();
223215

@@ -237,6 +229,7 @@ private List<String> getAllExistingIndices() {
237229
}
238230

239231
private List<String> getCurrentActiveIndices() {
232+
Ingest ingest = context.getIngest();
240233
GetAliasesResponse getAliasesResponse = ingest.client().admin().indices().prepareGetAliases(alias).execute().actionGet();
241234

242235
List<String> existingIndices = new ArrayList<>();
@@ -250,6 +243,7 @@ private List<String> getCurrentActiveIndices() {
250243
}
251244

252245
private void removeOldIndices(List<String> indices) {
246+
Ingest ingest = context.getIngest();
253247
List<String> orderedIndexList = getOrderedIndexList(indices);
254248
for (int i = 0; i < (orderedIndexList.size() - keep_last_indices); i++) {
255249
String existingIndex = orderedIndexList.get(i);
@@ -259,6 +253,7 @@ private void removeOldIndices(List<String> indices) {
259253
}
260254

261255
private void switchAliasToNewIndex(List<String> existingIndices) {
256+
Ingest ingest = context.getIngest();
262257
IndicesAliasesRequestBuilder prepareAliasesRequest = ingest.client().admin().indices().prepareAliases();
263258
prepareAliasesRequest.addAlias(rebuild_index, alias).execute().actionGet().isAcknowledged();
264259

0 commit comments

Comments
 (0)