diff --git a/blobstore/src/main/clojure/org/jclouds/blobstore.clj b/blobstore/src/main/clojure/org/jclouds/blobstore.clj index 3ae9545754..b28b4a46aa 100644 --- a/blobstore/src/main/clojure/org/jclouds/blobstore.clj +++ b/blobstore/src/main/clojure/org/jclouds/blobstore.clj @@ -100,9 +100,9 @@ Options can also be specified for extension modules (blobstore-context? (first args)) (.getBlobStore (first args)) :else (apply blobstore args))) -(def *blobstore*) +(def ^{:dynamic :true} *blobstore*) -(def *max-retries* 3) +(def ^{:dynamic :true} *max-retries* 3) (defmacro with-blobstore [[& blobstore-or-args] & body] `(binding [*blobstore* (as-blobstore ~@blobstore-or-args)] @@ -249,7 +249,7 @@ Note: (apply concat coll) or (lazy-cat coll) are not lazy wrt coll itself." ([container-name path #^BlobStore blobstore] (.blobMetadata blobstore container-name path))) -(defn get-blob +(defn ^{:dynamic :true} get-blob "Get blob from given path" ([container-name path] (get-blob container-name path *blobstore*)) diff --git a/blobstore/src/test/clojure/org/jclouds/blobstore2_test.clj b/blobstore/src/test/clojure/org/jclouds/blobstore2_test.clj index 7cb86c2d73..99651f9e77 100644 --- a/blobstore/src/test/clojure/org/jclouds/blobstore2_test.clj +++ b/blobstore/src/test/clojure/org/jclouds/blobstore2_test.clj @@ -34,95 +34,94 @@ (delete-container blobstore (.getName container))) (f))) -(def *blobstore* (blobstore "transient" "" "")) +(def blobstore-stub (blobstore "transient" "" "")) -(use-fixtures :each (clean-stub-fixture *blobstore*)) +(use-fixtures :each (clean-stub-fixture blobstore-stub)) (deftest blobstore?-test - (is (blobstore? *blobstore*))) + (is (blobstore? blobstore-stub))) (deftest as-blobstore-test - (is (blobstore? (blobstore "transient" "user" "password"))) - (is (blobstore? *blobstore*))) + (is (blobstore? (blobstore "transient" "user" "password")))) (deftest create-existing-container-test - (is (not (container-exists? *blobstore* ""))) - (is (create-container *blobstore* "fred")) - (is (container-exists? *blobstore* "fred"))) + (is (not (container-exists? blobstore-stub ""))) + (is (create-container blobstore-stub "fred")) + (is (container-exists? blobstore-stub "fred"))) (deftest create-container-test - (is (create-container *blobstore* "fred")) - (is (container-exists? *blobstore* "fred"))) + (is (create-container blobstore-stub "fred")) + (is (container-exists? blobstore-stub "fred"))) (deftest locations-test - (is (not (empty? (locations *blobstore*)))) - (is (create-container *blobstore* "fred" - :location (first (locations *blobstore*))))) + (is (not (empty? (locations blobstore-stub)))) + (is (create-container blobstore-stub "fred" + :location (first (locations blobstore-stub))))) (deftest containers-test - (is (empty? (containers *blobstore*))) - (is (create-container *blobstore* "fred")) - (is (= 1 (count (containers *blobstore*))))) + (is (empty? (containers blobstore-stub))) + (is (create-container blobstore-stub "fred")) + (is (= 1 (count (containers blobstore-stub))))) (deftest blobs-test - (is (create-container *blobstore* "container")) - (is (empty? (blobs *blobstore* "container"))) - (is (put-blob *blobstore* "container" + (is (create-container blobstore-stub "container")) + (is (empty? (blobs blobstore-stub "container"))) + (is (put-blob blobstore-stub "container" (blob "blob1" :payload "blob1" :calculate-md5 true))) - (is (put-blob *blobstore* "container" + (is (put-blob blobstore-stub "container" (blob "blob2" :payload "blob2" :calculate-md5 true))) - (is (= 2 (count (blobs *blobstore* "container")))) - (is (= 1 (count (blobs *blobstore* "container" :max-results 1)))) - (create-directory *blobstore* "container" "dir") - (is (put-blob *blobstore* "container" + (is (= 2 (count (blobs blobstore-stub "container")))) + (is (= 1 (count (blobs blobstore-stub "container" :max-results 1)))) + (create-directory blobstore-stub "container" "dir") + (is (put-blob blobstore-stub "container" (blob "dir/blob2" :payload "blob2" :calculate-md5 true))) - (is (= 3 (count-blobs *blobstore* "container"))) - (is (= 3 (count (blobs *blobstore* "container")))) - (is (= 4 (count (blobs *blobstore* "container" :recursive true)))) - (is (= 3 (count (blobs *blobstore* "container" :with-details true)))) - (is (= 1 (count (blobs *blobstore* "container" :in-directory "dir"))))) + (is (= 3 (count-blobs blobstore-stub "container"))) + (is (= 3 (count (blobs blobstore-stub "container")))) + (is (= 4 (count (blobs blobstore-stub "container" :recursive true)))) + (is (= 3 (count (blobs blobstore-stub "container" :with-details true)))) + (is (= 1 (count (blobs blobstore-stub "container" :in-directory "dir"))))) (deftest large-container-list-test (let [container-name "test" total-blobs 5000] ;; create a container full of blobs - (create-container *blobstore* container-name) - (dotimes [i total-blobs] (put-blob *blobstore* container-name + (create-container blobstore-stub container-name) + (dotimes [i total-blobs] (put-blob blobstore-stub container-name (blob (str i) :payload (str i) :calculate-md5 true))) ;; verify - (is (= total-blobs (count-blobs *blobstore* container-name))))) + (is (= total-blobs (count-blobs blobstore-stub container-name))))) (deftest container-seq-test - (is (create-container *blobstore* "container")) - (is (empty? (container-seq *blobstore* "container"))) - (is (empty? (container-seq *blobstore* "container" "/a")))) + (is (create-container blobstore-stub "container")) + (is (empty? (container-seq blobstore-stub "container"))) + (is (empty? (container-seq blobstore-stub "container" "/a")))) (deftest get-blob-test - (is (create-container *blobstore* "blob")) - (is (put-blob *blobstore* "blob" + (is (create-container blobstore-stub "blob")) + (is (put-blob blobstore-stub "blob" (blob "blob1" :payload "blob1" :calculate-md5 true))) - (is (put-blob *blobstore* "blob" + (is (put-blob blobstore-stub "blob" (blob "blob2" :payload "blob2" :calculate-md5 true))) - (is (= "blob2" (Strings2/toStringAndClose (get-blob-stream *blobstore* + (is (= "blob2" (Strings2/toStringAndClose (get-blob-stream blobstore-stub "blob" "blob2"))))) (deftest put-blob-test ;; Check multipart works - (is (create-container *blobstore* "blobs")) - (is (put-blob *blobstore* "blobs" + (is (create-container blobstore-stub "blobs")) + (is (put-blob blobstore-stub "blobs" (blob "blob1" :payload "blob1") :multipart? true)) - (is (= 1 (count (blobs *blobstore* "blobs"))))) + (is (= 1 (count (blobs blobstore-stub "blobs"))))) (deftest sign-get-test - (let [request (sign-get *blobstore* "container" "path")] + (let [request (sign-get blobstore-stub "container" "path")] (is (= "http://localhost/container/path" (str (.getEndpoint request)))) (is (= "GET" (.getMethod request))))) (deftest sign-put-test - (let [request (sign-put *blobstore* "container" + (let [request (sign-put blobstore-stub "container" (blob "path" :content-length 10))] (is (= "http://localhost/container/path" (str (.getEndpoint request)))) (is (= "PUT" (.getMethod request))) @@ -131,7 +130,7 @@ (first (.get (.getHeaders request) "Content-Type")))))) (deftest sign-put-with-headers-test - (let [request (sign-put *blobstore* + (let [request (sign-put blobstore-stub "container" (blob "path" :content-length 10 @@ -147,7 +146,7 @@ (is (= "g" (first (.get (.getHeaders request) "Content-Encoding")))))) (deftest sign-delete-test - (let [request (sign-delete *blobstore* "container" "path")] + (let [request (sign-delete blobstore-stub "container" "path")] (is (= "http://localhost/container/path" (str (.getEndpoint request)))) (is (= "DELETE" (.getMethod request))))) @@ -161,34 +160,34 @@ (deftest payload-protocol-test (is (instance? org.jclouds.io.Payload (payload "test"))) (is (blob "blob1" :payload (payload "blob1"))) - (is (create-container *blobstore* "container")) + (is (create-container blobstore-stub "container")) (is (= "blob1" (do - (put-blob *blobstore* "container" + (put-blob blobstore-stub "container" (blob "blob1" :payload "blob1")) - (Strings2/toStringAndClose (get-blob-stream *blobstore* + (Strings2/toStringAndClose (get-blob-stream blobstore-stub "container" "blob1"))))) (is (= "blob2" (do - (put-blob *blobstore* "container" + (put-blob blobstore-stub "container" (blob "blob2" :payload (StringBufferInputStream. "blob2"))) - (Strings2/toStringAndClose (get-blob-stream *blobstore* + (Strings2/toStringAndClose (get-blob-stream blobstore-stub "container" "blob2"))))) (is (= "blob3" (do - (put-blob *blobstore* "container" + (put-blob blobstore-stub "container" (blob "blob3" :payload (.getBytes "blob3"))) - (Strings2/toStringAndClose (get-blob-stream *blobstore* + (Strings2/toStringAndClose (get-blob-stream blobstore-stub "container" "blob3"))))) (is (= "blob4" (do - (put-blob *blobstore* "container" + (put-blob blobstore-stub "container" (blob "blob4" :payload #(.write % (.getBytes "blob4")))) - (Strings2/toStringAndClose (get-blob-stream *blobstore* + (Strings2/toStringAndClose (get-blob-stream blobstore-stub "container" "blob4")))))) ;; TODO: more tests involving blob-specific functions diff --git a/compute/src/main/clojure/org/jclouds/compute.clj b/compute/src/main/clojure/org/jclouds/compute.clj index b0f6863a7e..21f4b7b639 100644 --- a/compute/src/main/clojure/org/jclouds/compute.clj +++ b/compute/src/main/clojure/org/jclouds/compute.clj @@ -109,7 +109,7 @@ See http://code.google.com/p/jclouds for details." (compute-context? (first args)) (.getComputeService (first args)) :else (apply compute-service args))) -(def *compute*) +(def ^{:dynamic :true} *compute*) (defmacro with-compute-service "Specify the default compute service" diff --git a/compute/src/test/clojure/org/jclouds/compute2_test.clj b/compute/src/test/clojure/org/jclouds/compute2_test.clj index 4de651a594..94f01d4ccd 100644 --- a/compute/src/test/clojure/org/jclouds/compute2_test.clj +++ b/compute/src/test/clojure/org/jclouds/compute2_test.clj @@ -42,7 +42,7 @@ list, Alan Dipert and MeikelBrandmeyer." (deftest os-families-test (is (some #{"centos"} (map str (os-families))))) -(def *compute* (compute-service "stub" "" "" :extensions [(ssh-test/ssh-test-client ssh-test/no-op-ssh-client)])) +(def compute-stub (compute-service "stub" "" "" :extensions [(ssh-test/ssh-test-client ssh-test/no-op-ssh-client)])) (defn clean-stub-fixture "This should allow basic tests to easily be run with another service." @@ -52,50 +52,50 @@ list, Alan Dipert and MeikelBrandmeyer." (destroy-node compute-service (.getId node))) (f))) -(use-fixtures :each (clean-stub-fixture *compute*)) +(use-fixtures :each (clean-stub-fixture compute-stub)) (deftest compute-service?-test - (is (compute-service? *compute*))) + (is (compute-service? compute-stub))) (deftest as-compute-service-test (is (compute-service? (compute-service "stub" "user" "password"))) - (is (compute-service? *compute*)) - (is (compute-service? (compute-service (compute-context *compute*))))) + (is (compute-service? compute-stub)) + (is (compute-service? (compute-service (compute-context compute-stub))))) (deftest nodes-test - (is (create-node *compute* "fred" (build-template *compute* {} ))) - (is (= 1 (count (nodes-in-group *compute* "fred")))) + (is (create-node compute-stub "fred" (build-template compute-stub {} ))) + (is (= 1 (count (nodes-in-group compute-stub "fred")))) ;; pass in a function that selects node metadata based on NodeMetadata field - (is (= 1 (count (nodes-with-details-matching *compute* (in-group? "fred"))))) + (is (= 1 (count (nodes-with-details-matching compute-stub (in-group? "fred"))))) ;; or make your query inline - (is (= 1 (count (nodes-with-details-matching *compute* #(= (.getGroup %) "fred"))))) + (is (= 1 (count (nodes-with-details-matching compute-stub #(= (.getGroup %) "fred"))))) ;; or get real fancy, and use the underlying Predicate object jclouds uses - (is (= 1 (count (nodes-with-details-matching *compute* + (is (= 1 (count (nodes-with-details-matching compute-stub (reify com.google.common.base.Predicate (apply [this input] (= (.getGroup input) "fred"))))))) - (is (= 0 (count (nodes-with-details-matching *compute* (in-group? "othergroup"))))) - (suspend-nodes-matching *compute* (in-group? "fred")) - (is (suspended? (first (nodes-with-details-matching *compute* (in-group? "fred"))))) - (resume-nodes-matching *compute* (in-group? "fred")) - (is (running? (first (nodes-in-group *compute* "fred")))) - (reboot-nodes-matching *compute* (in-group? "fred")) - (is (running? (first (nodes-in-group *compute* "fred")))) - (is (create-nodes *compute* "fred" 2 (build-template *compute* {} ))) - (is (= 3 (count (nodes-in-group *compute* "fred")))) - (is (= "fred" (group (first (nodes *compute*))))) - (destroy-nodes-matching *compute* (in-group? "fred")) - (is (terminated? (first (nodes-in-group *compute* "fred"))))) + (is (= 0 (count (nodes-with-details-matching compute-stub (in-group? "othergroup"))))) + (suspend-nodes-matching compute-stub (in-group? "fred")) + (is (suspended? (first (nodes-with-details-matching compute-stub (in-group? "fred"))))) + (resume-nodes-matching compute-stub (in-group? "fred")) + (is (running? (first (nodes-in-group compute-stub "fred")))) + (reboot-nodes-matching compute-stub (in-group? "fred")) + (is (running? (first (nodes-in-group compute-stub "fred")))) + (is (create-nodes compute-stub "fred" 2 (build-template compute-stub {} ))) + (is (= 3 (count (nodes-in-group compute-stub "fred")))) + (is (= "fred" (group (first (nodes compute-stub))))) + (destroy-nodes-matching compute-stub (in-group? "fred")) + (is (terminated? (first (nodes-in-group compute-stub "fred"))))) (defn localhost? [node] "Returns true if the localhost address is in the node's private ips" (seq? (some #(= "localhost" %) (private-ips node)))) (deftest compound-predicate-test - (is (create-node *compute* "my-group" (build-template *compute* {}))) - (is (= 0 (count (nodes-with-details-matching *compute* #(and (suspended? %) (not (localhost? %))))))) - (is (= 0 (count (nodes-with-details-matching *compute* #(and (suspended? %) (localhost? %)))))) - (is (= 0 (count (nodes-with-details-matching *compute* #(and (running? %) (localhost? %)))))) - (is (= 1 (count (nodes-with-details-matching *compute* #(and (running? %) (not (localhost? %)))))))) + (is (create-node compute-stub "my-group" (build-template compute-stub {}))) + (is (= 0 (count (nodes-with-details-matching compute-stub #(and (suspended? %) (not (localhost? %))))))) + (is (= 0 (count (nodes-with-details-matching compute-stub #(and (suspended? %) (localhost? %)))))) + (is (= 0 (count (nodes-with-details-matching compute-stub #(and (running? %) (localhost? %)))))) + (is (= 1 (count (nodes-with-details-matching compute-stub #(and (running? %) (not (localhost? %)))))))) (deftest run-script-on-nodes-matching-with-options-test (let [echo (Statements/exec "echo hello") @@ -103,20 +103,20 @@ list, Alan Dipert and MeikelBrandmeyer." (runAsRoot false) (wrapInInitScript false)) pred #(= (.getGroup %) "scriptednode")] - (is (create-node *compute* "scriptednode" (build-template *compute* {}))) - (is (run-script-on-nodes-matching *compute* pred echo script-options)) + (is (create-node compute-stub "scriptednode" (build-template compute-stub {}))) + (is (run-script-on-nodes-matching compute-stub pred echo script-options)) (is (thrown? NoSuchElementException - (run-script-on-nodes-matching *compute* #(= (.getGroup %) "nonexistingnode") echo script-options))))) + (run-script-on-nodes-matching compute-stub #(= (.getGroup %) "nonexistingnode") echo script-options))))) (deftest run-script-on-node-with-options-test (let [echo (Statements/exec "echo hello") script-options (.. (RunScriptOptions$Builder/overrideCredentialsWith (Credentials. "user" "password")) (runAsRoot false) (wrapInInitScript false)) - test_node (create-node *compute* "scriptednode" (build-template *compute* {}))] - (is (run-script-on-node *compute* (id test_node) echo script-options)) + test_node (create-node compute-stub "scriptednode" (build-template compute-stub {}))] + (is (run-script-on-node compute-stub (id test_node) echo script-options)) (is (thrown? NoSuchElementException - (run-script-on-node *compute* "nonexistingnode" echo script-options))))) + (run-script-on-node compute-stub "nonexistingnode" echo script-options))))) (deftest build-template-test (let [service (compute-service "stub" "user" "password")] diff --git a/core/src/main/clojure/org/jclouds/core.clj b/core/src/main/clojure/org/jclouds/core.clj index 2279c83d00..a7a574bfb7 100644 --- a/core/src/main/clojure/org/jclouds/core.clj +++ b/core/src/main/clojure/org/jclouds/core.clj @@ -24,7 +24,7 @@ (com.google.common.collect ImmutableSet)) (:require [clojure.string :as string])) -(def module-lookup +(def ^{:dynamic :true} module-lookup {:log4j 'org.jclouds.logging.log4j.config.Log4JLoggingModule :slf4j 'org.jclouds.logging.slf4j.config.SLF4JLoggingModule :lognull 'org.jclouds.logging.config.NullLoggingModule