levilentz commented on code in PR #7677: URL: https://github.com/apache/nifi/pull/7677#discussion_r1337995149
########## nifi-nar-bundles/nifi-graph-bundle/nifi-other-graph-services/src/main/java/org/apache/nifi/graph/TinkerpopClientService.java: ########## @@ -0,0 +1,545 @@ +/* + * 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 io.netty.handler.ssl.ClientAuth; +import io.netty.handler.ssl.JdkSslContext; +import org.apache.commons.codec.digest.DigestUtils; +import org.apache.nifi.annotation.behavior.RequiresInstanceClassLoading; +import org.apache.nifi.annotation.documentation.CapabilityDescription; +import org.apache.nifi.annotation.documentation.SeeAlso; +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.components.AllowableValue; +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.components.ValidationContext; +import org.apache.nifi.components.ValidationResult; +import org.apache.nifi.components.Validator; +import org.apache.nifi.components.resource.ResourceCardinality; +import org.apache.nifi.components.resource.ResourceType; +import org.apache.nifi.controller.AbstractControllerService; +import org.apache.nifi.controller.ConfigurationContext; +import org.apache.nifi.expression.ExpressionLanguageScope; +import org.apache.nifi.graph.gremlin.SimpleEntry; +import org.apache.nifi.processor.exception.ProcessException; +import org.apache.nifi.processor.util.StandardValidators; +import org.apache.nifi.reporting.InitializationException; +import org.apache.nifi.ssl.SSLContextService; +import org.apache.nifi.util.StringUtils; +import org.apache.nifi.util.file.classloader.ClassLoaderUtils; +import org.apache.tinkerpop.gremlin.driver.Client; +import org.apache.tinkerpop.gremlin.driver.Cluster; +import org.apache.tinkerpop.gremlin.driver.Result; +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.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + + +@Tags({"graph", "gremlin"}) +@CapabilityDescription("This service interacts with a tinkerpop-compliant graph service, providing both script submission and bytecode submission capabilities. " + + "Script submission is the default, with the script command being sent to the gremlin server as text. This should only be used for simple interactions with a tinkerpop-compliant server " + + "such as counts or other operations that do not require the injection of custom classed. " + + "Bytecode submission allows much more flexibility. When providing a jar, custom serializers can be used and pre-compiled graph logic can be utilized by groovy scripts" + + "provided by processors such as the ExecuteGraphQueryRecordProcessor.") +@SeeAlso(classNames = {"ExecuteGraphQueryRecordProcessor"}) +@RequiresInstanceClassLoading +public class TinkerpopClientService extends AbstractControllerService implements GraphClientService { + public static final String NOT_SUPPORTED = "NOT_SUPPORTED"; + private static final AllowableValue BYTECODE_SUBMISSION = new AllowableValue("bytecode-submission", "ByteCode Submission", + "Groovy scripts are compiled within NiFi, with the GraphTraversalSource injected as a variable 'g'. Effectively allowing " + + "your logic to directly manipulates the graph without string serialization overheard." + ); + + private static final AllowableValue SCRIPT_SUBMISSION = new AllowableValue("script-submission", "Script Submission", + "Script is sent to the gremlin server as a submission. Similar to a rest request. " + ); + + private static final AllowableValue YAML_SETTINGS = new AllowableValue("yaml-settings", "Yaml Settings", + "Connection to the gremlin server will be specified via a yaml file (very flexible)"); + + private static final AllowableValue SERVICE_SETTINGS = new AllowableValue("service-settings", "Service-Defined Settings", + "Connection to the gremlin server will be specified via values on this controller (simpler). " + + "Only recommended for testing and development with a simple grpah instance. "); + + public static final PropertyDescriptor SUBMISSION_TYPE = new PropertyDescriptor.Builder() + .name("submission-type") + .displayName("Script Submission Type") + .description("A selection that toggles for between script submission or as bytecode submission") + .allowableValues(SCRIPT_SUBMISSION, BYTECODE_SUBMISSION) + .defaultValue("script-submission") + .required(true) + .build(); + + public static final PropertyDescriptor CONNECTION_SETTINGS = new PropertyDescriptor.Builder() + .name("connection-settings") + .displayName("Settings Specification") + .description("Selecting \"Service-Defined Settings\" connects using the setting on this service. Selecting \"Yaml Settings\" uses the specified yaml file for connection settings. ") + .allowableValues(SERVICE_SETTINGS, YAML_SETTINGS) + .defaultValue("service-settings") + .required(true) + .build(); + + public static final PropertyDescriptor CONTACT_POINTS = new PropertyDescriptor.Builder() + .name("tinkerpop-contact-points") + .displayName("Contact Points") + .description("A comma-separated list of hostnames or IP addresses where an OpenCypher-enabled server can be found.") Review Comment: Updated to gremlin. -- 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. To unsubscribe, e-mail: issues-unsubscr...@nifi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org