diff --git a/src/ciste/config.clj b/src/ciste/config.clj index 3624cab..081012f 100644 --- a/src/ciste/config.clj +++ b/src/ciste/config.clj @@ -25,15 +25,7 @@ [clojurewerkz.propertied.properties :as p] [environ.core :refer [env]] [slingshot.slingshot :refer [throw+ try+]]) - (:import java.io.FileNotFoundException - java.net.InetAddress)) - -;; TODO: read from env var -(defonce - ^{:dynamic true - :doc "The current environment. use the set-environment!, - environment, and with"} - *environment* (atom nil)) + (:import java.net.InetAddress)) (defonce ^{:dynamic true @@ -52,20 +44,6 @@ [] (.getHostAddress (InetAddress/getLocalHost))) -(defn environment* - [] - @*environment*) - -(defn environment - "Returns the currently bound environment. - - Throws an exception if no environment is bound" - [] - (or (environment*) - (throw - (RuntimeException. - "Environment not set. export CISTE_ENV to choose an environment")))) - (defn merge-config "Recursively merges m1 into m2. If the value of any of the key is a map, the elements in that map are also merged" @@ -125,31 +103,7 @@ (let [value (apply config* ks)] (if-not (nil? value) value - (throw - (IllegalArgumentException. - (str "no config option matching path " ks " for " (environment)))))))) - -(defn set-config! - "Set the value of the config setting matching the key sequence" - [ks value] - (dosync - (alter *config-map* - assoc-in (concat [(environment)] ks) value)) - value) - -(defn set-environment! - "Sets's the environment globally" - [env] - (timbre/with-context {:env env} - (timbre/debugf "Setting environment - %s" env)) - (dosync (reset! *environment* env))) - -(defmacro with-environment - "Run body with the evironment bound" - [environment & body] - `(binding [ciste.config/*environment* (atom nil)] - (set-environment! ~environment) - ~@body)) + (throw (IllegalArgumentException. (str "no config option matching path " ks))))))) (defmacro describe-config "Macro to record config information diff --git a/src/ciste/runner.clj b/src/ciste/runner.clj index cccdcb3..f9f6247 100644 --- a/src/ciste/runner.clj +++ b/src/ciste/runner.clj @@ -2,7 +2,7 @@ "This is the runner for ciste applications. Specify this namespace as the main class of your application." - (:require [ciste.config :refer [config describe-config set-environment!]] + (:require [ciste.config :refer [config describe-config]] [ciste.service :as service] [environ.core :refer [env]] [taoensso.timbre :as timbre]) @@ -15,10 +15,13 @@ "A namespace containing a logging config") (defn configure-logging - [environment] - (let [logger (symbol (env :ciste-logger "ciste.logger"))] - (require logger) - ((ns-resolve logger 'set-logger)))) + [] + (try + (let [logger (symbol (env :ciste-logger "ciste.logger"))] + (require logger) + ((ns-resolve logger 'set-logger))) + (catch Exception ex + (timbre/error "Could not set up logging" ex)))) (defn stop-application! [] @@ -29,14 +32,11 @@ (timbre/error "Application promise is nil"))) (defn start-application! - ([] (start-application! (env :ciste-env "default"))) - ([environment] (start-application! environment nil)) - ([environment modules] - (set-environment! environment) - (configure-logging environment) - (timbre/with-context {:env environment} - (timbre/infof "Starting application with environment: %s" environment)) - (service/init-services environment modules) + ([] (start-application! nil)) + ([modules] + (configure-logging) + (timbre/infof "Starting application") + (service/init-services modules) ;; (service/start-services!) (dosync (ref-set application-promise (promise))) (timbre/info "application initialized") diff --git a/src/ciste/service.clj b/src/ciste/service.clj index a277bc2..2ed9ca9 100644 --- a/src/ciste/service.clj +++ b/src/ciste/service.clj @@ -24,13 +24,11 @@ (defn init-services "Ensure that all namespaces for services have been required and that the config provider has benn initialized" - ([environment] (init-services environment nil)) - ([environment modules] - (timbre/info "initializing services") - ;; TODO: initialize config backend - (load-config! (env :ciste-properties (str "config/" (name environment) ".properties"))) - (loader/require-modules modules) - (loader/process-requires))) + [modules] + ;; TODO: initialize config backend + (load-config! (env :ciste-properties "config/ciste.properties")) + (loader/require-modules modules) + (loader/process-requires)) (defn stop-services! "Shut down all services" diff --git a/src/ciste/test_helper.clj b/src/ciste/test_helper.clj index 4103759..ea0e099 100644 --- a/src/ciste/test_helper.clj +++ b/src/ciste/test_helper.clj @@ -5,6 +5,6 @@ "Wrapper to ensure tests are run in the test environment" [& body] `(do - (start-application! :test) + (start-application!) ~@body (stop-application!))) diff --git a/test/ciste/config_test.clj b/test/ciste/config_test.clj index 396d088..3256881 100644 --- a/test/ciste/config_test.clj +++ b/test/ciste/config_test.clj @@ -1,14 +1,11 @@ (ns ciste.config-test - (:require [ciste.config :refer [environment get-host-address merge-config]] + (:require [ciste.config :refer [get-host-address merge-config]] [midje.sweet :refer [contains fact =>]])) (fact "#'ciste.config/get-host-address" (fact "should return a string" (get-host-address) => string?)) -(fact "#'ciste.config/environment" - (environment) => :test) - (fact "#'ciste.config/merge-config" (let [m1 {:key1 "value1" :key2 {:sub-key1 "value2"