|
|
|
@ -1,23 +1,29 @@ |
|
|
|
|
|
|
|
|
|
|
|
module Main where |
|
|
|
module Main where |
|
|
|
|
|
|
|
|
|
|
|
import Data.Aeson |
|
|
|
import Data.Aeson |
|
|
|
import qualified Data.Text as T |
|
|
|
import qualified Data.ByteString.Lazy as BL |
|
|
|
import qualified Data.ByteString.Lazy as BL |
|
|
|
import qualified Data.Text as T |
|
|
|
|
|
|
|
|
|
|
|
import ATrade.MDS.Database |
|
|
|
import ATrade.MDS.Database |
|
|
|
import ATrade.MDS.HistoryServer |
|
|
|
import ATrade.MDS.HistoryServer |
|
|
|
|
|
|
|
|
|
|
|
import Control.Concurrent |
|
|
|
import Control.Concurrent |
|
|
|
import Control.Monad |
|
|
|
import Control.Monad |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import System.IO |
|
|
|
|
|
|
|
import System.Log.Formatter |
|
|
|
|
|
|
|
import System.Log.Handler (setFormatter) |
|
|
|
|
|
|
|
import System.Log.Handler.Simple |
|
|
|
|
|
|
|
import System.Log.Logger |
|
|
|
|
|
|
|
import System.ZMQ4 |
|
|
|
|
|
|
|
|
|
|
|
import System.ZMQ4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data MdsConfig = MdsConfig { |
|
|
|
data MdsConfig = MdsConfig { |
|
|
|
cfgDbPath :: T.Text, |
|
|
|
cfgDbPath :: T.Text, |
|
|
|
cfgDbName :: T.Text, |
|
|
|
cfgDbName :: T.Text, |
|
|
|
cfgDbAccount :: T.Text, |
|
|
|
cfgDbAccount :: T.Text, |
|
|
|
cfgDbPassword :: T.Text, |
|
|
|
cfgDbPassword :: T.Text, |
|
|
|
cfgQHPEndpoint :: T.Text, |
|
|
|
cfgQHPEndpoint :: T.Text, |
|
|
|
cfgHAPEndpoint :: T.Text |
|
|
|
cfgHAPEndpoint :: T.Text |
|
|
|
} deriving (Show, Eq) |
|
|
|
} deriving (Show, Eq) |
|
|
|
@ -32,27 +38,42 @@ instance FromJSON MdsConfig where |
|
|
|
v .: "qhp_endpoint" <*> |
|
|
|
v .: "qhp_endpoint" <*> |
|
|
|
v .: "hap_endpoint" |
|
|
|
v .: "hap_endpoint" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
initLogging :: IO () |
|
|
|
|
|
|
|
initLogging = do |
|
|
|
|
|
|
|
handler <- fileHandler "mds.log" DEBUG >>= |
|
|
|
|
|
|
|
(\x -> return $ |
|
|
|
|
|
|
|
setFormatter x (simpleLogFormatter "$utcTime\t {$loggername} <$prio> -> $msg")) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hSetBuffering stderr LineBuffering |
|
|
|
|
|
|
|
updateGlobalLogger rootLoggerName (setLevel DEBUG) |
|
|
|
|
|
|
|
updateGlobalLogger rootLoggerName (setHandlers [handler]) |
|
|
|
|
|
|
|
|
|
|
|
getConfig :: IO MdsConfig |
|
|
|
getConfig :: IO MdsConfig |
|
|
|
getConfig = do |
|
|
|
getConfig = do |
|
|
|
rawCfg <- BL.readFile "mds.conf" |
|
|
|
rawCfg <- BL.readFile "mds.conf" |
|
|
|
case eitherDecode' rawCfg of |
|
|
|
case eitherDecode' rawCfg of |
|
|
|
Left err -> error err |
|
|
|
Left err -> error err |
|
|
|
Right cfg -> return cfg |
|
|
|
Right cfg -> return cfg |
|
|
|
|
|
|
|
|
|
|
|
main :: IO () |
|
|
|
main :: IO () |
|
|
|
main = do |
|
|
|
main = do |
|
|
|
|
|
|
|
initLogging |
|
|
|
|
|
|
|
debugM "main" "Initializing MDS" |
|
|
|
cfg <- getConfig |
|
|
|
cfg <- getConfig |
|
|
|
|
|
|
|
debugM "main" "Config OK" |
|
|
|
let dbConfig = DatabaseConfig { dbPath = cfgDbPath cfg, |
|
|
|
let dbConfig = DatabaseConfig { dbPath = cfgDbPath cfg, |
|
|
|
dbDatabase = cfgDbName cfg, |
|
|
|
dbDatabase = cfgDbName cfg, |
|
|
|
dbUser = cfgDbAccount cfg, |
|
|
|
dbUser = cfgDbAccount cfg, |
|
|
|
dbPassword = cfgDbPassword cfg } |
|
|
|
dbPassword = cfgDbPassword cfg } |
|
|
|
|
|
|
|
|
|
|
|
db <- initDatabase dbConfig |
|
|
|
db <- initDatabase dbConfig |
|
|
|
|
|
|
|
debugM "main" "DB initialized" |
|
|
|
|
|
|
|
|
|
|
|
let hsConfig = HistoryServerConfig { |
|
|
|
let hsConfig = HistoryServerConfig { |
|
|
|
hspQHPEndpoint = cfgQHPEndpoint cfg, |
|
|
|
hspQHPEndpoint = cfgQHPEndpoint cfg, |
|
|
|
hspHAPEndpoint = cfgHAPEndpoint cfg } |
|
|
|
hspHAPEndpoint = cfgHAPEndpoint cfg } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
debugM "main" "Starting history server" |
|
|
|
withContext $ \ctx -> do |
|
|
|
withContext $ \ctx -> do |
|
|
|
_ <- startHistoryServer hsConfig db ctx |
|
|
|
_ <- startHistoryServer hsConfig db ctx |
|
|
|
forever $ threadDelay 1000000 |
|
|
|
forever $ threadDelay 1000000 |
|
|
|
|