mchades commented on code in PR #5908:
URL: https://github.com/apache/gravitino/pull/5908#discussion_r1893592144


##########
core/src/main/java/org/apache/gravitino/catalog/ModelOperationDispatcher.java:
##########
@@ -40,40 +49,114 @@ public ModelOperationDispatcher(
 
   @Override
   public NameIdentifier[] listModels(Namespace namespace) throws 
NoSuchSchemaException {
-    throw new UnsupportedOperationException("Not implemented");
+    return TreeLockUtils.doWithTreeLock(
+        NameIdentifier.of(namespace.levels()),
+        LockType.READ,
+        () ->
+            doWithCatalog(
+                getCatalogIdentifier(NameIdentifier.of(namespace.levels())),
+                c -> c.doWithModelOps(m -> m.listModels(namespace)),
+                NoSuchSchemaException.class));
   }
 
   @Override
   public Model getModel(NameIdentifier ident) throws NoSuchModelException {
-    throw new UnsupportedOperationException("Not implemented");
+    NameIdentifier catalogIdent = getCatalogIdentifier(ident);
+    Model model =
+        TreeLockUtils.doWithTreeLock(
+            ident,
+            LockType.READ,
+            () ->
+                doWithCatalog(
+                    catalogIdent,
+                    c -> c.doWithModelOps(m -> m.getModel(ident)),
+                    NoSuchModelException.class));
+
+    return EntityCombinedModel.of(model)
+        .withHiddenPropertiesSet(
+            getHiddenPropertyNames(
+                catalogIdent, HasPropertyMetadata::modelPropertiesMetadata, 
model.properties()));
   }
 
   @Override
   public Model registerModel(NameIdentifier ident, String comment, Map<String, 
String> properties)
       throws NoSuchModelException, ModelAlreadyExistsException {
-    throw new UnsupportedOperationException("Not implemented");
+    NameIdentifier catalogIdent = getCatalogIdentifier(ident);
+    Map<String, String> updatedProperties = 
checkAndUpdateProperties(catalogIdent, properties);
+
+    Model registeredModel =
+        TreeLockUtils.doWithTreeLock(
+            NameIdentifier.of(ident.namespace().levels()),
+            LockType.WRITE,
+            () ->
+                doWithCatalog(
+                    catalogIdent,
+                    c -> c.doWithModelOps(m -> m.registerModel(ident, comment, 
updatedProperties)),
+                    NoSuchSchemaException.class,
+                    ModelAlreadyExistsException.class));
+
+    return EntityCombinedModel.of(registeredModel)
+        .withHiddenPropertiesSet(
+            getHiddenPropertyNames(
+                catalogIdent,
+                HasPropertyMetadata::modelPropertiesMetadata,
+                registeredModel.properties()));
   }
 
   @Override
   public boolean deleteModel(NameIdentifier ident) {
-    throw new UnsupportedOperationException("Not implemented");
+    return TreeLockUtils.doWithTreeLock(
+        NameIdentifier.of(ident.namespace().levels()),
+        LockType.WRITE,
+        () ->
+            doWithCatalog(
+                getCatalogIdentifier(ident),
+                c -> c.doWithModelOps(m -> m.deleteModel(ident)),
+                RuntimeException.class));
   }
 
   @Override
   public int[] listModelVersions(NameIdentifier ident) throws 
NoSuchModelException {
-    throw new UnsupportedOperationException("Not implemented");
+    return TreeLockUtils.doWithTreeLock(
+        ident,
+        LockType.READ,
+        () ->
+            doWithCatalog(
+                getCatalogIdentifier(ident),
+                c -> c.doWithModelOps(m -> m.listModelVersions(ident)),
+                NoSuchModelException.class));
   }
 
   @Override
   public ModelVersion getModelVersion(NameIdentifier ident, int version)
       throws NoSuchModelVersionException {
-    throw new UnsupportedOperationException("Not implemented");
+    return internalGetModelVersion(
+        ident,
+        () ->
+            TreeLockUtils.doWithTreeLock(
+                NameIdentifierUtil.toModelVersionIdentifier(ident, version),
+                LockType.READ,
+                () ->
+                    doWithCatalog(
+                        getCatalogIdentifier(ident),
+                        c -> c.doWithModelOps(m -> m.getModelVersion(ident, 
version)),
+                        NoSuchModelVersionException.class)));
   }
 
   @Override
   public ModelVersion getModelVersion(NameIdentifier ident, String alias)
       throws NoSuchModelVersionException {
-    throw new UnsupportedOperationException("Not implemented");
+    return internalGetModelVersion(
+        ident,
+        () ->
+            TreeLockUtils.doWithTreeLock(
+                NameIdentifierUtil.toModelVersionIdentifier(ident, alias),

Review Comment:
   here lock the model version by model `name identifier` and `alias`, above 
137 line lock the model version by model `name identifier` and `version number`.
   
   when the alias and version point to the same model version, they will obtain 
two read locks, is it expected?



-- 
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]

Reply via email to