Skip to content

Commit

Permalink
Update /api/status to match output from lorax-composer
Browse files Browse the repository at this point in the history
Fixes issue weldr#71

Output now looks like:

{
    "build": "b18d239",
    "backend": "weldr",
    "schema_version": "4",
    "db_supported": true,
    "api": "0",
    "db_version": "4"
}
  • Loading branch information
bcl committed May 15, 2018
1 parent b18d239 commit 13090d3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
21 changes: 10 additions & 11 deletions src/BDCS/API/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import Control.Monad.Except(runExceptT)
import Control.Monad.Logger(runFileLoggingT, runStderrLoggingT)
import Control.Monad.STM(atomically)
import Data.Aeson
import Data.Int(Int64)
import Data.IORef(IORef, atomicModifyIORef', newIORef, readIORef)
import qualified Data.Map as Map
import Data.Sequence((|>), Seq(..), deleteAt, empty, findIndexL, index)
Expand Down Expand Up @@ -85,16 +84,16 @@ instance ToJSON ServerStatus where
, "build" .= srvBuild
, "schema_version" .= srvSchemaVersion
, "db_version" .= srvDbVersion
, "db_supported" .= srvSupported ]
, "db_supported" .= srvDbSupported ]

instance FromJSON ServerStatus where
parseJSON = withObject "server status" $ \o -> do
srvApi <- o .: "api"
srvBackend <- o .: "backend"
srvBuild <- o .: "build"
srvSchema <- o .: "schema_version"
srvDb <- o .: "db_version"
srvSupported <- o .: "db_supported"
srvApi <- o .: "api"
srvBackend <- o .: "backend"
srvBuild <- o .: "build"
srvSchemaVersion <- o .: "schema_version"
srvDbVersion <- o .: "db_version"
srvDbSupported <- o .: "db_supported"
return ServerStatus{..}

-- | The /status route
Expand All @@ -108,13 +107,13 @@ maxComposes = 1
serverStatus :: ServerConfig -> Handler ServerStatus
serverStatus ServerConfig{..} = do
version <- dbVersion
return (ServerStatus "0" "weldr" buildVersion (show schemaVersion) version (schemaVersion == version))
return (ServerStatus "0" "weldr" buildVersion (show schemaVersion) (show version) (schemaVersion == version))
where
dbVersion = do
result <- runExceptT $ runSqlPool getDbVersion cfgPool
case result of
Left _ -> return "0"
Right version -> return $ show version
Left _ -> return 0
Right version -> return version

commonServer :: ServerConfig -> Server CommonAPI
commonServer cfg = serverStatus cfg
Expand Down
6 changes: 3 additions & 3 deletions tests/ServerSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -317,17 +317,17 @@ modulesListResponse4 = ModulesListResponse
checkStatusResponse :: ClientM Bool
checkStatusResponse = do
response <- getStatus
return $ weldrOK response && schemaOK response && dbOK response && srvSupported response
return $ weldrOK response && schemaOK response && dbOK response && srvDbSupported response
where
weldrOK :: ServerStatus -> Bool
weldrOK response = srvBackend response == "weldr"

schemaOK :: ServerStatus -> Bool
schemaOK response = srvSchema response == schemaVersion
schemaOK response = srvSchemaVersion response == show schemaVersion

-- During testing the schema and the database should always be equal
dbOK :: ServerStatus -> Bool
dbOK response = srvDb response == schemaVersion
dbOK response = srvDbVersion response == show schemaVersion



Expand Down
4 changes: 2 additions & 2 deletions tools/bdcs-api-server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
-- along with bdcs-api. If not, see <http://www.gnu.org/licenses/>.

import BDCS.API.Server(runServer)
import BDCS.API.Version(apiVersion)
import BDCS.API.Version(buildVersion)
import Cmdline(CliOptions(..),
parseArgs)
import Control.Monad(when)
Expand All @@ -25,6 +25,6 @@ main :: IO ()
main = do
opts <- parseArgs

when (optShowVersion opts) $ putStrLn ("bdcs-api " ++ apiVersion)
when (optShowVersion opts) $ putStrLn ("bdcs-api " ++ buildVersion)

runServer (optPort opts) (optBDCS opts) (optRecipeRepo opts) (optMetadataDB opts)

0 comments on commit 13090d3

Please sign in to comment.