karma_messages 0.1.0 → 0.1.1

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: c4fc92338635c4dc312346b58d3acae65276ed75
4
- data.tar.gz: c0688fa673d3cbfa2eb65837be500c07020aa660
3
+ metadata.gz: 8ab2bc4ab71e723d3d19fb93a3a60e7478e425d8
4
+ data.tar.gz: c0c3933008d8fc32529f881d7de6f0c9c4f8a18f
5
5
  SHA512:
6
- metadata.gz: 11fbde59ef9ca0ae0fb6fac1579d78111a637c1d1565bd057f8419d3d980b57c8e1a4d328da345cb0d029e99f00ea8809233f726f26d2ad5058d966ce67aae5a
7
- data.tar.gz: bbe4a37b60c6f9fe2417444d9994e05609ada7b8b82c4abd0a20112846b19d358a6415c118e5a7fc135c7b77cd2bf45f9c4338ad5a20236418891c05c3e13bee
6
+ metadata.gz: edfa09e8f3125baf49e63b72e88d6cf97e27a9e7661467c605024fd1c08e4b716b61702a5aff6cd74d1141a4db6c09230d9c6d8b171806bda951b1d1ec6c6109
7
+ data.tar.gz: 3cd3d2e13d9f8e1b58081d254466c6a3b703fd307a5714cdd6b7fc0aa6996993fdd26ee37ee416610c8301dc81e8192e11295ce21dcdc88d38fccdd8ca479807
data/.gitignore CHANGED
@@ -57,6 +57,8 @@ spec/solr/test/data/*
57
57
  # byebug history file
58
58
  .byebug_history
59
59
 
60
+ .ruby-version
61
+
60
62
  /node_modules
61
63
  /dump.rdb
62
64
  /cassandra.*
data/Gemfile CHANGED
@@ -1,9 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- group :development, :test do
4
- # Call 'byebug' anywhere in the code to stop execution and get a debugger console
5
- gem 'byebug', platform: :mri
6
- end
3
+ gem 'byebug'
7
4
 
8
5
  # Specify your gem's dependencies in karma_messages.gemspec
9
6
  gemspec
data/Gemfile.lock CHANGED
@@ -25,6 +25,8 @@ GEM
25
25
 
26
26
  PLATFORMS
27
27
  ruby
28
+ x86_64-darwin-15
29
+ x86_64-darwin-16
28
30
 
29
31
  DEPENDENCIES
30
32
  bundler (~> 1.14)
@@ -9,19 +9,10 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["extendi"]
10
10
  spec.email = ["info@extendi.it"]
11
11
 
12
- spec.summary = "Sqs message parser"
13
- spec.description = ""
12
+ spec.summary = "summary"
13
+ spec.description = "desription"
14
14
  spec.homepage = "http://extendi.it"
15
15
 
16
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
- # to allow pushing to a single host or delete this section to allow pushing to any host.
18
- # if spec.respond_to?(:metadata)
19
- # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
20
- # else
21
- # raise "RubyGems 2.0 or newer is required to protect against " \
22
- # "public gem pushes."
23
- # end
24
-
25
16
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
17
  f.match(%r{^(test|spec|features)/})
27
18
  end
@@ -1,9 +1,13 @@
1
1
  module Karma::Messages
2
+
2
3
  class Base
4
+
3
5
  attr_accessor :errors, :service
4
6
 
5
7
  def initialize(params)
8
+ Karma::Messages.logger.debug("#{self.class.name} - #{params}")
6
9
  parse(params)
10
+ Karma::Messages.logger.warn("Message is invalid: - #{errors}") if errors.any?
7
11
  end
8
12
 
9
13
  def to_message
@@ -13,7 +17,6 @@ module Karma::Messages
13
17
  def parse(params)
14
18
  clear_errors
15
19
  @errors << {service: 'Required'} if params[:service].nil?
16
-
17
20
  @service = params[:service]
18
21
  end
19
22
 
@@ -30,6 +33,7 @@ module Karma::Messages
30
33
  end
31
34
 
32
35
  end
36
+
33
37
  end
34
38
 
35
39
  require "karma_messages/base_karma"
@@ -1,4 +1,5 @@
1
1
  module Karma::Messages
2
+
2
3
  class BaseKarma < Base
3
4
 
4
5
  attr_reader :host, :project
@@ -16,5 +17,7 @@ module Karma::Messages
16
17
  ret = super
17
18
  ret.merge!({ project: @project, host: @host })
18
19
  end
20
+
19
21
  end
22
+
20
23
  end
@@ -1,4 +1,7 @@
1
1
  module Karma::Messages
2
+
2
3
  class BaseKarmap < Base
4
+
3
5
  end
6
+
4
7
  end
@@ -1,9 +1,10 @@
1
1
  module Karma::Messages
2
+
2
3
  class ProcessCommandMessage < BaseKarmap
3
4
 
4
- attr_accessor :command, :pid
5
+ attr_reader :command, :pid
5
6
 
6
- COMMANDS = ['start', 'stop'].freeze
7
+ COMMANDS = {start: 'start', stop: 'stop', restart: 'restart'}.freeze
7
8
 
8
9
  def self.services=(val)
9
10
  @@services = val
@@ -14,8 +15,6 @@ module Karma::Messages
14
15
  end
15
16
 
16
17
  def initialize(params)
17
- Karma::Messages.logger.debug("ProcessCommandMessage::initialize")
18
- Karma::Messages.logger.debug(params)
19
18
  super(params)
20
19
  end
21
20
 
@@ -24,7 +23,7 @@ module Karma::Messages
24
23
  @@services ||= {}
25
24
  @errors << {service: 'Not a valid service'} if !@@services.empty? && !@@services.include?(params[:service])
26
25
  @errors << {command: 'Required'} if params[:command].nil?
27
- @errors << {command: 'Not a valid command'} if !params[:command].nil? && !COMMANDS.include?(params[:command])
26
+ @errors << {command: 'Not a valid command'} if !params[:command].nil? && !COMMANDS.values.include?(params[:command])
28
27
  @errors << {pid: 'Required'} if params[:command] == 'stop' && params[:pid].nil?
29
28
 
30
29
  @command = params[:command]
@@ -34,9 +33,10 @@ module Karma::Messages
34
33
  def to_message
35
34
  ret = super
36
35
  ret.merge!({ type: message_type, command: @command})
37
- ret.merge!({ pid: @pid}) if @command == 'stop'
36
+ ret.merge!({ pid: @pid}) if @command != COMMANDS[:start]
38
37
  ret
39
38
  end
40
39
 
41
40
  end
41
+
42
42
  end
@@ -1,18 +1,17 @@
1
1
  module Karma::Messages
2
+
2
3
  class ProcessConfigUpdateMessage < BaseKarmap
3
-
4
- attr_accessor :memory_max, :cpu_quota, :min_running, :max_running, :auto_restart, :auto_start
5
-
4
+
5
+ attr_reader :memory_max, :cpu_quota, :min_running, :max_running, :auto_restart, :auto_start
6
+
6
7
  def parse(params)
7
8
  super(params)
8
9
 
9
- @errors << { memory_max: 'Required' } if params[:memory_max].nil?
10
- @errors << { cpu_quota: 'Required' } if params[:cpu_quota].nil?
11
10
  @errors << { min_running: 'Required' } if params[:min_running].nil?
12
11
  @errors << { max_running: 'Required' } if params[:max_running].nil?
13
12
  @errors << { auto_restart: 'Required' } if params[:auto_restart].nil?
14
13
  @errors << { auto_start: 'Required' } if params[:auto_start].nil?
15
-
14
+
16
15
  @memory_max = params[:memory_max]
17
16
  @cpu_quota = params[:cpu_quota]
18
17
  @min_running = params[:min_running]
@@ -24,8 +23,23 @@ module Karma::Messages
24
23
 
25
24
  def to_message
26
25
  ret = super
27
- ret.merge!({ type: message_type, memory_max: @memory_max, cpu_quota: @cpu_quota, min_running: @min_running, max_running: @max_running, auto_restart: @auto_restart, auto_start: @auto_start })
26
+ ret.merge!({ min_running: @min_running, max_running: @max_running, auto_restart: @auto_restart, auto_start: @auto_start })
27
+ ret.merge!({ memory_max: @memory_max} ) if !@memory_max.nil?
28
+ ret.merge!({ cpu_quota: @cpu_quota} ) if !@cpu_quota.nil?
28
29
  ret
29
30
  end
31
+
32
+ def to_config
33
+ {
34
+ memory_max: memory_max,
35
+ cpu_quota: cpu_quota,
36
+ min_running: min_running,
37
+ max_running: max_running,
38
+ auto_restart: auto_restart,
39
+ auto_start: auto_start
40
+ }
41
+ end
42
+
30
43
  end
44
+
31
45
  end
@@ -1,5 +1,39 @@
1
1
  module Karma::Messages
2
+
2
3
  class ProcessRegisterMessage < BaseKarma
3
-
4
+
5
+ attr_reader :memory_max, :cpu_quota, :min_running, :max_running, :auto_restart, :auto_start, :log_level, :num_threads, :overwrite
6
+
7
+ def parse(params)
8
+ super(params)
9
+ @errors << {min_running: 'Required'} if params[:min_running].nil?
10
+ @errors << {max_running: 'Required'} if params[:max_running].nil?
11
+ @errors << {auto_restart: 'Required'} if params[:auto_restart].nil?
12
+ @errors << {auto_start: 'Required'} if params[:auto_start].nil?
13
+ @errors << {log_level: 'Required'} if params[:log_level].nil?
14
+ @errors << {num_threads: 'Required'} if params[:num_threads].nil?
15
+
16
+ @memory_max = params[:memory_max]
17
+ @cpu_quota = params[:cpu_quota]
18
+ @min_running = params[:min_running]
19
+ @max_running = params[:max_running]
20
+ @auto_restart = params[:auto_restart]
21
+ @auto_start = params[:auto_start]
22
+ @log_level = params[:log_level]
23
+ @num_threads = params[:num_threads]
24
+ @overwrite = params[:overwrite] || false
25
+ end
26
+
27
+ def to_message
28
+ ret = super
29
+ ret.merge!({ min_running: @min_running, max_running: @max_running,
30
+ auto_restart: @auto_restart, auto_start: @auto_start,
31
+ memory_max: @memory_max, cpu_quota: @cpu_quota})
32
+ ret.merge!({ log_level: @log_level, num_threads: @num_threads })
33
+ ret.merge!({ overwrite: @overwrite })
34
+ ret
35
+ end
36
+
4
37
  end
38
+
5
39
  end
@@ -1,24 +1,23 @@
1
1
  module Karma::Messages
2
+
2
3
  class ProcessStatusUpdateMessage < BaseKarma
3
4
 
4
5
  STATUSES = {running: 'running', stopped: 'stopped', dead: 'dead'}.freeze
5
6
 
6
- attr_reader :pid, :instance_name, :status
7
+ attr_reader :pid, :status
7
8
 
8
9
  def parse(params)
9
10
  super(params)
10
11
  @errors << {pid: 'Required'} if params[:pid].nil?
11
- @errors << {instance_name: 'Required'} if params[:instance_name].nil?
12
12
  @errors << {status: 'Not a valid status'} if params[:status].nil? && !STATUSES.values.include?(params[:status])
13
13
 
14
14
  @pid = params[:pid]
15
- @instance_name = params[:instance_name]
16
15
  @status = params[:status]
17
16
  end
18
17
 
19
18
  def to_message
20
19
  ret = super
21
- ret.merge!({ pid: @pid, instance_name: @instance_name, status: @status })
20
+ ret.merge!({ pid: @pid, status: @status })
22
21
  end
23
22
 
24
23
  end
@@ -1,6 +1,8 @@
1
1
  module Karma::Messages
2
+
2
3
  class ThreadConfigUpdateMessage < BaseKarmap
3
- attr_accessor :log_level, :num_threads
4
+
5
+ attr_reader :log_level, :num_threads
4
6
 
5
7
  def parse(params)
6
8
  super(params)
@@ -15,8 +17,17 @@ module Karma::Messages
15
17
 
16
18
  def to_message
17
19
  ret = super
18
- ret.merge!({ type: message_type, log_level: @log_level, num_threads: @num_threads })
20
+ ret.merge!({ log_level: @log_level, num_threads: @num_threads })
19
21
  ret
20
22
  end
23
+
24
+ def to_config
25
+ {
26
+ num_threads: num_threads,
27
+ log_level: log_level
28
+ }
29
+ end
30
+
21
31
  end
32
+
22
33
  end
@@ -1,5 +1,5 @@
1
1
  module Karma
2
2
  module Messages
3
- VERSION = "0.1.0"
3
+ VERSION = '0.1.1'
4
4
  end
5
5
  end
@@ -2,18 +2,15 @@ require 'logger'
2
2
 
3
3
  module Karma
4
4
  module Messages
5
-
6
5
  class << self
7
6
  attr_writer :logger
8
-
9
7
  def logger
10
- filename = $stdout
11
- @@logger ||= Logger.new(filename).tap do |log|
8
+ @logger ||= Logger.new($stdout, 2, 52428800).tap do |log|
9
+ log.level = Logger::INFO
12
10
  log.progname = self.name
13
11
  end
14
12
  end
15
13
  end
16
-
17
14
  end
18
15
  end
19
16
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: karma_messages
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - extendi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-17 00:00:00.000000000 Z
11
+ date: 2017-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
- description: ''
55
+ description: desription
56
56
  email:
57
57
  - info@extendi.it
58
58
  executables: []
@@ -61,7 +61,6 @@ extra_rdoc_files: []
61
61
  files:
62
62
  - ".editorconfig"
63
63
  - ".gitignore"
64
- - ".ruby-version"
65
64
  - Gemfile
66
65
  - Gemfile.lock
67
66
  - README.md
@@ -98,8 +97,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
97
  version: '0'
99
98
  requirements: []
100
99
  rubyforge_project:
101
- rubygems_version: 2.6.8
100
+ rubygems_version: 2.4.5
102
101
  signing_key:
103
102
  specification_version: 4
104
- summary: Sqs message parser
103
+ summary: summary
105
104
  test_files: []
105
+ has_rdoc:
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.4.0