Browse Source

Added a chainspace status check

Jim Barritt 11 months ago
parent
commit
b039e97d87

+ 10 - 2
apps/petitions/decode-app/src/decode_app/chainspace.clj

@@ -8,8 +8,16 @@
8 8
         port (:chainspace-port (config/get-config))]
9 9
     (format "%s:%s/%s" host port path)))
10 10
 
11
+(defn status []
12
+  (try
13
+    (let [response (client/get (get-url "/"))]
14
+      (if (client/success? response)
15
+        (array-map :status "UP" :url (get-url "") )
16
+        (array-map :status "DOWN" :url (get-url "")  :description (str "[" (:status response) "] " (:body response)))))
17
+    (catch Exception e (array-map :status "DOWN" :url (get-url "") :message (str (.getClass e) " : " (.getMessage e))))))
18
+
11 19
 
12 20
 (defn create [] (let [response (client/post (get-url "chainspace/petitions"))
13
-                      body (get response :body)
21
+                      body (:body response)
14 22
                       content (json/read-str body :key_fn keyword)]
15
-                     (get content "petitionObjectId")))
23
+                  (get content "petitionObjectId")))

+ 9 - 8
apps/petitions/decode-app/src/decode_app/database.clj

@@ -32,20 +32,21 @@
32 32
     (let [db (get-db)]
33 33
       (let [petition-count (mc/count db "petitions")
34 34
             user-count (mc/count db "users")]
35
-        {:status         "UP"
36
-         :petition-count petition-count
37
-         :user-count     user-count}))
38
-    (catch Exception e {:status "DOWN" :message (str (.getClass e) " : " (.getMessage e))})))
35
+        (array-map :status "UP"
36
+                   :petition-count petition-count
37
+                   :user-count user-count)))
38
+    (catch Exception e (array-map :status "DOWN" :message (str (.getClass e) " : " (.getMessage e))))))
39 39
 
40 40
 (defn status []
41 41
   (let [config (config/get-config)
42 42
         database (:database config)
43 43
         host (:mongo-host config)
44 44
         port (:mongo-port config)]
45
-    {(keyword database) (merge {:db-type           "mongo"
46
-                                :host              host
47
-                                :port              port}
48
-                               (test-connection)) }))
45
+    {(keyword database) (merge (test-connection)
46
+                               {:db-type "mongo"
47
+                                :host    host
48
+                                :port    port}
49
+                               )}))
49 50
 
50 51
 (defn find-by-query [collection query]
51 52
   (let [db (get-db)

+ 1 - 1
apps/petitions/decode-app/src/decode_app/handler.clj

@@ -53,7 +53,7 @@
53 53
              :code-version "0.1"
54 54
              :endpoints {:home {:url (local-url request "/") :description "Index page"}
55 55
                          :status {:url (local-url request "/status") :description "Check for status of api and connections to services it depends on"}
56
-                         :petitions { :url (local-url request "/petitions") :description {:get "List of all petitions" :post "Create a new petition"}}
56
+                         :petitions { :url (local-url request "/petitions") :description {:get "List of all petitions" :post "Create a new petition, submits to chainspace"}}
57 57
                          :petition { :url (local-url request "/petitions/:id") :description "Retrieves a particular petition by id"}
58 58
                          :close-petition {:url (local-url request "/close") :description {:post  "Close a petition (send id in body)"}}
59 59
                          ;; These pages were transitional before we had the mobile app. Think they can be removed as they are fake

+ 4 - 2
apps/petitions/decode-app/src/decode_app/status.clj

@@ -1,5 +1,7 @@
1 1
 (ns decode-app.status
2
-  (:require [decode-app.database :as db]))
2
+  (:require [decode-app.database :as db]
3
+            [decode-app.chainspace :as cs]))
3 4
 
4 5
 (defn get-status []
5
-  {:database (db/status)})
6
+  {:database (db/status)
7
+   :chainspace (cs/status)})