cf_light_api 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cf_light_api/lib.rb +13 -0
- data/lib/cf_light_api/worker.rb +15 -15
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c695feed1d26f00127af6fac5fb24de9d64e0b56
|
4
|
+
data.tar.gz: 42228f7a1efecd0f66f4f3ac0a1f31ad8de6d734
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a412171a1799c8797bcd53e064cdad186154c42ab01d2bf46145b15f2d56ac9b3fbb6303f9140546478bbfc48e9bcba0d832b777b26ae280850acf15222772e
|
7
|
+
data.tar.gz: 5de6fde920e3ad043ed7673a8fe0b70500665e377f076b1844a1f053b6c004180a95e87943a9c8f3fe028fedc525325e2ce51567db6f6463b5036ed4f57da00a
|
data/lib/cf_light_api/lib.rb
CHANGED
@@ -58,3 +58,16 @@ def format_duration(elapsed_seconds)
|
|
58
58
|
hours = elapsed_seconds / (60 * 60)
|
59
59
|
format("%02d hrs, %02d mins, %02d secs", hours, minutes, seconds)
|
60
60
|
end
|
61
|
+
|
62
|
+
def format_routes_for_app app
|
63
|
+
routes = cf_rest app['entity']['routes_url']
|
64
|
+
routes.collect do |route|
|
65
|
+
host = route['entity']['host']
|
66
|
+
path = route['entity']['path']
|
67
|
+
|
68
|
+
domain = @domains.find{|a_domain| a_domain['metadata']['guid'] == route['entity']['domain_guid']}
|
69
|
+
domain = domain['entity']['name']
|
70
|
+
|
71
|
+
"#{host}.#{domain}#{path}"
|
72
|
+
end
|
73
|
+
end
|
data/lib/cf_light_api/worker.rb
CHANGED
@@ -63,6 +63,7 @@ scheduler.every UPDATE_INTERVAL, :first_in => '5s', :overlap => false, :timeout
|
|
63
63
|
@quotas = cf_rest('/v2/quota_definitions?results-per-page=100')
|
64
64
|
@spaces = cf_rest('/v2/spaces?results-per-page=100')
|
65
65
|
@stacks = cf_rest('/v2/stacks?results-per-page=100')
|
66
|
+
@domains = cf_rest('/v2/domains?results-per-page=100')
|
66
67
|
|
67
68
|
formatted_orgs = @orgs.map do |org|
|
68
69
|
quota = @quotas.find{|a_quota| a_quota['metadata']['guid'] == org['entity']['quota_definition_guid']}
|
@@ -81,38 +82,39 @@ scheduler.every UPDATE_INTERVAL, :first_in => '5s', :overlap => false, :timeout
|
|
81
82
|
|
82
83
|
formatted_apps = @apps.map do |app|
|
83
84
|
# TODO: This is a bit repetative, could maybe improve?
|
84
|
-
space
|
85
|
-
org
|
86
|
-
stack
|
85
|
+
space = @spaces.find{|a_space| a_space['metadata']['guid'] == app['entity']['space_guid']}
|
86
|
+
org = @orgs.find{|an_org| an_org['metadata']['guid'] == space['entity']['organization_guid']}
|
87
|
+
stack = @stacks.find{|a_stack| a_stack['metadata']['guid'] == app['entity']['stack_guid']}
|
88
|
+
routes = format_routes_for_app(app)
|
87
89
|
|
88
90
|
running = (app['entity']['state'] == "STARTED")
|
89
91
|
|
90
92
|
base_data = {
|
93
|
+
:buildpack => app['entity']['buildpack'],
|
94
|
+
:data_from => Time.now.to_i,
|
95
|
+
:diego => app['entity']['diego'],
|
96
|
+
:docker => app['entity']['docker_image'] ? true : false,
|
97
|
+
:docker_image => app['entity']['docker_image'],
|
91
98
|
:guid => app['metadata']['guid'],
|
99
|
+
:last_uploaded => app['metadata']['updated_at'] ? DateTime.parse(app['metadata']['updated_at']).strftime('%Y-%m-%d %T %z') : nil,
|
92
100
|
:name => app['entity']['name'],
|
93
101
|
:org => org['entity']['name'],
|
102
|
+
:routes => routes,
|
94
103
|
:space => space['entity']['name'],
|
95
104
|
:stack => stack['entity']['name'],
|
96
|
-
:
|
97
|
-
:data_from => Time.now.to_i,
|
98
|
-
:last_uploaded => app['metadata']['updated_at'] ? DateTime.parse(app['metadata']['updated_at']).strftime('%Y-%m-%d %T %z') : nil
|
105
|
+
:state => app['entity']['state']
|
99
106
|
}
|
100
107
|
|
101
|
-
# Add additional data, such as instance usage statistics
|
102
|
-
# if the instance is running.
|
108
|
+
# Add additional data, such as instance usage statistics - but this is only possible if the instances are running.
|
103
109
|
additional_data = {}
|
104
110
|
|
105
111
|
begin
|
106
112
|
instance_stats = []
|
107
|
-
routes = []
|
108
113
|
if running
|
109
|
-
# Finds the first running app instance that has a set of routes, in case there are stopped/crashed app instances that don't have any routes.
|
110
114
|
instance_stats = formatted_instance_stats_for_app(app)
|
111
115
|
running_instances = instance_stats.select{|instance| instance['stats']['uris'] if instance['state'] == 'RUNNING'}
|
112
|
-
raise "
|
116
|
+
raise "There are no running instances of this app." if running_instances.empty?
|
113
117
|
|
114
|
-
routes = running_instances.first['stats']['uris']
|
115
|
-
|
116
118
|
if @graphite
|
117
119
|
send_instance_usage_data_to_graphite(instance_stats, org['entity']['name'], space['entity']['name'], app['entity']['name'])
|
118
120
|
end
|
@@ -121,7 +123,6 @@ scheduler.every UPDATE_INTERVAL, :first_in => '5s', :overlap => false, :timeout
|
|
121
123
|
additional_data = {
|
122
124
|
:running => running,
|
123
125
|
:instances => instance_stats,
|
124
|
-
:routes => routes,
|
125
126
|
:error => nil
|
126
127
|
}
|
127
128
|
|
@@ -133,7 +134,6 @@ scheduler.every UPDATE_INTERVAL, :first_in => '5s', :overlap => false, :timeout
|
|
133
134
|
additional_data = {
|
134
135
|
:running => 'error',
|
135
136
|
:instances => [],
|
136
|
-
:routes => [],
|
137
137
|
:error => e.message
|
138
138
|
}
|
139
139
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cf_light_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Springer Platform Engineering
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cfoundry
|