diff --git a/VERSION b/VERSION index faef31a..39e898a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.7.0 +0.7.1 diff --git a/src/clj/job_streamer/control_bus/component/jobs.clj b/src/clj/job_streamer/control_bus/component/jobs.clj index 172efb7..bee228b 100644 --- a/src/clj/job_streamer/control_bus/component/jobs.clj +++ b/src/clj/job_streamer/control_bus/component/jobs.clj @@ -75,13 +75,17 @@ (let [since (.substring q (count "since:"))] (when (b/valid? {:since since} :since [[v/datetime (:date f/formatters)]]) - {:since (f/parse (:date f/formatters) since)}))) + {:since (some->> since (f/parse (:date f/formatters)) .toDate)}))) (defn- parse-query-until [q] - (let [until (.substring q (count "until:"))] + (let [until (.substring q (count "until:")) + parse-date-fn (partial f/parse (:date f/formatters))] (when (b/valid? {:until until} :until [[v/datetime (:date f/formatters)]]) - {:until (f/parse (:date f/formatters) until)}))) + {:until (some-> until + parse-date-fn + (.plusDays 1) + .toDate)}))) (defn- parse-query-exit-status [q] (let [exit-status (.substring q (count "exit-status:"))] @@ -125,17 +129,17 @@ (:until qmap) (update-in [:where] conj - '[(<= ?end-time ?until-condition)]) + '[(< ?end-time ?until-condition)]) (:exit-status qmap) (update-in [:where] conj '[(.contains ^String ?exit-status ?exit-status-condition)])) app-name - (:job-name qmap []) + ;if argument is nil or empty vector datomic occurs error + (or (not-empty (:job-name qmap)) [""]) (:since qmap "") (:until qmap "") (:exit-status qmap ""))] - {:results (->> jobs (drop (dec (or offset 0))) (take (or limit 20)) diff --git a/src/java/net/unit8/job_streamer/control_bus/JobStreamerExecuteJob.java b/src/java/net/unit8/job_streamer/control_bus/JobStreamerExecuteJob.java index f31c1a3..6881a11 100644 --- a/src/java/net/unit8/job_streamer/control_bus/JobStreamerExecuteJob.java +++ b/src/java/net/unit8/job_streamer/control_bus/JobStreamerExecuteJob.java @@ -20,7 +20,7 @@ public void execute(JobExecutionContext context) throws JobExecutionException { JobDataMap data = context.getMergedJobDataMap(); String jobName = data.getString("job-name"); String host = data.getString("host"); - int port = data.getInt("port"); + long port = data.getLong("port"); String appName = data.getString("app-name"); URLConnection conn; diff --git a/test/clj/job_streamer/control_bus/component/jobs_test.clj b/test/clj/job_streamer/control_bus/component/jobs_test.clj index b25f1b3..a79e15c 100644 --- a/test/clj/job_streamer/control_bus/component/jobs_test.clj +++ b/test/clj/job_streamer/control_bus/component/jobs_test.clj @@ -1,7 +1,7 @@ (ns job-streamer.control-bus.component.jobs-test (:require (job-streamer.control-bus.component [jobs :as jobs] [apps :as apps] - [datomic :refer [datomic-component]] + [datomic :refer [datomic-component] :as d] [migration :refer [migration-component]]) (job-streamer.control-bus [system :as system] [model :as model] @@ -11,7 +11,8 @@ [clojure.test :refer :all] [clojure.pprint :refer :all] [clojure.edn :as edn] - [clj-time.format :as f])) + [clj-time.format :as f]) + (:import [org.joda.time DateTime])) @@ -45,6 +46,22 @@ :application/classpaths []})}] (handler request))) +(defn setup-execution [{:keys [datomic] :as jobs} + {:keys [db/id job-execution/end-time job-execution/create-time] + :or {job-execution/end-time (java.util.Date.) + job-execution/create-time (java.util.Date.)}}] + (let [execution-id (d/tempid :db.part/user)] + (-> (d/transact + datomic + [{:db/id execution-id + :job-execution/batch-status :batch-status/undispatched + :job-execution/create-time create-time + :job-execution/end-time end-time + :job-execution/exit-status "COMPLETE" + :job-execution/job-parameters "{}"} + [:db/add id :job/executions execution-id]]) + :tempids))) + (deftest find-all (testing "find-all" (let [system (new-system config)] @@ -73,12 +90,57 @@ (let [res (jobs/find-all (:jobs system) "default" nil)] (is (= 1 (:hits res))))))) +(deftest find-all-with-query + (let [system (new-system config) + handler (-> (jobs/list-resource (:jobs system) "default"))] + (create-app system) + ;; setup data + (handler {:request-method :post + :content-type "application/edn" + :body (pr-str {:job/name "job1"})}) + (handler {:request-method :post + :content-type "application/edn" + :body (pr-str {:job/name "job2"})}) + (testing "Mathes exactly" + (let [res (jobs/find-all (:jobs system) "default" "job1")] + (is (= 1 (:hits res))))) + + (testing "A query of multiple keywords" + (let [res (jobs/find-all (:jobs system) "default" "job1 job2")] + (is (= 2 (:hits res))))) + + (testing "backward matching" + (let [res (jobs/find-all (:jobs system) "default" "b2")] + (is (= 1 (:hits res))) + (is (= "job2" (get-in res [:results 0 :job/name]))))) + + (let [job-id (get-in (jobs/find-all (:jobs system) "default" "job1") [:results 0 :db/id]) + end-time (.toDate (f/parse (:date f/formatters) "2016-09-09"))] + (setup-execution (:jobs system) + {:db/id job-id :job-execution/end-time end-time}) + (testing "since" + (let [res (jobs/find-all (:jobs system) "default" "since:2016-09-09")] + (pprint res) + (is (= 1 (:hits res))) + (is (= "job1" (get-in res [:results 0 :job/name]))))) + (testing "until" + (let [res (jobs/find-all (:jobs system) "default" "until:2016-09-09")] + (is (= 1 (:hits res))) + (is (= "job1" (get-in res [:results 0 :job/name]))))) + (testing "range" + (let [res (jobs/find-all (:jobs system) "default" "since:2016-09-09 until:2016-09-09")] + (is (= 1 (:hits res))) + (is (= "job1" (get-in res [:results 0 :job/name]))))) + + + ))) + (deftest parse-query (testing "parse-query" (let [result (jobs/parse-query "a b since:2016-09-01 until:2016-09-02 exit-status:COMPLETED")] (is (= "a" (first (:job-name result)))) - (is (= "2016-09-01" (f/unparse (:date f/formatters) (:since result)))) - (is (= "2016-09-02" (f/unparse (:date f/formatters) (:until result)))) + (is (= "2016-09-01" (some->> result :since (new DateTime) (f/unparse (:date f/formatters))))) + (is (= "2016-09-03" (some->> result :until (new DateTime) (f/unparse (:date f/formatters))))) (is (= "COMPLETED" (:exit-status result))))) (testing "nil query returns nil" (let [result (jobs/parse-query nil)] @@ -91,10 +153,6 @@ (let [result (jobs/parse-query "a")] (is (= {:job-name '("a")} result)))) - (testing "single simple query" - (let [result (jobs/parse-query "a")] - (is (= {:job-name '("a")} result)))) - (testing "ignore breaking tokens in a query" (let [result (jobs/parse-query "a since: until: since:xxx until:yyy")] (is (= {:job-name '("a")} result)))))