Index: apimod.scm ================================================================== --- apimod.scm +++ apimod.scm @@ -168,11 +168,12 @@ ((get-keys-write) (db:get-keys dbstruct)) ;; force a dummy "write" query to force server; for debug in -repl ;; SERVERS ;; ((start-server) (apply server:kind-run params)) - ((kill-server) (set! *server-run* #f)) + ((kill-server) (set! *server-run* #f)) + ((get-server) (apply db:get-server-info dbstruct params)) ;; TESTS ;;((test-set-state-status-by-id) (apply mt:test-set-state-status-by-id dbstruct params)) ;;BB - commented out above because it was calling below, eventually, incorrectly (dbstruct passed to mt:test-set-state-status-by-id, which previosly did more, but now only passes thru to db:set-state-status-and-roll-up-items. Index: dbmod.scm ================================================================== --- dbmod.scm +++ dbmod.scm @@ -1260,10 +1260,22 @@ owner_pid INTEGER, owner_host TEXT, event_time TIMESTAMP DEFAULT (strftime('%s','now')), CONSTRAINT lock_constraint UNIQUE (lockname));") + ;; maps to *srvpktspec* from http-transportmod + (sqlite3:execute db "CREATE TABLE IF NOT EXISTS servers + (id INTEGER PRIMARY KEY, + host TEXT, + port INTEGER, + servkey TEXT, + pid TEXT, + ipaddr TEXT, + dbpath TEXT, + event_time TIMESTAMP DEFAULT (strftime('%s','now')), + CONSTRAINT servers_constraint UNIQUE (dbpath));") + (sqlite3:execute db "CREATE TABLE IF NOT EXISTS keys (id INTEGER PRIMARY KEY, fieldname TEXT, fieldtype TEXT, CONSTRAINT keyconstraint UNIQUE (fieldname));") @@ -2503,13 +2515,16 @@ (let* ((dat (hash-table-ref *db-api-call-time* cmd-key)) (num (length dat)) (avg (if (> num 0) (/ (common:sum dat)(length dat))))) (set! total (+ total num)) - (debug:print-info 0 *default-log-port* cmd-key "\tavg: " avg " max: " (common:max dat) " min: " (common:min-max < dat) " num: " (length dat)))) + (debug:print-info 0 *default-log-port* cmd-key "\tavg: "avg + " max: " (common:max dat) " min: " + (common:min-max < dat) " num: " (length dat)))) ordered-keys) - (debug:print-info 0 *default-log-port* "TOTAL: " total " api calls since start."))) + (debug:print-info 0 *default-log-port* "TOTAL: "total + " api calls since start."))) (define (db:get-all-run-ids dbstruct) (db:with-db dbstruct #f @@ -4739,11 +4754,16 @@ (tests . ,(sqlite3:fold-row backcons '() db "SELECT id FROM tests WHERE last_update>=?" since-time)) (test_steps . ,(sqlite3:fold-row backcons '() db "SELECT id FROM test_steps WHERE last_update>=?" since-time)) (test_data . ,(sqlite3:fold-row backcons '() db "SELECT id FROM test_data WHERE last_update>=?" since-time)) ;; (test_meta . ,(fold-row backcons '() db "SELECT id FROM test_meta WHERE last_update>?" since-time)) (run_stats . ,(sqlite3:fold-row backcons '() db "SELECT id FROM run_stats WHERE last_update>=?" since-time)) - ))))) + )))) + + ) + + + ;;====================================================================== ;; tdb stuff ;;====================================================================== @@ -5490,7 +5510,34 @@ (or stmth (let* ((newstmth (sqlite3:prepare db stmt))) (db:hoh-set! stmt-cache db stmt newstmth) newstmth)))) +;;====================================================================== +;; S E R V E R R E C O R D S +;;====================================================================== + +;; these are all intended to be run against main.db + +;; run this one in a transaction where first check if host:port is taken +(define (db:register-server dbstruct host port servkey pid ipaddr dbpath) + (db:with-db + dbstruct + #f #f + (lambda (db) + (sqlite3:execute db "INSERT INTO servers (host,port,servkey,pid,ipaddr,dbpath) VALUES (?,?,?,?,?,?);" + host port servkey pid ipaddr dbpath)))) + +(define (db:get-server-info dbstruct dbpath) + (db:with-db + dbstruct + #f #f + (lambda (db) + (sqlite3:fold-row + (lambda (res host port servkey pid ipaddr dbpath) + (list host port servkey pid ipaddr dbpath)) + '() + db + "SELECT host,port,servkey,pid,ipaddr,dbpath FROM servers WHERE dbpath=?;" + dbpath)))) ) Index: tests/unittests/basicserver.scm ================================================================== --- tests/unittests/basicserver.scm +++ tests/unittests/basicserver.scm @@ -44,12 +44,12 @@ rmt:get-connection with-input-from-request ) (define *db* #f) -(test #f #f (api:execute-requests *db* 'get-server `(,*toppath* ".db/1.db"))) -(test #f #f (rmt:general-open-connection *rmt:remote* *toppath* ".db/1.db")) +(test #f #f (api:execute-requests *db* 'get-server (list (conc *toppath*"/.db/1.db")))) +(test #f #f (rmt:general-open-connection *rmt:remote* (list (conc *toppath*"/.db/1.db")))) ;; (delete-file* "logs/1.log") ;; (define run-id 1) ;; (test "setup for run" #t (begin (launch:setup)