falcore 0.1.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.
@@ -0,0 +1,118 @@
1
+ #
2
+ # Author: Seth Vargo <sethvargo@gmail.com>
3
+ #
4
+ # Copyright 2014 Chef Software, Inc.
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
+
19
+ module Falcore
20
+ class Node::Base
21
+ def initialize(data = {})
22
+ @data = data.dup
23
+ end
24
+
25
+ #
26
+ # The unique ID for this node. This is the {display_name}, but any dots
27
+ # (+.+) are substituted with dashes (+-+), because dots are the delimiters
28
+ # for StatsD and other common dumpers.
29
+ #
30
+ # @return [String]
31
+ #
32
+ def id
33
+ "jenkins.#{display_name.gsub(/\./, '-')}"
34
+ end
35
+
36
+ # @return [String]
37
+ def display_name
38
+ @data['displayName']
39
+ end
40
+
41
+ # @return [true, false]
42
+ def idle?
43
+ !!@data['idle']
44
+ end
45
+
46
+ # @return [Integer]
47
+ def executors
48
+ @data['numExecutors'].to_i
49
+ end
50
+
51
+ # @return [true, false]
52
+ def offline?
53
+ !!@data['offline']
54
+ end
55
+
56
+ # @return [true, false]
57
+ def temporarily_offline?
58
+ !!@data['temporarilyOffline']
59
+ end
60
+
61
+ # @return [Integer]
62
+ def response_time
63
+ Util.deep_fetch(@data, 'monitorData',
64
+ 'hudson.node_monitors.ResponseTimeMonitor', 'average').to_f
65
+ end
66
+
67
+ # @return [Integer]
68
+ def temporary_space
69
+ Util.deep_fetch(@data, 'monitorData',
70
+ 'hudson.node_monitors.TemporarySpaceMonitor', 'size').to_i
71
+ end
72
+
73
+ # @return [Integer]
74
+ def disk_space
75
+ Util.deep_fetch(@data, 'monitorData',
76
+ 'hudson.node_monitors.DiskSpaceMonitor', 'size').to_i
77
+ end
78
+
79
+ # @return [Integer]
80
+ def free_memory
81
+ Util.deep_fetch(@data, 'monitorData',
82
+ 'hudson.node_monitors.SwapSpaceMonitor', 'availablePhysicalMemory').to_i
83
+ end
84
+
85
+ # @return [Integer]
86
+ def total_memory
87
+ Util.deep_fetch(@data, 'monitorData',
88
+ 'hudson.node_monitors.SwapSpaceMonitor', 'totalPhysicalMemory').to_i
89
+ end
90
+
91
+ # @return [Integer]
92
+ def free_swap
93
+ Util.deep_fetch(@data, 'monitorData',
94
+ 'hudson.node_monitors.SwapSpaceMonitor', 'availableSwapSpace').to_i
95
+ end
96
+
97
+ # @return [Integer]
98
+ def total_swap
99
+ Util.deep_fetch(@data, 'monitorData',
100
+ 'hudson.node_monitors.SwapSpaceMonitor', 'totalSwapSpace').to_i
101
+ end
102
+
103
+ # @private
104
+ def to_s
105
+ "#<#{self.class}>"
106
+ end
107
+
108
+ # @private
109
+ def inspect
110
+ list = Node::Base.public_instance_methods(false)
111
+ .reject { |name| [:to_s, :inspect].include?(name) }
112
+ .sort
113
+ .map { |name| "#{name}: #{public_send(name).inspect}" }
114
+
115
+ "#<#{self.class} #{list.join(', ')}>"
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,48 @@
1
+ #
2
+ # Author: Seth Vargo <sethvargo@gmail.com>
3
+ #
4
+ # Copyright 2014 Chef Software, Inc.
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
+
19
+ module Falcore
20
+ class Node::Master < Node::Base
21
+ #
22
+ # @param data (see Node::Base#initialize)
23
+ #
24
+ def initialize(data = {})
25
+ super(data)
26
+ @slaves = {}
27
+ end
28
+
29
+ #
30
+ # @param [Node::Slave] slave
31
+ #
32
+ def add_slave(slave)
33
+ unless slave.is_a?(Node::Slave)
34
+ raise ArgumentError, "#{slave.class} is not an Falcore::Node::Slave"
35
+ end
36
+
37
+ @slaves[slave.id] = slave
38
+ self
39
+ end
40
+
41
+ #
42
+ # @return [Array<Node::Slave>]
43
+ #
44
+ def slaves
45
+ @slaves.values
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,48 @@
1
+ #
2
+ # Author: Seth Vargo <sethvargo@gmail.com>
3
+ #
4
+ # Copyright 2014 Chef Software, Inc.
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
+
19
+ module Falcore
20
+ class Node::Slave < Node::Base
21
+ # @return [Node::Master]
22
+ attr_reader :master
23
+
24
+ #
25
+ # @param [Node::Master] master
26
+ # @param data (see Node::Base#initialize)
27
+ #
28
+ def initialize(master, data = {})
29
+ super(data)
30
+
31
+ unless master.is_a?(Node::Master)
32
+ raise ArgumentError, "#{master.class} is not an Falcore::Node::Master!"
33
+ end
34
+
35
+ @master = master
36
+ @master.add_slave(self)
37
+ end
38
+
39
+ #
40
+ # Namespace the slave under it's master.
41
+ #
42
+ # @return (see Base#id)
43
+ #
44
+ def id
45
+ "#{@master.id}.#{display_name.gsub(/\./, '-')}"
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,56 @@
1
+ #
2
+ # Author: Seth Vargo <sethvargo@gmail.com>
3
+ #
4
+ # Copyright 2014 Chef Software, Inc.
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
+
19
+ module Falcore
20
+ class NullObject < BasicObject
21
+ ARRAY = []
22
+ INTEGER = 0
23
+ FLOAT = 0.0
24
+ STRING = ''
25
+ INSPECT = 'nil'
26
+
27
+ def nil?
28
+ true
29
+ end
30
+ alias_method :empty?, :nil?
31
+
32
+ def to_a
33
+ ARRAY.dup
34
+ end
35
+
36
+ def to_i
37
+ INTEGER
38
+ end
39
+
40
+ def to_f
41
+ FLOAT
42
+ end
43
+
44
+ def to_s
45
+ STRING.dup
46
+ end
47
+
48
+ def inspect
49
+ INSPECT.dup
50
+ end
51
+
52
+ def method_missing(m, *args, &block)
53
+ self
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,39 @@
1
+ #
2
+ # Author: Seth Vargo <sethvargo@gmail.com>
3
+ #
4
+ # Copyright 2014 Chef Software, Inc.
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
+
19
+ module Falcore
20
+ module Util
21
+ extend self
22
+
23
+ #
24
+ # Deeply fech the nested keys, returning +nil+ if an item along the
25
+ # pathway returns +nil+.
26
+ #
27
+ # @param [Hash] hash
28
+ # the hash to deep fetch
29
+ # @param [Array] keys
30
+ # the list of keys to fetch (in order)
31
+ #
32
+ def deep_fetch(hash = {}, *keys)
33
+ keys.inject(hash.dup) do |hash, key|
34
+ return nil if hash.nil?
35
+ hash[key]
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,21 @@
1
+ #
2
+ # Author: Seth Vargo <sethvargo@gmail.com>
3
+ #
4
+ # Copyright 2014 Chef Software, Inc.
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
+
19
+ module Falcore
20
+ VERSION = '0.1.0'
21
+ end
@@ -0,0 +1,180 @@
1
+ {
2
+ "busyExecutors": 0,
3
+ "computer": [
4
+ {
5
+ "actions": [],
6
+ "displayName": "master.jenkins.example.com",
7
+ "executors": [
8
+ {},
9
+ {}
10
+ ],
11
+ "icon": "computer.png",
12
+ "idle": true,
13
+ "jnlpAgent": false,
14
+ "launchSupported": true,
15
+ "loadStatistics": {
16
+ },
17
+ "manualLaunchAllowed": true,
18
+ "monitorData": {
19
+ "hudson.node_monitors.SwapSpaceMonitor": {
20
+ "availablePhysicalMemory": 1977520128,
21
+ "availableSwapSpace": 0,
22
+ "totalPhysicalMemory": 8374779904,
23
+ "totalSwapSpace": 0
24
+ },
25
+ "hudson.node_monitors.ArchitectureMonitor": "Linux (amd64)",
26
+ "hudson.node_monitors.ResponseTimeMonitor": {
27
+ "average": 0
28
+ },
29
+ "hudson.node_monitors.TemporarySpaceMonitor": {
30
+ "path": "/tmp",
31
+ "size": 72230727680
32
+ },
33
+ "hudson.node_monitors.DiskSpaceMonitor": {
34
+ "path": "/var/lib/jenkins",
35
+ "size": 72230727680
36
+ },
37
+ "hudson.node_monitors.ClockMonitor": {
38
+ "diff": 0
39
+ }
40
+ },
41
+ "numExecutors": 2,
42
+ "offline": false,
43
+ "offlineCause": null,
44
+ "offlineCauseReason": "",
45
+ "oneOffExecutors": [],
46
+ "temporarilyOffline": false
47
+ },
48
+ {
49
+ "actions": [],
50
+ "displayName": "slave1.jenkins.example.com",
51
+ "executors": [
52
+ {}
53
+ ],
54
+ "icon": "computer.png",
55
+ "idle": true,
56
+ "jnlpAgent": true,
57
+ "launchSupported": false,
58
+ "loadStatistics": {
59
+ },
60
+ "manualLaunchAllowed": true,
61
+ "monitorData": {
62
+ "hudson.node_monitors.SwapSpaceMonitor": {
63
+ "availablePhysicalMemory": 1072775168,
64
+ "availableSwapSpace": 0,
65
+ "totalPhysicalMemory": 4152627200,
66
+ "totalSwapSpace": 0
67
+ },
68
+ "hudson.node_monitors.ArchitectureMonitor": "Linux (amd64)",
69
+ "hudson.node_monitors.ResponseTimeMonitor": {
70
+ "average": 30
71
+ },
72
+ "hudson.node_monitors.TemporarySpaceMonitor": {
73
+ "path": "/tmp",
74
+ "size": 16421466112
75
+ },
76
+ "hudson.node_monitors.DiskSpaceMonitor": {
77
+ "path": "/home/jenkins",
78
+ "size": 16421466112
79
+ },
80
+ "hudson.node_monitors.ClockMonitor": {
81
+ "diff": 4
82
+ }
83
+ },
84
+ "numExecutors": 1,
85
+ "offline": false,
86
+ "offlineCause": null,
87
+ "offlineCauseReason": "",
88
+ "oneOffExecutors": [],
89
+ "temporarilyOffline": false
90
+ },
91
+ {
92
+ "actions": [],
93
+ "displayName": "slave2.jenkins.example.com",
94
+ "executors": [
95
+ {}
96
+ ],
97
+ "icon": "computer.png",
98
+ "idle": true,
99
+ "jnlpAgent": true,
100
+ "launchSupported": false,
101
+ "loadStatistics": {
102
+ },
103
+ "manualLaunchAllowed": true,
104
+ "monitorData": {
105
+ "hudson.node_monitors.SwapSpaceMonitor": {
106
+ "availablePhysicalMemory": 1197740032,
107
+ "availableSwapSpace": 0,
108
+ "totalPhysicalMemory": 4152627200,
109
+ "totalSwapSpace": 0
110
+ },
111
+ "hudson.node_monitors.ArchitectureMonitor": "Linux (amd64)",
112
+ "hudson.node_monitors.ResponseTimeMonitor": {
113
+ "average": 9
114
+ },
115
+ "hudson.node_monitors.TemporarySpaceMonitor": {
116
+ "path": "/tmp",
117
+ "size": 19061014528
118
+ },
119
+ "hudson.node_monitors.DiskSpaceMonitor": {
120
+ "path": "/home/jenkins",
121
+ "size": 19061014528
122
+ },
123
+ "hudson.node_monitors.ClockMonitor": {
124
+ "diff": 34
125
+ }
126
+ },
127
+ "numExecutors": 1,
128
+ "offline": false,
129
+ "offlineCause": null,
130
+ "offlineCauseReason": "",
131
+ "oneOffExecutors": [],
132
+ "temporarilyOffline": false
133
+ },
134
+ {
135
+ "actions": [],
136
+ "displayName": "slave3.jenkins.example.com",
137
+ "executors": [
138
+ {}
139
+ ],
140
+ "icon": "computer.png",
141
+ "idle": true,
142
+ "jnlpAgent": true,
143
+ "launchSupported": false,
144
+ "loadStatistics": {
145
+ },
146
+ "manualLaunchAllowed": true,
147
+ "monitorData": {
148
+ "hudson.node_monitors.SwapSpaceMonitor": {
149
+ "availablePhysicalMemory": -1,
150
+ "availableSwapSpace": 1038090240,
151
+ "totalPhysicalMemory": -1,
152
+ "totalSwapSpace": 1074790400
153
+ },
154
+ "hudson.node_monitors.ArchitectureMonitor": "Mac OS X (x86_64)",
155
+ "hudson.node_monitors.ResponseTimeMonitor": {
156
+ "average": 23
157
+ },
158
+ "hudson.node_monitors.TemporarySpaceMonitor": {
159
+ "path": "/private/var/folders/4p/tv3nqk6j1gg19vhb6slz6dpw00007h/T",
160
+ "size": 15131881472
161
+ },
162
+ "hudson.node_monitors.DiskSpaceMonitor": {
163
+ "path": "/Users/jenkins",
164
+ "size": 15131881472
165
+ },
166
+ "hudson.node_monitors.ClockMonitor": {
167
+ "diff": 7812
168
+ }
169
+ },
170
+ "numExecutors": 1,
171
+ "offline": false,
172
+ "offlineCause": null,
173
+ "offlineCauseReason": "",
174
+ "oneOffExecutors": [],
175
+ "temporarilyOffline": false
176
+ }
177
+ ],
178
+ "displayName": "nodes",
179
+ "totalExecutors": 14
180
+ }