Skip to content

Commit

Permalink
add {set,get,delete}BucketReplication APIs (#1030)
Browse files Browse the repository at this point in the history
  • Loading branch information
balamurugana authored Aug 8, 2020
1 parent 387db23 commit ed3d00d
Show file tree
Hide file tree
Showing 9 changed files with 757 additions and 18 deletions.
28 changes: 28 additions & 0 deletions api/src/main/java/io/minio/DeleteBucketReplicationArgs.java
Original file line number Diff line number Diff line change
@@ -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 {@link MinioClient#deleteBucketReplication}. */
public class DeleteBucketReplicationArgs extends BucketArgs {
public static Builder builder() {
return new Builder();
}

/** Argument builder of {@link DeleteBucketReplicationArgs}. */
public static final class Builder
extends BucketArgs.Builder<Builder, DeleteBucketReplicationArgs> {}
}
27 changes: 27 additions & 0 deletions api/src/main/java/io/minio/GetBucketReplicationArgs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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 {@link MinioClient#getBucketReplication}. */
public class GetBucketReplicationArgs extends BucketArgs {
public static Builder builder() {
return new Builder();
}

/** Argument builder of {@link GetBucketReplicationArgs}. */
public static final class Builder extends BucketArgs.Builder<Builder, GetBucketReplicationArgs> {}
}
132 changes: 132 additions & 0 deletions api/src/main/java/io/minio/MinioClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -5744,6 +5744,138 @@ public void deleteBucketNotification(DeleteBucketNotificationArgs args)
response.close();
}

/**
* Gets bucket replication configuration of a bucket.
*
* <pre>Example:{@code
* String config =
* minioClient.getBucketReplication(
* GetBucketReplicationArgs.builder().bucket("my-bucketname").build());
* }</pre>
*
* @param args {@link GetBucketReplicationArgs} object.
* @return String - Bucket replication configuration as JSON string.
* @throws ErrorResponseException thrown to indicate S3 service returned an error response.
* @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 String getBucketReplication(GetBucketReplicationArgs args)
throws ErrorResponseException, InsufficientDataException, InternalException,
InvalidBucketNameException, InvalidKeyException, InvalidResponseException, IOException,
NoSuchAlgorithmException, ServerException, XmlParserException {
checkArgs(args);
try (Response response = executeGet(args, null, newMultimap("replication", ""))) {
return response.body().string();
} catch (ErrorResponseException e) {
if (!e.errorResponse().code().equals("ReplicationConfigurationNotFoundError")) {
throw e;
}
}

return "";
}

/**
* Sets bucket replication configuration to a bucket.
*
* <pre>Example:{@code
* // Lets consider variable 'config' contains below XML String;
* // <ReplicationConfiguration>
* // <Role>REPLACE-WITH-ACTUAL-REPLICATION-ROLE</Role>
* // <Rule>
* // <ID>rule1</ID>
* // <Status>Enabled</Status>
* // <Priority>1</Priority>
* // <DeleteMarkerReplication>
* // <Status>Disabled</Status>
* // </DeleteMarkerReplication>
* // <Filter>
* // <And>
* // <Prefix>TaxDocs</Prefix>
* // <Tag>
* // <Key>key1</Key>
* // <Value>value1</Value>
* // </Tag>
* // <Tag>
* // <Key>key2</Key>
* // <Value>value2</Value>
* // </Tag>
* // </And>
* // </Filter>
* // <Destination>
* // <Bucket>REPLACE-WITH-ACTUAL-DESTINATION-BUCKET-ARN</Bucket>
* // </Destination>
* // </Rule>
* // </ReplicationConfiguration>
*
* minioClient.setBucketReplication(
* SetBucketReplicationArgs.builder().bucket("my-bucketname").config(config).build());
* }</pre>
*
* @param args {@link SetBucketReplicationArgs} object.
* @throws ErrorResponseException thrown to indicate S3 service returned an error response.
* @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 setBucketReplication(SetBucketReplicationArgs args)
throws ErrorResponseException, InsufficientDataException, InternalException,
InvalidBucketNameException, InvalidKeyException, InvalidResponseException, IOException,
NoSuchAlgorithmException, ServerException, XmlParserException {
checkArgs(args);
Response response =
executePut(
args,
(args.objectLockToken() != null)
? newMultimap("x-amz-bucket-object-lock-token", args.objectLockToken())
: null,
newMultimap("replication", ""),
args.config(),
0);
response.close();
}

/**
* Deletes bucket replication configuration from a bucket.
*
* <pre>Example:{@code
* minioClient.deleteBucketReplication(
* DeleteBucketReplicationArgs.builder().bucket("my-bucketname"));
* }</pre>
*
* @param args {@link DeleteBucketReplicationArgs} object.
* @throws ErrorResponseException thrown to indicate S3 service returned an error response.
* @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 deleteBucketReplication(DeleteBucketReplicationArgs args)
throws ErrorResponseException, InsufficientDataException, InternalException,
InvalidBucketNameException, InvalidKeyException, InvalidResponseException, IOException,
NoSuchAlgorithmException, ServerException, XmlParserException {
checkArgs(args);
executeDelete(args, null, newMultimap("replication", ""));
}

/**
* Lists incomplete object upload information of a bucket.
*
Expand Down
65 changes: 65 additions & 0 deletions api/src/main/java/io/minio/SetBucketReplicationArgs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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 {@link MinioClient#setBucketReplication}. */
public class SetBucketReplicationArgs extends BucketArgs {
private String config;
private String objectLockToken;

public String config() {
return config;
}

public String objectLockToken() {
return objectLockToken;
}

public static Builder builder() {
return new Builder();
}

/** Argument builder of {@link SetBucketReplicationArgs}. */
public static final class Builder extends BucketArgs.Builder<Builder, SetBucketReplicationArgs> {
private void validateConfig(String config) {
validateNotNull(config, "replication configuration");
}

private void validateObjectLockToken(String token) {
validateNullOrNotEmptyString(token, "object lock token");
}

@Override
protected void validate(SetBucketReplicationArgs args) {
super.validate(args);
validateConfig(args.config);
validateObjectLockToken(args.objectLockToken);
}

public Builder config(String config) {
validateConfig(config);
operations.add(args -> args.config = config);
return this;
}

public Builder objectLockToken(String token) {
validateObjectLockToken(token);
operations.add(args -> args.objectLockToken = token);
return this;
}
}
}
Loading

0 comments on commit ed3d00d

Please sign in to comment.