You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by mans2singh <gi...@git.apache.org> on 2017/06/26 13:30:43 UTC
[GitHub] nifi pull request #1942: NIFI-4118 First commit of RethinkDB put processor
GitHub user mans2singh opened a pull request:
https://github.com/apache/nifi/pull/1942
NIFI-4118 First commit of RethinkDB put processor
Thank you for submitting a contribution to Apache NiFi.
In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:
### For all changes:
- [x ] Is there a JIRA ticket associated with this PR? Is it referenced
in the commit message?
- [x ] Does your PR title start with NIFI-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
- [x ] Has your PR been rebased against the latest commit within the target branch (typically master)?
- [x ] Is your initial contribution a single, squashed commit?
### For code changes:
- [x ] Have you ensured that the full suite of tests is executed via mvn -Pcontrib-check clean install at the root nifi folder?
- [x] Have you written or updated unit tests to verify your changes?
- [] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
- [x] If applicable, have you updated the LICENSE file, including the main LICENSE file under nifi-assembly?
- [x] If applicable, have you updated the NOTICE file, including the main NOTICE file found under nifi-assembly?
- [ ] If adding new Properties, have you added .displayName in addition to .name (programmatic access) for each of the new properties?
### For documentation related changes:
- [ ] Have you ensured that format looks appropriate for the output in which it is rendered?
### Note:
Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/mans2singh/nifi NIFI-4118
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/nifi/pull/1942.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #1942
----
commit 21fe145211d8e6ef2a340ca15a61b3df5c885c51
Author: mans2singh <ma...@yahoo.com>
Date: 2017-06-25T22:58:37Z
NIFI-4118 First commit of RethinkDB put processor
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] nifi issue #1942: NIFI-4118 First commit of RethinkDB put processor
Posted by mans2singh <gi...@git.apache.org>.
Github user mans2singh commented on the issue:
https://github.com/apache/nifi/pull/1942
Hi @jvwing -
Thanks for your comments and feedback. I've updated the code (added RethinkDB site link to the description, renamed classes to match RethinkDB conventions, updated notice files and corrected the relation) based on your review.
Regarding thread safety of the driver - as you pointed out, it is thread safe. Here is the pull request for thread safety (https://github.com/rethinkdb/rethinkdb/issues/5166).
Please let me know if you have any additional observations/recommendations.
Thanks again for your thorough review.
Mans
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] nifi issue #1942: NIFI-4118 First commit of RethinkDB put processor
Posted by jvwing <gi...@git.apache.org>.
Github user jvwing commented on the issue:
https://github.com/apache/nifi/pull/1942
Reviewing
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] nifi pull request #1942: NIFI-4118 First commit of RethinkDB put processor
Posted by joewitt <gi...@git.apache.org>.
Github user joewitt commented on a diff in the pull request:
https://github.com/apache/nifi/pull/1942#discussion_r126294188
--- Diff: nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-nar/src/main/resources/META-INF/NOTICE ---
@@ -0,0 +1,30 @@
+nifi-rethinkdb-nar
+Copyright 2016 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
+===========================================
+Apache Software License v2
+===========================================
+
+The following binary components are provided under the Apache Software License v2
+
+ (ASLv2) RethinkDB Java Driver
+ The following NOTICE information applies:
+ RethinkDB Language Drivers
+
+ Copyright 2010-2012 RethinkDB
+
--- End diff --
lines 18-29 can be removed. Also need to add 'commons-io' in here. Can copy it from the top level NOTICE that has it.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] nifi issue #1942: NIFI-4118 First commit of RethinkDB put processor
Posted by mans2singh <gi...@git.apache.org>.
Github user mans2singh commented on the issue:
https://github.com/apache/nifi/pull/1942
The integration tests failed because RethinkDB was not available. I've disabled the integration tests.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] nifi pull request #1942: NIFI-4118 First commit of RethinkDB put processor
Posted by jvwing <gi...@git.apache.org>.
Github user jvwing commented on a diff in the pull request:
https://github.com/apache/nifi/pull/1942#discussion_r126293188
--- Diff: nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-processors/src/main/java/org/apache/nifi/processors/rethinkdb/PutRethinkDB.java ---
@@ -0,0 +1,237 @@
+/*
+ * 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.nifi.annotation.behavior.EventDriven;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.SupportsBatching;
+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.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.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.json.simple.parser.JSONParser;
+import com.rethinkdb.gen.ast.Insert;
+import java.io.ByteArrayOutputStream;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@EventDriven
+@SupportsBatching
+@Tags({"rethinkdb", "stream","insert", "update", "write", "put"})
+@CapabilityDescription("Processor to write the JSON content of a FlowFile to RethinkDB (https://www.rethinkdb.com/). The flow file should contain either JSON Object an array of JSON documents")
+@WritesAttributes({
+ @WritesAttribute(attribute = PutRethinkDB.RETHINKDB_ERROR_MESSAGE, description = "RethinkDB error message"),
+ @WritesAttribute(attribute = PutRethinkDB.RETHINKDB_INSERT_RESULT_ERROR_KEY, description = "Error count while inserting documents"),
+ @WritesAttribute(attribute = PutRethinkDB.RETHINKDB_INSERT_RESULT_DELETED_KEY, description = "Number of documents deleted"),
+ @WritesAttribute(attribute = PutRethinkDB.RETHINKDB_INSERT_RESULT_GENERATED_KEYS_KEY, description = "Keys generated on inserting documents"),
+ @WritesAttribute(attribute = PutRethinkDB.RETHINKDB_INSERT_RESULT_INSERTED_KEY, description = "Number of documents inserted"),
+ @WritesAttribute(attribute = PutRethinkDB.RETHINKDB_INSERT_RESULT_REPLACED_KEY, description = "Number of documents replaced"),
+ @WritesAttribute(attribute = PutRethinkDB.RETHINKDB_INSERT_RESULT_SKIPPED_KEY, description = "Number of documents skipped because they already existed"),
+ @WritesAttribute(attribute = PutRethinkDB.RETHINKDB_INSERT_RESULT_UNCHANGED_KEY, description = "Number of documents unchanged since they already existed"),
+ @WritesAttribute(attribute = PutRethinkDB.RETHINKDB_INSERT_RESULT_FIRST_ERROR_KEY, description = "First error while inserting documents"),
+ @WritesAttribute(attribute = PutRethinkDB.RETHINKDB_INSERT_RESULT_WARNINGS_KEY, description = "Warning message in case of large number of ids being returned on insertion")
+ })
+public class PutRethinkDB extends AbstractRethinkDBProcessor {
+
+ public static AllowableValue CONFLICT_STRATEGY_UPDATE = new AllowableValue("update", "Update", "Update the document having same id with new values");
+ public static AllowableValue CONFLICT_STRATEGY_REPLACE = new AllowableValue("replace", "Replace", "Replace the document with having same id new document");
+ public static AllowableValue CONFLICT_STRATEGY_ERROR = new AllowableValue("error", "Error", "Return error if the document with same id exists");
+
+ public static AllowableValue DURABILITY_SOFT = new AllowableValue("soft", "Soft", "Don't save document on disk before ack");
+ public static AllowableValue DURABILITY_HARD = new AllowableValue("hard", "Hard", "Save document on disk before ack");
+
+ protected static final PropertyDescriptor CONFLICT_STRATEGY = new PropertyDescriptor.Builder()
+ .name("rethinkdb-conflict-strategy")
+ .displayName("Conflict strategy")
+ .description("Conflict strategy to be used in case of inserting existing document.")
+ .required(true)
+ .defaultValue(CONFLICT_STRATEGY_UPDATE.getValue())
+ .allowableValues(CONFLICT_STRATEGY_UPDATE, CONFLICT_STRATEGY_REPLACE, CONFLICT_STRATEGY_ERROR)
+ .expressionLanguageSupported(true)
+ .build();
+
+ protected static final PropertyDescriptor DURABILITY = new PropertyDescriptor.Builder()
+ .name("rethinkdb-durability")
+ .displayName("Durablity of documents")
+ .description("Durability of documents being inserted")
+ .required(true)
+ .defaultValue("hard")
+ .allowableValues(DURABILITY_HARD, DURABILITY_SOFT)
+ .expressionLanguageSupported(true)
+ .build();
+
+ protected String CONFLICT_OPTION_KEY = "conflict";
+ protected String DURABILITY_OPTION_KEY = "durability";
+
+ private static final Set<Relationship> relationships;
+ private static final List<PropertyDescriptor> propertyDescriptors;
+
+ public static final String RETHINKDB_ERROR_MESSAGE = "rethinkdb.error.message";
+ public static final String RETHINKDB_INSERT_RESULT = "rethinkdb.insert.result";
+ public static final String RETHINKDB_INSERT_RESULT_ERROR_KEY = "rethinkdb.insert.errors";
+ public static final String RETHINKDB_INSERT_RESULT_DELETED_KEY = "rethinkdb.insert.deleted";
+ public static final String RETHINKDB_INSERT_RESULT_GENERATED_KEYS_KEY = "rethinkdb.insert.generated_keys";
+ public static final String RETHINKDB_INSERT_RESULT_INSERTED_KEY = "rethinkdb.insert.inserted";
+ public static final String RETHINKDB_INSERT_RESULT_REPLACED_KEY = "rethinkdb.insert.replaced";
+ public static final String RETHINKDB_INSERT_RESULT_SKIPPED_KEY = "rethinkdb.insert.skipped";
+ public static final String RETHINKDB_INSERT_RESULT_UNCHANGED_KEY = "rethinkdb.insert.unchanged";
+ public static final String RETHINKDB_INSERT_RESULT_FIRST_ERROR_KEY = "rethinkdb.insert.first_error";
+ public static final String RETHINKDB_INSERT_RESULT_WARNINGS_KEY = "rethinkdb.insert.warnings";
+
+ static {
+ final Set<Relationship> tempRelationships = new HashSet<>();
+ tempRelationships.add(REL_SUCCESS);
+ tempRelationships.add(REL_FAILURE);
+ 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(CONFLICT_STRATEGY);
+ tempDescriptors.add(DURABILITY);
+ 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;
+ }
+
+ if ( flowFile.getSize() == 0) {
+ getLogger().error("Empty message");
+ flowFile = session.putAttribute(flowFile, RETHINKDB_ERROR_MESSAGE, "Empty message size " + flowFile.getSize());
+ session.transfer(flowFile, REL_FAILURE);
+ return;
+ }
+
+ if ( flowFile.getSize() > maxDocumentsSize) {
+ getLogger().error("Message size exceeded {} max allowed is {}", new Object[] { flowFile.getSize(), maxDocumentsSize});
+ flowFile = session.putAttribute(flowFile, RETHINKDB_ERROR_MESSAGE, "Max message size exceeded " + flowFile.getSize());
+ session.transfer(flowFile, REL_FAILURE);
+ return;
+ }
+
+ Charset charset = Charset.forName(context.getProperty(CHARSET).evaluateAttributeExpressions(flowFile).getValue());
+ String conflictStrategy = context.getProperty(CONFLICT_STRATEGY).evaluateAttributeExpressions(flowFile).getValue();
+ String durability = context.getProperty(DURABILITY).evaluateAttributeExpressions(flowFile).getValue();
+
+ try {
+ long startTimeMillis = System.currentTimeMillis();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ session.exportTo(flowFile, baos);
+ String documents = new String(baos.toByteArray(), charset);
+ JSONParser parser = new JSONParser();
+ Object jsonDocuments = parser.parse(documents);
+
+ Insert insert = getRdbTable().insert(jsonDocuments)
+ .optArg(CONFLICT_OPTION_KEY, conflictStrategy)
+ .optArg(DURABILITY_OPTION_KEY, durability);
+
+ HashMap<String,Object> result = runInsert(insert);
+ final long endTimeMillis = System.currentTimeMillis();
+ getLogger().debug("Json documents {} inserted Result: {}", new Object[] {documents, result});
+ flowFile = populateAttributes(session, flowFile, result);
+
+ if ( (Long)result.get(RESULT_ERROR_KEY) != 0 ) {
+ getLogger().error("There were errors while inserting data documents {} result {}",
+ new Object [] {documents, result});
+ session.transfer(flowFile, REL_FAILURE);
+ } else {
+ session.transfer(flowFile, REL_SUCCESS);
+ session.getProvenanceReporter().send(flowFile,
+ new StringBuilder("rethinkdb://").append(databaseName).append("/").append(tableName).toString(),
+ (endTimeMillis - startTimeMillis));
+ }
+ } catch (Exception exception) {
+ getLogger().error("Failed to insert into RethinkDB due to {}",
+ new Object[]{exception.getLocalizedMessage()}, exception);
+ flowFile = session.putAttribute(flowFile, RETHINKDB_ERROR_MESSAGE, exception.getMessage() + "");
--- End diff --
I notice you use the `+ ""` method to cast objects to strings in several places. Any special reason? It does not appear too much in the NiFi codebase, as opposed to `String.valueOf()`.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] nifi issue #1942: NIFI-4118 First commit of RethinkDB put processor
Posted by jvwing <gi...@git.apache.org>.
Github user jvwing commented on the issue:
https://github.com/apache/nifi/pull/1942
Thanks @mans2singh! This has been merged in.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] nifi issue #1942: NIFI-4118 First commit of RethinkDB put processor
Posted by mans2singh <gi...@git.apache.org>.
Github user mans2singh commented on the issue:
https://github.com/apache/nifi/pull/1942
@jvwing -
I've updated the code based on your comments. Please let me know if there is anything else required.
Thanks again.
Mans
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] nifi pull request #1942: NIFI-4118 First commit of RethinkDB put processor
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/nifi/pull/1942
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] nifi issue #1942: NIFI-4118 First commit of RethinkDB put processor
Posted by mans2singh <gi...@git.apache.org>.
Github user mans2singh commented on the issue:
https://github.com/apache/nifi/pull/1942
@joewitt @jvwing -
Thanks for your review feedback. I've updated the notices as you had mentioned.
Let me know if you have any other thoughts/recommendations.
Mans
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] nifi issue #1942: NIFI-4118 First commit of RethinkDB put processor
Posted by jvwing <gi...@git.apache.org>.
Github user jvwing commented on the issue:
https://github.com/apache/nifi/pull/1942
@mans2singh, thanks for contributing this! I have a few general comments from a first pass:
* The notice information for RethinkDB should be included in the nifi-assembly/NOTICE file.
* The RethinkDB project styles it's name as "RethinkDB" with capitalized R, D, and B. I recommend we do the same in all of the user-visible processor naming, docs, property descriptions, etc.
* The processor docs should include a link to the RethinkDB project.
* Thanks for including a comprehensive test suite with solid code coverage. The integration tests also ran fine for me.
And I have a question about connection management. I don't have any experience with RethinkDB. A brief search for documentation suggests that the Java connection might be thread safe ([RethinkDB Issue #1041](https://github.com/rethinkdb/docs/issues/1041)). Is that your understanding?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] nifi issue #1942: NIFI-4118 First commit of RethinkDB put processor
Posted by mans2singh <gi...@git.apache.org>.
Github user mans2singh commented on the issue:
https://github.com/apache/nifi/pull/1942
Hey Folks:
Can you please give me your feedback on this RethinkDB Put processor ?
Thanks
Mans
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] nifi pull request #1942: NIFI-4118 First commit of RethinkDB put processor
Posted by mans2singh <gi...@git.apache.org>.
Github user mans2singh commented on a diff in the pull request:
https://github.com/apache/nifi/pull/1942#discussion_r126294310
--- Diff: nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-nar/src/main/resources/META-INF/NOTICE ---
@@ -0,0 +1,30 @@
+nifi-rethinkdb-nar
+Copyright 2016 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
+===========================================
+Apache Software License v2
+===========================================
+
+The following binary components are provided under the Apache Software License v2
+
+ (ASLv2) RethinkDB Java Driver
+ The following NOTICE information applies:
+ RethinkDB Language Drivers
+
+ Copyright 2010-2012 RethinkDB
+
--- End diff --
Removed extra lines and added commons-io as recommended.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] nifi pull request #1942: NIFI-4118 First commit of RethinkDB put processor
Posted by mans2singh <gi...@git.apache.org>.
Github user mans2singh commented on a diff in the pull request:
https://github.com/apache/nifi/pull/1942#discussion_r126294305
--- Diff: nifi-assembly/NOTICE ---
@@ -1026,6 +1026,24 @@ The following binary components are provided under the Apache Software License v
This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
+ (ASLv2) RethinkDB Java Driver
+ The following NOTICE information applies:
+ RethinkDB Language Drivers
+
+ Copyright 2010-2012 RethinkDB
+
+ Licensed under the Apache License, Version 2.0 (the "License");
--- End diff --
Removed the extra lines.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] nifi issue #1942: NIFI-4118 First commit of RethinkDB put processor
Posted by mans2singh <gi...@git.apache.org>.
Github user mans2singh commented on the issue:
https://github.com/apache/nifi/pull/1942
Thanks @jvwing
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] nifi pull request #1942: NIFI-4118 First commit of RethinkDB put processor
Posted by mans2singh <gi...@git.apache.org>.
Github user mans2singh commented on a diff in the pull request:
https://github.com/apache/nifi/pull/1942#discussion_r126293852
--- Diff: nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-processors/src/test/java/org/apache/nifi/processors/rethinkdb/ITPutRethinkDBTest.java ---
@@ -0,0 +1,216 @@
+/*
+ * 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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import java.util.List;
+import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.json.simple.JSONArray;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import com.rethinkdb.RethinkDB;
+import com.rethinkdb.net.Connection;
+
+import net.minidev.json.JSONObject;
+
+/**
+ * Integration test for RethinkDB. Please ensure that the RethinkDB is running
+ * on local host with default port and has database test with table test and user
+ * admin with password admin before running the integration tests or set the attributes in the
+ * test accordingly.
+ */
+@Ignore("Comment this out for running tests against a real instance of RethinkDB")
+public class ITPutRethinkDBTest {
+ private TestRunner runner;
+ private Connection connection;
+ private String dbName = "test";
+ private String dbHost = "localhost";
+ private String dbPort = "28015";
+ private String user = "admin";
+ private String password = "admin";
+ private String table = "test";
+
+ @Before
+ public void setUp() throws Exception {
+ runner = TestRunners.newTestRunner(PutRethinkDB.class);
+ runner.setProperty(PutRethinkDB.DB_NAME, dbName);
+ runner.setProperty(PutRethinkDB.DB_HOST, dbHost);
+ runner.setProperty(PutRethinkDB.DB_PORT, dbPort);
+ runner.setProperty(PutRethinkDB.USERNAME, user);
+ runner.setProperty(PutRethinkDB.PASSWORD, password);
+ runner.setProperty(PutRethinkDB.TABLE_NAME, table);
+ runner.setProperty(PutRethinkDB.CHARSET, "UTF-8");
+ runner.setProperty(PutRethinkDB.CONFLICT_STRATEGY, PutRethinkDB.CONFLICT_STRATEGY_UPDATE);
+ runner.setProperty(PutRethinkDB.DURABILITY, PutRethinkDB.DURABILITY_HARD);
+ runner.setProperty(PutRethinkDB.MAX_DOCUMENTS_SIZE, "1 KB");
+ runner.assertValid();
+
+ connection = RethinkDB.r.connection().user(user, password).db(dbName).hostname(dbHost).port(Integer.parseInt(dbPort)).connect();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ runner = null;
+ connection.close();
+ connection = null;
+ }
+
+ @Test
+ public void testValidSingleMessage() {
+ RethinkDB.r.db(dbName).table(table).delete().run(connection);
+ long count = RethinkDB.r.db(dbName).table(table).count().run(connection);
+ assertEquals("Count should be same", 0L, count);
+
+ JSONObject message = new JSONObject();
+ message.put("hello", "rethinkdb");
+ byte [] bytes = message.toJSONString().getBytes();
+ runner.enqueue(bytes);
+ runner.run(1,true,true);
+ runner.assertAllFlowFilesTransferred(PutRethinkDB.REL_SUCCESS, 1);
+
+ List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(PutRethinkDB.REL_SUCCESS);
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_DELETED_KEY), "0");
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_ERROR_KEY),"0");
+ assertNotNull(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_GENERATED_KEYS_KEY));
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_INSERTED_KEY),"1");
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_REPLACED_KEY),"0");
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_SKIPPED_KEY),"0");
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_UNCHANGED_KEY),"0");
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_FIRST_ERROR_KEY),"null");
+
+ count = RethinkDB.r.db(dbName).table(table).count().run(connection);
+ assertEquals("Count should be same", 1L, count);
+ }
+
+ @Test
+ public void testValidSingleMessageTwiceConflictUpdate() {
+ RethinkDB.r.db(dbName).table(table).delete().run(connection);
+ long count = RethinkDB.r.db(dbName).table(table).count().run(connection);
+ assertEquals("Count should be same", 0L, count);
+
+ JSONObject message = new JSONObject();
+ message.put("id", "rethinkdb");
+ byte [] bytes = message.toJSONString().getBytes();
+ runner.enqueue(bytes);
+ runner.run(1,false,true);
+
+ List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(PutRethinkDB.REL_SUCCESS);
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_DELETED_KEY), "0");
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_ERROR_KEY),"0");
+ assertNotNull(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_GENERATED_KEYS_KEY));
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_INSERTED_KEY),"1");
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_REPLACED_KEY),"0");
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_SKIPPED_KEY),"0");
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_UNCHANGED_KEY),"0");
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_FIRST_ERROR_KEY),"null");
+
+ runner.enqueue(bytes);
+ runner.run(1,true,true);
+
+ flowFiles = runner.getFlowFilesForRelationship(PutRethinkDB.REL_SUCCESS);
+ assertEquals(flowFiles.get(1).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_DELETED_KEY), "0");
+ assertEquals(flowFiles.get(1).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_ERROR_KEY),"0");
+ assertNotNull(flowFiles.get(1).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_GENERATED_KEYS_KEY));
+ assertEquals(flowFiles.get(1).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_INSERTED_KEY),"0");
+ assertEquals(flowFiles.get(1).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_REPLACED_KEY),"0");
+ assertEquals(flowFiles.get(1).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_SKIPPED_KEY),"0");
+ assertEquals(flowFiles.get(1).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_UNCHANGED_KEY),"1");
+ assertEquals(flowFiles.get(1).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_FIRST_ERROR_KEY),"null");
+
+ count = RethinkDB.r.db(dbName).table(table).count().run(connection);
+ assertEquals("Count should be same", 1L, count);
+ }
+
+ @Test
+ public void testValidSingleMessageTwiceConflictError() {
+ runner.setProperty(PutRethinkDB.CONFLICT_STRATEGY, PutRethinkDB.CONFLICT_STRATEGY_ERROR);
+ RethinkDB.r.db(dbName).table(table).delete().run(connection);
+ long count = RethinkDB.r.db(dbName).table(table).count().run(connection);
+ assertEquals("Count should be same", 0L, count);
+
+ JSONObject message = new JSONObject();
+ message.put("id", "rethinkdb");
+ byte [] bytes = message.toJSONString().getBytes();
+ runner.enqueue(bytes);
+ runner.run(1,false,true);
+
+ List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(PutRethinkDB.REL_SUCCESS);
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_DELETED_KEY), "0");
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_ERROR_KEY),"0");
+ assertNotNull(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_GENERATED_KEYS_KEY));
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_INSERTED_KEY),"1");
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_REPLACED_KEY),"0");
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_SKIPPED_KEY),"0");
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_UNCHANGED_KEY),"0");
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_FIRST_ERROR_KEY),"null");
+
+ runner.enqueue(bytes);
+ runner.run(1,true,true);
+
+ flowFiles = runner.getFlowFilesForRelationship(PutRethinkDB.REL_FAILURE);
+ assertEquals(flowFiles.get(1).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_DELETED_KEY), "0");
--- End diff --
You are right - it was an oversight on my part. I've corrected the test.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] nifi pull request #1942: NIFI-4118 First commit of RethinkDB put processor
Posted by joewitt <gi...@git.apache.org>.
Github user joewitt commented on a diff in the pull request:
https://github.com/apache/nifi/pull/1942#discussion_r126294117
--- Diff: nifi-assembly/NOTICE ---
@@ -1026,6 +1026,24 @@ The following binary components are provided under the Apache Software License v
This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
+ (ASLv2) RethinkDB Java Driver
+ The following NOTICE information applies:
+ RethinkDB Language Drivers
+
+ Copyright 2010-2012 RethinkDB
+
+ Licensed under the Apache License, Version 2.0 (the "License");
--- End diff --
Lines 1035-1045 should be removed. See other ASLv2 dependencies as examples.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] nifi pull request #1942: NIFI-4118 First commit of RethinkDB put processor
Posted by jvwing <gi...@git.apache.org>.
Github user jvwing commented on a diff in the pull request:
https://github.com/apache/nifi/pull/1942#discussion_r126293212
--- Diff: nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-processors/src/test/java/org/apache/nifi/processors/rethinkdb/ITPutRethinkDBTest.java ---
@@ -0,0 +1,216 @@
+/*
+ * 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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import java.util.List;
+import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.json.simple.JSONArray;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import com.rethinkdb.RethinkDB;
+import com.rethinkdb.net.Connection;
+
+import net.minidev.json.JSONObject;
+
+/**
+ * Integration test for RethinkDB. Please ensure that the RethinkDB is running
+ * on local host with default port and has database test with table test and user
+ * admin with password admin before running the integration tests or set the attributes in the
+ * test accordingly.
+ */
+@Ignore("Comment this out for running tests against a real instance of RethinkDB")
+public class ITPutRethinkDBTest {
+ private TestRunner runner;
+ private Connection connection;
+ private String dbName = "test";
+ private String dbHost = "localhost";
+ private String dbPort = "28015";
+ private String user = "admin";
+ private String password = "admin";
+ private String table = "test";
+
+ @Before
+ public void setUp() throws Exception {
+ runner = TestRunners.newTestRunner(PutRethinkDB.class);
+ runner.setProperty(PutRethinkDB.DB_NAME, dbName);
+ runner.setProperty(PutRethinkDB.DB_HOST, dbHost);
+ runner.setProperty(PutRethinkDB.DB_PORT, dbPort);
+ runner.setProperty(PutRethinkDB.USERNAME, user);
+ runner.setProperty(PutRethinkDB.PASSWORD, password);
+ runner.setProperty(PutRethinkDB.TABLE_NAME, table);
+ runner.setProperty(PutRethinkDB.CHARSET, "UTF-8");
+ runner.setProperty(PutRethinkDB.CONFLICT_STRATEGY, PutRethinkDB.CONFLICT_STRATEGY_UPDATE);
+ runner.setProperty(PutRethinkDB.DURABILITY, PutRethinkDB.DURABILITY_HARD);
+ runner.setProperty(PutRethinkDB.MAX_DOCUMENTS_SIZE, "1 KB");
+ runner.assertValid();
+
+ connection = RethinkDB.r.connection().user(user, password).db(dbName).hostname(dbHost).port(Integer.parseInt(dbPort)).connect();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ runner = null;
+ connection.close();
+ connection = null;
+ }
+
+ @Test
+ public void testValidSingleMessage() {
+ RethinkDB.r.db(dbName).table(table).delete().run(connection);
+ long count = RethinkDB.r.db(dbName).table(table).count().run(connection);
+ assertEquals("Count should be same", 0L, count);
+
+ JSONObject message = new JSONObject();
+ message.put("hello", "rethinkdb");
+ byte [] bytes = message.toJSONString().getBytes();
+ runner.enqueue(bytes);
+ runner.run(1,true,true);
+ runner.assertAllFlowFilesTransferred(PutRethinkDB.REL_SUCCESS, 1);
+
+ List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(PutRethinkDB.REL_SUCCESS);
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_DELETED_KEY), "0");
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_ERROR_KEY),"0");
+ assertNotNull(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_GENERATED_KEYS_KEY));
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_INSERTED_KEY),"1");
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_REPLACED_KEY),"0");
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_SKIPPED_KEY),"0");
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_UNCHANGED_KEY),"0");
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_FIRST_ERROR_KEY),"null");
+
+ count = RethinkDB.r.db(dbName).table(table).count().run(connection);
+ assertEquals("Count should be same", 1L, count);
+ }
+
+ @Test
+ public void testValidSingleMessageTwiceConflictUpdate() {
+ RethinkDB.r.db(dbName).table(table).delete().run(connection);
+ long count = RethinkDB.r.db(dbName).table(table).count().run(connection);
+ assertEquals("Count should be same", 0L, count);
+
+ JSONObject message = new JSONObject();
+ message.put("id", "rethinkdb");
+ byte [] bytes = message.toJSONString().getBytes();
+ runner.enqueue(bytes);
+ runner.run(1,false,true);
+
+ List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(PutRethinkDB.REL_SUCCESS);
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_DELETED_KEY), "0");
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_ERROR_KEY),"0");
+ assertNotNull(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_GENERATED_KEYS_KEY));
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_INSERTED_KEY),"1");
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_REPLACED_KEY),"0");
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_SKIPPED_KEY),"0");
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_UNCHANGED_KEY),"0");
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_FIRST_ERROR_KEY),"null");
+
+ runner.enqueue(bytes);
+ runner.run(1,true,true);
+
+ flowFiles = runner.getFlowFilesForRelationship(PutRethinkDB.REL_SUCCESS);
+ assertEquals(flowFiles.get(1).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_DELETED_KEY), "0");
+ assertEquals(flowFiles.get(1).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_ERROR_KEY),"0");
+ assertNotNull(flowFiles.get(1).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_GENERATED_KEYS_KEY));
+ assertEquals(flowFiles.get(1).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_INSERTED_KEY),"0");
+ assertEquals(flowFiles.get(1).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_REPLACED_KEY),"0");
+ assertEquals(flowFiles.get(1).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_SKIPPED_KEY),"0");
+ assertEquals(flowFiles.get(1).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_UNCHANGED_KEY),"1");
+ assertEquals(flowFiles.get(1).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_FIRST_ERROR_KEY),"null");
+
+ count = RethinkDB.r.db(dbName).table(table).count().run(connection);
+ assertEquals("Count should be same", 1L, count);
+ }
+
+ @Test
+ public void testValidSingleMessageTwiceConflictError() {
+ runner.setProperty(PutRethinkDB.CONFLICT_STRATEGY, PutRethinkDB.CONFLICT_STRATEGY_ERROR);
+ RethinkDB.r.db(dbName).table(table).delete().run(connection);
+ long count = RethinkDB.r.db(dbName).table(table).count().run(connection);
+ assertEquals("Count should be same", 0L, count);
+
+ JSONObject message = new JSONObject();
+ message.put("id", "rethinkdb");
+ byte [] bytes = message.toJSONString().getBytes();
+ runner.enqueue(bytes);
+ runner.run(1,false,true);
+
+ List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(PutRethinkDB.REL_SUCCESS);
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_DELETED_KEY), "0");
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_ERROR_KEY),"0");
+ assertNotNull(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_GENERATED_KEYS_KEY));
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_INSERTED_KEY),"1");
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_REPLACED_KEY),"0");
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_SKIPPED_KEY),"0");
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_UNCHANGED_KEY),"0");
+ assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_FIRST_ERROR_KEY),"null");
+
+ runner.enqueue(bytes);
+ runner.run(1,true,true);
+
+ flowFiles = runner.getFlowFilesForRelationship(PutRethinkDB.REL_FAILURE);
+ assertEquals(flowFiles.get(1).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_DELETED_KEY), "0");
--- End diff --
This integration test failed for me. I believe the failing flowfile is now at index 0, since REL_FAILURE is separate.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] nifi pull request #1942: NIFI-4118 First commit of RethinkDB put processor
Posted by jvwing <gi...@git.apache.org>.
Github user jvwing commented on a diff in the pull request:
https://github.com/apache/nifi/pull/1942#discussion_r125534346
--- Diff: nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-processors/src/main/java/org/apache/nifi/processors/rethinkdb/AbstractRethinkDbProcessor.java ---
@@ -0,0 +1,170 @@
+/*
+ * 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.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.DataUnit;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.util.StandardValidators;
+import com.rethinkdb.RethinkDB;
+import com.rethinkdb.gen.ast.Table;
+import com.rethinkdb.net.Connection;
+
+/**
+ * Abstract base class for RethinkDb processors
+ */
+abstract class AbstractRethinkDbProcessor extends AbstractProcessor {
+
+ protected static final PropertyDescriptor CHARSET = new PropertyDescriptor.Builder()
+ .name("rethinkdb-charset")
+ .displayName("Character Set")
+ .description("Specifies the character set of the document data.")
+ .required(true)
+ .defaultValue("UTF-8")
+ .expressionLanguageSupported(true)
+ .addValidator(StandardValidators.CHARACTER_SET_VALIDATOR)
+ .build();
+
+ public static final PropertyDescriptor DB_NAME = new PropertyDescriptor.Builder()
+ .name("rethinkdb-dbname")
+ .displayName("DB Name")
+ .description("RethinkDb database to connect to")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .build();
+
+ public static final PropertyDescriptor DB_HOST = new PropertyDescriptor.Builder()
+ .name("rethinkdb-host")
+ .displayName("Hostname")
+ .description("RethinkDb hostname")
+ .required(true)
+ .defaultValue("localhost")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .build();
+
+ public static final PropertyDescriptor DB_PORT = new PropertyDescriptor.Builder()
+ .name("rethinkdb-port")
+ .displayName("DB Port")
+ .description("RethinkDb database port to connect to")
+ .required(true)
+ .defaultValue("28015")
+ .addValidator(StandardValidators.PORT_VALIDATOR)
+ .build();
+
+ public static final PropertyDescriptor USERNAME = new PropertyDescriptor.Builder()
+ .name("rethinkdb-username")
+ .displayName("Username")
+ .description("Username for accessing RethinkDb")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .build();
+
+ public static final PropertyDescriptor PASSWORD = new PropertyDescriptor.Builder()
+ .name("rethinkdb-password")
+ .displayName("Password")
+ .description("Password for user")
+ .required(false)
+ .sensitive(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .build();
+
+ public static final PropertyDescriptor TABLE_NAME = new PropertyDescriptor.Builder()
+ .name("rethinkdb-table")
+ .displayName("Table name")
+ .description("RethinkDb table to connect to")
+ .required(true)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .build();
+
+ protected static final PropertyDescriptor MAX_DOCUMENTS_SIZE = new PropertyDescriptor.Builder()
+ .name("rethinkdb-max-document-size")
+ .displayName("Max size of documents in MBs")
+ .description("Maximum size of documents allowed to be posted in one batch")
+ .defaultValue("1 MB")
+ .required(true)
+ .addValidator(StandardValidators.DATA_SIZE_VALIDATOR)
+ .build();
+
+ static final Relationship REL_SUCCESS = new Relationship.Builder().name("success")
+ .description("Sucessful FlowFiles are routed to this relationship").build();
+
+ static final Relationship REL_FAILURE = new Relationship.Builder().name("success")
--- End diff --
Should this be named `failure`?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] nifi pull request #1942: NIFI-4118 First commit of RethinkDB put processor
Posted by mans2singh <gi...@git.apache.org>.
Github user mans2singh commented on a diff in the pull request:
https://github.com/apache/nifi/pull/1942#discussion_r126293831
--- Diff: nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-processors/src/main/java/org/apache/nifi/processors/rethinkdb/PutRethinkDB.java ---
@@ -0,0 +1,237 @@
+/*
+ * 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.nifi.annotation.behavior.EventDriven;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.SupportsBatching;
+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.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.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.json.simple.parser.JSONParser;
+import com.rethinkdb.gen.ast.Insert;
+import java.io.ByteArrayOutputStream;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@EventDriven
+@SupportsBatching
+@Tags({"rethinkdb", "stream","insert", "update", "write", "put"})
+@CapabilityDescription("Processor to write the JSON content of a FlowFile to RethinkDB (https://www.rethinkdb.com/). The flow file should contain either JSON Object an array of JSON documents")
+@WritesAttributes({
+ @WritesAttribute(attribute = PutRethinkDB.RETHINKDB_ERROR_MESSAGE, description = "RethinkDB error message"),
+ @WritesAttribute(attribute = PutRethinkDB.RETHINKDB_INSERT_RESULT_ERROR_KEY, description = "Error count while inserting documents"),
+ @WritesAttribute(attribute = PutRethinkDB.RETHINKDB_INSERT_RESULT_DELETED_KEY, description = "Number of documents deleted"),
+ @WritesAttribute(attribute = PutRethinkDB.RETHINKDB_INSERT_RESULT_GENERATED_KEYS_KEY, description = "Keys generated on inserting documents"),
+ @WritesAttribute(attribute = PutRethinkDB.RETHINKDB_INSERT_RESULT_INSERTED_KEY, description = "Number of documents inserted"),
+ @WritesAttribute(attribute = PutRethinkDB.RETHINKDB_INSERT_RESULT_REPLACED_KEY, description = "Number of documents replaced"),
+ @WritesAttribute(attribute = PutRethinkDB.RETHINKDB_INSERT_RESULT_SKIPPED_KEY, description = "Number of documents skipped because they already existed"),
+ @WritesAttribute(attribute = PutRethinkDB.RETHINKDB_INSERT_RESULT_UNCHANGED_KEY, description = "Number of documents unchanged since they already existed"),
+ @WritesAttribute(attribute = PutRethinkDB.RETHINKDB_INSERT_RESULT_FIRST_ERROR_KEY, description = "First error while inserting documents"),
+ @WritesAttribute(attribute = PutRethinkDB.RETHINKDB_INSERT_RESULT_WARNINGS_KEY, description = "Warning message in case of large number of ids being returned on insertion")
+ })
+public class PutRethinkDB extends AbstractRethinkDBProcessor {
+
+ public static AllowableValue CONFLICT_STRATEGY_UPDATE = new AllowableValue("update", "Update", "Update the document having same id with new values");
+ public static AllowableValue CONFLICT_STRATEGY_REPLACE = new AllowableValue("replace", "Replace", "Replace the document with having same id new document");
+ public static AllowableValue CONFLICT_STRATEGY_ERROR = new AllowableValue("error", "Error", "Return error if the document with same id exists");
+
+ public static AllowableValue DURABILITY_SOFT = new AllowableValue("soft", "Soft", "Don't save document on disk before ack");
+ public static AllowableValue DURABILITY_HARD = new AllowableValue("hard", "Hard", "Save document on disk before ack");
+
+ protected static final PropertyDescriptor CONFLICT_STRATEGY = new PropertyDescriptor.Builder()
+ .name("rethinkdb-conflict-strategy")
+ .displayName("Conflict strategy")
+ .description("Conflict strategy to be used in case of inserting existing document.")
+ .required(true)
+ .defaultValue(CONFLICT_STRATEGY_UPDATE.getValue())
+ .allowableValues(CONFLICT_STRATEGY_UPDATE, CONFLICT_STRATEGY_REPLACE, CONFLICT_STRATEGY_ERROR)
+ .expressionLanguageSupported(true)
+ .build();
+
+ protected static final PropertyDescriptor DURABILITY = new PropertyDescriptor.Builder()
+ .name("rethinkdb-durability")
+ .displayName("Durablity of documents")
+ .description("Durability of documents being inserted")
+ .required(true)
+ .defaultValue("hard")
+ .allowableValues(DURABILITY_HARD, DURABILITY_SOFT)
+ .expressionLanguageSupported(true)
+ .build();
+
+ protected String CONFLICT_OPTION_KEY = "conflict";
+ protected String DURABILITY_OPTION_KEY = "durability";
+
+ private static final Set<Relationship> relationships;
+ private static final List<PropertyDescriptor> propertyDescriptors;
+
+ public static final String RETHINKDB_ERROR_MESSAGE = "rethinkdb.error.message";
+ public static final String RETHINKDB_INSERT_RESULT = "rethinkdb.insert.result";
+ public static final String RETHINKDB_INSERT_RESULT_ERROR_KEY = "rethinkdb.insert.errors";
+ public static final String RETHINKDB_INSERT_RESULT_DELETED_KEY = "rethinkdb.insert.deleted";
+ public static final String RETHINKDB_INSERT_RESULT_GENERATED_KEYS_KEY = "rethinkdb.insert.generated_keys";
+ public static final String RETHINKDB_INSERT_RESULT_INSERTED_KEY = "rethinkdb.insert.inserted";
+ public static final String RETHINKDB_INSERT_RESULT_REPLACED_KEY = "rethinkdb.insert.replaced";
+ public static final String RETHINKDB_INSERT_RESULT_SKIPPED_KEY = "rethinkdb.insert.skipped";
+ public static final String RETHINKDB_INSERT_RESULT_UNCHANGED_KEY = "rethinkdb.insert.unchanged";
+ public static final String RETHINKDB_INSERT_RESULT_FIRST_ERROR_KEY = "rethinkdb.insert.first_error";
+ public static final String RETHINKDB_INSERT_RESULT_WARNINGS_KEY = "rethinkdb.insert.warnings";
+
+ static {
+ final Set<Relationship> tempRelationships = new HashSet<>();
+ tempRelationships.add(REL_SUCCESS);
+ tempRelationships.add(REL_FAILURE);
+ 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(CONFLICT_STRATEGY);
+ tempDescriptors.add(DURABILITY);
+ 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;
+ }
+
+ if ( flowFile.getSize() == 0) {
+ getLogger().error("Empty message");
+ flowFile = session.putAttribute(flowFile, RETHINKDB_ERROR_MESSAGE, "Empty message size " + flowFile.getSize());
+ session.transfer(flowFile, REL_FAILURE);
+ return;
+ }
+
+ if ( flowFile.getSize() > maxDocumentsSize) {
+ getLogger().error("Message size exceeded {} max allowed is {}", new Object[] { flowFile.getSize(), maxDocumentsSize});
+ flowFile = session.putAttribute(flowFile, RETHINKDB_ERROR_MESSAGE, "Max message size exceeded " + flowFile.getSize());
+ session.transfer(flowFile, REL_FAILURE);
+ return;
+ }
+
+ Charset charset = Charset.forName(context.getProperty(CHARSET).evaluateAttributeExpressions(flowFile).getValue());
+ String conflictStrategy = context.getProperty(CONFLICT_STRATEGY).evaluateAttributeExpressions(flowFile).getValue();
+ String durability = context.getProperty(DURABILITY).evaluateAttributeExpressions(flowFile).getValue();
+
+ try {
+ long startTimeMillis = System.currentTimeMillis();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ session.exportTo(flowFile, baos);
+ String documents = new String(baos.toByteArray(), charset);
+ JSONParser parser = new JSONParser();
+ Object jsonDocuments = parser.parse(documents);
+
+ Insert insert = getRdbTable().insert(jsonDocuments)
+ .optArg(CONFLICT_OPTION_KEY, conflictStrategy)
+ .optArg(DURABILITY_OPTION_KEY, durability);
+
+ HashMap<String,Object> result = runInsert(insert);
+ final long endTimeMillis = System.currentTimeMillis();
+ getLogger().debug("Json documents {} inserted Result: {}", new Object[] {documents, result});
+ flowFile = populateAttributes(session, flowFile, result);
+
+ if ( (Long)result.get(RESULT_ERROR_KEY) != 0 ) {
+ getLogger().error("There were errors while inserting data documents {} result {}",
+ new Object [] {documents, result});
+ session.transfer(flowFile, REL_FAILURE);
+ } else {
+ session.transfer(flowFile, REL_SUCCESS);
+ session.getProvenanceReporter().send(flowFile,
+ new StringBuilder("rethinkdb://").append(databaseName).append("/").append(tableName).toString(),
+ (endTimeMillis - startTimeMillis));
+ }
+ } catch (Exception exception) {
+ getLogger().error("Failed to insert into RethinkDB due to {}",
+ new Object[]{exception.getLocalizedMessage()}, exception);
+ flowFile = session.putAttribute(flowFile, RETHINKDB_ERROR_MESSAGE, exception.getMessage() + "");
--- End diff --
You are right - I've updated the code to use String.valueOf method.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---