lorj 0.2.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +46 -0
  4. data/Gemfile +15 -15
  5. data/README.md +22 -17
  6. data/Rakefile +12 -2
  7. data/bin/cloud_test.rb +13 -65
  8. data/example/students_1/process/students.rb +39 -0
  9. data/example/students_1/students.rb +22 -5
  10. data/example/students_2/process/students.rb +48 -0
  11. data/example/students_2/students.rb +39 -16
  12. data/example/students_3/controller/yaml_students.rb +50 -43
  13. data/example/students_3/controller/yaml_students_controller.rb +100 -87
  14. data/example/students_3/process/students.rb +161 -97
  15. data/example/students_3/students.rb +85 -56
  16. data/example/yaml_students/students.rb +40 -40
  17. data/example/yaml_students/yaml_students.rb +103 -90
  18. data/lib/core/core.rb +356 -696
  19. data/lib/core/core_controller.rb +227 -0
  20. data/lib/core/core_internal.rb +339 -0
  21. data/lib/core/core_model.rb +328 -0
  22. data/lib/core/core_object_data.rb +330 -0
  23. data/lib/core/core_object_params.rb +230 -0
  24. data/lib/core/core_process.rb +391 -0
  25. data/lib/core/core_process_setup.rb +353 -0
  26. data/lib/core/core_setup_ask.rb +241 -0
  27. data/lib/core/core_setup_encrypt.rb +146 -0
  28. data/lib/core/core_setup_init.rb +229 -0
  29. data/lib/core/core_setup_list.rb +160 -0
  30. data/lib/core/definition.rb +647 -469
  31. data/lib/core/definition_internal.rb +264 -308
  32. data/lib/core/lorj_basecontroller.rb +95 -0
  33. data/lib/core/lorj_basedefinition.rb +307 -0
  34. data/lib/core/lorj_baseprocess.rb +265 -0
  35. data/lib/core/lorj_data.rb +583 -0
  36. data/lib/core/lorj_keypath.rb +119 -0
  37. data/lib/core_process/cloud/process/common.rb +63 -0
  38. data/lib/core_process/cloud/process/connection.rb +93 -0
  39. data/lib/core_process/cloud/process/external_network.rb +94 -0
  40. data/lib/core_process/cloud/process/flavor.rb +99 -0
  41. data/lib/core_process/cloud/process/images.rb +87 -0
  42. data/lib/core_process/cloud/process/internet_network.rb +34 -0
  43. data/lib/core_process/cloud/process/internet_server.rb +30 -0
  44. data/lib/core_process/cloud/process/keypairs.rb +276 -0
  45. data/lib/core_process/cloud/process/network.rb +108 -0
  46. data/lib/core_process/cloud/process/public_ip.rb +100 -0
  47. data/lib/core_process/cloud/process/router.rb +260 -0
  48. data/lib/core_process/cloud/process/rules.rb +120 -0
  49. data/lib/core_process/cloud/process/security_groups.rb +121 -0
  50. data/lib/core_process/cloud/process/server.rb +127 -0
  51. data/lib/core_process/cloud/process/server_log.rb +35 -0
  52. data/lib/core_process/cloud/process/subnetwork.rb +108 -0
  53. data/lib/core_process/cloud_process.rb +30 -0
  54. data/lib/logging.rb +298 -0
  55. data/lib/lorj/version.rb +18 -1
  56. data/lib/lorj.rb +58 -18
  57. data/lib/lorj_account.rb +556 -0
  58. data/lib/lorj_config.rb +468 -0
  59. data/lib/lorj_defaults.rb +278 -0
  60. data/lib/prc.rb +136 -104
  61. data/lib/prc_base_config.rb +285 -0
  62. data/lib/prc_core_config.rb +878 -0
  63. data/lib/prc_section_config.rb +57 -0
  64. data/lib/providers/hpcloud/compute.rb +81 -93
  65. data/lib/providers/hpcloud/hpcloud.rb +462 -0
  66. data/lib/providers/hpcloud/network.rb +96 -98
  67. data/lib/providers/hpcloud/security_groups.rb +41 -40
  68. data/lib/providers/mock/mock.rb +144 -0
  69. data/lib/providers/openstack/openstack.rb +45 -0
  70. data/lib/providers/templates/compute.rb +21 -23
  71. data/lib/providers/templates/mycloud.rb +72 -0
  72. data/lib/providers/templates/network.rb +11 -12
  73. data/lib/rh.rb +339 -0
  74. data/lorj-spec/defaults.yaml +4 -0
  75. data/lorj.gemspec +6 -0
  76. data/spec/00_lorj_log_spec.rb +53 -0
  77. data/spec/01_hash_rh_spec.rb +243 -0
  78. data/spec/02_prc_base_config_spec.rb +216 -0
  79. data/spec/04_prc_core_config_spec.rb +83 -0
  80. data/spec/11_lorj_config_spec.rb +263 -0
  81. data/spec/12_lorj_account_spec.rb +181 -0
  82. metadata +76 -28
  83. data/Gemfile.lock +0 -37
  84. data/example/students_1/process/Students.rb +0 -20
  85. data/example/students_2/process/Students.rb +0 -27
  86. data/example/students_4/controller/yaml_students.rb +0 -82
  87. data/example/students_4/controller/yaml_students_controller.rb +0 -141
  88. data/example/students_4/process/students.rb +0 -112
  89. data/example/students_4/students.rb +0 -103
  90. data/lib/core/lorj-basecontroller.rb +0 -90
  91. data/lib/core/lorj-basedefinition.rb +0 -1139
  92. data/lib/core/lorj-baseprocess.rb +0 -236
  93. data/lib/core/lorj-data.rb +0 -567
  94. data/lib/core/lorj-keypath.rb +0 -115
  95. data/lib/core_process/CloudProcess.rb +0 -337
  96. data/lib/core_process/global_process.rb +0 -502
  97. data/lib/core_process/network_process.rb +0 -605
  98. data/lib/prc-account.rb +0 -339
  99. data/lib/prc-config.rb +0 -1030
  100. data/lib/prc-logging.rb +0 -261
  101. data/lib/providers/hpcloud/Hpcloud.rb +0 -426
  102. data/lib/providers/mock/Mock.rb +0 -141
  103. data/lib/providers/openstack/Openstack.rb +0 -47
  104. data/lib/providers/templates/core.rb +0 -61
  105. data/spec/forj-account_spec.rb +0 -75
  106. data/spec/forj-config_spec.rb +0 -196
@@ -16,323 +16,279 @@
16
16
  # limitations under the License.
17
17
 
18
18
  module Lorj
19
- class BaseDefinition
20
-
21
- private
22
- # ------------------------------------------------------
23
- # Class Definition internal function.
24
- # ------------------------------------------------------
25
-
26
- def _ask_encrypted(sDesc, sDefault)
27
- # Checking key file used to encrypt/decrypt passwords
28
- key_file = File.join($FORJ_CREDS_PATH, '.key')
29
- if not File.exists?(key_file)
30
- # Need to create a random key.
31
- entr = {
32
- :key => rand(36**10).to_s(36),
33
- :salt => Time.now.to_i.to_s,
34
- :iv => Base64::strict_encode64(OpenSSL::Cipher::Cipher.new('aes-256-cbc').random_iv)
35
- }
36
-
37
- Lorj.debug(2, "Writing '%s' key file" % key_file)
38
- File.open(key_file, 'w') do |out|
39
- out.write(Base64::encode64(entr.to_yaml))
40
- end
41
- else
42
- Lorj.debug(2, "Loading '%s' key file" % key_file)
43
- encoded_key = IO.read(key_file)
44
- entr = YAML.load(Base64::decode64(encoded_key))
45
- end
46
-
47
- enc_value = sDefault
48
-
49
- if not enc_value.nil?
50
- begin
51
- value_hidden = '*' * Encryptor.decrypt(
52
- :value => Base64::strict_decode64(enc_value),
53
- :key => entr[:key],
54
- :iv => Base64::strict_decode64(entr[:iv]),
55
- :salt => entr[:salt]
56
- ).length
57
- rescue => e
58
- Lorj.error("Unable to decrypt your %s. You will need to re-enter it." % sDesc)
59
- enc_value = ""
60
- else
61
- value_hidden="[%s]" % value_hidden
62
- PrcLib.message("%s is already set. If you want to keep it, just press Enter" % [sDesc])
63
- end
64
- else
65
- value_hidden = ""
66
- end
67
-
68
- value_free = ""
69
- while value_free == ""
70
- # ask for encrypted data.
71
- value_free = ask("Enter %s: [%s]" % [sDesc, value_hidden]) do |q|
72
- q.echo = '*'
73
- end
74
- if value_free == "" and enc_value
75
- value_free = Encryptor.decrypt(
76
- :value => Base64::strict_decode64(enc_value),
77
- :key => entr[:key],
78
- :iv => Base64::strict_decode64(entr[:iv]),
79
- :salt => entr[:salt]
80
- )
81
- else
82
- PrcLib.message("%s cannot be empty." % sDesc) if value_free == ""
83
- end
84
- end
85
- enc_value = Base64::strict_encode64(
86
- Encryptor.encrypt(
87
- :value => value_free,
88
- :key => entr[:key],
89
- :iv => Base64::strict_decode64(entr[:iv]),
90
- :salt => entr[:salt]
91
- )
92
- )
19
+ # Class Definition internal function.
20
+ class BaseDefinition
21
+ private
22
+
23
+ # return Object data meta data.
24
+ def _get_meta_data(key)
25
+ meta_default = Lorj.defaults.get_meta(key)
26
+ return nil if meta_default.nil?
27
+ meta_default = meta_default.clone
28
+
29
+ section = Lorj.defaults.get_meta_section(key)
30
+ return meta_default if section.nil?
31
+ meta = PrcLib.model.meta_data.rh_get(section, key)
32
+ return meta_default if meta.nil?
33
+
34
+ meta_default.merge!(meta)
35
+ end
36
+
37
+ # internal runtime function for process call
38
+ # Get the controller result and map controller object data to
39
+ # lorj object attributes, using controller mapping function.
40
+ #
41
+ # *parameters*:
42
+ # - +object_type+ : object_type to map
43
+ # - +oControlerObject+ : Controller object
44
+ #
45
+ # *return*:
46
+ # - value : Hash. return the parameter value.
47
+ #
48
+ # *raise*:
49
+ #
50
+ def _return_map(object_type, oControlerObject)
51
+ return nil if oControlerObject.nil?
52
+
53
+ attr_value = {}
54
+
55
+ map_handler = _map_identify_mapping_handler(object_type)
56
+ return nil if map_handler.nil?
57
+
58
+ object_opts = PrcLib.model.meta_obj.rh_get(object_type)
59
+
60
+ maps = object_opts[:returns]
61
+ maps.each do |key, map|
62
+ next unless map
63
+
64
+ key_obj = KeyPath.new(key)
65
+ map_obj = KeyPath.new(map)
66
+
67
+ value = _call_controller_map(map_handler, oControlerObject,
68
+ map_obj.tree)
69
+ value = _mapping_data(object_type, key_obj, object_opts, value)
70
+ attr_value.rh_set(value, key_path.tree)
93
71
  end
94
-
95
- def _ask(sDesc, sDefault, rValidate, bEncrypted, bRequired)
96
- if bEncrypted
97
- value = _ask_encrypted(sDesc, sDefault)
98
- if bRequired and value == ""
99
- say "%sThis information is required!%s" % [ANSI.bold, ANSI.clear]
100
- while value == ""
101
- value = _ask_encrypted(sDesc, sDefault)
102
- end
103
- end
104
- else
105
- value = ask('Enter %s:' % [sDesc]) do |q|
106
- q.default = sDefault unless sDefault.nil?
107
- q.validate = rValidate unless rValidate.nil?
108
- end
109
- if bRequired and value == ""
110
- say "%sThis information is required!%s" % [ANSI.bold, ANSI.clear]
111
- while value == ""
112
- value = ask('Enter %s:[%s]' % [sDesc, sDefault]) do |q|
113
- q.default = sDefault unless sDefault.nil?
114
- q.validate = rValidate unless rValidate.nil?
115
- end
116
- end
117
- end
118
- end
119
- value.to_s
120
- end
121
-
122
- # return Object data meta data.
123
- def _get_meta_data(sKey)
124
-
125
- hMetaDefault = Lorj::Default.get_meta(sKey)
126
- return nil if hMetaDefault.nil?
127
- hMetaDefault = hMetaDefault.clone
128
-
129
- sSection = Lorj::Default.get_meta_section(sKey)
130
- return hMetaDefault if sSection.nil?
131
- hMeta = Lorj::rhGet(@@meta_data, sSection, sKey)
132
- return hMetaDefault if hMeta.nil?
133
-
134
- hMetaDefault.merge!(hMeta)
135
- end
136
-
137
- def _return_map(sCloudObj, oControlerObject)
138
- return nil if oControlerObject.nil?
139
-
140
- attr_value = {}
141
-
142
- pProc = Lorj::rhGet(@@meta_obj, sCloudObj, :lambdas, :get_attr_e)
143
- bController = Lorj::rhGet(@@meta_obj, sCloudObj, :options, :controller)
144
- return nil if not pProc and not bController
145
-
146
- hMap = Lorj::rhGet(@@meta_obj, sCloudObj, :returns)
147
- hMap.each { |key, map|
148
- oKeyPath = KeyPath.new(key)
149
- oMapPath = KeyPath.new(map)
150
- next if not map
151
- if pProc
152
- Lorj::debug(4, "Calling process function '%s' to retrieve/map Controller object '%s' data " % [pProc, sCloudObj])
153
- controller_attr_value = @oForjProcess.method(pProc).call(sCloudObj, oControlerObject)
154
- else
155
- Lorj::debug(4, "Calling controller function 'get_attr' to retrieve/map Controller object '%s' data " % [sCloudObj])
156
- controller_attr_value = @oProvider.get_attr(oControlerObject, oMapPath.aTree) if bController
157
- end
158
-
159
- hValueMapping = Lorj::rhGet(@@meta_obj, sCloudObj, :value_mapping, oKeyPath.sFullPath)
160
- if hValueMapping and not controller_attr_value.nil?
161
- hValueMapping.each { | map_key, map_value |
162
- if controller_attr_value == map_value
163
- Lorj::rhSet(attr_value, map_key ,oKeyPath.aTree)
164
- Lorj::debug(5, "Object '%s' value mapped '%s': '%s' => '%s'" % [sCloudObj, oKeyPath.aTree, controller_attr_value, map_value])
165
- break
166
- end
167
- }
168
- raise Lorj::PrcError.new(), "'%s.%s': No controller value mapping for '%s'." % [sCloudObj, oKeyPath.sKey, controller_attr_value] if attr_value.nil?
169
- else
170
- Lorj::debug(5, "Object '%s' value '%s' extracted: '%s'" % [sCloudObj, oKeyPath.aTree, controller_attr_value])
171
- Lorj::rhSet(attr_value, controller_attr_value ,oKeyPath.aTree)
172
- end
173
- }
174
- attr_value
72
+ attr_value
73
+ end
74
+
75
+ # internal runtime function for process call
76
+ # Get the object controller mapping method and method origin.
77
+ #
78
+ # If the object is fully managed by the process, ie no controller
79
+ # object is attached to it, the process will own the mapping method.
80
+ #
81
+ # *parameters*:
82
+ # - +object_type+ : object_type to map
83
+ #
84
+ # *return*:
85
+ # - map_method : return the parameter value.
86
+ # - method_name : Name of the map method.
87
+ # - is_controller : true if the map method is owned by the controller
88
+ # false if the map method is owned by the process.
89
+ # - class owner : Class owner of the map method.
90
+ #
91
+ # *raise*:
92
+ #
93
+ def _map_identify_mapping_handler(object_type)
94
+ proc_name = PrcLib.model.meta_obj.rh_get(object_type,
95
+ :lambdas, :get_attr_e)
96
+
97
+ is_controller = PrcLib.model.meta_obj.rh_get(object_type,
98
+ :options, :controller)
99
+
100
+ return nil if !proc_name && !is_controller
101
+
102
+ if proc_name
103
+ map_handler = [@process.method(proc_name), proc_name, false]
104
+ map_handler << @process.class
105
+ return map_handler
175
106
  end
176
107
 
177
- def _build_data(sCloudObj, oParam, oKeyPath, hParams, bController = false)
178
-
179
- sKey = oKeyPath.sKey
180
- sDefault = Lorj::rhGet(hParams, :default_value)
181
- if Lorj::rhExist?(hParams, :extract_from) == 1
182
- value = oParam[hParams[:extract_from]]
183
- end
184
- value = @oForjConfig.get(sKey, sDefault) if not value
185
-
186
- if bController
187
- hValueMapping = Lorj::rhGet(@@meta_obj, sCloudObj, :value_mapping, oKeyPath.sFullPath)
188
-
189
- # Mapping from Object/data definition
190
- if hValueMapping
191
- raise Lorj::PrcError.new(), "'%s.%s': No value mapping for '%s'" % [sCloudObj, sKey, value] if Lorj::rhExist?(hValueMapping, value) != 1
192
- value = hValueMapping[value]
193
- # Will be moved to the setup section or while setting it for a controller attached account.
194
- #~ else
195
- #~ # Or mapping from Config/data definition
196
- #~ section = Lorj::Default.get_meta_section(sKey)
197
- #~ section = :runtime if section.nil?
198
- #~ hValueMapping = Lorj::rhGet(@@meta_data, section, sKey, :value_mapping)
199
- #~ if hValueMapping
200
- #~ raise PrcError.new(), "'%s.%s': No Config value mapping for '%s'" % [section, sKey, value] if Lorj::rhExist?(hValueMapping, value) != 1
201
- #~ value = hValueMapping[value]
202
- #~ end
203
- end
204
- if Lorj::rhExist?(hParams, :mapping) == 1
205
- # NOTE: if mapping is set, the definition subtree
206
- # is ignored.
207
- # if key map to mykey
208
- # [:section1][subsect][key] = value
209
- # oParam => [:hdata][mykey] = value
210
- # not oParam => [:hdata][:section1][subsect][mykey] = value
211
- Lorj::rhSet(oParam[:hdata], value, Lorj::rhGet(hParams, :mapping))
212
- end
213
- end
214
- oParam[oKeyPath.aTree] = value
108
+ [@controller.method(:get_attr), :get_attr, true, @controller.class]
109
+ end
110
+
111
+ # internal runtime function for process call
112
+ # Call the mapping method to get the controller attribute data.
113
+ #
114
+ #
115
+ # *parameters*:
116
+ # - +map_handler+ : map array returned by _map_identify_mapping_handler
117
+ # - +controller_obj+ : Controller object
118
+ # - +attr_tree+ : Array of attribute tree to get the controller data.
119
+ #
120
+ # *return*:
121
+ # - controller data.
122
+ #
123
+ # *raise*:
124
+ #
125
+ def _call_controller_map(map_handler, oControlerObject, attr_tree)
126
+ if map_handler[2]
127
+ type = 'controller'
128
+ else
129
+ type = 'process'
215
130
  end
216
-
217
- def _get_object_params(sCloudObj, sEventType, fname, bController = false)
218
-
219
- oParams = ObjectData.new(not(bController)) # hdata is built for controller. ie, ObjectData is NOT internal.
220
-
221
- hTopParams= Lorj::rhGet(@@meta_obj,sCloudObj, :params)
222
- hkeyPaths = Lorj::rhGet(hTopParams, :keys)
223
- raise Lorj::PrcError.new(), "'%s' Object data needs not set. Forgot obj_needs?" % [sCloudObj] if hkeyPaths.nil?
224
-
225
- if sEventType == :delete_e
226
- if @ObjectData.exist?(sCloudObj)
227
- oParams.add(@ObjectData[sCloudObj, :ObjectData])
228
- end
229
- end
230
-
231
- hkeyPaths.each { | sKeypath, hParams|
232
- next if not hParams[:for].include?(sEventType)
233
- oKeyPath = KeyPath.new(sKeypath)
234
- sKey = oKeyPath.sKey
235
- case hParams[:type]
236
- when :data
237
- _build_data(sCloudObj, oParams, oKeyPath, hParams, bController)
238
- when :CloudObject
239
- #~ if hParams[:required] and Lorj::rhExist?(@CloudData, sKey, :object) != 2
240
- if hParams[:required] and @ObjectData.type?(sKey) != :DataObject
241
- raise Lorj::PrcError.new(), "Object '%s/%s' is not defined. '%s' requirement failed." % [ self.class, sKey, fname]
242
- end
243
- if @ObjectData.exist?(sKey)
244
- oParams.add(@ObjectData[sKey, :ObjectData])
245
- else
246
- Lorj::debug(2, "The optional '%s' was not loaded" % sKey)
247
- end
248
- else
249
- raise Lorj::PrcError.new(), "Undefined ObjectData '%s'." % [ hParams[:type]]
250
- end
251
- }
252
- oParams
131
+ Lorj.debug(4, "Calling '%s.%s' to retrieve/map %s object '%s' data ",
132
+ map_handler[3], map_handler[1], type, attr_tree)
133
+
134
+ map_handler[0].call(oControlerObject, attr_tree)
135
+ end
136
+
137
+ # internal runtime function for process call
138
+ # Do the mapping of the value as defined by obj_needs options:
139
+ # :value_mapping => (Array of attribute tree)
140
+ #
141
+ # *parameters*:
142
+ # - +object_type+ : Object type to get data mapped.
143
+ # - +key_obj+ : Attribute to map
144
+ # - +object_opts+ : Attribute options.
145
+ # - +value+ : Controller value to map.
146
+ #
147
+ # *return*:
148
+ # - controller data.
149
+ #
150
+ # *raise*:
151
+ #
152
+ def _mapping_data(object_type, key_obj, object_opts, value)
153
+ value_mapping = object_opts.rh_get(:value_mapping, key_obj.fpath)
154
+ if value_mapping && !value.nil?
155
+ value_mapping.each do | map_key, map_value |
156
+ next unless value == map_value
157
+ Lorj.debug(5, "Object '%s' value mapped '%s': '%s' => '%s'",
158
+ object_type, key_obj.tree,
159
+ value, map_value)
160
+ return map_key
161
+ end
162
+ runtime_fail("'%s.%s': No controller value mapping for '%s'.",
163
+ object_type, key_obj.tree, value)
253
164
  end
254
165
 
255
- def _get_controller_map_value(keypath, sProcessValue)
256
- section = Lorj::Default.get_meta_section(sData)
257
- section = :runtime if section.nil?
258
- oKeypath = KeyPath.new(keypath)
259
- sKeyPath = oKeypath.sKeyPath
260
- return nil if Lorj::rhExist?(@@meta_data, section, sKeyPath, :controller, sProcessValue) != 4
261
- Lorj::rhGet(@@meta_data, section, sKeyPath, :controller, sProcessValue)
166
+ Lorj.debug(5, "Object '%s' value '%s' extracted: '%s'",
167
+ object_type, key_obj.tree, value)
168
+ value
169
+ end
170
+
171
+ # internal runtime function for process call
172
+ # Check object needs list, to report missing required data.
173
+ # raise a runtime error if at least, one data is not set.
174
+ # It returns a list "missing objects".
175
+ #
176
+ # *parameters*:
177
+ # - +object_missing+ : Array of missing object for process caller.
178
+ # - +attr_name+ : attribute/data name
179
+ # - +attr_options+ : attribute options
180
+ # - +fname+ : caller function
181
+ #
182
+ # *return*:
183
+ # - Array : missing objects.
184
+ #
185
+ # *raise*:
186
+ # - runtime error if required data is not set. (empty or nil)
187
+ #
188
+ def _check_required(object_type, sEventType, fname)
189
+ object_missing = []
190
+
191
+ attr_paths = PrcLib.model.meta_obj.rh_get(object_type,
192
+ :params, :keys)
193
+ PrcLib.runtime_fail("'%s' Object data needs not set. Forgot "\
194
+ 'obj_needs?', object_type) if attr_paths.nil?
195
+
196
+ if sEventType == :delete_e &&
197
+ @object_data.type?(object_type) != :DataObject
198
+ object_missing << object_type
262
199
  end
263
200
 
264
- def _get_process_map_value(keypath, sControllerValue)
265
- section = Lorj::Default.get_meta_section(sData)
266
- section = :runtime if section.nil?
267
- oKeypath = KeyPath.new(keypath)
268
- sKeyPath = oKeypath.sKeyPath
269
- return nil if Lorj::rhExist?(@@meta_data, section, sKeyPath, :process, sControllerValue) != 4
270
- Lorj::rhGet(@@meta_data, section, sKeyPath, :process, sControllerValue)
201
+ attr_paths.each do | _attr_path, attr_options|
202
+ next if attr_options[:for] && !attr_options[:for].include?(sEventType)
203
+ _check_required_attr(object_missing, attr_name, attr_options, fname)
271
204
  end
272
-
273
- def _check_required(sCloudObj, sEventType, fname)
274
- aCaller = caller
275
- aCaller.pop
276
-
277
- oObjMissing=[]
278
-
279
- hTopParams= Lorj::rhGet(@@meta_obj,sCloudObj, :params)
280
- hkeyPaths = Lorj::rhGet(hTopParams, :keys)
281
- raise Lorj::PrcError.new(), "'%s' Object data needs not set. Forgot obj_needs?" % [sCloudObj] if hkeyPaths.nil?
282
-
283
- if sEventType == :delete_e
284
- if @ObjectData.type?(sCloudObj) != :DataObject
285
- oObjMissing << sCloudObj
286
- end
287
- end
288
-
289
- hkeyPaths.each { | sKeypath, hParams|
290
- next if not hParams[:for].include?(sEventType)
291
- oKeyPath = KeyPath.new(sKeypath)
292
-
293
- sKey = oKeyPath.sKey
294
- case hParams[:type]
295
- when :data
296
- sDefault = Lorj::rhGet(hParams, :default_value)
297
- if hParams[:required]
298
- if hParams.key?(:extract_from)
299
- if not @ObjectData.exist?(hParams[:extract_from])
300
- raise Lorj::PrcError.new(), "key '%s' was not extracted from '%s'. '%s' requirement failed." % [ sKey, hParams[:extract_from], fname], aCaller
301
- end
302
- elsif @oForjConfig.get(sKey, sDefault).nil?
303
- sSection = Lorj::Default.get_meta_section(sKey)
304
- sSection = 'runtime' if not sSection
305
- raise Lorj::PrcError.new(), "key '%s/%s' is not set. '%s' requirement failed." % [ sSection, sKey, fname], aCaller
306
- end
307
- end
308
- when :CloudObject
309
- #~ if hParams[:required] and Lorj::rhExist?(@CloudData, sKey, :object) != 2
310
- if hParams[:required] and @ObjectData.type?(sKey) != :DataObject
311
- oObjMissing << sKey
312
- end
313
- end
314
- }
315
- return oObjMissing
205
+ object_missing
206
+ end
207
+
208
+ # internal runtime function
209
+ # Check while the attribute data or object is required, if it is set.
210
+ # raise a runtime error if data is not set.
211
+ # add object in the missing object Array if object is not set.
212
+ #
213
+ # *parameters*:
214
+ # - +object_missing+ : Array of missing object for process caller.
215
+ # - +attr_name+ : attribute/data name
216
+ # - +attr_options+ : attribute options
217
+ # - +fname+ : caller function
218
+ #
219
+ # *return*:
220
+ #
221
+ # *raise*:
222
+ # - runtime error if required data is not set. (empty or nil)
223
+ #
224
+ def _check_required_attr(object_missing, attr_name, attr_options, fname)
225
+ attr_obj = KeyPath.new(attr_path)
226
+
227
+ attr_name = attr_obj.key
228
+ case attr_options[:type]
229
+ when :data
230
+ _check_required_attr_data(attr_name, attr_options, fname)
231
+ when :CloudObject
232
+ if attr_options[:required] &&
233
+ @object_data.type?(attr_name) != :DataObject
234
+ object_missing << attr_name
235
+ end
316
236
  end
317
-
318
- def _identify_data(sCloudObj, sEventType, sObjectType = :data)
319
- aCaller = caller
320
- aCaller.pop
321
-
322
- aData = []
323
-
324
- hTopParams= Lorj::rhGet(@@meta_obj,sCloudObj, :params)
325
- hkeyPaths = Lorj::rhGet(hTopParams, :keys)
326
- raise Lorj::PrcError.new(), "'%s' Object data needs not set. Forgot obj_needs?" % [sCloudObj] if hkeyPaths.nil?
327
-
328
- hkeyPaths.each { | sKeypath, hParams|
329
- next if not hParams[:for].include?(sEventType)
330
- oKeyPath = KeyPath.new(sKeypath)
331
-
332
- aData << oKeyPath.aTree if hParams[:type] == sObjectType
333
- }
334
- return aData
237
+ end
238
+
239
+ # internal runtime function
240
+ # Check while the attribute data is required, if data is not set
241
+ # raise a runtime error if not.
242
+ #
243
+ # *parameters*:
244
+ # - +attr_name+ : attribute/data name
245
+ # - +attr_options+ : attribute options
246
+ # - +fname+ : caller function
247
+ #
248
+ # *return*:
249
+ #
250
+ # *raise*:
251
+ # - runtime error if required data is not set. (empty or nil)
252
+ #
253
+ def _check_required_attr_data(attr_name, attr_options, fname)
254
+ default = attr_options.rh_get(:default_value)
255
+
256
+ return unless attr_options[:required]
257
+
258
+ if attr_options.key?(:extract_from)
259
+ unless @object_data.exist?(attr_options[:extract_from])
260
+ PrcLib.runtime_fail("key '%s' was not extracted from '%s'"\
261
+ ". '%s' requirement failed.",
262
+ attr_name, attr_options[:extract_from], fname)
263
+ end
264
+ elsif @config.get(attr_name, default).nil?
265
+ section = Lorj.defaults.get_meta_section(attr_name)
266
+ section = 'runtime' unless section
267
+ PrcLib.runtime_fail("key '%s/%s' is not set. '%s' requirement"\
268
+ ' failed.', section, attr_name, fname)
335
269
  end
336
-
337
- end
270
+ end
271
+
272
+ # Obsolete function
273
+ #
274
+ # *parameters*:
275
+ # -
276
+
277
+ # def _identify_data(object_type, sEventType, data_type = :data)
278
+ # data_array = []
279
+ #
280
+ # key_paths = PrcLib.model.meta_obj.rh_get(object_type,
281
+ # :params, :keys)
282
+ # runtime_fail("'%s' Object data needs not set. Forgot obj_needs?",
283
+ # object_type) if key_paths.nil?
284
+ #
285
+ # key_paths.each do | sKeypath, hParams|
286
+ # next if hParams[:for] && !hParams[:for].include?(sEventType)
287
+ # key_path = KeyPath.new(sKeypath)
288
+ #
289
+ # data_array << key_path.tree if hParams[:type] == data_type
290
+ # end
291
+ # data_array
292
+ # end
293
+ end
338
294
  end