clowder-common-ruby 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ require 'ostruct'
2
+ require 'json'
3
+
4
+ require 'clowder-common-ruby/version'
5
+ require 'clowder-common-ruby/config'
6
+ require 'clowder-common-ruby/types'
@@ -0,0 +1,87 @@
1
+ require 'ostruct'
2
+ require 'json'
3
+ require_relative 'types'
4
+
5
+ module ClowderCommonRuby
6
+ class Config < AppConfig
7
+ # Check if clowder config's ENV var is defined
8
+ # If true, svc is deployed by Clowder
9
+ def self.clowder_enabled?
10
+ !ENV['ACG_CONFIG'].nil? && ENV['ACG_CONFIG'] != ""
11
+ end
12
+
13
+ def self.load(acg_config = ENV['ACG_CONFIG'] || 'test.json')
14
+ unless File.exist?(acg_config)
15
+ raise "ERROR: #{acg_config} does not exist"
16
+ end
17
+
18
+ new(acg_config)
19
+ end
20
+
21
+ def initialize(acg_config)
22
+ super(JSON.parse(File.read(acg_config)))
23
+ kafka_servers
24
+ kafka_topics
25
+ object_buckets
26
+ dependency_endpoints
27
+ private_dependency_endpoints
28
+ end
29
+
30
+ # List of Kafka Broker URLs.
31
+ def kafka_servers
32
+ @kafka_servers ||= [].tap do |servers|
33
+ kafka.brokers.each do |broker|
34
+ servers << "{#{broker.hostname}}:{#{broker.port}}"
35
+ end
36
+ end
37
+ end
38
+
39
+ # Map of KafkaTopics using the requestedName as the key and the topic object as the value.
40
+ def kafka_topics
41
+ @kafka_topics ||= {}.tap do |topics|
42
+ kafka.topics.each do |topic|
43
+ next if topic.requestedName.nil?
44
+
45
+ topics[topic.requestedName] = topic
46
+ end
47
+ end
48
+ end
49
+
50
+ # List of ObjectBuckets using the requestedName
51
+ def object_buckets
52
+ @object_buckets ||= {}.tap do |buckets|
53
+ objectStore.buckets.each do |bucket|
54
+ next if bucket.requestedName.nil?
55
+
56
+ buckets[bucket.requestedName] = bucket
57
+ end
58
+ end
59
+ end
60
+
61
+ # Nested map using [appName][deploymentName]
62
+ # for the public services of requested applications.
63
+ def dependency_endpoints
64
+ @dependency_endpoints ||= {}.tap do |endpts|
65
+ endpoints.each do |endpoint|
66
+ next if endpoint.app.nil? || endpoint.name.nil?
67
+
68
+ endpts[endpoint.app] = {} unless endpts.include?(endpoint.app)
69
+ endpts[endpoint.app][endpoint.name] = endpoint
70
+ end
71
+ end
72
+ end
73
+
74
+ # nested map using [appName][deploymentName]
75
+ # for the private services of requested applications.
76
+ def private_dependency_endpoints
77
+ @private_dependency_endpoints ||= {}.tap do |priv_endpts|
78
+ privateEndpoints.each do |endpoint|
79
+ next if endpoint.app.nil? || endpoint.name.nil?
80
+
81
+ priv_endpts[endpoint.app] = {} unless priv_endpts.include?(endpoint.app)
82
+ priv_endpts[endpoint.app][endpoint.name] = endpoint
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,401 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "$ref": "#/definitions/AppConfig",
4
+ "$id": "https://cloud.redhat.com/schemas/clowder-appconfig",
5
+ "title": "AppConfig",
6
+ "definitions": {
7
+ "AppConfig": {
8
+ "type": "object",
9
+ "description": "ClowdApp deployment configuration for Clowder enabled apps.",
10
+ "properties": {
11
+ "privatePort": {
12
+ "description": "Defines the private port that the app should be configured to listen on for API traffic.",
13
+ "type": "integer"
14
+ },
15
+ "publicPort": {
16
+ "description": "Defines the public port that the app should be configured to listen on for API traffic.",
17
+ "type": "integer"
18
+ },
19
+ "webPort": {
20
+ "description": "Deprecated: Use 'publicPort' instead.",
21
+ "type": "integer"
22
+ },
23
+ "metricsPort": {
24
+ "description": "Defines the metrics port that the app should be configured to listen on for metric traffic.",
25
+ "type": "integer"
26
+ },
27
+ "metricsPath": {
28
+ "description": "Defines the path to the metrics server that the app should be configured to listen on for metric traffic.",
29
+ "type": "string"
30
+ },
31
+ "logging": {
32
+ "$ref": "#/definitions/LoggingConfig"
33
+ },
34
+ "kafka": {
35
+ "$ref": "#/definitions/KafkaConfig"
36
+ },
37
+ "database": {
38
+ "$ref": "#/definitions/DatabaseConfig"
39
+ },
40
+ "objectStore": {
41
+ "$ref": "#/definitions/ObjectStoreConfig"
42
+ },
43
+ "inMemoryDb": {
44
+ "$ref": "#/definitions/InMemoryDBConfig"
45
+ },
46
+ "featureFlags": {
47
+ "$ref": "#/definitions/FeatureFlagsConfig"
48
+ },
49
+ "endpoints": {
50
+ "id": "endpoints",
51
+ "type": "array",
52
+ "items": {
53
+ "$ref": "#/definitions/DependencyEndpoint"
54
+ }
55
+ },
56
+ "privateEndpoints": {
57
+ "id": "privateEndpoints",
58
+ "type": "array",
59
+ "items": {
60
+ "$ref": "#/definitions/PrivateDependencyEndpoint"
61
+ }
62
+ }
63
+
64
+ },
65
+ "required": [
66
+ "metricsPort",
67
+ "metricsPath",
68
+ "logging"
69
+ ]
70
+ },
71
+ "LoggingConfig": {
72
+ "title": "LoggingConfig",
73
+ "type": "object",
74
+ "description": "Logging Configuration",
75
+ "properties": {
76
+ "type": {
77
+ "description": "Defines the type of logging configuration",
78
+ "type": "string"
79
+ },
80
+ "cloudwatch": {
81
+ "$ref": "#/definitions/CloudWatchConfig"
82
+ }
83
+ },
84
+ "required": [
85
+ "type"
86
+ ]
87
+ },
88
+ "CloudWatchConfig": {
89
+ "title": "CloudWatchConfig",
90
+ "type": "object",
91
+ "description": "Cloud Watch configuration",
92
+ "properties": {
93
+ "accessKeyId": {
94
+ "description": "Defines the access key that the app should use for configuring CloudWatch.",
95
+ "type": "string"
96
+ },
97
+ "secretAccessKey": {
98
+ "description": "Defines the secret key that the app should use for configuring CloudWatch.",
99
+ "type": "string"
100
+ },
101
+ "region": {
102
+ "description": "Defines the region that the app should use for configuring CloudWatch.",
103
+ "type": "string"
104
+ },
105
+ "logGroup": {
106
+ "description": "Defines the logGroup that the app should use for configuring CloudWatch.",
107
+ "type": "string"
108
+ }
109
+ },
110
+ "required": [
111
+ "accessKeyId",
112
+ "secretAccessKey",
113
+ "region",
114
+ "logGroup"
115
+ ]
116
+ },
117
+ "KafkaConfig": {
118
+ "id": "kafkaConfig",
119
+ "type": "object",
120
+ "description": "Kafka Configuration",
121
+ "properties": {
122
+ "brokers": {
123
+ "description": "Defines the brokers the app should connect to for Kafka services.",
124
+ "type": "array",
125
+ "items": {
126
+ "$ref": "#/definitions/BrokerConfig"
127
+ }
128
+ },
129
+ "topics": {
130
+ "type": "array",
131
+ "description": "Defines a list of the topic configurations available to the application.",
132
+ "items": {
133
+ "$ref": "#/definitions/TopicConfig"
134
+ }
135
+ }
136
+ },
137
+ "required": [
138
+ "brokers",
139
+ "topics"
140
+ ]
141
+ },
142
+ "BrokerConfig": {
143
+ "id": "brokerConfig",
144
+ "type": "object",
145
+ "description": "Broker Configuration",
146
+ "properties": {
147
+ "hostname": {
148
+ "type": "string"
149
+ },
150
+ "port": {
151
+ "type": "integer"
152
+ }
153
+ },
154
+ "required": [
155
+ "hostname"
156
+ ]
157
+ },
158
+ "TopicConfig": {
159
+ "id": "topicConfig",
160
+ "type": "object",
161
+ "description": "Topic Configuration",
162
+ "properties": {
163
+ "requestedName": {
164
+ "description": "The name that the app requested in the ClowdApp definition.",
165
+ "type": "string"
166
+ },
167
+ "name": {
168
+ "description": "The name of the actual topic on the Kafka server.",
169
+ "type": "string"
170
+ },
171
+ "consumerGroup": {
172
+ "description": "Defines the consumer group that should be used for the topic.",
173
+ "type": "string"
174
+ }
175
+ },
176
+ "required": [
177
+ "name",
178
+ "requestedName"
179
+ ]
180
+ },
181
+ "DatabaseConfig": {
182
+ "id": "database",
183
+ "title": "DatabaseConfig",
184
+ "type": "object",
185
+ "description": "Database Configuration",
186
+ "properties": {
187
+ "name": {
188
+ "description": "Defines the database name.",
189
+ "type": "string"
190
+ },
191
+ "username": {
192
+ "description": "Defines a username with standard access to the database.",
193
+ "type": "string"
194
+ },
195
+ "password": {
196
+ "description": "Defines the password for the standard user.",
197
+ "type": "string"
198
+ },
199
+ "hostname": {
200
+ "description": "Defines the hostname of the database configured for the ClowdApp.",
201
+ "type": "string"
202
+ },
203
+ "port": {
204
+ "description": "Defines the port of the database configured for the ClowdApp.",
205
+ "type": "integer"
206
+ },
207
+ "adminUsername": {
208
+ "description": "Defines the pgAdmin username.",
209
+ "type": "string"
210
+ },
211
+ "adminPassword": {
212
+ "description": "Defines the pgAdmin password.",
213
+ "type": "string"
214
+ },
215
+ "rdsCa": {
216
+ "description": "Defines the CA used to access the database.",
217
+ "type": "string"
218
+ }
219
+ },
220
+ "required": [
221
+ "name",
222
+ "username",
223
+ "password",
224
+ "hostname",
225
+ "port",
226
+ "adminUsername",
227
+ "adminPassword"
228
+ ]
229
+ },
230
+ "ObjectStoreBucket": {
231
+ "id": "objectStoreBucket",
232
+ "type": "object",
233
+ "description": "Object Storage Bucket",
234
+ "properties": {
235
+ "accessKey": {
236
+ "description": "Defines the access key for specificed bucket.",
237
+ "type": "string"
238
+ },
239
+ "secretKey": {
240
+ "description": "Defines the secret key for the specified bucket.",
241
+ "type": "string"
242
+ },
243
+ "requestedName": {
244
+ "description": "The name that was requested for the bucket in the ClowdApp.",
245
+ "type": "string"
246
+ },
247
+ "name": {
248
+ "description": "The actual name of the bucket being accessed.",
249
+ "type": "string"
250
+ }
251
+ },
252
+ "required": [
253
+ "name",
254
+ "requestedName"
255
+ ]
256
+ },
257
+ "ObjectStoreConfig": {
258
+ "id": "objectStoreConfig",
259
+ "type": "object",
260
+ "description": "Object Storage Configuration",
261
+ "properties": {
262
+ "buckets": {
263
+ "type": "array",
264
+ "items": {
265
+ "$ref": "#/definitions/ObjectStoreBucket"
266
+ }
267
+ },
268
+ "accessKey": {
269
+ "description": "Defines the access key for the Object Storage server configuration.",
270
+ "type": "string"
271
+ },
272
+ "secretKey": {
273
+ "description": "Defines the secret key for the Object Storage server configuration.",
274
+ "type": "string"
275
+ },
276
+ "hostname": {
277
+ "description": "Defines the hostname for the Object Storage server configuration.",
278
+ "type": "string"
279
+ },
280
+ "port": {
281
+ "description": "Defines the port for the Object Storage server configuration.",
282
+ "type": "integer"
283
+ },
284
+ "tls": {
285
+ "description": "Details if the Object Server uses TLS.",
286
+ "type": "boolean"
287
+ }
288
+ },
289
+ "required": [
290
+ "hostname",
291
+ "port",
292
+ "tls"
293
+ ]
294
+ },
295
+ "FeatureFlagsConfig": {
296
+ "id": "featureFlagsConfig",
297
+ "type": "object",
298
+ "description": "Feature Flags Configuration",
299
+ "properties": {
300
+ "hostname": {
301
+ "description": "Defines the hostname for the FeatureFlags server",
302
+ "type": "string"
303
+ },
304
+ "port": {
305
+ "description": "Defines the port for the FeatureFlags server",
306
+ "type": "integer"
307
+ }
308
+ },
309
+ "required":[
310
+ "hostname",
311
+ "port"
312
+ ]
313
+ },
314
+ "InMemoryDBConfig": {
315
+ "id": "inMemoryDbConfig",
316
+ "type": "object",
317
+ "description": "In Memory DB Configuration",
318
+ "properties": {
319
+ "hostname": {
320
+ "description": "Defines the hostname for the In Memory DB server configuration.",
321
+ "type": "string"
322
+ },
323
+ "port": {
324
+ "description": "Defines the port for the In Memory DB server configuration.",
325
+ "type": "integer"
326
+ },
327
+ "username": {
328
+ "description": "Defines the username for the In Memory DB server configuration.",
329
+ "type": "string"
330
+ },
331
+ "password": {
332
+ "description": "Defines the password for the In Memory DB server configuration.",
333
+ "type": "string"
334
+ }
335
+ },
336
+ "required": [
337
+ "hostname",
338
+ "port"
339
+
340
+ ]
341
+ },
342
+ "DependencyEndpoint": {
343
+ "id": "dependency",
344
+ "type": "object",
345
+ "description": "Dependent service connection info",
346
+ "properties": {
347
+ "name": {
348
+ "description": "The PodSpec name of the dependent service inside the ClowdApp.",
349
+ "type": "string"
350
+ },
351
+ "hostname": {
352
+ "description": "The hostname of the dependent service.",
353
+ "type": "string"
354
+ },
355
+ "port": {
356
+ "description": "The port of the dependent service.",
357
+ "type": "integer"
358
+ },
359
+ "app": {
360
+ "description": "The app name of the ClowdApp hosting the service.",
361
+ "type": "string"
362
+ }
363
+ },
364
+ "required": [
365
+ "name",
366
+ "hostname",
367
+ "port",
368
+ "app"
369
+ ]
370
+ },
371
+ "PrivateDependencyEndpoint": {
372
+ "id": "privateDependency",
373
+ "type": "object",
374
+ "description": "Dependent service connection info",
375
+ "properties": {
376
+ "name": {
377
+ "description": "The PodSpec name of the dependent service inside the ClowdApp.",
378
+ "type": "string"
379
+ },
380
+ "hostname": {
381
+ "description": "The hostname of the dependent service.",
382
+ "type": "string"
383
+ },
384
+ "port": {
385
+ "description": "The port of the dependent service.",
386
+ "type": "integer"
387
+ },
388
+ "app": {
389
+ "description": "The app name of the ClowdApp hosting the service.",
390
+ "type": "string"
391
+ }
392
+ },
393
+ "required": [
394
+ "name",
395
+ "hostname",
396
+ "port",
397
+ "app"
398
+ ]
399
+ }
400
+ }
401
+ }