[Add] add force-delete model in daemon.
authorSuyeon Kim <suyeon5.kim@samsung.com>
Wed, 3 Apr 2024 00:43:56 +0000 (09:43 +0900)
committerjaeyun-jung <39614140+jaeyun-jung@users.noreply.github.com>
Fri, 5 Apr 2024 09:25:21 +0000 (18:25 +0900)
In rpk uninstall, The target model will be deteted, even if the model is activated.
Add force-delete model in daemon.

Signed-off-by: Suyeon Kim <suyeon5.kim@samsung.com>
daemon/dbus-interface.h
daemon/include/mlops-agent-interface.h
daemon/mlops-agent-interface.c
daemon/model-dbus-impl.cc
daemon/service-db-util.h
daemon/service-db.cc
daemon/service-db.hh
dbus/model-dbus.xml

index b381c90..e0015f2 100644 (file)
@@ -47,6 +47,7 @@
 #define DBUS_MODEL_I_HANDLER_GET_ACTIVATED      "handle-get-activated"
 #define DBUS_MODEL_I_HANDLER_GET_ALL            "handle-get-all"
 #define DBUS_MODEL_I_HANDLER_DELETE             "handle-delete"
+#define DBUS_MODEL_I_HANDLER_DELETE_FORCE       "handle-delete-force"
 
 /* Resource Interface */
 #define DBUS_RESOURCE_INTERFACE         "org.tizen.machinelearning.service.resource"
index adee390..a9b1d6e 100644 (file)
@@ -146,6 +146,17 @@ int ml_agent_model_get_all (const char *name, char **model_info);
 int ml_agent_model_delete (const char *name, const uint32_t version);
 
 /**
+ * @brief An interface exported for removing the model of @a name and @a version.
+ * @details If version is 0, this function removes all registered model of @a name.
+ * @param[in] name A name indicating the model that would be removed.
+ * @param[in] version A version for identifying a specific model.
+ * @param[in] force A force to forcibly delete a specific model.
+ * @return 0 on success, a negative error value if failed.
+ */
+int ml_agent_model_delete_force (
+    const char *name, const uint32_t version, const gboolean force);
+
+/**
  * @brief An interface exported for adding the resource.
  * @param[in] name A name indicating the resource.
  * @param[in] path A path that specifies the location of the resource.
index ded8abd..864a50e 100644 (file)
@@ -490,6 +490,33 @@ ml_agent_model_delete (const char *name, const uint32_t version)
 }
 
 /**
+ * @brief An interface exported for forcibly removing the model of @a name and @a version if @a force is true.
+ */
+int
+ml_agent_model_delete_force (const char *name, const uint32_t version, const gboolean force)
+{
+  MachinelearningServiceModel *mlsm;
+  gboolean result;
+  gint ret;
+
+  if (!STR_IS_VALID (name)) {
+    g_return_val_if_reached (-EINVAL);
+  }
+
+  mlsm = _get_proxy_new_for_bus_sync (ML_AGENT_SERVICE_MODEL);
+  if (!mlsm) {
+    g_return_val_if_reached (-EIO);
+  }
+
+  result = machinelearning_service_model_call_delete_force_sync (
+      mlsm, name, version, force, &ret, NULL, NULL);
+  g_object_unref (mlsm);
+
+  g_return_val_if_fail (ret == 0 && result, ret);
+  return 0;
+}
+
+/**
  * @brief An interface exported for adding the resource.
  */
 int
index c474db7..3545260 100644 (file)
@@ -195,6 +195,28 @@ gdbus_cb_model_delete (MachinelearningServiceModel *obj,
 }
 
 /**
+ * @brief The callback function of delete method
+ *
+ * @param obj Proxy instance.
+ * @param invoc Method invocation handle.
+ * @param name The name of target model.
+ * @param version The version of target model.
+ * @param force If the force is set to @c TRUE, the target model will be forced to delete.
+ * @return @c TRUE if the request is handled. FALSE if the service is not available.
+ */
+static gboolean
+gdbus_cb_model_delete_force (MachinelearningServiceModel *obj,
+    GDBusMethodInvocation *invoc, const gchar *name, const guint version, const gboolean force)
+{
+  gint ret = 0;
+
+  ret = svcdb_model_delete_force (name, version, force);
+  machinelearning_service_model_complete_delete_force (obj, invoc, ret);
+
+  return TRUE;
+}
+
+/**
  * @brief Event handler list of Model interface
  */
 static struct gdbus_signal_info handler_infos[] = {
@@ -240,6 +262,12 @@ static struct gdbus_signal_info handler_infos[] = {
       .cb_data = NULL,
       .handler_id = 0,
   },
+  {
+      .signal_name = DBUS_MODEL_I_HANDLER_DELETE_FORCE,
+      .cb = G_CALLBACK (gdbus_cb_model_delete_force),
+      .cb_data = NULL,
+      .handler_id = 0,
+  },
 };
 
 /**
index 2a01809..e98bac0 100644 (file)
@@ -29,6 +29,7 @@ gint svcdb_model_get (const gchar *name, const guint version, gchar **model_info
 gint svcdb_model_get_activated (const gchar *name, gchar **model_info);
 gint svcdb_model_get_all (const gchar *name, gchar **model_info);
 gint svcdb_model_delete (const gchar *name, const guint version);
+gint svcdb_model_delete_force (const gchar *name, const guint version, const gboolean force);
 gint svcdb_resource_add (const gchar *name, const gchar *path, const gchar *description, const gchar *app_info);
 gint svcdb_resource_get (const gchar *name, gchar **res_info);
 gint svcdb_resource_delete (const gchar *name);
index f73cbbc..a82a211 100644 (file)
@@ -675,9 +675,10 @@ MLServiceDB::get_model (const std::string name, const gint version, gchar **mode
  * @brief Delete the model.
  * @param[in] name The unique name to delete.
  * @param[in] version The version of the model to delete.
+ * @param[in] force The model to delete by force (default is false). 
  */
 void
-MLServiceDB::delete_model (const std::string name, const guint version)
+MLServiceDB::delete_model (const std::string name, const guint version, const gboolean force)
 {
   char *sql;
   sqlite3_stmt *res;
@@ -695,7 +696,10 @@ MLServiceDB::delete_model (const std::string name, const guint version)
   }
 
   if (version > 0U) {
-    if (is_model_activated (key_with_prefix, version))
+    if (force)
+      ml_logw ("The model with name %s and version %u may be activated, delete it from ml-service.",
+          name.c_str (), version);
+    else if (is_model_activated (key_with_prefix, version))
       throw std::invalid_argument ("The model with name " + name
                                    + " and version " + std::to_string (version)
                                    + " is activated, cannot delete it.");
@@ -1149,6 +1153,33 @@ svcdb_model_delete (const gchar *name, const guint version)
 }
 
 /**
+ * @brief Delete the model.
+ * @param[in] name The unique name to delete.
+ * @param[in] version The version of the model to delete.
+ * @param[in] force If the force is set to @c TRUE, the target model will be forced to delete.
+ * @return @c 0 on success. Otherwise a negative error value.
+ */
+gint
+svcdb_model_delete_force (const gchar *name, const guint version, const gboolean force)
+{
+  gint ret = 0;
+  MLServiceDB *db = svcdb_get ();
+
+  try {
+    db->delete_model (name, version, force);
+  } catch (const std::invalid_argument &e) {
+    ml_loge ("%s", e.what ());
+    ret = -EINVAL;
+  } catch (const std::exception &e) {
+    ml_loge ("%s", e.what ());
+    ret = -EIO;
+  }
+
+  return ret;
+}
+
+
+/**
  * @brief Set the resource with given name.
  * @param[in] name Unique name of ml-resource.
  * @param[in] path The path to be stored.
index 00fba39..221bbe0 100644 (file)
@@ -39,7 +39,8 @@ class MLServiceDB
       const guint version, const std::string description);
   virtual void activate_model (const std::string name, const guint version);
   virtual void get_model (const std::string name, const gint version, gchar **model);
-  virtual void delete_model (const std::string name, const guint version);
+  virtual void delete_model (
+      const std::string name, const guint version, const gboolean force = FALSE);
   virtual void set_resource (const std::string name, const std::string path,
       const std::string description, const std::string app_info);
   virtual void get_resource (const std::string name, gchar **resource);
index 4f42586..62af552 100644 (file)
       <arg type="u" name="version" direction="in" />
       <arg type="i" name="result" direction="out" />
     </method>
+    <method name="DeleteForce">
+      <arg type="s" name="name" direction="in" />
+      <arg type="u" name="version" direction="in" />
+      <arg type="b" name="force" direction="in" />
+      <arg type="i" name="result" direction="out" />
+    </method>
   </interface>
 </node>