wakame-dolphin 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +4 -0
- data/.travis.yml +25 -0
- data/Gemfile +18 -0
- data/Makefile +56 -0
- data/README.md +77 -0
- data/Rakefile +67 -0
- data/bin/dolphin_server +98 -0
- data/config/db/cassandra_clear.txt +1 -0
- data/config/db/cassandra_schema.txt +14 -0
- data/config/db/sequel/migrations/0001_add_notification.rb +15 -0
- data/config/db/sequel/migrations/0002_add_event.rb +15 -0
- data/config/dolphin-mysql.conf.travis +26 -0
- data/config/dolphin.conf.example +26 -0
- data/lib/dolphin.rb +148 -0
- data/lib/dolphin/data_store.rb +55 -0
- data/lib/dolphin/data_stores/base_rdb.rb +57 -0
- data/lib/dolphin/data_stores/cassandra.rb +98 -0
- data/lib/dolphin/data_stores/mysql.rb +31 -0
- data/lib/dolphin/helpers/message/zabbix_helper.rb +16 -0
- data/lib/dolphin/helpers/request_helper.rb +72 -0
- data/lib/dolphin/mailer.rb +83 -0
- data/lib/dolphin/manager.rb +35 -0
- data/lib/dolphin/message_builder.rb +98 -0
- data/lib/dolphin/models/base.rb +8 -0
- data/lib/dolphin/models/cassandra/base.rb +11 -0
- data/lib/dolphin/models/cassandra/event.rb +42 -0
- data/lib/dolphin/models/cassandra/notification.rb +28 -0
- data/lib/dolphin/models/rdb/base.rb +12 -0
- data/lib/dolphin/models/rdb/event.rb +47 -0
- data/lib/dolphin/models/rdb/notification.rb +27 -0
- data/lib/dolphin/models/rdb/orm/base.rb +10 -0
- data/lib/dolphin/models/rdb/orm/event.rb +8 -0
- data/lib/dolphin/models/rdb/orm/notification.rb +8 -0
- data/lib/dolphin/query_processor.rb +50 -0
- data/lib/dolphin/request_handler.rb +150 -0
- data/lib/dolphin/sender.rb +47 -0
- data/lib/dolphin/util.rb +18 -0
- data/lib/dolphin/version.rb +3 -0
- data/lib/dolphin/worker.rb +149 -0
- data/script/console +13 -0
- data/spec/files/cassandra_models_spec.rb +127 -0
- data/spec/files/dolphin_spec.rb +110 -0
- data/spec/files/endpoint/event_spec.rb +123 -0
- data/spec/files/endpoint/notification_spec.rb +54 -0
- data/spec/files/message_builder_spec.rb +15 -0
- data/spec/helpers/test_helper.rb +21 -0
- data/spec/helpers/web_request_helper.rb +40 -0
- data/spec/spec_helper.rb +18 -0
- data/templates/email/alert_port.erb +24 -0
- data/templates/email/default.erb +3 -0
- data/tests/test_dolphin +10 -0
- data/tests/test_get_event +31 -0
- data/tests/test_get_notification +27 -0
- data/tests/test_post_event +37 -0
- data/tests/test_post_notification +43 -0
- data/wakame-dolphin.gemspec +40 -0
- metadata +311 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1083fcd12c989df0d9878212ca88dd1e9799d3a0
|
4
|
+
data.tar.gz: 064f9d4865ff443cb3d0a1abc6e7b687e8fcc9e8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0cc6b3984d0c446b8fe8acc8cbd8d8794c0142774f3a87e762616985e3ba50b80c1a6a17f9c99b7732da3366218b789844f4ad00be41efa25c30a440d60cc47c
|
7
|
+
data.tar.gz: 68faacea3a90b3b3277fb06251dcc8b69632bfef277d6c0cfd7c975277704bda759969c514072f4ce6831c74d7560cd3ed3c7db8a1ae4cdeb1b0b8febf0bffb8
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
language: ruby
|
2
|
+
|
3
|
+
env:
|
4
|
+
- DB=mysql CONFIG_FILE=dolphin-mysql.conf.travis
|
5
|
+
|
6
|
+
rvm:
|
7
|
+
- 1.9.3
|
8
|
+
|
9
|
+
before_install:
|
10
|
+
- gem update bundler
|
11
|
+
|
12
|
+
before_script:
|
13
|
+
- mysql -e 'create database dolphin;'
|
14
|
+
- bundle exec rake db:mysql:init
|
15
|
+
- bundle exec ./bin/dolphin_server -c "./config/${CONFIG_FILE}" &
|
16
|
+
|
17
|
+
script:
|
18
|
+
- bundle exec rspec ./spec/files/endpoint/
|
19
|
+
|
20
|
+
after_script:
|
21
|
+
- bundle exec rake db:mysql:drop
|
22
|
+
|
23
|
+
branches:
|
24
|
+
only:
|
25
|
+
- master
|
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
group :mysql do
|
6
|
+
gem 'sequel', '3.48.0'
|
7
|
+
gem 'mysql2', '0.3.11'
|
8
|
+
end
|
9
|
+
|
10
|
+
group :cassandra do
|
11
|
+
gem 'cassandra', '0.17.0'
|
12
|
+
end
|
13
|
+
|
14
|
+
group :development, :test do
|
15
|
+
gem 'rspec', '2.13.0'
|
16
|
+
gem 'pry'
|
17
|
+
gem 'rb-readline'
|
18
|
+
end
|
data/Makefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
CURDIR ?= $(PWD)
|
2
|
+
RUBYDIR = $(CURDIR)/ruby
|
3
|
+
DSTDIR ?= ""
|
4
|
+
|
5
|
+
define BUNDLE_CFG
|
6
|
+
---
|
7
|
+
BUNDLE_PATH: vendor/bundle
|
8
|
+
BUNDLE_DISABLE_SHARED_GEMS: '1'
|
9
|
+
endef
|
10
|
+
# We're exporting this as a shell variable because otherwise Make can't echo multiline strings into a file
|
11
|
+
export BUNDLE_CFG
|
12
|
+
|
13
|
+
dev: build-ruby install-bundle-dev
|
14
|
+
|
15
|
+
build-ruby:
|
16
|
+
$(CURDIR)/deployment/rubybuild/build_ruby.sh
|
17
|
+
|
18
|
+
install-bundle-dev:
|
19
|
+
$(RUBYDIR)/bin/gem install bundler
|
20
|
+
(cd $(CURDIR); mkdir .bundle; echo "$$BUNDLE_CFG" > .bundle/config)
|
21
|
+
(cd $(CURDIR); $(RUBYDIR)/bin/bundle install)
|
22
|
+
|
23
|
+
install-bundle-with-cassandra:
|
24
|
+
$(RUBYDIR)/bin/gem install bundler
|
25
|
+
(cd $(CURDIR); mkdir .bundle; echo "$$BUNDLE_CFG" > .bundle/config)
|
26
|
+
(cd $(CURDIR); $(RUBYDIR)/bin/bundle install --without development test mysql)
|
27
|
+
|
28
|
+
install-bundle-with-mysql:
|
29
|
+
$(RUBYDIR)/bin/gem install bundler
|
30
|
+
(cd $(CURDIR); mkdir .bundle; echo "$$BUNDLE_CFG" > .bundle/config)
|
31
|
+
(cd $(CURDIR); $(RUBYDIR)/bin/bundle install --without development test cassandra)
|
32
|
+
|
33
|
+
install: update-config
|
34
|
+
mkdir -p $(DSTDIR)/opt/axsh/wakame-dolphin
|
35
|
+
mkdir -p $(DSTDIR)/etc/wakame-vdc
|
36
|
+
cp -r . $(DSTDIR)/opt/axsh/wakame-dolphin
|
37
|
+
cp -r deployment/conf_files/etc/default $(DSTDIR)/etc
|
38
|
+
cp -r deployment/conf_files/etc/init $(DSTDIR)/etc
|
39
|
+
|
40
|
+
uninstall:
|
41
|
+
rm -rf $(DSTDIR)/opt/axsh/wakame-dolphin
|
42
|
+
rm -rf $(DSTDIR)/tmp/log
|
43
|
+
rm -rf $(DSTDIR)/var/run/wakame-dolphin
|
44
|
+
rm $(DSTDIR)/etc/default/vdc-dolphin
|
45
|
+
rm $(DSTDIR)/etc/init/vdc-dolphin.conf
|
46
|
+
|
47
|
+
update-config:
|
48
|
+
cp -r deployment/conf_files/etc/wakame-vdc $(DSTDIR)/etc/
|
49
|
+
|
50
|
+
remove-config:
|
51
|
+
rm -rf $(DSTDIR)/etc/wakame-vdc/dolphin.conf
|
52
|
+
|
53
|
+
clean:
|
54
|
+
# rm -rf $(RUBYDIR)
|
55
|
+
rm -rf $(CURDIR)/vendor
|
56
|
+
rm -rf $(CURDIR)/.bundle
|
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# Dolphin
|
2
|
+
|
3
|
+
Dolphin is notification service.
|
4
|
+
|
5
|
+
### Install for production
|
6
|
+
|
7
|
+
Dolphin supported multi datastore are mysql and cassandra.
|
8
|
+
|
9
|
+
#### DataStore cassandra
|
10
|
+
```
|
11
|
+
$ bundle install --without test development mysql
|
12
|
+
```
|
13
|
+
|
14
|
+
#### DataStore mysql
|
15
|
+
```
|
16
|
+
$ bundle install --without test development cassandra
|
17
|
+
```
|
18
|
+
|
19
|
+
### Copy Settings File
|
20
|
+
|
21
|
+
```
|
22
|
+
$ cp -ip ./config/dolphin.conf.example ./config/dolphin.conf
|
23
|
+
```
|
24
|
+
|
25
|
+
### Edit config
|
26
|
+
|
27
|
+
```
|
28
|
+
$ vi ./config/dolphin.conf
|
29
|
+
```
|
30
|
+
|
31
|
+
./config/dolphin.conf
|
32
|
+
```
|
33
|
+
from=yourname@yourdomain
|
34
|
+
```
|
35
|
+
|
36
|
+
### Start Service
|
37
|
+
|
38
|
+
```
|
39
|
+
$ ./bin/dolphin_server
|
40
|
+
```
|
41
|
+
|
42
|
+
```
|
43
|
+
I, [2013-03-12T14:41:17.533784 #27820] INFO -- : [11950120] [Dolphin::RequestHandler] Running on ruby 1.9.3 with selected Celluloid::TaskThread
|
44
|
+
I, [2013-03-12T14:41:17.533922 #27820] INFO -- : [11950120] [Dolphin::RequestHandler] Listening on http://127.0.0.1:9004
|
45
|
+
```
|
46
|
+
|
47
|
+
### Add Notification
|
48
|
+
|
49
|
+
```
|
50
|
+
$ MAIL_TO=example@example.com ruby ./example/client/put_notification.rb
|
51
|
+
```
|
52
|
+
|
53
|
+
### Add Event
|
54
|
+
|
55
|
+
```
|
56
|
+
$ ruby ./example/client/post_event.rb
|
57
|
+
```
|
58
|
+
|
59
|
+
### Tempolary mail
|
60
|
+
|
61
|
+
```
|
62
|
+
$ ls ./tmp/mails
|
63
|
+
```
|
64
|
+
|
65
|
+
### Run Test Case
|
66
|
+
|
67
|
+
```
|
68
|
+
$ bundle exec rake spec
|
69
|
+
```
|
70
|
+
|
71
|
+
### Code Status
|
72
|
+
|
73
|
+
[![Build Status](https://travis-ci.org/axsh/wakame-dolphin.png?branch=master)](https://travis-ci.org/axsh/wakame-dolphin)
|
74
|
+
|
75
|
+
### License
|
76
|
+
|
77
|
+
Copyright (c) Axsh Co. Components are included distribution under LGPL 3.0 and Apache 2.0
|
data/Rakefile
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
require "rubygems"
|
4
|
+
require "bundler/setup"
|
5
|
+
|
6
|
+
require File.join(File.expand_path('../', __FILE__), 'lib/dolphin')
|
7
|
+
|
8
|
+
unless ENV['CONFIG_FILE'].blank?
|
9
|
+
Dolphin.settings(File.join(Dolphin.config_path, ENV['CONFIG_FILE']))
|
10
|
+
end
|
11
|
+
|
12
|
+
require "rspec/core/rake_task"
|
13
|
+
desc 'Run rspec'
|
14
|
+
RSpec::Core::RakeTask.new("spec") do |spec|
|
15
|
+
spec.pattern = FileList["spec/files/endpoint/*_spec.rb"]
|
16
|
+
end
|
17
|
+
|
18
|
+
task :default => :spec
|
19
|
+
|
20
|
+
namespace :db do
|
21
|
+
namespace :cassandra do
|
22
|
+
|
23
|
+
desc 'Clean cassandra'
|
24
|
+
task :clean do |tasks|
|
25
|
+
begin
|
26
|
+
|
27
|
+
db_config = Dolphin.settings['database']
|
28
|
+
@host = db_config['hosts'].split(',')[0]
|
29
|
+
@port = db_config['port']
|
30
|
+
|
31
|
+
@connect = Dolphin::DataStore::Cassandra.new({
|
32
|
+
:keyspace => Dolphin::DataStore::Cassandra::KEYSPACE,
|
33
|
+
:hosts => @host,
|
34
|
+
:port => @port
|
35
|
+
}).connect
|
36
|
+
|
37
|
+
@connect.drop_keyspace(Dolphin::DataStore::Cassandra::KEYSPACE)
|
38
|
+
rescue => e
|
39
|
+
puts "Doesn't exist #{Dolphin::DataStore::Cassandra::KEYSPACE} keyspace or dropped already"
|
40
|
+
exit
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
desc 'Migrate cassandra'
|
45
|
+
task :migrate do
|
46
|
+
filename = Dolphin.db_path + '/cassandra_schema.txt'
|
47
|
+
exec "/usr/bin/cassandra-cli -h #{@host} -p #{@port} -f #{filename}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
namespace :mysql do
|
52
|
+
|
53
|
+
desc 'Create all database tables'
|
54
|
+
task :init do
|
55
|
+
Dolphin::DataStore.current_store.connect
|
56
|
+
Sequel.extension :migration
|
57
|
+
Sequel::Migrator.apply(Sequel::DATABASES.first, File.expand_path('../config/db/sequel/migrations', __FILE__), 9999)
|
58
|
+
end
|
59
|
+
|
60
|
+
desc 'Drop all database tables'
|
61
|
+
task :drop do
|
62
|
+
Dolphin::DataStore.current_store.connect
|
63
|
+
Sequel.extension :migration
|
64
|
+
Sequel::Migrator.apply(Sequel::DATABASES.first, File.expand_path('../config/db/sequel/migrations', __FILE__), 0)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/bin/dolphin_server
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
# TODO: better loading libraries
|
5
|
+
setup_rb = File.expand_path('../../vendor/bundle/bundler/setup.rb', __FILE__)
|
6
|
+
|
7
|
+
begin
|
8
|
+
require 'rubygems'
|
9
|
+
if File.exists?(setup_rb)
|
10
|
+
load setup_rb
|
11
|
+
else
|
12
|
+
require 'bundler/setup'
|
13
|
+
end
|
14
|
+
rescue LoadError => e
|
15
|
+
end
|
16
|
+
|
17
|
+
require File.join(File.expand_path('../../', __FILE__), 'lib/dolphin')
|
18
|
+
require 'optparse'
|
19
|
+
|
20
|
+
options = {}
|
21
|
+
opt = OptionParser.new do |opt|
|
22
|
+
opt.on('-c [dolphin.conf]', "Dolphin configuration file") {|v| options[:config_file] = v }
|
23
|
+
opt.on('-h', "--help") {|v| puts opt.help(); Kernel.exit(true) }
|
24
|
+
opt.on('-v', "--version") {|v| puts Dolphin::VERSION; Kernel.exit(true) }
|
25
|
+
end
|
26
|
+
|
27
|
+
begin
|
28
|
+
opt.parse!(ARGV)
|
29
|
+
rescue => e
|
30
|
+
STDERR.puts e
|
31
|
+
exit!
|
32
|
+
end
|
33
|
+
|
34
|
+
require 'ltsv'
|
35
|
+
require 'celluloid'
|
36
|
+
|
37
|
+
module Dolphin
|
38
|
+
|
39
|
+
Celluloid.logger.datetime_format = "%Y-%m-%d %H:%M:%S"
|
40
|
+
Celluloid.logger.formatter = proc { |severity, datetime, progname, msg|
|
41
|
+
case settings['logger']['format']
|
42
|
+
when 'human_readable'
|
43
|
+
msg = "[#{msg[:thread_id]}] [#{msg[:classname]}] #{msg[:message]}" if msg.is_a?(Hash)
|
44
|
+
Logger::Formatter.new.call(severity, datetime, progname, msg)
|
45
|
+
when 'ltsv'
|
46
|
+
LTSV.dump({
|
47
|
+
:log_level => severity,
|
48
|
+
:time => datetime,
|
49
|
+
:thread_id => msg[:thread_id],
|
50
|
+
:classname => msg[:classname],
|
51
|
+
:message => msg[:message],
|
52
|
+
}) + "\n"
|
53
|
+
end
|
54
|
+
}
|
55
|
+
|
56
|
+
def self.run(options)
|
57
|
+
|
58
|
+
# init config_file
|
59
|
+
Dolphin.settings(options[:config_file])
|
60
|
+
|
61
|
+
if RUBY_VERSION.to_f >= 2
|
62
|
+
# Celluloid::TaskFiber by default
|
63
|
+
elsif RUBY_VERSION.to_f >= 1.9
|
64
|
+
Celluloid.task_class = Celluloid::TaskThread
|
65
|
+
else
|
66
|
+
raise "Doesn't support ruby version: #{RUBY_VERSION}"
|
67
|
+
exit!
|
68
|
+
end
|
69
|
+
|
70
|
+
# verify possible for to load Gem related database.
|
71
|
+
begin
|
72
|
+
Dolphin::Models::Base
|
73
|
+
rescue Gem::LoadError => e
|
74
|
+
raise e.message
|
75
|
+
exit!
|
76
|
+
end
|
77
|
+
|
78
|
+
manager = Manager.new
|
79
|
+
# manager.pool(Worker, :as => :workers, :size => 2)
|
80
|
+
# manager.pool(Sender::Mail, :as => :mail_senders, :size => 2)
|
81
|
+
# manager.pool(QueryProcessor, :as => :query_processors, :size => 2)
|
82
|
+
|
83
|
+
manager.add(Worker, :as => :workers)
|
84
|
+
manager.add(Sender::Mail, :as => :mail_senders)
|
85
|
+
manager.add(QueryProcessor, :as => :query_processors)
|
86
|
+
|
87
|
+
# TODO: RequestHandler link to Manager
|
88
|
+
# TODO: Chanage to rackup
|
89
|
+
|
90
|
+
server_settings = Dolphin.settings['server']
|
91
|
+
RequestHandler.new(server_settings['host'], server_settings['port'])
|
92
|
+
|
93
|
+
Manager.run
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
Dolphin.run(options)
|
98
|
+
sleep
|
@@ -0,0 +1 @@
|
|
1
|
+
drop keyspace dolphin;
|
@@ -0,0 +1,14 @@
|
|
1
|
+
create keyspace dolphin with
|
2
|
+
placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy' AND
|
3
|
+
strategy_options = {replication_factor:1};
|
4
|
+
|
5
|
+
use dolphin;
|
6
|
+
|
7
|
+
create column family events with comparator = TimeUUIDType
|
8
|
+
AND key_validation_class = AsciiType
|
9
|
+
AND default_validation_class = UTF8Type;
|
10
|
+
|
11
|
+
create column family notifications with comparator = AsciiType
|
12
|
+
AND key_validation_class = AsciiType
|
13
|
+
AND default_validation_class = UTF8Type;
|
14
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Sequel.migration do
|
2
|
+
up do
|
3
|
+
create_table(:notifications) do
|
4
|
+
primary_key :id, :type=>"int(11)"
|
5
|
+
column :uuid, "varchar(255)", :null=>false
|
6
|
+
column :value, "blob", :null=>false
|
7
|
+
column :timestamp, "datetime", :null=>false
|
8
|
+
index [:uuid], :unique=>true, :name=>:uuid
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
down do
|
13
|
+
drop_table(:notifications)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Sequel.migration do
|
2
|
+
up do
|
3
|
+
create_table(:events) do
|
4
|
+
primary_key :id, :type=>"int(11)"
|
5
|
+
column :uuid, "varchar(255)", :null=>false
|
6
|
+
column :value, "blob", :null=>false
|
7
|
+
column :timestamp, "datetime", :null=>false
|
8
|
+
index [:uuid], :unique=>true, :name=>:uuid
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
down do
|
13
|
+
drop_table(:events)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
[server]
|
2
|
+
host = 0.0.0.0
|
3
|
+
port = 9004
|
4
|
+
|
5
|
+
[agent]
|
6
|
+
request_handler = 1
|
7
|
+
query_processor = 1
|
8
|
+
worker = 1
|
9
|
+
sender = 1
|
10
|
+
|
11
|
+
[database]
|
12
|
+
adapter = mysql
|
13
|
+
host = 127.0.0.1
|
14
|
+
port = 3306
|
15
|
+
user = root
|
16
|
+
pass =
|
17
|
+
|
18
|
+
[mail]
|
19
|
+
from = demo@example.com
|
20
|
+
# host = localhost
|
21
|
+
# port = 25
|
22
|
+
type = file
|
23
|
+
|
24
|
+
[logger]
|
25
|
+
format = human_readable
|
26
|
+
# format = ltsv
|