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>
#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"
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.
}
/**
+ * @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
}
/**
+ * @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[] = {
.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,
+ },
};
/**
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);
* @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;
}
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.");
}
/**
+ * @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.
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);
<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>