World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#7436] feat(model): Implement REST APIs for model version with multiple URIs (#8173)
XiaoZ66583b6ce10d
diff --git a/clients/client-java/src/main/java/org/apache/gravitino/client/DTOConverters.java b/clients/client-java/src/main/java/org/apache/gravitino/client/DTOConverters.javaindex e848466a89..4657644e1f 100644--- a/clients/client-java/src/main/java/org/apache/gravitino/client/DTOConverters.java+++ b/clients/client-java/src/main/java/org/apache/gravitino/client/DTOConverters.java@@ -435,8 +435,18 @@ class DTOConverters {((ModelVersionChange.RemoveProperty) change).property());} else if (change instanceof ModelVersionChange.UpdateUri) {+ ModelVersionChange.UpdateUri updateUri = (ModelVersionChange.UpdateUri) change;return new ModelVersionUpdateRequest.UpdateModelVersionUriRequest(- ((ModelVersionChange.UpdateUri) change).newUri());+ updateUri.uriName(), updateUri.newUri());++ } else if (change instanceof ModelVersionChange.AddUri) {+ ModelVersionChange.AddUri addUri = (ModelVersionChange.AddUri) change;+ return new ModelVersionUpdateRequest.AddModelVersionUriRequest(+ addUri.uriName(), addUri.uri());++ } else if (change instanceof ModelVersionChange.RemoveUri) {+ return new ModelVersionUpdateRequest.RemoveModelVersionUriRequest(+ ((ModelVersionChange.RemoveUri) change).uriName());} else if (change instanceof ModelVersionChange.UpdateAliases) {ModelVersionChange.UpdateAliases updateAliases = (ModelVersionChange.UpdateAliases) change;diff --git a/clients/client-java/src/test/java/org/apache/gravitino/client/TestGenericModelCatalog.java b/clients/client-java/src/test/java/org/apache/gravitino/client/TestGenericModelCatalog.javaindex 22f031dc60..47d00a6599 100644--- a/clients/client-java/src/test/java/org/apache/gravitino/client/TestGenericModelCatalog.java+++ b/clients/client-java/src/test/java/org/apache/gravitino/client/TestGenericModelCatalog.java@@ -861,7 +861,7 @@ public class TestGenericModelCatalog extends TestBase {int version, String uri, String[] aliases, String comment, Map<String, String> properties) {return ModelVersionDTO.builder().withVersion(version)- .withUri(uri)+ .withUris(ImmutableMap.of(ModelVersion.URI_NAME_UNKNOWN, uri)).withAliases(aliases).withComment(comment).withProperties(properties)diff --git a/common/src/main/java/org/apache/gravitino/dto/model/ModelVersionDTO.java b/common/src/main/java/org/apache/gravitino/dto/model/ModelVersionDTO.javaindex e887ba5bdb..c82d565947 100644--- a/common/src/main/java/org/apache/gravitino/dto/model/ModelVersionDTO.java+++ b/common/src/main/java/org/apache/gravitino/dto/model/ModelVersionDTO.java@@ -48,6 +48,9 @@ public class ModelVersionDTO implements ModelVersion {@JsonProperty("uri")private String uri;+ @JsonProperty("uris")+ private Map<String, String> uris;+@JsonProperty("properties")private Map<String, String> properties;@@ -75,8 +78,8 @@ public class ModelVersionDTO implements ModelVersion {}@Override- public String uri() {- return uri;+ public Map<String, String> uris() {+ return uris;}@Override@@ -98,7 +101,7 @@ public class ModelVersionDTO implements ModelVersion {private int version;private String comment;private String[] aliases;- private String uri;+ private Map<String, String> uris;private Map<String, String> properties;private AuditDTO audit;@@ -136,13 +139,13 @@ public class ModelVersionDTO implements ModelVersion {}/**- * Sets the URI of the model version.+ * Sets the URIs of the model version.*- * @param uri The URI.+ * @param uris The URIs.* @return The builder.*/- public Builder withUri(String uri) {- this.uri = uri;+ public Builder withUris(Map<String, String> uris) {+ this.uris = uris;return this;}@@ -175,10 +178,24 @@ public class ModelVersionDTO implements ModelVersion {*/public ModelVersionDTO build() {Preconditions.checkArgument(version >= 0, "Version must be non-negative");- Preconditions.checkArgument(StringUtils.isNotBlank(uri), "URI cannot be null or empty");Preconditions.checkArgument(audit != null, "Audit cannot be null");-- return new ModelVersionDTO(version, comment, aliases, uri, properties, audit);+ Preconditions.checkArgument(+ uris != null && !uris.isEmpty(),+ "At least one URI needs to be set for the model version");+ uris.forEach(+ (n, u) -> {+ Preconditions.checkArgument(StringUtils.isNotBlank(n), "URI name must not be blank");+ Preconditions.checkArgument(StringUtils.isNotBlank(u), "URI must not be blank");+ });++ return new ModelVersionDTO(+ version,+ comment,+ aliases,+ uris.get(ModelVersion.URI_NAME_UNKNOWN),+ uris,+ properties,+ audit);}}}diff --git a/common/src/main/java/org/apache/gravitino/dto/requests/ModelVersionLinkRequest.java b/common/src/main/java/org/apache/gravitino/dto/requests/ModelVersionLinkRequest.javaindex 24e5932932..297e07182f 100644--- a/common/src/main/java/org/apache/gravitino/dto/requests/ModelVersionLinkRequest.java+++ b/common/src/main/java/org/apache/gravitino/dto/requests/ModelVersionLinkRequest.java@@ -21,6 +21,7 @@ package org.apache.gravitino.dto.requests;import com.fasterxml.jackson.annotation.JsonProperty;import com.google.common.base.Preconditions;import java.util.Map;+import javax.annotation.Nullable;import lombok.AllArgsConstructor;import lombok.EqualsAndHashCode;import lombok.Getter;@@ -38,9 +39,14 @@ import org.apache.gravitino.rest.RESTRequest;@AllArgsConstructorpublic class ModelVersionLinkRequest implements RESTRequest {+ @Nullable@JsonProperty("uri")private String uri;+ @Nullable+ @JsonProperty("uris")+ private Map<String, String> uris;+@JsonProperty("aliases")private String[] aliases;@@ -50,11 +56,34 @@ public class ModelVersionLinkRequest implements RESTRequest {@JsonProperty("properties")private Map<String, String> properties;+ /**+ * Constructor for ModelVersionLinkRequest.+ *+ * @param uri the uri of the model version.+ * @param aliases the aliases of the model version.+ * @param comment the comment of the model version.+ * @param properties the properties of the model version.+ */+ public ModelVersionLinkRequest(+ String uri, String[] aliases, String comment, Map<String, String> properties) {+ this(uri, null, aliases, comment, properties);+ }++ /**+ * Constructor for ModelVersionLinkRequest+ *+ * @param uris the uris of the model version.+ * @param aliases the aliases of the model version.+ * @param comment the comment of the model version.+ * @param properties the properties of the model version.+ */+ public ModelVersionLinkRequest(+ Map<String, String> uris, String[] aliases, String comment, Map<String, String> properties) {+ this(null, uris, aliases, comment, properties);+ }+@Overridepublic void validate() throws IllegalArgumentException {- Preconditions.checkArgument(- StringUtils.isNotBlank(uri), "\"uri\" field is required and cannot be empty");-if (aliases != null && aliases.length > 0) {for (String alias : aliases) {Preconditions.checkArgument(@@ -63,5 +92,17 @@ public class ModelVersionLinkRequest implements RESTRequest {!NumberUtils.isCreatable(alias), "alias must not be a number or a number string");}}++ if (uris == null || uris.isEmpty()) {+ Preconditions.checkArgument(+ StringUtils.isNotBlank(uri),+ "\"uri\" field cannot be empty if uris field is null or empty");+ } else {+ uris.forEach(+ (n, u) -> {+ Preconditions.checkArgument(StringUtils.isNotBlank(n), "URI name must not be blank");+ Preconditions.checkArgument(StringUtils.isNotBlank(u), "URI must not be blank");+ });+ }}}diff --git a/common/src/main/java/org/apache/gravitino/dto/requests/ModelVersionUpdateRequest.java b/common/src/main/java/org/apache/gravitino/dto/requests/ModelVersionUpdateRequest.javaindex 395dfd08c6..e5d282df64 100644--- a/common/src/main/java/org/apache/gravitino/dto/requests/ModelVersionUpdateRequest.java+++ b/common/src/main/java/org/apache/gravitino/dto/requests/ModelVersionUpdateRequest.java@@ -49,6 +49,12 @@ import org.apache.gravitino.rest.RESTRequest;@JsonSubTypes.Type(value = ModelVersionUpdateRequest.UpdateModelVersionUriRequest.class,name = "updateUri"),+ @JsonSubTypes.Type(+ value = ModelVersionUpdateRequest.AddModelVersionUriRequest.class,+ name = "addUri"),+ @JsonSubTypes.Type(+ value = ModelVersionUpdateRequest.RemoveModelVersionUriRequest.class,+ name = "removeUri"),@JsonSubTypes.Type(value = ModelVersionUpdateRequest.UpdateModelVersionAliasesRequest.class,name = "updateAliases")@@ -150,12 +156,27 @@ public interface ModelVersionUpdateRequest extends RESTRequest {@ToString@Getterclass UpdateModelVersionUriRequest implements ModelVersionUpdateRequest {+ @JsonProperty("uriName")+ private final String uriName;+@JsonProperty("newUri")private final String newUri;+ /**+ * Constructor for UpdateModelVersionUriRequest.+ *+ * @param newUri the new uri of the model version.+ */+ public UpdateModelVersionUriRequest(String newUri) {+ this(null, newUri);+ }+/** {@inheritDoc} */@Overridepublic ModelVersionChange modelVersionChange() {+ if (StringUtils.isNotBlank(uriName)) {+ return ModelVersionChange.updateUri(uriName, newUri);+ }return ModelVersionChange.updateUri(newUri);}@@ -171,6 +192,67 @@ public interface ModelVersionUpdateRequest extends RESTRequest {}}+ /** Request to add the URI of a model version. */+ @EqualsAndHashCode+ @AllArgsConstructor+ @NoArgsConstructor(force = true)+ @ToString+ @Getter+ class AddModelVersionUriRequest implements ModelVersionUpdateRequest {+ @JsonProperty("uriName")+ private final String uriName;++ @JsonProperty("uri")+ private final String uri;++ /** {@inheritDoc} */+ @Override+ public ModelVersionChange modelVersionChange() {+ return ModelVersionChange.addUri(uriName, uri);+ }++ /**+ * Validates the request.+ *+ * @throws IllegalArgumentException If the request is invalid, this exception is thrown.+ */+ @Override+ public void validate() throws IllegalArgumentException {+ Preconditions.checkArgument(+ StringUtils.isNotBlank(uriName), "\"uriName\" field is required and cannot be empty");+ Preconditions.checkArgument(+ StringUtils.isNotBlank(uri), "\"uri\" field is required and cannot be empty");+ }+ }++ /** Request to remove the URI of a model version. */+ @EqualsAndHashCode+ @AllArgsConstructor+ @NoArgsConstructor(force = true)+ @ToString+ @Getter+ class RemoveModelVersionUriRequest implements ModelVersionUpdateRequest {+ @JsonProperty("uriName")+ private final String uriName;++ /** {@inheritDoc} */+ @Override+ public ModelVersionChange modelVersionChange() {+ return ModelVersionChange.removeUri(uriName);+ }++ /**+ * Validates the request.+ *+ * @throws IllegalArgumentException If the request is invalid, this exception is thrown.+ */+ @Override+ public void validate() throws IllegalArgumentException {+ Preconditions.checkArgument(+ StringUtils.isNotBlank(uriName), "\"uriName\" field is required and cannot be empty");+ }+ }+/** Request to update the aliases of a model version. */@EqualsAndHashCode@AllArgsConstructordiff --git a/common/src/main/java/org/apache/gravitino/dto/responses/ModelVersionUriResponse.java b/common/src/main/java/org/apache/gravitino/dto/responses/ModelVersionUriResponse.javanew file mode 100644index 0000000000..17e9d75d53--- /dev/null+++ b/common/src/main/java/org/apache/gravitino/dto/responses/ModelVersionUriResponse.java@@ -0,0 +1,62 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one+ * or more contributor license agreements. See the NOTICE file+ * distributed with this work for additional information+ * regarding copyright ownership. The ASF licenses this file+ * to you 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 org.apache.gravitino.dto.responses;++import com.fasterxml.jackson.annotation.JsonProperty;+import com.google.common.base.Preconditions;+import lombok.EqualsAndHashCode;+import lombok.Getter;+import lombok.ToString;+import org.apache.commons.lang3.StringUtils;++/** Response for the model version uri. */+@Getter+@ToString+@EqualsAndHashCode(callSuper = true)+public class ModelVersionUriResponse extends BaseResponse {+ @JsonProperty("uri")+ private final String uri;++ /** Default constructor for ModelVersionUriResponse. */+ public ModelVersionUriResponse() {+ super(0);+ this.uri = null;+ }++ /**+ * Constructor for ModelVersionUriResponse.+ *+ * @param uri the uri of the model version+ */+ public ModelVersionUriResponse(String uri) {+ super(0);+ this.uri = uri;+ }++ /**+ * Validates the response.+ *+ * @throws IllegalArgumentException if the response is invalid.+ */+ @Override+ public void validate() throws IllegalArgumentException {+ super.validate();+ Preconditions.checkArgument(StringUtils.isNotBlank(uri), "uri must not be blank");+ }+}diff --git a/common/src/main/java/org/apache/gravitino/dto/util/DTOConverters.java b/common/src/main/java/org/apache/gravitino/dto/util/DTOConverters.javaindex fac66a4e99..29ac24fec7 100644--- a/common/src/main/java/org/apache/gravitino/dto/util/DTOConverters.java+++ b/common/src/main/java/org/apache/gravitino/dto/util/DTOConverters.java@@ -720,7 +720,7 @@ public class DTOConverters {.withVersion(modelVersion.version()).withComment(modelVersion.comment()).withAliases(modelVersion.aliases())- .withUri(modelVersion.uri())+ .withUris(modelVersion.uris()).withProperties(modelVersion.properties()).withAudit(toDTO(modelVersion.auditInfo())).build();diff --git a/common/src/test/java/org/apache/gravitino/dto/model/TestModelVersionDTO.java b/common/src/test/java/org/apache/gravitino/dto/model/TestModelVersionDTO.javaindex 5251246c37..0233bf5219 100644--- a/common/src/test/java/org/apache/gravitino/dto/model/TestModelVersionDTO.java+++ b/common/src/test/java/org/apache/gravitino/dto/model/TestModelVersionDTO.java@@ -21,6 +21,7 @@ package org.apache.gravitino.dto.model;import com.fasterxml.jackson.core.JsonProcessingException;import com.google.common.collect.ImmutableMap;import java.time.Instant;+import java.util.Collections;import java.util.Map;import org.apache.gravitino.dto.AuditDTO;import org.apache.gravitino.json.JsonUtils;@@ -39,7 +40,7 @@ public class TestModelVersionDTO {.withVersion(0).withComment("model version comment").withAliases(new String[] {"alias1", "alias2"})- .withUri("uri")+ .withUris(ImmutableMap.of("n1", "u1")).withProperties(props).withAudit(audit).build();@@ -55,7 +56,7 @@ public class TestModelVersionDTO {ModelVersionDTO.builder().withVersion(0).withComment("model version comment")- .withUri("uri")+ .withUris(ImmutableMap.of("n1", "u1")).withProperties(props).withAudit(audit).build();@@ -73,7 +74,7 @@ public class TestModelVersionDTO {.withVersion(0).withComment("model version comment").withAliases(new String[] {})- .withUri("uri")+ .withUris(ImmutableMap.of("n1", "u1")).withProperties(props).withAudit(audit).build();@@ -87,7 +88,11 @@ public class TestModelVersionDTO {// Test with null comment and propertiesModelVersionDTO modelVersionDTO3 =- ModelVersionDTO.builder().withVersion(0).withUri("uri").withAudit(audit).build();+ ModelVersionDTO.builder()+ .withVersion(0)+ .withUris(ImmutableMap.of("n1", "u1"))+ .withAudit(audit)+ .build();String serJson3 = JsonUtils.objectMapper().writeValueAsString(modelVersionDTO3);ModelVersionDTO deserModelVersionDTO3 =@@ -101,33 +106,21 @@ public class TestModelVersionDTO {@Testpublic void testInvalidModelVersionDTO() {Assertions.assertThrows(- IllegalArgumentException.class,- () -> {- ModelVersionDTO.builder().build();- });+ IllegalArgumentException.class, () -> ModelVersionDTO.builder().build());Assertions.assertThrows(- IllegalArgumentException.class,- () -> {- ModelVersionDTO.builder().withVersion(-1).build();- });+ IllegalArgumentException.class, () -> ModelVersionDTO.builder().withVersion(-1).build());Assertions.assertThrows(- IllegalArgumentException.class,- () -> {- ModelVersionDTO.builder().withVersion(0).build();- });+ IllegalArgumentException.class, () -> ModelVersionDTO.builder().withVersion(0).build());Assertions.assertThrows(IllegalArgumentException.class,- () -> {- ModelVersionDTO.builder().withVersion(0).withUri("").build();- });+ () -> ModelVersionDTO.builder().withVersion(0).withUris(Collections.emptyMap()).build());Assertions.assertThrows(IllegalArgumentException.class,- () -> {- ModelVersionDTO.builder().withVersion(0).withUri("uri").build();- });+ () ->+ ModelVersionDTO.builder().withVersion(0).withUris(ImmutableMap.of("n1", "u1")).build());}}diff --git a/common/src/test/java/org/apache/gravitino/dto/responses/TestResponses.java b/common/src/test/java/org/apache/gravitino/dto/responses/TestResponses.javaindex c3385cb9e8..781f5ef449 100644--- a/common/src/test/java/org/apache/gravitino/dto/responses/TestResponses.java+++ b/common/src/test/java/org/apache/gravitino/dto/responses/TestResponses.java@@ -457,7 +457,7 @@ public class TestResponses {.withVersion(0).withComment("model version1 comment").withAliases(new String[] {"alias1", "alias2"})- .withUri("uri")+ .withUris(ImmutableMap.of("n1", "u1")).withProperties(ImmutableMap.of("key", "value")).withAudit(AuditDTO.builder().withCreator("user1").withCreateTime(Instant.now()).build())@@ -467,7 +467,7 @@ public class TestResponses {.withVersion(1).withComment("model version2 comment").withAliases(new String[] {"alias3", "alias4"})- .withUri("uri")+ .withUris(ImmutableMap.of("n2", "u2")).withProperties(ImmutableMap.of("key", "value")).withAudit(AuditDTO.builder().withCreator("user1").withCreateTime(Instant.now()).build())@@ -494,7 +494,7 @@ public class TestResponses {.withVersion(0).withComment("model version comment").withAliases(new String[] {"alias1", "alias2"})- .withUri("uri")+ .withUris(ImmutableMap.of("n1", "u1")).withProperties(props).withAudit(audit).build();diff --git a/docs/open-api/models.yaml b/docs/open-api/models.yamlindex 09eba18c0b..79e94ea06d 100644--- a/docs/open-api/models.yaml+++ b/docs/open-api/models.yaml@@ -366,6 +366,82 @@ paths:"5xx":$ref: "./openapi.yaml#/components/responses/ServerErrorResponse"+ /metalakes/{metalake}/catalogs/{catalog}/schemas/{schema}/models/{model}/versions/{version}/uri:+ parameters:+ - $ref: "./openapi.yaml#/components/parameters/metalake"+ - $ref: "./openapi.yaml#/components/parameters/catalog"+ - $ref: "./openapi.yaml#/components/parameters/schema"+ - $ref: "./openapi.yaml#/components/parameters/model"+ - $ref: "#/components/parameters/version"++ get:+ tags:+ - model+ summary: Get model version uri+ operationId: getModelVersionUri+ parameters:+ - name: uriName+ in: query+ required: false+ schema:+ type: string+ default: null+ description: The uri name of the model version+ responses:+ "200":+ $ref: "#/components/responses/ModelVersionUriResponse"+ "404":+ description: Not Found - The target model version uri does not exist+ content:+ application/vnd.gravitino.v1+json:+ schema:+ $ref: "./openapi.yaml#/components/schemas/ErrorModel"+ examples:+ NoSuchModelVersionException:+ $ref: "#/components/examples/NoSuchModelVersionException"+ NoSuchModelVersionURINameException:+ $ref: "#/components/examples/NoSuchModelVersionURINameException"+ "5xx":+ $ref: "./openapi.yaml#/components/responses/ServerErrorResponse"++ /metalakes/{metalake}/catalogs/{catalog}/schemas/{schema}/models/{model}/aliases/{alias}/uri:+ parameters:+ - $ref: "./openapi.yaml#/components/parameters/metalake"+ - $ref: "./openapi.yaml#/components/parameters/catalog"+ - $ref: "./openapi.yaml#/components/parameters/schema"+ - $ref: "./openapi.yaml#/components/parameters/model"+ - $ref: "#/components/parameters/alias"++ get:+ tags:+ - model+ summary: Get model version uri by alias+ operationId: getModelVersionUriByAlias+ parameters:+ - name: uriName+ in: query+ required: false+ schema:+ type: string+ default: null+ description: The uri name of the model version+ responses:+ "200":+ $ref: "#/components/responses/ModelVersionUriResponse"+ "404":+ description: Not Found - The target model version uri does not exist+ content:+ application/vnd.gravitino.v1+json:+ schema:+ $ref: "./openapi.yaml#/components/schemas/ErrorModel"+ examples:+ NoSuchModelVersionException:+ $ref: "#/components/examples/NoSuchModelVersionException"+ NoSuchModelVersionURINameException:+ $ref: "#/components/examples/NoSuchModelVersionURINameException"+ "5xx":+ $ref: "./openapi.yaml#/components/responses/ServerErrorResponse"+components:parameters:version:@@ -422,13 +498,20 @@ components:ModelVersion:type: objectrequired:- - uri- version- auditproperties:uri:type: stringdescription: The uri of the model version+ nullable: true+ uris:+ type: object+ description: The uris of the model version+ nullable: true+ default: {}+ additionalProperties:+ type: stringversion:type: integerdescription: The version of the model@@ -578,12 +661,18 @@ components:ModelVersionLinkRequest:type: object- required:- - uriproperties:uri:type: stringdescription: The uri of the model version+ nullable: true+ uris:+ type: object+ description: The uris of the model version, either uris or uri should be provided+ nullable: true+ default: {}+ additionalProperties:+ type: stringaliases:type: arraydescription: The aliases of the model version@@ -619,6 +708,8 @@ components:- $ref: "#/components/schemas/SetModelVersionPropertyRequest"- $ref: "#/components/schemas/RemoveModelVersionPropertyRequest"- $ref: "#/components/schemas/UpdateModelVersionUriRequest"+ - $ref: "#/components/schemas/AddModelVersionUriRequest"+ - $ref: "#/components/schemas/RemoveModelVersionUriRequest"- $ref: "#/components/schemas/UpdateModelVersionAliasesRequest"discriminator:propertyName: "@type"@@ -627,6 +718,8 @@ components:setProperty: "#/components/schemas/SetModelVersionPropertyRequest"removeProperty: "#/components/schemas/RemoveModelVersionPropertyRequest"updateUri: "#/components/schemas/UpdateModelVersionUriRequest"+ addUri: "#/components/schemas/AddModelVersionUriRequest"+ removeUri: "#/components/schemas/RemoveModelVersionUriRequest"updateAliases: "#/components/schemas/UpdateModelVersionAliasesRequest"UpdateModelVersionCommentRequest:@@ -703,9 +796,54 @@ components:newUri:type: stringdescription: The new uri of the model version+ uriName:+ type: string+ description: The uri name of the model version to be updatedexample: {"@type": "updateUri",- "newUri": "s3://path/to/model"+ "newUri": "s3://path/to/model",+ "uriName": "default-uri-name"+ }++ AddModelVersionUriRequest:+ type: object+ required:+ - "@type"+ - uriName+ - uri+ properties:+ "@type":+ type: string+ enum:+ - "addUri"+ uriName:+ type: string+ description: The uri name of the model version to be added+ uri:+ type: string+ description: The uri of the model version to be added+ example: {+ "@type": "addUri",+ "uriName": "default-uri-name",+ "uri": "s3://path/to/model"+ }++ RemoveModelVersionUriRequest:+ type: object+ required:+ - "@type"+ - uriName+ properties:+ "@type":+ type: string+ enum:+ - "removeUri"+ uriName:+ type: string+ description: The uri name of the model version to be removed+ example: {+ "@type": "removeUri",+ "uriName": "default-uri-name"}UpdateModelVersionAliasesRequest:@@ -807,6 +945,26 @@ components:ModelResponse:$ref: "#/components/examples/ModelVersionResponse"+ ModelVersionUriResponse:+ description: The response of model version uri+ content:+ application/vnd.gravitino.v1+json:+ schema:+ type: object+ properties:+ code:+ type: integer+ format: int32+ description: Status code of the response+ enum:+ - 0+ uri:+ type: string+ description: The uri of the model version+ examples:+ ModelResponse:+ $ref: "#/components/examples/ModelVersionUriResponse"+examples:ModelRegisterRequest:value: {@@ -882,7 +1040,10 @@ components:value: {"code": 0,"modelVersion" : {- "uri": "hdfs://path/to/model",+ "uris": {+ "hdfs": "hdfs://path/to/model",+ "s3": "s3://path/to/model"+ },"version": 0,"aliases": ["alias1", "alias2"],"comment": "This is a comment",@@ -899,6 +1060,12 @@ components:}}+ ModelVersionUriResponse:+ value: {+ "code": 0,+ "uri": "hdfs://path/to/model"+ }+ModelAlreadyExistsException:value: {"code": 1004,@@ -938,3 +1105,13 @@ components:"org.apache.gravitino.exceptions.NoSuchModelVersionException: Model version does not exist"]}++ NoSuchModelVersionURINameException:+ value: {+ "code": 1003,+ "type": "NoSuchModelVersionURINameException",+ "message": "Model version uri does not exist",+ "stack": [+ "org.apache.gravitino.exceptions.NoSuchModelVersionURINameException: Model version uri does not exist"+ ]+ }\ No newline at end of filediff --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 0ad3875922..a77b47ef88 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@@ -20,7 +20,11 @@ package org.apache.gravitino.server.web.rest;import com.codahale.metrics.annotation.ResponseMetered;import com.codahale.metrics.annotation.Timed;+import com.google.common.collect.ImmutableMap;import java.util.Arrays;+import java.util.Collections;+import java.util.Map;+import java.util.Optional;import javax.inject.Inject;import javax.servlet.http.HttpServletRequest;import javax.ws.rs.DELETE;@@ -52,6 +56,7 @@ import org.apache.gravitino.dto.responses.ModelResponse;import org.apache.gravitino.dto.responses.ModelVersionInfoListResponse;import org.apache.gravitino.dto.responses.ModelVersionListResponse;import org.apache.gravitino.dto.responses.ModelVersionResponse;+import org.apache.gravitino.dto.responses.ModelVersionUriResponse;import org.apache.gravitino.dto.util.DTOConverters;import org.apache.gravitino.metrics.MetricNames;import org.apache.gravitino.model.Model;@@ -407,9 +412,15 @@ public class ModelOperations {return Utils.doAs(httpRequest,() -> {+ Map<String, String> tmpUris =+ Optional.ofNullable(request.getUris()).orElse(Collections.emptyMap());+ ImmutableMap.Builder<String, String> uris =+ ImmutableMap.<String, String>builder().putAll(tmpUris);+ Optional.ofNullable(request.getUri())+ .ifPresent(uri -> uris.put(ModelVersion.URI_NAME_UNKNOWN, uri));modelDispatcher.linkModelVersion(modelId,- request.getUri(),+ uris.buildKeepingLast(),request.getAliases(),request.getComment(),request.getProperties());@@ -662,6 +673,86 @@ public class ModelOperations {}}+ @GET+ @Path("{model}/versions/{version}/uri")+ @Produces("application/vnd.gravitino.v1+json")+ @Timed(name = "get-model-version-uri." + MetricNames.HTTP_PROCESS_DURATION, absolute = true)+ @ResponseMetered(name = "get-model-version-uri", absolute = true)+ @AuthorizationExpression(+ expression = loadModelAuthorizationExpression,+ accessMetadataType = MetadataObject.Type.MODEL)+ public Response getModelVersionUri(+ @PathParam("metalake") @AuthorizationMetadata(type = Entity.EntityType.METALAKE)+ String metalake,+ @PathParam("catalog") @AuthorizationMetadata(type = Entity.EntityType.CATALOG) String catalog,+ @PathParam("schema") @AuthorizationMetadata(type = Entity.EntityType.SCHEMA) String schema,+ @PathParam("model") @AuthorizationMetadata(type = Entity.EntityType.MODEL) String model,+ @PathParam("version") int version,+ @QueryParam("uriName") String uriName) {+ LOG.info(+ "Received get model version uri request: {}.{}.{}.{}.{}, uriName: {}",+ metalake,+ catalog,+ schema,+ model,+ version,+ uriName);+ NameIdentifier modelId = NameIdentifierUtil.ofModel(metalake, catalog, schema, model);++ try {+ return Utils.doAs(+ httpRequest,+ () -> {+ String uri = modelDispatcher.getModelVersionUri(modelId, version, uriName);+ return Utils.ok(new ModelVersionUriResponse(uri));+ });++ } catch (Exception e) {+ return ExceptionHandlers.handleModelException(+ OperationType.GET, versionString(model, version), schema, e);+ }+ }++ @GET+ @Path("{model}/aliases/{alias}/uri")+ @Produces("application/vnd.gravitino.v1+json")+ @Timed(name = "get-model-alias-uri." + MetricNames.HTTP_PROCESS_DURATION, absolute = true)+ @ResponseMetered(name = "get-model-alias-uri", absolute = true)+ @AuthorizationExpression(+ expression = loadModelAuthorizationExpression,+ accessMetadataType = MetadataObject.Type.MODEL)+ public Response getModelVersionUriByAlias(+ @PathParam("metalake") @AuthorizationMetadata(type = Entity.EntityType.METALAKE)+ String metalake,+ @PathParam("catalog") @AuthorizationMetadata(type = Entity.EntityType.CATALOG) String catalog,+ @PathParam("schema") @AuthorizationMetadata(type = Entity.EntityType.SCHEMA) String schema,+ @PathParam("model") @AuthorizationMetadata(type = Entity.EntityType.MODEL) String model,+ @PathParam("alias") String alias,+ @QueryParam("uriName") String uriName) {+ LOG.info(+ "Received get model version alias uri request: {}.{}.{}.{}.{}, uriName: {}",+ metalake,+ catalog,+ schema,+ model,+ alias,+ uriName);+ NameIdentifier modelId = NameIdentifierUtil.ofModel(metalake, catalog, schema, model);++ try {+ return Utils.doAs(+ httpRequest,+ () -> {+ String uri = modelDispatcher.getModelVersionUri(modelId, alias, uriName);+ return Utils.ok(new ModelVersionUriResponse(uri));+ });++ } catch (Exception e) {+ return ExceptionHandlers.handleModelException(+ OperationType.GET, aliasString(model, alias), schema, e);+ }+ }+private String versionString(String model, int version) {return model + " version(" + version + ")";}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 3068444dc8..02aaecc764 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@@ -52,6 +52,7 @@ import org.apache.gravitino.dto.responses.ModelResponse;import org.apache.gravitino.dto.responses.ModelVersionInfoListResponse;import org.apache.gravitino.dto.responses.ModelVersionListResponse;import org.apache.gravitino.dto.responses.ModelVersionResponse;+import org.apache.gravitino.dto.responses.ModelVersionUriResponse;import org.apache.gravitino.exceptions.ModelAlreadyExistsException;import org.apache.gravitino.exceptions.NoSuchModelException;import org.apache.gravitino.exceptions.NoSuchSchemaException;@@ -476,8 +477,9 @@ public class TestModelOperations extends BaseOperationsTest {NameIdentifier modelId = NameIdentifierUtil.ofModel(metalake, catalog, schema, "model1");ModelVersion[] expected =new ModelVersion[] {- mockModelVersion(0, "uri1", new String[] {"alias1"}, "comment1"),- mockModelVersion(1, "uri2", new String[] {"alias2", "alias3"}, "comment2")+ mockModelVersion(0, ImmutableMap.of("n1", "u1"), new String[] {"alias1"}, "comment1"),+ mockModelVersion(+ 1, ImmutableMap.of("n2", "u2"), new String[] {"alias2", "alias3"}, "comment2")};when(modelDispatcher.listModelVersionInfos(modelId)).thenReturn(expected);@@ -584,7 +586,7 @@ public class TestModelOperations extends BaseOperationsTest {public void testGetModelVersion() {NameIdentifier modelIdent = NameIdentifierUtil.ofModel(metalake, catalog, schema, "model1");ModelVersion mockModelVersion =- mockModelVersion(0, "uri1", new String[] {"alias1"}, "comment1");+ mockModelVersion(0, ImmutableMap.of("n1", "u1"), new String[] {"alias1"}, "comment1");when(modelDispatcher.getModelVersion(modelIdent, 0)).thenReturn(mockModelVersion);Response resp =@@ -710,7 +712,12 @@ public class TestModelOperations extends BaseOperationsTest {NameIdentifier modelIdent = NameIdentifierUtil.ofModel(metalake, catalog, schema, "model1");doNothing().when(modelDispatcher)- .linkModelVersion(modelIdent, "uri1", new String[] {"alias1"}, "comment1", properties);+ .linkModelVersion(+ modelIdent,+ ImmutableMap.of(ModelVersion.URI_NAME_UNKNOWN, "uri1"),+ new String[] {"alias1"},+ "comment1",+ properties);ModelVersionLinkRequest req =new ModelVersionLinkRequest("uri1", new String[] {"alias1"}, "comment1", properties);@@ -732,7 +739,12 @@ public class TestModelOperations extends BaseOperationsTest {// Test mock throw NoSuchModelExceptiondoThrow(new NoSuchModelException("mock error")).when(modelDispatcher)- .linkModelVersion(modelIdent, "uri1", new String[] {"alias1"}, "comment1", properties);+ .linkModelVersion(+ modelIdent,+ ImmutableMap.of(ModelVersion.URI_NAME_UNKNOWN, "uri1"),+ new String[] {"alias1"},+ "comment1",+ properties);Response resp1 =target(modelPath())@@ -751,7 +763,12 @@ public class TestModelOperations extends BaseOperationsTest {// Test mock throw ModelVersionAliasesAlreadyExistExceptiondoThrow(new ModelAlreadyExistsException("mock error")).when(modelDispatcher)- .linkModelVersion(modelIdent, "uri1", new String[] {"alias1"}, "comment1", properties);+ .linkModelVersion(+ modelIdent,+ ImmutableMap.of(ModelVersion.URI_NAME_UNKNOWN, "uri1"),+ new String[] {"alias1"},+ "comment1",+ properties);Response resp2 =target(modelPath())@@ -771,7 +788,97 @@ public class TestModelOperations extends BaseOperationsTest {// Test mock throw RuntimeExceptiondoThrow(new RuntimeException("mock error")).when(modelDispatcher)- .linkModelVersion(modelIdent, "uri1", new String[] {"alias1"}, "comment1", properties);+ .linkModelVersion(+ modelIdent,+ ImmutableMap.of(ModelVersion.URI_NAME_UNKNOWN, "uri1"),+ new String[] {"alias1"},+ "comment1",+ properties);++ Response resp3 =+ target(modelPath())+ .path("model1")+ .path("versions")+ .request(MediaType.APPLICATION_JSON_TYPE)+ .accept("application/vnd.gravitino.v1+json")+ .post(Entity.entity(req, MediaType.APPLICATION_JSON_TYPE));++ Assertions.assertEquals(+ Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), resp3.getStatus());++ ErrorResponse errorResp2 = resp3.readEntity(ErrorResponse.class);+ Assertions.assertEquals(ErrorConstants.INTERNAL_ERROR_CODE, errorResp2.getCode());+ Assertions.assertEquals(RuntimeException.class.getSimpleName(), errorResp2.getType());+ }++ @Test+ public void testLinkModelVersionWithMultipleUris() {+ NameIdentifier modelIdent = NameIdentifierUtil.ofModel(metalake, catalog, schema, "model1");+ Map<String, String> uris = ImmutableMap.of("n1", "u1", "n2", "u2");+ doNothing()+ .when(modelDispatcher)+ .linkModelVersion(modelIdent, uris, new String[] {"alias1"}, "comment1", properties);++ ModelVersionLinkRequest req =+ new ModelVersionLinkRequest(uris, new String[] {"alias1"}, "comment1", properties);++ Response resp =+ target(modelPath())+ .path("model1")+ .path("versions")+ .request(MediaType.APPLICATION_JSON_TYPE)+ .accept("application/vnd.gravitino.v1+json")+ .post(Entity.entity(req, MediaType.APPLICATION_JSON_TYPE));++ Assertions.assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());+ Assertions.assertEquals(MediaType.APPLICATION_JSON_TYPE, resp.getMediaType());++ BaseResponse baseResponse = resp.readEntity(BaseResponse.class);+ Assertions.assertEquals(0, baseResponse.getCode());++ // Test mock throw NoSuchModelException+ doThrow(new NoSuchModelException("mock error"))+ .when(modelDispatcher)+ .linkModelVersion(modelIdent, uris, new String[] {"alias1"}, "comment1", properties);++ Response resp1 =+ target(modelPath())+ .path("model1")+ .path("versions")+ .request(MediaType.APPLICATION_JSON_TYPE)+ .accept("application/vnd.gravitino.v1+json")+ .post(Entity.entity(req, MediaType.APPLICATION_JSON_TYPE));++ Assertions.assertEquals(Response.Status.NOT_FOUND.getStatusCode(), resp1.getStatus());++ ErrorResponse errorResp = resp1.readEntity(ErrorResponse.class);+ Assertions.assertEquals(ErrorConstants.NOT_FOUND_CODE, errorResp.getCode());+ Assertions.assertEquals(NoSuchModelException.class.getSimpleName(), errorResp.getType());++ // Test mock throw ModelVersionAliasesAlreadyExistException+ doThrow(new ModelAlreadyExistsException("mock error"))+ .when(modelDispatcher)+ .linkModelVersion(modelIdent, uris, new String[] {"alias1"}, "comment1", properties);++ Response resp2 =+ target(modelPath())+ .path("model1")+ .path("versions")+ .request(MediaType.APPLICATION_JSON_TYPE)+ .accept("application/vnd.gravitino.v1+json")+ .post(Entity.entity(req, MediaType.APPLICATION_JSON_TYPE));++ Assertions.assertEquals(Response.Status.CONFLICT.getStatusCode(), resp2.getStatus());++ ErrorResponse errorResp1 = resp2.readEntity(ErrorResponse.class);+ Assertions.assertEquals(ErrorConstants.ALREADY_EXISTS_CODE, errorResp1.getCode());+ Assertions.assertEquals(+ ModelAlreadyExistsException.class.getSimpleName(), errorResp1.getType());++ // Test mock throw RuntimeException+ doThrow(new RuntimeException("mock error"))+ .when(modelDispatcher)+ .linkModelVersion(modelIdent, uris, new String[] {"alias1"}, "comment1", properties);Response resp3 =target(modelPath())@@ -1084,12 +1191,12 @@ public class TestModelOperations extends BaseOperationsTest {void testUpdateModelVersionComment() {String modelName = "model1";String newComment = "new comment";- String uri = "uri1";+ Map<String, String> uris = ImmutableMap.of("n1", "u1");int version = 0;String[] alias = new String[] {"alias1"};NameIdentifier modelId = NameIdentifierUtil.ofModel(metalake, catalog, schema, modelName);- ModelVersion mockModelVersion = mockModelVersion(version, uri, alias, newComment);+ ModelVersion mockModelVersion = mockModelVersion(version, uris, alias, newComment);when(modelDispatcher.alterModelVersion(modelId, version, ModelVersionChange.updateComment(newComment)))@@ -1116,19 +1223,19 @@ public class TestModelOperations extends BaseOperationsTest {Assertions.assertEquals(newComment, modelVersion.comment());Assertions.assertArrayEquals(alias, modelVersion.aliases());Assertions.assertEquals(version, modelVersion.version());- Assertions.assertEquals(uri, modelVersion.uri());+ Assertions.assertEquals(uris, modelVersion.uris());}@Testvoid testUpdateModelVersionCommentByAlias() {String modelName = "model1";String newComment = "new comment";- String uri = "uri1";+ Map<String, String> uris = ImmutableMap.of("n1", "u1");int version = 0;String[] alias = new String[] {"alias1"};NameIdentifier modelId = NameIdentifierUtil.ofModel(metalake, catalog, schema, modelName);- ModelVersion mockModelVersion = mockModelVersion(version, uri, alias, newComment);+ ModelVersion mockModelVersion = mockModelVersion(version, uris, alias, newComment);when(modelDispatcher.alterModelVersion(modelId, alias[0], ModelVersionChange.updateComment(newComment)))@@ -1155,7 +1262,257 @@ public class TestModelOperations extends BaseOperationsTest {Assertions.assertEquals(newComment, modelVersion.comment());Assertions.assertArrayEquals(alias, modelVersion.aliases());Assertions.assertEquals(version, modelVersion.version());- Assertions.assertEquals(uri, modelVersion.uri());+ Assertions.assertEquals(uris, modelVersion.uris());+ }++ @Test+ void testUpdateModelVersionUri() {+ String modelName = "model1";+ String comment = "comment";+ Map<String, String> uris = ImmutableMap.of("n1", "u2");+ int version = 0;+ String[] alias = new String[] {"alias1"};++ NameIdentifier modelId = NameIdentifierUtil.ofModel(metalake, catalog, schema, modelName);+ ModelVersion mockModelVersion = mockModelVersion(version, uris, alias, comment);++ when(modelDispatcher.alterModelVersion(+ modelId, version, ModelVersionChange.updateUri("n1", "u2")))+ .thenReturn(mockModelVersion);++ ModelVersionUpdatesRequest req =+ new ModelVersionUpdatesRequest(+ Collections.singletonList(+ new ModelVersionUpdateRequest.UpdateModelVersionUriRequest("n1", "u2")));++ 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.OK.getStatusCode(), resp.getStatus());+ ModelVersionResponse modelVersionResponse = resp.readEntity(ModelVersionResponse.class);+ ModelVersionDTO modelVersion = modelVersionResponse.getModelVersion();++ Assertions.assertEquals(comment, modelVersion.comment());+ Assertions.assertArrayEquals(alias, modelVersion.aliases());+ Assertions.assertEquals(version, modelVersion.version());+ Assertions.assertEquals(uris, modelVersion.uris());+ }++ @Test+ void testAddModelVersionUri() {+ String modelName = "model1";+ String comment = "comment";+ Map<String, String> uris = ImmutableMap.of("n1", "u1", "n2", "u2");+ int version = 0;+ String[] alias = new String[] {"alias1"};++ NameIdentifier modelId = NameIdentifierUtil.ofModel(metalake, catalog, schema, modelName);+ ModelVersion mockModelVersion = mockModelVersion(version, uris, alias, comment);++ when(modelDispatcher.alterModelVersion(modelId, version, ModelVersionChange.addUri("n2", "u2")))+ .thenReturn(mockModelVersion);++ ModelVersionUpdatesRequest req =+ new ModelVersionUpdatesRequest(+ Collections.singletonList(+ new ModelVersionUpdateRequest.AddModelVersionUriRequest("n2", "u2")));++ 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.OK.getStatusCode(), resp.getStatus());+ ModelVersionResponse modelVersionResponse = resp.readEntity(ModelVersionResponse.class);+ ModelVersionDTO modelVersion = modelVersionResponse.getModelVersion();++ Assertions.assertEquals(comment, modelVersion.comment());+ Assertions.assertArrayEquals(alias, modelVersion.aliases());+ Assertions.assertEquals(version, modelVersion.version());+ Assertions.assertEquals(uris, modelVersion.uris());+ }++ @Test+ void testRemoveModelVersionUri() {+ String modelName = "model1";+ String comment = "comment";+ Map<String, String> uris = ImmutableMap.of("n2", "u2");+ int version = 0;+ String[] alias = new String[] {"alias1"};++ NameIdentifier modelId = NameIdentifierUtil.ofModel(metalake, catalog, schema, modelName);+ ModelVersion mockModelVersion = mockModelVersion(version, uris, alias, comment);++ when(modelDispatcher.alterModelVersion(modelId, version, ModelVersionChange.removeUri("n1")))+ .thenReturn(mockModelVersion);++ ModelVersionUpdatesRequest req =+ new ModelVersionUpdatesRequest(+ Collections.singletonList(+ new ModelVersionUpdateRequest.RemoveModelVersionUriRequest("n1")));++ 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.OK.getStatusCode(), resp.getStatus());+ ModelVersionResponse modelVersionResponse = resp.readEntity(ModelVersionResponse.class);+ ModelVersionDTO modelVersion = modelVersionResponse.getModelVersion();++ Assertions.assertEquals(comment, modelVersion.comment());+ Assertions.assertArrayEquals(alias, modelVersion.aliases());+ Assertions.assertEquals(version, modelVersion.version());+ Assertions.assertEquals(uris, modelVersion.uris());+ }++ @Test+ public void testGetModelVersionUri() {+ NameIdentifier modelIdent = NameIdentifierUtil.ofModel(metalake, catalog, schema, "model1");+ when(modelDispatcher.getModelVersionUri(modelIdent, 0, "n1")).thenReturn("u1");++ Response resp =+ target(modelPath())+ .path("model1")+ .path("versions")+ .path("0")+ .path("uri")+ .queryParam("uriName", "n1")+ .request(MediaType.APPLICATION_JSON_TYPE)+ .accept("application/vnd.gravitino.v1+json")+ .get();++ Assertions.assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());+ Assertions.assertEquals(MediaType.APPLICATION_JSON_TYPE, resp.getMediaType());++ ModelVersionUriResponse response = resp.readEntity(ModelVersionUriResponse.class);+ Assertions.assertEquals(0, response.getCode());+ Assertions.assertEquals("u1", response.getUri());++ // Test mock throw NoSuchModelVersionException+ doThrow(new NoSuchModelException("mock error"))+ .when(modelDispatcher)+ .getModelVersionUri(modelIdent, 0, "n1");++ Response resp1 =+ target(modelPath())+ .path("model1")+ .path("versions")+ .path("0")+ .path("uri")+ .queryParam("uriName", "n1")+ .request(MediaType.APPLICATION_JSON_TYPE)+ .accept("application/vnd.gravitino.v1+json")+ .get();++ Assertions.assertEquals(Response.Status.NOT_FOUND.getStatusCode(), resp1.getStatus());++ ErrorResponse errorResp = resp1.readEntity(ErrorResponse.class);+ Assertions.assertEquals(ErrorConstants.NOT_FOUND_CODE, errorResp.getCode());+ Assertions.assertEquals(NoSuchModelException.class.getSimpleName(), errorResp.getType());++ // Test mock throw RuntimeException+ doThrow(new RuntimeException("mock error"))+ .when(modelDispatcher)+ .getModelVersionUri(modelIdent, 0, "n1");++ Response resp2 =+ target(modelPath())+ .path("model1")+ .path("versions")+ .path("0")+ .path("uri")+ .queryParam("uriName", "n1")+ .request(MediaType.APPLICATION_JSON_TYPE)+ .accept("application/vnd.gravitino.v1+json")+ .get();++ Assertions.assertEquals(+ Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), resp2.getStatus());++ ErrorResponse errorResp1 = resp2.readEntity(ErrorResponse.class);+ Assertions.assertEquals(ErrorConstants.INTERNAL_ERROR_CODE, errorResp1.getCode());+ Assertions.assertEquals(RuntimeException.class.getSimpleName(), errorResp1.getType());++ // Test get model version by alias+ when(modelDispatcher.getModelVersionUri(modelIdent, "alias1", "n1")).thenReturn("u1");++ Response resp3 =+ target(modelPath())+ .path("model1")+ .path("aliases")+ .path("alias1")+ .path("uri")+ .queryParam("uriName", "n1")+ .request(MediaType.APPLICATION_JSON_TYPE)+ .accept("application/vnd.gravitino.v1+json")+ .get();++ Assertions.assertEquals(Response.Status.OK.getStatusCode(), resp3.getStatus());+ Assertions.assertEquals(MediaType.APPLICATION_JSON_TYPE, resp3.getMediaType());++ ModelVersionUriResponse response1 = resp3.readEntity(ModelVersionUriResponse.class);+ Assertions.assertEquals(0, response1.getCode());+ Assertions.assertEquals("u1", response1.getUri());++ // Test mock throw NoSuchModelVersionException+ doThrow(new NoSuchModelException("mock error"))+ .when(modelDispatcher)+ .getModelVersionUri(modelIdent, "alias1", "n1");++ Response resp4 =+ target(modelPath())+ .path("model1")+ .path("aliases")+ .path("alias1")+ .path("uri")+ .queryParam("uriName", "n1")+ .request(MediaType.APPLICATION_JSON_TYPE)+ .accept("application/vnd.gravitino.v1+json")+ .get();++ Assertions.assertEquals(Response.Status.NOT_FOUND.getStatusCode(), resp4.getStatus());++ ErrorResponse errorResp2 = resp4.readEntity(ErrorResponse.class);+ Assertions.assertEquals(ErrorConstants.NOT_FOUND_CODE, errorResp2.getCode());+ Assertions.assertEquals(NoSuchModelException.class.getSimpleName(), errorResp2.getType());++ // Test mock throw RuntimeException+ doThrow(new RuntimeException("mock error"))+ .when(modelDispatcher)+ .getModelVersionUri(modelIdent, "alias1", "n1");++ Response resp5 =+ target(modelPath())+ .path("model1")+ .path("aliases")+ .path("alias1")+ .path("uri")+ .queryParam("uriName", "n1")+ .request(MediaType.APPLICATION_JSON_TYPE)+ .accept("application/vnd.gravitino.v1+json")+ .get();++ Assertions.assertEquals(+ Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), resp5.getStatus());++ ErrorResponse errorResp3 = resp5.readEntity(ErrorResponse.class);+ Assertions.assertEquals(ErrorConstants.INTERNAL_ERROR_CODE, errorResp3.getCode());+ Assertions.assertEquals(RuntimeException.class.getSimpleName(), errorResp3.getType());}private String modelPath() {@@ -1183,10 +1540,11 @@ public class TestModelOperations extends BaseOperationsTest {return mockModel;}- private ModelVersion mockModelVersion(int version, String uri, String[] aliases, String comment) {+ private ModelVersion mockModelVersion(+ int version, Map<String, String> uris, String[] aliases, String comment) {ModelVersion mockModelVersion = mock(ModelVersion.class);when(mockModelVersion.version()).thenReturn(version);- when(mockModelVersion.uri()).thenReturn(uri);+ when(mockModelVersion.uris()).thenReturn(uris);when(mockModelVersion.aliases()).thenReturn(aliases);when(mockModelVersion.comment()).thenReturn(comment);when(mockModelVersion.properties()).thenReturn(properties);@@ -1209,7 +1567,7 @@ public class TestModelOperations extends BaseOperationsTest {private void compare(ModelVersion left, ModelVersion right) {Assertions.assertEquals(left.version(), right.version());- Assertions.assertEquals(left.uri(), right.uri());+ Assertions.assertEquals(left.uris(), right.uris());Assertions.assertArrayEquals(left.aliases(), right.aliases());Assertions.assertEquals(left.comment(), right.comment());Assertions.assertEquals(left.properties(), right.properties());