From a7048ce7aa0d3772ad4b641ef391b10fcdfcb6b5 Mon Sep 17 00:00:00 2001 From: "Bala.FA" Date: Thu, 14 May 2020 12:40:23 +0530 Subject: [PATCH] add arg builder to {set,get,delete}BucketNotification APIs --- .../minio/DeleteBucketNotificationArgs.java | 28 +++ .../io/minio/GetBucketNotificationArgs.java | 28 +++ api/src/main/java/io/minio/MinioClient.java | 132 ++++++++++- .../io/minio/SetBucketNotificationArgs.java | 52 ++++ .../main/java/io/minio/messages/Filter.java | 7 +- .../NotificationCommonConfiguration.java | 20 +- .../messages/NotificationConfiguration.java | 12 +- docs/API.md | 120 +++++----- ...ion.java => DeleteBucketNotification.java} | 6 +- examples/GetBucketNotification.java | 8 +- examples/SetBucketNotification.java | 13 +- functional/FunctionalTest.java | 223 ++++++++---------- 12 files changed, 424 insertions(+), 225 deletions(-) create mode 100644 api/src/main/java/io/minio/DeleteBucketNotificationArgs.java create mode 100644 api/src/main/java/io/minio/GetBucketNotificationArgs.java create mode 100644 api/src/main/java/io/minio/SetBucketNotificationArgs.java rename examples/{RemoveAllBucketNotification.java => DeleteBucketNotification.java} (88%) diff --git a/api/src/main/java/io/minio/DeleteBucketNotificationArgs.java b/api/src/main/java/io/minio/DeleteBucketNotificationArgs.java new file mode 100644 index 000000000..e34c43893 --- /dev/null +++ b/api/src/main/java/io/minio/DeleteBucketNotificationArgs.java @@ -0,0 +1,28 @@ +/* + * MinIO Java SDK for Amazon S3 Compatible Cloud Storage, (C) 2020 MinIO, Inc. + * + * Licensed 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 io.minio; + +/** Argument class of MinioClient.deleteBucketNotification(). */ +public class DeleteBucketNotificationArgs extends BucketArgs { + public static Builder builder() { + return new Builder(); + } + + /** Argument builder of {@link DeleteBucketNotificationArgs}. */ + public static final class Builder + extends BucketArgs.Builder {} +} diff --git a/api/src/main/java/io/minio/GetBucketNotificationArgs.java b/api/src/main/java/io/minio/GetBucketNotificationArgs.java new file mode 100644 index 000000000..d7a783a77 --- /dev/null +++ b/api/src/main/java/io/minio/GetBucketNotificationArgs.java @@ -0,0 +1,28 @@ +/* + * MinIO Java SDK for Amazon S3 Compatible Cloud Storage, (C) 2020 MinIO, Inc. + * + * Licensed 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 io.minio; + +/** Argument class of MinioClient.getBucketNotification(). */ +public class GetBucketNotificationArgs extends BucketArgs { + public static Builder builder() { + return new Builder(); + } + + /** Argument builder of {@link GetBucketNotificationArgs}. */ + public static final class Builder + extends BucketArgs.Builder {} +} diff --git a/api/src/main/java/io/minio/MinioClient.java b/api/src/main/java/io/minio/MinioClient.java index 394dd8b71..07e0cb6d5 100755 --- a/api/src/main/java/io/minio/MinioClient.java +++ b/api/src/main/java/io/minio/MinioClient.java @@ -4961,15 +4961,49 @@ public String getBucketLifeCycle(GetBucketLifeCycleArgs args) * @throws IOException thrown to indicate I/O error on S3 operation. * @throws NoSuchAlgorithmException thrown to indicate missing of MD5 or SHA-256 digest library. * @throws XmlParserException thrown to indicate XML parsing error. + * @deprecated use {@link #getBucketNotification(GetBucketNotificationArgs)} */ + @Deprecated public NotificationConfiguration getBucketNotification(String bucketName) throws ErrorResponseException, IllegalArgumentException, InsufficientDataException, InternalException, InvalidBucketNameException, InvalidKeyException, InvalidResponseException, IOException, NoSuchAlgorithmException, XmlParserException { + return getBucketNotification(GetBucketNotificationArgs.builder().bucket(bucketName).build()); + } + + /** + * Gets notification configuration of a bucket. + * + *
Example:{@code
+   * NotificationConfiguration config =
+   *     minioClient.getBucketNotification(
+   *         GetBucketNotificationArgs.builder().bucket("my-bucketname").build());
+   * }
+ * + * @param args {@link GetBucketNotificationArgs} object. + * @return {@link NotificationConfiguration} - Notification configuration. + * @throws ErrorResponseException thrown to indicate S3 service returned an error response. + * @throws IllegalArgumentException throws to indicate invalid argument passed. + * @throws InsufficientDataException thrown to indicate not enough data available in InputStream. + * @throws InternalException thrown to indicate internal library error. + * @throws InvalidBucketNameException thrown to indicate invalid bucket name passed. + * @throws InvalidKeyException thrown to indicate missing of HMAC SHA-256 library. + * @throws InvalidResponseException thrown to indicate S3 service returned invalid or no error + * response. + * @throws IOException thrown to indicate I/O error on S3 operation. + * @throws NoSuchAlgorithmException thrown to indicate missing of MD5 or SHA-256 digest library. + * @throws XmlParserException thrown to indicate XML parsing error. + */ + public NotificationConfiguration getBucketNotification(GetBucketNotificationArgs args) + throws ErrorResponseException, IllegalArgumentException, InsufficientDataException, + InternalException, InvalidBucketNameException, InvalidKeyException, + InvalidResponseException, IOException, NoSuchAlgorithmException, XmlParserException { + checkArgs(args); + Map queryParamMap = new HashMap<>(); queryParamMap.put("notification", ""); - Response response = executeGet(bucketName, null, null, queryParamMap); + Response response = executeGet(args.bucket(), null, null, queryParamMap); try (ResponseBody body = response.body()) { return Xml.unmarshal(NotificationConfiguration.class, body.charStream()); } @@ -5011,17 +5045,68 @@ public NotificationConfiguration getBucketNotification(String bucketName) * @throws IOException thrown to indicate I/O error on S3 operation. * @throws NoSuchAlgorithmException thrown to indicate missing of MD5 or SHA-256 digest library. * @throws XmlParserException thrown to indicate XML parsing error. + * @deprecated use {@link #setBucketNotification(SetBucketNotificationArgs)} */ + @Deprecated public void setBucketNotification( String bucketName, NotificationConfiguration notificationConfiguration) throws ErrorResponseException, IllegalArgumentException, InsufficientDataException, InternalException, InvalidBucketNameException, InvalidKeyException, InvalidResponseException, IOException, NoSuchAlgorithmException, XmlParserException { + setBucketNotification( + SetBucketNotificationArgs.builder() + .bucket(bucketName) + .config(notificationConfiguration) + .build()); + } + + /** + * Sets notification configuration to a bucket. + * + *
Example:{@code
+   * List eventList = new LinkedList<>();
+   * eventList.add(EventType.OBJECT_CREATED_PUT);
+   * eventList.add(EventType.OBJECT_CREATED_COPY);
+   *
+   * QueueConfiguration queueConfiguration = new QueueConfiguration();
+   * queueConfiguration.setQueue("arn:minio:sqs::1:webhook");
+   * queueConfiguration.setEvents(eventList);
+   * queueConfiguration.setPrefixRule("images");
+   * queueConfiguration.setSuffixRule("pg");
+   *
+   * List queueConfigurationList = new LinkedList<>();
+   * queueConfigurationList.add(queueConfiguration);
+   *
+   * NotificationConfiguration config = new NotificationConfiguration();
+   * config.setQueueConfigurationList(queueConfigurationList);
+   *
+   * minioClient.setBucketNotification(
+   *     SetBucketNotificationArgs.builder().bucket("my-bucketname").config(config).build());
+   * }
+ * + * @param args {@link SetBucketNotificationArgs} object. + * @throws ErrorResponseException thrown to indicate S3 service returned an error response. + * @throws IllegalArgumentException throws to indicate invalid argument passed. + * @throws InsufficientDataException thrown to indicate not enough data available in InputStream. + * @throws InternalException thrown to indicate internal library error. + * @throws InvalidBucketNameException thrown to indicate invalid bucket name passed. + * @throws InvalidKeyException thrown to indicate missing of HMAC SHA-256 library. + * @throws InvalidResponseException thrown to indicate S3 service returned invalid or no error + * response. + * @throws IOException thrown to indicate I/O error on S3 operation. + * @throws NoSuchAlgorithmException thrown to indicate missing of MD5 or SHA-256 digest library. + * @throws XmlParserException thrown to indicate XML parsing error. + */ + public void setBucketNotification(SetBucketNotificationArgs args) + throws ErrorResponseException, IllegalArgumentException, InsufficientDataException, + InternalException, InvalidBucketNameException, InvalidKeyException, + InvalidResponseException, IOException, NoSuchAlgorithmException, XmlParserException { + checkArgs(args); + Map queryParamMap = new HashMap<>(); queryParamMap.put("notification", ""); - Response response = - executePut(bucketName, null, null, queryParamMap, notificationConfiguration, 0); - response.body().close(); + Response response = executePut(args.bucket(), null, null, queryParamMap, args.config(), 0); + response.close(); } /** @@ -5043,13 +5128,48 @@ public void setBucketNotification( * @throws IOException thrown to indicate I/O error on S3 operation. * @throws NoSuchAlgorithmException thrown to indicate missing of MD5 or SHA-256 digest library. * @throws XmlParserException thrown to indicate XML parsing error. + * @deprecated use {@link #deleteBucketNotification(DeleteBucketNotificationArgs)} */ + @Deprecated public void removeAllBucketNotification(String bucketName) throws ErrorResponseException, IllegalArgumentException, InsufficientDataException, InternalException, InvalidBucketNameException, InvalidKeyException, InvalidResponseException, IOException, NoSuchAlgorithmException, XmlParserException { - NotificationConfiguration notificationConfiguration = new NotificationConfiguration(); - setBucketNotification(bucketName, notificationConfiguration); + deleteBucketNotification(DeleteBucketNotificationArgs.builder().bucket(bucketName).build()); + } + + /** + * Deletes notification configuration of a bucket. + * + *
Example:{@code
+   * minioClient.deleteBucketNotification(
+   *     DeleteBucketNotificationArgs.builder().bucket("my-bucketname").build());
+   * }
+ * + * @param args {@link DeleteBucketNotificationArgs} object. + * @throws ErrorResponseException thrown to indicate S3 service returned an error response. + * @throws IllegalArgumentException throws to indicate invalid argument passed. + * @throws InsufficientDataException thrown to indicate not enough data available in InputStream. + * @throws InternalException thrown to indicate internal library error. + * @throws InvalidBucketNameException thrown to indicate invalid bucket name passed. + * @throws InvalidKeyException thrown to indicate missing of HMAC SHA-256 library. + * @throws InvalidResponseException thrown to indicate S3 service returned invalid or no error + * response. + * @throws IOException thrown to indicate I/O error on S3 operation. + * @throws NoSuchAlgorithmException thrown to indicate missing of MD5 or SHA-256 digest library. + * @throws XmlParserException thrown to indicate XML parsing error. + */ + public void deleteBucketNotification(DeleteBucketNotificationArgs args) + throws ErrorResponseException, IllegalArgumentException, InsufficientDataException, + InternalException, InvalidBucketNameException, InvalidKeyException, + InvalidResponseException, IOException, NoSuchAlgorithmException, XmlParserException { + checkArgs(args); + + setBucketNotification( + SetBucketNotificationArgs.builder() + .bucket(args.bucket()) + .config(new NotificationConfiguration()) + .build()); } /** diff --git a/api/src/main/java/io/minio/SetBucketNotificationArgs.java b/api/src/main/java/io/minio/SetBucketNotificationArgs.java new file mode 100644 index 000000000..730065677 --- /dev/null +++ b/api/src/main/java/io/minio/SetBucketNotificationArgs.java @@ -0,0 +1,52 @@ +/* + * MinIO Java SDK for Amazon S3 Compatible Cloud Storage, (C) 2020 MinIO, Inc. + * + * Licensed 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 io.minio; + +import io.minio.messages.NotificationConfiguration; + +/** Argument class of MinioClient.setBucketNotification(). */ +public class SetBucketNotificationArgs extends BucketArgs { + private NotificationConfiguration config; + + public NotificationConfiguration config() { + return config; + } + + public static Builder builder() { + return new Builder(); + } + + /** Argument builder of {@link SetBucketNotificationArgs}. */ + public static final class Builder extends BucketArgs.Builder { + private void validateConfig(NotificationConfiguration config) { + if (config == null) { + throw new IllegalArgumentException("null notification configuration"); + } + } + + protected void validate(SetBucketNotificationArgs args) { + super.validate(args); + validateConfig(args.config); + } + + public Builder config(NotificationConfiguration config) { + validateConfig(config); + operations.add(args -> args.config = config); + return this; + } + } +} diff --git a/api/src/main/java/io/minio/messages/Filter.java b/api/src/main/java/io/minio/messages/Filter.java index 803a2744f..cbcbf9e5b 100644 --- a/api/src/main/java/io/minio/messages/Filter.java +++ b/api/src/main/java/io/minio/messages/Filter.java @@ -67,10 +67,7 @@ public void setSuffixRule(String value) throws IllegalArgumentException { } public List filterRuleList() { - if (filterRuleList == null) { - return null; - } - - return Collections.unmodifiableList(filterRuleList); + return Collections.unmodifiableList( + filterRuleList == null ? new LinkedList<>() : filterRuleList); } } diff --git a/api/src/main/java/io/minio/messages/NotificationCommonConfiguration.java b/api/src/main/java/io/minio/messages/NotificationCommonConfiguration.java index 9ad088429..3466109c3 100644 --- a/api/src/main/java/io/minio/messages/NotificationCommonConfiguration.java +++ b/api/src/main/java/io/minio/messages/NotificationCommonConfiguration.java @@ -17,6 +17,7 @@ package io.minio.messages; import java.util.Collections; +import java.util.LinkedList; import java.util.List; import org.simpleframework.xml.Element; import org.simpleframework.xml.ElementList; @@ -25,14 +26,14 @@ * Helper class to denote common fields of {@link CloudFunctionConfiguration}, {@link * QueueConfiguration} and {@link TopicConfiguration}. */ -public class NotificationCommonConfiguration { +public abstract class NotificationCommonConfiguration { @Element(name = "Id", required = false) private String id; - @ElementList(name = "Event", inline = true, required = false) + @ElementList(name = "Event", inline = true) private List events; - @Element(name = "Filter") + @Element(name = "Filter", required = false) private Filter filter; public NotificationCommonConfiguration() {} @@ -49,11 +50,7 @@ public void setId(String id) { /** Returns events. */ public List events() { - if (events == null) { - return null; - } - - return Collections.unmodifiableList(events); + return Collections.unmodifiableList(events == null ? new LinkedList<>() : events); } /** Sets event. */ @@ -81,10 +78,7 @@ public void setSuffixRule(String value) throws IllegalArgumentException { /** returns filter rule list. */ public List filterRuleList() { - if (filter == null) { - return null; - } - - return filter.filterRuleList(); + return Collections.unmodifiableList( + filter == null ? new LinkedList<>() : filter.filterRuleList()); } } diff --git a/api/src/main/java/io/minio/messages/NotificationConfiguration.java b/api/src/main/java/io/minio/messages/NotificationConfiguration.java index df2144bb7..616c67713 100644 --- a/api/src/main/java/io/minio/messages/NotificationConfiguration.java +++ b/api/src/main/java/io/minio/messages/NotificationConfiguration.java @@ -17,6 +17,7 @@ package io.minio.messages; import java.util.Collections; +import java.util.LinkedList; import java.util.List; import org.simpleframework.xml.ElementList; import org.simpleframework.xml.Namespace; @@ -45,7 +46,10 @@ public NotificationConfiguration() {} /** Returns cloud function configuration. */ public List cloudFunctionConfigurationList() { - return cloudFunctionConfigurationList; + return Collections.unmodifiableList( + cloudFunctionConfigurationList == null + ? new LinkedList<>() + : cloudFunctionConfigurationList); } /** Sets cloud function configuration list. */ @@ -57,7 +61,8 @@ public void setCloudFunctionConfigurationList( /** Returns queue configuration list. */ public List queueConfigurationList() { - return queueConfigurationList; + return Collections.unmodifiableList( + queueConfigurationList == null ? new LinkedList<>() : queueConfigurationList); } /** Sets queue configuration list. */ @@ -67,7 +72,8 @@ public void setQueueConfigurationList(List queueConfiguratio /** Returns topic configuration list. */ public List topicConfigurationList() { - return topicConfigurationList; + return Collections.unmodifiableList( + topicConfigurationList == null ? new LinkedList<>() : topicConfigurationList); } /** Sets topic configuration list. */ diff --git a/docs/API.md b/docs/API.md index a45515409..f5b2bb139 100644 --- a/docs/API.md +++ b/docs/API.md @@ -16,34 +16,34 @@ MinioClient s3Client = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY"); ``` -| Bucket operations | Object operations | -|---------------------------------------------------------------|---------------------------------------------------------| -| [`bucketExists`](#bucketExists) | [`composeObject`](#composeObject) | -| [`deleteBucketEncryption`](#deleteBucketEncryption) | [`copyObject`](#copyObject) | -| [`deleteBucketLifeCycle`](#deleteBucketLifeCycle) | [`deleteObjectTags`](#deleteObjectTags) | -| [`deleteBucketPolicy`](#deleteBucketPolicy) | [`disableObjectLegalHold`](#disableObjectLegalHold) | -| [`deleteBucketTags`](#deleteBucketTags) | [`downloadObject`](#downloadObject) | -| [`disableVersioning`](#disableVersioning) | [`enableObjectLegalHold`](#enableObjectLegalHold) | -| [`enableVersioning`](#enableVersioning) | [`getObject`](#getObject) | -| [`getBucketEncryption`](#getBucketEncryption) | [`getObjectRetention`](#getObjectRetention) | -| [`getBucketLifeCycle`](#getBucketLifeCycle) | [`getObjectTags`](#getObjectTags) | -| [`getBucketNotification`](#getBucketNotification) | [`getObjectUrl`](#getObjectUrl) | -| [`getBucketPolicy`](#getBucketPolicy) | [`getPresignedObjectUrl`](#getPresignedObjectUrl) | -| [`getBucketTags`](#getBucketTags) | [`isObjectLegalHoldEnabled`](#isObjectLegalHoldEnabled) | -| [`getDefaultRetention`](#getDefaultRetention) | [`listObjects`](#listObjects) | -| [`listBuckets`](#listBuckets) | [`presignedGetObject`](#presignedGetObject) | -| [`listenBucketNotification`](#listenBucketNotification) | [`presignedPostPolicy`](#presignedPostPolicy) | -| [`listIncompleteUploads`](#listIncompleteUploads) | [`presignedPutObject`](#presignedPutObject) | -| [`makeBucket`](#makeBucket) | [`putObject`](#putObject) | -| [`removeAllBucketNotification`](#removeAllBucketNotification) | [`removeObject`](#removeObject) | -| [`removeBucket`](#removeBucket) | [`removeObjects`](#removeObjects) | -| [`removeIncompleteUpload`](#removeIncompleteUpload) | [`selectObjectContent`](#selectObjectContent) | -| [`setBucketEncryption`](#setBucketEncryption) | [`setObjectRetention`](#setObjectRetention) | -| [`setBucketLifeCycle`](#setBucketLifeCycle) | [`setObjectTags`](#setObjectTags) | -| [`setBucketNotification`](#setBucketNotification) | [`statObject`](#statObject) | -| [`setBucketPolicy`](#setBucketPolicy) | | -| [`setBucketTags`](#setBucketTags) | | -| [`setDefaultRetention`](#setDefaultRetention) | | +| Bucket operations | Object operations | +|---------------------------------------------------------|---------------------------------------------------------| +| [`bucketExists`](#bucketExists) | [`composeObject`](#composeObject) | +| [`deleteBucketEncryption`](#deleteBucketEncryption) | [`copyObject`](#copyObject) | +| [`deleteBucketLifeCycle`](#deleteBucketLifeCycle) | [`deleteObjectTags`](#deleteObjectTags) | +| [`deleteBucketNotification`](#deleteBucketNotification) | [`disableObjectLegalHold`](#disableObjectLegalHold) | +| [`deleteBucketPolicy`](#deleteBucketPolicy) | [`downloadObject`](#downloadObject) | +| [`deleteBucketTags`](#deleteBucketTags) | [`enableObjectLegalHold`](#enableObjectLegalHold) | +| [`disableVersioning`](#disableVersioning) | [`getObject`](#getObject) | +| [`enableVersioning`](#enableVersioning) | [`getObjectRetention`](#getObjectRetention) | +| [`getBucketEncryption`](#getBucketEncryption) | [`getObjectTags`](#getObjectTags) | +| [`getBucketLifeCycle`](#getBucketLifeCycle) | [`getObjectUrl`](#getObjectUrl) | +| [`getBucketNotification`](#getBucketNotification) | [`getPresignedObjectUrl`](#getPresignedObjectUrl) | +| [`getBucketPolicy`](#getBucketPolicy) | [`isObjectLegalHoldEnabled`](#isObjectLegalHoldEnabled) | +| [`getBucketTags`](#getBucketTags) | [`listObjects`](#listObjects) | +| [`getDefaultRetention`](#getDefaultRetention) | [`presignedGetObject`](#presignedGetObject) | +| [`listBuckets`](#listBuckets) | [`presignedPostPolicy`](#presignedPostPolicy) | +| [`listenBucketNotification`](#listenBucketNotification) | [`presignedPutObject`](#presignedPutObject) | +| [`listIncompleteUploads`](#listIncompleteUploads) | [`putObject`](#putObject) | +| [`makeBucket`](#makeBucket) | [`removeObject`](#removeObject) | +| [`removeBucket`](#removeBucket) | [`removeObjects`](#removeObjects) | +| [`removeIncompleteUpload`](#removeIncompleteUpload) | [`selectObjectContent`](#selectObjectContent) | +| [`setBucketEncryption`](#setBucketEncryption) | [`setObjectRetention`](#setObjectRetention) | +| [`setBucketLifeCycle`](#setBucketLifeCycle) | [`setObjectTags`](#setObjectTags) | +| [`setBucketNotification`](#setBucketNotification) | [`statObject`](#statObject) | +| [`setBucketPolicy`](#setBucketPolicy) | | +| [`setBucketTags`](#setBucketTags) | | +| [`setDefaultRetention`](#setDefaultRetention) | | ## 1. Constructors | | @@ -354,6 +354,23 @@ __Example__ minioClient.deleteBucketPolicy(DeleteBucketPolicyArgs.builder().bucket("my-bucketname").build()); ``` + +### deleteBucketNotification(DeleteBucketNotificationArgs args) +`public void deleteBucketNotification(DeleteBucketNotificationArgs args)` _[[Javadoc]](http://minio.github.io/minio-java/io/minio/MinioClient.html#deleteBucketNotification-io.minio.DeleteBucketNotificationArgs-)_ + +Deletes notification configuration of a bucket. + +__Parameters__ +| Parameter | Type | Description | +|:----------|:---------------------------------|:------------| +| ``args`` | _[DeleteBucketNotificationArgs]_ | Arguments. | + +__Example__ +```java +minioClient.deleteBucketNotification( + DeleteBucketNotificationArgs.builder().bucket("my-bucketname").build()); +``` + ### disableVersioning(DisableVersioningArgs args) `public void disableVersioning(DisableVersioningArgs args)` _[[Javadoc]](http://minio.github.io/minio-java/io/minio/MinioClient.html#disableVersioning-io.minio.DisableVersioningArgs-)_ @@ -434,15 +451,15 @@ System.out.println("Life cycle settings: " + lifecycle); ``` -### getBucketNotification(String bucketName) -`public NotificationConfiguration getBucketNotification(String bucketName)` _[[Javadoc]](http://minio.github.io/minio-java/io/minio/MinioClient.html#getBucketNotification-java.lang.String-)_ +### getBucketNotification(GetBucketNotificationArgs args) +`public NotificationConfiguration getBucketNotification(GetBucketNotificationArgs args)` _[[Javadoc]](http://minio.github.io/minio-java/io/minio/MinioClient.html#getBucketNotification-io.minio.GetBucketNotificationArgs-)_ Gets notification configuration of a bucket. __Parameters__ -| Parameter | Type | Description | -|:---------------|:---------|:--------------------| -| ``bucketName`` | _String_ | Name of the bucket. | +| Parameter | Type | Description | +|:----------|:------------------------------|:------------| +| ``args`` | _[GetBucketNotificationArgs]_ | Arguments. | | Returns | |:------------------------------------------------------------| @@ -450,7 +467,9 @@ __Parameters__ __Example__ ```java -NotificationConfiguration config = minioClient.getBucketNotification("my-bucketname"); +NotificationConfiguration config = + minioClient.getBucketNotification( + GetBucketNotificationArgs.builder().bucket("my-bucketname").build()); ``` @@ -715,22 +734,6 @@ minioClient.makeBucket( .build()); ``` - -### removeAllBucketNotification(String bucketName) -`public void removeAllBucketNotification(String bucketName)` _[[Javadoc]](http://minio.github.io/minio-java/io/minio/MinioClient.html#removeAllBucketNotification-java.lang.String-)_ - -Removes notification configuration of a bucket. - -__Parameters__ -| Parameter | Type | Description | -|:---------------|:---------|:--------------------| -| ``bucketName`` | _String_ | Name of the bucket. | - -__Example__ -```java -minioClient.removeAllBucketNotification("my-bucketname"); -``` - ### removeBucket(RemoveBucketArgs args) `public void removeBucket(RemoveBucketArgs args)` _[[Javadoc]](http://minio.github.io/minio-java/io/minio/MinioClient.html#removeBucket-io.minio.RemoveBucketArgs-)_ @@ -812,17 +815,16 @@ minioClient.setBucketLifecycle( ``` -### setBucketNotification(String bucketName, NotificationConfiguration notificationConfiguration) -`public void setBucketNotification(String bucketName, NotificationConfiguration notificationConfiguration)` _[[Javadoc]](http://minio.github.io/minio-java/io/minio/MinioClient.html#setBucketNotification-java.lang.String-io.minio.messages.NotificationConfiguration-)_ +### setBucketNotification(SetBucketNotificationArgs args) +`public void setBucketNotification(SetBucketNotificationArgs args)` _[[Javadoc]](http://minio.github.io/minio-java/io/minio/MinioClient.html#setBucketNotification-io.minio.SetBucketNotificationArgs-)_ Sets notification configuration to a bucket. __Parameters__ -| Parameter | Type | Description | -|:------------------------------|:------------------------------|:--------------------------------------| -| ``bucketName`` | _String_ | Name of the bucket. | -| ``notificationConfiguration`` | _[NotificationConfiguration]_ | Notification configuration to be set. | +| Parameter | Type | Description | +|:----------|:------------------------------|:------------| +| ``args`` | _[SetBucketNotificationArgs]_ | Arguments. | __Example__ ```java @@ -842,7 +844,8 @@ queueConfigurationList.add(queueConfiguration); NotificationConfiguration config = new NotificationConfiguration(); config.setQueueConfigurationList(queueConfigurationList); -minioClient.setBucketNotification("my-bucketname", config); +minioClient.setBucketNotification( + SetBucketNotificationArgs.builder().bucket("my-bucketname").config(config).build()); ``` @@ -1737,3 +1740,6 @@ ObjectStat objectStat = [DeleteBucketPolicyArgs]: http://minio.github.io/minio-java/io/minio/DeleteBucketPolicyArgs.html [GetObjectArgs]: http://minio.github.io/minio-java/io/minio/GetObjectArgs.html [DownloadObjectArgs]: http://minio.github.io/minio-java/io/minio/DownloadObjectArgs.html +[DeleteBucketNotificationArgs]: http://minio.github.io/minio-java/io/minio/DeleteBucketNotificationArgs.html +[GetBucketNotificationArgs]: http://minio.github.io/minio-java/io/minio/GetBucketNotificationArgs.html +[SetBucketNotificationArgs]: http://minio.github.io/minio-java/io/minio/SetBucketNotificationArgs.html diff --git a/examples/RemoveAllBucketNotification.java b/examples/DeleteBucketNotification.java similarity index 88% rename from examples/RemoveAllBucketNotification.java rename to examples/DeleteBucketNotification.java index 4ecd68135..7d3a882d6 100644 --- a/examples/RemoveAllBucketNotification.java +++ b/examples/DeleteBucketNotification.java @@ -14,13 +14,14 @@ * limitations under the License. */ +import io.minio.DeleteBucketNotificationArgs; import io.minio.MinioClient; import io.minio.errors.MinioException; import java.io.IOException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; -public class RemoveAllBucketNotification { +public class DeleteBucketNotification { /** MinioClient.removeAllBucketNotification() example. */ public static void main(String[] args) throws IOException, NoSuchAlgorithmException, InvalidKeyException { @@ -36,7 +37,8 @@ public static void main(String[] args) // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID", // "YOUR-SECRETACCESSKEY"); - minioClient.removeAllBucketNotification("my-bucketname"); + minioClient.deleteBucketNotification( + DeleteBucketNotificationArgs.builder().bucket("my-bucketname").build()); System.out.println("Removed all bucket notification"); } catch (MinioException e) { System.out.println("Error occurred: " + e); diff --git a/examples/GetBucketNotification.java b/examples/GetBucketNotification.java index f4eadea9e..86a2a71a8 100644 --- a/examples/GetBucketNotification.java +++ b/examples/GetBucketNotification.java @@ -14,6 +14,7 @@ * limitations under the License. */ +import io.minio.GetBucketNotificationArgs; import io.minio.MinioClient; import io.minio.errors.MinioException; import io.minio.messages.NotificationConfiguration; @@ -37,9 +38,10 @@ public static void main(String[] args) // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID", // "YOUR-SECRETACCESSKEY"); - NotificationConfiguration notificationConfiguration = - minioClient.getBucketNotification("my-bucketname"); - System.out.println(notificationConfiguration); + NotificationConfiguration config = + minioClient.getBucketNotification( + GetBucketNotificationArgs.builder().bucket("my-bucketname").build()); + System.out.println(config); } catch (MinioException e) { System.out.println("Error occurred: " + e); } diff --git a/examples/SetBucketNotification.java b/examples/SetBucketNotification.java index 3f0f3e11e..f16b15048 100644 --- a/examples/SetBucketNotification.java +++ b/examples/SetBucketNotification.java @@ -15,6 +15,7 @@ */ import io.minio.MinioClient; +import io.minio.SetBucketNotificationArgs; import io.minio.errors.MinioException; import io.minio.messages.EventType; import io.minio.messages.NotificationConfiguration; @@ -38,13 +39,10 @@ public static void main(String[] args) // MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID", // "YOUR-SECRETACCESSKEY"); - // Get current notification configuration. - NotificationConfiguration notificationConfiguration = - minioClient.getBucketNotification("my-bucketname"); + NotificationConfiguration config = new NotificationConfiguration(); // Add a new SQS configuration. - List queueConfigurationList = - notificationConfiguration.queueConfigurationList(); + List queueConfigurationList = config.queueConfigurationList(); QueueConfiguration queueConfiguration = new QueueConfiguration(); queueConfiguration.setQueue("arn:minio:sqs::1:webhook"); @@ -56,10 +54,11 @@ public static void main(String[] args) queueConfiguration.setSuffixRule("pg"); queueConfigurationList.add(queueConfiguration); - notificationConfiguration.setQueueConfigurationList(queueConfigurationList); + config.setQueueConfigurationList(queueConfigurationList); // Set updated notification configuration. - minioClient.setBucketNotification("my-bucketname", notificationConfiguration); + minioClient.setBucketNotification( + SetBucketNotificationArgs.builder().bucket("my-bucketname").config(config).build()); System.out.println("Bucket notification is set successfully"); } catch (MinioException e) { System.out.println("Error occurred: " + e); diff --git a/functional/FunctionalTest.java b/functional/FunctionalTest.java index d1c24c5cf..e4b1ebd00 100644 --- a/functional/FunctionalTest.java +++ b/functional/FunctionalTest.java @@ -24,6 +24,7 @@ import io.minio.CopyConditions; import io.minio.DeleteBucketEncryptionArgs; import io.minio.DeleteBucketLifeCycleArgs; +import io.minio.DeleteBucketNotificationArgs; import io.minio.DeleteBucketPolicyArgs; import io.minio.DeleteBucketTagsArgs; import io.minio.DeleteObjectTagsArgs; @@ -33,6 +34,7 @@ import io.minio.ErrorCode; import io.minio.GetBucketEncryptionArgs; import io.minio.GetBucketLifeCycleArgs; +import io.minio.GetBucketNotificationArgs; import io.minio.GetBucketPolicyArgs; import io.minio.GetBucketTagsArgs; import io.minio.GetObjectArgs; @@ -52,12 +54,14 @@ import io.minio.ServerSideEncryptionCustomerKey; import io.minio.SetBucketEncryptionArgs; import io.minio.SetBucketLifeCycleArgs; +import io.minio.SetBucketNotificationArgs; import io.minio.SetBucketPolicyArgs; import io.minio.SetBucketTagsArgs; import io.minio.SetObjectRetentionArgs; import io.minio.SetObjectTagsArgs; import io.minio.StatObjectArgs; import io.minio.Time; +import io.minio.Xml; import io.minio.errors.ErrorResponseException; import io.minio.errors.InsufficientDataException; import io.minio.messages.Bucket; @@ -70,6 +74,7 @@ import io.minio.messages.NotificationRecords; import io.minio.messages.ObjectLockConfiguration; import io.minio.messages.OutputSerialization; +import io.minio.messages.QueueConfiguration; import io.minio.messages.QuoteFields; import io.minio.messages.Retention; import io.minio.messages.RetentionDurationDays; @@ -80,7 +85,6 @@ import io.minio.messages.SseConfigurationRule; import io.minio.messages.Stats; import io.minio.messages.Tags; -import io.minio.messages.TopicConfiguration; import io.minio.messages.Upload; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -137,6 +141,7 @@ public class FunctionalTest { private static String accessKey; private static String secretKey; private static String region; + private static String sqsArn = null; private static MinioClient client = null; static { @@ -4017,190 +4022,149 @@ public static void getBucketLifeCycle_test1() throws Exception { } } - /** - * Test: setBucketNotification(String bucketName, NotificationConfiguration - * notificationConfiguration). - */ + /** Test: setBucketNotification(SetBucketNotificationArgs args). */ public static void setBucketNotification_test1() throws Exception { - // This test requires 'MINIO_JAVA_TEST_TOPIC' and 'MINIO_JAVA_TEST_REGION' - // environment variables. - String topic = System.getenv("MINIO_JAVA_TEST_TOPIC"); - String region = System.getenv("MINIO_JAVA_TEST_REGION"); - if (topic == null || topic.equals("") || region == null || region.equals("")) { - // do not run functional test as required environment variables are missing. + String methodName = "setBucketNotification(SetBucketNotificationArgs args)"; + long startTime = System.currentTimeMillis(); + if (sqsArn == null) { + mintIgnoredLog(methodName, null, startTime); return; } if (!mintEnv) { - System.out.println( - "Test: setBucketNotification(String bucketName, " - + "NotificationConfiguration notificationConfiguration)"); + System.out.println("Test: " + methodName); } - long startTime = System.currentTimeMillis(); try { - String destBucketName = getRandomName(); - client.makeBucket(MakeBucketArgs.builder().bucket(destBucketName).region(region).build()); - - NotificationConfiguration notificationConfiguration = new NotificationConfiguration(); - - // Add a new topic configuration. - List topicConfigurationList = - notificationConfiguration.topicConfigurationList(); - TopicConfiguration topicConfiguration = new TopicConfiguration(); - topicConfiguration.setTopic(topic); + String bucketName = getRandomName(); + client.makeBucket(MakeBucketArgs.builder().bucket(bucketName).region(region).build()); List eventList = new LinkedList<>(); eventList.add(EventType.OBJECT_CREATED_PUT); eventList.add(EventType.OBJECT_CREATED_COPY); - topicConfiguration.setEvents(eventList); - topicConfiguration.setPrefixRule("images"); - topicConfiguration.setSuffixRule("pg"); + QueueConfiguration queueConfig = new QueueConfiguration(); + queueConfig.setQueue(sqsArn); + queueConfig.setEvents(eventList); + queueConfig.setPrefixRule("images"); + queueConfig.setSuffixRule("pg"); - topicConfigurationList.add(topicConfiguration); - notificationConfiguration.setTopicConfigurationList(topicConfigurationList); + List queueConfigList = new LinkedList<>(); + queueConfigList.add(queueConfig); - client.setBucketNotification(destBucketName, notificationConfiguration); + NotificationConfiguration config = new NotificationConfiguration(); + config.setQueueConfigurationList(queueConfigList); - client.removeBucket(RemoveBucketArgs.builder().bucket(destBucketName).build()); - mintSuccessLog( - "setBucketNotification(String bucketName, NotificationConfiguration notificationConfiguration)", - null, - startTime); + client.setBucketNotification( + SetBucketNotificationArgs.builder().bucket(bucketName).config(config).build()); + + client.removeBucket(RemoveBucketArgs.builder().bucket(bucketName).build()); + mintSuccessLog(methodName, null, startTime); } catch (Exception e) { - mintFailedLog( - "setBucketNotification(String bucketName, NotificationConfiguration notificationConfiguration)", - null, - startTime, - null, - e.toString() + " >>> " + Arrays.toString(e.getStackTrace())); - throw e; + handleException(methodName, null, startTime, e); } } - /** Test: getBucketNotification(String bucketName). */ + /** Test: getBucketNotification(GetBucketNotificationArgs args). */ public static void getBucketNotification_test1() throws Exception { - // This test requires 'MINIO_JAVA_TEST_TOPIC' and 'MINIO_JAVA_TEST_REGION' - // environment variables. - String topic = System.getenv("MINIO_JAVA_TEST_TOPIC"); - String region = System.getenv("MINIO_JAVA_TEST_REGION"); - if (topic == null || topic.equals("") || region == null || region.equals("")) { - // do not run functional test as required environment variables are missing. + String methodName = "getBucketNotification(GetBucketNotificationArgs args)"; + long startTime = System.currentTimeMillis(); + if (sqsArn == null) { + mintIgnoredLog(methodName, null, startTime); return; } if (!mintEnv) { - System.out.println("Test: getBucketNotification(String bucketName)"); + System.out.println("Test: " + methodName); } - long startTime = System.currentTimeMillis(); try { - String destBucketName = getRandomName(); - client.makeBucket(MakeBucketArgs.builder().bucket(destBucketName).region(region).build()); - - NotificationConfiguration notificationConfiguration = new NotificationConfiguration(); - - // Add a new topic configuration. - List topicConfigurationList = - notificationConfiguration.topicConfigurationList(); - TopicConfiguration topicConfiguration = new TopicConfiguration(); - topicConfiguration.setTopic(topic); + String bucketName = getRandomName(); + client.makeBucket(MakeBucketArgs.builder().bucket(bucketName).region(region).build()); List eventList = new LinkedList<>(); eventList.add(EventType.OBJECT_CREATED_PUT); - topicConfiguration.setEvents(eventList); + QueueConfiguration queueConfig = new QueueConfiguration(); + queueConfig.setQueue(sqsArn); + queueConfig.setEvents(eventList); - topicConfigurationList.add(topicConfiguration); - notificationConfiguration.setTopicConfigurationList(topicConfigurationList); + List queueConfigList = new LinkedList<>(); + queueConfigList.add(queueConfig); - client.setBucketNotification(destBucketName, notificationConfiguration); - String expectedResult = notificationConfiguration.toString(); + NotificationConfiguration expectedConfig = new NotificationConfiguration(); + expectedConfig.setQueueConfigurationList(queueConfigList); - notificationConfiguration = client.getBucketNotification(destBucketName); + client.setBucketNotification( + SetBucketNotificationArgs.builder().bucket(bucketName).config(expectedConfig).build()); - topicConfigurationList = notificationConfiguration.topicConfigurationList(); - topicConfiguration = topicConfigurationList.get(0); - topicConfiguration.setId(null); - String result = notificationConfiguration.toString(); + NotificationConfiguration config = + client.getBucketNotification( + GetBucketNotificationArgs.builder().bucket(bucketName).build()); - if (!result.equals(expectedResult)) { - System.out.println("FAILED. expected: " + expectedResult + ", got: " + result); + if (config.queueConfigurationList().size() != 1 + || !sqsArn.equals(config.queueConfigurationList().get(0).queue()) + || config.queueConfigurationList().get(0).events().size() != 1 + || config.queueConfigurationList().get(0).events().get(0) + != EventType.OBJECT_CREATED_PUT) { + System.out.println( + "FAILED. expected: " + Xml.marshal(expectedConfig) + ", got: " + Xml.marshal(config)); } - client.removeBucket(RemoveBucketArgs.builder().bucket(destBucketName).build()); - mintSuccessLog("getBucketNotification(String bucketName)", null, startTime); + client.removeBucket(RemoveBucketArgs.builder().bucket(bucketName).build()); + mintSuccessLog(methodName, null, startTime); } catch (Exception e) { - mintFailedLog( - "getBucketNotification(String bucketName)", - null, - startTime, - null, - e.toString() + " >>> " + Arrays.toString(e.getStackTrace())); - throw e; + handleException(methodName, null, startTime, e); } } - /** Test: removeAllBucketNotification(String bucketName). */ - public static void removeAllBucketNotification_test1() throws Exception { - // This test requires 'MINIO_JAVA_TEST_TOPIC' and 'MINIO_JAVA_TEST_REGION' - // environment variables. - String topic = System.getenv("MINIO_JAVA_TEST_TOPIC"); - String region = System.getenv("MINIO_JAVA_TEST_REGION"); - if (topic == null || topic.equals("") || region == null || region.equals("")) { - // do not run functional test as required environment variables are missing. + /** Test: deleteBucketNotification(DeleteBucketNotificationArgs args). */ + public static void deleteBucketNotification_test1() throws Exception { + String methodName = "deleteBucketNotification(DeleteBucketNotificationArgs args)"; + long startTime = System.currentTimeMillis(); + if (sqsArn == null) { + mintIgnoredLog(methodName, null, startTime); return; } if (!mintEnv) { - System.out.println("Test: removeAllBucketNotification(String bucketName)"); + System.out.println("Test: " + methodName); } - long startTime = System.currentTimeMillis(); try { - String destBucketName = getRandomName(); - client.makeBucket(MakeBucketArgs.builder().bucket(destBucketName).region(region).build()); - - NotificationConfiguration notificationConfiguration = new NotificationConfiguration(); - - // Add a new topic configuration. - List topicConfigurationList = - notificationConfiguration.topicConfigurationList(); - TopicConfiguration topicConfiguration = new TopicConfiguration(); - topicConfiguration.setTopic(topic); + String bucketName = getRandomName(); + client.makeBucket(MakeBucketArgs.builder().bucket(bucketName).region(region).build()); List eventList = new LinkedList<>(); eventList.add(EventType.OBJECT_CREATED_PUT); eventList.add(EventType.OBJECT_CREATED_COPY); - topicConfiguration.setEvents(eventList); - topicConfiguration.setPrefixRule("images"); - topicConfiguration.setSuffixRule("pg"); + QueueConfiguration queueConfig = new QueueConfiguration(); + queueConfig.setQueue(sqsArn); + queueConfig.setEvents(eventList); + queueConfig.setPrefixRule("images"); + queueConfig.setSuffixRule("pg"); - topicConfigurationList.add(topicConfiguration); - notificationConfiguration.setTopicConfigurationList(topicConfigurationList); + List queueConfigList = new LinkedList<>(); + queueConfigList.add(queueConfig); - client.setBucketNotification(destBucketName, notificationConfiguration); + NotificationConfiguration config = new NotificationConfiguration(); + config.setQueueConfigurationList(queueConfigList); - notificationConfiguration = new NotificationConfiguration(); - String expectedResult = notificationConfiguration.toString(); + client.setBucketNotification( + SetBucketNotificationArgs.builder().bucket(bucketName).config(config).build()); - client.removeAllBucketNotification(destBucketName); + client.deleteBucketNotification( + DeleteBucketNotificationArgs.builder().bucket(bucketName).build()); - notificationConfiguration = client.getBucketNotification(destBucketName); - String result = notificationConfiguration.toString(); - if (!result.equals(expectedResult)) { - throw new Exception("[FAILED] Expected: " + expectedResult + ", Got: " + result); + config = + client.getBucketNotification( + GetBucketNotificationArgs.builder().bucket(bucketName).build()); + if (config.queueConfigurationList().size() != 0) { + System.out.println("FAILED. expected: , got: " + Xml.marshal(config)); } - client.removeBucket(RemoveBucketArgs.builder().bucket(destBucketName).build()); - mintSuccessLog("removeAllBucketNotification(String bucketName)", null, startTime); + client.removeBucket(RemoveBucketArgs.builder().bucket(bucketName).build()); + mintSuccessLog(methodName, null, startTime); } catch (Exception e) { - mintFailedLog( - "removeAllBucketNotification(String bucketName)", - null, - startTime, - null, - e.toString() + " >>> " + Arrays.toString(e.getStackTrace())); - throw e; + handleException(methodName, null, startTime, e); } } @@ -4834,12 +4798,9 @@ public static void runTests() throws Exception { teardown(); - // notification tests requires 'MINIO_JAVA_TEST_TOPIC' and - // 'MINIO_JAVA_TEST_REGION' environment variables - // to be set appropriately. setBucketNotification_test1(); getBucketNotification_test1(); - removeAllBucketNotification_test1(); + deleteBucketNotification_test1(); } /** runQuickTests: runs tests those completely quicker. */ @@ -4940,6 +4901,9 @@ public static Process runMinio() throws Exception { env.put("MINIO_KMS_KES_KEY_FILE", "play.min.io.kes.root.key"); env.put("MINIO_KMS_KES_CERT_FILE", "play.min.io.kes.root.cert"); env.put("MINIO_KMS_KES_KEY_NAME", "my-minio-key"); + env.put("MINIO_NOTIFY_WEBHOOK_ENABLE_miniojavatest", "on"); + env.put("MINIO_NOTIFY_WEBHOOK_ENDPOINT_miniojavatest", "http://example.org/"); + sqsArn = "arn:minio:sqs::miniojavatest:webhook"; pb.redirectErrorStream(true); pb.redirectOutput(ProcessBuilder.Redirect.to(new File(MINIO_BINARY + ".log"))); @@ -4964,6 +4928,7 @@ public static void main(String[] args) throws Exception { accessKey = "minio"; secretKey = "minio123"; region = "us-east-1"; + sqsArn = System.getenv("MINIO_JAVA_TEST_SQS_ARN"); if (!downloadMinio()) { System.out.println("usage: FunctionalTest ");