[
https://issues.apache.org/jira/browse/NIFI-4188?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16091122#comment-16091122
]
ASF GitHub Bot commented on NIFI-4188:
--------------------------------------
Github user jvwing commented on a diff in the pull request:
https://github.com/apache/nifi/pull/2012#discussion_r127882745
--- Diff:
nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-processors/src/main/java/org/apache/nifi/processors/rethinkdb/GetRethinkDB.java
---
@@ -0,0 +1,197 @@
+/*
+ * 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.processors.rethinkdb;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.nifi.annotation.behavior.EventDriven;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.behavior.WritesAttributes;
+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.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.expression.AttributeExpression.ResultType;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+
+import com.google.gson.Gson;
+
+import java.io.ByteArrayInputStream;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@EventDriven
+@Tags({"rethinkdb", "get", "read"})
+@CapabilityDescription("Processor to get a JSON document from RethinkDB
(https://www.rethinkdb.com/) using the document id. The FlowFile will contain
the retrieved document")
+@WritesAttributes({
+ @WritesAttribute(attribute = GetRethinkDB.RETHINKDB_ERROR_MESSAGE,
description = "RethinkDB error message"),
+ })
+@SeeAlso({PutRethinkDB.class})
+public class GetRethinkDB extends AbstractRethinkDBProcessor {
+
+ public static AllowableValue READ_MODE_SINGLE = new
AllowableValue("single", "Single", "Read values from memory from primary
replica (Default)");
+ public static AllowableValue READ_MODE_MAJORITY = new
AllowableValue("majority", "Majority", "Read values commited to disk on
majority of replicas");
+ public static AllowableValue READ_MODE_OUTDATED = new
AllowableValue("outdated", "Outdated", "Read values from memory from an
arbitrary replica ");
+
+ protected static final PropertyDescriptor READ_MODE = new
PropertyDescriptor.Builder()
+ .name("rethinkdb-read-mode")
+ .displayName("Read Mode")
+ .description("Read mode used for consistency")
+ .required(true)
+ .defaultValue(READ_MODE_SINGLE.getValue())
+ .allowableValues(READ_MODE_SINGLE, READ_MODE_MAJORITY,
READ_MODE_OUTDATED)
+ .expressionLanguageSupported(true)
+ .build();
+
+ public static final PropertyDescriptor RETHINKDB_DOCUMENT_ID = new
PropertyDescriptor.Builder()
+ .displayName("Document Identifier")
+ .name("rethinkdb-document-identifier")
+ .description("A FlowFile attribute, or attribute expression
used " +
+ "for determining RethinkDB key for the Flow File content")
+ .required(true)
+
.addValidator(StandardValidators.createAttributeExpressionLanguageValidator(ResultType.STRING,
true))
+ .expressionLanguageSupported(true)
+ .build();
+
+ protected String READ_MODE_KEY = "read_mode";
+
+ private static final Set<Relationship> relationships;
+ private static final List<PropertyDescriptor> propertyDescriptors;
+
+ public static final String RETHINKDB_ERROR_MESSAGE =
"rethinkdb.error.message";
+
+ protected Gson gson = new Gson();
+
+ static {
+ final Set<Relationship> tempRelationships = new HashSet<>();
+ tempRelationships.add(REL_SUCCESS);
+ tempRelationships.add(REL_FAILURE);
+ tempRelationships.add(REL_NOT_FOUND);
+ relationships = Collections.unmodifiableSet(tempRelationships);
+
+ final List<PropertyDescriptor> tempDescriptors = new ArrayList<>();
+ tempDescriptors.add(DB_NAME);
+ tempDescriptors.add(DB_HOST);
+ tempDescriptors.add(DB_PORT);
+ tempDescriptors.add(USERNAME);
+ tempDescriptors.add(PASSWORD);
+ tempDescriptors.add(TABLE_NAME);
+ tempDescriptors.add(CHARSET);
+ tempDescriptors.add(RETHINKDB_DOCUMENT_ID);
+ tempDescriptors.add(READ_MODE);
+ tempDescriptors.add(MAX_DOCUMENTS_SIZE);
+ propertyDescriptors =
Collections.unmodifiableList(tempDescriptors);
+ }
+
+ @Override
+ public Set<Relationship> getRelationships() {
+ return relationships;
+ }
+
+ @Override
+ public final List<PropertyDescriptor>
getSupportedPropertyDescriptors() {
+ return propertyDescriptors;
+ }
+
+ @OnScheduled
+ public void onScheduled(final ProcessContext context) {
+ super.onScheduled(context);
+ }
+
+ @Override
+ public void onTrigger(final ProcessContext context, final
ProcessSession session) throws ProcessException {
+ FlowFile flowFile = session.get();
+ if (flowFile == null) {
+ return;
+ }
+
+ Charset charset =
Charset.forName(context.getProperty(CHARSET).evaluateAttributeExpressions(flowFile).getValue());
+ String id =
context.getProperty(RETHINKDB_DOCUMENT_ID).evaluateAttributeExpressions(flowFile).getValue();
+ String readMode =
context.getProperty(READ_MODE).evaluateAttributeExpressions(flowFile).getValue();
+
+ if ( StringUtils.isEmpty(id) ) {
+ getLogger().error("Empty id '" + id + "'");
+ flowFile = session.putAttribute(flowFile,
RETHINKDB_ERROR_MESSAGE, "Empty id '" + id + "'");
+ session.transfer(flowFile, REL_FAILURE);
+ return;
+ }
+
+ try {
+ long startTimeMillis = System.currentTimeMillis();
+ Map<String,Object> document = getDocument(id, readMode);
+
+ if ( document == null ) {
+ getLogger().error("Document not found for id " + id);
--- End diff --
Is not found an error? It seems possible that this could happen at high
volume. Given that it has it's own relationship, and there is a separate
relationship for failure, didn't this "succeed" in not finding the key? I
don't have a strong opinion, I'll accept it as-is if you believe in it.
> Create RethinkDB get processor
> ------------------------------
>
> Key: NIFI-4188
> URL: https://issues.apache.org/jira/browse/NIFI-4188
> Project: Apache NiFi
> Issue Type: New Feature
> Components: Extensions
> Affects Versions: 1.3.0
> Environment: All
> Reporter: Mans Singh
> Assignee: Mans Singh
> Priority: Minor
> Labels: document, get, rethinkdb
> Fix For: 1.4.0
>
>
> Create processor for getting documents by id from RethinkDB
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)