lorj 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,181 @@
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
+ # require 'rubygems'
19
+ # require 'byebug'
20
+ # require 'bundler/setup'
21
+
22
+ app_path = File.dirname(File.dirname(__FILE__))
23
+
24
+ $LOAD_PATH << '../lib'
25
+
26
+ require 'lorj' # Load lorj framework
27
+
28
+ describe 'class: Lorj::Account,' do
29
+ context 'Lorj::Account.new,' do
30
+ it 'instance is created.' do
31
+ PrcLib.log_file = 'lorj-rspec.log'
32
+ PrcLib.level = Logger::FATAL
33
+ PrcLib.app_name = 'lorj-spec'
34
+ PrcLib.app_defaults = File.join(app_path, 'lorj-spec')
35
+
36
+ account = Lorj::Account.new
37
+ expect(account).to be
38
+ end
39
+
40
+ it 'account.layers is compliant' do
41
+ account = Lorj::Account.new
42
+ expect(account.layers).to eq(%w(runtime account local default))
43
+ end
44
+ end
45
+
46
+ context "Key | runtime | accounts | local | default)\n"\
47
+ " :keypair | nil | nil | nova_local| default_key\n"\
48
+ " :data | nil | nil | no effect | None\n"\
49
+ " :data is account exclusive\n => accounts/test1 not set:" do
50
+ before(:all) do
51
+ File.open(File.join(PrcLib.data_path, 'config.yaml'),
52
+ 'w+') do |file|
53
+ file.write(":default:\n :keypair_name: nova_local\n :data: no effect")
54
+ end
55
+ File.open(File.join(PrcLib.data_path, 'accounts', 'test1'),
56
+ 'w+') do |file|
57
+ file.write(":credentials:\n :keypair_name: nova_test1\n "\
58
+ ":tenant_name: test\n :data: ac_data")
59
+ end
60
+
61
+ @account = Lorj::Account.new
62
+ end
63
+
64
+ it 'account.exist?(:keypair_name) return true, stored only in local.' do
65
+ expect(@account.exist?(:keypair_name)).to equal(true)
66
+ end
67
+
68
+ it "account[:keypair_name] return 'nova_local', stored only in local." do
69
+ expect(@account[:keypair_name]).to eq('nova_local')
70
+ end
71
+
72
+ it 'account.where?(:keypair_name) return %w(local default)' do
73
+ expect(@account.where?(:keypair_name)).to eq(%w(local default))
74
+ end
75
+
76
+ it "after account.local_del(:keypair_name) value is 'default_key'" do
77
+ expect(@account.local_del(:keypair_name)).to eq('nova_local')
78
+ expect(@account.where?(:keypair_name)).to eq(%w(default))
79
+ expect(@account[:keypair_name]).to eq('default_key')
80
+ end
81
+
82
+ it 'account.exist?(:data) return false, stored only in local.' do
83
+ expect(@account.exist?(:data)).to equal(false)
84
+ end
85
+
86
+ it "account[:data] return 'nova_local', stored only in local." do
87
+ expect(@account[:data]).to eq(nil)
88
+ end
89
+ it 'account.where?(:data) return false, as account not loaded.' do
90
+ expect(@account.where?(:data)).to equal(false)
91
+ end
92
+ end
93
+
94
+ context "Key | runtime | accounts | local | default)\n"\
95
+ " :keypair | none | nova_test1 | nova_local| default_key\n"\
96
+ " :data | none | ac_data | no effect | None\n"\
97
+ " :data is account exclusive\n => accounts/test1 not set:" do
98
+ before(:all) do
99
+ @account = Lorj::Account.new
100
+ end
101
+ it 'account.load return true' do
102
+ expect(@account.ac_load 'test1').to equal(true)
103
+ expect(@account.where?(:data)).to eq(%w(account))
104
+ end
105
+
106
+ it "account[:data] = 'value' return 'value'" do
107
+ expect(@account[:data] = 'value').to eq('value')
108
+ expect(@account.where?(:data)).to eq(%w(runtime account))
109
+ end
110
+
111
+ it 'runtime data structure is valid' do
112
+ runtime = @account.config_dump(%w(runtime))
113
+ expect(runtime).to eq(:data => 'value')
114
+ end
115
+
116
+ it "account[:data] return 'value'" do
117
+ expect(@account[:data]).to eq('value')
118
+ end
119
+
120
+ it 'account.where?(:keypair_name) return %w(account local default)' do
121
+ expect(@account.where?(:keypair_name)).to eq(%w(account local default))
122
+ end
123
+ it "account[:keypair_name] = 'value' return 'value'" do
124
+ expect(@account[:keypair_name] = 'value').to eq('value')
125
+ expect(@account.where?(:keypair_name)).to eq(%w(runtime account local
126
+ default))
127
+ end
128
+
129
+ it "account.del(:keypair_name) return 'value'" do
130
+ expect(@account.del(:keypair_name)).to eq('value')
131
+ expect(@account.where?(:keypair_name)).to eq(%w(account local default))
132
+ end
133
+
134
+ it "account.get(:keypair_name) return back default value 'nova_test1'" do
135
+ expect(@account.get(:keypair_name)).to eq('nova_test1')
136
+ end
137
+
138
+ it "account.set(:keypair_name, 'nova_test2', :name => 'account') return "\
139
+ " 'nova_test2'" do
140
+ expect(@account.set(:keypair_name, 'nova_test2',
141
+ :name => 'account')).to eq('nova_test2')
142
+ expect(@account.where?(:keypair_name)).to eq(%w(account local default))
143
+ end
144
+
145
+ it "account.get(:keypair_name, :name => 'account') return 'nova_test2'" do
146
+ expect(@account.get(:keypair_name,
147
+ :name => 'account')).to eq('nova_test2')
148
+ end
149
+
150
+ it 'account.ac_save return false - '\
151
+ 'file has no valid provider name' do
152
+ expect(@account.ac_save).to equal(false)
153
+ end
154
+
155
+ it 'set provider name' do
156
+ expect(@account.set(:provider, 'myprovider',
157
+ :name => 'account',
158
+ :section => :account)).to eq('myprovider')
159
+ end
160
+
161
+ it 'account.ac_save return true' do
162
+ expect(@account.ac_save).to equal(true)
163
+ end
164
+
165
+ it 'account.ac_new return true, and :data disappeared.' do
166
+ expect(@account.ac_new 'test1').to equal(true)
167
+ expect(@account.where?(:data)).to eq(%w(runtime))
168
+ end
169
+
170
+ it 'account.load return true, and :data is back' do
171
+ expect(@account.ac_load 'test1').to equal(true)
172
+ expect(@account.where?(:data)).to eq(%w(runtime account))
173
+ end
174
+
175
+ it "account.get(:keypair_name, :name => 'account') return "\
176
+ "saved 'nova_test2'" do
177
+ expect(@account.get(:keypair_name,
178
+ :name => 'account')).to eq('nova_test2')
179
+ end
180
+ end
181
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lorj
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - forj team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-18 00:00:00.000000000 Z
11
+ date: 2015-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: 3.1.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: highline
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -106,61 +120,91 @@ extra_rdoc_files: []
106
120
  files:
107
121
  - .gitignore
108
122
  - .gitreview
123
+ - .rubocop.yml
109
124
  - Gemfile
110
- - Gemfile.lock
111
125
  - LICENSE.txt
112
126
  - README.md
113
127
  - Rakefile
114
128
  - bin/cloud_test.rb
115
- - example/students_1/process/Students.rb
129
+ - example/students_1/process/students.rb
116
130
  - example/students_1/students.rb
117
- - example/students_2/process/Students.rb
131
+ - example/students_2/process/students.rb
118
132
  - example/students_2/students.rb
119
133
  - example/students_3/controller/yaml_students.rb
120
134
  - example/students_3/controller/yaml_students_controller.rb
121
135
  - example/students_3/process/students.rb
122
136
  - example/students_3/students.rb
123
- - example/students_4/controller/yaml_students.rb
124
- - example/students_4/controller/yaml_students_controller.rb
125
- - example/students_4/process/students.rb
126
- - example/students_4/students.rb
127
137
  - example/yaml_students/students.rb
128
138
  - example/yaml_students/yaml_students.rb
129
139
  - lib/concept.md
130
140
  - lib/core/core.rb
141
+ - lib/core/core_controller.rb
142
+ - lib/core/core_internal.rb
143
+ - lib/core/core_model.rb
144
+ - lib/core/core_object_data.rb
145
+ - lib/core/core_object_params.rb
146
+ - lib/core/core_process.rb
147
+ - lib/core/core_process_setup.rb
148
+ - lib/core/core_setup_ask.rb
149
+ - lib/core/core_setup_encrypt.rb
150
+ - lib/core/core_setup_init.rb
151
+ - lib/core/core_setup_list.rb
131
152
  - lib/core/definition.rb
132
153
  - lib/core/definition_internal.rb
133
- - lib/core/lorj-basecontroller.rb
134
- - lib/core/lorj-basedefinition.rb
135
- - lib/core/lorj-baseprocess.rb
136
- - lib/core/lorj-data.rb
137
- - lib/core/lorj-keypath.rb
138
- - lib/core_process/CloudProcess.rb
139
- - lib/core_process/global_process.rb
140
- - lib/core_process/network_process.rb
154
+ - lib/core/lorj_basecontroller.rb
155
+ - lib/core/lorj_basedefinition.rb
156
+ - lib/core/lorj_baseprocess.rb
157
+ - lib/core/lorj_data.rb
158
+ - lib/core/lorj_keypath.rb
159
+ - lib/core_process/cloud/process/common.rb
160
+ - lib/core_process/cloud/process/connection.rb
161
+ - lib/core_process/cloud/process/external_network.rb
162
+ - lib/core_process/cloud/process/flavor.rb
163
+ - lib/core_process/cloud/process/images.rb
164
+ - lib/core_process/cloud/process/internet_network.rb
165
+ - lib/core_process/cloud/process/internet_server.rb
166
+ - lib/core_process/cloud/process/keypairs.rb
167
+ - lib/core_process/cloud/process/network.rb
168
+ - lib/core_process/cloud/process/public_ip.rb
169
+ - lib/core_process/cloud/process/router.rb
170
+ - lib/core_process/cloud/process/rules.rb
171
+ - lib/core_process/cloud/process/security_groups.rb
172
+ - lib/core_process/cloud/process/server.rb
173
+ - lib/core_process/cloud/process/server_log.rb
174
+ - lib/core_process/cloud/process/subnetwork.rb
175
+ - lib/core_process/cloud_process.rb
141
176
  - lib/img/.directory
142
177
  - lib/img/account_data_access.png
143
178
  - lib/img/config_data_access.png
144
179
  - lib/img/forj-lib-concept.png
180
+ - lib/logging.rb
145
181
  - lib/lorj.rb
146
182
  - lib/lorj/version.rb
147
- - lib/prc-account.rb
148
- - lib/prc-config.rb
149
- - lib/prc-logging.rb
183
+ - lib/lorj_account.rb
184
+ - lib/lorj_config.rb
185
+ - lib/lorj_defaults.rb
150
186
  - lib/prc.rb
151
- - lib/providers/hpcloud/Hpcloud.rb
187
+ - lib/prc_base_config.rb
188
+ - lib/prc_core_config.rb
189
+ - lib/prc_section_config.rb
152
190
  - lib/providers/hpcloud/compute.rb
191
+ - lib/providers/hpcloud/hpcloud.rb
153
192
  - lib/providers/hpcloud/network.rb
154
193
  - lib/providers/hpcloud/security_groups.rb
155
- - lib/providers/mock/Mock.rb
156
- - lib/providers/openstack/Openstack.rb
194
+ - lib/providers/mock/mock.rb
195
+ - lib/providers/openstack/openstack.rb
157
196
  - lib/providers/templates/compute.rb
158
- - lib/providers/templates/core.rb
197
+ - lib/providers/templates/mycloud.rb
159
198
  - lib/providers/templates/network.rb
199
+ - lib/rh.rb
160
200
  - lorj-spec/defaults.yaml
161
201
  - lorj.gemspec
162
- - spec/forj-account_spec.rb
163
- - spec/forj-config_spec.rb
202
+ - spec/00_lorj_log_spec.rb
203
+ - spec/01_hash_rh_spec.rb
204
+ - spec/02_prc_base_config_spec.rb
205
+ - spec/04_prc_core_config_spec.rb
206
+ - spec/11_lorj_config_spec.rb
207
+ - spec/12_lorj_account_spec.rb
164
208
  homepage: https://github.com/forj-oss/lorj
165
209
  licenses:
166
210
  - Apache License, Version 2.0.
@@ -188,6 +232,10 @@ signing_key:
188
232
  specification_version: 4
189
233
  summary: Process Controllers framework system
190
234
  test_files:
191
- - spec/forj-account_spec.rb
192
- - spec/forj-config_spec.rb
235
+ - spec/00_lorj_log_spec.rb
236
+ - spec/01_hash_rh_spec.rb
237
+ - spec/02_prc_base_config_spec.rb
238
+ - spec/04_prc_core_config_spec.rb
239
+ - spec/11_lorj_config_spec.rb
240
+ - spec/12_lorj_account_spec.rb
193
241
  has_rdoc:
data/Gemfile.lock DELETED
@@ -1,37 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- lorj (0.2.0)
5
- ansi (>= 1.4.3)
6
- encryptor (= 1.3.0)
7
- highline (~> 1.6.21)
8
-
9
- GEM
10
- remote: https://rubygems.org/
11
- specs:
12
- ansi (1.4.3)
13
- diff-lcs (1.2.5)
14
- encryptor (1.3.0)
15
- highline (1.6.21)
16
- rake (10.4.2)
17
- rspec (3.1.0)
18
- rspec-core (~> 3.1.0)
19
- rspec-expectations (~> 3.1.0)
20
- rspec-mocks (~> 3.1.0)
21
- rspec-core (3.1.7)
22
- rspec-support (~> 3.1.0)
23
- rspec-expectations (3.1.2)
24
- diff-lcs (>= 1.2.0, < 2.0)
25
- rspec-support (~> 3.1.0)
26
- rspec-mocks (3.1.3)
27
- rspec-support (~> 3.1.0)
28
- rspec-support (3.1.2)
29
-
30
- PLATFORMS
31
- ruby
32
-
33
- DEPENDENCIES
34
- bundler
35
- lorj!
36
- rake (~> 10.0)
37
- rspec (~> 3.1.0)
@@ -1,20 +0,0 @@
1
- # Students process
2
- class StudentsProcess
3
- def create_student(sObjectType, hParams)
4
- puts "Running creation process for object '%s' = '%s'" % [sObjectType, hParams[:student_name] ]
5
- # If you prefer to print out to the log system instead:
6
- # PrcLib::debug("Running creation process for object '%s' = '%s'" % [sObjectType, hParams[:student_name] ])
7
- end
8
- end
9
-
10
- # Declaring your data model and handlers.
11
- class Lorj::BaseDefinition
12
-
13
- # We need to define the student object and the handler to use while we need to create it.
14
- define_obj(:student,
15
- {
16
- :create_e => :create_student # The function to call in the class Students
17
- })
18
-
19
- obj_needs :data, :student_name, { :for => [:create_e] }
20
- end
@@ -1,27 +0,0 @@
1
- # Students process
2
- class StudentsProcess
3
- def create_student(sObjectType, hParams)
4
- PrcLib::state ("Running creation process for object '%s' = '%s'" % [sObjectType, hParams[:student_name] ])
5
-
6
- oObject = controller_create(sObjectType)
7
- raise "Student '%s' not created." % hParams[:student_name] if oObject.nil?
8
- PrcLib::info ("'%s': '%s' created with id %s" % [sObjectType, hParams[:student_name], oObject[:id]])
9
- oObject
10
- end
11
-
12
- end
13
-
14
- # Declaring your data model and handlers.
15
- class Lorj::BaseDefinition
16
-
17
- # We need to define the student object and the handler to use while we need to create it.
18
- define_obj(:student,
19
- {
20
- :create_e => :create_student, # The function to call in the class Students
21
- :query_e => :controller_query, # We use predefined call to the controller query
22
- :get_e => :controller_get, # We use predefined call to the controller get
23
- :delete_e => :controller_delete # We use predefined call to the controller delete
24
- })
25
-
26
- obj_needs :data, :student_name, { :for => [:create_e], :mapping => :name }
27
- end
@@ -1,82 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- # (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
-
17
-
18
- # This class describes how to process some actions, and will do everything prior
19
- # this task to make it to work.
20
-
21
- # This Mock controller keep the data in memory in hash/Array data.
22
-
23
- # declare yaml student API to the controller
24
- cur_path = File.dirname(__FILE__)
25
- api_file = File.expand_path(File.join(cur_path, "..", "..", "yaml_students", 'yaml_students.rb'))
26
- require api_file
27
-
28
- # The controller is a combination of 2 elements:
29
- # - Controller class
30
- # Code which will interfere with the external API.
31
- #
32
- # The file name must respect the name of the class. 1st letter already capitalized and letter after _ is capitalized.
33
- # file: my_code.rb => needs to create MyCodeController class
34
- #
35
- # - Definition class
36
- # This class declare any kind of mapping or additional fields to consider.
37
- # Additionnal fields are unknow by the process. So, those fields will needs to be setup before.
38
- #
39
- # file name convention is identical than controller class.
40
- # file: my_code.rb => needs to create MyCode class
41
-
42
- controller_file = File.expand_path(File.join(cur_path,'yaml_students_controller.rb'))
43
- require controller_file # Load controller mapping
44
-
45
- # Declare
46
- # - additional objects and their specific process (:connection using basic predefined :controller_create process)
47
- # - data_mapping :
48
- # :connection_string => :file_name
49
- # :course => :training
50
- #
51
- # If some data has been added by the controller, the main and process, won't take care and the framework will fails.
52
- # To eliminate this errors, there is 2 cases:
53
- # - detect this change in the process or the main.
54
- # - set it up, using lorj setup function, if the data is declared askable by the controller.
55
- # The controller can define how the setup have to ask values, and even can get data
56
- # from itself.
57
-
58
- class YamlStudents
59
-
60
- define_obj(:connection,{
61
- :create_e => :controller_create # Nothing complex to do. So, simply call the controller create.
62
- })
63
-
64
- obj_needs :data, :connection_string, :mapping => :file_name
65
- undefine_attribute :id # Do not return any predefined ID
66
- undefine_attribute :name # Do not return any predefined NAME
67
-
68
- # The student model has been expanded. The object name will be built from first and last name
69
- define_obj(:student)
70
- obj_needs :CloudObject, :connection
71
-
72
- set_hdata :first_name
73
- set_hdata :last_name
74
- set_hdata :course, :mapping => :training
75
-
76
- get_attr_mapping :course, :training
77
-
78
- # This controller will know how to manage a student file with those data.
79
- # But note that the file can have a lot of more data than what the process
80
- # usually manage. It is up to you to increase your process to manage more data.
81
- # Then each controller may need to define mapping fields.
82
- end
@@ -1,141 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- # (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
-
17
-
18
- # This class describes how to process some actions, and will do everything prior
19
- # this task to make it to work.
20
-
21
- # This Mock controller keep the data in memory in hash/Array data.
22
-
23
- # declare yaml student API to the controller
24
- cur_file = File.expand_path(File.join(File.dirname(File.dirname(__FILE__)), "..", "yaml_students", 'yaml_students.rb'))
25
- require cur_file
26
-
27
- # The controller is a combination of 2 elements:
28
- # - Controller class
29
- # Code which will interfere with the external API.
30
- #
31
- # The file name must respect the name of the class. 1st letter already capitalized and letter after _ is capitalized.
32
- # file: my_code.rb => needs to create MyCodeController class
33
- #
34
- # - Definition class
35
- # This class declare any kind of mapping or additional fields to consider.
36
- # Additionnal fields are unknow by the process. So, those fields will needs to be setup before.
37
- #
38
- # file name convention is identical than controller class.
39
- # file: my_code.rb => needs to create MyCode class
40
-
41
- class YamlStudentsController
42
- def initialize()
43
- @@valid_attributes = [:name, :first_name, :last_name, :id, :status, :training]
44
-
45
- end
46
-
47
- def create(sObjectType, hParams)
48
- case sObjectType
49
- when :connection
50
- required?(hParams, :hdata, :file_name)
51
- YamlSchool.new(hParams[:hdata, :file_name])
52
- when :student
53
- required?(hParams, :connection)
54
- required?(hParams, :student_name)
55
-
56
- hParams[:connection].create_student(hParams[:student_name], hParams[:hdata])
57
- else
58
- Error "'%s' is not a valid object for 'create'" % sObjectType
59
- end
60
- end
61
-
62
- # This function return a collection which have to provide:
63
- # functions: [], length, each
64
- # Used by network process.
65
- def query(sObjectType, sQuery, hParams)
66
- case sObjectType
67
- when :student
68
- required?(hParams, :connection)
69
-
70
- hParams[:connection].query_student(sQuery)
71
- else
72
- Error "'%s' is not a valid object for 'create'" % sObjectType
73
- end
74
-
75
- end
76
-
77
- def delete(sObjectType, hParams)
78
- case sObjectType
79
- when :student
80
- required?(hParams, :connection)
81
-
82
- hParams[:connection].delete_student(hParams[sObjectType][:id])
83
- else
84
- Error "'%s' is not a valid object for 'create'" % sObjectType
85
- end
86
- end
87
-
88
- def get(sObjectType, sUniqId, hParams)
89
- case sObjectType
90
- when :student
91
- required?(hParams, :connection)
92
-
93
- list = hParams[:connection].query_student({:id => sUniqId})
94
- if list.length == 0
95
- nil
96
- else
97
- list[0]
98
- end
99
- else
100
- Error "'%s' is not a valid object for 'create'" % sObjectType
101
- end
102
- end
103
-
104
- def get_attr(oControlerObject, key)
105
- # This controller function read the data and
106
- # extract the information requested by the framework.
107
- # Those data will be mapped to the process data model.
108
- # The key is an array, to get data from a level tree.
109
- # [data_l1, data_l2, data_l3] => should retrieve data from structure like data[ data_l2[ data_l3 ] ]
110
- begin
111
- attributes = oControlerObject
112
- raise "get_attr: attribute '%s' is unknown in '%s'. Valid one are : '%s'" % [key[0], oControlerObject.class, @@valid_attributes ] unless @@valid_attributes.include?(key[0])
113
- Lorj::rhGet(attributes, key)
114
- rescue => e
115
- Error "get_attr: Unable to map '%s'. %s" % [key, e.message]
116
- end
117
- end
118
-
119
- def set_attr(oControlerObject, key, value)
120
- begin
121
- attributes = oControlerObject
122
- raise "set_attr: attribute '%s' is unknown in '%s'. Valid one are : '%s'" % [key[0], oControlerObject.class, @@valid_attributes ] unless @@valid_attributes.include?(key[0])
123
- Lorj::rhSet(attributes, value, key)
124
- rescue => e
125
- Error "set_attr: Unable to map '%s' on '%s'" % [key, sObjectType]
126
- end
127
- end
128
-
129
-
130
- def update(sObjectType, oObject, hParams)
131
- case sObjectType
132
- when :student
133
- required?(hParams, :connection)
134
-
135
- hParams[:connection].update_student(oObject)
136
- else
137
- Error "'%s' is not a valid object for 'create'" % sObjectType
138
- end
139
- end
140
-
141
- end