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
@@ -0,0 +1,230 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ # (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+ module Lorj
19
+ # Class Definition internal function.
20
+ class BaseDefinition
21
+ private
22
+
23
+ # internal runtime function for process call
24
+ # Build a process/controller parameter object (ObjectData)
25
+ #
26
+ # *parameters*:
27
+ # - +new_params+ : Parameters ObjectData
28
+ # - +param_object+ : parameter object
29
+ # - +param_options+ : parameter options
30
+ # - +predefined_params+ : predefined parameters.
31
+ #
32
+ # *return*:
33
+ # - value : return the parameter value.
34
+ #
35
+ # *raise*:
36
+ #
37
+ def _build_data(new_params, param_obj, param_options, predefined_value)
38
+ param_name = param_obj.key
39
+ value = nil
40
+
41
+ default = param_options.rh_get(:default_value)
42
+
43
+ if param_options[:extract_from]
44
+ value = new_params[param_options[:extract_from]]
45
+ end
46
+
47
+ return predefined_value if predefined_value && value.nil?
48
+
49
+ value = @config.get(param_name, default) if value.nil?
50
+
51
+ new_params[param_obj.tree] = value
52
+
53
+ value
54
+ end
55
+
56
+ # internal runtime function for process call
57
+ # Build a process/controller parameter object (ObjectData)
58
+ #
59
+ # *parameters*:
60
+ # - +object_type+ : object type needing this parameter.
61
+ # - +new_params+ : Parameters ObjectData
62
+ # - +param_obj+ : parameter object
63
+ # - +param_options+ : parameter options
64
+ # - +value+ : value to add in hdata Hash.
65
+ #
66
+ # *return*:
67
+ #
68
+ # *raise*:
69
+ #
70
+ def _build_hdata(object_type, new_params, param_obj, param_options, value)
71
+ return unless param_options[:type] == :data
72
+
73
+ value_mapping = PrcLib.model.meta_obj.rh_get(object_type, :value_mapping,
74
+ param_obj.fpath)
75
+
76
+ attr_name = param_obj.key
77
+
78
+ # Mapping from Object/data definition
79
+ if value_mapping
80
+ runtime_fail("'%s.%s': No value mapping for '%s'",
81
+ object_type, attr_name,
82
+ value) if Lorj.rhExist?(value_mapping, value) != 1
83
+ value = value_mapping[value]
84
+ end
85
+
86
+ return unless param_options[:mapping]
87
+
88
+ # NOTE: if mapping is set, the definition subtree
89
+ # is ignored.
90
+ # if key map to mykey
91
+ # [:section1][subsect][key] = value
92
+ # new_params => [:hdata][mykey] = value
93
+ # not new_params => [:hdata][:section1][subsect][mykey] = value
94
+ new_params[:hdata].rh_set(value, param_options[:mapping])
95
+ nil
96
+ end
97
+
98
+ # internal runtime function for process call
99
+ # Build a process/controller parameter object (ObjectData)
100
+ #
101
+ # *parameters*:
102
+ # - +new_params+ : ObjectData. Parameters ObjectData
103
+ # - +param_path+ : Symbol. parameter name
104
+ # - +param_options+ : Hash. parameter options
105
+ # - +predefined_params+ : Hash. predefined parameters.
106
+ #
107
+ #
108
+ # *return*:
109
+ # - value : return the parameter value.
110
+ #
111
+ # *raise*:
112
+ #
113
+ def _build_param(new_params,
114
+ param_obj, param_options, predefined_value)
115
+
116
+ param_name = param_obj.key
117
+
118
+ case param_options[:type]
119
+ when :data
120
+ return _build_data(new_params, param_obj, param_options,
121
+ predefined_value)
122
+ when :CloudObject
123
+ if param_options[:required] &&
124
+ @object_data.type?(param_name) != :DataObject
125
+ fail Lorj::PrcError.new,
126
+ format("Object '%s/%s' is not defined. '%s' requirement "\
127
+ 'failed.', self.class, param_name, fname)
128
+ end
129
+ if @object_data.exist?(param_name)
130
+ new_params.add(@object_data[param_name, :ObjectData])
131
+ else
132
+ Lorj.debug(2, "The optional '%s' was not loaded", param_name)
133
+ end
134
+ else
135
+ PrcLib.runtime_fail("Undefined ObjectData '%s'.", param_options[:type])
136
+ end
137
+ nil
138
+ end
139
+
140
+ # internal runtime function for process call
141
+ # Build a process/controller parameters object (ObjectData)
142
+ #
143
+ # *parameters*:
144
+ # - +object_type+ : object type requiring parameters.
145
+ # - +sEventType+ : event type used to call the process
146
+ # - +fname+ : caller function
147
+ # - +as_controller+ : attribute options
148
+ # - +predefined_params+ : pre-defined parameters values.
149
+ #
150
+ # *return*:
151
+ # - ObjectData : list of data and objects wanted by the process or
152
+ # the controller. In case of the controller, hdata
153
+ # controller map is also added.
154
+ #
155
+ # *raise*:
156
+ # - runtime error if required data is not set. (empty or nil)
157
+ #
158
+ def _get_object_params(object_type, sEventType, _fname,
159
+ as_controller = false, predefined_params = {})
160
+ # Building handler parameters
161
+ # hdata is built for controller. ie, ObjectData is NOT internal.
162
+
163
+ obj_params = PrcLib.model.meta_obj.rh_get(object_type, :params, :keys)
164
+
165
+ fail Lorj::PrcError.new, "'%s' Object data needs not set. Forgot "\
166
+ 'obj_needs?', object_type if obj_params.nil?
167
+
168
+ new_params = _obj_param_init(object_type, sEventType, as_controller)
169
+
170
+ obj_params.each do | param_path, param_options|
171
+ next if Lorj.rhExist?(param_options, :for, sEventType) == 2
172
+
173
+ param_obj = KeyPath.new(param_path)
174
+ param_name = param_obj.key
175
+
176
+ value = _build_param(new_params, param_path, param_options,
177
+ predefined_params[param_name])
178
+
179
+ if as_controller && !value.nil?
180
+ _build_hdata(object_type, new_params, param_obj, param_options, value)
181
+ end
182
+ end
183
+ new_params
184
+ end
185
+
186
+ # Internal runtime function for process call
187
+ #
188
+ # initialize Object parameters object (ObjectData)
189
+ # And add the current object in parameters in case we called
190
+ # delete_e handler
191
+ #
192
+ # *parameters*:
193
+ # - +object_type+ : ObjectData parameters for this object type.
194
+ # - +sEventType+ : Event handler called
195
+ # - +as_controller+: true if this will be a controller parameters object.
196
+ #
197
+ # *returns*
198
+ # - ObjectData: for controller or process
199
+ #
200
+ def _obj_param_init(object_type, sEventType, as_controller)
201
+ new_params = ObjectData.new(!as_controller)
202
+
203
+ if sEventType == :delete_e && @object_data.exist?(object_type)
204
+ new_params.add(@object_data[object_type, :ObjectData])
205
+ end
206
+ new_params
207
+ end
208
+ # unused function???
209
+ # def _get_controller_map_value(keypath, sProcessValue)
210
+ # section = Lorj.defaults.get_meta_section(sData)
211
+ # section = :runtime if section.nil?
212
+ # keypath = KeyPath.new(keypath).keyPath
213
+ # return nil if Lorj.rhExist?(PrcLib.model.meta_data, section, keypath,
214
+ # :controller, sProcessValue) != 4
215
+ # PrcLib.model.meta_data.rh_get(section, keypath,
216
+ # :controller, sProcessValue)
217
+ # end
218
+
219
+ # unused function???
220
+ # def _get_process_map_value(keypath, sControllerValue)
221
+ # section = Lorj.defaults.get_meta_section(sData)
222
+ # section = :runtime if section.nil?
223
+ # keypath = KeyPath.new(keypath).keyPath
224
+ # return nil if Lorj.rhExist?(PrcLib.model.meta_data, section, keypath,
225
+ # :process, sControllerValue) != 4
226
+ # PrcLib.model.meta_data.rh_get(section, keypath,
227
+ # :process, sControllerValue)
228
+ # end
229
+ end
230
+ end
@@ -0,0 +1,391 @@
1
+ # (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ # Module Lorj which contains several classes.
16
+ #
17
+ # Those classes describes :
18
+ # - processes (BaseProcess) : How to create/delete/edit/query object.
19
+ # - controler (BaseControler) : If a provider is defined, define how will do
20
+ # object creation/etc...
21
+ # - definition(BaseDefinition): Functions to declare objects, query/data mapping
22
+ # and setup
23
+ # this task to make it to work.
24
+ module Lorj
25
+ # Adding process core functions.
26
+ class BaseDefinition
27
+ # Capitalized function are called to start a process. It is done by Core
28
+ # class.
29
+
30
+ # Call meta lorj object creation process.
31
+ # The creation process can implement any logic like:
32
+ # - create an object in the DB.
33
+ # - check object existence in the DB. If not exists, create it.
34
+ #
35
+ # * *Args* :
36
+ # - +ObjectType+ : Meta object type to create.
37
+ # - +Config+ : Optional. Hash containing list of data to use for
38
+ # creation.
39
+ #
40
+ # * *Returns* :
41
+ # - +Object+ : Lorj::Data object of type +ObjectType+ created.
42
+ #
43
+ # * *Raises* :
44
+ # - Warning if the create_e process handler did not return any data. (nil)
45
+ # - Warning if the Config data passed are not required by the meta object
46
+ # (or dependencies) at creation time.
47
+ # - Error if ObjectType has never been declared.
48
+ # - Error if the dependencies create_e process handler did not return any
49
+ # data. (nil) - Loop detection.
50
+ # - Error if the create_e process handler raise an error.
51
+ #
52
+ def process_create(sObjectType, hConfig = {})
53
+ # if hConfig.length > 0
54
+ # # cleanup runtime data to avoid conflicts between multiple calls
55
+ # valid_keys = _identify_data(sObjectType, :create_e)
56
+ # valid_keys.each do | sKey|
57
+ # value = hConfig.rh_get(sKey)
58
+ # @config[sKey] = value if !@config.exist?(sKey) ||
59
+ # @config.exist?(sKey) == 'runtime'
60
+ # hConfig.rh_set(nil, sKey)
61
+ # end
62
+ # if hConfig.length > 0
63
+ # PrcLib.warning("'%s' has been passed but not declared to '%s'"\
64
+ # ' object. Those are ignored until you add it in the'\
65
+ # " model definition of '%s'",
66
+ # hConfig.keys, sObjectType, sObjectType)
67
+ # end
68
+ # end
69
+
70
+ return nil unless sObjectType
71
+
72
+ unless PrcLib.model.meta_obj.rh_exist?(sObjectType)
73
+ runtime_fail "%s.Create: '%s' is not a known object type.",
74
+ self.class, sObjectType
75
+ end
76
+ proc = PrcLib.model.meta_obj.rh_get(sObjectType, :lambdas, :create_e)
77
+
78
+ # Check required parameters
79
+ _process_load_dependencies(object_type, proc, :create_e, __callee__)
80
+
81
+ # Context: Default object used
82
+ @runtime_context[:oCurrentObj] = sObjectType
83
+
84
+ if proc.nil?
85
+ # This object is a meta object, without any data.
86
+ # Used to build other kind of objects.
87
+ object = Lorj::Data.new
88
+ object.set({}, sObjectType) {}
89
+ else
90
+ # build Function params to pass to the event handler.
91
+ params = _get_object_params(sObjectType, :create_e, proc, hConfig)
92
+ Lorj.debug(2, "Create Object '%s' - Running '%s'", sObjectType, proc)
93
+
94
+ # Call the process function.
95
+ # At some point, the process will call the controller, via the framework
96
+ # This controller call via the framework has the role to
97
+ # create an ObjectData well formatted, with _return_map function
98
+ # See Definition.connect/create/update/query/get functions (lowercase)
99
+ object = @process.method(proc).call(sObjectType, params)
100
+ # return usually is the main object that the process called should
101
+ # provide.
102
+ # Save Object if the object has been created by the process, without
103
+ # controller
104
+ end
105
+
106
+ if object.nil?
107
+ PrcLib.warning("'%s' has returned no data for object Lorj::Data '%s'!",
108
+ proc, sObjectType)
109
+ else
110
+ query_cleanup(sObjectType)
111
+ @object_data.add(object)
112
+ end
113
+ end
114
+
115
+ # Call meta lorj object deletion process
116
+ # There is no implementation of cascade deletion. It is up to the process to
117
+ # do it or not.
118
+ #
119
+ # * *Args* :
120
+ # - +ObjectType+ : Meta object type to create.
121
+ # - +Config+ : Optional. Hash containing list of data to use for
122
+ # creation.
123
+ #
124
+ # * *Returns* :
125
+ # - +Deleted+ : true if deleted or false otherwise.
126
+ #
127
+ # * *Raises* :
128
+ # - Warning if the create_e process handler did not return any data. (nil)
129
+ # - Warning if the Config data passed are not required by the meta object
130
+ # (or dependencies) at creation time.
131
+ # - Error if ObjectType has never been declared.
132
+ # - Error if the dependencies query_e process handler did not return any
133
+ # data. (nil) - Loop detection.
134
+ # - Error if the query_e process handler raise an error.
135
+ #
136
+ def process_delete(object_type, hConfig = {})
137
+ return nil unless object_type
138
+
139
+ unless PrcLib.model.meta_obj.rh_exist?(object_type)
140
+ runtime_fail "%s.Delete: '%s' is not a known object type.",
141
+ self.class, object_type
142
+ end
143
+
144
+ proc = PrcLib.model.meta_obj.rh_get(object_type, :lambdas, :delete_e)
145
+
146
+ return nil if proc.nil?
147
+
148
+ # Check required parameters
149
+ _process_load_dependencies(object_type, proc, :delete_e, __callee__)
150
+
151
+ # Context: Default object used.
152
+ @runtime_context[:oCurrentObj] = object_type
153
+
154
+ # build Function params to pass to the event handler.
155
+ params = _get_object_params(object_type, :delete_e, proc, hConfig)
156
+
157
+ state = @process.method(proc).call(object_type, params)
158
+ # return usually is the main object that the process called should provide
159
+
160
+ @object_data.delete(object_type) if state
161
+ end
162
+
163
+ # Function to clean the cache for a specific meta lorj object queried.
164
+ #
165
+ # * *Args* :
166
+ # - +ObjectType+ : Meta object type to cleanup.
167
+ #
168
+ # * *Returns* :
169
+ # no data
170
+ #
171
+ # * *Raises* :
172
+ #
173
+ def query_cleanup(object_type)
174
+ list = @object_data[:query, object_type]
175
+ return if list.nil?
176
+
177
+ @object_data.delete(list)
178
+ Lorj.debug(2, "Query cache for object '%s' cleaned.", object_type)
179
+ end
180
+
181
+ # Function to clean the cache for a specific meta lorj object.
182
+ #
183
+ # * *Args* :
184
+ # - +ObjectType+ : Meta object type to cleanup.
185
+ #
186
+ # * *Returns* :
187
+ # no data
188
+ #
189
+ # * *Raises* :
190
+ #
191
+ def object_cleanup(object_type)
192
+ object = @object_data[object_type, :ObjectData]
193
+
194
+ @object_data.delete(object) unless object.nil?
195
+ end
196
+
197
+ # Function to execute a query process. This function returns a Lorj::Data of
198
+ # type :list.
199
+ #
200
+ # * *Args* :
201
+ # - +ObjectType+ : Meta object type to query.
202
+ # - +Query+ : Hash. Represent the query to execute.
203
+ # - +Config+ : Optional. Hash containing list of data to use for query
204
+ #
205
+ # * *Returns* :
206
+ # Lorj::Data of type :list
207
+ #
208
+ # * *Raises* :
209
+ #
210
+ #
211
+ def process_query(object_type, hQuery, hConfig = {})
212
+ return nil unless object_type
213
+ unless PrcLib.model.meta_obj.rh_exist?(object_type)
214
+ runtime_fail "%s.Get: '%s' is not a known object type.",
215
+ self.class, object_type
216
+ end
217
+
218
+ # Check if we can re-use a previous query
219
+ list = query_cache(object_type, hQuery)
220
+ return list unless list.nil?
221
+
222
+ proc = PrcLib.model.meta_obj.rh_get(object_type, :lambdas, :query_e)
223
+
224
+ return nil if proc.nil?
225
+
226
+ # Check required parameters
227
+ _process_load_dependencies(object_type, proc, :query_e, __callee__)
228
+
229
+ # Context: Default object used.
230
+ @runtime_context[:oCurrentObj] = object_type
231
+
232
+ # build Function params to pass to the Process Event handler.
233
+ params = _get_object_params(object_type, :query_e, proc, hConfig)
234
+
235
+ # Call the process function.
236
+ # At some point, the process will call the controller, via the framework.
237
+ # This controller call via the framework has the role to
238
+ # create an ObjectData well formatted, with _return_map function
239
+ # See Definition.connect/create/update/query/get functions (lowercase)
240
+ object = @process.method(proc).call(object_type, hQuery, params)
241
+ # return usually is the main object that the process called should provide
242
+ if object.nil?
243
+ PrcLib.warning("'%s' returned no collection of objects Lorj::Data "\
244
+ "for '%s'", proc, object_type)
245
+ else
246
+ # Save Object if the object has been created by the process, without
247
+ # controller
248
+ @object_data.add(object)
249
+ end
250
+ end
251
+
252
+ def query_cache(object_type, hQuery)
253
+ # Check if we can re-use a previous query
254
+ list = @object_data[:query, object_type]
255
+
256
+ return if list.nil?
257
+
258
+ if list[:query] == hQuery
259
+ Lorj.debug(3, "Using Object '%s' query cache : %s",
260
+ object_type, hQuery)
261
+ return list
262
+ end
263
+
264
+ nil
265
+ end
266
+
267
+ # Function to execute a get process. This function returns a Lorj::Data of
268
+ # type :object.
269
+ #
270
+ # * *Args* :
271
+ # - +ObjectType+ : Meta object type to query.
272
+ # - +UniqId+ : Uniq ID.
273
+ # - +Config+ : Optional. Hash containing list of data to use for
274
+ # getting.
275
+ #
276
+ # * *Returns* :
277
+ # Lorj::Data of type :object
278
+ #
279
+ # * *Raises* :
280
+ # - Warning if the Config data passed are not required by the meta object
281
+ # (or dependencies) at creation time.
282
+ # - Error if ObjectType has never been declared.
283
+ # - Error if the dependencies get_e process handler did not return any
284
+ # data. (nil) - Loop detection.
285
+ # - Error if the get_e process handler raise an error.
286
+ #
287
+ def process_get(object_type, sUniqId, hConfig = {})
288
+ return nil unless object_type
289
+ unless PrcLib.model.meta_obj.rh_exist?(object_type)
290
+ runtime_fail "$s.Get: '%s' is not a known object type.",
291
+ self.class, object_type
292
+ end
293
+
294
+ proc = PrcLib.model.meta_obj.rh_get(object_type, :lambdas, :get_e)
295
+
296
+ return nil if proc.nil?
297
+
298
+ # Check required parameters
299
+ _process_load_dependencies(object_type, proc, :get_e, __callee__)
300
+
301
+ # Context: Default object used
302
+ @runtime_context[:oCurrentObj] = object_type
303
+
304
+ # build Function params to pass to the Process Event handler.
305
+ params = _get_object_params(object_type, :get_e, proc, hConfig)
306
+
307
+ # Call the process function.
308
+ # At some point, the process will call the controller, via the framework.
309
+ # This controller call via the framework has the role to
310
+ # create an ObjectData well formatted, with _return_map function
311
+ # See Definition.connect/create/update/query/get functions (lowercase)
312
+ object = @process.method(proc).call(object_type, sUniqId, params)
313
+ # return usually is the main object that the process called should provide
314
+
315
+ # Save Object if the object has been created by the process, without
316
+ # controller
317
+ @object_data.add(object) unless object.nil?
318
+ end
319
+
320
+ # Function to execute a update process. This function returns a Lorj::Data
321
+ # of type :object.
322
+ #
323
+ # * *Args* :
324
+ # - +object_type+ : Meta object type to query.
325
+ # - +config+ : Optional. Hash containing list of data to use for
326
+ # updating.
327
+ #
328
+ # * *Returns* :
329
+ # Lorj::Data of type :object
330
+ #
331
+ # * *Raises* :
332
+ # - Warning if the Config data passed are not required by the meta object
333
+ # (or dependencies) at creation time.
334
+ # - Error if ObjectType has never been declared.
335
+ # - Error if the dependencies get_e process handler did not return any
336
+ # data. (nil) - Loop detection.
337
+ # - Error if the get_e process handler raise an error.
338
+ #
339
+ def process_update(object_type, hConfig = {})
340
+ return nil unless object_type
341
+
342
+ unless PrcLib.model.meta_obj.rh_exist?(object_type)
343
+ runtime_fail "$s.Update: '%s' is not a known object type.",
344
+ self.class, object_type
345
+ end
346
+
347
+ proc = PrcLib.model.meta_obj.rh_get(object_type, :lambdas, :update_e)
348
+
349
+ return nil if proc.nil?
350
+
351
+ _process_load_dependencies(object_type, proc, :update_e, __callee__)
352
+
353
+ # Context: Default object used.
354
+ @runtime_context[:oCurrentObj] = object_type
355
+
356
+ # build Function params to pass to the event handler.
357
+ params = _get_object_params(object_type, :update_e, proc, hConfig)
358
+
359
+ object = @process.method(proc).call(object_type, params)
360
+ # return usually is the main object that the process called should provide
361
+
362
+ # Save Object if the object has been created by the process, without
363
+ # controller
364
+ @object_data.add(object) unless object.nil?
365
+ end
366
+
367
+ def _process_load_dependencies(object_type, proc, handler_name,
368
+ function_name)
369
+ missing_obj = _check_required(object_type, handler_name, proc).reverse
370
+
371
+ while missing_obj.length > 0
372
+ elem = missing_obj.pop
373
+
374
+ if elem == object_type && function_name == :process_delete
375
+ debug(2, "'%s' object is not previously loaded or created.",
376
+ object_type)
377
+ next
378
+ end
379
+
380
+ unless process_create(elem)
381
+ runtime_fail "Unable to create Object '%s'", elem
382
+ end
383
+
384
+ missing_obj = _check_required(object_type, handler_name, proc).reverse
385
+ runtime_fail "loop detection: '%s' is required but"\
386
+ " #{function_name}(%s) did not loaded it.",
387
+ elem, elem if missing_obj.include?(elem)
388
+ end
389
+ end
390
+ end
391
+ end