Skip to content

Commit 755099a

Browse files
balamuruganaharshavardhana
authored andcommitted
api: add new bucket notification APIs. (#551)
Below methods are added * public NotificationConfiguration getBucketNotification(String bucketName) * public void setBucketNotification(String bucketName, NotificationConfiguration notificationConfiguration) * public void removeAllBucketNotification(String bucketName) Fixes #437
1 parent c93f11b commit 755099a

13 files changed

+1149
-0
lines changed

api/src/main/java/io/minio/MinioClient.java

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import io.minio.messages.Part;
5858
import io.minio.messages.Prefix;
5959
import io.minio.messages.Upload;
60+
import io.minio.messages.NotificationConfiguration;
6061
import io.minio.org.apache.commons.validator.routines.InetAddressValidator;
6162
import io.minio.policy.PolicyType;
6263
import io.minio.policy.BucketPolicy;
@@ -2987,6 +2988,97 @@ public void setBucketPolicy(String bucketName, String objectPrefix, PolicyType p
29872988
}
29882989

29892990

2991+
/**
2992+
* Get bucket notification configuration
2993+
*
2994+
* @param bucketName Bucket name.
2995+
*
2996+
* </p><b>Example:</b><br>
2997+
* <pre>{@code NotificationConfiguration notificationConfig = minioClient.getBucketNotification("my-bucketname");
2998+
* }</pre>
2999+
*
3000+
* @throws InvalidBucketNameException upon invalid bucket name is given
3001+
* @throws NoResponseException upon no response from server
3002+
* @throws IOException upon connection error
3003+
* @throws XmlPullParserException upon parsing response xml
3004+
* @throws ErrorResponseException upon unsuccessful execution
3005+
* @throws InternalException upon internal library error
3006+
*
3007+
*/
3008+
public NotificationConfiguration getBucketNotification(String bucketName)
3009+
throws InvalidBucketNameException, InvalidObjectPrefixException, NoSuchAlgorithmException,
3010+
InsufficientDataException, IOException, InvalidKeyException, NoResponseException,
3011+
XmlPullParserException, ErrorResponseException, InternalException {
3012+
Map<String,String> queryParamMap = new HashMap<>();
3013+
queryParamMap.put("notification", "");
3014+
3015+
HttpResponse response = executeGet(bucketName, null, null, queryParamMap);
3016+
NotificationConfiguration result = new NotificationConfiguration();
3017+
try {
3018+
result.parseXml(response.body().charStream());
3019+
} finally {
3020+
response.body().close();
3021+
}
3022+
3023+
return result;
3024+
}
3025+
3026+
3027+
/**
3028+
* Set bucket notification configuration
3029+
*
3030+
* @param bucketName Bucket name.
3031+
* @param notificationConfiguration Notification configuration to be set.
3032+
*
3033+
* </p><b>Example:</b><br>
3034+
* <pre>{@code minioClient.setBucketNotification("my-bucketname", notificationConfiguration);
3035+
* }</pre>
3036+
*
3037+
* @throws InvalidBucketNameException upon invalid bucket name is given
3038+
* @throws NoResponseException upon no response from server
3039+
* @throws IOException upon connection error
3040+
* @throws XmlPullParserException upon parsing response xml
3041+
* @throws ErrorResponseException upon unsuccessful execution
3042+
* @throws InternalException upon internal library error
3043+
*
3044+
*/
3045+
public void setBucketNotification(String bucketName, NotificationConfiguration notificationConfiguration)
3046+
throws InvalidBucketNameException, InvalidObjectPrefixException, NoSuchAlgorithmException,
3047+
InsufficientDataException, IOException, InvalidKeyException, NoResponseException,
3048+
XmlPullParserException, ErrorResponseException, InternalException {
3049+
Map<String,String> queryParamMap = new HashMap<>();
3050+
queryParamMap.put("notification", "");
3051+
HttpResponse response = executePut(bucketName, null, null, queryParamMap, notificationConfiguration.toString(), 0);
3052+
response.body().close();
3053+
}
3054+
3055+
3056+
/**
3057+
* Remove all bucket notification.
3058+
*
3059+
* @param bucketName Bucket name.
3060+
*
3061+
* </p><b>Example:</b><br>
3062+
* <pre>{@code minioClient.removeAllBucketNotification("my-bucketname");
3063+
* }</pre>
3064+
*
3065+
* @throws InvalidBucketNameException upon invalid bucket name is given
3066+
* @throws NoResponseException upon no response from server
3067+
* @throws IOException upon connection error
3068+
* @throws XmlPullParserException upon parsing response xml
3069+
* @throws ErrorResponseException upon unsuccessful execution
3070+
* @throws InternalException upon internal library error
3071+
*
3072+
*/
3073+
public void removeAllBucketNotification(String bucketName)
3074+
throws InvalidBucketNameException, InvalidObjectPrefixException, NoSuchAlgorithmException,
3075+
InsufficientDataException, IOException, InvalidKeyException, NoResponseException,
3076+
XmlPullParserException, ErrorResponseException, InternalException {
3077+
NotificationConfiguration notificationConfiguration = new NotificationConfiguration();
3078+
setBucketNotification(bucketName, notificationConfiguration);
3079+
}
3080+
3081+
29903082
/**
29913083
* Returns next part if exists.
29923084
*/
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* Minio Java SDK for Amazon S3 Compatible Cloud Storage, (C) 2017 Minio, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.minio.messages;
18+
19+
import java.util.LinkedList;
20+
import java.util.List;
21+
22+
import org.xmlpull.v1.XmlPullParserException;
23+
24+
import com.google.api.client.util.Key;
25+
26+
import io.minio.errors.InvalidArgumentException;
27+
28+
29+
/**
30+
* Helper class to parse Amazon AWS S3 response XML containing cloud function configuration.
31+
*/
32+
public class CloudFunctionConfiguration extends XmlEntity {
33+
@Key("Id")
34+
private String id;
35+
@Key("CloudFunction")
36+
private String cloudFunction;
37+
@Key("Event")
38+
private List<String> events = new LinkedList<>();
39+
@Key("Filter")
40+
private Filter filter;
41+
42+
43+
public CloudFunctionConfiguration() throws XmlPullParserException {
44+
super();
45+
super.name = "CloudFunctionConfiguration";
46+
}
47+
48+
49+
/**
50+
* Returns id.
51+
*/
52+
public String id() {
53+
return id;
54+
}
55+
56+
57+
/**
58+
* Sets id.
59+
*/
60+
public void setId(String id) {
61+
this.id = id;
62+
}
63+
64+
65+
/**
66+
* Returns cloudFunction.
67+
*/
68+
public String cloudFunction() {
69+
return cloudFunction;
70+
}
71+
72+
73+
/**
74+
* Sets cloudFunction.
75+
*/
76+
public void setCloudFunction(String cloudFunction) {
77+
this.cloudFunction = cloudFunction;
78+
}
79+
80+
81+
/**
82+
* Returns events.
83+
*/
84+
public List<EventType> events() throws InvalidArgumentException {
85+
return EventType.fromStringList(events);
86+
}
87+
88+
89+
/**
90+
* Sets event.
91+
*/
92+
public void setEvents(List<EventType> events) {
93+
this.events = EventType.toStringList(events);
94+
}
95+
96+
97+
/**
98+
* Returns filter.
99+
*/
100+
public Filter filter() {
101+
return filter;
102+
}
103+
104+
105+
/**
106+
* Sets filter.
107+
*/
108+
public void setFilter(Filter filter) {
109+
this.filter = filter;
110+
}
111+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Minio Java SDK for Amazon S3 Compatible Cloud Storage, (C) 2017 Minio, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.minio.messages;
18+
19+
import java.util.LinkedList;
20+
import java.util.List;
21+
22+
import io.minio.errors.InvalidArgumentException;
23+
24+
25+
/**
26+
* Amazon AWS S3 event types for notifications.
27+
*/
28+
public enum EventType {
29+
OBJECT_CREATED_ANY("s3:ObjectCreated:*"),
30+
OBJECT_CREATED_PUT("s3:ObjectCreated:Put"),
31+
OBJECT_CREATED_POST("s3:ObjectCreated:Post"),
32+
OBJECT_CREATED_COPY("s3:ObjectCreated:Copy"),
33+
OBJECT_CREATED_COMPLETE_MULTIPART_UPLOAD("s3:ObjectCreated:CompleteMultipartUpload"),
34+
OBJECT_REMOVED_ANY("s3:ObjectRemoved:*"),
35+
OBJECT_REMOVED_DELETE("s3:ObjectRemoved:Delete"),
36+
OBJECT_REMOVED_DELETED_MARKER_CREATED("s3:ObjectRemoved:DeleteMarkerCreated"),
37+
REDUCED_REDUNDANCY_LOST_OBJECT("s3:ReducedRedundancyLostObject");
38+
39+
private final String value;
40+
41+
42+
private EventType(String value) {
43+
this.value = value;
44+
}
45+
46+
47+
public String toString() {
48+
return this.value;
49+
}
50+
51+
52+
/**
53+
* Returns EventType of given string.
54+
*/
55+
public static EventType fromString(String eventTypeString) throws InvalidArgumentException {
56+
for (EventType et : EventType.values()) {
57+
if (eventTypeString.equals(et.value)) {
58+
return et;
59+
}
60+
}
61+
62+
63+
throw new InvalidArgumentException("unknown event '" + eventTypeString + "'");
64+
}
65+
66+
67+
/**
68+
* Returns List&lt;EventType&gt; of given List&lt;String&gt;.
69+
*/
70+
public static List<EventType> fromStringList(List<String> eventList) throws InvalidArgumentException {
71+
List<EventType> eventTypeList = new LinkedList<EventType>();
72+
for (String event: eventList) {
73+
eventTypeList.add(EventType.fromString(event));
74+
}
75+
76+
return eventTypeList;
77+
}
78+
79+
80+
/**
81+
* Returns List&lt;String&gt; of given List&lt;EventType&gt;.
82+
*/
83+
public static List<String> toStringList(List<EventType> eventTypeList) {
84+
List<String> events = new LinkedList<String>();
85+
for (EventType eventType: eventTypeList) {
86+
events.add(eventType.toString());
87+
}
88+
89+
return events;
90+
}
91+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Minio Java SDK for Amazon S3 Compatible Cloud Storage, (C) 2017 Minio, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.minio.messages;
18+
19+
import org.xmlpull.v1.XmlPullParserException;
20+
21+
import com.google.api.client.util.Key;
22+
23+
import io.minio.errors.InvalidArgumentException;
24+
25+
26+
/**
27+
* Helper class to parse Amazon AWS S3 response XML containing Filter.
28+
*/
29+
@SuppressWarnings("WeakerAccess")
30+
public class Filter extends XmlEntity {
31+
@Key("S3Key")
32+
private S3Key s3Key = new S3Key();
33+
34+
35+
public Filter() throws XmlPullParserException {
36+
super();
37+
super.name = "Filter";
38+
}
39+
40+
41+
/**
42+
* Returns S3 Key.
43+
*/
44+
public S3Key s3Key() {
45+
return s3Key;
46+
}
47+
48+
49+
/**
50+
* Sets S3 Key.
51+
*/
52+
public void setS3Key(S3Key s3Key) {
53+
this.s3Key = s3Key;
54+
}
55+
56+
57+
public void setPrefixRule(String value) throws InvalidArgumentException, XmlPullParserException {
58+
s3Key.setPrefixRule(value);
59+
}
60+
61+
62+
public void setSuffixRule(String value) throws InvalidArgumentException, XmlPullParserException {
63+
s3Key.setSuffixRule(value);
64+
}
65+
}

0 commit comments

Comments
 (0)