 (ns backtype.storm.config
   (:import [java.io FileReader File])
-  (:import [backtype.storm Config])
+  (:import [backtype.storm Config Config$FieldValidator])
   (:import [backtype.storm.utils Utils LocalState])
   (:import [org.apache.commons.io FileUtils])
   (:require [clojure [string :as str]])

(defn read-default-config []
  (clojurify-structure (Utils/readDefaultConfig)))

(defn read-storm-config []
  (clojurify-structure (Utils/readStormConfig)))

(defn read-yaml-config [name]
  (clojurify-structure (Utils/findAndReadConfigFile name true)))

(defn master-local-dir [conf]
  (let [ret (str (conf STORM-LOCAL-DIR) "/nimbus")]

  (dofor [f (seq (.getFields Config))]
         (.get f nil)
         ))

;; Create a mapping of config-string -> validator
;; Config fields must have a _SCHEMA field defined
(def CONFIG-SCHEMA-MAP
  (reduce (fn [mp [k v]] (assoc mp k v)) {}
    (for [f (seq (.getFields Config))
      :when (not (re-matches #".*_SCHEMA$" (.getName f)))
      :let [k (.get f nil)
            nam (.getName f) 
            field-to-get (str/replace nam #"$" "_SCHEMA")
;            _ (println (str "Trying to set " k " to " field-to-get " value"))
            v (-> Config (.getField field-to-get) (.get nil))
;            _ (println (str "and value was " v ))
            ]]
      [k v]
    )
  )
)

(defn cluster-mode [conf & args]
  (keyword (conf STORM-CLUSTER-MODE)))
