Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make bucket with builder #927

Merged
merged 4 commits into from
May 12, 2020
Merged

Conversation

sinhaashish
Copy link
Contributor

No description provided.

@sinhaashish sinhaashish force-pushed the builder-make-bucket branch 3 times, most recently from 73eeb8e to 199fb44 Compare May 11, 2020 07:43
Copy link
Contributor

@anjalshireesh anjalshireesh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommended syntax for building the make-bucket args:

MakeBucketArgs.builder()
        .bucket("<bucketname>")
        .region("<region>")
        .objectLock(<true/false>)
        .build()

api/src/main/java/io/minio/BucketArgs.java Show resolved Hide resolved
api/src/main/java/io/minio/MakeBucketArgs.java Outdated Show resolved Hide resolved
api/src/main/java/io/minio/BucketArgs.java Outdated Show resolved Hide resolved
api/src/main/java/io/minio/MakeBucketArgs.java Outdated Show resolved Hide resolved
api/src/main/java/io/minio/MakeBucketArgs.java Outdated Show resolved Hide resolved
api/src/main/java/io/minio/BucketArgs.java Outdated Show resolved Hide resolved
api/src/main/java/io/minio/MinioClient.java Outdated Show resolved Hide resolved
private String region;

BucketArgs(Builder<?> builder) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this whitespace.

api/src/main/java/io/minio/BucketArgs.java Show resolved Hide resolved
public String name;
public String region;

@SuppressWarnings("unchecked")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add justification as Its safe to type cast to T as T is inherited this class.

this(new Builder());
}

public Builder builder() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its been decided to add this feature later on demand.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can find @anjalshireesh comment above, and thus i have made this as static and created the object like

MakeBucketArgs.builder()
        .bucket("<bucketname>")
        .region("<region>")
        .objectLock(<true/false>)
        .build()

@@ -1957,27 +1957,27 @@ public void getObject(
* Creates an object by server-side copying data from another object.
*
* <pre>Example:{@code
* // Copy data from my-source-bucketname/my-objectname to my-bucketname/my-objectname.
* Copy data from my-source-bucketname/my-objectname to my-bucketname/my-objectname.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is code block. It should be a comment. Also touch relevant code to this PR.

docs/API.md Outdated

__Example__
```java
minioClient.makeBucket("my-bucketname", "us-west-2", true);
// Create bucket with default region.
minioClient.makeBucket(new MakeBucketArgs.Builder().bucket("my-bucketname").build());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its better to have new line after each example.

docs/API.md Outdated
minioClient.makeBucket(new MakeBucketArgs.Builder().bucket("my-bucketname").build());
// Create bucket with specific region.
minioClient.makeBucket(
new MakeBucketArgs.Builder().bucket("my-bucketname").region("us-west-1").build());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make same indention like below example.

| ``objectLock`` | _boolean_ | Flag to enable object lock feature. |
| Parameter | Type | Description |
|:---------------|:-----------------|:---------------------------|
| ``args`` | _[MakeBucketArgs]_ | Arguments to create bucket |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You would need to add link to [MakeBucketArgs]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have tried the below but the link is visible. Is this correct approach


__Parameters__

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

@@ -36,7 +37,8 @@ public static void main(String[] args)
System.out.println("my-bucketname already exists");
} else {
// Create bucket 'my-bucketname' with object lock functionality enabled
s3Client.makeBucket("my-bucketname", null, true);
s3Client.makeBucket(
new MakeBucketArgs.Builder().bucket("my-bucketname").objectLock(true).build());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now you could have one example MakeBucket.java and add three variation there.

public static void makeBucketwithRegion_test() throws Exception {
if (!mintEnv) {
System.out.println("Test: makeBucket(String bucketName, String region)");
System.out.println("Test: makeBucket(MakeBucketArgs args)");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add a tag like with region, with objectLock or with region and objectLock

@@ -16,30 +16,55 @@

package io.minio;

/** Bucket Arguments to hold base bucket properties */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/** Base argument class holds bucket name and region */

this.region = builder.region;
}

/** Returns the name of bucket */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/** Returns bucket name */ to consistent with other docs.

return name;
}

/** Returns the region of bucket */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/** Returns region */

}

@SuppressWarnings("unchecked")
/** Its safe to type cast to T as T is inherited this class. */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check how to add justification in @suppressWarnings

}

/** Validate the name of the bucket */
public void validateName(String name) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could make this as static method.


public Builder() {}

public Builder(MakeBucketArgs args) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could remove Builder(XXXArgs args) constructor everywhere and will be added on demand.

docs/API.md Outdated
| ``region`` | _String_ | Region in which the bucket will be created. |
| Parameter | Type | Description |
|:---------------|:-------------------|:---------------------------|
| ``args`` | _[MakeBucketArgs](#https://minio.github.io/minio-java/io/minio/MakeBucketArgs.html)_ | Arguments to create bucket |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check how [Method] link is added as reference.

.region("us-west-1")
.objectLock(true)
.build());
System.out.println("my-bucketname3 is created successfully");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. You could have bucket names as my-bucketname, my-bucketname-in-eu, my-bucketname-in-eu-with-object-lock
  2. I prefer longer block in if i.e. if (!minioClient.bucketExists(...)) { is better.

public static void makeBucketwithRegion_test() throws Exception {
if (!mintEnv) {
System.out.println("Test: makeBucket(String bucketName, String region)");
System.out.println("Test: makeBucket(MakeBucketArgs args) with region");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add tag before the API Test: with region: makeBucket(...)

@@ -303,6 +301,33 @@ public static void makeBucketWithPeriod_test() throws Exception {
}
}

/** Test: makeBucket(MakeBucketArgs args). */
public static void makeBucketwithRegioAndObjectLock() throws Exception {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use makeBucket_testN() like other tests.

@sinhaashish sinhaashish force-pushed the builder-make-bucket branch 2 times, most recently from bbf54c3 to 076b9e7 Compare May 12, 2020 04:56
build.gradle Outdated
@@ -67,6 +67,7 @@ subprojects {
it.options.fork = true
it.options.compilerArgs += ["-Xlint:unchecked", "-Xlint:deprecation", "-Xlint:-options"]
it.options.encoding = "UTF-8"
it.options.compilerArgs << "-Werror"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add "-Werror" in it.options.compilerArgs += line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This worked
it.options.compilerArgs += ["-Xlint:unchecked", "-Xlint:deprecation", "-Xlint:-options", "-Werror"]

Copy link
Contributor

@anjalshireesh anjalshireesh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@kannappanr kannappanr merged commit 7eaf152 into minio:master May 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants