   (:require [aws.sdk.ec2 :as ec2])
   (:import (java.util UUID))
   (:use 
+    [minderbinder.time :only (parse-time-unit)]
+    [slingshot.slingshot :only  [throw+ try+]]
     [aws.sdk.ec2 :only 
        (run-instances describe-instances terminate-instances start-instances
         stop-instances instance-filter instance-id-filter)]

          this)
  (delete [this]
          (debug "deleting" uuid)
          (ec2 terminate-instances (@ids uuid)))
  (start [this]
         (debug "starting" uuid)
         (ec2 start-instances (@ids uuid)))
  (stop [this]
        (debug "stopping" uuid )
        (stop-instances  (@ids uuid)))
  (status [this] 
          (-> (ec2 describe-instances (instance-id-filter (@ids uuid)))
              first :instances first :state :name

  (apply ->Instance (translate spec)))

(comment 
  (use 'celestial.fixtures)
  (def m (.create (vconstruct celestial.fixtures/redis-ec2-spec))) 
  (.start m)
  (.status m) 
  (.stop m) 
  (wait-for-status m "stopped") 
  (.delete m)
  (parse-time-unit [1 :minute])
  (wait-for-status m "running" {:timeout [1 :minute]}) 
  ) 


