From 674d433931e79dcb8e3ba12de2f1ffb48a27ebbf Mon Sep 17 00:00:00 2001 From: seki Date: Wed, 28 Sep 2016 02:35:52 +0900 Subject: [PATCH 1/5] fix make query --- src/clj/job_streamer/control_bus/component/jobs.clj | 8 ++++---- .../job_streamer/control_bus/component/jobs_test.clj | 11 ++++------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/clj/job_streamer/control_bus/component/jobs.clj b/src/clj/job_streamer/control_bus/component/jobs.clj index 172efb7..3ffce1c 100644 --- a/src/clj/job_streamer/control_bus/component/jobs.clj +++ b/src/clj/job_streamer/control_bus/component/jobs.clj @@ -75,13 +75,13 @@ (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:"))] (when (b/valid? {:until until} :until [[v/datetime (:date f/formatters)]]) - {:until (f/parse (:date f/formatters) until)}))) + {:until (some->> until (f/parse (:date f/formatters)) .toDate)}))) (defn- parse-query-exit-status [q] (let [exit-status (.substring q (count "exit-status:"))] @@ -131,11 +131,11 @@ (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/test/clj/job_streamer/control_bus/component/jobs_test.clj b/test/clj/job_streamer/control_bus/component/jobs_test.clj index b25f1b3..ed3c787 100644 --- a/test/clj/job_streamer/control_bus/component/jobs_test.clj +++ b/test/clj/job_streamer/control_bus/component/jobs_test.clj @@ -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])) @@ -77,8 +78,8 @@ (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-02" (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 +92,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))))) From 075cd56467f996d1b565d456c1b52651692110b6 Mon Sep 17 00:00:00 2001 From: kawasima Date: Wed, 28 Sep 2016 09:21:44 +0900 Subject: [PATCH 2/5] Starts developing for v0.7.1 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index faef31a..7df013a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.7.0 +0.7.1-SNAPSHOT From 0a28ab022c17ff656efe25aa1aeb4c45f55fe696 Mon Sep 17 00:00:00 2001 From: kawasima Date: Wed, 28 Sep 2016 16:54:42 +0900 Subject: [PATCH 3/5] Fixes the problem by range search --- .../control_bus/component/jobs.clj | 10 ++- .../control_bus/component/jobs_test.clj | 65 ++++++++++++++++++- 2 files changed, 70 insertions(+), 5 deletions(-) diff --git a/src/clj/job_streamer/control_bus/component/jobs.clj b/src/clj/job_streamer/control_bus/component/jobs.clj index 3ffce1c..bee228b 100644 --- a/src/clj/job_streamer/control_bus/component/jobs.clj +++ b/src/clj/job_streamer/control_bus/component/jobs.clj @@ -78,10 +78,14 @@ {: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 (some->> until (f/parse (:date f/formatters)) .toDate)}))) + {:until (some-> until + parse-date-fn + (.plusDays 1) + .toDate)}))) (defn- parse-query-exit-status [q] (let [exit-status (.substring q (count "exit-status:"))] @@ -125,7 +129,7 @@ (:until qmap) (update-in [:where] conj - '[(<= ?end-time ?until-condition)]) + '[(< ?end-time ?until-condition)]) (:exit-status qmap) (update-in [:where] conj 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 ed3c787..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] @@ -46,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)] @@ -74,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" (some->> result :since (new DateTime) (f/unparse (:date f/formatters))))) - (is (= "2016-09-02" (some->> result :until (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)] From 7297d7b406cc09bc9732db8560b83212774844ec Mon Sep 17 00:00:00 2001 From: seki Date: Wed, 28 Sep 2016 18:59:16 +0900 Subject: [PATCH 4/5] enable schedule job execution --- .../unit8/job_streamer/control_bus/JobStreamerExecuteJob.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; From 855ab9e0f6f92e68f3e1f9c2821ea50797864c86 Mon Sep 17 00:00:00 2001 From: kawasima Date: Wed, 28 Sep 2016 18:00:43 +0900 Subject: [PATCH 5/5] Fixes the version for release --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 7df013a..39e898a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.7.1-SNAPSHOT +0.7.1