Revision e5a4dd4f

b/src/main/resources/policy.yaml
4 4
      name: bndup
5 5
      unit: MB
6 6
      complex: false
7
      costpolicy: diff
7
      costpolicy: continuous
8 8
    - resource:
9 9
      name: bnddown
10 10
      unit: MB
11 11
      complex: false
12
      costpolicy: diff
12
      costpolicy: continuous
13 13
    - resource:
14 14
      name: vmtime
15 15
      unit: Hour
......
20 20
      name: dsksp
21 21
      unit: MB
22 22
      complex: false
23
      costpolicy: diff
23
      costpolicy: continuous
24 24

  
25 25
  algorithms:
26 26
    - algorithm:
b/src/main/scala/gr/grnet/aquarium/logic/accounting/dsl/DSL.scala
52 52
  val emptyTimeFrame = DSLTimeFrame(new Date(0), None, List())
53 53

  
54 54
  /**An empty resource*/
55
  val emptyResource = DSLSimpleResource("", "", "")
55
  val emptyResource = DSLSimpleResource("", "", OnOffCostPolicy)
56 56

  
57 57
  /**An empty algorithm */
58 58
  val emptyAlgorithm = DSLAlgorithm("", None, Map(), emptyTimeFrame)
......
123 123
    }
124 124

  
125 125
    val costpolicy = resource / Vocabulary.costpolicy match {
126
      case x: YAMLStringNode => x.string
126
      case x: YAMLStringNode => DSLCostPolicy(x.string)
127 127
      case _ => throw new DSLParseException("Resource %s does specify a cost policy".format(name))
128 128
    }
129 129

  
b/src/main/scala/gr/grnet/aquarium/logic/accounting/dsl/DSLCostPolicy.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.logic.accounting.dsl
37

  
38
/**
39
 * A cost policy indicates how charging for a resource will be done
40
 * wrt the various states a resource can be.
41
 *
42
 * @author Georgios Gousios <gousiosg@gmail.com>
43
 */
44
abstract class DSLCostPolicy(name: String)
45

  
46

  
47
object DSLCostPolicy {
48
  def apply(name: String): DSLCostPolicy  = {
49
    name match {
50
      case x if(x.equalsIgnoreCase("onoff"))  => OnOffCostPolicy
51
      case y if(y.equalsIgnoreCase("continuous"))   => ContinuousCostPolicy
52
      case z if(z.equalsIgnoreCase("discrete")) => DiscreteCostPolicy
53
      case _ => throw new DSLParseException("Invalid cost policy %s".format(name))
54
    }
55
  }
56
}
57

  
58
/**
59
 * A continuous cost policy expects a resource's usage to be
60
 * a continuous function `f(t)`, where `t` is the time since the
61
 * resource was first used.
62
 * For continuous resources, the charging algorithm calculates costs
63
 * as the integral of function `f(t)`. In practice, this means that
64
 * a resource usage will be charged for the total amount of usage
65
 * between resource usage changes.
66
 *
67
 * Example resources that might be adept to a continuous policy
68
 * are bandwidth and diskspace.
69
 */
70
object ContinuousCostPolicy extends DSLCostPolicy("continuous")
71

  
72
/**
73
 * An onoff cost policy expects a resource to be in one of the two allowed
74
 * states (`on` and `off`, respectively). It will charge for resource usage
75
 * within the timeframes specified by consecutive on and off resource events.
76
 * An onoff policy is the same as a continuous policy, except for
77
 * the timeframes within the resource is in the `off` state.
78
 *
79
 * Example resources that might be adept to onoff policies are VMs in a
80
 * cloud application and books in a book lending application.
81
 */
82
object OnOffCostPolicy extends DSLCostPolicy("onoff")
83

  
84
/**
85
 * An discrete cost policy indicates that a resource should be charged directly
86
 * at each resource state change, i.e. the charging is not dependent on
87
 * the time the resource.
88
 *
89
 * Example oneoff resources might be individual charges applied to various
90
 * actions (e.g. the fact that a user has created an account) or resources
91
 * that should be charged per volume once (e.g. the allocation of a volume)
92
 */
93
object DiscreteCostPolicy extends DSLCostPolicy("discrete")
b/src/main/scala/gr/grnet/aquarium/logic/accounting/dsl/DSLResource.scala
48 48
  val unit: String,
49 49

  
50 50
  /** Algorithm used to calculate costs */
51
  val costpolicy: String
51
  val costpolicy: DSLCostPolicy
52 52
) {
53 53
  def isComplex: Boolean
54 54
}
......
65 65
  override val unit: String,
66 66

  
67 67
  /**Algorithm used to calculate costs */
68
  override val costpolicy: String,
68
  override val costpolicy: DSLCostPolicy,
69 69

  
70 70
  /**Name of field used to describe a unique instance of the resource*/
71 71
  descriminatorField: String
......
84 84
  override val unit: String,
85 85

  
86 86
  /**Algorithm used to calculate costs */
87
  override val costpolicy: String
87
  override val costpolicy: DSLCostPolicy
88 88
) extends DSLResource(name, unit, costpolicy) {
89 89
  override def isComplex = false
90
}
90
}
91

  
b/src/test/resources/policy.yaml
4 4
      name: bandwidthup
5 5
      unit: MB
6 6
      complex: false
7
      costpolicy: diff
7
      costpolicy: continuous
8 8
    - resource:
9 9
      name: bandwidthdown
10 10
      unit: MB
11 11
      complex: false
12
      costpolicy: diff
12
      costpolicy: continuous
13 13
    - resource:
14 14
      name: vmtime
15 15
      unit: Hour
......
20 20
      name: diskspace
21 21
      unit: MB
22 22
      complex: false
23
      costpolicy: diff
23
      costpolicy: continuous
24 24

  
25 25
  implicitvars:
26 26
    - price

Also available in: Unified diff