lita-marathon 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5b116dd6ad9177e39b022baa8fdad0076d5f0f04
4
+ data.tar.gz: 31d21ab80e7779a07197d3ca6862af6cd24c782e
5
+ SHA512:
6
+ metadata.gz: 407d1123439c3bd2e314cc01d2ec9550ce70044077ede2d1d84d79f76aa83cbb362e5dd7750163b8cd96b19d29613d328a2712c6eb047a5c55b6ad1b517c6654
7
+ data.tar.gz: b7ce7ceebe10cc786c8a6ea30704a248bd9d8f817e42ef7f59c73a73c07558029d907e1fa54afa354edfd3ac8c1546c72dab39d56fc2e8d412fc876650cd0812
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Nicholas Silva
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # lita-marathon
2
+
3
+ Interact with the Marathon API for your Mesos cluster
4
+
5
+ ## Installation
6
+
7
+ Add lita-marathon to your Lita instance's Gemfile:
8
+
9
+ ``` ruby
10
+ gem "lita-marathon"
11
+ ```
12
+
13
+ ## Configuration
14
+
15
+ ### Required Configuration
16
+
17
+ ``` ruby
18
+ config.handlers.marathon.url = "http://example.com"
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ ```
24
+ m(arathon) list <filter> # List apps
25
+ m(arathon) count <filter> # Show instance counts
26
+ m(arathon) (force-)restart <filter> # Restart apps
27
+ m(arathon) (force-)suspend <filter> # Suspend apps
28
+ m(arathon) (force-)scale <filter> <instances> # Scale apps
29
+ ```
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,12 @@
1
+ require "lita"
2
+
3
+ Lita.load_locales Dir[File.expand_path(
4
+ File.join("..", "..", "locales", "*.yml"), __FILE__
5
+ )]
6
+
7
+ require "lita/handlers/marathon"
8
+
9
+ Lita::Handlers::Marathon.template_root File.expand_path(
10
+ File.join("..", "..", "templates"),
11
+ __FILE__
12
+ )
@@ -0,0 +1,76 @@
1
+ require 'marathon'
2
+
3
+ module Lita
4
+ module Handlers
5
+ class Marathon < Handler
6
+ # insert handler code here
7
+ config :url, type: String, required: true
8
+
9
+ route(/m(?:arathon)? list(?: (\S+))?/i,
10
+ :list_apps,
11
+ command: true,
12
+ restrict_to: [:deployers],
13
+ help: {
14
+ "m(arathon) list <filter>" => t("help.list")
15
+ })
16
+
17
+ route(/m(?:arathon)? count(?: (\S+))?/i,
18
+ :count_apps,
19
+ command: true,
20
+ restrict_to: [:deployers],
21
+ help: {
22
+ "m(arathon) count <filter>" => t("help.count")
23
+ })
24
+
25
+ route(/m(?:arathon)? (force-)?(restart|suspend|scale) (\S+)(?: (\d+))?/i,
26
+ :change_apps,
27
+ command: true,
28
+ restrict_to: [:deployers],
29
+ help: {
30
+ "m(arathon) (force-)restart <filter>" => t("help.restart"),
31
+ "m(arathon) (force-)suspend <filter>" => t("help.suspend"),
32
+ "m(arathon) (force-)scale <filter> <instances>" => t("help.scale")
33
+ })
34
+
35
+ def list_apps response
36
+ filter = response.matches.flatten.first
37
+ apps = ::Marathon::App.list(nil, nil, filter)
38
+ response.reply render_template("list_apps", apps: apps)
39
+ end
40
+
41
+ def count_apps response
42
+ filter = response.matches.flatten.first
43
+ apps = ::Marathon::App.list(nil, "apps.taskStats", filter)
44
+ response.reply render_template("count_apps", apps: apps)
45
+ end
46
+
47
+ def change_apps response
48
+ force, command, filter, instances = response.matches.flatten
49
+ list = ::Marathon::App.list(nil, nil, filter)
50
+ response.reply t("response.no_apps") if list.empty?
51
+ list.each do |app|
52
+ begin
53
+ case command
54
+ when "restart"
55
+ app.restart!(force)
56
+ when "suspend"
57
+ app.suspend!(force)
58
+ when "scale"
59
+ app.scale!(instances.to_i, force)
60
+ else
61
+ end
62
+ response.reply render_template("change_app", command: command, app: app.id, instances: instances)
63
+ rescue ::Marathon::Error::UnexpectedResponseError => e
64
+ response.reply t("error.unexpected_response", app: app.id)
65
+ end
66
+ end
67
+ end
68
+
69
+ on :connected do
70
+ ::Marathon.url = config.url
71
+ end
72
+
73
+ Lita.register_handler(self)
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,25 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "lita-marathon"
3
+ spec.version = "0.1.0"
4
+ spec.authors = ["Nicholas Silva"]
5
+ spec.email = ["nick@silvamerica.com"]
6
+ spec.description = "Interact with the Marathon API for your Mesos cluster"
7
+ spec.summary = "Interact with the Marathon API for your Mesos cluster"
8
+ spec.homepage = "https://github.com/silvamerica/lita-marathon"
9
+ spec.license = "MIT"
10
+ spec.metadata = { "lita_plugin_type" => "handler" }
11
+
12
+ spec.files = `git ls-files`.split($/)
13
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.require_paths = ["lib"]
16
+
17
+ spec.add_runtime_dependency "lita", ">= 4.7"
18
+ spec.add_runtime_dependency "marathon-api", "~> 2.0.1"
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "pry-byebug"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rack-test"
24
+ spec.add_development_dependency "rspec", ">= 3.0.0"
25
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,17 @@
1
+ en:
2
+ lita:
3
+ handlers:
4
+ marathon:
5
+ response:
6
+ restart: "Restarting %{app}"
7
+ suspend: "Suspending %{app}"
8
+ scale: "Scaling %{app} to %{instances}"
9
+ no_apps: "No apps found."
10
+ help:
11
+ list: "List Marathon apps"
12
+ count: "Show number of instances for Marathon apps"
13
+ restart: "Restart Marathon apps"
14
+ suspend: "Suspend Marathon apps"
15
+ scale: "Scale Marathon apps"
16
+ error:
17
+ unexpected_response: "The server returned an unexpected response. %{app} is probably locked by a deployment."
@@ -0,0 +1,4 @@
1
+ require "spec_helper"
2
+
3
+ describe Lita::Handlers::Marathon, lita_handler: true do
4
+ end
@@ -0,0 +1,6 @@
1
+ require "lita-marathon"
2
+ require "lita/rspec"
3
+
4
+ # A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin
5
+ # was generated with Lita 4, the compatibility mode should be left disabled.
6
+ Lita.version_3_compatibility_mode = false
File without changes
@@ -0,0 +1 @@
1
+ <%= I18n.translate "lita.handlers.marathon.response.#{@command}", app: @app, instances: @instances %>
@@ -0,0 +1 @@
1
+ <%= I18n.translate "lita.handlers.marathon.response.#{@command}", app: "`#{@app}`", instances: @instances %>
@@ -0,0 +1,6 @@
1
+ <% max_id_length = @apps.max_by{|app|app.id.length}.id.length %>
2
+
3
+ <% @apps.sort_by{|app|app.id}.each do |app| %>
4
+ <%= app.id.ljust(max_id_length + 3) %><%= app.tasksRunning %>/<%= app.instances %>
5
+
6
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <% max_id_length = @apps.max_by{|app|app.id.length}.id.length %>
2
+
3
+ ```<% @apps.sort_by{|app|app.id}.each do |app| %>
4
+ <%= app.id.ljust(max_id_length + 3) %><%= app.tasksRunning %>/<%= app.instances %>
5
+
6
+ <% end %>```
@@ -0,0 +1,4 @@
1
+ <% @apps.sort_by{|app|app.id}.each do |app| %>
2
+ <%= app.id %>
3
+
4
+ <% end %>
@@ -0,0 +1,4 @@
1
+ ```<% @apps.sort_by{|app|app.id}.each do |app| %>
2
+ <%= app.id %>
3
+
4
+ <% end %>```
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-marathon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nicholas Silva
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lita
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '4.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '4.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: marathon-api
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rack-test
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: 3.0.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: 3.0.0
111
+ description: Interact with the Marathon API for your Mesos cluster
112
+ email:
113
+ - nick@silvamerica.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - Gemfile
120
+ - LICENSE
121
+ - README.md
122
+ - Rakefile
123
+ - lib/lita-marathon.rb
124
+ - lib/lita/handlers/marathon.rb
125
+ - lita-marathon.gemspec
126
+ - locales/en.yml
127
+ - spec/lita/handlers/marathon_spec.rb
128
+ - spec/spec_helper.rb
129
+ - templates/.gitkeep
130
+ - templates/change_app.erb
131
+ - templates/change_app.slack.erb
132
+ - templates/count_apps.erb
133
+ - templates/count_apps.slack.erb
134
+ - templates/list_apps.erb
135
+ - templates/list_apps.slack.erb
136
+ homepage: https://github.com/silvamerica/lita-marathon
137
+ licenses:
138
+ - MIT
139
+ metadata:
140
+ lita_plugin_type: handler
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - '>='
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 2.0.14.1
158
+ signing_key:
159
+ specification_version: 4
160
+ summary: Interact with the Marathon API for your Mesos cluster
161
+ test_files:
162
+ - spec/lita/handlers/marathon_spec.rb
163
+ - spec/spec_helper.rb