diff --git a/nifi-nar-bundles/nifi-graph-bundle/nifi-other-graph-services/pom.xml b/nifi-nar-bundles/nifi-graph-bundle/nifi-other-graph-services/pom.xml index 82670b0e22..f2add1df83 100644 --- a/nifi-nar-bundles/nifi-graph-bundle/nifi-other-graph-services/pom.xml +++ b/nifi-nar-bundles/nifi-graph-bundle/nifi-other-graph-services/pom.xml @@ -74,11 +74,6 @@ 2.0.0-SNAPSHOT compile - - org.opencypher.gremlin - cypher-gremlin-neo4j-driver - 1.0.4 - org.codehaus.groovy groovy diff --git a/nifi-nar-bundles/nifi-graph-bundle/nifi-other-graph-services/src/main/java/org/apache/nifi/graph/OpenCypherClientService.java b/nifi-nar-bundles/nifi-graph-bundle/nifi-other-graph-services/src/main/java/org/apache/nifi/graph/OpenCypherClientService.java deleted file mode 100644 index 47e44ee5d8..0000000000 --- a/nifi-nar-bundles/nifi-graph-bundle/nifi-other-graph-services/src/main/java/org/apache/nifi/graph/OpenCypherClientService.java +++ /dev/null @@ -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 handleInternalNode(Map 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 executeQuery(String query, Map 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 asMap = handleInternalNode(record.asMap()); - handler.process(asMap, result.hasNext()); - count++; - } - - Map 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; - } -} diff --git a/nifi-nar-bundles/nifi-graph-bundle/nifi-other-graph-services/src/main/resources/META-INF/services/org.apache.nifi.controller.ControllerService b/nifi-nar-bundles/nifi-graph-bundle/nifi-other-graph-services/src/main/resources/META-INF/services/org.apache.nifi.controller.ControllerService index a85b146021..685741c262 100644 --- a/nifi-nar-bundles/nifi-graph-bundle/nifi-other-graph-services/src/main/resources/META-INF/services/org.apache.nifi.controller.ControllerService +++ b/nifi-nar-bundles/nifi-graph-bundle/nifi-other-graph-services/src/main/resources/META-INF/services/org.apache.nifi.controller.ControllerService @@ -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 \ No newline at end of file +org.apache.nifi.graph.GremlinClientService \ No newline at end of file diff --git a/nifi-nar-bundles/nifi-graph-bundle/nifi-other-graph-services/src/test/java/org/apache/nifi/graph/OpenCypherClientServiceIT.java b/nifi-nar-bundles/nifi-graph-bundle/nifi-other-graph-services/src/test/java/org/apache/nifi/graph/OpenCypherClientServiceIT.java deleted file mode 100644 index f3174b4a9c..0000000000 --- a/nifi-nar-bundles/nifi-graph-bundle/nifi-other-graph-services/src/test/java/org/apache/nifi/graph/OpenCypherClientServiceIT.java +++ /dev/null @@ -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> results = new ArrayList<>(); - Map attributes = service.executeQuery(query, new HashMap<>(), (record, hasMore) -> results.add(record)); - assertNotNull(attributes); - assertEquals(7, attributes.size()); - assertEquals(2, results.size()); - } -}