Skip to content

Commit

Permalink
Merge pull request #50 from seki-seki/fix/deploy
Browse files Browse the repository at this point in the history
Enable undeploy
  • Loading branch information
kawasima authored Dec 27, 2016
2 parents e2dbcb1 + 41060ad commit 7185369
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/clj/job_streamer/control_bus/component/apps.clj
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,13 @@
:application/description (:application/description app)
:application/classpaths (:application/classpaths app)}]))
(register-app applications (assoc app :application/name "default"))

(when-let [components (scan-components (:application/classpaths app))]
(let [batch-component-id (find-batch-component datomic "default")]
(when batch-component-id
(d/transact datomic
[[:db.fn/retractEntity batch-component-id]]))
(d/transact datomic
[(merge {:db/id (or batch-component-id
[ (merge {:db/id (or batch-component-id
(d/tempid :db.part/user))
:batch-component/application [:application/name "default"]}
components)]))))
Expand Down Expand Up @@ -144,8 +146,11 @@
:application/description description})
(when-let [components (scan-components classpaths)]
(let [batch-component-id (find-batch-component datomic app-name)]
(when batch-component-id
(d/transact datomic
[[:db.fn/retractEntity batch-component-id]]))
(d/transact datomic
[(merge {:db/id (or batch-component-id
[ (merge {:db/id (or batch-component-id
(d/tempid :db.part/user))
:batch-component/application [:application/name app-name]}
components)])))))
Expand Down
44 changes: 43 additions & 1 deletion test/clj/job_streamer/control_bus/component/apps_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,48 @@
:migration [:datomic]})
(component/start-system)))

(deftest list-resources
(let [system (new-system config)
list-handler (-> (apps/list-resource (:apps system)))
entry-handler (-> (apps/batch-components-resource (:apps system) "default"))
get-request {:request-method :get}]
(testing "deploy app"
(let [post-request {:request-method :post
:content-type "application/edn"
:body (pr-str {:application/name "default",
:application/description "This is examples.",
:application/classpaths []})}]
(with-redefs-fn
{#'apps/scan-components (fn [classpaths]
{:batch-component/batchlet ["batchlet1", "batchelt2"]
:batch-component/item-reader []
:batch-component/item-writer []
:batch-component/item-processor []
:batch-component/throwable []})}
#(list-handler post-request))
(is (entry-handler get-request)
{:batch-component/batchlet ["batchlet1", "batchelt2"]
:batch-component/item-reader []
:batch-component/item-writer []
:batch-component/item-processor []
:batch-component/throwable []})))
(testing "undeploy app"
(let [post-request {:request-method :post
:content-type "application/edn"
:body (pr-str {:application/name "default",
:application/description "This is examples.",
:application/classpaths []})}]
(with-redefs-fn
{#'apps/scan-components (fn [classpaths]
{:batch-component/batchlet ["batchlet1"]
:batch-component/item-reader []
:batch-component/item-writer []
:batch-component/item-processor []
:batch-component/throwable []})}
#(list-handler post-request))
(is (= (-> get-request entry-handler :body read-string :batch-component/batchlet)
["org.jobstreamer.batch.ShellBatchlet" "batchlet1"]))))))

(deftest batch-components-resource
(let [system (new-system config)
handler (-> (apps/batch-components-resource (:apps system) "default"))]
Expand All @@ -45,7 +87,7 @@
(io/delete-file uploaded))]
(try
(delete-updated)
(is (is (= 201 (-> (handler request) :status))))
(is (= 201 (-> (handler request) :status)))
(is (.exists uploaded))
(finally (delete-updated)))))

Expand Down

0 comments on commit 7185369

Please sign in to comment.