ood_appkit 0.2.5 → 0.2.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d9dd72dd897997eadf63e025a8e085a6ae842b7
4
- data.tar.gz: 8db16a0e7b2c3e010412967a1c015288780dd212
3
+ metadata.gz: 8eb6d20b4747f2021e1f88650dbccf1128a3783c
4
+ data.tar.gz: c04296d552fb068865ee30feaee0addba8a6bd76
5
5
  SHA512:
6
- metadata.gz: 35aad26d17cf8df49f4399b55f138c9959b795e4d16e6054593a6066ab364d0754ba25a24adfb3a35a9ebadaefe71d20aaed70bab2200612276789fc03c88cab
7
- data.tar.gz: ecdf518bfded907f0faf195c4468d82f82e7ba3433cef67a64ba71dfffa87ebb4882b343c5f56c1bab0916048029c495f220130383e7b1cb740c1a402f793870
6
+ metadata.gz: 6ed370c8a4107a89f89ef3cbe0354f39cf762854d064a7d9a7a2177632a77cef1a3be94ad452d2da4ea7be3260506d8602f2b9a0813d185b0bc5f28a5d0eec5b
7
+ data.tar.gz: 905ca68526ade3d6299a1bcaedf32035c73f9476ea28dcf181203e3820b1423916730c661401f1bccb3381a178b4abfc84841c5a2c0d5bb9d3fb87c28507c96a
data/README.md CHANGED
@@ -542,7 +542,7 @@ ganglia_server.uri.to_s
542
542
  #=> "https://www.ganglia.com/gweb/graph.php?c=MyCluster"
543
543
 
544
544
  # To add query values as options for the server
545
- ganglia_server.merge_query_values(g: 'cpu_report').to_s
545
+ ganglia_server.uri(query_values: {g: 'cpu_report'}).to_s
546
546
  #=> "https://www.ganglia.com/gweb/graph.php?c=MyCluster&g=cpu_report"
547
547
  ```
548
548
 
data/config/clusters.yml CHANGED
@@ -19,10 +19,14 @@ v1:
19
19
  ganglia:
20
20
  type: 'OodAppkit::Servers::Ganglia'
21
21
  host: 'cts05.osc.edu'
22
- scheme: 'https'
23
- path: '/gweb/graph.php'
24
- query_values:
22
+ scheme: 'https://'
23
+ segments:
24
+ - 'gweb'
25
+ - 'graph.php'
26
+ query:
25
27
  c: 'Oakley nodes'
28
+ opt_query:
29
+ h: '%{h}.ten.osc.edu'
26
30
  version: '3'
27
31
  ruby:
28
32
  title: 'Ruby'
@@ -49,10 +53,14 @@ v1:
49
53
  ganglia:
50
54
  type: 'OodAppkit::Servers::Ganglia'
51
55
  host: 'cts05.osc.edu'
52
- scheme: 'https'
53
- path: '/gweb/graph.php'
54
- query_values:
56
+ scheme: 'https://'
57
+ segments:
58
+ - 'gweb'
59
+ - 'graph.php'
60
+ query:
55
61
  c: 'Ruby'
62
+ opt_query:
63
+ h: '%{h}.ten.osc.edu'
56
64
  version: '3'
57
65
  quick:
58
66
  title: 'Quick'
@@ -65,8 +65,9 @@ module OodAppkit
65
65
  self.dataroot = ENV['OOD_DATAROOT'] || ENV['RAILS_DATAROOT']
66
66
 
67
67
  # Initialize list of available clusters
68
+ c_conf = ENV['OOD_CLUSTERS'] || ( OOD_CONFIG.join('clusters.yml') if OOD_CONFIG.join('clusters.yml').file? )
68
69
  self.clusters = OpenStruct.new
69
- clusters.all = OodAppkit::Cluster.all( ENV['OOD_CLUSTERS'] ? {file: ENV['OOD_CLUSTERS']} : {} )
70
+ clusters.all = OodAppkit::Cluster.all( c_conf ? {file: c_conf} : {} )
70
71
  def clusters.hpc
71
72
  all.select {|k,v| v.hpc_cluster?}
72
73
  end
@@ -2,41 +2,81 @@ module OodAppkit
2
2
  module Servers
3
3
  # This defines a Ganglia server and defining parameters
4
4
  class Ganglia < Server
5
- # The URI used to access information about given cluster
6
- # @return [Addressable] the uri for ganglia server
7
- attr_reader :uri
5
+ # Template used to describe URI
6
+ # @see https://www.rfc-editor.org/rfc/rfc6570.txt RFC describing template format
7
+ TEMPLATE = '{+scheme}{host}{/segments*}{?query*}'
8
+
9
+ # The scheme of the URI
10
+ # @example Scheme of SSL protocol
11
+ # "my_ganglia.scheme" #=> "https://"
12
+ # @return [String] scheme of uri
13
+ attr_reader :scheme
14
+
15
+ # The segments used to describe the path of the URI
16
+ # @example Segments for URI with path "/ganglia/gweb.php"
17
+ # "my_ganglia.segments"
18
+ # #=> ["ganglia", "gweb.php"]
19
+ # @return [Array<String>] segments of uri
20
+ attr_reader :segments
21
+
22
+ # The required query values of the URI
23
+ # @example Required cluster query value
24
+ # "my_ganglia.query"
25
+ # #=> {c: "MyCluster"}
26
+ # @return [Hash] required query values of uri
27
+ attr_reader :query
28
+
29
+ # Optional query values of the URI, these query values are
30
+ # only defined if specified
31
+ # @return [Hash] optional query values of uri
32
+ attr_reader :opt_query
8
33
 
9
34
  # The version of this software
10
35
  # @return [String] version of software
11
36
  attr_reader :version
12
37
 
13
- # @param scheme [String] scheme component of URI
14
- # @param path [String] path component of URI
15
- # @param query_values [Hash<String>] hash of query values
38
+ # @param scheme [String] the scheme used for URI
39
+ # @param segments [Array<String>] the segments used to
40
+ # construct path of URI
41
+ # @param query [Hash] hash of query values used for
42
+ # URI
43
+ # @param opt_query [Hash] hash of optional query
44
+ # values if they exist
16
45
  # @param version [String] version of server software
17
- def initialize(scheme:, path:, query_values: {}, version:, **kwargs)
46
+ def initialize(scheme:, segments: [], query: {}, opt_query: {}, version:, **kwargs)
18
47
  super(kwargs)
19
48
 
20
49
  # uri
21
- @uri = Addressable::URI.new({
22
- scheme: scheme,
23
- host: host,
24
- path: path,
25
- query_values: query_values
26
- })
50
+ @scheme = scheme
51
+ @segments = segments
52
+ @query = query
53
+ @opt_query = opt_query
27
54
 
28
- # version number
55
+ # version
29
56
  @version = version
30
57
  end
31
58
 
32
- # Merge a hash of query values into this URI
33
- # NB: This doesn't alter the original URI
34
- # @param new_query_values [Hash] hash of query values
35
- # @return [Addressable] new uri with merged query values
36
- def merge_query_values(new_query_values)
37
- uri.dup.tap do |u|
38
- u.query_values = (uri.query_values || {}).merge(new_query_values)
39
- end
59
+ # The full hash of query values used to construct URI
60
+ # @param other_query [Hash] user specified query hash
61
+ # @return [Hash] full hash of query values
62
+ def query_values(other_query)
63
+ query.merge(
64
+ other_query.each_with_object({}) do |(k, v), h|
65
+ h[k] = opt_query.has_key?(k) ? (opt_query[k] % query.merge(other_query)) : v
66
+ end
67
+ )
68
+ end
69
+
70
+ # The URI used to access information about given cluster
71
+ # @param query_values [Hash] user specified query hash
72
+ # @return [Addressable] the uri for ganglia server
73
+ def uri(query_values: {})
74
+ Addressable::Template.new(TEMPLATE).expand({
75
+ scheme: scheme,
76
+ host: host,
77
+ segments: segments,
78
+ query: query_values(query_values)
79
+ })
40
80
  end
41
81
  end
42
82
  end
@@ -1,4 +1,4 @@
1
1
  module OodAppkit
2
2
  # The current version of OodAppkit
3
- VERSION = "0.2.5"
3
+ VERSION = "0.2.6"
4
4
  end
data/lib/ood_appkit.rb CHANGED
@@ -15,6 +15,9 @@ require 'ood_appkit/server'
15
15
 
16
16
  # The main namespace for OodAppkit. Provides a global configuration.
17
17
  module OodAppkit
18
+ # Global OOD config location
19
+ OOD_CONFIG = Pathname.new '/etc/ood/config'
20
+
18
21
  extend Configuration
19
22
  require 'ood_appkit/engine' if defined?(Rails)
20
23
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ood_appkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Franz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-08 00:00:00.000000000 Z
11
+ date: 2016-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails