DenisIstomin commented on a change in pull request #3897:
URL: https://github.com/apache/camel/pull/3897#discussion_r463689546
##########
File path:
catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/minio-component.adoc
##########
@@ -0,0 +1,162 @@
+[[minio-component]]
Review comment:
Contend is not updated from original `adoc` file.
##########
File path:
components/camel-minio/src/main/java/org/apache/camel/component/minio/MinioEndpoint.java
##########
@@ -0,0 +1,294 @@
+/*
+ * 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.camel.component.minio;
+
+import java.io.*;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+
+import io.minio.BucketExistsArgs;
+import io.minio.MakeBucketArgs;
+import io.minio.MinioClient;
+import io.minio.ObjectStat;
+import io.minio.SetBucketPolicyArgs;
+import io.minio.StatObjectArgs;
+import io.minio.errors.InvalidBucketNameException;
+import org.apache.camel.Category;
+import org.apache.camel.Component;
+import org.apache.camel.Consumer;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.ExtendedExchange;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.component.minio.client.MinioClientFactory;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.spi.UriPath;
+import org.apache.camel.support.ScheduledPollEndpoint;
+import org.apache.camel.support.SynchronizationAdapter;
+import org.apache.camel.util.IOHelper;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Store and retrieve objects from Minio Storage Service using Minio SDK.
+ */
+@UriEndpoint(firstVersion = "3.5.0", scheme = "minio", title = "Minio Storage
Service", syntax = "minio://bucketName",
+ category = {Category.CLOUD, Category.FILE})
+
+public class MinioEndpoint extends ScheduledPollEndpoint {
+
+ private static final Logger LOG =
LoggerFactory.getLogger(MinioEndpoint.class);
+
+ private MinioClient minioClient;
+
+ @UriPath(description = "Bucket name")
+ @Metadata(required = true)
+ private String bucketName; // to support component docs
+ @UriParam
+ private MinioConfiguration configuration;
+ @UriParam(label = "consumer", defaultValue = "10")
+ private int maxMessagesPerPoll = 10;
+ @UriParam(label = "consumer", defaultValue = "60")
+ private int maxConnections = 50 + maxMessagesPerPoll;
+
+ public MinioEndpoint(String uri, Component component, MinioConfiguration
configuration) {
+ super(uri, component);
+ this.configuration = configuration;
+ }
+
+ @Override
+ public Consumer createConsumer(Processor processor) throws Exception {
+ MinioConsumer minioConsumer = new MinioConsumer(this, processor);
+ configureConsumer(minioConsumer);
+ minioConsumer.setMaxMessagesPerPoll(maxMessagesPerPoll);
+ return minioConsumer;
+ }
+
+ @Override
+ public Producer createProducer() {
+ return new MinioProducer(this);
+ }
+
+ @Override
+ public void doStart() throws Exception {
+ super.doStart();
+
+ minioClient = getConfiguration().getMinioClient() != null
+ ? getConfiguration().getMinioClient()
+ :
MinioClientFactory.getClient(getConfiguration()).getMinioClient();
+
+ String objectName = getConfiguration().getObjectName();
+
+ if (objectName != null) {
+ LOG.trace("Object name {} requested, so skipping bucket check...",
objectName);
+ return;
+ }
+
+ String bucketName = getConfiguration().getBucketName();
+ LOG.trace("Querying whether bucket {} already exists...", bucketName);
+
+ if (bucketExists(bucketName)) {
+ LOG.trace("Bucket {} already exists", bucketName);
+ } else {
+ if (!getConfiguration().isAutoCreateBucket()) {
+ throw new InvalidBucketNameException("Bucket {} does not
exists, set autoCreateBucket option for bucket auto creation", bucketName);
+ } else {
+ LOG.trace("AutoCreateBucket set to true, Creating bucket
{}...", bucketName);
+ makeBucket(bucketName);
+ LOG.trace("Bucket created");
+ }
+ }
+
+ if (getConfiguration().getPolicy() != null) {
+ setBucketPolicy(bucketName);
+ }
+ }
+
+ @Override
+ public void doStop() throws Exception {
+ if (ObjectHelper.isEmpty(getConfiguration().getMinioClient())) {
+ if (minioClient != null) {
+ minioClient = null;
+ }
+ }
+ super.doStop();
+ }
+
+ public Exchange createExchange(InputStream minioObject, String objectName)
throws Exception {
+ return createExchange(getExchangePattern(), minioObject, objectName);
+ }
+
+ public Exchange createExchange(ExchangePattern pattern,
+ InputStream minioObject, String objectName)
throws Exception {
+ LOG.trace("Getting object with objectName {} from bucket {}...",
objectName, getConfiguration().getBucketName());
+
+ Exchange exchange = super.createExchange(pattern);
+ Message message = exchange.getIn();
+ LOG.trace("Got object!");
+
+ getObjectStat(objectName, message);
+
+ if (getConfiguration().isIncludeBody()) {
+ try {
+ message.setBody(readInputStream(minioObject));
+ if (getConfiguration().isAutocloseBody()) {
+ exchange.adapt(ExtendedExchange.class).addOnCompletion(new
SynchronizationAdapter() {
+ @Override
+ public void onDone(Exchange exchange) {
+ IOHelper.close(minioObject);
+ }
+ });
+ }
+
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ } else {
+ message.setBody(null);
+ IOHelper.close(minioObject);
+ }
+
+ return exchange;
+ }
+
+ public MinioConfiguration getConfiguration() {
+ return configuration;
+ }
+
+ public void setConfiguration(MinioConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
+ public MinioClient getMinioClient() {
+ return minioClient;
+ }
+
+ public void setMinioClient(MinioClient minioClient) {
+ this.minioClient = minioClient;
+ }
+
+ public int getMaxMessagesPerPoll() {
+ return maxMessagesPerPoll;
+ }
+
+ /**
+ * Gets the maximum number of messages as a limit to poll at each polling.
+ * <p/>
+ * Gets the maximum number of messages as a limit to poll at each polling.
+ * The default value is 10. Use 0 or a negative number to set it as
+ * unlimited.
+ */
+ public void setMaxMessagesPerPoll(int maxMessagesPerPoll) {
+ this.maxMessagesPerPoll = maxMessagesPerPoll;
+ }
+
+ public int getMaxConnections() {
+ return maxConnections;
+ }
+
+ /**
+ * Set the maxConnections parameter in the minio client configuration
+ */
+ public void setMaxConnections(int maxConnections) {
+ this.maxConnections = maxConnections;
+ }
+
+ private String readInputStream(InputStream minioObject) throws IOException
{
+ StringBuilder textBuilder = new StringBuilder();
+ try (Reader reader = new BufferedReader(new
InputStreamReader(minioObject,
Charset.forName(StandardCharsets.UTF_8.name())))) {
Review comment:
Looks like it could be simplified:
```
Reader reader = new BufferedReader(new InputStreamReader(minioObject,
StandardCharsets.UTF_8));
```
##########
File path:
components/camel-minio/src/main/java/org/apache/camel/component/minio/MinioComponentVerifierExtension.java
##########
@@ -0,0 +1,98 @@
+/*
+ * 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.camel.component.minio;
+
+import java.util.Map;
+
+import io.minio.MinioClient;
+import io.minio.errors.MinioException;
+import
org.apache.camel.component.extension.verifier.DefaultComponentVerifierExtension;
+import org.apache.camel.component.extension.verifier.ResultBuilder;
+import org.apache.camel.component.extension.verifier.ResultErrorBuilder;
+import org.apache.camel.component.extension.verifier.ResultErrorHelper;
+
+public class MinioComponentVerifierExtension extends
DefaultComponentVerifierExtension {
+
+ public MinioComponentVerifierExtension() {
+ this("minio");
+ }
+
+ public MinioComponentVerifierExtension(String scheme) {
+ super(scheme);
+ }
+
+ // *********************************
+ // Parameters validation
+ // *********************************
+
+ @Override
Review comment:
And the same below
##########
File path:
components/camel-minio/src/main/java/org/apache/camel/component/minio/MinioComponentVerifierExtension.java
##########
@@ -0,0 +1,98 @@
+/*
+ * 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.camel.component.minio;
+
+import java.util.Map;
+
+import io.minio.MinioClient;
+import io.minio.errors.MinioException;
+import
org.apache.camel.component.extension.verifier.DefaultComponentVerifierExtension;
+import org.apache.camel.component.extension.verifier.ResultBuilder;
+import org.apache.camel.component.extension.verifier.ResultErrorBuilder;
+import org.apache.camel.component.extension.verifier.ResultErrorHelper;
+
+public class MinioComponentVerifierExtension extends
DefaultComponentVerifierExtension {
+
+ public MinioComponentVerifierExtension() {
+ this("minio");
+ }
+
+ public MinioComponentVerifierExtension(String scheme) {
+ super(scheme);
+ }
+
+ // *********************************
+ // Parameters validation
+ // *********************************
+
+ @Override
Review comment:
I would suggest to reformat it like this:
```
@Override
protected Result verifyParameters(Map<String, Object> parameters) {
ResultBuilder builder =
ResultBuilder.withStatusAndScope(Result.Status.OK, Scope.PARAMETERS)
.error(ResultErrorHelper.requiresOption("accessKey", parameters))
.error(ResultErrorHelper.requiresOption("secretKey", parameters))
.error(ResultErrorHelper.requiresOption("region", parameters));
// Validate using the catalog
super.verifyParametersAgainstCatalog(builder, parameters);
return builder.build();
}
```
##########
File path:
components/camel-minio/src/test/java/org/apache/camel/component/minio/integration/MinioConsumerIntegrationTest.java
##########
@@ -0,0 +1,83 @@
+/*
+ * 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.camel.component.minio.integration;
+
+import io.minio.MinioClient;
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.minio.MinioConstants;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+@Disabled("Must be manually tested. Provide your own accessKey and secretKey!")
+public class MinioConsumerIntegrationTest extends CamelTestSupport {
+
+ @BindToRegistry("minioClient")
+ MinioClient client = MinioClient.builder()
+ .endpoint("https://play.min.io")
+ .credentials("Q3AM3UQ867SPQQA43P2F",
"zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
Review comment:
It would be nice to extract all credentials into `.properties` file
##########
File path:
components/camel-minio/src/main/java/org/apache/camel/component/minio/MinioEndpoint.java
##########
@@ -0,0 +1,294 @@
+/*
+ * 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.camel.component.minio;
+
+import java.io.*;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+
+import io.minio.BucketExistsArgs;
+import io.minio.MakeBucketArgs;
+import io.minio.MinioClient;
+import io.minio.ObjectStat;
+import io.minio.SetBucketPolicyArgs;
+import io.minio.StatObjectArgs;
+import io.minio.errors.InvalidBucketNameException;
+import org.apache.camel.Category;
+import org.apache.camel.Component;
+import org.apache.camel.Consumer;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.ExtendedExchange;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.component.minio.client.MinioClientFactory;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.spi.UriPath;
+import org.apache.camel.support.ScheduledPollEndpoint;
+import org.apache.camel.support.SynchronizationAdapter;
+import org.apache.camel.util.IOHelper;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Store and retrieve objects from Minio Storage Service using Minio SDK.
+ */
+@UriEndpoint(firstVersion = "3.5.0", scheme = "minio", title = "Minio Storage
Service", syntax = "minio://bucketName",
+ category = {Category.CLOUD, Category.FILE})
+
+public class MinioEndpoint extends ScheduledPollEndpoint {
+
+ private static final Logger LOG =
LoggerFactory.getLogger(MinioEndpoint.class);
+
+ private MinioClient minioClient;
+
+ @UriPath(description = "Bucket name")
+ @Metadata(required = true)
+ private String bucketName; // to support component docs
Review comment:
This is TODO comment?
##########
File path:
components/camel-minio/src/test/java/org/apache/camel/component/minio/integration/MinioConsumerIntegrationTest.java
##########
@@ -0,0 +1,83 @@
+/*
+ * 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.camel.component.minio.integration;
+
+import io.minio.MinioClient;
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.minio.MinioConstants;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+@Disabled("Must be manually tested. Provide your own accessKey and secretKey!")
+public class MinioConsumerIntegrationTest extends CamelTestSupport {
+
+ @BindToRegistry("minioClient")
+ MinioClient client = MinioClient.builder()
+ .endpoint("https://play.min.io")
+ .credentials("Q3AM3UQ867SPQQA43P2F",
"zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
+ .region("us-west-1")
+ .build();
+
+ @EndpointInject
+ private ProducerTemplate template;
+
+ @EndpointInject("mock:result")
+ private MockEndpoint result;
+
+ @Test
+ public void sendIn() throws Exception {
+ result.expectedMessageCount(3);
+
+ template.send("direct:putObject", exchange -> {
+ exchange.getIn().setHeader(MinioConstants.OBJECT_NAME,
"test1.txt");
+ exchange.getIn().setBody("Test1");
+ });
+
+ template.send("direct:putObject", exchange -> {
+ exchange.getIn().setHeader(MinioConstants.OBJECT_NAME,
"test2.txt");
+ exchange.getIn().setBody("Test2");
+ });
+
+ template.send("direct:putObject", exchange -> {
+ exchange.getIn().setHeader(MinioConstants.OBJECT_NAME,
"test3.txt");
+ exchange.getIn().setBody("Test3");
+ });
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ String minioEndpoint =
"minio://mycamel?autoCreateBucket=false";
+
+
from("direct:putObject").startupOrder(1).to(minioEndpoint).to("mock:result");
+
+ // TODO: Check why this is not working
Review comment:
Please resolve this TODO
##########
File path:
components/camel-minio/src/test/java/org/apache/camel/component/minio/integration/MinioComponentIntegrationTest.java
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.camel.component.minio.integration;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.Message;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.minio.MinioConstants;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
Review comment:
Please avoid `star import` usage.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]