aboutsummaryrefslogtreecommitdiffstats
path: root/src/chameleon/route.clj
diff options
context:
space:
mode:
authorShwetank Dave <shwetank.dave@amdocs.com>2018-06-11 10:15:34 -0400
committerShwetank Dave <shwetank.dave@amdocs.com>2018-07-26 09:13:18 -0400
commite16bda37d76e63e0f903bba13ed1dccf3b17f395 (patch)
tree1b8036103cf598bc645e3d4da1b6340d9c164447 /src/chameleon/route.clj
parent36b5671af2c3eec5ca81663382c4ca2898f79e55 (diff)
Add logging and tests and build using mvn
An initial version of adding logs to chameleon An initial version of adding specs (tests) to chameleon. Adding pom.xml so the project can be build using maven. Updating README.md for instructions on running it locally. Issue-ID: AAI-1220 Change-Id: I85f46fd7f625c83b84f211d6766970431e6d91eb Signed-off-by: Shwetank Dave <shwetank.dave@amdocs.com>
Diffstat (limited to 'src/chameleon/route.clj')
-rw-r--r--src/chameleon/route.clj50
1 files changed, 22 insertions, 28 deletions
diff --git a/src/chameleon/route.clj b/src/chameleon/route.clj
index e8f3a3c..0918da4 100644
--- a/src/chameleon/route.clj
+++ b/src/chameleon/route.clj
@@ -1,12 +1,7 @@
(ns chameleon.route
- (:require [org.httpkit.client :as kitclient]))
-
-(defn- interpret-response
- "Print out the response from the Gallifrey server"
- [key response]
- (let [{:keys [status body]}@response]
- (println "Response for request with key " key " resulted in status " status
- " with body " body )))
+ (:require [org.httpkit.client :as kitclient]
+ [chameleon.logging :as log]
+ [ring.util.http-status :as hs]))
(defn query
"Retrieve an entity referenced by id at the provided host. Optionally provide
@@ -21,11 +16,10 @@
:keepalive 300
:timeout 20000}))
-(defn assert-create
+(defn assert-create!
"Creates an entity in Gallifrey with an initial set of assertions coming from the provided payload"
[host actor type key payload & [time-dimensions]]
- (kitclient/request {
- :url (str "https://" host "/" type "/" key)
+ (kitclient/request {:url (str "https://" host "/" type "/" key)
:method :put
:query-params (into {"actor" actor "create" "true"} time-dimensions)
:body payload
@@ -33,11 +27,10 @@
:keepalive 300
:timeout 1000}))
-(defn assert-update
+(defn assert-update!
"Update an entity in Gallifrey with a set of assertions coming from the provided payload"
[host actor type key payload & [time-dimensions]]
- (kitclient/request {
- :url (str "https://" host "/" type "/" key)
+ (kitclient/request {:url (str "https://" host "/" type "/" key)
:method :put
:query-params (into {"actor" actor "changes-only" "true"} time-dimensions)
:body payload
@@ -45,26 +38,27 @@
:keepalive 300
:timeout 1000}))
-(defn assert-delete
+(defn assert-delete!
"Assert a deletion for an entity in Gallifrey based on the provided key."
[host actor type key & [time-dimensions]]
- (kitclient/request {
- :url (str "https://" host "/" type "/" key)
+ (kitclient/request {:url (str "https://" host "/" type "/" key)
:method :delete
- :query-params (into {"actor" actor} time-dimensions)
+ :query-params (into {"actor" actor} time-dimensions)
:insecure? true
:keepalive 300
:timeout 1000}))
-(defn assert-gallifrey [host actor type payload]
+(defn assert-gallifrey!
+ [host actor type payload & [e-logger a-logger]]
"Propagates an assertion to Gallifrey based off of an event payload coming in from the event service."
(let [{:keys [meta body]} payload
- {:keys [key operation time]} meta]
- (println operation " " type " with key " key)
- (interpret-response key (case operation
- "CREATE"
- (assert-create host actor type key body time)
- "UPDATE"
- (assert-update host actor type key body time)
- "DELETE"
- (assert-delete host actor type key time)))))
+ {:keys [key operation time]} meta
+ _ (log/info e-logger "GALLIFREY_ASSERTION" (mapv str [operation type key]))
+ g-assert (case operation
+ "CREATE" (assert-create! host actor type key body time)
+ "UPDATE" (assert-update! host actor type key body time)
+ "DELETE" (assert-delete! host actor type key time))
+ {:keys [status body]} @g-assert]
+ (log/info e-logger "GALLIFREY_ASSERTED" [(str type) (str key)])
+ (log/info a-logger "RESPONSE" (mapv str [operation key status body])
+ :fields {:response-code status :response-description (hs/get-name status)})))