Module: JvmwatcherUtil

Defined in:
lib/fluent/plugin/jvmwatcher_util.rb

Constant Summary collapse

SetEnvFileName =
"setEnvWatcher.sh"
Log4JFileName =
"log4j.xml"
SetEnvTemplateFileName =
"setEnv.sh.template"
Log4JTemplateFileName =
"log4j.xml.template"
BinDirName =
"bin"
LibDirName =
"lib"
ConfigDirName =
"config"
LogDirName =
"log"

Class Method Summary collapse

Class Method Details

.find_filter_config_path(config_path) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/fluent/plugin/jvmwatcher_util.rb', line 109

def find_filter_config_path (config_path)

  # check nil
  return "NO_CONFIG" unless config_path

  unless File.file?(config_path)

    path = find_watcher_java_path(ConfigDirName)
    config_path = File.join(path, config_path)
    config_path = "NO_CONFIG" unless File.file?(config_path)

  end

  return config_path
end

.find_watcher_java_path(dir_name, file_name = nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fluent/plugin/jvmwatcher_util.rb', line 14

def find_watcher_java_path (dir_name, file_name = nil)

  java_path = nil

  # find java command path
  $LOAD_PATH.map do |load_path|
    path = File.join(load_path, "fluent/plugin")  # make fluentd plugin path
    if File.directory?(path)

      # find target java directory
      path_name = "#{path}/jvmwatcher/#{dir_name}"
      
      next unless File.directory?(path_name)  # chech directory

      if file_name
        # check file
        java_path = File.join(path_name, file_name)
        java_path = nil unless File.file?(java_path)
      else
        java_path = path_name
      end

      break if java_path
    end
  end

  return java_path
end

.make_log4j_fileObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/fluent/plugin/jvmwatcher_util.rb', line 78

def make_log4j_file

  template_path = find_watcher_java_path(ConfigDirName, Log4JTemplateFileName)
  output_path = find_watcher_java_path(ConfigDirName)
  log_path = find_watcher_java_path(LogDirName)

  # path nil check
  return nil unless template_path
  return nil unless output_path
  return nil unless log_path

  output_path = File.join(output_path, Log4JFileName)
  # make setEnvWatcher.sh
  temp_io = File.open(template_path, "r")
  env_io = File.open(output_path, "w")

  temp_io.each do |line|
    line.chomp!
    line = line.gsub(/\[LOG_PATH\]/, log_path)

    env_io.puts(line)
  end

  temp_io.close
  env_io.close 

  return output_path

end

.make_setenv_fileObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/fluent/plugin/jvmwatcher_util.rb', line 44

def make_setenv_file

  template_path = find_watcher_java_path(BinDirName, SetEnvTemplateFileName)
  output_path = find_watcher_java_path(BinDirName)
  lib_path = find_watcher_java_path(LibDirName)
  config_path = find_watcher_java_path(ConfigDirName)

  # path nil check
  return nil unless template_path
  return nil unless output_path
  return nil unless lib_path
  return nil unless config_path

  output_path = File.join(output_path, SetEnvFileName)
  # make setEnvWatcher.sh
  temp_io = File.open(template_path, "r")
  env_io = File.open(output_path, "w")

  temp_io.each do |line|
    line.chomp!
    line = line.gsub(/\[LIB_PATH\]/, lib_path)
    line = line.gsub(/\[CONFIG_PATH\]/, config_path)

    env_io.puts(line)
  end

  temp_io.close
  env_io.close 

  return output_path

end