Skip to content

Commit

Permalink
hadmin: improvement Connector commands (#1822)
Browse files Browse the repository at this point in the history
* extending the fields returned by the listConnector command
* rename recoverConnector to resumeConnector
* add deleteConnector command
  • Loading branch information
YangKian authored May 27, 2024
1 parent 1f351c8 commit b8702aa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
7 changes: 3 additions & 4 deletions hstream-admin/app/admin.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{-# LANGUAGE BangPatterns #-}

module Main (main) where

import Data.List (uncons)
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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, "")

Expand Down
18 changes: 12 additions & 6 deletions hstream-admin/server/HStream/Admin/Server/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
)

-------------------------------------------------------------------------------
Expand Down
9 changes: 7 additions & 2 deletions hstream/src/HStream/Server/Handler/Admin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b8702aa

Please sign in to comment.