World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#10660] fix: Move model version request validation inside try block (#10663)
yunhwan1205285d4e03
diff --git a/server/src/main/java/org/apache/gravitino/server/web/rest/ModelOperations.java b/server/src/main/java/org/apache/gravitino/server/web/rest/ModelOperations.javaindex 66b292b2cf..3c5dd63946 100644--- a/server/src/main/java/org/apache/gravitino/server/web/rest/ModelOperations.java+++ b/server/src/main/java/org/apache/gravitino/server/web/rest/ModelOperations.java@@ -180,13 +180,12 @@ public class ModelOperations {request.getName());try {- request.validate();- NameIdentifier modelId =- NameIdentifierUtil.ofModel(metalake, catalog, schema, request.getName());-return Utils.doAs(httpRequest,() -> {+ request.validate();+ NameIdentifier modelId =+ NameIdentifierUtil.ofModel(metalake, catalog, schema, request.getName());Model m =modelDispatcher.registerModel(modelId, request.getComment(), request.getProperties());@@ -422,11 +421,10 @@ public class ModelOperations {NameIdentifier modelId = NameIdentifierUtil.ofModel(metalake, catalog, schema, model);try {- request.validate();-return Utils.doAs(httpRequest,() -> {+ request.validate();Map<String, String> tmpUris =Optional.ofNullable(request.getUris()).orElse(Collections.emptyMap());ImmutableMap.Builder<String, String> uris =@@ -575,7 +573,6 @@ public class ModelOperations {schema,model,version);- request.validate();try {NameIdentifier modelId = NameIdentifierUtil.ofModel(metalake, catalog, schema, model);@@ -630,7 +627,6 @@ public class ModelOperations {schema,model,alias);- request.validate();try {NameIdentifier modelId = NameIdentifierUtil.ofModel(metalake, catalog, schema, model);diff --git a/server/src/main/java/org/apache/gravitino/server/web/rest/PartitionOperations.java b/server/src/main/java/org/apache/gravitino/server/web/rest/PartitionOperations.javaindex cc46d88bf5..85aebb6fdd 100644--- a/server/src/main/java/org/apache/gravitino/server/web/rest/PartitionOperations.java+++ b/server/src/main/java/org/apache/gravitino/server/web/rest/PartitionOperations.java@@ -181,24 +181,24 @@ public class PartitionOperations {@PathParam("table") @AuthorizationMetadata(type = Entity.EntityType.TABLE) String table,AddPartitionsRequest request) {try {- if (request == null || request.getPartitions() == null) {- throw new IllegalArgumentException("partitions must not be null");- }- LOG.info(- "Received add {} partition(s) request for table {}.{}.{}.{} ",- request.getPartitions().length,- metalake,- catalog,- schema,- table);- Preconditions.checkArgument(- request.getPartitions().length == 1, "Only one partition is supported");-- request.validate();-return Utils.doAs(httpRequest,() -> {+ if (request == null || request.getPartitions() == null) {+ throw new IllegalArgumentException("partitions must not be null");+ }+ LOG.info(+ "Received add {} partition(s) request for table {}.{}.{}.{} ",+ request.getPartitions().length,+ metalake,+ catalog,+ schema,+ table);+ Preconditions.checkArgument(+ request.getPartitions().length == 1, "Only one partition is supported");++ request.validate();+NameIdentifier tableIdent = NameIdentifier.of(metalake, catalog, schema, table);Partition p = dispatcher.addPartition(tableIdent, fromDTO(request.getPartitions()[0]));Response response =diff --git a/server/src/test/java/org/apache/gravitino/server/web/rest/TestModelOperations.java b/server/src/test/java/org/apache/gravitino/server/web/rest/TestModelOperations.javaindex 521096a717..12c1695768 100644--- a/server/src/test/java/org/apache/gravitino/server/web/rest/TestModelOperations.java+++ b/server/src/test/java/org/apache/gravitino/server/web/rest/TestModelOperations.java@@ -1395,6 +1395,46 @@ public class TestModelOperations extends BaseOperationsTest {Assertions.assertEquals(uris, modelVersion.uris());}+ @Test+ void testAlterModelVersionWithNullUpdates() {+ ModelVersionUpdatesRequest req = new ModelVersionUpdatesRequest(null);++ Response resp =+ target(modelPath())+ .path("model1")+ .path("versions")+ .path("0")+ .request(MediaType.APPLICATION_JSON_TYPE)+ .accept("application/vnd.gravitino.v1+json")+ .put(Entity.entity(req, MediaType.APPLICATION_JSON_TYPE));++ Assertions.assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), resp.getStatus());++ ErrorResponse errorResp = resp.readEntity(ErrorResponse.class);+ Assertions.assertEquals(ErrorConstants.ILLEGAL_ARGUMENTS_CODE, errorResp.getCode());+ Assertions.assertEquals(IllegalArgumentException.class.getSimpleName(), errorResp.getType());+ }++ @Test+ void testAlterModelVersionByAliasWithNullUpdates() {+ ModelVersionUpdatesRequest req = new ModelVersionUpdatesRequest(null);++ Response resp =+ target(modelPath())+ .path("model1")+ .path("aliases")+ .path("alias1")+ .request(MediaType.APPLICATION_JSON_TYPE)+ .accept("application/vnd.gravitino.v1+json")+ .put(Entity.entity(req, MediaType.APPLICATION_JSON_TYPE));++ Assertions.assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), resp.getStatus());++ ErrorResponse errorResp = resp.readEntity(ErrorResponse.class);+ Assertions.assertEquals(ErrorConstants.ILLEGAL_ARGUMENTS_CODE, errorResp.getCode());+ Assertions.assertEquals(IllegalArgumentException.class.getSimpleName(), errorResp.getType());+ }+@Testpublic void testGetModelVersionUri() {NameIdentifier modelIdent = NameIdentifierUtil.ofModel(metalake, catalog, schema, "model1");