fixed so that you can pass properties into blobstore

This commit is contained in:
Adrian Cole 2011-03-29 13:05:24 -07:00
parent 550056d214
commit 5fd7e559f4
1 changed files with 16 additions and 9 deletions

View File

@ -23,12 +23,12 @@
Current supported services are: Current supported services are:
[transient, filesystem, azureblob, atmos, walrus, scaleup-storage, [transient, filesystem, azureblob, atmos, walrus, scaleup-storage,
googlestorage, synaptic, peer1-storage, aws-s3, eucalyptus-partnercloud-s3, googlestorage, synaptic, peer1-storage, aws-s3, eucalyptus-partnercloud-s3,
cloudfiles-us, cloudfiles-uk, swift, scality-rs2, hosteurope-storage] cloudfiles-us, cloudfiles-uk, swift, scality-rs2, hosteurope-storage
tiscali-storage]
Here's a quick example of how to viewresources in rackspace Here's a quick example of how to viewresources in rackspace
(use 'org.jclouds.blobstore) (use 'org.jclouds.blobstore)
(use 'clojure.contrib.pprint)
(def user \"rackspace_username\") (def user \"rackspace_username\")
(def password \"rackspace_password\") (def password \"rackspace_password\")
@ -42,6 +42,7 @@ Here's a quick example of how to viewresources in rackspace
See http://code.google.com/p/jclouds for details." See http://code.google.com/p/jclouds for details."
(:use [org.jclouds.core]) (:use [org.jclouds.core])
(:import [java.io File FileOutputStream OutputStream] (:import [java.io File FileOutputStream OutputStream]
java.util.Properties
[org.jclouds.blobstore [org.jclouds.blobstore
AsyncBlobStore BlobStore BlobStoreContext BlobStoreContextFactory AsyncBlobStore BlobStore BlobStoreContext BlobStoreContextFactory
domain.BlobMetadata domain.StorageMetadata domain.Blob domain.BlobMetadata domain.StorageMetadata domain.Blob
@ -63,14 +64,20 @@ Options for communication style
:sync and :async. :sync and :async.
Options can also be specified for extension modules Options can also be specified for extension modules
:log4j :enterprise :ning :apachehc :bouncycastle :joda :gae" :log4j :enterprise :ning :apachehc :bouncycastle :joda :gae"
[#^String service #^String account #^String key & options] ([#^String provider #^String provider-identity #^String provider-credential
(let [context & options]
(.createContext (let [module-keys (set (keys module-lookup))
(BlobStoreContextFactory.) service account key ext-modules (filter #(module-keys %) options)
(apply modules (filter #(not (#{:sync :async} %)) options)))] opts (apply hash-map (filter #(not (module-keys %)) options))]
(if (some #(= :async %) options) (let [context (.. (BlobStoreContextFactory.)
(createContext
provider provider-identity provider-credential
(apply modules (concat ext-modules (opts :extensions)))
(reduce #(do (.put %1 (name (first %2)) (second %2)) %1)
(Properties.) (dissoc opts :extensions))))]
(if (some #(= :async %) options)
(.getAsyncBlobStore context) (.getAsyncBlobStore context)
(.getBlobStore context)))) (.getBlobStore context))))))
(defn blobstore-context (defn blobstore-context
"Returns a blobstore context from a blobstore." "Returns a blobstore context from a blobstore."