/
implementation.clj
57 lines (51 loc) · 1.61 KB
/
implementation.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
(ns pallet.compute.implementation
"Implementation details"
(:require
[chiba.plugin :refer [plugins]]
[clojure.tools.logging :as logging]))
(defmulti service
"Instantiate a compute service. Providers should implement a method for this.
See pallet.compute/instantiate-provider."
(fn [provider-name & _] (keyword provider-name)))
(def compute-prefix "pallet.compute")
(def exclude-compute-ns
#{'pallet.compute
'pallet.compute.jvm
'pallet.compute.implementation})
(def exclude-regex #".*test.*")
(def provider-list (atom nil))
(defn- providers
"Find the available providers."
[]
(->> (plugins compute-prefix exclude-regex)
(remove exclude-compute-ns)))
(defn load-providers
"Require all providers, ensuring no errors if individual providers can not be
loaded"
[]
(when-not @provider-list
(reset! provider-list (providers))
(let [loaded (filter
identity
(doall
(for [provider @provider-list]
(try
(require provider)
provider
(catch Throwable e
(logging/debugf
"%s provider failed to load: %s"
provider
(.getMessage e)))))))]
(reset! provider-list loaded)))
@provider-list)
(defn supported-providers
"Create a list of supported providers"
[]
(->>
(doall
(for [provider (load-providers)]
(when-let [providers (ns-resolve provider 'supported-providers)]
(@providers))))
(filter identity)
(apply concat)))