nifi-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zenfenan <...@git.apache.org>
Subject [GitHub] nifi pull request #2896: NIFI-5239 Made a client service an optional source ...
Date Mon, 17 Sep 2018 04:07:38 GMT
Github user zenfenan commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/2896#discussion_r217945280
  
    --- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/main/java/org/apache/nifi/mongodb/MongoDBControllerService.java
---
    @@ -17,156 +17,162 @@
     
     package org.apache.nifi.mongodb;
     
    -import com.mongodb.client.FindIterable;
    +import com.mongodb.MongoClient;
    +import com.mongodb.MongoClientOptions;
    +import com.mongodb.MongoClientURI;
    +import com.mongodb.WriteConcern;
     import com.mongodb.client.MongoCollection;
    -import com.mongodb.client.MongoCursor;
     import com.mongodb.client.MongoDatabase;
    -import com.mongodb.client.model.UpdateOptions;
    -
    +import org.apache.commons.lang3.StringUtils;
     import org.apache.nifi.annotation.documentation.CapabilityDescription;
     import org.apache.nifi.annotation.documentation.Tags;
     import org.apache.nifi.annotation.lifecycle.OnDisabled;
     import org.apache.nifi.annotation.lifecycle.OnEnabled;
    +import org.apache.nifi.annotation.lifecycle.OnStopped;
    +import org.apache.nifi.authentication.exception.ProviderCreationException;
    +import org.apache.nifi.components.PropertyDescriptor;
    +import org.apache.nifi.controller.AbstractControllerService;
     import org.apache.nifi.controller.ConfigurationContext;
    -import org.apache.nifi.reporting.InitializationException;
    +import org.apache.nifi.security.util.SslContextFactory;
    +import org.apache.nifi.ssl.SSLContextService;
     import org.bson.Document;
     
    -import java.io.IOException;
    +import javax.net.ssl.SSLContext;
     import java.util.ArrayList;
     import java.util.List;
     
     @Tags({"mongo", "mongodb", "service"})
     @CapabilityDescription(
         "Provides a controller service that wraps most of the functionality of the MongoDB
driver."
     )
    -public class MongoDBControllerService extends AbstractMongoDBControllerService implements
MongoDBClientService {
    +public class MongoDBControllerService extends AbstractControllerService implements MongoDBClientService
{
         private MongoDatabase db;
         private MongoCollection<Document> col;
    +    private String uri;
     
         @OnEnabled
    -    public void onEnabled(final ConfigurationContext context) throws InitializationException,
IOException, InterruptedException {
    +    public void onEnabled(final ConfigurationContext context) {
    +        this.uri = context.getProperty(URI).evaluateAttributeExpressions().getValue();
             this.createClient(context);
    -        this.db = this.mongoClient.getDatabase(context.getProperty(MongoDBControllerService.DATABASE_NAME).getValue());
    -        this.col = this.db.getCollection(context.getProperty(MongoDBControllerService.COLLECTION_NAME).getValue());
    -    }
    -
    -    @OnDisabled
    -    public void onDisable() {
    -        this.mongoClient.close();
    -    }
    -
    -    @Override
    -    public long count(Document query) {
    -        return this.col.count(query);
    -    }
    -
    -    @Override
    -    public void delete(Document query) {
    -        this.col.deleteMany(query);
         }
     
    -    @Override
    -    public boolean exists(Document query) {
    -        return this.col.count(query) > 0;
    -    }
    -
    -    @Override
    -    public Document findOne(Document query) {
    -        MongoCursor<Document> cursor  = this.col.find(query).limit(1).iterator();
    -        Document retVal = cursor.tryNext();
    -        cursor.close();
    -
    -        return retVal;
    -    }
    +    static List<PropertyDescriptor> descriptors = new ArrayList<>();
     
    -    @Override
    -    public Document findOne(Document query, Document projection) {
    -        MongoCursor<Document> cursor  = projection != null
    -                ? this.col.find(query).projection(projection).limit(1).iterator()
    -                : this.col.find(query).limit(1).iterator();
    -        Document retVal = cursor.tryNext();
    -        cursor.close();
    -
    -        return retVal;
    -    }
    -
    -    @Override
    -    public List<Document> findMany(Document query) {
    -        return findMany(query, null, -1);
    +    static {
    +        descriptors.add(URI);
    +        descriptors.add(SSL_CONTEXT_SERVICE);
    --- End diff --
    
    Why are we only exposing `URI` alone? I thought this PR intends to offer a controller
service where we can configure a connection to a MongoDB database & collection and use
that controller service optionally instead of the processor level `URI`, `Database Name`,
`Collection Name`.


---

Mime
View raw message