exceptionfactory commented on code in PR #10031: URL: https://github.com/apache/nifi/pull/10031#discussion_r2413861202
########## nifi-extension-bundles/nifi-couchbase-bundle/nifi-couchbase-services-api/src/main/java/org/apache/nifi/services/couchbase/utils/DocumentType.java: ########## @@ -0,0 +1,37 @@ +/* + * 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.services.couchbase.utils; + +/** + * Couchbase document types. + */ +public enum DocumentType { + + JSON( "application/json"), + BINARY( "application/octet-stream"); Review Comment: ```suggestion JSON("application/json"), BINARY("application/octet-stream"); ``` ########## nifi-extension-bundles/nifi-couchbase-bundle/nifi-couchbase-processors/pom.xml: ########## @@ -0,0 +1,67 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.nifi</groupId> + <artifactId>nifi-couchbase-bundle</artifactId> + <version>2.7.0-SNAPSHOT</version> + </parent> + + <artifactId>nifi-couchbase-processors</artifactId> + <packaging>jar</packaging> + + <dependencies> + <dependency> + <groupId>org.apache.nifi</groupId> + <artifactId>nifi-couchbase-services-api</artifactId> + <version>2.7.0-SNAPSHOT</version> + <scope>provided</scope> + </dependency> + + <!-- Test Dependencies --> + <dependency> + <groupId>org.apache.nifi</groupId> + <artifactId>nifi-couchbase-standard-services</artifactId> + <version>2.7.0-SNAPSHOT</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.nifi</groupId> + <artifactId>nifi-ssl-context-service-api</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.testcontainers</groupId> + <artifactId>testcontainers</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.testcontainers</groupId> + <artifactId>couchbase</artifactId> + <version>1.21.3</version> Review Comment: This version should either be removed, or reference `testcontainers.version` ########## nifi-extension-bundles/nifi-couchbase-bundle/nifi-couchbase-standard-services/pom.xml: ########## @@ -0,0 +1,70 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.nifi</groupId> + <artifactId>nifi-couchbase-bundle</artifactId> + <version>2.7.0-SNAPSHOT</version> + </parent> + + <artifactId>nifi-couchbase-standard-services</artifactId> + <packaging>jar</packaging> + + <properties> + <couchbase.version>3.9.0</couchbase.version> Review Comment: This can now be updated to 3.9.1 ########## nifi-extension-bundles/nifi-couchbase-bundle/nifi-couchbase-standard-services/src/main/java/org/apache/nifi/services/couchbase/StandardCouchbaseClient.java: ########## @@ -0,0 +1,162 @@ +/* + * 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.services.couchbase; + +import com.couchbase.client.core.error.AuthenticationFailureException; +import com.couchbase.client.core.error.BucketNotFoundException; +import com.couchbase.client.core.error.CasMismatchException; +import com.couchbase.client.core.error.CollectionNotFoundException; +import com.couchbase.client.core.error.ConfigException; +import com.couchbase.client.core.error.DatasetNotFoundException; +import com.couchbase.client.core.error.DecodingFailureException; +import com.couchbase.client.core.error.DocumentExistsException; +import com.couchbase.client.core.error.DocumentLockedException; +import com.couchbase.client.core.error.DocumentMutationLostException; +import com.couchbase.client.core.error.DocumentNotFoundException; +import com.couchbase.client.core.error.DocumentNotLockedException; +import com.couchbase.client.core.error.DocumentUnretrievableException; +import com.couchbase.client.core.error.DurableWriteInProgressException; +import com.couchbase.client.core.error.DurableWriteReCommitInProgressException; +import com.couchbase.client.core.error.FeatureNotAvailableException; +import com.couchbase.client.core.error.InvalidArgumentException; +import com.couchbase.client.core.error.RequestCanceledException; +import com.couchbase.client.core.error.ScopeNotFoundException; +import com.couchbase.client.core.error.ServerOutOfMemoryException; +import com.couchbase.client.core.error.ServiceNotAvailableException; +import com.couchbase.client.core.error.TemporaryFailureException; +import com.couchbase.client.core.error.ValueTooLargeException; +import com.couchbase.client.core.error.subdoc.PathExistsException; +import com.couchbase.client.core.error.subdoc.PathNotFoundException; +import com.couchbase.client.java.Collection; +import com.couchbase.client.java.codec.RawBinaryTranscoder; +import com.couchbase.client.java.codec.RawJsonTranscoder; +import com.couchbase.client.java.codec.Transcoder; +import com.couchbase.client.java.kv.GetOptions; +import com.couchbase.client.java.kv.GetResult; +import com.couchbase.client.java.kv.MutationResult; +import com.couchbase.client.java.kv.PersistTo; +import com.couchbase.client.java.kv.ReplicateTo; +import com.couchbase.client.java.kv.UpsertOptions; +import org.apache.nifi.services.couchbase.exception.CouchbaseErrorHandler; +import org.apache.nifi.services.couchbase.exception.CouchbaseException; +import org.apache.nifi.services.couchbase.utils.CouchbaseGetResult; +import org.apache.nifi.services.couchbase.utils.CouchbaseUpsertResult; +import org.apache.nifi.services.couchbase.utils.DocumentType; +import org.apache.nifi.services.couchbase.utils.JsonValidator; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Predicate; + +import static java.util.Map.entry; +import static org.apache.nifi.services.couchbase.exception.CouchbaseErrorHandler.ErrorHandlingStrategy.FAILURE; +import static org.apache.nifi.services.couchbase.exception.CouchbaseErrorHandler.ErrorHandlingStrategy.RETRY; +import static org.apache.nifi.services.couchbase.exception.CouchbaseErrorHandler.ErrorHandlingStrategy.ROLLBACK; + +class StandardCouchbaseClient implements CouchbaseClient { + + private final Collection collection; + private final DocumentType documentType; + private final PersistTo persistTo; + private final ReplicateTo replicateTo; + + StandardCouchbaseClient(Collection collection, DocumentType documentType, PersistTo persistTo, ReplicateTo replicateTo) { + this.collection = collection; + this.documentType = documentType; + this.persistTo = persistTo; + this.replicateTo = replicateTo; + } + + @Override + public CouchbaseGetResult getDocument(String documentId) throws CouchbaseException { + try { + final GetResult result = collection.get(documentId, GetOptions.getOptions().transcoder(getTranscoder(documentType))); + + return new CouchbaseGetResult(result.contentAsBytes(), result.cas()); + } catch (Exception e) { + throw new CouchbaseException("An error occurred while getting the document from Couchbase", e); + } + } + + @Override + public CouchbaseUpsertResult upsertDocument(String documentId, byte[] content) throws CouchbaseException { + try { + if (!getInputValidator(documentType).test(content)) { + throw new CouchbaseException("The provided input is invalid"); + } + + final MutationResult result = collection.upsert(documentId, content, + UpsertOptions.upsertOptions() + .durability(persistTo, replicateTo) + .transcoder(getTranscoder(documentType)) + .clientContext(new HashMap<>())); + + return new CouchbaseUpsertResult(result.cas()); + } catch (Exception e) { + throw new CouchbaseException("An error occurred while upserting the document in Couchbase", e); Review Comment: ```suggestion throw new CouchbaseException("Failed to upsert document [%s] in Couchbase".formatted(documentId), e); ``` ########## nifi-extension-bundles/nifi-couchbase-bundle/nifi-couchbase-standard-services/src/main/java/org/apache/nifi/services/couchbase/StandardCouchbaseClient.java: ########## @@ -0,0 +1,162 @@ +/* + * 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.services.couchbase; + +import com.couchbase.client.core.error.AuthenticationFailureException; +import com.couchbase.client.core.error.BucketNotFoundException; +import com.couchbase.client.core.error.CasMismatchException; +import com.couchbase.client.core.error.CollectionNotFoundException; +import com.couchbase.client.core.error.ConfigException; +import com.couchbase.client.core.error.DatasetNotFoundException; +import com.couchbase.client.core.error.DecodingFailureException; +import com.couchbase.client.core.error.DocumentExistsException; +import com.couchbase.client.core.error.DocumentLockedException; +import com.couchbase.client.core.error.DocumentMutationLostException; +import com.couchbase.client.core.error.DocumentNotFoundException; +import com.couchbase.client.core.error.DocumentNotLockedException; +import com.couchbase.client.core.error.DocumentUnretrievableException; +import com.couchbase.client.core.error.DurableWriteInProgressException; +import com.couchbase.client.core.error.DurableWriteReCommitInProgressException; +import com.couchbase.client.core.error.FeatureNotAvailableException; +import com.couchbase.client.core.error.InvalidArgumentException; +import com.couchbase.client.core.error.RequestCanceledException; +import com.couchbase.client.core.error.ScopeNotFoundException; +import com.couchbase.client.core.error.ServerOutOfMemoryException; +import com.couchbase.client.core.error.ServiceNotAvailableException; +import com.couchbase.client.core.error.TemporaryFailureException; +import com.couchbase.client.core.error.ValueTooLargeException; +import com.couchbase.client.core.error.subdoc.PathExistsException; +import com.couchbase.client.core.error.subdoc.PathNotFoundException; +import com.couchbase.client.java.Collection; +import com.couchbase.client.java.codec.RawBinaryTranscoder; +import com.couchbase.client.java.codec.RawJsonTranscoder; +import com.couchbase.client.java.codec.Transcoder; +import com.couchbase.client.java.kv.GetOptions; +import com.couchbase.client.java.kv.GetResult; +import com.couchbase.client.java.kv.MutationResult; +import com.couchbase.client.java.kv.PersistTo; +import com.couchbase.client.java.kv.ReplicateTo; +import com.couchbase.client.java.kv.UpsertOptions; +import org.apache.nifi.services.couchbase.exception.CouchbaseErrorHandler; +import org.apache.nifi.services.couchbase.exception.CouchbaseException; +import org.apache.nifi.services.couchbase.utils.CouchbaseGetResult; +import org.apache.nifi.services.couchbase.utils.CouchbaseUpsertResult; +import org.apache.nifi.services.couchbase.utils.DocumentType; +import org.apache.nifi.services.couchbase.utils.JsonValidator; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Predicate; + +import static java.util.Map.entry; +import static org.apache.nifi.services.couchbase.exception.CouchbaseErrorHandler.ErrorHandlingStrategy.FAILURE; +import static org.apache.nifi.services.couchbase.exception.CouchbaseErrorHandler.ErrorHandlingStrategy.RETRY; +import static org.apache.nifi.services.couchbase.exception.CouchbaseErrorHandler.ErrorHandlingStrategy.ROLLBACK; + +class StandardCouchbaseClient implements CouchbaseClient { + + private final Collection collection; + private final DocumentType documentType; + private final PersistTo persistTo; + private final ReplicateTo replicateTo; + + StandardCouchbaseClient(Collection collection, DocumentType documentType, PersistTo persistTo, ReplicateTo replicateTo) { + this.collection = collection; + this.documentType = documentType; + this.persistTo = persistTo; + this.replicateTo = replicateTo; + } + + @Override + public CouchbaseGetResult getDocument(String documentId) throws CouchbaseException { + try { + final GetResult result = collection.get(documentId, GetOptions.getOptions().transcoder(getTranscoder(documentType))); + + return new CouchbaseGetResult(result.contentAsBytes(), result.cas()); + } catch (Exception e) { + throw new CouchbaseException("An error occurred while getting the document from Couchbase", e); Review Comment: Recommend including the `documentId` in the message ```suggestion throw new CouchbaseException("Failed to get document [%s] from Couchbase".formatted(documentId), e); ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
