Commit a27705f8 authored by Chris Price's avatar Chris Price

Rename "event group" to "report"

This commit just changes all existing occurrences of `event-group`
and `group-id` to `report` and `report-id`.  This includes
renaming some files.
parent 31d72c03
......@@ -5,18 +5,18 @@ require 'puppet/util/puppetdb/report_helper'
Puppet::Reports.register_report(:puppetdb) do
CommandSubmitReport = Puppet::Util::Puppetdb::CommandSubmitReport
CommandStoreReport = Puppet::Util::Puppetdb::CommandStoreReport
desc <<-DESC
Send report information to PuppetDB via the REST API. Reports are serialized to
JSON format, and then submitted to puppetdb using the '#{CommandSubmitReport}'
JSON format, and then submitted to puppetdb using the '#{CommandStoreReport}'
command.
DESC
def process
helper = Puppet::Util::Puppetdb::ReportHelper.new
helper.submit_command(self.host, report_to_hash, CommandSubmitReport, 1)
helper.submit_command(self.host, report_to_hash, CommandStoreReport, 1)
end
private
......@@ -30,8 +30,6 @@ Puppet::Reports.register_report(:puppetdb) do
# seems more consistent and safer for the long-term. However, for reasons
# relating to backwards compatibility we won't be able to switch over to
# the accessors until version 3.x of puppet is our oldest supported version.
# Choosing a somewhat arbitrary string for group-id for the time being.
{
"certname" => host,
"puppet-version" => @puppet_version,
......
......@@ -15,10 +15,10 @@ module Puppet::Util::Puppetdb
CommandsUrl = "/v2/commands"
CommandReplaceCatalog = "replace catalog"
CommandReplaceFacts = "replace facts"
CommandDeactivateNode = "deactivate node"
CommandSubmitReport = "submit event group"
CommandReplaceCatalog = "replace catalog"
CommandReplaceFacts = "replace facts"
CommandDeactivateNode = "deactivate node"
CommandStoreReport = "store report"
# TODO: we should get rid of these; it's global state and it can make our
# tests fail based on the order that they are run in.
......
......@@ -25,7 +25,7 @@ describe processor do
subject.stubs(:run_duration).returns(10)
payload = {
:command => Puppet::Util::Puppetdb::CommandSubmitReport,
:command => Puppet::Util::Puppetdb::CommandStoreReport,
:version => 1,
:payload => subject.send(:report_to_hash).to_pson
}.to_pson
......@@ -86,7 +86,9 @@ describe processor do
context "resource without events" do
it "should not include the resource" do
result = subject.send(:report_to_hash)
result.has_key?("group-id").should be_false
# the server will populate the report id, so we validate that the
# client doesn't include one
result.has_key?("report-id").should be_false
result["certname"].should == subject.host
# TODO: change these two to use accessors as soon as we get up to puppet 3.0
result["puppet-version"].should == subject.instance_variable_get(:@puppet_version)
......
......@@ -60,7 +60,7 @@
(:require [clojure.tools.logging :as log]
[com.puppetlabs.puppetdb.scf.storage :as scf-storage]
[com.puppetlabs.puppetdb.catalog :as cat]
[com.puppetlabs.puppetdb.event :as event]
[com.puppetlabs.puppetdb.report :as report]
[com.puppetlabs.puppetdb.command.dlo :as dlo]
[com.puppetlabs.mq :as mq]
[com.puppetlabs.utils :as pl-utils]
......@@ -348,22 +348,22 @@
(scf-storage/deactivate-node! certname))
(log/info (format "[%s] [deactivate node] %s" id certname))))
;; Event group submission
;; Report submission
(defmethod process-command! ["submit event group" 1]
(defmethod process-command! ["store report" 1]
[{:keys [payload annotations]} {:keys [db]}]
(let [id (:id annotations)
event-group (upon-error-throw-fatality
(event/parse-from-json-string payload id))
report (upon-error-throw-fatality
(report/parse-from-json-string payload id))
timestamp (:received annotations)]
(with-transacted-connection db
(scf-storage/add-event-group! event-group timestamp))
;; TODO: replace this ":group-id" bit in the log message with something better;
;; the real group ids are likely to be completely useless for this purpose,
(scf-storage/add-report! report timestamp))
;; TODO: replace this ":report-id" bit in the log message with something better;
;; the real report ids are likely to be completely useless for this purpose,
;; but we can't necessarily use something like a certname because there is
;; no guarantee that all of the events in a group will be from the same
;; node? need like a 'group desc' or something.
(log/info (format "[%s] [submit event group] %s" id (:group-id event-group)))))
(log/info (format "[%s] [store report] %s" id (:id report)))))
;; ## MQ I/O
;;
......
......@@ -5,7 +5,7 @@
[com.puppetlabs.puppetdb.http.v2.node :only (node-app)]
[com.puppetlabs.puppetdb.http.v2.resources :only (resources-app)]
[com.puppetlabs.puppetdb.http.v2.event :only (events-app)]
[com.puppetlabs.puppetdb.http.v2.event-group :only (event-groups-app)]
[com.puppetlabs.puppetdb.http.v2.report :only (reports-app)]
[com.puppetlabs.puppetdb.http.v2.status :only (status-app)]
[com.puppetlabs.puppetdb.http.v2.metrics :only (metrics-app)]
[com.puppetlabs.puppetdb.http.v2.version :only (version-app)]
......@@ -31,8 +31,8 @@
["events"]
{:get events-app}
["event-groups"]
{:get event-groups-app}
["reports"]
{:get reports-app}
["status" &]
{:any status-app}
......
......@@ -3,24 +3,24 @@
(ns com.puppetlabs.puppetdb.http.v2.event
(:require [com.puppetlabs.http :as pl-http]
[com.puppetlabs.puppetdb.query.event :as query]
[com.puppetlabs.puppetdb.query.report :as query]
[ring.util.response :as rr])
(:use [com.puppetlabs.jdbc :only (with-transacted-connection)]))
(defn produce-body
"Given an optional `query`, an optional `group-id` (the id of the event group),
"Given an optional `query`, an optional `report-id` (the id of the report),
and a database connection, return a Ring response with the query results. The
result format conforms to that documented above.
If the query can't be parsed, an HTTP `Bad Request` (400) is returned."
[query group-id db]
[query report-id db]
;; TODO: implement query
(if query
(throw (UnsupportedOperationException. "query is not yet implemented")))
(try
(with-transacted-connection db
(-> (query/resource-event-query->sql query group-id)
(-> (query/resource-event-query->sql query report-id)
(query/query-resource-events)
(pl-http/json-response)))
(catch com.fasterxml.jackson.core.JsonParseException e
......@@ -36,8 +36,8 @@
[{:keys [params headers globals] :as request}]
(cond
(not (or (params "query")
(params "group-id")))
(pl-http/error-response "must provide at least one of 'query', 'group-id'")
(params "report-id")))
(pl-http/error-response "must provide at least one of 'query', 'report-id'")
;; TODO: this is copied and pasted from resources-app, should be able to
;; be refactored
......@@ -48,4 +48,4 @@
(rr/status pl-http/status-not-acceptable))
:else
(produce-body (params "query") (params "group-id") (:scf-db globals))))
(produce-body (params "query") (params "report-id") (:scf-db globals))))
;; ## Request Format
;; TODO: fill this in once it stabilizes
(ns com.puppetlabs.puppetdb.http.v2.event-group
(ns com.puppetlabs.puppetdb.http.v2.report
(:require [com.puppetlabs.http :as pl-http]
[com.puppetlabs.puppetdb.query.event :as query]
[com.puppetlabs.puppetdb.query.report :as query]
[ring.util.response :as rr])
(:use [com.puppetlabs.jdbc :only (with-transacted-connection)]))
(defn produce-body
"Given an optional `query`, an optional `group-id` (the id of the event group),
"Given an optional `query`, an optional `report-id` (the id of the report),
and a database connection, return a Ring response with the query results. The
result format conforms to that documented above.
If the query can't be parsed, an HTTP `Bad Request` (400) is returned."
[query group-id db]
[query report-id db]
;; TODO: implement query
(if query
(throw (UnsupportedOperationException. "query is not yet implemented")))
(try
(with-transacted-connection db
(-> (query/event-group-query->sql query group-id)
(query/query-event-groups)
(-> (query/report-query->sql query report-id)
(query/query-reports)
(pl-http/json-response)))
(catch com.fasterxml.jackson.core.JsonParseException e
(pl-http/error-response e))
......@@ -32,14 +32,14 @@
(defn event-groups-app
"Ring app for querying event groups"
(defn reports-app
"Ring app for querying reports"
[{:keys [params headers globals] :as request}]
(cond
;; TODO: decide what params are required (if any)
; (not (or (params "query")
; (params "group-id")))
; (pl-http/error-response "must provide at least one of 'query', 'group-id'")
; (params "report-id")))
; (pl-http/error-response "must provide at least one of 'query', 'report-id'")
;; TODO: this is copied and pasted from resources-app, should be able to
;; be refactored
......@@ -50,4 +50,4 @@
(rr/status pl-http/status-not-acceptable))
:else
(produce-body (params "query") (params "group-id") (:scf-db globals))))
(produce-body (params "query") (params "report-id") (:scf-db globals))))
;; ## SQL/query-related functions for events
(ns com.puppetlabs.puppetdb.query.event
(ns com.puppetlabs.puppetdb.query.report
(:require [com.puppetlabs.utils :as utils])
(:use [com.puppetlabs.jdbc :only [query-to-vec]]
[com.puppetlabs.puppetdb.query.utils :only [valid-query-format? sql-to-wire]]))
(defn event-group-query->sql
"Given the set of inputs for an event group query, build up the corresponding
(defn report-query->sql
"Given the set of inputs for a report query, build up the corresponding
SQL expression."
[query group-id]
[query report-id]
;; TODO: real precondition for the query argument. Not supported yet.
{:pre [(nil? query)]
:post [(valid-query-format? %)]}
(if group-id
(vector " WHERE event_groups.group_id = ?" group-id)
(if report-id
(vector " WHERE reports.id = ?" report-id)
(vector "")))
(defn query-event-groups
"Take a query and its parameters, and return a vector of matching event groups."
(defn query-reports
"Take a query and its parameters, and return a vector of matching reports."
[[sql & params]]
{:pre [(string? sql)]}
;; TODO: do we need LIMIT stuff here, like we're doing with resource queries?
(let [query (format (str "SELECT group_id,
(let [query (format (str "SELECT id,
certname,
puppet_version,
report_format,
......@@ -31,7 +31,7 @@
end_time,
receive_time,
description
FROM event_groups %s ORDER BY start_time DESC")
FROM reports %s ORDER BY start_time DESC")
sql)
results (map sql-to-wire (query-to-vec (apply vector query params)))]
results))
......@@ -41,13 +41,13 @@
(defn resource-event-query->sql
"Given the set of inputs for a resource event query, build up the corresponding
SQL expression."
[query event-group-id]
[query report-id]
;; TODO: real precondition for the query argument. Not supported yet.
{:pre [(nil? query)
((some-fn nil? string?) event-group-id)]
((some-fn nil? string?) report-id)]
:post [(valid-query-format? %)]}
(if event-group-id
(vector " WHERE resource_events.event_group_id = ?" event-group-id)
(if report-id
(vector " WHERE resource_events.report_id = ?" report-id)
(vector "")))
(defn query-resource-events
......@@ -56,7 +56,7 @@
[[sql & params]]
{:pre [(string? sql)]}
;; TODO: do we need LIMIT stuff here, like we're doing with resource queries?
(let [query (format (str "SELECT event_group_id,
(let [query (format (str "SELECT report_id,
status,
timestamp,
resource_type,
......
;; ## Puppet event-group parsing
;; ## Puppet report/event parsing
;;
;; Functions that handle conversion of event-groups from wire format to
;; Functions that handle conversion of reports from wire format to
;; internal PuppetDB format, including validation.
(ns com.puppetlabs.puppetdb.event
(ns com.puppetlabs.puppetdb.report
(:use [clj-time.coerce :only [to-timestamp]]
[com.puppetlabs.utils :only [datetime? string-or-nil?]]
[com.puppetlabs.puppetdb.query.utils :only [wire-to-sql]])
......@@ -40,10 +40,10 @@
desc required-key type-desc (required-key m)))))))
(defn validate-meta
"Validate that the event group data structure contains all of the required metadata."
[event-group]
(validate-map "Event group" event-group
[[:group-id string? "string"]
"Validate that the report data structure contains all of the required metadata."
[report]
(validate-map "Report" report
[[:id string? "string"]
[:certname string? "string"]
[:puppet-version string? "string"]
[:report-format integer? "integer"]
......@@ -51,7 +51,7 @@
[:start-time datetime? "datetime"]
[:end-time datetime? "datetime"]
[:description string-or-nil? "string"]])
event-group)
report)
(defn validate-resource-event
"Validate a resource event data structure."
......@@ -68,48 +68,47 @@
resource-event)
(defn validate-resource-events
"Verify that any resource events contained in the event group data structure
"Verify that any resource events contained in the report data structure
are valid."
[event-group]
(doseq [resource-event (:resource-events event-group)]
[report]
(doseq [resource-event (:resource-events report)]
(validate-resource-event resource-event))
event-group)
report)
(defn validate
"Validate an event group data structure. Throws IllegalArgumentException if
the event group is invalid."
[event-group]
(-> event-group
"Validate a report data structure. Throws IllegalArgumentException if
the report is invalid."
[report]
(-> report
validate-meta
validate-resource-events))
(defn parse-from-json-string
"Parse an event group from a json string. Validates the resulting data structure
"Parse a report from a json string. Validates the resulting data structure
and ensures that it conforms to the puppetdb wire format; throws
IllegalArgumentException if the data is not valid.
`s` - the JSON string to parse.
`group-id` - the group id to uniquely identify this event group. This will usually be a UUID
`report-id` - the report id to uniquely identify this report. This will usually be a UUID
generated by the command processor."
[s group-id]
[s report-id]
{:pre [(string? s)
(string? group-id)]
(string? report-id)]
:post [(map? %)]}
(let [json-obj (json/parse-string s true)]
(when-not (map? json-obj)
(throw (IllegalArgumentException.
(format "Invalid JSON string for event group; expected a JSON 'Object', got '%s'" s))))
(validate (assoc-in json-obj [:group-id] group-id))))
(format "Invalid JSON string for report; expected a JSON 'Object', got '%s'" s))))
(validate (assoc-in json-obj [:id] report-id))))
(defn resource-event-to-sql
"Given a resource event object in its puppetdb wire format, convert the data
structure into a format suitable for handing off to JDBC function such as
`insert-records`.
Also requires a 'group-id' argument, which should contain the group id of the
event group that this event is associated with."
[resource-event group-id]
Also requires a 'report-id' argument, which should contain the report id of the
report that this event is associated with."
[resource-event report-id]
(-> resource-event
(assoc-in [:event-group-id] group-id)
(assoc-in [:report-id] report-id)
(wire-to-sql {[:timestamp] to-timestamp})))
......@@ -190,11 +190,11 @@
(sql/drop-table :classes)
(sql/drop-table :tags))
(defn add-events-tables
"Add a resource_events and event_groups tables."
(defn add-reports-tables
"Add a resource_events and reports tables."
[]
(sql/create-table :event_groups
["group_id" "VARCHAR(40)" "NOT NULL" "PRIMARY KEY"]
(sql/create-table :reports
["id" "VARCHAR(40)" "NOT NULL" "PRIMARY KEY"]
["certname" "TEXT" "NOT NULL"]
["puppet_version" "VARCHAR(40)" "NOT NULL"]
["report_format" "SMALLINT" "NOT NULL"]
......@@ -206,7 +206,7 @@
["description" "TEXT"])
(sql/create-table :resource_events
["event_group_id" "VARCHAR(40)" "NOT NULL" "REFERENCES event_groups(group_id)" "ON DELETE CASCADE"]
["report_id" "VARCHAR(40)" "NOT NULL" "REFERENCES reports(id)" "ON DELETE CASCADE"]
["status" "VARCHAR(40)" "NOT NULL"]
["timestamp" "TIMESTAMP WITH TIME ZONE" "NOT NULL"]
["resource_type" "TEXT" "NOT NULL"]
......@@ -223,17 +223,14 @@
;; this out into two tables (which means two SELECTS and some in-code sorting would be necessary
;; in order to build up the complete data for a report), or (cough) use a sentinel value
;; for "property" for skips, and make that field NOT NULL. Both options seem pretty sucky.
; ["PRIMARY KEY (event_group_id, resource_type, resource_title, property)"]
; ["PRIMARY KEY (report_id, resource_type, resource_title, property)"]
)
(sql/do-commands
"CREATE INDEX idx_event_groups_group_id ON event_groups(group_id)")
"CREATE INDEX idx_reports_certname ON reports(certname)")
(sql/do-commands
"CREATE INDEX idx_event_groups_certname ON event_groups(certname)")
(sql/do-commands
"CREATE INDEX idx_resource_events_event_group_id ON resource_events(event_group_id)")
"CREATE INDEX idx_resource_events_report_id ON resource_events(report_id)")
(sql/do-commands
"CREATE INDEX idx_resource_events_resource_type ON resource_events(resource_type)")
......@@ -251,7 +248,7 @@
4 add-certname-facts-metadata-table
5 add-missing-indexes
6 drop-classes-and-tags
7 add-events-tables})
7 add-reports-tables})
(defn schema-version
"Returns the current version of the schema, or 0 if the schema
......
......@@ -20,7 +20,7 @@
(ns com.puppetlabs.puppetdb.scf.storage
(:require [com.puppetlabs.puppetdb.catalog :as cat]
[com.puppetlabs.puppetdb.event :as event]
[com.puppetlabs.puppetdb.report :as report]
[com.puppetlabs.utils :as utils]
[com.puppetlabs.jdbc :as jdbc]
[clojure.java.jdbc :as sql]
......@@ -629,27 +629,27 @@ must be supplied as the value to be matched."
(delete-facts! name)
(add-facts! name values timestamp))))
(defn add-event-group!
"Add an event group and all of the associated events."
[event-group timestamp]
{:pre [(map? event-group)
(defn add-report!
"Add a report and all of the associated events."
[report timestamp]
{:pre [(map? report)
(utils/datetime? timestamp)]}
(let [group-id (:group-id event-group)
(let [report-id (:id report)
;; TODO: either need to do some validation here, or need to document that we expect everything
;; to be validated before we are called (in which case we need to validate for extraneous keys
;; in the validation functions).
resource-event-rows (map #(event/resource-event-to-sql % group-id)
(:resource-events event-group))]
resource-event-rows (map #(report/resource-event-to-sql % report-id)
(:resource-events report))]
;; TODO: metrics?
(sql/transaction
(sql/insert-record :event_groups
{ :group_id (:group-id event-group)
:puppet_version (:puppet-version event-group)
:certname (:certname event-group)
:report_format (:report-format event-group)
:configuration_version (:configuration-version event-group)
:start_time (to-timestamp (:start-time event-group))
:end_time (to-timestamp (:end-time event-group))
(sql/insert-record :reports
{ :id (:id report)
:puppet_version (:puppet-version report)
:certname (:certname report)
:report_format (:report-format report)
:configuration_version (:configuration-version report)
:start_time (to-timestamp (:start-time report))
:end_time (to-timestamp (:end-time report))
:receive_time (to-timestamp timestamp)
:description (:description event-group)})
:description (:description report)})
(apply sql/insert-records :resource_events resource-event-rows))))
(ns com.puppetlabs.puppetdb.examples.event
(ns com.puppetlabs.puppetdb.examples.report
(:require [clj-time.coerce :as coerce]))
(def resource-event-groups
(def reports
{:basic
{:certname "foo.local"
:puppet-version "3.0.1"
......
......@@ -3,7 +3,7 @@
[clojure.java.jdbc :as sql]
[com.puppetlabs.puppetdb.scf.storage :as scf-store]
[com.puppetlabs.puppetdb.catalog :as catalog]
[com.puppetlabs.puppetdb.examples.event :as event-examples])
[com.puppetlabs.puppetdb.examples.report :as report-examples])
(:use [com.puppetlabs.puppetdb.command]
[com.puppetlabs.utils]
[com.puppetlabs.puppetdb.testutils]
......@@ -224,7 +224,7 @@
~discard-var discard-dir#]
~@body
; Uncommenting this line can be very useful for debugging
; (println @log-output#)
;(println @log-output#)
)
(finally
(fs/delete-dir discard-dir#)))))
......@@ -511,14 +511,14 @@
(is (= 0 (times-called publish)))
(is (empty? (fs/list-dir discard-dir))))))))
(let [event-group (:basic event-examples/resource-event-groups)
command {:command "submit event group"
(let [report (:basic report-examples/reports)
command {:command "store report"
:version 1
:payload (json/generate-string event-group)}]
(deftest submit-event-group
(testing "should store the event-group"
:payload (json/generate-string report)}]
(deftest store-report
(testing "should store the report"
(test-msg-handler command publish discard-dir
(is (= (query-to-vec "SELECT certname,configuration_version FROM event_groups")
[{:certname (:certname event-group) :configuration_version (:configuration-version event-group)}]))
(is (= (query-to-vec "SELECT certname,configuration_version FROM reports")
[{:certname (:certname report) :configuration_version (:configuration-version report)}]))
(is (= 0 (times-called publish)))
(is (empty? (fs/list-dir discard-dir)))))))
(ns com.puppetlabs.puppetdb.test.http.v2.event
(:require [com.puppetlabs.puppetdb.event :as event]
(:require [com.puppetlabs.puppetdb.report :as report]
[com.puppetlabs.utils :as utils]
[com.puppetlabs.puppetdb.scf.storage :as scf-store]
[cheshire.core :as json])
(:use clojure.test
ring.mock.request
com.puppetlabs.puppetdb.examples.event
com.puppetlabs.puppetdb.examples.report
com.puppetlabs.puppetdb.fixtures
[clj-time.core :only [now]]
[clj-time.coerce :only [to-string]]
......@@ -18,45 +18,45 @@
;; TODO: these might be able to be abstracted out and consolidated with the similar version
;; that currently resides in test.http.resource
(defn get-request
[path query group-id]
[path query report-id]
;; TODO: clean this up... gotta be a better way :)
(let [query-arg (if query
{"query" (if (string? query) query (json/generate-string query))}
{})
group-id-arg (if group-id
{"group-id" group-id}
report-id-arg (if report-id
{"report-id" report-id}
{})
request (request :get path (merge query-arg group-id-arg))
request (request :get path (merge query-arg report-id-arg))
headers (:headers request)]
(assoc request :headers (assoc headers "Accept" content-type-json))))
(defn get-response
[query group-id] (*app* (get-request "/v2/events" query group-id)))
[query report-id] (*app* (get-request "/v2/events" query report-id)))
(defn resource-event-response
[resource-event group-id]
[resource-event report-id]
(-> resource-event
(assoc-in [:event-group-id] group-id)
(assoc-in [:report-id] report-id)
;; the timestamps are already strings, but calling to-string on them forces
;; them to be coerced to dates and then back to strings, which normalizes
;; the timezone so that it will match the value returned form the db.
(update-in [:timestamp] to-string)))
(defn resource-events-response
[resource-events group-id]
(set (map #(resource-event-response % group-id) resource-events)))
[resource-events report-id]
(set (map #(resource-event-response % report-id) resource-events)))
(deftest query-by-event-group
(let [group-id (utils/uuid)
basic (assoc-in (:basic resource-event-groups) [:group-id] group-id)]
(event/validate basic)
(scf-store/add-event-group! basic (now))
(deftest query-by-report
(let [report-id (utils/uuid)
basic (assoc-in (:basic reports) [:id] report-id)]
(report/validate basic)
(scf-store/add-report! basic (now))
;; TODO: test invalid requests
(testing "should return the list of resource events for a given event group id"
(testing "should return the list of resource events for a given report id"
(response-equal?
(get-response nil (:group-id basic))
(resource-events-response (:resource-events basic) group-id)))))
(get-response nil (:id basic))
(resource-events-response (:resource-events basic) report-id)))))
(ns com.puppetlabs.puppetdb.test.http.v2.event-group
(ns com.puppetlabs.puppetdb.test.http.v2.report
(:require [cheshire.core :as json]
[com.puppetlabs.puppetdb.scf.storage :as scf-store]
[com.puppetlabs.puppetdb.event :as event]
[com.puppetlabs.puppetdb.report :as report]
[com.puppetlabs.utils :as utils])
(:use clojure.test
ring.mock.request
com.puppetlabs.puppetdb.fixtures
com.puppetlabs.puppetdb.examples.event
com.puppetlabs.puppetdb.examples.report
[com.puppetlabs.puppetdb.testutils :only (response-equal?)]
[clj-time.coerce :only [to-date-time to-string]]
[clj-time.core :only [now]]))
......@@ -19,53 +19,53 @@
;; TODO: this might be able to be abstracted out and consolidated with the similar
;; versions that currently reside in test.http.resource and test.http.event
(defn get-request
[path query group-id]
[path query report-id]
;; TODO: clean this up... gotta be a better way :)
(let [query-arg (if query
{"query" (if (string? query) query (json/generate-string query))}
{})
group-id-arg (if group-id
{"group-id" group-id}
report-id-arg (if report-id
{"report-id" report-id}
{})
request (request :get path (merge query-arg group-id-arg))
request (request :get path (merge query-arg report-id-arg))
headers (:headers request)]
(assoc request :headers (assoc headers "Accept" content-type-json))))
(defn get-response
[query group-id] (*app* (get-request "/v2/event-groups" query group-id)))
[query report-id] (*app* (get-request "/v2/reports" query report-id)))
(defn event-group-response
[event-group]
(defn report-response
[report]
(utils/mapvals
;; the timestamps are already strings, but calling to-string on them forces
;; them to be coerced to dates and then back to strings, which normalizes
;; the timezone so that it will match the value returned form the db.
to-string
;; the response won't include individual events, so we need to pluck those