norikra-client-jruby 0.0.1-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3bceb2e549ab68a8adb33a743994b49710bca961
4
+ data.tar.gz: 06cdd57d9cff8afb0a184a933b08f29a0af068e3
5
+ SHA512:
6
+ metadata.gz: 954e891d1d8a654527981b45ee2aa0a12fa4ae6b1e29e230d076a5bd28bdab08c8ceedb48a5692e6e4c74bb82944f94508f3c5f35f462e453a0f8f337b7df78c
7
+ data.tar.gz: 6e5e3f0349db57c51bd930bf21af670184ea47564320aa4347f2f8b5a3c84df294313848ed46d25e0a85eb498b071eed4f2af64a82809a0d94edbb98f8eb89ce
data/.gitignore ADDED
@@ -0,0 +1,18 @@
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
18
+ vendor/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in norikra-client.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 TAGOMORI Satoshi
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # Norikra::Client (norikra-client)
2
+
3
+ This is the client library implementation for Norikra, and its handy CLI commands.
4
+
5
+ `Norikra` is CEP server, based on Esper. You can install `gem install norikra` on your JRuby.
6
+ For more information, see https://github.com/tagomoris/norikra .
7
+
8
+ Command `norikra-client` and module `Norikra::Client` are provided for both of CRuby and JRuby.
9
+
10
+ * For CRuby: `gem install norikra-client`
11
+ * For JRuby: `gem install norikra-client-jruby`
12
+
13
+ Both have a same API and same data representaions. You can use which you want.
14
+
15
+ ## Commands
16
+
17
+ Command `norikra-client` have some subcommands.
18
+
19
+ norikra-client -h
20
+ Commands:
21
+ norikra-client event CMD ...ARGS # send/fetch events
22
+ norikra-client help [COMMAND] # Describe available commands or one specific command
23
+ norikra-client query CMD ...ARGS # manage queries
24
+ norikra-client target CMD ...ARGS # manage targets
25
+ norikra-client typedef CMD ...ARGS # manage table field/datatype definitions
26
+
27
+ Options:
28
+ [--host=HOST]
29
+ # Default: localhost
30
+ [--port=N]
31
+ # Default: 26571
32
+
33
+ Of course, you can see helps of each subcommands by `norikra-client SUBCMD help`
34
+
35
+ ## Client Library
36
+
37
+ In your programs, you can operate Norikra with Norikra::Client instances.
38
+
39
+ require 'norikra-client'
40
+
41
+ client = Norikra::Client.new # connect to localhost:26571
42
+ # client = Norikra::Client.new(hostname, portnum)
43
+
44
+ ### Instance methods
45
+
46
+ TBD
47
+
48
+ ## Versions
49
+
50
+ TBD
51
+
52
+ ## TODO
53
+
54
+ * TBD
55
+
56
+ ## Copyright
57
+
58
+ * Copyright (c) 2013- TAGOMORI Satoshi (tagomoris)
59
+ * License
60
+ * MIT License
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pathname'
4
+ lib = Pathname.new(__FILE__).dirname.join('..', 'lib').expand_path
5
+ $LOAD_PATH.unshift lib.to_s
6
+
7
+ require 'norikra/client/cli'
8
+ Norikra::Client::CLI.start
@@ -0,0 +1,35 @@
1
+ module Norikra::Client::CLIUtil
2
+ def formatter(format, *args)
3
+ format ||= 'json'
4
+ case format
5
+ when /^json$/i
6
+ require 'json'
7
+ Formatter::JSON.new(*args)
8
+ when /^ltsv$/i
9
+ require 'ltsv'
10
+ Formatter::LTSV.new(*args)
11
+ else
12
+ raise ArgumentError, "unknown format name: #{format}"
13
+ end
14
+ end
15
+
16
+ module Formatter
17
+ class JSON
18
+ def initialize(*args)
19
+ require 'json'
20
+ end
21
+ def format(obj)
22
+ ::JSON.dump(obj)
23
+ end
24
+ end
25
+
26
+ class LTSV
27
+ def initialize(*args)
28
+ require 'ltsv'
29
+ end
30
+ def format(obj)
31
+ ::LTSV.dump(obj)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,35 @@
1
+ module Norikra::Client::CLIUtil
2
+ def parser(format, *args)
3
+ format ||= 'json'
4
+ case format
5
+ when /^json$/i
6
+ require 'json'
7
+ Parser::JSON.new(*args)
8
+ when /^ltsv$/i
9
+ require 'ltsv'
10
+ Parser::LTSV.new(*args)
11
+ else
12
+ raise ArgumentError, "unknown format name: #{format}"
13
+ end
14
+ end
15
+
16
+ module Parser
17
+ class JSON
18
+ def initialize(*args)
19
+ require 'json'
20
+ end
21
+ def parse(line)
22
+ ::JSON.parse(line.chop)
23
+ end
24
+ end
25
+
26
+ class LTSV
27
+ def initialize(*args)
28
+ require 'ltsv'
29
+ end
30
+ def parse(line)
31
+ ::LTSV.parse_line(line.chop, {:symbolize_keys => false})
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,168 @@
1
+ require 'thor'
2
+ require 'norikra/client'
3
+
4
+ require 'norikra/client/cli/parser'
5
+ require 'norikra/client/cli/formatter'
6
+
7
+ class Norikra::Client
8
+ module CLIUtil
9
+ def client(options)
10
+ Norikra::Client.new(options[:host], options[:port])
11
+ end
12
+ end
13
+
14
+ class Target < Thor
15
+ include Norikra::Client::CLIUtil
16
+
17
+ desc "list", "show list of targets"
18
+ option :simple, :type => :boolean, :default => false, :desc => "suppress header/footer", :aliases => "-s"
19
+ def list
20
+ puts "TARGET" unless options[:simple]
21
+ targets = client(parent_options).targets
22
+ targets.each do |t|
23
+ puts t
24
+ end
25
+ puts "#{targets.size} targets found." unless options[:simple]
26
+ end
27
+
28
+ desc "open TARGET [fieldname1:type1 [fieldname2:type2 [fieldname3:type3] ...]]", "create new target (and define its fields)"
29
+ def open(target, *field_defs)
30
+ fields = nil
31
+ if field_defs.size > 0
32
+ fields = {}
33
+ field_defs.each do |str|
34
+ fname,ftype = str.split(':')
35
+ fields[fname] = ftype
36
+ end
37
+ end
38
+ client(parent_options).open(target, fields)
39
+ end
40
+
41
+ desc "close TARGET", "close existing target and all its queries"
42
+ def close(target)
43
+ client(parent_options).close(target)
44
+ end
45
+ end
46
+
47
+ class Query < Thor
48
+ include Norikra::Client::CLIUtil
49
+
50
+ desc "list", "show list of queries"
51
+ option :simple, :type => :boolean, :default => false, :desc => "suppress header/footer", :aliases => "-s"
52
+ def list
53
+ puts "TARGET\tQUERY_NAME\tQUERY" unless options[:simple]
54
+ queries = client(parent_options).queries
55
+ queries.sort{|a,b| (a['target'] <=> b['target']).nonzero? || a['name'] <=> b['name']}.each do |q|
56
+ puts "#{q['target']}\t#{q['name']}\t#{q['expression']}"
57
+ end
58
+ puts "#{queries.size} queries found." unless options[:simple]
59
+ end
60
+
61
+ desc "add QUERY_NAME QUERY_EXPRESSION", "register a query"
62
+ def add(query_name, expression)
63
+ client(parent_options).register(query_name, expression)
64
+ end
65
+
66
+ desc "remove QUERY_NAME", "deregister a query"
67
+ def remove(query_name)
68
+ client(parent_options).deregister(query_name)
69
+ end
70
+ end
71
+
72
+ class Field < Thor
73
+ include Norikra::Client::CLIUtil
74
+
75
+ desc "list TARGET", "show list of field definitions of specified target"
76
+ option :simple, :type => :boolean, :default => false, :desc => "suppress header/footer", :aliases => "-s"
77
+ def list(target)
78
+ puts "FIELD\tTYPE\tOPTIONAL" unless options[:simple]
79
+ fields = client(parent_options).fields(target)
80
+ fields.each do |f|
81
+ puts "#{f['name']}\t#{f['type']}\t#{f['optional']}"
82
+ end
83
+ puts "#{fields.size} fields found." unless options[:simple]
84
+ end
85
+
86
+ desc "add TARGET FIELDNAME TYPE", "reserve fieldname and its type of target"
87
+ def add(target, field, type)
88
+ client(parent_options).reserve(target, field, type)
89
+ end
90
+ end
91
+
92
+ class Event < Thor
93
+ include Norikra::Client::CLIUtil
94
+
95
+ desc "send TARGET", "send data into targets"
96
+ option :format, :type => :string, :default => 'json', :desc => "format of input data per line of stdin [json(default), ltsv]"
97
+ option :batch_size, :type => :numeric, :default => 10000, :desc => "records sent in once transferring (default: 10000)"
98
+ def send(target)
99
+ client = client(parent_options)
100
+ parser = parser(options[:format])
101
+ buffer = []
102
+ $stdin.each_line do |line|
103
+ buffer.push(parser.parse(line))
104
+ if buffer.size >= options[:batch_size]
105
+ client.send(target, buffer)
106
+ buffer = []
107
+ end
108
+ end
109
+ client.send(target, buffer) if buffer.size > 0
110
+ end
111
+
112
+ desc "fetch QUERY_NAME", "fetch events from specified query"
113
+ option :format, :type => :string, :default => 'json', :desc => "format of output data per line of stdout [json(default), ltsv]"
114
+ option :time_key, :type => :string, :default => 'time', :desc => "output key name for event time (default: time)"
115
+ option :time_format, :type => :string, :default => '%Y/%m/%d %H:%M:%S', :desc => "output time format (default: '2013/05/14 17:57:59')"
116
+ def fetch(query_name)
117
+ formatter = formatter(options[:format])
118
+ time_formatter = lambda{|t| Time.at(t).strftime(options[:time_format])}
119
+
120
+ client(parent_options).event(query_name).each do |time,event|
121
+ event = {options[:time_key] => Time.at(time).strftime(options[:time_format])}.merge(event)
122
+ puts formatter.format(event)
123
+ end
124
+ end
125
+
126
+ desc "sweep", "fetch all output events of all queries"
127
+ option :format, :type => :string, :default => 'json', :desc => "format of output data per line of stdout [json(default), ltsv]"
128
+ option :query_name_key, :type => :string, :default => 'query', :desc => "output key name for query name (default: query)"
129
+ option :time_key, :type => :string, :default => 'time', :desc => "output key name for event time (default: time)"
130
+ option :time_format, :type => :string, :default => '%Y/%m/%d %H:%M:%S', :desc => "output time format (default: '2013/05/14 17:57:59')"
131
+ def sweep
132
+ formatter = formatter(options[:format])
133
+ time_formatter = lambda{|t| Time.at(t).strftime(options[:time_format])}
134
+
135
+ data = client(parent_options).sweep
136
+
137
+ data.keys.sort.each do |queryname|
138
+ events = data[queryname]
139
+ events.each do |time,event|
140
+ event = {
141
+ options[:time_key] => Time.at(time).strftime(options[:time_format]),
142
+ options[:query_name_key] => queryname,
143
+ }.merge(event)
144
+ puts formatter.format(event)
145
+ end
146
+ end
147
+ end
148
+ end
149
+
150
+ class CLI < Thor
151
+ include Norikra::Client::CLIUtil
152
+
153
+ class_option :host, :type => :string, :default => 'localhost'
154
+ class_option :port, :type => :numeric, :default => 26571
155
+
156
+ desc "target CMD ...ARGS", "manage targets"
157
+ subcommand "target", Target
158
+
159
+ desc "field CMD ...ARGS", "manage target field/datatype definitions"
160
+ subcommand "field", Field
161
+
162
+ desc "query CMD ...ARGS", "manage queries"
163
+ subcommand "query", Query
164
+
165
+ desc "event CMD ...ARGS", "send/fetch events"
166
+ subcommand "event", Event
167
+ end
168
+ end
File without changes
@@ -0,0 +1,5 @@
1
+ module Norikra
2
+ class Client
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,59 @@
1
+ require "norikra/client/version"
2
+
3
+ require 'msgpack-rpc-over-http'
4
+
5
+ module Norikra
6
+ class Client
7
+ RPC_DEFAULT_PORT = 26571
8
+
9
+ def initialize(host='localhost', port=RPC_DEFAULT_PORT)
10
+ @client = MessagePack::RPCOverHTTP::Client.new("http://#{host}:#{port}/")
11
+ end
12
+
13
+ def targets
14
+ @client.call(:targets)
15
+ end
16
+
17
+ def open(target, fields=nil)
18
+ @client.call(:open, target, fields)
19
+ end
20
+
21
+ def close(target)
22
+ @client.call(:close, target)
23
+ end
24
+
25
+ def queries
26
+ @client.call(:queries)
27
+ end
28
+
29
+ def register(query_name, query_expression)
30
+ @client.call(:register, query_name, query_expression)
31
+ end
32
+
33
+ def deregister(query_name)
34
+ @client.call(:deregister, query_name)
35
+ end
36
+
37
+ def fields(target)
38
+ @client.call(:fields, target)
39
+ end
40
+
41
+ def reserve(target, field, type)
42
+ @client.call(:reserve, target, field, type)
43
+ end
44
+
45
+ def send(target, events)
46
+ @client.call(:send, target, events)
47
+ end
48
+
49
+ # [ [time, event], ... ]
50
+ def event(query_name)
51
+ @client.call(:event, query_name)
52
+ end
53
+
54
+ # {'query_name' => [ [time, event], ... ]}
55
+ def sweep
56
+ @client.call(:sweep)
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'norikra/client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "norikra-client-jruby"
8
+ spec.version = Norikra::Client::VERSION
9
+ spec.platform = "java"
10
+ spec.authors = ["TAGOMORI Satoshi"]
11
+ spec.email = ["tagomoris@gmail.com"]
12
+ spec.description = %q{Client commands and libraries for Norikra}
13
+ spec.summary = %q{Client commands and libraries for Norikra}
14
+ spec.homepage = "https://github.com/tagomoris/norikra-client"
15
+ spec.license = "APLv2"
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency "msgpack-rpc-over-http-jruby", ">= 0.0.4"
23
+ spec.add_runtime_dependency "thor"
24
+ spec.add_runtime_dependency "ltsv"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.3"
27
+ spec.add_development_dependency "rake"
28
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: norikra-client-jruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: java
6
+ authors:
7
+ - TAGOMORI Satoshi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: msgpack-rpc-over-http-jruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: ltsv
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
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
+ description: Client commands and libraries for Norikra
84
+ email:
85
+ - tagomoris@gmail.com
86
+ executables:
87
+ - norikra-client
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - bin/norikra-client
97
+ - lib/norikra/client.rb
98
+ - lib/norikra/client/cli.rb
99
+ - lib/norikra/client/cli/formatter.rb
100
+ - lib/norikra/client/cli/parser.rb
101
+ - lib/norikra/client/query.rb
102
+ - lib/norikra/client/version.rb
103
+ - norikra-client.gemspec
104
+ homepage: https://github.com/tagomoris/norikra-client
105
+ licenses:
106
+ - APLv2
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.0.0
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Client commands and libraries for Norikra
128
+ test_files: []