MikeThomsen commented on a change in pull request #4204: NIFI-7355 Added 
Gremlin bytecode client service.
URL: https://github.com/apache/nifi/pull/4204#discussion_r407234311
 
 

 ##########
 File path: 
nifi-nar-bundles/nifi-graph-bundle/nifi-other-graph-services/src/main/java/org/apache/nifi/graph/GremlinBytecodeClientService.java
 ##########
 @@ -0,0 +1,150 @@
+/*
+ * 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.commons.codec.digest.DigestUtils;
+import org.apache.nifi.annotation.lifecycle.OnDisabled;
+import org.apache.nifi.annotation.lifecycle.OnEnabled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.controller.ConfigurationContext;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.reporting.InitializationException;
+import org.apache.tinkerpop.gremlin.driver.Cluster;
+import org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteConnection;
+import org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource;
+import 
org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+
+import javax.script.Bindings;
+import javax.script.Compilable;
+import javax.script.CompiledScript;
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
+import javax.script.ScriptException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class GremlinBytecodeClientService extends 
AbstractTinkerpopClientService implements GraphClientService {
+
+    private static final List<PropertyDescriptor> NEW_DESCRIPTORS;
+
+    public static final PropertyDescriptor ADDITIONAL_JARS = new 
PropertyDescriptor.Builder()
+            .name("gremlin-bytecode-additional-jars")
+            .displayName("Additional Jars")
+            .description("Additional jars needed for the traversal to work go 
here.")
+            .dynamicallyModifiesClasspath(true)
+            
.expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+            .build();
+
+    static {
+        List<PropertyDescriptor> _temp = new ArrayList<>();
+        _temp.addAll(DESCRIPTORS);
+        _temp.add(ADDITIONAL_JARS);
+        NEW_DESCRIPTORS = Collections.unmodifiableList(_temp);
+    }
+
+
+    @Override
+    public List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+        return NEW_DESCRIPTORS;
+    }
+
+    private ScriptEngineManager MANAGER = new ScriptEngineManager();
+    private ScriptEngine engine;
+    private Map<String, CompiledScript> compiledCode;
+    private Cluster cluster;
+
+    /**
+     * @param context
+     *            the configuration context
+     * @throws InitializationException
+     *             if unable to create a database connection
+     */
+    @OnEnabled
+    public void onEnabled(final ConfigurationContext context) throws 
InitializationException {
+        cluster = buildCluster(context);
+
+        compiledCode = new ConcurrentHashMap<>();
+        engine = MANAGER.getEngineByName("groovy");
+    }
+
+    @OnDisabled
+    public void shutdown() {
+        try {
+            compiledCode = null;
+            engine = null;
+            cluster.close();
+        } catch (Exception e) {
+            throw new ProcessException(e);
+        }
+    }
+
 
 Review comment:
   Yes, there would. Our graph APIs are built with the idea that you will 
parameterize your scripts because that's a best practice with either Cypher or 
Gremlin. This Gremlin process is a little different, but not so much that it 
would make any sense to skip parameterization.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to