rbatch 2.1.0 → 2.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.
- data/bin/rbatch-init +1 -1
- data/lib/rbatch.rb +29 -89
- data/lib/rbatch/common_config.rb +0 -71
- data/lib/rbatch/config.rb +2 -21
- data/lib/rbatch/controller.rb +75 -0
- data/lib/rbatch/log.rb +7 -7
- data/lib/rbatch/version.rb +1 -1
- data/sample/bin/ftp_get.rb +20 -0
- data/sample/bin/store_to_idm.rb +10 -0
- data/sample/conf/common.yaml +5 -0
- data/sample/conf/store_to_idm.yaml +0 -0
- data/sample/lib/openidm_common_func.rb +46 -0
- data/spec/common_config_spec.rb +85 -85
- data/spec/config_spec.rb +7 -7
- data/spec/rbatch_spec.rb +1 -1
- metadata +8 -2
data/bin/rbatch-init
CHANGED
data/lib/rbatch.rb
CHANGED
@@ -2,108 +2,48 @@ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)))
|
|
2
2
|
require 'yaml'
|
3
3
|
|
4
4
|
module RBatch
|
5
|
-
@@
|
6
|
-
@@program_base = nil
|
7
|
-
@@program_path = nil
|
8
|
-
@@home_dir = nil
|
9
|
-
@@run_conf_path = nil
|
10
|
-
@@run_conf_fpath = nil
|
11
|
-
@@run_conf = nil
|
12
|
-
@@config = nil
|
13
|
-
@@common_config = nil
|
14
|
-
@@journal_verbose = 3
|
15
|
-
@@journal_verbose_map = { :error => 1, :warn => 2, :info => 3, :debug => 4}
|
16
|
-
@@journals = []
|
17
|
-
@@logs = []
|
5
|
+
@@ctrl = nil
|
18
6
|
module_function
|
19
|
-
def program_name ; @@program_name ; end
|
20
|
-
def program_base ; @@program_base ; end
|
21
|
-
def program_path ; @@program_path ; end
|
22
|
-
def home_dir ; @@home_dir ; end
|
23
|
-
def run_conf_path ; @@run_conf_path ; end
|
24
|
-
def run_conf ; @@run_conf ; end
|
25
|
-
def conf_dir ; @@run_conf[:conf_dir].gsub("<home>",@@home_dir) ; end
|
26
|
-
def log_dir ; @@run_conf[:log_dir].gsub("<home>",@@home_dir) ; end
|
27
|
-
def lib_dir ; @@run_conf[:lib_dir].gsub("<home>",@@home_dir) ; end
|
28
|
-
def config ; @@config ; end
|
29
|
-
def common_config ; @@common_config ; end
|
30
|
-
def journals ; @@journals ; end
|
31
|
-
def add_log(log)
|
32
|
-
@@logs << log
|
33
|
-
end
|
34
|
-
def journal(level,str)
|
35
|
-
if @@journal_verbose_map[level] <= @@journal_verbose
|
36
|
-
str = "[RBatch] " + str
|
37
|
-
puts str
|
38
|
-
@@journals << str
|
39
|
-
@@logs.each do |log|
|
40
|
-
if RBatch.run_conf[:mix_rbatch_msg_to_log]
|
41
|
-
log.journal(str)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
7
|
def init
|
47
|
-
@@
|
48
|
-
RBatch.journal :info,"=== START RBatch === (PID=#{$$.to_s})"
|
49
|
-
@@program_name = $PROGRAM_NAME
|
50
|
-
@@program_base = File.basename($PROGRAM_NAME)
|
51
|
-
@@program_path = File.expand_path(@@program_name)
|
52
|
-
if ENV["RB_HOME"]
|
53
|
-
@@home_dir = File.expand_path(ENV["RB_HOME"])
|
54
|
-
RBatch.journal :debug,"RB_HOME : \"#{@@home_dir}\" (defined by $RB_HOME)"
|
55
|
-
else
|
56
|
-
@@home_dir = File.expand_path(File.join(File.dirname(@@program_name) , ".."))
|
57
|
-
RBatch.journal :debug,"RB_HOME : \"#{@@home_dir}\" (default)"
|
58
|
-
end
|
59
|
-
@@run_conf_path = File.join(@@home_dir,".rbatchrc")
|
60
|
-
RBatch.journal :info,"Load Run-Conf: \"#{@@run_conf_path}\""
|
61
|
-
@@run_conf = RunConf.new(@@run_conf_path,@@home_dir)
|
62
|
-
RBatch.journal :debug,"RBatch option : #{@@run_conf.inspect}"
|
63
|
-
@@common_config = RBatch::CommonConfig.new
|
64
|
-
RBatch.journal :info,"Load Config : \"#{@@common_config.path}\"" if @@common_config.exist?
|
65
|
-
@@config = RBatch::Config.new
|
66
|
-
RBatch.journal :info,"Load Config : \"#{@@config.path}\"" if @@config.exist?
|
8
|
+
@@ctrl = RBatch::Controller.new
|
67
9
|
end
|
68
|
-
def
|
69
|
-
|
70
|
-
@@config = RBatch::Config.new
|
71
|
-
RBatch.journal :info, "Load Config : \"#{@@config.path}\""
|
72
|
-
rescue Errno::ENOENT => e
|
73
|
-
end
|
10
|
+
def ctrl
|
11
|
+
@@ctrl
|
74
12
|
end
|
75
|
-
def
|
76
|
-
|
77
|
-
@@common_config = RBatch::CommonConfig.new
|
78
|
-
RBatch.journal :info,"Load Config : \"#{@@common_config.path}\""
|
79
|
-
rescue Errno::ENOENT => e
|
80
|
-
end
|
13
|
+
def run_conf
|
14
|
+
@@ctrl.run_conf
|
81
15
|
end
|
16
|
+
def run_conf_path ; @@ctrl.run_conf_path ; end
|
17
|
+
|
18
|
+
# Config Reader
|
19
|
+
#
|
20
|
+
# Read config file and return hash opject. If the key does not exist in config file, raise RBatch::Config::Exception.
|
21
|
+
#
|
22
|
+
# Default config file path is "${RB_HOME}/conf/(program base name).yaml"
|
23
|
+
# ==== Sample
|
24
|
+
# config : ${RB_HOME}/conf/sample2.yaml
|
25
|
+
# key: value
|
26
|
+
# array:
|
27
|
+
# - item1
|
28
|
+
# - item2
|
29
|
+
# - item3
|
30
|
+
# script : ${RB_HOME}/bin/sample2.rb
|
31
|
+
# require 'rbatch'
|
32
|
+
# p RBatch::Config.new
|
33
|
+
# # or p RBatch::config
|
34
|
+
# => {"key" => "value", "array" => ["item1", "item2", "item3"]}
|
35
|
+
def config ; @@ctrl.config ; end
|
36
|
+
def common_config ; @@ctrl.common_config ; end
|
37
|
+
def journal(a,b) ; @@ctrl.journal(a,b) ; end
|
82
38
|
end
|
83
39
|
|
84
40
|
# main
|
41
|
+
require 'rbatch/controller'
|
85
42
|
require 'rbatch/run_conf'
|
86
43
|
require 'rbatch/double_run_checker'
|
87
44
|
require 'rbatch/log'
|
88
45
|
require 'rbatch/config'
|
89
|
-
require 'rbatch/common_config'
|
90
46
|
require 'rbatch/cmd'
|
91
47
|
|
92
48
|
RBatch::init
|
93
49
|
|
94
|
-
if ( RBatch.run_conf[:forbid_double_run] )
|
95
|
-
RBatch::DoubleRunChecker.check(File.basename(RBatch.program_name)) #raise error if check is NG
|
96
|
-
RBatch::DoubleRunChecker.make_lock_file(File.basename(RBatch.program_name))
|
97
|
-
end
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
if RBatch.run_conf[:auto_lib_load] && Dir.exist?(RBatch.lib_dir)
|
102
|
-
Dir::foreach(RBatch.lib_dir) do |file|
|
103
|
-
if /.*rb/ =~ file
|
104
|
-
require File.join(RBatch.lib_dir,File.basename(file,".rb"))
|
105
|
-
RBatch.journal :info, "Load Library : \"#{File.join(RBatch.lib_dir,file)}\" "
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
RBatch.journal :info,"Start Script : \"#{RBatch.program_path}\""
|
data/lib/rbatch/common_config.rb
CHANGED
@@ -1,71 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
require 'pathname'
|
3
|
-
|
4
|
-
module RBatch
|
5
|
-
|
6
|
-
module_function
|
7
|
-
# Common-config Reader
|
8
|
-
#
|
9
|
-
# Read common config file and return hash opject. If the key does not exist in config file, raise RBatch::CommonConfig::Exception.
|
10
|
-
#
|
11
|
-
# Default common config file path is "${RB_HOME}/conf/common.yaml"
|
12
|
-
# ==== Sample
|
13
|
-
# config : ${RB_HOME}/conf/common.yaml
|
14
|
-
# key: value
|
15
|
-
# array:
|
16
|
-
# - item1
|
17
|
-
# - item2
|
18
|
-
# - item3
|
19
|
-
# script : ${RB_HOME}/bin/sample.rb
|
20
|
-
# require 'rbatch'
|
21
|
-
# p RBatch::common_config
|
22
|
-
# => {"key" => "value", "array" => ["item1", "item2", "item3"]}
|
23
|
-
class CommonConfig
|
24
|
-
@path
|
25
|
-
@hash
|
26
|
-
def initialize
|
27
|
-
file = RBatch.run_conf[:common_conf_name]
|
28
|
-
@path = File.join(RBatch.conf_dir,file)
|
29
|
-
begin
|
30
|
-
@hash = YAML::load_file(@path)
|
31
|
-
rescue Errno::ENOENT => e
|
32
|
-
@hash = nil
|
33
|
-
end
|
34
|
-
end
|
35
|
-
def[](key)
|
36
|
-
if @hash.nil?
|
37
|
-
raise RBatch::CommonConfig::Exception, "Common Config file \"#{@path}\" does not exist"
|
38
|
-
end
|
39
|
-
if @hash[key].nil?
|
40
|
-
if key.class == Symbol
|
41
|
-
raise RBatch::CommonConfig::Exception, "Value of key(:#{key} (Symbol)) is nil. By any chance, dou you mistake key class Symbol for String?"
|
42
|
-
elsif key.class == String
|
43
|
-
raise RBatch::CommonConfig::Exception, "Value of key(\"#{key}\" (String)) is nil"
|
44
|
-
else
|
45
|
-
raise RBatch::CommonConfig::Exception, "Value of key(#{key}) is nil"
|
46
|
-
end
|
47
|
-
else
|
48
|
-
@hash[key]
|
49
|
-
end
|
50
|
-
end
|
51
|
-
def path ; @path ; end
|
52
|
-
def exist? ; ! @hash.nil? ; end
|
53
|
-
def to_h
|
54
|
-
if @hash.nil?
|
55
|
-
raise RBatch::CommonConfig::Exception, "Common Config file \"#{@path}\" does not exist"
|
56
|
-
else
|
57
|
-
@hash
|
58
|
-
end
|
59
|
-
end
|
60
|
-
def to_s
|
61
|
-
if @hash.nil?
|
62
|
-
raise RBatch::CommonConfig::Exception, "Common Config file \"#{@path}\" does not exist"
|
63
|
-
else
|
64
|
-
@hash.to_s
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
class RBatch::CommonConfig::Exception < Exception; end
|
70
|
-
end
|
71
|
-
|
data/lib/rbatch/config.rb
CHANGED
@@ -3,30 +3,11 @@ require 'pathname'
|
|
3
3
|
|
4
4
|
module RBatch
|
5
5
|
|
6
|
-
module_function
|
7
|
-
# Config Reader
|
8
|
-
#
|
9
|
-
# Read config file and return hash opject. If the key does not exist in config file, raise RBatch::Config::Exception.
|
10
|
-
#
|
11
|
-
# Default config file path is "${RB_HOME}/conf/(program base name).yaml"
|
12
|
-
# ==== Sample
|
13
|
-
# config : ${RB_HOME}/conf/sample2.yaml
|
14
|
-
# key: value
|
15
|
-
# array:
|
16
|
-
# - item1
|
17
|
-
# - item2
|
18
|
-
# - item3
|
19
|
-
# script : ${RB_HOME}/bin/sample2.rb
|
20
|
-
# require 'rbatch'
|
21
|
-
# p RBatch::Config.new
|
22
|
-
# # or p RBatch::config
|
23
|
-
# => {"key" => "value", "array" => ["item1", "item2", "item3"]}
|
24
6
|
class Config
|
25
7
|
@path
|
26
8
|
@hash
|
27
|
-
def initialize
|
28
|
-
|
29
|
-
@path = File.join(RBatch.conf_dir,file)
|
9
|
+
def initialize(path)
|
10
|
+
@path = path
|
30
11
|
begin
|
31
12
|
@hash = YAML::load_file(@path)
|
32
13
|
rescue Errno::ENOENT => e
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module RBatch
|
2
|
+
class Controller
|
3
|
+
@@journal_verbose_map = { :error => 1, :warn => 2, :info => 3, :debug => 4}
|
4
|
+
attr :program_name,:program_path
|
5
|
+
attr :home_dir,:log_dir,:conf_dir,:lib_dir
|
6
|
+
attr :run_conf_path, :run_conf
|
7
|
+
attr :config, :config_path
|
8
|
+
attr :common_config, :common_config_path
|
9
|
+
attr :journals,:logs
|
10
|
+
def initialize
|
11
|
+
@journals = []
|
12
|
+
@logs = []
|
13
|
+
if ENV["RB_VERBOSE"]
|
14
|
+
@journal_verbose = ENV["RB_VERBOSE"].to_i
|
15
|
+
else
|
16
|
+
@journal_verbose = 3
|
17
|
+
end
|
18
|
+
@program_name = $PROGRAM_NAME
|
19
|
+
@program_base = File.basename($PROGRAM_NAME)
|
20
|
+
@program_path = File.expand_path(@program_name)
|
21
|
+
if ENV["RB_HOME"]
|
22
|
+
@home_dir = File.expand_path(ENV["RB_HOME"])
|
23
|
+
else
|
24
|
+
@home_dir = File.expand_path(File.join(File.dirname(@program_name) , ".."))
|
25
|
+
end
|
26
|
+
@run_conf_path = File.join(@home_dir,".rbatchrc")
|
27
|
+
@run_conf = RunConf.new(@run_conf_path,@home_dir)
|
28
|
+
journal :info, "=== START RBatch === (PID=#{$$.to_s})"
|
29
|
+
journal :debug,"RB_HOME : \"#{@home_dir}\""
|
30
|
+
journal :info, "Load Run-Conf: \"#{@run_conf_path}\""
|
31
|
+
journal :debug,"RBatch option : #{@run_conf.inspect}"
|
32
|
+
@lib_dir = @run_conf[:lib_dir].gsub("<home>",@home_dir)
|
33
|
+
@conf_dir = @run_conf[:conf_dir].gsub("<home>",@home_dir)
|
34
|
+
@log_dir = @run_conf[:log_dir].gsub("<home>",@home_dir)
|
35
|
+
# common config
|
36
|
+
@common_config_path = File.join(@conf_dir,@run_conf[:common_conf_name])
|
37
|
+
@common_config = RBatch::Config.new(@common_config_path)
|
38
|
+
journal :info, "Load Config : \"#{@common_config_path}\"" if ! @common_config.nil?
|
39
|
+
# user config
|
40
|
+
@config_path = File.join(@conf_dir,Pathname(File.basename(@program_name)).sub_ext(".yaml").to_s)
|
41
|
+
@config = RBatch::Config.new(@config_path)
|
42
|
+
journal :info, "Load Config : \"#{@config_path}\"" if ! @config.nil?
|
43
|
+
# double_run_check
|
44
|
+
if ( @run_conf[:forbid_double_run] )
|
45
|
+
RBatch::DoubleRunChecker.check(@program_base) #raise error if check is NG
|
46
|
+
RBatch::DoubleRunChecker.make_lock_file(@program_base)
|
47
|
+
end
|
48
|
+
# load_lib
|
49
|
+
if @run_conf[:auto_lib_load] && Dir.exist?(@lib_dir)
|
50
|
+
Dir::foreach(@lib_dir) do |file|
|
51
|
+
if /.*rb/ =~ file
|
52
|
+
require File.join(@lib_dir,File.basename(file,".rb"))
|
53
|
+
journal :info, "Load Library : \"#{File.join(@lib_dir,file)}\" "
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
journal :info,"Start Script : \"#{@program_path}\""
|
58
|
+
end #end def
|
59
|
+
def journal(level,str)
|
60
|
+
if @@journal_verbose_map[level] <= @journal_verbose
|
61
|
+
str = "[RBatch] " + str
|
62
|
+
puts str
|
63
|
+
@journals << str
|
64
|
+
@logs.each do |log|
|
65
|
+
if RBatch.run_conf[:mix_rbatch_msg_to_log]
|
66
|
+
log.journal(str)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
def add_log(log)
|
72
|
+
@logs << log
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/rbatch/log.rb
CHANGED
@@ -90,13 +90,13 @@ module RBatch
|
|
90
90
|
end
|
91
91
|
|
92
92
|
# determine log file name
|
93
|
-
@prog_base = Pathname(File.basename(RBatch.program_name)).sub_ext("").to_s
|
93
|
+
@prog_base = Pathname(File.basename(RBatch.ctrl.program_name)).sub_ext("").to_s
|
94
94
|
@file_name = @opt[:log_name].clone
|
95
95
|
@file_name.gsub!("<date>", Time.now.strftime("%Y%m%d"))
|
96
96
|
@file_name.gsub!("<time>", Time.now.strftime("%H%M%S"))
|
97
97
|
@file_name.gsub!("<prog>", @prog_base)
|
98
98
|
@file_name.gsub!("<host>", @opt[:log_hostname])
|
99
|
-
@log_dir = @opt[:log_dir].gsub("<home>",RBatch.home_dir)
|
99
|
+
@log_dir = @opt[:log_dir].gsub("<home>",RBatch.ctrl.home_dir)
|
100
100
|
path = File.join(@log_dir,@file_name)
|
101
101
|
# create Logger instance
|
102
102
|
begin
|
@@ -106,7 +106,7 @@ module RBatch
|
|
106
106
|
@log = Logger.new(open(path,"w"))
|
107
107
|
end
|
108
108
|
rescue Errno::ENOENT => e
|
109
|
-
RBatch.journal :error, "Can not open log file - #{path}"
|
109
|
+
RBatch.ctrl.journal :error, "Can not open log file - #{path}"
|
110
110
|
raise e
|
111
111
|
end
|
112
112
|
# set logger option
|
@@ -126,15 +126,15 @@ module RBatch
|
|
126
126
|
@stdout_log.level = @@log_level_map[@opt[:log_level]]
|
127
127
|
@stdout_log.formatter = formatter
|
128
128
|
end
|
129
|
-
RBatch.journal :info,"Start Logging: \"#{path}\""
|
129
|
+
RBatch.ctrl.journal :info,"Start Logging: \"#{path}\""
|
130
130
|
# delete old log
|
131
131
|
self.delete_old_log(@opt[:log_delete_old_log_date]) if @opt[:log_delete_old_log]
|
132
132
|
# Firstly write journal to log
|
133
133
|
if RBatch.run_conf[:mix_rbatch_msg_to_log]
|
134
|
-
RBatch.journals.each do |str|
|
134
|
+
RBatch.ctrl.journals.each do |str|
|
135
135
|
self.journal(str)
|
136
136
|
end
|
137
|
-
RBatch.add_log(self)
|
137
|
+
RBatch.ctrl.add_log(self)
|
138
138
|
end
|
139
139
|
# Start logging
|
140
140
|
if block_given?
|
@@ -215,7 +215,7 @@ module RBatch
|
|
215
215
|
body = <<EOT
|
216
216
|
From: <#{@opt[:log_mail_from]}>
|
217
217
|
To: <#{@opt[:log_mail_to]}>
|
218
|
-
Subject: [RBatch] #{RBatch.program_name} has error
|
218
|
+
Subject: [RBatch] #{RBatch.ctrl.program_name} has error
|
219
219
|
Date: #{Time::now.strftime("%a, %d %b %Y %X %z")}
|
220
220
|
Mime-Version: 1.0
|
221
221
|
Content-Type: text/plain; charset=ISO-2022-JP
|
data/lib/rbatch/version.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "rbatch"
|
2
|
+
require "net/ftp"
|
3
|
+
|
4
|
+
server=""
|
5
|
+
user=""
|
6
|
+
password=""
|
7
|
+
target_files=["",""]
|
8
|
+
|
9
|
+
RBatch::Log.new do | log |
|
10
|
+
ftp = Net::FTP.new(server,user,password)
|
11
|
+
log.info("ftp login: server=#{server},user=#{user},password=#{password}")
|
12
|
+
ftp.login
|
13
|
+
ftp.passive = true
|
14
|
+
ftp.chdir('pub/ruby')
|
15
|
+
files = ftp.list('ruby*')
|
16
|
+
target_files.each do |file|
|
17
|
+
ftp.getbinaryfile(file)
|
18
|
+
end
|
19
|
+
ftp.close
|
20
|
+
end
|
File without changes
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'rbatch'
|
3
|
+
|
4
|
+
require 'net/http'
|
5
|
+
require 'net/http/post/multipart'
|
6
|
+
|
7
|
+
# Send file-upload request to OpenIDM
|
8
|
+
# @param category : openidf file category
|
9
|
+
# @param filepath : file
|
10
|
+
# @param log : RBatch::Log instance
|
11
|
+
#
|
12
|
+
# do same
|
13
|
+
# curl --header "X-OpenIDM-Username: openidm-admin" --header "X-OpenIDM-Password: openidm-admin" -F file=@"D:\test.pdf" "http://localhost:8080/openidm/filerepo/cat/?_action=upload&save=true"
|
14
|
+
def store_file_to_openidm(category,filepath,log)
|
15
|
+
server = RBatch.common_config["openidm"]["server"]
|
16
|
+
port = RBatch.common_config["openidm"]["port"]
|
17
|
+
path = "/openidm/filerepo/#{category}/?_action=upload&save=true"
|
18
|
+
param = "_action=upload&save=true"
|
19
|
+
headers = {
|
20
|
+
"X-OpenIDM-Username" => RBatch.common_config["openidm"]["api_user"],
|
21
|
+
"X-OpenIDM-Password" => RBatch.common_config["openidm"]["api_pass"]
|
22
|
+
}
|
23
|
+
File.open(filepath) do |file|
|
24
|
+
http = Net::HTTP.new(server,port)
|
25
|
+
http.use_ssl = true
|
26
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
27
|
+
request = Net::HTTP::Post::Multipart.new(
|
28
|
+
path,
|
29
|
+
{"file" => UploadIO.new(file, "image/jpeg", "image.jpg")},
|
30
|
+
headers)
|
31
|
+
|
32
|
+
log.info("upload file: " + file.path)
|
33
|
+
log.info("post url: http://#{server}:#{port}#{path}" )
|
34
|
+
log.info("header: #{request.to_hash}" )
|
35
|
+
|
36
|
+
response = http.request(request) #send request
|
37
|
+
|
38
|
+
log.info("response code: #{response.message} #{response.code}")
|
39
|
+
response.body.split("\n").each {|l| log.info("response body: #{l}")}
|
40
|
+
if response.code == 200 || response.code == 201 || response.code == 202
|
41
|
+
log.info("Success to upload file to OpenIDM");
|
42
|
+
else
|
43
|
+
raise "Faild to upload file to OpenIDM"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/spec/common_config_spec.rb
CHANGED
@@ -1,85 +1,85 @@
|
|
1
|
-
require File.expand_path(File.join( File.dirname(__FILE__), 'spec_helper'))
|
2
|
-
|
3
|
-
require 'rbatch'
|
4
|
-
|
5
|
-
describe RBatch::
|
6
|
-
before :all do
|
7
|
-
@config_dir=File.join(ENV["RB_HOME"],"conf")
|
8
|
-
@config_file = File.join(@config_dir , "common.yaml")
|
9
|
-
Dir::mkdir @config_dir if ! Dir.exists? @config_dir
|
10
|
-
end
|
11
|
-
|
12
|
-
before :each do
|
13
|
-
end
|
14
|
-
|
15
|
-
after :each do
|
16
|
-
FileUtils.rm @config_file if File.exists? @config_file
|
17
|
-
end
|
18
|
-
|
19
|
-
after :all do
|
20
|
-
end
|
21
|
-
|
22
|
-
it "read config" do
|
23
|
-
open( @config_file , "w" ){|f| f.write("key: value")}
|
24
|
-
RBatch.
|
25
|
-
expect(RBatch.common_config["key"]).to eq "value"
|
26
|
-
end
|
27
|
-
|
28
|
-
it "read config. Key is Symbol" do
|
29
|
-
open( @config_file , "w" ){|f| f.write(":key: value")}
|
30
|
-
RBatch.
|
31
|
-
expect(RBatch.common_config[:key]).to eq "value"
|
32
|
-
end
|
33
|
-
|
34
|
-
it "raise error when config does not exist" do
|
35
|
-
RBatch.
|
36
|
-
expect {
|
37
|
-
RBatch.common_config["hoge"]
|
38
|
-
}.to raise_error(RBatch::
|
39
|
-
expect {
|
40
|
-
RBatch.common_config.to_h
|
41
|
-
}.to raise_error(RBatch::
|
42
|
-
expect {
|
43
|
-
RBatch.common_config.to_s
|
44
|
-
}.to raise_error(RBatch::
|
45
|
-
end
|
46
|
-
|
47
|
-
it "read config twice" do
|
48
|
-
open( @config_file , "w" ){|f| f.write("key: value")}
|
49
|
-
RBatch.
|
50
|
-
expect(RBatch.common_config["key"]).to eq "value"
|
51
|
-
expect(RBatch.common_config["key"]).to eq "value"
|
52
|
-
end
|
53
|
-
|
54
|
-
it "raise error when read value which key does not exist" do
|
55
|
-
open( @config_file , "w" ){|f| f.write("key: value")}
|
56
|
-
RBatch.
|
57
|
-
expect {
|
58
|
-
RBatch.common_config["not_exist"]
|
59
|
-
}.to raise_error(RBatch::
|
60
|
-
end
|
61
|
-
|
62
|
-
it "raise error when read value which key mistake String for Symbol" do
|
63
|
-
open( @config_file , "w" ){|f| f.write(":key: value")}
|
64
|
-
RBatch.
|
65
|
-
expect {
|
66
|
-
RBatch.common_config["key"]
|
67
|
-
}.to raise_error(RBatch::
|
68
|
-
end
|
69
|
-
|
70
|
-
it "raise error when read value which key mistake Symbol for String" do
|
71
|
-
open( @config_file , "w" ){|f| f.write("key: value")}
|
72
|
-
RBatch.
|
73
|
-
expect {
|
74
|
-
RBatch.common_config[:key]
|
75
|
-
}.to raise_error(RBatch::
|
76
|
-
end
|
77
|
-
|
78
|
-
it "success when common_conf_name changed" do
|
79
|
-
conf=File.join(RBatch.conf_dir,"global.yaml")
|
80
|
-
open( conf , "w" ){|f| f.write("key4: value4")}
|
81
|
-
RBatch.
|
82
|
-
RBatch.
|
83
|
-
expect(RBatch.common_config["key4"]).to eq "value4"
|
84
|
-
end
|
85
|
-
end
|
1
|
+
require File.expand_path(File.join( File.dirname(__FILE__), 'spec_helper'))
|
2
|
+
|
3
|
+
require 'rbatch'
|
4
|
+
|
5
|
+
describe RBatch::Config do
|
6
|
+
before :all do
|
7
|
+
@config_dir=File.join(ENV["RB_HOME"],"conf")
|
8
|
+
@config_file = File.join(@config_dir , "common.yaml")
|
9
|
+
Dir::mkdir @config_dir if ! Dir.exists? @config_dir
|
10
|
+
end
|
11
|
+
|
12
|
+
before :each do
|
13
|
+
end
|
14
|
+
|
15
|
+
after :each do
|
16
|
+
FileUtils.rm @config_file if File.exists? @config_file
|
17
|
+
end
|
18
|
+
|
19
|
+
after :all do
|
20
|
+
end
|
21
|
+
|
22
|
+
it "read config" do
|
23
|
+
open( @config_file , "w" ){|f| f.write("key: value")}
|
24
|
+
RBatch.init
|
25
|
+
expect(RBatch.common_config["key"]).to eq "value"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "read config. Key is Symbol" do
|
29
|
+
open( @config_file , "w" ){|f| f.write(":key: value")}
|
30
|
+
RBatch.init
|
31
|
+
expect(RBatch.common_config[:key]).to eq "value"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "raise error when config does not exist" do
|
35
|
+
RBatch.init
|
36
|
+
expect {
|
37
|
+
RBatch.common_config["hoge"]
|
38
|
+
}.to raise_error(RBatch::Config::Exception)
|
39
|
+
expect {
|
40
|
+
RBatch.common_config.to_h
|
41
|
+
}.to raise_error(RBatch::Config::Exception)
|
42
|
+
expect {
|
43
|
+
RBatch.common_config.to_s
|
44
|
+
}.to raise_error(RBatch::Config::Exception)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "read config twice" do
|
48
|
+
open( @config_file , "w" ){|f| f.write("key: value")}
|
49
|
+
RBatch.init
|
50
|
+
expect(RBatch.common_config["key"]).to eq "value"
|
51
|
+
expect(RBatch.common_config["key"]).to eq "value"
|
52
|
+
end
|
53
|
+
|
54
|
+
it "raise error when read value which key does not exist" do
|
55
|
+
open( @config_file , "w" ){|f| f.write("key: value")}
|
56
|
+
RBatch.init
|
57
|
+
expect {
|
58
|
+
RBatch.common_config["not_exist"]
|
59
|
+
}.to raise_error(RBatch::Config::Exception)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "raise error when read value which key mistake String for Symbol" do
|
63
|
+
open( @config_file , "w" ){|f| f.write(":key: value")}
|
64
|
+
RBatch.init
|
65
|
+
expect {
|
66
|
+
RBatch.common_config["key"]
|
67
|
+
}.to raise_error(RBatch::Config::Exception)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "raise error when read value which key mistake Symbol for String" do
|
71
|
+
open( @config_file , "w" ){|f| f.write("key: value")}
|
72
|
+
RBatch.init
|
73
|
+
expect {
|
74
|
+
RBatch.common_config[:key]
|
75
|
+
}.to raise_error(RBatch::Config::Exception)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "success when common_conf_name changed" do
|
79
|
+
conf=File.join(RBatch.ctrl.conf_dir,"global.yaml")
|
80
|
+
open( conf , "w" ){|f| f.write("key4: value4")}
|
81
|
+
open( RBatch.run_conf_path , "w" ){|f| f.write("common_conf_name: global.yaml")}
|
82
|
+
RBatch.init
|
83
|
+
expect(RBatch.common_config["key4"]).to eq "value4"
|
84
|
+
end
|
85
|
+
end
|
data/spec/config_spec.rb
CHANGED
@@ -21,18 +21,18 @@ describe RBatch::Config do
|
|
21
21
|
|
22
22
|
it "read config" do
|
23
23
|
open( @config_file , "w" ){|f| f.write("key: value")}
|
24
|
-
RBatch.
|
24
|
+
RBatch.init
|
25
25
|
expect(RBatch.config["key"]).to eq "value"
|
26
26
|
end
|
27
27
|
|
28
28
|
it "read config. Key is Symbol" do
|
29
29
|
open( @config_file , "w" ){|f| f.write(":key: value")}
|
30
|
-
RBatch.
|
30
|
+
RBatch.init
|
31
31
|
expect(RBatch.config[:key]).to eq "value"
|
32
32
|
end
|
33
33
|
|
34
34
|
it "raise error when config does not exist" do
|
35
|
-
RBatch.
|
35
|
+
RBatch.init
|
36
36
|
expect {
|
37
37
|
RBatch.config["hoge"]
|
38
38
|
}.to raise_error(RBatch::Config::Exception)
|
@@ -46,14 +46,14 @@ describe RBatch::Config do
|
|
46
46
|
|
47
47
|
it "read config twice" do
|
48
48
|
open( @config_file , "w" ){|f| f.write("key: value")}
|
49
|
-
RBatch.
|
49
|
+
RBatch.init
|
50
50
|
expect(RBatch.config["key"]).to eq "value"
|
51
51
|
expect(RBatch.config["key"]).to eq "value"
|
52
52
|
end
|
53
53
|
|
54
54
|
it "raise error when read value which key does not exist" do
|
55
55
|
open( @config_file , "w" ){|f| f.write("key: value")}
|
56
|
-
RBatch.
|
56
|
+
RBatch.init
|
57
57
|
expect {
|
58
58
|
RBatch.config["not_exist"]
|
59
59
|
}.to raise_error(RBatch::Config::Exception)
|
@@ -61,7 +61,7 @@ describe RBatch::Config do
|
|
61
61
|
|
62
62
|
it "raise error when read value which key mistake String for Symbol" do
|
63
63
|
open( @config_file , "w" ){|f| f.write("key: value")}
|
64
|
-
RBatch.
|
64
|
+
RBatch.init
|
65
65
|
expect {
|
66
66
|
RBatch.config[:key]
|
67
67
|
}.to raise_error(RBatch::Config::Exception)
|
@@ -69,7 +69,7 @@ describe RBatch::Config do
|
|
69
69
|
|
70
70
|
it "raise error when read value which key mistake Symbol for String" do
|
71
71
|
open( @config_file , "w" ){|f| f.write(":key: value")}
|
72
|
-
RBatch.
|
72
|
+
RBatch.init
|
73
73
|
expect {
|
74
74
|
RBatch.config["key"]
|
75
75
|
}.to raise_error(RBatch::Config::Exception)
|
data/spec/rbatch_spec.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: rbatch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 2.1.
|
5
|
+
version: 2.1.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- fetaro
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2014-01-
|
13
|
+
date: 2014-01-10 00:00:00 Z
|
14
14
|
dependencies: []
|
15
15
|
|
16
16
|
description: RBatch has many fanctions to help with your making a batch script such as "data backup script" or "proccess starting script".
|
@@ -83,6 +83,7 @@ files:
|
|
83
83
|
- lib/rbatch/cmd.rb
|
84
84
|
- lib/rbatch/common_config.rb
|
85
85
|
- lib/rbatch/config.rb
|
86
|
+
- lib/rbatch/controller.rb
|
86
87
|
- lib/rbatch/double_run_checker.rb
|
87
88
|
- lib/rbatch/log.rb
|
88
89
|
- lib/rbatch/run_conf.rb
|
@@ -91,17 +92,21 @@ files:
|
|
91
92
|
- sample/.rbatchrc
|
92
93
|
- sample/bin/apache_log_insert.rb
|
93
94
|
- sample/bin/file_batch_copy.rb
|
95
|
+
- sample/bin/ftp_get.rb
|
94
96
|
- sample/bin/log_backup.rb
|
95
97
|
- sample/bin/mysql_data_backup.rb
|
96
98
|
- sample/bin/openam_log_insert.rb
|
97
99
|
- sample/bin/openldap_backup.rb
|
100
|
+
- sample/bin/store_to_idm.rb
|
98
101
|
- sample/bin/webagent_log_insert.rb
|
99
102
|
- sample/conf/apache_log_insert.yaml
|
103
|
+
- sample/conf/common.yaml
|
100
104
|
- sample/conf/file_batch_copy.yaml
|
101
105
|
- sample/conf/log_backup.yaml
|
102
106
|
- sample/conf/mysql_data_backup.yaml
|
103
107
|
- sample/conf/openam_log_insert.yaml
|
104
108
|
- sample/conf/openldap_backup.yaml
|
109
|
+
- sample/conf/store_to_idm.yaml
|
105
110
|
- sample/conf/webagent_log_insert.yaml
|
106
111
|
- sample/data/access_log.1
|
107
112
|
- sample/data/access_log.2012-07-10
|
@@ -111,6 +116,7 @@ files:
|
|
111
116
|
- sample/data/amAuthentication.access.2012-07-10
|
112
117
|
- sample/data/amAuthentication.error.1
|
113
118
|
- sample/data/amAuthentication.error.2012-07-10
|
119
|
+
- sample/lib/openidm_common_func.rb
|
114
120
|
- sample/log/empty
|
115
121
|
- spec/cmd_spec.rb
|
116
122
|
- spec/common_config_spec.rb
|