You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by MikeThomsen <gi...@git.apache.org> on 2018/03/14 18:10:52 UTC
[GitHub] nifi pull request #2546: NIFI-4975 Add GridFS processors
GitHub user MikeThomsen opened a pull request:
https://github.com/apache/nifi/pull/2546
NIFI-4975 Add GridFS processors
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:
- [ ] Is there a JIRA ticket associated with this PR? Is it referenced
in the commit message?
- [ ] 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.
- [ ] Has your PR been rebased against the latest commit within the target branch (typically master)?
- [ ] Is your initial contribution a single, squashed commit?
### For code changes:
- [ ] Have you ensured that the full suite of tests is executed via mvn -Pcontrib-check clean install at the root nifi folder?
- [ ] 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)?
- [ ] If applicable, have you updated the LICENSE file, including the main LICENSE file under nifi-assembly?
- [ ] 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/MikeThomsen/nifi NIFI-4975
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/nifi/pull/2546.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 #2546
----
commit caef8ce496ab861e8e32224aa37fda32d43f45d2
Author: Mike Thomsen <mi...@...>
Date: 2018-03-10T17:57:28Z
NIFI-4975 Add GridFS processors
----
---
[GitHub] nifi pull request #2546: NIFI-4975 Add GridFS processors
Posted by MikeThomsen <gi...@git.apache.org>.
Github user MikeThomsen commented on a diff in the pull request:
https://github.com/apache/nifi/pull/2546#discussion_r181035376
--- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/AbstractMongoProcessor.java ---
@@ -229,7 +252,9 @@ protected MongoDatabase getDatabase(final ProcessContext context, final FlowFile
}
protected MongoCollection<Document> getCollection(final ProcessContext context, final FlowFile flowFile) {
- final String collectionName = context.getProperty(COLLECTION_NAME).evaluateAttributeExpressions(flowFile).getValue();
+ final String collectionName = flowFile == null
--- End diff --
Done.
---
[GitHub] nifi pull request #2546: NIFI-4975 Add GridFS processors
Posted by mattyb149 <gi...@git.apache.org>.
Github user mattyb149 commented on a diff in the pull request:
https://github.com/apache/nifi/pull/2546#discussion_r180938216
--- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/gridfs/DeleteGridFS.java ---
@@ -0,0 +1,161 @@
+/*
+ * 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.mongodb.gridfs;
+
+import com.mongodb.client.MongoCursor;
+import com.mongodb.client.gridfs.GridFSBucket;
+import com.mongodb.client.gridfs.model.GridFSFile;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.ValidationContext;
+import org.apache.nifi.components.ValidationResult;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+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 org.apache.nifi.util.StringUtils;
+import org.bson.Document;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+@CapabilityDescription("Deletes a file from GridFS using a file name or a query.")
+@Tags({"gridfs", "delete", "mongodb"})
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+public class DeleteGridFS extends AbstractGridFSProcessor {
+ static final PropertyDescriptor QUERY = new PropertyDescriptor.Builder()
+ .name("delete-gridfs-query")
+ .displayName("Query")
+ .description("A valid MongoDB query to use to find and delete one or more files from GridFS.")
+ .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+ .addValidator(DOCUMENT_VALIDATOR)
+ .required(false)
+ .build();
+
+ static final PropertyDescriptor FILE_NAME = new PropertyDescriptor.Builder()
+ .name("gridfs-file-name")
+ .displayName("File Name")
--- End diff --
Is this a fully-qualified path or just a file name? I couldn't tell if it worked like S3 buckets or not, if so maybe add something to the description for a n00b like me?
---
[GitHub] nifi pull request #2546: NIFI-4975 Add GridFS processors
Posted by mattyb149 <gi...@git.apache.org>.
Github user mattyb149 commented on a diff in the pull request:
https://github.com/apache/nifi/pull/2546#discussion_r180937862
--- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/QueryHelper.java ---
@@ -0,0 +1,67 @@
+/*
+ * 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.mongodb;
+
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.Validator;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+public interface QueryHelper {
+ AllowableValue MODE_ONE_COMMIT = new AllowableValue("all-at-once", "Full Query Fetch",
+ "Fetch the entire query result and then make it available to downstream processors.");
+ AllowableValue MODE_MANY_COMMITS = new AllowableValue("streaming", "Stream Query Results",
+ "As soon as the query start sending results to the downstream processors at regular intervals.");
+
+ PropertyDescriptor OPERATION_MODE = new PropertyDescriptor.Builder()
+ .name("mongo-operation-mode")
+ .displayName("Operation Mode")
+ .allowableValues(MODE_ONE_COMMIT, MODE_MANY_COMMITS)
+ .defaultValue(MODE_ONE_COMMIT.getValue())
+ .required(true)
+ .description("This option controls when results are made available to downstream processors. If streaming mode is enabled, " +
+ "provenance will not be tracked relative to the input flowfile if an input flowfile is received and starts the query. In streaming mode " +
--- End diff --
Can you explain why provenance would not be tracked relative to the input flowfile? Also perhaps refer to "streaming mode" as "Stream Query Results" for consistency with what is presented to the user.
---
[GitHub] nifi pull request #2546: NIFI-4975 Add GridFS processors
Posted by MikeThomsen <gi...@git.apache.org>.
Github user MikeThomsen commented on a diff in the pull request:
https://github.com/apache/nifi/pull/2546#discussion_r181036257
--- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/gridfs/DeleteGridFS.java ---
@@ -0,0 +1,161 @@
+/*
+ * 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.mongodb.gridfs;
+
+import com.mongodb.client.MongoCursor;
+import com.mongodb.client.gridfs.GridFSBucket;
+import com.mongodb.client.gridfs.model.GridFSFile;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.ValidationContext;
+import org.apache.nifi.components.ValidationResult;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+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 org.apache.nifi.util.StringUtils;
+import org.bson.Document;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+@CapabilityDescription("Deletes a file from GridFS using a file name or a query.")
+@Tags({"gridfs", "delete", "mongodb"})
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+public class DeleteGridFS extends AbstractGridFSProcessor {
+ static final PropertyDescriptor QUERY = new PropertyDescriptor.Builder()
+ .name("delete-gridfs-query")
+ .displayName("Query")
+ .description("A valid MongoDB query to use to find and delete one or more files from GridFS.")
+ .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+ .addValidator(DOCUMENT_VALIDATOR)
+ .required(false)
+ .build();
+
+ static final PropertyDescriptor FILE_NAME = new PropertyDescriptor.Builder()
+ .name("gridfs-file-name")
+ .displayName("File Name")
--- End diff --
It's like buckets from everything I've seen, so I'll clarify that.
---
[GitHub] nifi issue #2546: NIFI-4975 Add GridFS processors
Posted by MikeThomsen <gi...@git.apache.org>.
Github user MikeThomsen commented on the issue:
https://github.com/apache/nifi/pull/2546
@pvillard31 @mattyb149 @mans2singh Anyone up for a code review?
All of the tests work out of the box w/ dockerized Mongo using defaults:
`docker run --name mongotest -p 27017:27017 mongo:latest`
---
[GitHub] nifi pull request #2546: NIFI-4975 Add GridFS processors
Posted by mattyb149 <gi...@git.apache.org>.
Github user mattyb149 commented on a diff in the pull request:
https://github.com/apache/nifi/pull/2546#discussion_r180937580
--- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/AbstractMongoProcessor.java ---
@@ -229,7 +252,9 @@ protected MongoDatabase getDatabase(final ProcessContext context, final FlowFile
}
protected MongoCollection<Document> getCollection(final ProcessContext context, final FlowFile flowFile) {
- final String collectionName = context.getProperty(COLLECTION_NAME).evaluateAttributeExpressions(flowFile).getValue();
+ final String collectionName = flowFile == null
--- End diff --
I think this should be != like the getDatabase() call above?
---
[GitHub] nifi pull request #2546: NIFI-4975 Add GridFS processors
Posted by MikeThomsen <gi...@git.apache.org>.
Github user MikeThomsen commented on a diff in the pull request:
https://github.com/apache/nifi/pull/2546#discussion_r181038091
--- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/QueryHelper.java ---
@@ -0,0 +1,67 @@
+/*
+ * 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.mongodb;
+
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.Validator;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+public interface QueryHelper {
+ AllowableValue MODE_ONE_COMMIT = new AllowableValue("all-at-once", "Full Query Fetch",
+ "Fetch the entire query result and then make it available to downstream processors.");
+ AllowableValue MODE_MANY_COMMITS = new AllowableValue("streaming", "Stream Query Results",
+ "As soon as the query start sending results to the downstream processors at regular intervals.");
+
+ PropertyDescriptor OPERATION_MODE = new PropertyDescriptor.Builder()
+ .name("mongo-operation-mode")
+ .displayName("Operation Mode")
+ .allowableValues(MODE_ONE_COMMIT, MODE_MANY_COMMITS)
+ .defaultValue(MODE_ONE_COMMIT.getValue())
+ .required(true)
+ .description("This option controls when results are made available to downstream processors. If streaming mode is enabled, " +
+ "provenance will not be tracked relative to the input flowfile if an input flowfile is received and starts the query. In streaming mode " +
--- End diff --
When you call `session.commit()`, it will throw an exception if you keep the original input flowfile around. So what I had to do was immediate transfer the original flowfile to REL_ORIGINAL and mark it null.
---
[GitHub] nifi pull request #2546: NIFI-4975 Add GridFS processors
Posted by mattyb149 <gi...@git.apache.org>.
Github user mattyb149 commented on a diff in the pull request:
https://github.com/apache/nifi/pull/2546#discussion_r180937998
--- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/gridfs/AbstractGridFSProcessor.java ---
@@ -0,0 +1,111 @@
+/*
+ * 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.mongodb.gridfs;
+
+import com.mongodb.client.gridfs.GridFSBucket;
+import com.mongodb.client.gridfs.GridFSBuckets;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.Validator;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.processors.mongodb.AbstractMongoProcessor;
+import org.apache.nifi.util.StringUtils;
+import org.bson.types.ObjectId;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public abstract class AbstractGridFSProcessor extends AbstractMongoProcessor {
+
+ static final PropertyDescriptor BUCKET_NAME = new PropertyDescriptor.Builder()
+ .name("gridfs-bucket-name")
+ .displayName("Bucket Name")
+ .description("The GridFS bucket where the files will be stored. If left blank, it will use the default value 'fs' " +
+ "that the MongoDB client driver uses.")
+ .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+ .required(false)
+ .addValidator(Validator.VALID)
+ .build();
+
+ static final PropertyDescriptor FILE_NAME = new PropertyDescriptor.Builder()
+ .name("gridfs-file-name")
+ .displayName("File Name")
+ .description("The name of the file in the bucket that is the target of this processor.")
+ .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .build();
+
+ static final Relationship REL_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("When there is a failure processing the flowfile, it goes to this relationship.")
+ .build();
+
+ static final Relationship REL_SUCCESS = new Relationship.Builder()
+ .name("success")
+ .description("When the operation success, the flowfile is sent to this relationship.")
--- End diff --
This wording is a bit awkward (perhaps copy-paste, but here's the chance to improve it)
---
[GitHub] nifi issue #2546: NIFI-4975 Add GridFS processors
Posted by MikeThomsen <gi...@git.apache.org>.
Github user MikeThomsen commented on the issue:
https://github.com/apache/nifi/pull/2546
@mattyb149 when I rebased this commit, I added fixes for the integration tests so they could run again with the new way of handling EL.
---
[GitHub] nifi pull request #2546: NIFI-4975 Add GridFS processors
Posted by MikeThomsen <gi...@git.apache.org>.
Github user MikeThomsen commented on a diff in the pull request:
https://github.com/apache/nifi/pull/2546#discussion_r181035977
--- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/gridfs/AbstractGridFSProcessor.java ---
@@ -0,0 +1,111 @@
+/*
+ * 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.mongodb.gridfs;
+
+import com.mongodb.client.gridfs.GridFSBucket;
+import com.mongodb.client.gridfs.GridFSBuckets;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.Validator;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.processors.mongodb.AbstractMongoProcessor;
+import org.apache.nifi.util.StringUtils;
+import org.bson.types.ObjectId;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public abstract class AbstractGridFSProcessor extends AbstractMongoProcessor {
+
+ static final PropertyDescriptor BUCKET_NAME = new PropertyDescriptor.Builder()
+ .name("gridfs-bucket-name")
+ .displayName("Bucket Name")
+ .description("The GridFS bucket where the files will be stored. If left blank, it will use the default value 'fs' " +
+ "that the MongoDB client driver uses.")
+ .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+ .required(false)
+ .addValidator(Validator.VALID)
+ .build();
+
+ static final PropertyDescriptor FILE_NAME = new PropertyDescriptor.Builder()
+ .name("gridfs-file-name")
+ .displayName("File Name")
+ .description("The name of the file in the bucket that is the target of this processor.")
+ .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .build();
+
+ static final Relationship REL_FAILURE = new Relationship.Builder()
+ .name("failure")
+ .description("When there is a failure processing the flowfile, it goes to this relationship.")
+ .build();
+
+ static final Relationship REL_SUCCESS = new Relationship.Builder()
+ .name("success")
+ .description("When the operation success, the flowfile is sent to this relationship.")
--- End diff --
Done.
---
[GitHub] nifi issue #2546: NIFI-4975 Add GridFS processors
Posted by MikeThomsen <gi...@git.apache.org>.
Github user MikeThomsen commented on the issue:
https://github.com/apache/nifi/pull/2546
@zenfenan @mattyb149 any chance we could get a review going for this before 1.8?
---