Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hadmin: Update cli command #1822

Merged
merged 3 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading