Permalink
Browse files

Merge branch 'release/0.4.0-beta-1'

  • Loading branch information...
2 parents c56080f + 8653458 commit d17bd8c7b5850bb4b844d92609a21edc6ad41f39 @hugoduncan hugoduncan committed Feb 10, 2011
View
@@ -4,12 +4,12 @@
<parent>
<groupId>org.cloudhoist</groupId>
<artifactId>pallet-pom</artifactId>
- <version>0.4.0-SNAPSHOT</version>
+ <version>0.4.0-beta-1</version>
<relativePath>../pallet-pom</relativePath>
</parent>
<groupId>org.cloudhoist</groupId>
<artifactId>pallet</artifactId>
- <version>0.4.0-SNAPSHOT</version>
+ <version>0.4.0-beta-1</version>
<packaging>jar</packaging>
<name>pallet</name>
<description>
@@ -129,7 +129,7 @@
<dependency>
<groupId>vmfest</groupId>
<artifactId>vmfest</artifactId>
- <version>0.1.0-SNAPSHOT</version>
+ <version>0.1.0</version>
<optional>true</optional>
</dependency>
<dependency>
View
@@ -86,8 +86,8 @@
not, then report the exception."
[e]
(when-not (= e exit-task-exception)
- (report-error (.getMessage e))
- (.. e .printStackTrace *err*)))
+ (report-error (.getMessage e))
+ (.printStackTrace e)))
(defn pallet-task
"A pallet task.
View
@@ -162,13 +162,16 @@ configuration code."
[x y]
(let [before-fn (fn [f]
(let [before (:always-before (meta f))
- before (and before (find-var before))]
- (and before (:resource-fn (meta before)))))
+ before (if (or (set? before) (nil? before))
+ before
+ #{before})
+ before (seq (filter identity (map find-var before)))]
+ (into #{} (map (comp :resource-fn meta) before))))
fx (:f x)
fy (:f y)]
(cond
- (= (before-fn fx) (var-get fy)) -1
- (= (before-fn fy) (var-get fx)) 1
+ ((before-fn fx) (var-get fy)) -1
+ ((before-fn fy) (var-get fx)) 1
:else 0)))
(defn- execution-invocations
@@ -43,14 +43,20 @@
(script/defscript md5sum-verify [file & {:as options}])
(stevedore/defimpl md5sum-verify :default
[file & {:keys [quiet check] :or {quiet true check true} :as options}]
- ("md5sum" ~(stevedore/map-to-arg-string {:quiet quiet :check check}) ~file))
-(stevedore/defimpl md5sum-verify [#{:centos :amzn-linux :rhel}]
+ (chain-and
+ (cd @(dirname ~file))
+ ("md5sum"
+ ~(stevedore/map-to-arg-string {:quiet quiet :check check})
+ @(basename ~file))
+ (cd -)))
+(stevedore/defimpl md5sum-verify [#{:centos :debian :amzn-linux :rhel}]
[file & {:keys [quiet check] :or {quiet true check true} :as options}]
(chain-and
(cd @(dirname ~file))
("md5sum"
~(stevedore/map-to-arg-string {:status quiet :check check})
- @(basename ~file))))
+ @(basename ~file))
+ (cd -)))
(stevedore/defimpl md5sum-verify [#{:darwin :os-x}] [file & {:as options}]
(chain-and
(var testfile @(cut -d "' '" -f 2 ~file))
@@ -65,28 +71,50 @@
(script/defscript sed-file [file expr-map options])
-(stevedore/defimpl sed-file :default [file expr-map options]
+(def ^{:doc "Possible sed separators" :private true}
+ sed-separators
+ (concat [\/ \_ \| \: \% \! \@] (map char (range 42 127))))
+
+(stevedore/defimpl sed-file :default
+ [file expr-map {:keys [seperator restriction] :as options}]
("sed" "-i"
- ~(let [sep (:seperator options "/")]
+ ~(if (map? expr-map)
(string/join
" "
(map
- #(format "-e \"s%s%s%s%s%s\"" sep (first %) sep (second %) sep)
- expr-map)))
+ (fn [[key value]]
+ (let [used (fn [c]
+ (or (>= (.indexOf key (int c)) 0)
+ (>= (.indexOf value (int c)) 0)))
+ seperator (or seperator (first (remove used sed-separators)))]
+ (format
+ "-e \"%ss%s%s%s%s%s\""
+ (if restriction (str restriction " ") "")
+ seperator key seperator value seperator)))
+ expr-map))
+ (format "-e \"%s%s\"" (when restriction (str restriction " ")) expr-map))
~file))
-(script/defscript download-file [url path])
+(script/defscript download-file [url path & {:keys [proxy]}])
-(stevedore/defimpl download-file :default [url path]
+(stevedore/defimpl download-file :default [url path & {:keys [proxy]}]
(if (test @(which curl))
("curl" "-o" (quoted ~path)
--retry 5 --silent --show-error --fail --location
+ ~(if proxy
+ (let [url (java.net.URL. proxy)]
+ (format "--proxy %s:%s" (.getHost url) (.getPort url)))
+ "")
(quoted ~url))
(if (test @(which wget))
- ("wget" "-O" (quoted ~path) --tries 5 --no-verbose (quoted ~url))
- (do
- (println "No download utility available")
- (exit 1)))))
+ ("wget" "-O" (quoted ~path) --tries 5 --no-verbose
+ ~(if proxy
+ (format "-e \"http_proxy = %s\" -e \"ftp_proxy = %s\"" proxy proxy)
+ "")
+ (quoted ~url))
+ (do
+ (println "No download utility available")
+ (exit 1)))))
(script/defscript download-request [path request])
(stevedore/defimpl download-request :default [path request]
@@ -192,7 +220,7 @@
(defresource sed
"Execute sed on a file. Takes a path and a map for expr to replacement."
(sed*
- [request path exprs-map & {:keys [seperator no-md5] :as options}]
+ [request path exprs-map & {:keys [seperator no-md5 restriction] :as options}]
(stevedore/checked-script
(format "sed file %s" path)
(sed-file ~path ~exprs-map ~options)
@@ -0,0 +1,79 @@
+(ns pallet.resource.network-service
+ "Resource for working with network services"
+ (:require
+ [pallet.resource.exec-script :as exec-script]))
+
+(defn wait-for-port-listen
+ "Wait for the network port `port` to be in a listening state.
+
+ Options:
+ - :standoff time between checking port state (seconds)
+ - :max-retries number of times to test port state before erroring
+ - :service-name name of service to use in messages (defaults to port)"
+
+ [request port & {:keys [max-retries standoff service-name]
+ :or {max-retries 5 standoff 2
+ service-name (str "port " port)}}]
+ (->
+ request
+ (exec-script/exec-checked-script
+ (format "Wait for %s to be in a listen state" service-name)
+ (group (chain-or (let x 0) true))
+ (while
+ (pipe (netstat -lnt) (awk ~(format "'$4 ~ /:%s$/ {exit 1}'" port)))
+ (let x (+ x 1))
+ (if (= ~max-retries @x)
+ (do
+ (println
+ ~(format "Timed out waiting for listen state for %s" service-name)
+ >&2)
+ (exit 1)))
+ (println ~(format "Waiting for %s to be in a listen state" service-name))
+ (sleep ~standoff))
+ (sleep ~standoff))))
+
+(defn wait-for-http-status
+ "Wait for a url to respond with the given HTTP status code.
+
+ Options:
+ - :standoff time between checking HTTP status (seconds)
+ - :max-retries number of times to test HTTP status before erroring
+ - :url-name name of url to use in messages (defaults to url)"
+
+ [request url status & {:keys [max-retries standoff url-name]
+ :or {max-retries 5 standoff 2
+ url-name url}}]
+ (->
+ request
+ (exec-script/exec-checked-script
+ (format "Wait for %s to return a %s status" url-name status)
+
+ (if ("test" @(shell/which wget))
+ (defn httpresponse []
+ (pipe
+ ("wget" -q -S -O "/dev/null" (quoted ~url) "2>&1")
+ ("grep" "HTTP/1.1")
+ ("tail" -1)
+ ("grep" -o -e (quoted "[0-9][0-9][0-9]"))))
+ (if ("test" @(shell/which curl))
+ (defn httpresponse []
+ ("curl" -sL -w (quoted "%{http_code}") (quoted ~url)
+ -o "/dev/null"))
+ (do
+ (println "No httpresponse utility available")
+ (shell/exit 1))))
+
+ (group (chain-or (let x 0) true))
+ (while
+ (!= ~status @(httpresponse))
+ (let x (+ x 1))
+ (if (= ~max-retries @x)
+ (do
+ (println
+ ~(format
+ "Timed out waiting for %s to return a %s status" url-name status)
+ >&2)
+ (exit 1)))
+ (println ~(format "Waiting for %s to return a %s status" url-name status))
+ (sleep ~standoff))
+ (sleep ~standoff))))
Oops, something went wrong.

0 comments on commit d17bd8c

Please sign in to comment.