NIFI-6425 Made executeQuery able to reconnect to the Gremlin cluster.

Signed-off-by: Matthew Burgess <mattyb149@apache.org>

This closes #3572
This commit is contained in:
Mike Thomsen 2019-07-04 07:50:21 -04:00 committed by Matthew Burgess
parent 4c6c1cbb14
commit 768a7b8c00
No known key found for this signature in database
GPG Key ID: 05D3DEB8126DAD24
1 changed files with 16 additions and 2 deletions

View File

@ -37,9 +37,11 @@ public class GremlinClientService extends AbstractTinkerpopClientService impleme
private Cluster cluster;
protected Client client;
public static final String NOT_SUPPORTED = "NOT_SUPPORTED";
private ConfigurationContext context;
@OnEnabled
public void onEnabled(ConfigurationContext context) {
this.context = context;
cluster = buildCluster(context);
client = cluster.connect();
}
@ -52,8 +54,7 @@ public class GremlinClientService extends AbstractTinkerpopClientService impleme
cluster = null;
}
@Override
public Map<String, String> executeQuery(String query, Map<String, Object> parameters, GraphQueryResultCallback handler) {
public Map<String, String> doQuery(String query, Map<String, Object> parameters, GraphQueryResultCallback handler) {
try {
Iterator<Result> iterator = client.submit(query, parameters).iterator();
long count = 0;
@ -86,6 +87,19 @@ public class GremlinClientService extends AbstractTinkerpopClientService impleme
}
}
@Override
public Map<String, String> executeQuery(String query, Map<String, Object> parameters, GraphQueryResultCallback handler) {
try {
return doQuery(query, parameters, handler);
} catch (Exception ex) {
cluster.close();
client.close();
cluster = buildCluster(context);
client = cluster.connect();
return doQuery(query, parameters, handler);
}
}
@Override
public String getTransitUrl() {
return transitUrl;