a14eff07520a02029fba258c73c062abad0a3acd
[aquarium] / src / main / scala / gr / grnet / aquarium / user / UserDataSnapshot.scala
1 /*
2  * Copyright 2011 GRNET S.A. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or
5  * without modification, are permitted provided that the following
6  * conditions are met:
7  *
8  *   1. Redistributions of source code must retain the above
9  *      copyright notice, this list of conditions and the following
10  *      disclaimer.
11  *
12  *   2. Redistributions in binary form must reproduce the above
13  *      copyright notice, this list of conditions and the following
14  *      disclaimer in the documentation and/or other materials
15  *      provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  *
30  * The views and conclusions contained in the software and
31  * documentation are those of the authors and should not be
32  * interpreted as representing official policies, either expressed
33  * or implied, of GRNET S.A.
34  */
35
36 package gr.grnet.aquarium
37 package user
38
39 import logic.accounting.dsl.{DSLResource, DSLAgreement}
40 import collection.mutable
41 import logic.events.WalletEntry
42
43
44 /**
45  * Snapshot of data that are user-related.
46  *
47  * @author Christos KK Loverdos <loverdos@gmail.com>
48  */
49
50 sealed trait UserDataSnapshot[T] extends DataSnapshot[T]
51
52 case class CreditSnapshot(data: Double, snapshotTime: Long) extends UserDataSnapshot[Double]
53
54 case class AgreementSnapshot(data: DSLAgreement, snapshotTime: Long) extends UserDataSnapshot[DSLAgreement]
55
56 case class RolesSnapshot(data: List[String], snapshotTime: Long) extends UserDataSnapshot[List[String]]
57
58 case class PaymentOrdersSnapshot(data: List[AnyRef], snapshotTime: Long) extends UserDataSnapshot[List[AnyRef]]
59
60 case class OwnedGroupsSnapshot(data: List[String], snapshotTime: Long) extends UserDataSnapshot[List[String]]
61
62 case class GroupMembershipsSnapshot(data: List[String], snapshotTime: Long) extends UserDataSnapshot[List[String]]
63
64 /**
65  * Maintains the current state of resources owned by the user. In order to have a
66  * uniform representation of the resource state for all resource types
67  * (complex or simple) the following convention applies:
68  *
69  *  * If the resource is complex, then `data.get(AResource)` returns a Map of
70  *  `("instance-id" -> current_resource_value)`, as expected.
71  *  * If the resource is simple, then `data.get(AResource)` returns
72  *   `("1" -> current_resource_value)`. This means that simple resources are
73  *   always stored with key 1 as `instance-id`.
74  */
75 case class OwnedResourcesSnapshot(data: Map[DSLResource, Map[String, Float]], snapshotTime: Long)
76   extends UserDataSnapshot[Map[DSLResource, Map[String, Float]]]
77
78 /**
79  * Bandwidth is counted in MB (?)
80  *
81  * @author Christos KK Loverdos <loverdos@gmail.com>
82  */
83 case class BandwidthUpSnapshot(data: Double, snapshotTime: Long) extends UserDataSnapshot[Double]
84
85 /**
86  * Bandwidth is counted in MB (?)
87  *
88  * @author Christos KK Loverdos <loverdos@gmail.com>
89  */
90 case class BandwidthDownSnapshot(data: Double, snapshotTime: Long) extends UserDataSnapshot[Double]
91
92 /**
93  * Time is counted in seconds (?)
94  *
95  * @author Christos KK Loverdos <loverdos@gmail.com>
96  */
97 case class VMTimeSnapshot(data: Double, snapshotTime: Long) extends UserDataSnapshot[Double]
98
99
100 /**
101  * Disk space is counted in MB (?)
102  *
103  * @author Christos KK Loverdos <loverdos@gmail.com>
104  */
105 case class DiskSpaceSnapshot(data: Double, snapshotTime: Long) extends UserDataSnapshot[Double]
106
107 /**
108  * A generic exception thrown when errors occur in dealing with user data snapshots
109  *
110  * @author Georgios Gousios <gousiosg@gmail.com>
111  */
112 class UserDataSnapshotException(msg: String) extends Exception(msg)