devmadhuu commented on code in PR #12080:
URL: https://github.com/apache/ozone/pull/12080#discussion_r4628096979


##########
hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java:
##########
@@ -1262,6 +1269,9 @@ public void setBucketStoragePolicy(OmBucketArgs args) 
throws IOException {
     Objects.requireNonNull(args, "args == null");
     verifyVolumeName(args.getVolumeName());
     verifyBucketName(args.getBucketName());
+    if (!OzoneManagerVersion.STORAGE_POLICY_SUPPORT.isSupportedBy(omVersion)) {

Review Comment:
   Should this check be little narrower, because it rejects even when args 
carries no storage policy. OM validator also rejects only when a field is set. 
I mean, the OM validator rejects only when `storagePolicy, 
allowFallbackStoragePolicy or unsetStoragePolicy` is set.  Could something like 
below be better , so client and server stay consistent ?
   
   `(args.getStoragePolicy() != null || args.getAllowFallbackStoragePolicy() != 
null || Boolean.TRUE.equals(args.getUnsetStoragePolicy()))`



##########
hadoop-ozone/client/src/test/java/org/apache/hadoop/ozone/client/rpc/TestRpcClient.java:
##########
@@ -810,6 +811,119 @@ public OMResponse submitRequest(OMRequest request) throws 
IOException {
     }
   }
 
+  /**
+   * A storage policy field is sent only to an OM that supports it, and a 
request without one is never rejected.
+   */
+  @ParameterizedTest
+  @EnumSource(value = OzoneManagerVersion.class, mode = 
EnumSource.Mode.EXCLUDE, names = "UNKNOWN_VERSION")
+  public void 
testCreateBucketWithStoragePolicyRequiresSupportedOmVersion(OzoneManagerVersion 
version)
+      throws IOException {
+    List<BucketInfo> requests = new ArrayList<>();
+    OmTransport transport = new MockOmTransport() {
+      @Override
+      public OMResponse submitRequest(OMRequest request) throws IOException {
+        if (request.getCmdType() == Type.ServiceList) {
+          return 
OMResponse.newBuilder().setCmdType(Type.ServiceList).setStatus(Status.OK).setSuccess(true)
+              
.setServiceListResponse(ServiceListResponse.newBuilder().addServiceInfo(om(version).getProtobuf()))
+              .build();
+        }
+        if (request.getCmdType() == Type.CreateBucket) {
+          requests.add(request.getCreateBucketRequest().getBucketInfo());
+          throw new IOException("captured");
+        }
+        return super.submitRequest(request);
+      }
+    };
+    RpcClient client = createRpcClient(transport);
+    try {
+      IOException withoutPolicyError = assertThrows(IOException.class, () -> 
client.createBucket(
+          "vol", "bucket", BucketArgs.newBuilder().build()));
+      IOException withPolicyError = assertThrows(IOException.class, () -> 
client.createBucket(
+          "vol", "bucket", 
BucketArgs.newBuilder().setStoragePolicy(OzoneStoragePolicy.COLD).build()));
+      IOException withFallbackError = assertThrows(IOException.class, () -> 
client.createBucket(
+          "vol", "bucket", 
BucketArgs.newBuilder().setAllowFallbackStoragePolicy(false).build()));
+
+      assertThat(withoutPolicyError).hasMessage("captured");
+      assertThat(requests.get(0).hasStoragePolicy()).isFalse();
+      assertThat(requests.get(0).hasAllowFallbackStoragePolicy()).isFalse();
+      if (OzoneManagerVersion.STORAGE_POLICY_SUPPORT.isSupportedBy(version)) {
+        assertThat(withPolicyError).hasMessage("captured");
+        assertThat(withFallbackError).hasMessage("captured");
+        assertThat(requests).hasSize(3);
+        
assertThat(requests.get(1).getStoragePolicy()).isEqualTo(OzoneStoragePolicy.toProto(OzoneStoragePolicy.COLD));
+        assertThat(requests.get(2).hasAllowFallbackStoragePolicy()).isTrue();
+        assertThat(requests.get(2).getAllowFallbackStoragePolicy()).isFalse();
+      } else {
+        assertThat(withPolicyError).hasMessage("OzoneManager does not support 
storage policy");
+        assertThat(withFallbackError).hasMessage("OzoneManager does not 
support storage policy");
+        assertThat(requests).hasSize(1);
+      }
+    } finally {
+      client.close();
+    }
+  }
+
+  /**
+   * Setting a storage policy needs an OM that supports it, whatever the 
arguments are. This includes
+   * arguments that carry no storage policy field, since the method is a 
public storage policy API.
+   */
+  @ParameterizedTest
+  @EnumSource(value = OzoneManagerVersion.class, mode = 
EnumSource.Mode.EXCLUDE, names = "UNKNOWN_VERSION")
+  public void 
testSetBucketStoragePolicyRequiresSupportedOmVersion(OzoneManagerVersion 
version)
+      throws IOException {
+    List<OzoneManagerProtocolProtos.BucketArgs> requests = new ArrayList<>();
+    OmTransport transport = new MockOmTransport() {
+      @Override
+      public OMResponse submitRequest(OMRequest request) throws IOException {
+        if (request.getCmdType() == Type.ServiceList) {
+          return 
OMResponse.newBuilder().setCmdType(Type.ServiceList).setStatus(Status.OK).setSuccess(true)
+              
.setServiceListResponse(ServiceListResponse.newBuilder().addServiceInfo(om(version).getProtobuf()))
+              .build();

Review Comment:
   This ServiceList mock block is now copied three times in this test class.  A 
small helper method such as `transportWithOmVersion(version, Type, captor)` 
would reduce the repetition.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to