Skip to content

Commit

Permalink
Address bala's comment
Browse files Browse the repository at this point in the history
  • Loading branch information
sinhaashish committed May 12, 2020
1 parent 0542e61 commit 962b995
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 74 deletions.
27 changes: 13 additions & 14 deletions api/src/main/java/io/minio/BucketArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

package io.minio;

/** Bucket Arguments to hold base bucket properties */
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

/** Base argument class holds bucket name and region */
public abstract class BucketArgs {
private final String name;
private final String region;
Expand All @@ -26,45 +28,42 @@ public abstract class BucketArgs {
this.region = builder.region;
}

/** Returns the name of bucket */
/** Returns bucket name */
public String bucketName() {
return name;
}

/** Returns the region of bucket */
/** Returns region */
public String region() {
return region;
}

/** Builder class to create base bucket object */
/** Base argument builder class. */
public abstract static class Builder<T extends Builder<T>> {
public String name;
public String region;

public Builder() {}

public Builder(BucketArgs args) {
this.name = args.bucketName();
this.region = args.region();
}

@SuppressWarnings("unchecked")
/** Its safe to type cast to T as T is inherited this class. */
@SuppressFBWarnings(
value = "GC",
justification = "Its safe to type cast to T as T is inherited by this class")
public T bucket(String name) {
validateName(name);
this.name = name;
return (T) this;
}

@SuppressWarnings("unchecked")
/** Its safe to type cast to T as T is inherited this class. */
@SuppressFBWarnings(
value = "GC",
justification = "Its safe to type cast to T as T is inherited by this class")
public T region(String region) {
this.region = region;
return (T) this;
}

/** Validate the name of the bucket */
public void validateName(String name) {
public static void validateName(String name) {
if (name == null) {
throw new IllegalArgumentException("null bucket name");
}
Expand Down
10 changes: 2 additions & 8 deletions api/src/main/java/io/minio/MakeBucketArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package io.minio;

/** Bucket Arguments to be used to create Bukcet. */
/** Argument class of @see #makeBucket(MakeBucketArgs args) */
public class MakeBucketArgs extends BucketArgs {
private final boolean objectLock;

Expand All @@ -25,12 +25,11 @@ private MakeBucketArgs(Builder builder) {
this.objectLock = builder.objectLock;
}

/** Return true if object lock functionality is enabled */
/** Returns object lock flag. */
public boolean objectLock() {
return objectLock;
}

/** Return new Builder */
public static Builder builder() {
return new Builder();
}
Expand All @@ -40,11 +39,6 @@ public static final class Builder extends BucketArgs.Builder<Builder> {

public Builder() {}

public Builder(MakeBucketArgs args) {
super(args);
this.objectLock = args.objectLock();
}

public Builder objectLock(boolean objectLock) {
this.objectLock = objectLock;
return this;
Expand Down
3 changes: 2 additions & 1 deletion docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ __Parameters__

| Parameter | Type | Description |
|:---------------|:-------------------|:---------------------------|
| ``args`` | _[MakeBucketArgs](#https://minio.github.io/minio-java/io/minio/MakeBucketArgs.html)_ | Arguments to create bucket |
| ``args`` | _[MakeBucketArgs]_ | Arguments to create bucket |

__Example__

Expand Down Expand Up @@ -1598,4 +1598,5 @@ ObjectStat objectStat = minioClient.statObject("my-bucketname", "my-objectname",
[ObjectStat]: http://minio.github.io/minio-java/io/minio/ObjectStat.html
[DeleteError]: http://minio.github.io/minio-java/io/minio/messages/DeleteError.html
[SelectResponseStream]: http://minio.github.io/minio-java/io/minio/SelectResponseStream.html
[MakeBucketArgs]: http://minio.github.io/minio-java/io/minio/MakeBucketArgs.html
[Method]: http://minio.github.io/minio-java/io/minio/http/Method.html
33 changes: 13 additions & 20 deletions examples/MakeBucket.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,36 +37,29 @@ public static void main(String[] args)
// MinioClient minioClient = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID",
// "YOUR-SECRETACCESSKEY");

// Create bucket if it doesn't exist.
if (minioClient.bucketExists("my-bucketname")) {
System.out.println("my-bucketname already exists");
} else {
// Create bucket 'my-bucketname'.
// Create bucket 'my-bucketname' if it doesn`t exist.
if (!minioClient.bucketExists("my-bucketname")) {
minioClient.makeBucket(MakeBucketArgs.builder().bucket("my-bucketname").build());
System.out.println("my-bucketname is created successfully");
}
// Create bucket if it doesn't exist.
if (minioClient.bucketExists("my-bucketname2")) {
System.out.println("my-bucketname2 already exists");
} else {
// Create bucket 'my-bucketname2' and region.

// Create bucket 'my-bucketname-in-eu' in 'eu-west-1' region if it doesn't exist.
if (!minioClient.bucketExists("my-bucketname-in-eu")) {
minioClient.makeBucket(
MakeBucketArgs.builder().bucket("my-bucketname2").region("us-west-1").build());
System.out.println("my-bucketname2 is created successfully");
MakeBucketArgs.builder().bucket("my-bucketname-in-eu").region("eu-west-1").build());
System.out.println("my-bucketname-in-eu is created successfully");
}
// Create bucket if it doesn't exist.
if (minioClient.bucketExists("my-bucketname3")) {
System.out.println("my-bucketname3 already exists");
} else {

// Create bucket 'my-bucketname3' , egion and object lock functionality enabled.
// Create bucket 'my-bucketname-in-eu-with-object-lock' in 'eu-west-1' with object lock
// functionality enabled.
if (!minioClient.bucketExists("my-bucketname-in-eu-with-object-lock")) {
minioClient.makeBucket(
MakeBucketArgs.builder()
.bucket("my-bucketname3")
.region("us-west-1")
.bucket("my-bucketname-in-eu-with-object-lock")
.region("eu-west-1")
.objectLock(true)
.build());
System.out.println("my-bucketname3 is created successfully");
System.out.println("my-bucketname-in-eu-with-object-lock is created successfully");
}
} catch (MinioException e) {
System.out.println("Error occurred: " + e);
Expand Down
61 changes: 30 additions & 31 deletions functional/FunctionalTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,75 +252,74 @@ public static void makeBucket_test1() throws Exception {
}

/** Test: makeBucket(MakeBucketArgs args). */
public static void makeBucketwithRegion_test() throws Exception {
public static void makeBucket_test2() throws Exception {
if (!mintEnv) {
System.out.println("Test: makeBucket(MakeBucketArgs args) with region");
System.out.println(
"Test: with region and object lock functionality : makeBucket(MakeBucketArgs args)");
}

long startTime = System.currentTimeMillis();
try {
String name = getRandomName();
client.makeBucket(MakeBucketArgs.builder().bucket(name).region("eu-west-1").build());
client.makeBucket(
MakeBucketArgs.builder().bucket(name).region("eu-west-1").objectLock(true).build());
client.removeBucket(name);
mintSuccessLog("makeBucket(MakeBucketArgs args) with region", "region: eu-west-1", startTime);
mintSuccessLog(
"makeBucket(MakeBucketArgs args)", "region: eu-west-1, objectLock: true", startTime);
} catch (Exception e) {
mintFailedLog(
"makeBucket(MakeBucketArgs args) with region",
"region: eu-west-1",
"makeBucket(MakeBucketArgs args)",
"region: eu-west-1, objectLock: true",
startTime,
null,
e.toString() + " >>> " + Arrays.toString(e.getStackTrace()));
throw e;
}
}

/** Test: makeBucket(MakeBucketArgs args) where bucketName has periods in its name. */
public static void makeBucketWithPeriod_test() throws Exception {
/** Test: makeBucket(MakeBucketArgs args). */
public static void makeBucket_test3() throws Exception {
if (!mintEnv) {
System.out.println(
"Test: makeBucket(MakeBucketArgs args) with bucketname having periods in its name ");
System.out.println("Test: with region: makeBucket(MakeBucketArgs args)");
}

long startTime = System.currentTimeMillis();
String name = getRandomName() + ".withperiod";
try {
client.makeBucket(MakeBucketArgs.builder().bucket(name).region("eu-central-1").build());
String name = getRandomName();
client.makeBucket(MakeBucketArgs.builder().bucket(name).region("eu-west-1").build());
client.removeBucket(name);
mintSuccessLog(
"makeBucket(MakeBucketArgs args) bucketname having periods in its name",
"name: " + name + ", region: eu-central-1",
startTime);
mintSuccessLog("makeBucket(MakeBucketArgs args) ", "region: eu-west-1", startTime);
} catch (Exception e) {
mintFailedLog(
"makeBucket(MakeBucketArgs args) bucketname having periods in its name",
"name: " + name + ", region: eu-central-1",
"makeBucket(MakeBucketArgs args) ",
"region: eu-west-1",
startTime,
null,
e.toString() + " >>> " + Arrays.toString(e.getStackTrace()));
throw e;
}
}

/** Test: makeBucket(MakeBucketArgs args). */
public static void makeBucketwithRegioAndObjectLock() throws Exception {
/** Test: makeBucket(MakeBucketArgs args) where bucketName has periods in its name. */
public static void makeBucket_test4() throws Exception {
if (!mintEnv) {
System.out.println("Test: makeBucket(MakeBucketArgs args) with region and object lock");
System.out.println(
"Test: with bucket name having periods in its name: makeBucket(MakeBucketArgs args)");
}

long startTime = System.currentTimeMillis();
String name = getRandomName() + ".withperiod";
try {
String name = getRandomName();
client.makeBucket(
MakeBucketArgs.builder().bucket(name).region("eu-west-1").objectLock(true).build());
client.makeBucket(MakeBucketArgs.builder().bucket(name).region("eu-central-1").build());
client.removeBucket(name);
mintSuccessLog(
"makeBucket(MakeBucketArgs args) with region and objectllock",
"region: eu-west-1",
"makeBucket(MakeBucketArgs args) bucketname having periods in its name",
"name: " + name + ", region: eu-central-1",
startTime);
} catch (Exception e) {
mintFailedLog(
"makeBucket(MakeBucketArgs args) with region and objectlock",
"region: eu-west-1",
"makeBucket(MakeBucketArgs args) bucketname having periods in its name",
"name: " + name + ", region: eu-central-1",
startTime,
null,
e.toString() + " >>> " + Arrays.toString(e.getStackTrace()));
Expand Down Expand Up @@ -4019,10 +4018,10 @@ public static void selectObjectContent_test1() throws Exception {
/** runTests: runs as much as possible of test combinations. */
public static void runTests() throws Exception {
makeBucket_test1();
makeBucketwithRegioAndObjectLock();
makeBucket_test2();
if (endpoint.toLowerCase(Locale.US).contains("s3")) {
makeBucketwithRegion_test();
makeBucketWithPeriod_test();
makeBucket_test3();
makeBucket_test4();
}

listBuckets_test();
Expand Down

0 comments on commit 962b995

Please sign in to comment.