Search for user specified config file first
authorGeorgios Gousios <gousiosg@gmail.com>
Fri, 16 Mar 2012 16:11:17 +0000 (18:11 +0200)
committerGeorgios Gousios <gousiosg@gmail.com>
Fri, 16 Mar 2012 16:12:02 +0000 (18:12 +0200)
src/main/scala/gr/grnet/aquarium/logic/accounting/Policy.scala
src/main/scala/gr/grnet/aquarium/logic/accounting/RoleAgreements.scala

index c60bfaa..a73e80f 100644 (file)
@@ -43,7 +43,8 @@ import gr.grnet.aquarium.util.date.TimeHelpers
 import gr.grnet.aquarium.util.Loggable
 import java.util.concurrent.atomic.AtomicReference
 import gr.grnet.aquarium.Configurator
-import com.ckkloverdos.maybe.{Failed, NoVal, Maybe, Just}
+import gr.grnet.aquarium.Configurator.Keys
+import com.ckkloverdos.maybe.{Failed, NoVal, Just}
 import collection.immutable.{TreeMap, SortedMap}
 
 /**
@@ -152,24 +153,10 @@ object Policy extends DSL with Loggable {
    * Set the configurator to use for loading policy stores. Should only
    * used for unit testing.
    */
-  /*private[logic] */def withConfigurator(config: Configurator): Unit =
+  def withConfigurator(config: Configurator): Unit =
     this.config = config
 
   /**
-   * Search default locations for a policy file and provide an
-   * arbitrary default if this cannot be found.
-   */
-   private[logic] def policyFile = {
-    BasicResourceContext.getResource(PolicyConfName) match {
-      case Just(policyResource) ⇒
-        val path = policyResource.url.getPath
-        new File(path)
-      case _ ⇒
-        new File("policy.yaml")
-    }
-  }
-
-  /**
    * Check whether the policy definition file (in whichever path) is
    * newer than the latest stored policy, reload and set it as current.
    * This method has side-effects to this object's state.
@@ -187,7 +174,7 @@ object Policy extends DSL with Loggable {
 
     //2. Check whether policy file has been updated
     val latestPolicyChange = if (pol.isEmpty) 0 else pol.last.validFrom
-    val policyf = policyFile
+    val policyf = MasterConfigurator.findConfigFile(PolicyConfName, Keys.aquarium_policy, PolicyConfName)
     var updated = false
 
     if (policyf.exists) {
index 8e2dc79..7fa0623 100644 (file)
@@ -37,6 +37,7 @@ package gr.grnet.aquarium.logic.accounting
 
 import dsl.DSLAgreement
 import gr.grnet.aquarium.util.Loggable
+import gr.grnet.aquarium.Configurator
 import gr.grnet.aquarium.Configurator.{MasterConfigurator, Keys}
 import io.Source
 import java.io.{InputStream, File}
@@ -77,10 +78,12 @@ object RoleAgreements extends Loggable {
    */
   private[logic] def loadMappings = synchronized {
     val config = MasterConfigurator.get(Keys.aquarium_role_agreement_map)
-    val configFile = new File(config)
+    val configFile = MasterConfigurator.findConfigFile(
+      Configurator.RolesAgreementsName, Keys.aquarium_role_agreement_map,
+      Configurator.RolesAgreementsName)
 
     def loadFromClasspath: Source = {
-      getClass.getClassLoader.getResourceAsStream("roles-agreements.map") match {
+      getClass.getClassLoader.getResourceAsStream(Configurator.RolesAgreementsName) match {
         case x: InputStream =>
           logger.warn("Using default role to agreement mappings, this is " +
             "problably not what you want")