NIFI-11441 Removed OpenCypherClientService

- The cypher-gremlin-neo4j-driver library is no longer supported

This closes #7171

Signed-off-by: David Handermann <exceptionfactory@apache.org>
This commit is contained in:
Mike Thomsen 2023-04-13 09:14:57 -04:00 committed by exceptionfactory
parent bdcd4fcfda
commit f3f966ca37
No known key found for this signature in database
GPG Key ID: 29B6A52D2AAE8DBA
4 changed files with 1 additions and 205 deletions

View File

@ -74,11 +74,6 @@
<version>2.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.opencypher.gremlin</groupId>
<artifactId>cypher-gremlin-neo4j-driver</artifactId>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>

View File

@ -1,101 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.nifi.graph;
import org.apache.nifi.annotation.documentation.CapabilityDescription;
import org.apache.nifi.annotation.documentation.Tags;
import org.apache.nifi.annotation.lifecycle.OnDisabled;
import org.apache.nifi.annotation.lifecycle.OnEnabled;
import org.apache.nifi.controller.ConfigurationContext;
import org.apache.nifi.processor.exception.ProcessException;
import org.apache.tinkerpop.gremlin.driver.Cluster;
import org.neo4j.driver.internal.InternalNode;
import org.neo4j.driver.v1.Driver;
import org.neo4j.driver.v1.Record;
import org.neo4j.driver.v1.Session;
import org.neo4j.driver.v1.StatementResult;
import org.opencypher.gremlin.neo4j.driver.GremlinDatabase;
import java.util.HashMap;
import java.util.Map;
@CapabilityDescription("A client service that uses the OpenCypher implementation of the Cypher query language to connect to " +
"databases other than Neo4J that are on the supported list of OpenCypher-compatible products. For more information, see: " +
"http://www.opencypher.org/")
@Tags({ "cypher", "opencypher", "graph", "database", "janus" })
public class OpenCypherClientService extends AbstractTinkerpopClientService implements GraphClientService {
private volatile Driver gremlinDriver;
@OnEnabled
public void onEnabled(ConfigurationContext context) {
Cluster cluster = buildCluster(context);
gremlinDriver = GremlinDatabase.driver(cluster);
}
@OnDisabled
public void onDisabled() {
gremlinDriver.close();
}
public static final String NOT_SUPPORTED = "NOT_SUPPORTED";
private Map<String, Object> handleInternalNode(Map<String, Object> recordMap) {
if (recordMap.size() == 1) {
String key = recordMap.keySet().iterator().next();
Object value = recordMap.get(key);
if (value instanceof InternalNode) {
return ((InternalNode)value).asMap();
}
}
return recordMap;
}
@Override
public Map<String, String> executeQuery(String query, Map<String, Object> parameters, GraphQueryResultCallback handler) {
try (Session session = gremlinDriver.session()) {
StatementResult result = session.run(query, parameters);
long count = 0;
while (result.hasNext()) {
Record record = result.next();
Map<String, Object> asMap = handleInternalNode(record.asMap());
handler.process(asMap, result.hasNext());
count++;
}
Map<String,String> resultAttributes = new HashMap<>();
resultAttributes.put(NODES_CREATED, NOT_SUPPORTED);
resultAttributes.put(RELATIONS_CREATED, NOT_SUPPORTED);
resultAttributes.put(LABELS_ADDED, NOT_SUPPORTED);
resultAttributes.put(NODES_DELETED, NOT_SUPPORTED);
resultAttributes.put(RELATIONS_DELETED, NOT_SUPPORTED);
resultAttributes.put(PROPERTIES_SET, NOT_SUPPORTED);
resultAttributes.put(ROWS_RETURNED, String.valueOf(count));
return resultAttributes;
} catch (Exception ex) {
throw new ProcessException(ex);
}
}
@Override
public String getTransitUrl() {
return transitUrl;
}
}

View File

@ -13,5 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
org.apache.nifi.graph.GremlinClientService
org.apache.nifi.graph.OpenCypherClientService
org.apache.nifi.graph.GremlinClientService

View File

@ -1,97 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.nifi.graph;
import org.apache.nifi.util.NoOpProcessor;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.neo4j.driver.v1.Driver;
import org.neo4j.driver.v1.Session;
import org.neo4j.driver.v1.StatementResult;
import org.opencypher.gremlin.neo4j.driver.GremlinDatabase;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
/*
* To run this, setup JanusGraph using just the BerkeleyJE configuration for the server.
*
* 1. Documentation for configuring JanusGraph: https://docs.janusgraph.org/latest/configuration.html
* 2. Documentation for setting up the Janus Server including adding both REST and WebSocket support:
* https://docs.janusgraph.org/latest/server.html
*
* Then follow these steps with JanusGraph to install OpenCypher support:
*
* 1. Add support to the Janus console: https://github.com/opencypher/cypher-for-gremlin/tree/master/tinkerpop/cypher-gremlin-console-plugin
* 2. Add support to the Janus server: https://github.com/opencypher/cypher-for-gremlin/tree/master/tinkerpop/cypher-gremlin-server-plugin
*/
public class OpenCypherClientServiceIT {
TestRunner runner;
GraphClientService service;
private Driver driver;
@BeforeEach
public void before() throws Exception {
service = new OpenCypherClientService();
runner = TestRunners.newTestRunner(NoOpProcessor.class);
runner.addControllerService("clientService", service);
runner.setProperty(service, AbstractTinkerpopClientService.CONTACT_POINTS, "localhost");
runner.enableControllerService(service);
runner.assertValid();
assertEquals("gremlin://localhost:8182/gremlin", service.getTransitUrl());
driver = GremlinDatabase.driver("//localhost:8182");
executeSession("MATCH (n) detach delete n");
executeSession("CREATE (rover:dog { name: \"Rover\"})");
executeSession("CREATE (fido:dog { name: \"Fido\"})");
executeSession("MATCH (fido:dog) WHERE fido.name = \"Rover\" " +
"MATCH (rover:dog) WHERE rover.name = \"Rover\" " +
"CREATE (rover)-[:chases]->(fido)");
}
@AfterEach
public void after() {
executeSession("MATCH (n) DETACH DELETE n");
}
protected StatementResult executeSession(String statement) {
try (Session session = driver.session()) {
return session.run(statement);
}
}
@Test
public void testBasicQuery() {
String query = "MATCH (n) RETURN n";
List<Map<String, Object>> results = new ArrayList<>();
Map<String, String> attributes = service.executeQuery(query, new HashMap<>(), (record, hasMore) -> results.add(record));
assertNotNull(attributes);
assertEquals(7, attributes.size());
assertEquals(2, results.size());
}
}