lds-cf-plugin 0.3.5 → 0.4.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.
- data/lib/lds-cf-plugin/app_dynamics_service.rb +51 -0
- data/lib/lds-cf-plugin/loggregator/client_config.rb +14 -0
- data/lib/lds-cf-plugin/loggregator/log_message.pb.rb +31 -0
- data/lib/lds-cf-plugin/loggregator/log_message.proto +22 -0
- data/lib/lds-cf-plugin/loggregator/log_message_extender.rb +15 -0
- data/lib/lds-cf-plugin/loggregator/logs.rb +44 -0
- data/lib/lds-cf-plugin/loggregator/message_writer.rb +18 -0
- data/lib/lds-cf-plugin/loggregator/tailling_logs_client.rb +101 -0
- data/lib/lds-cf-plugin/plugin.rb +2 -0
- data/lib/lds-cf-plugin/servicemanager_service.rb +3 -2
- data/lib/lds-cf-plugin/version.rb +1 -1
- metadata +45 -5
@@ -0,0 +1,51 @@
|
|
1
|
+
require "cf/cli"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
module LdsCfPlugin
|
5
|
+
class AppDynamicsService < CF::CLI
|
6
|
+
def precondition
|
7
|
+
check_target
|
8
|
+
end
|
9
|
+
|
10
|
+
desc "Create a App Dynamics Service"
|
11
|
+
group :lds, :services
|
12
|
+
input :name, :desc => "Name for your service", :argument => :optional
|
13
|
+
|
14
|
+
def create_app_dynamics_service
|
15
|
+
offerings = client.services
|
16
|
+
offerings.keep_if { |s| s.label == 'app-dynamics-service' && s.provider == 'ICS' }
|
17
|
+
service = offerings.first
|
18
|
+
|
19
|
+
if !service
|
20
|
+
fail "Cannot find App Dynamics service on #{client.target}"
|
21
|
+
end
|
22
|
+
|
23
|
+
if service.version != "0.1"
|
24
|
+
fail "Your lds-cf-plugin version is out of date. To update execute `gem update lds-cf-plugin`"
|
25
|
+
end
|
26
|
+
|
27
|
+
rest_client = CFoundry::RestClient.new(service.url, client.token)
|
28
|
+
rest_client.trace = client.trace
|
29
|
+
|
30
|
+
instance_name = input[:name]
|
31
|
+
if !instance_name
|
32
|
+
instance_name = ask("Name")
|
33
|
+
end
|
34
|
+
|
35
|
+
plan = service.service_plans.first
|
36
|
+
|
37
|
+
# Create service instance
|
38
|
+
instance = client.managed_service_instance
|
39
|
+
instance.name = instance_name
|
40
|
+
|
41
|
+
instance.service_plan = plan
|
42
|
+
instance.space = client.current_space
|
43
|
+
|
44
|
+
with_progress("Creating service #{c(instance.name, :name)}") do
|
45
|
+
instance.create!
|
46
|
+
end
|
47
|
+
|
48
|
+
instance
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module LogsCfPlugin
|
2
|
+
class ClientConfig
|
3
|
+
attr_reader :loggregator_host, :loggregator_port, :user_token, :output, :trace, :use_ssl
|
4
|
+
|
5
|
+
def initialize(loggregator_host, loggregator_port, user_token, output, trace, use_ssl = true)
|
6
|
+
@output = output
|
7
|
+
@loggregator_host = loggregator_host
|
8
|
+
@loggregator_port = loggregator_port
|
9
|
+
@user_token = user_token
|
10
|
+
@trace = trace
|
11
|
+
@use_ssl = use_ssl
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
## Generated from log_message.proto for logmessage
|
2
|
+
require "beefcake"
|
3
|
+
|
4
|
+
|
5
|
+
class LogMessage
|
6
|
+
include Beefcake::Message
|
7
|
+
|
8
|
+
module MessageType
|
9
|
+
OUT = 1
|
10
|
+
ERR = 2
|
11
|
+
end
|
12
|
+
|
13
|
+
required :message, :bytes, 1
|
14
|
+
required :message_type, LogMessage::MessageType, 2
|
15
|
+
required :timestamp, :sint64, 3
|
16
|
+
required :app_id, :string, 4
|
17
|
+
optional :source_id, :string, 6
|
18
|
+
repeated :drain_urls, :string, 7
|
19
|
+
optional :source_name, :string, 8
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
class LogEnvelope
|
24
|
+
include Beefcake::Message
|
25
|
+
|
26
|
+
|
27
|
+
required :routing_key, :string, 1
|
28
|
+
required :signature, :bytes, 2
|
29
|
+
required :log_message, LogMessage, 3
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
package logmessage;
|
2
|
+
|
3
|
+
message LogMessage {
|
4
|
+
enum MessageType {
|
5
|
+
OUT = 1;
|
6
|
+
ERR = 2;
|
7
|
+
}
|
8
|
+
|
9
|
+
required bytes message = 1;
|
10
|
+
required MessageType message_type = 2;
|
11
|
+
required sint64 timestamp = 3;
|
12
|
+
required string app_id = 4;
|
13
|
+
optional string source_id = 6;
|
14
|
+
repeated string drain_urls = 7;
|
15
|
+
optional string source_name = 8;
|
16
|
+
}
|
17
|
+
|
18
|
+
message LogEnvelope {
|
19
|
+
required string routing_key = 1;
|
20
|
+
required bytes signature = 2;
|
21
|
+
required LogMessage log_message = 3;
|
22
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class LogMessage
|
2
|
+
def message_type_name
|
3
|
+
{MessageType::OUT => "OUT", MessageType::ERR => "ERR"}[message_type]
|
4
|
+
end
|
5
|
+
|
6
|
+
def time=(time)
|
7
|
+
self.timestamp = (time.tv_sec * 1000000000) + time.tv_nsec
|
8
|
+
end
|
9
|
+
|
10
|
+
def time
|
11
|
+
num_secs = @timestamp / 1000000000
|
12
|
+
fractional_usecs = (@timestamp % 1000000000).to_f / 1000
|
13
|
+
Time.at(num_secs, fractional_usecs)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'cf'
|
2
|
+
require 'eventmachine'
|
3
|
+
require 'faye/websocket'
|
4
|
+
require 'uri'
|
5
|
+
|
6
|
+
module LogsCfPlugin
|
7
|
+
require 'lds-cf-plugin/loggregator/message_writer'
|
8
|
+
require 'lds-cf-plugin/loggregator/client_config'
|
9
|
+
require 'lds-cf-plugin/loggregator/tailling_logs_client'
|
10
|
+
|
11
|
+
class Plugin < CF::CLI
|
12
|
+
include LoginRequirements
|
13
|
+
include MessageWriter
|
14
|
+
|
15
|
+
desc "Tail or dump logs for CF applications"
|
16
|
+
group :lds, :diagnostics
|
17
|
+
input :app, :desc => "App to tail logs from", :argument => :optional, :from_given => by_name(:app)
|
18
|
+
input :recent, :type => :boolean, :desc => "Dump recent logs instead of tailing", :default => false
|
19
|
+
|
20
|
+
def logs
|
21
|
+
client.current_organization.name # resolve org name so CC will validate AuthToken
|
22
|
+
|
23
|
+
unless input[:app]
|
24
|
+
Mothership::Help.command_help(@@commands[:logs])
|
25
|
+
fail "Please provide an application to log."
|
26
|
+
end
|
27
|
+
port = input[:recent] ? nil : 4443
|
28
|
+
client_config = ClientConfig.new(loggregator_host, port, client.token.auth_header, STDOUT, input[:trace], use_ssl)
|
29
|
+
|
30
|
+
TailingLogsClient.new(client_config).logs_for(input[:app], input[:recent])
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def loggregator_host
|
36
|
+
target_base = client.target.sub(/^https?:\/\/([^\.]+\.)?(.+)\/?/, '\2')
|
37
|
+
"loggregator.#{target_base}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def use_ssl
|
41
|
+
client.target.start_with?('https')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "cf/cli"
|
2
|
+
require "lds-cf-plugin/loggregator/log_message_extender"
|
3
|
+
|
4
|
+
module MessageWriter
|
5
|
+
include CF::Interactive
|
6
|
+
|
7
|
+
def write(app, output, message)
|
8
|
+
msg = [format_time(message.time), "#{message.source_name}/#{message.source_id}", message.message_type_name, message.message].join(" ")
|
9
|
+
msg = c(msg.chomp, :error) if message.message_type == LogMessage::MessageType::ERR
|
10
|
+
output.puts(msg)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def format_time(time)
|
16
|
+
time.strftime("%b %d %H:%M:%S.%3N")
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require "lds-cf-plugin/loggregator/log_message.pb"
|
2
|
+
require "lds-cf-plugin/loggregator/log_message_extender"
|
3
|
+
|
4
|
+
module LogsCfPlugin
|
5
|
+
class TailingLogsClient
|
6
|
+
#include CFoundry::TraceHelpers
|
7
|
+
include MessageWriter
|
8
|
+
|
9
|
+
def initialize(config)
|
10
|
+
@config = config
|
11
|
+
end
|
12
|
+
|
13
|
+
def logs_for(app, recent)
|
14
|
+
protocol = use_ssl ? "wss" : "ws"
|
15
|
+
websocket_address = "#{protocol}://#{loggregator_host}#{loggregator_port ? ":#{loggregator_port}" : ""}/#{recent ? 'dump' : 'tail'}/?app=#{app.guid}"
|
16
|
+
|
17
|
+
output.puts "websocket_address: #{websocket_address}" if trace
|
18
|
+
|
19
|
+
make_websocket_request(app, websocket_address)
|
20
|
+
end
|
21
|
+
|
22
|
+
def make_websocket_request(app, websocket_address)
|
23
|
+
redirect_uri = nil
|
24
|
+
@em_client_thread = Thread.new do
|
25
|
+
EM.run {
|
26
|
+
ws = Faye::WebSocket::Client.new(websocket_address, nil, :headers => {"Origin" => "http://localhost", "Authorization" => user_token})
|
27
|
+
ws.on :open do |event|
|
28
|
+
output.puts("Connected to server.")
|
29
|
+
EventMachine.add_periodic_timer(keep_alive_interval) do
|
30
|
+
ws.send("I'm alive!")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
ws.on :message do |event|
|
35
|
+
begin
|
36
|
+
received_message = LogMessage.decode(event.data.pack("C*"))
|
37
|
+
write(app, output, received_message)
|
38
|
+
rescue Exception => e
|
39
|
+
output.puts e.message
|
40
|
+
output.puts e.backtrace
|
41
|
+
output.puts("Error parsing loggregator data. Please make sure you have the latest lds-cf-plugin.")
|
42
|
+
ws.close
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
ws.on :error do |event|
|
47
|
+
if !redirect_uri
|
48
|
+
if event.current_target.status == 302
|
49
|
+
redirect_uri = event.current_target.headers["location"]
|
50
|
+
ws.close
|
51
|
+
@em_client_thread.kill
|
52
|
+
ws = nil
|
53
|
+
else
|
54
|
+
output.puts("Server error: #{websocket_address}")
|
55
|
+
output.puts(event.data.inspect) if trace
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
ws.on :close do |event|
|
61
|
+
unless redirect_uri
|
62
|
+
ws.close
|
63
|
+
case event.code
|
64
|
+
when 4000
|
65
|
+
output.puts("Error: No space given.")
|
66
|
+
when 4001
|
67
|
+
output.puts("Error: No authorization token given.")
|
68
|
+
when 4002
|
69
|
+
output.puts("Error: Not authorized.")
|
70
|
+
end
|
71
|
+
output.puts("Server connection closed.")
|
72
|
+
@em_client_thread.kill
|
73
|
+
ws = nil
|
74
|
+
end
|
75
|
+
end
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
79
|
+
wait_for_em_thread_to_finish
|
80
|
+
|
81
|
+
make_websocket_request(app, redirect_uri) if redirect_uri
|
82
|
+
end
|
83
|
+
|
84
|
+
def wait_for_em_thread_to_finish
|
85
|
+
while @em_client_thread.alive? do
|
86
|
+
sleep 0.1
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
attr_reader :config
|
93
|
+
|
94
|
+
delegate :output, :loggregator_host, :loggregator_port, :user_token, :trace, :use_ssl,
|
95
|
+
to: :config
|
96
|
+
|
97
|
+
def keep_alive_interval
|
98
|
+
25
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
data/lib/lds-cf-plugin/plugin.rb
CHANGED
@@ -6,6 +6,7 @@ Mothership::Help.groups(
|
|
6
6
|
[:diagnostics, "Diagnostics"]]
|
7
7
|
)
|
8
8
|
|
9
|
+
require "lds-cf-plugin/app_dynamics_service"
|
9
10
|
require "lds-cf-plugin/custom_service"
|
10
11
|
require "lds-cf-plugin/oracle_service"
|
11
12
|
require "lds-cf-plugin/lds_account_service"
|
@@ -14,3 +15,4 @@ require "lds-cf-plugin/wam_service"
|
|
14
15
|
require "lds-cf-plugin/servicemanager_service"
|
15
16
|
require "lds-cf-plugin/marklogic_service"
|
16
17
|
require "lds-cf-plugin/tunnel"
|
18
|
+
require "lds-cf-plugin/loggregator/logs"
|
@@ -80,7 +80,7 @@ module LdsCfPlugin
|
|
80
80
|
end
|
81
81
|
|
82
82
|
prexisting = input[:prexisting]
|
83
|
-
prexisting = ask("Use existing Service Manager
|
83
|
+
prexisting = ask("Use existing Service Manager CI for '#{sm_app_name} - #{env}'?", :default => true) if !prexisting
|
84
84
|
|
85
85
|
if prexisting
|
86
86
|
payload = {
|
@@ -137,7 +137,8 @@ module LdsCfPlugin
|
|
137
137
|
:SuuportContactReason => "Primary Contact",
|
138
138
|
:PortfolioId => portfolioId,
|
139
139
|
:RegStandards => "None",
|
140
|
-
:SystemRiskLevel => "Low Risk"
|
140
|
+
:SystemRiskLevel => "Low Risk",
|
141
|
+
:prexisting => false
|
141
142
|
}
|
142
143
|
end
|
143
144
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lds-cf-plugin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-01-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cf
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - '='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 5.4.
|
21
|
+
version: 5.4.5
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - '='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 5.4.
|
29
|
+
version: 5.4.5
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: eventmachine
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,6 +59,38 @@ dependencies:
|
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '1.6'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: beefcake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.3.7
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 0.3.7
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: faye-websocket
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 0.6.1
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 0.6.1
|
62
94
|
description:
|
63
95
|
email:
|
64
96
|
- heathma@ldschurch.org
|
@@ -75,10 +107,18 @@ files:
|
|
75
107
|
- lib/lds-cf-plugin/tunnel.rb
|
76
108
|
- lib/lds-cf-plugin/version.rb
|
77
109
|
- lib/lds-cf-plugin/plugin.rb
|
110
|
+
- lib/lds-cf-plugin/app_dynamics_service.rb
|
111
|
+
- lib/lds-cf-plugin/loggregator/log_message_extender.rb
|
112
|
+
- lib/lds-cf-plugin/loggregator/tailling_logs_client.rb
|
113
|
+
- lib/lds-cf-plugin/loggregator/client_config.rb
|
114
|
+
- lib/lds-cf-plugin/loggregator/log_message.pb.rb
|
115
|
+
- lib/lds-cf-plugin/loggregator/message_writer.rb
|
116
|
+
- lib/lds-cf-plugin/loggregator/logs.rb
|
117
|
+
- lib/lds-cf-plugin/loggregator/log_message.proto
|
78
118
|
- lib/lds-cf-plugin/tunnel/tunnelclient.rb
|
79
119
|
- lib/lds-cf-plugin/wam_service.rb
|
80
120
|
- lib/lds-cf-plugin/servicemanager_service.rb
|
81
|
-
homepage:
|
121
|
+
homepage: https://cf.lds.org/
|
82
122
|
licenses: []
|
83
123
|
post_install_message:
|
84
124
|
rdoc_options: []
|