Class: SISFC::Configuration

Inherits:
Object
  • Object
show all
Includes:
Configurable, Logging
Defined in:
lib/sisfc/configuration.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

included, logger, #logger

Constructor Details

#initialize(filename) ⇒ Configuration

Returns a new instance of Configuration.



70
71
72
# File 'lib/sisfc/configuration.rb', line 70

def initialize(filename)
  @filename = filename
end

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



68
69
70
# File 'lib/sisfc/configuration.rb', line 68

def filename
  @filename
end

Class Method Details

.load_from_file(filename) ⇒ Object

Raises:

  • (ArgumentError)


109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/sisfc/configuration.rb', line 109

def self.load_from_file(filename)
  # allow filename, string, and IO objects as input
  raise ArgumentError, "File #{filename} does not exist!" unless File.exists?(filename)

  # create configuration object
  conf = Configuration.new(filename)

  # take the file content and pass it to instance_eval
  conf.instance_eval(File.new(filename, 'r').read)

  # validate and finalize configuration
  conf.validate

  # return new object
  conf
end

Instance Method Details

#end_timeObject



74
75
76
# File 'lib/sisfc/configuration.rb', line 74

def end_time
  @start_time + @duration
end

#validateObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/sisfc/configuration.rb', line 78

def validate
  # convert datetimes and integers into floats
  @start_time      = @start_time.to_f
  @duration        = @duration.to_f
  @warmup_duration = @warmup_duration.to_f

  # initialize kpi_customization to empty hash if needed
  @kpi_customization ||= {}

  # TODO: might want to restrict this substitution only to the :filename
  # and :command keys
  @request_generation.each do |k,v|
    v = v.gsub('<pwd>', File.expand_path(File.dirname(@filename)))
  end

  # freeze everything!
  IceNine.deep_freeze(@constraints)
  IceNine.deep_freeze(@customers)
  IceNine.deep_freeze(@custom_stats)
  IceNine.deep_freeze(@data_centers)
  IceNine.deep_freeze(@duration)
  IceNine.deep_freeze(@evaluation)
  IceNine.deep_freeze(@kpi_customization)
  IceNine.deep_freeze(@latency_models)
  IceNine.deep_freeze(@request_generation)
  IceNine.deep_freeze(@service_component_types)
  IceNine.deep_freeze(@start_time)
  IceNine.deep_freeze(@warmup_duration)
  IceNine.deep_freeze(@workflow_types)
end