1 package gr.grnet.aquarium.charging.bill
3 import gr.grnet.aquarium.charging.state.WorkingUserState
4 import gr.grnet.aquarium.util.json.JsonSupport
5 import com.ckkloverdos.resource.FileStreamResource
7 import com.ckkloverdos.props.Props
8 import gr.grnet.aquarium.converter.{PrettyJsonTextFormat, StdConverters}
9 import gr.grnet.aquarium.{Aquarium, ResourceLocator, AquariumBuilder}
10 import gr.grnet.aquarium.store.memory.MemStoreProvider
11 import gr.grnet.aquarium.converter.StdConverters._
13 import gr.grnet.aquarium.logic.accounting.dsl.Timeslot
16 * Copyright 2011-2012 GRNET S.A. All rights reserved.
18 * Redistribution and use in source and binary forms, with or
19 * without modification, are permitted provided that the following
22 * 1. Redistributions of source code must retain the above
23 * copyright notice, this list of conditions and the following
26 * 2. Redistributions in binary form must reproduce the above
27 * copyright notice, this list of conditions and the following
28 * disclaimer in the documentation and/or other materials
29 * provided with the distribution.
31 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
32 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
33 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
34 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
35 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
36 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
37 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
38 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
39 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
41 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGE.
44 * The views and conclusions contained in the software and
45 * documentation are those of the authors and should not be
46 * interpreted as representing official policies, either expressed
47 * or implied, of GRNET S.A.
52 * @author Prodromos Gerakios <pgerakios@grnet.gr>
55 class EventEntry(id:String,
61 credits:String) extends JsonSupport {
65 class ResourceEntry(val resourceName : String,
66 val resourceType : String,
67 val unitName : String,
68 val totalCredits : String,
69 val details : List[EventEntry]) extends JsonSupport {
73 class BillEntry(val id:String,
76 val remainingCredits:String,
77 val deductedCredits:String,
80 val bill:List[ResourceEntry]
81 ) extends JsonSupport {
86 def fromWorkingUserState(t:Timeslot,w:Option[WorkingUserState]) : BillEntry = {
87 //TODO: get entries at timeslot "t"
88 val eventEntry = new EventEntry("1234","onOff","0.1","323232323","3232223456","10000","5.00")
89 val resourceEntry = new ResourceEntry("VM_1","vmtime","0.01","5.0",List(eventEntry))
90 new BillEntry("323232","loverdos@grnet.gr","ok","100.00","5.00","23023020302","23232323",
95 def main(args: Array[String]) = {
96 //Console.err.println("JSON: " + (new BillEntry).toJsonString)
97 val propsfile = new FileStreamResource(new File("a1.properties"))
98 var _props: Props = Props(propsfile)(StdConverters.AllConverters).getOr(Props()(StdConverters.AllConverters))
99 val aquarium = new AquariumBuilder(_props, ResourceLocator.DefaultPolicyModel).
100 update(Aquarium.EnvKeys.storeProvider, new MemStoreProvider).
101 update(Aquarium.EnvKeys.eventsStoreFolder,Some(new File(".."))).