Class: ClowderCommonRuby::Config

Inherits:
AppConfig
  • Object
show all
Defined in:
lib/clowder-common-ruby/config.rb

Instance Attribute Summary

Attributes inherited from AppConfig

#database, #endpoints, #featureFlags, #inMemoryDb, #kafka, #logging, #metadata, #objectStore, #privateEndpoints

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AppConfig

#valid_keys

Constructor Details

#initialize(acg_config) ⇒ Config

Returns a new instance of Config.



21
22
23
24
25
26
27
28
# File 'lib/clowder-common-ruby/config.rb', line 21

def initialize(acg_config)
  super(JSON.parse(File.read(acg_config)))
  kafka_servers
  kafka_topics
  object_buckets
  dependency_endpoints
  private_dependency_endpoints
end

Class Method Details

.clowder_enabled?Boolean

Check if clowder config’s ENV var is defined If true, svc is deployed by Clowder

Returns:

  • (Boolean)


9
10
11
# File 'lib/clowder-common-ruby/config.rb', line 9

def self.clowder_enabled?
  !ENV['ACG_CONFIG'].nil? && ENV['ACG_CONFIG'] != ""
end

.load(acg_config = ENV['ACG_CONFIG'] || 'test.json') ⇒ Object



13
14
15
16
17
18
19
# File 'lib/clowder-common-ruby/config.rb', line 13

def self.load(acg_config = ENV['ACG_CONFIG'] || 'test.json')
  unless File.exist?(acg_config)
    raise "ERROR: #{acg_config} does not exist"
  end

  new(acg_config)
end

Instance Method Details

#dependency_endpointsObject

Nested map using [appName] for the public services of requested applications.



63
64
65
66
67
68
69
70
71
72
# File 'lib/clowder-common-ruby/config.rb', line 63

def dependency_endpoints
  @dependency_endpoints ||= {}.tap do |endpts|
    endpoints.each do |endpoint|
      next if endpoint.app.nil? || endpoint.name.nil?

      endpts[endpoint.app]                = {} unless endpts.include?(endpoint.app)
      endpts[endpoint.app][endpoint.name] = endpoint
    end
  end
end

#kafka_serversObject

List of Kafka Broker URLs.



31
32
33
34
35
36
37
# File 'lib/clowder-common-ruby/config.rb', line 31

def kafka_servers
  @kafka_servers ||= [].tap do |servers|
    kafka.brokers.each do |broker|
      servers << "{#{broker.hostname}}:{#{broker.port}}"
    end
  end
end

#kafka_topicsObject

Map of KafkaTopics using the requestedName as the key and the topic object as the value.



40
41
42
43
44
45
46
47
48
# File 'lib/clowder-common-ruby/config.rb', line 40

def kafka_topics
  @kafka_topics ||= {}.tap do |topics|
    kafka.topics.each do |topic|
      next if topic.requestedName.nil?

      topics[topic.requestedName] = topic
    end
  end
end

#object_bucketsObject

List of ObjectBuckets using the requestedName



51
52
53
54
55
56
57
58
59
# File 'lib/clowder-common-ruby/config.rb', line 51

def object_buckets
  @object_buckets ||= {}.tap do |buckets|
    objectStore.buckets.each do |bucket|
      next if bucket.requestedName.nil?

      buckets[bucket.requestedName] = bucket
    end
  end
end

#private_dependency_endpointsObject

nested map using [appName]

for the private services of requested applications.


76
77
78
79
80
81
82
83
84
85
# File 'lib/clowder-common-ruby/config.rb', line 76

def private_dependency_endpoints
  @private_dependency_endpoints ||= {}.tap do |priv_endpts|
    privateEndpoints.each do |endpoint|
      next if endpoint.app.nil? || endpoint.name.nil?

      priv_endpts[endpoint.app]                = {} unless priv_endpts.include?(endpoint.app)
      priv_endpts[endpoint.app][endpoint.name] = endpoint
    end
  end
end