Support for expanding all timeslots for a timeframe
authorGeorgios Gousios <gousiosg@gmail.com>
Mon, 28 Nov 2011 08:59:55 +0000 (10:59 +0200)
committerGeorgios Gousios <gousiosg@gmail.com>
Mon, 28 Nov 2011 09:01:01 +0000 (11:01 +0200)
logic/src/main/scala/gr/grnet/aquarium/logic/accounting/dsl/DSLUtils.scala
logic/src/test/scala/gr/grnet/aquarium/logic/test/DSLUtilsTest.scala
logic/src/test/scala/gr/grnet/aquarium/logic/test/EventProcessorTest.scala

index cee121b..ef25307 100644 (file)
@@ -46,12 +46,24 @@ import java.util.{GregorianCalendar, Calendar, Date}
 trait DSLUtils extends DateUtils {
 
   /**
+   * Get a list of all timeslots within which a algorithm/pricelist
+   * is effective.
+   */
+  def allEffectiveTimeslots(spec: DSLTimeFrame, from: Date, to: Date):
+    List[(Date, Date)] = {
+
+    
+
+    spec.repeat.flatMap{r =>effectiveTimeslots(r, from, Some(to))} sortWith sorter
+  }
+
+  /**
    * Get a list of all time periods within which a time frame is active.
    * If the to date is None, the expansion takes place within a timeframe
    * between `from .. from` + 1 year. The result is returned sorted by
    * timeframe start date.
    */
-  def expandTimeRepeat(spec: DSLTimeFrameRepeat, from: Date, to: Option[Date]):
+  def effectiveTimeslots(spec: DSLTimeFrameRepeat, from: Date, to: Option[Date]):
     List[(Date, Date)] = {
 
     assert(spec.start.size == spec.end.size)
@@ -65,12 +77,13 @@ trait DSLUtils extends DateUtils {
       case Some(y) => y
     }
 
-    def sorter(x: (Date, Date), y: (Date, Date)) : Boolean =
-      if (y._1 after x._1) true else false
-
     coExpandTimespecs(spec.start.zip(spec.end), from, endDate) sortWith sorter
   }
 
+  
+  private def sorter(x: (Date, Date), y: (Date, Date)) : Boolean =
+    if (y._1 after x._1) true else false
+
   /**
    * Calculate periods of activity for a list of timespecs
    */
index 7158335..8ab3c82 100644 (file)
@@ -89,14 +89,14 @@ class DSLUtilsTest extends DSLUtils with TestMethods with DSL {
   }
 
   @Test
-  def testExpandTimeRepeat = {
+  def testEffectiveTimeslots = {
     val from =  new Date(1321621969000L) //Fri Nov 18 15:12:49 +0200 2011
     val to =  new Date(1324214719000L)   //Sun Dec 18 15:25:19 +0200 2011
 
     var repeat = DSLTimeFrameRepeat(parseCronString("00 12 * * *"),
       parseCronString("00 14 * * *"))
 
-    var result = expandTimeRepeat(repeat, from, Some(to))
+    var result = effectiveTimeslots(repeat, from, Some(to))
 
     assertNotEmpty(result)
     assertEquals(31, result.size)
@@ -104,17 +104,17 @@ class DSLUtilsTest extends DSLUtils with TestMethods with DSL {
     //Expansion outside timeframe
     repeat = DSLTimeFrameRepeat(parseCronString("00 12 * May *"),
       parseCronString("00 14 * Sep *"))
-    result = expandTimeRepeat(repeat, from, Some(to))
+    result = effectiveTimeslots(repeat, from, Some(to))
     assertEquals(0, result.size)
 
     repeat = DSLTimeFrameRepeat(parseCronString("00 12 * * 5"),
       parseCronString("00 14 * * 1"))
-    result = expandTimeRepeat(repeat, from, Some(to))
+    result = effectiveTimeslots(repeat, from, Some(to))
     assertEquals(4, result.size)
 
     repeat = DSLTimeFrameRepeat(parseCronString("00 12 * * Mon,Wed,Fri"),
       parseCronString("00 14 * * Tue,Thu,Sat"))
-    result = expandTimeRepeat(repeat, from, Some(to))
+    result = effectiveTimeslots(repeat, from, Some(to))
     assertEquals(13, result.size)
   }
 }
\ No newline at end of file
index b06f83b..9afaa2f 100644 (file)
 
 package gr.grnet.aquarium.logic.test
 
-import java.util.Date
-import gr.grnet.aquarium.logic.events._
 import org.junit.Test
 
 class EventProcessorTest {
 
-   def getEvents(): List[Event] = {
-    //Tmp list of events
-    List[Event](
-      new VMCreated(1, new Date(123), 2, 1),
-      new VMStarted(2, new Date(123), 2, 1),
-      new VMCreated(3, new Date(125), 2, 2),
-      new DiskSpaceChanged(4, new Date(122), 2, 1554),
-      new DataUploaded(5, new Date(122), 2, 1554),
-      new DiskSpaceChanged(6, new Date(122), 1, 1524),
-      new DataUploaded(7, new Date(122), 1, 1524),
-      new DiskSpaceChanged(8, new Date(122), 1, 1332)
-    )
-  }
-  
   @Test
   def testProcess() = {
   }