From 926318dc72623ca2a83be1de1f3ec708dbce04ab Mon Sep 17 00:00:00 2001
From: YangKian <1207783292@qq.com>
Date: Mon, 27 May 2024 10:47:49 +0800
Subject: [PATCH] hadmin: add deleteConnector command

---
 hstream-admin/app/admin.hs                         | 1 +
 hstream-admin/server/HStream/Admin/Server/Types.hs | 6 ++++++
 hstream/src/HStream/Server/Handler/Admin.hs        | 3 +++
 3 files changed, 10 insertions(+)

diff --git a/hstream-admin/app/admin.hs b/hstream-admin/app/admin.hs
index 9f2bb8415..94ab2f210 100644
--- a/hstream-admin/app/admin.hs
+++ b/hstream-admin/app/admin.hs
@@ -71,6 +71,7 @@ runServerCli' s (Server.ServerAdminCmd adminCmd) = do
       Server.AdminSubscriptionCommand (Server.SubscriptionCmdDelete sid _) -> (True, sid)
       Server.AdminSubscriptionCommand (Server.SubscriptionCmdDescribe sid) -> (True, sid)
       Server.AdminConnectorCommand (Server.ConnectorCmdResume cId)         -> (True, cId)
+      Server.AdminConnectorCommand (Server.ConnectorCmdDelete cId)         -> (True, cId)
       Server.AdminConnectorCommand (Server.ConnectorCmdDescribe cId)       -> (True, cId)
       _                                                                    -> (False, "")
 
diff --git a/hstream-admin/server/HStream/Admin/Server/Types.hs b/hstream-admin/server/HStream/Admin/Server/Types.hs
index a8ac47a3e..7a861b189 100644
--- a/hstream-admin/server/HStream/Admin/Server/Types.hs
+++ b/hstream-admin/server/HStream/Admin/Server/Types.hs
@@ -245,6 +245,7 @@ data ConnectorCommand
   = ConnectorCmdList
   | ConnectorCmdResume Text
   | ConnectorCmdDescribe Text
+  | ConnectorCmdDelete Text
   deriving (Show)
 
 connectorCmdParser :: O.Parser ConnectorCommand
@@ -260,6 +261,11 @@ connectorCmdParser = O.hsubparser
                                                                       <> O.metavar "CONNECTOR_ID"
                                                                       <> O.help "The ID of the connector"))
                                  (O.progDesc "Get the details of specific connector"))
+ <> O.command "delete" (O.info (ConnectorCmdDelete <$> O.strOption ( O.long "id"
+                                                                  <> O.short 'i'
+                                                                  <> O.metavar "CONNECTOR_ID"
+                                                                  <> O.help "The ID of the connector"))
+                                 (O.progDesc "Delete specific connector"))
   )
 
 -------------------------------------------------------------------------------
diff --git a/hstream/src/HStream/Server/Handler/Admin.hs b/hstream/src/HStream/Server/Handler/Admin.hs
index 6bf4bd596..e71b7ce4a 100644
--- a/hstream/src/HStream/Server/Handler/Admin.hs
+++ b/hstream/src/HStream/Server/Handler/Admin.hs
@@ -475,6 +475,9 @@ runConnector ServerContext{..} (AT.ConnectorCmdDescribe cId) = do
              ]]
   let content = Aeson.object ["headers" .= headers, "rows" .= rows]
   return $ AT.tableResponse content
+runConnector ServerContext{..} (AT.ConnectorCmdDelete cId) = do
+  void $ HC.deleteIOTask scIOWorker cId
+  return $ AT.plainResponse "OK"
 
 -------------------------------------------------------------------------------
 -- Admin Status Command