From b8702aaa4c695e04bf45feb760ee692808e68063 Mon Sep 17 00:00:00 2001 From: YangKian <45479280+YangKian@users.noreply.github.com> Date: Mon, 27 May 2024 12:30:59 +0800 Subject: [PATCH] hadmin: improvement Connector commands (#1822) * extending the fields returned by the listConnector command * rename recoverConnector to resumeConnector * add deleteConnector command --- hstream-admin/app/admin.hs | 7 +++---- .../server/HStream/Admin/Server/Types.hs | 18 ++++++++++++------ hstream/src/HStream/Server/Handler/Admin.hs | 9 +++++++-- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/hstream-admin/app/admin.hs b/hstream-admin/app/admin.hs index 29b75230b..94ab2f210 100644 --- a/hstream-admin/app/admin.hs +++ b/hstream-admin/app/admin.hs @@ -1,5 +1,3 @@ -{-# LANGUAGE BangPatterns #-} - module Main (main) where import Data.List (uncons) @@ -33,7 +31,7 @@ main = do -- -- data Cli = ServerCli Server.Cli -- | StoreCli ... -data Cli = ServerCli Server.Cli +newtype Cli = ServerCli Server.Cli cliParser :: O.Parser Cli cliParser = @@ -72,7 +70,8 @@ runServerCli' s (Server.ServerAdminCmd adminCmd) = do Server.AdminStreamCommand (Server.StreamCmdDelete sid _) -> (True, sid) Server.AdminSubscriptionCommand (Server.SubscriptionCmdDelete sid _) -> (True, sid) Server.AdminSubscriptionCommand (Server.SubscriptionCmdDescribe sid) -> (True, sid) - Server.AdminConnectorCommand (Server.ConnectorCmdRecover cId) -> (True, cId) + 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 5a3e8c89e..7a861b189 100644 --- a/hstream-admin/server/HStream/Admin/Server/Types.hs +++ b/hstream-admin/server/HStream/Admin/Server/Types.hs @@ -243,23 +243,29 @@ queryCmdParser = O.hsubparser data ConnectorCommand = ConnectorCmdList - | ConnectorCmdRecover Text + | ConnectorCmdResume Text | ConnectorCmdDescribe Text + | ConnectorCmdDelete Text deriving (Show) connectorCmdParser :: O.Parser ConnectorCommand connectorCmdParser = O.hsubparser ( O.command "list" (O.info (pure ConnectorCmdList) (O.progDesc "Get all connectors")) - <> O.command "recover" (O.info (ConnectorCmdRecover <$> O.strOption ( O.long "id" - <> O.short 'i' - <> O.metavar "CONNECTOR_ID" - <> O.help "The ID of the connector")) - (O.progDesc "Recover specific connector")) + <> O.command "resume" (O.info (ConnectorCmdResume <$> O.strOption ( O.long "id" + <> O.short 'i' + <> O.metavar "CONNECTOR_ID" + <> O.help "The ID of the connector")) + (O.progDesc "Resume specific connector")) <> O.command "describe" (O.info (ConnectorCmdDescribe <$> O.strOption ( O.long "id" <> O.short 'i' <> 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 af9210981..e71b7ce4a 100644 --- a/hstream/src/HStream/Server/Handler/Admin.hs +++ b/hstream/src/HStream/Server/Handler/Admin.hs @@ -435,17 +435,19 @@ runQuery sc AT.QueryCmdList = do runConnector :: ServerContext -> AT.ConnectorCommand -> IO Text runConnector ServerContext{..} AT.ConnectorCmdList = do connectors <- HC.listIOTasks scIOWorker - let headers = ["Connector Name" :: Text, "Type", "Target", "Status", "CreatedTime"] + let headers = ["Connector Name" :: Text, "Type", "Target", "Node", "Task ID", "Status", "CreatedTime"] rows <- forM connectors $ \API.Connector{..} -> do return [ connectorName , connectorType , connectorTarget + , connectorNode + , connectorTaskId , connectorStatus , maybe "unknown" (Text.pack . show . timestampToMsTimestamp) connectorCreationTime ] let content = Aeson.object ["headers" .= headers, "rows" .= rows] return $ AT.tableResponse content -runConnector ServerContext{..} (AT.ConnectorCmdRecover cId) = do +runConnector ServerContext{..} (AT.ConnectorCmdResume cId) = do HC.recoverTask scIOWorker cId API.Connector{..} <- HC.showIOTask_ scIOWorker cId let headers = ["Connector Name" :: Text, "Type", "Target", "Status", "Config"] @@ -473,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