Override algorithms and effectivity periods with super-policy values
authorGeorgios Gousios <gousiosg@gmail.com>
Wed, 26 Oct 2011 14:39:47 +0000 (17:39 +0300)
committerGeorgios Gousios <gousiosg@gmail.com>
Wed, 26 Oct 2011 14:40:18 +0000 (17:40 +0300)
logic/src/main/scala/gr/grnet/aquarium/logic/accounting/dsl/DSL.scala

index 93d3529..eb26883 100644 (file)
@@ -110,11 +110,13 @@ object DSL extends Loggable {
       r =>
         val algo = policy / r.name match {
           case x: YAMLStringNode => x.string
-          case _ => policyTmpl.algorithms.get(r.name) match {
-            case Some(y) => y
-            case None => throw new DSLParseException(("Cannot find " +
-              "calculation algorithm for resource %s in either policy %s or " +
-              "superpolicy %s").format(r.name, name, policyTmpl.name))
+          case _ => policyTmpl.equals(emptyPolicy) match {
+            case false => policyTmpl.algorithms.getOrElse(r,
+              throw new DSLParseException(("Severe! Superpolicy does not " +
+                "specify an algorithm for resource:%s").format(r.name)))
+            case true => throw new DSLParseException(("Cannot find " +
+              "calculation algorithm for resource %s in either policy %s or a" +
+              " superpolicy").format(r.name, name))
           }
         }
         Map(r -> algo)
@@ -122,8 +124,11 @@ object DSL extends Loggable {
 
     val timeframe = policy / Vocabulary.effective match {
       case x: YAMLMapNode => parseTimeFrame(x)
-      case _ => throw new DSLParseException(("No effectivity period for " +
-        "policy %s").format(name))
+      case _ => policyTmpl.equals(emptyPolicy) match {
+        case false => policyTmpl.effective
+        case true => throw new DSLParseException(("Cannot find effectivity " +
+          "period for policy %s ").format(name))
+      }
     }
 
     DSLPolicy(name, overr,