rlogic 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/bin/wlst CHANGED
@@ -37,7 +37,7 @@ FileUtils::mkdir_p @scripts_dir
37
37
  FileUtils::mkdir_p @tmp_dir
38
38
 
39
39
  @script_file = "#{@tmp_dir}/wlst.py"
40
- @scrtip_log = "#{@tmp_dir}/out.log"
40
+ @script_log = "#{@tmp_dir}/out.log"
41
41
  @scrtip_output = "#{@tmp_dir}/out"
42
42
  servers_file = "#{@conf_dir}/servers.yaml"
43
43
  @servers_file = File.expand_path(servers_file)
@@ -47,7 +47,8 @@ weblogic[:wl_home] = (ENV["WL_HOME"] or Dir.pwd)
47
47
  invokes = {}
48
48
  mappings = {}
49
49
 
50
- resolver = WLST::ScriptResolver::new :scripts_dir => @scripts_dir
50
+ resolver = WLST::ScriptResolver::new :scripts_dir => @scripts_dir,
51
+ :redirect => @script_log
51
52
 
52
53
  def load_yaml
53
54
  return Hash::new unless File.exist?(@servers_file)
@@ -60,6 +61,7 @@ opts.on('--home PATH', 'Defines the WL_HOME variable') do |home|
60
61
  end
61
62
  opts.on('--host HOST', 'Defines the Weblogic host') do |host|
62
63
  weblogic[:host] = host
64
+ @connect = true
63
65
  end
64
66
  opts.on('--port PORT', 'Defines the Weblogic port') do |port|
65
67
  weblogic[:port] = port
@@ -71,6 +73,7 @@ opts.on('--connect SERVER_NAME',
71
73
  config.each do |key, value|
72
74
  weblogic[key.to_sym] = value
73
75
  end
76
+ @connect = true
74
77
  end
75
78
  opts.on('--save SERVER_NAME', "Saves the server configuration in #{servers_file}") do |server|
76
79
  save = (server or 'default')
@@ -87,7 +90,7 @@ opts.on('--print', 'Prints the script output') do
87
90
  end
88
91
 
89
92
  opts.on('--list', 'Lists available scripts') do
90
- puts "Available templates:"
93
+ puts "Available scripts:"
91
94
  resolver.scripts.each do |key, script|
92
95
  puts "\t#{key}"
93
96
  end
@@ -103,12 +106,14 @@ opts.on('--info SCRIPT', 'Shows info for selected script') do |script_key|
103
106
  end
104
107
  exit 0
105
108
  end
106
- opts.on('--monitor', 'Runs the script as a monitor') do
107
- resolver.monitor = true
109
+ opts.on('--loop INTERVAL', Float, 'Runs the script inside a loop') do |interval|
110
+ @monitor = true
111
+ @interval = interval
108
112
  end
109
113
 
110
114
  opts.on("-h", "--help", "Shows this help message") do
111
- puts opts; exit
115
+ puts opts
116
+ exit 0
112
117
  end
113
118
  opts.parse!(ARGV)
114
119
 
@@ -129,13 +134,6 @@ if save
129
134
  end
130
135
 
131
136
  @command = WLST::Command::new
132
- @command.redirect @scrtip_log, 'false'
133
-
134
- connect = (weblogic[:user] and weblogic[:password] and weblogic[:host] and weblogic[:port])
135
-
136
- if connect
137
- @command.connect(weblogic[:user], weblogic[:password], "t3://#{weblogic[:host]}:#{weblogic[:port]}")
138
- end
139
137
 
140
138
  invokes.each do |id, args|
141
139
  mappings[id]::new(@command).execute *args
@@ -152,24 +150,27 @@ unless ARGV.empty?
152
150
  :for => weblogic
153
151
  )
154
152
  else
153
+ if @connect
154
+ @command.connect(weblogic[:user], weblogic[:password], "t3://#{weblogic[:host]}:#{weblogic[:port]}")
155
+ end
155
156
  if ARGV.empty?
156
157
  @command.send script
157
158
  else
158
159
  ARGV.each { |arg| @command.send script, *(arg.split /,/) }
159
160
  end
161
+ if @connect
162
+ @command.disconnect
163
+ end
160
164
  end
161
165
  end
162
166
 
163
- if connect
164
- @command.disconnect
165
- end
166
-
167
167
  if @print
168
168
  puts @command.to_s
169
169
  else
170
170
  @command.to_f @script_file
171
- runner = WLST::Runner::new weblogic[:wl_home]
172
- result = runner.run @script_file
173
- puts result
174
- File.open(@scrtip_output, 'w') { |f| f.write result }
171
+ @runner = WLST::Runner::new :wl_home => weblogic[:wl_home],
172
+ :script_file => @script_file,
173
+ :output_file => @scrtip_output,
174
+ :print => true
175
+ @runner.run @interval
175
176
  end
@@ -26,8 +26,12 @@ require_relative "wlst/wlst"
26
26
  if RUBY_PLATFORM['linux']
27
27
  module WLST
28
28
  class Runner
29
- def command file
30
- ". #{@wl_home}/server/bin/setWLSEnv.sh && java weblogic.WLST #{file}"
29
+ def command
30
+ ". #{@wl_home}/server/bin/setWLSEnv.sh && java weblogic.WLST #{@file}"
31
+ end
32
+
33
+ def clear_screen
34
+ system("clear")
31
35
  end
32
36
  end
33
37
  class ScriptResolver
@@ -39,8 +43,12 @@ if RUBY_PLATFORM['linux']
39
43
  elsif RUBY_PLATFORM['mingw'] #Windows
40
44
  module WLST
41
45
  class Runner
42
- def command file
43
- "#{@wl_home}/server/bin/setWLSEnv.cmd && java weblogic.WLST #{file}"
46
+ def command
47
+ "#{@wl_home}/server/bin/setWLSEnv.cmd && java weblogic.WLST #{@file}"
48
+ end
49
+
50
+ def clear_screen
51
+ system("cls")
44
52
  end
45
53
  end
46
54
  class ScriptResolver
@@ -21,5 +21,5 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  module Rlogic
24
- VERSION = "0.1.0"
24
+ VERSION = "0.2.0"
25
25
  end
@@ -48,25 +48,25 @@ class ConsoleTheme:
48
48
  class TableBuilder:
49
49
  def __init__(self, theme=ConsoleTheme()):
50
50
  self.data = []
51
- self.theme = theme
51
+ self.colors = theme
52
52
 
53
53
  def title(self, title):
54
- self.titleText = self.theme.title(title)
54
+ self.titleText = self.colors.title(title)
55
55
 
56
56
  def header(self, header):
57
- self.data.append(self.theme.header(header))
57
+ self.data.append(self.colors.header(header))
58
58
 
59
59
  def bad(self, row):
60
- self.data.append(self.theme.bad(row))
60
+ self.data.append(self.colors.bad(row))
61
61
 
62
62
  def good(self, row):
63
- self.data.append(self.theme.good(row))
63
+ self.data.append(self.colors.good(row))
64
64
 
65
65
  def warn(self, row):
66
- self.data.append(self.theme.warn(row))
66
+ self.data.append(self.colors.warn(row))
67
67
 
68
68
  def normal(self, row):
69
- self.data.append(self.theme.normal(row))
69
+ self.data.append(self.colors.normal(row))
70
70
 
71
71
  def printData(self):
72
72
  print self.titleText
@@ -88,12 +88,8 @@ def getRunningServers():
88
88
  return cmo.getServers()
89
89
 
90
90
 
91
- def format_num(num):
92
- return str(num)
93
-
94
-
95
91
  def get_max_width(table, index):
96
- return max([len(format_num(row[index])) for row in table])
92
+ return max([len(str(row[index])) for row in table])
97
93
 
98
94
 
99
95
  def pprint_table(out, table):
@@ -107,6 +103,28 @@ def pprint_table(out, table):
107
103
  print >> out, row[0].ljust(col_paddings[0] + 1),
108
104
  # rest of the cols
109
105
  for i in range(1, len(row)):
110
- col = format_num(row[i]).rjust(col_paddings[i] + 2)
106
+ col = str(row[i]).rjust(col_paddings[i] + 2)
111
107
  print >> out, col,
112
108
  print >> out
109
+
110
+
111
+ def getServerNames(arg = "servers"):
112
+ if not len(args[arg]):
113
+ serverNames = []
114
+ servers = getRunningServers()
115
+ for server in servers:
116
+ serverNames.append(server.getName())
117
+ return serverNames
118
+ else:
119
+ return args[arg]
120
+
121
+ def online():
122
+ try:
123
+ connect(weblogic['user'], weblogic['password'], ('t3://' + weblogic['host'] + ':' + weblogic['port']))
124
+ except:
125
+ print ConsoleTheme().bad("Unable to find admin server!")
126
+
127
+ def offline():
128
+ disconnect()
129
+
130
+ colors = ConsoleTheme()
@@ -0,0 +1 @@
1
+ Controls a selected resource
@@ -0,0 +1,32 @@
1
+ online()
2
+
3
+ theme = ConsoleTheme()
4
+
5
+ def controlServer():
6
+ server = args['server']
7
+ domainRuntime()
8
+ cd("/ServerLifeCycleRuntimes/" + server)
9
+ force = args["force"]
10
+ if args['start']:
11
+ print theme.good("Starting " + server)
12
+ cmo.start()
13
+ elif args['shutdown']:
14
+ print theme.good("Shutting down " + server)
15
+ if force:
16
+ cmo.forceShutdown()
17
+ else:
18
+ cmo.shutdown()
19
+ elif args['suspend']:
20
+ print theme.good("Suspending " + server)
21
+ if force:
22
+ cmo.forceSuspend()
23
+ else:
24
+ cmo.suspend()
25
+ elif args['resume']:
26
+ print theme.good("Resuming " + server)
27
+ cmo.resume()
28
+
29
+ if args['server']:
30
+ controlServer()
31
+
32
+ offline()
@@ -0,0 +1,23 @@
1
+ server:
2
+ description: select a service to control
3
+ type: string
4
+ start:
5
+ description: start the resource
6
+ type: boolean
7
+ default: false
8
+ suspend:
9
+ description: suspend the resource
10
+ type: boolean
11
+ default: false
12
+ resume:
13
+ description: resume the resource
14
+ type: boolean
15
+ default: false
16
+ shutdown:
17
+ description: shutdown the resource
18
+ type: boolean
19
+ default: false
20
+ force:
21
+ description: force the operation (if available)
22
+ type: boolean
23
+ default: false
@@ -1,15 +1,6 @@
1
- threshold = args['threshold']
2
-
3
- def getServerNames():
4
- if not len(args["servers"]):
5
- serverNames = []
6
- servers = getRunningServers()
7
- for server in servers:
8
- serverNames.append(server.getName())
9
- return serverNames
10
- else:
11
- return args["servers"]
1
+ online()
12
2
 
3
+ threshold = args['threshold']
13
4
 
14
5
  def monitorConnectionPool():
15
6
  table = TableBuilder()
@@ -20,22 +11,21 @@ def monitorConnectionPool():
20
11
  for poolRT in poolrtlist:
21
12
  if len(pools) > 0 and not poolRT.getName() in pools:
22
13
  continue
23
- try:
24
- name = poolRT.getName()
25
- maxCapacity = int(poolRT.getAttribute("MaxCapacity"))
26
- activeCurrent = int(poolRT.getAttribute("ActiveConnectionsCurrentCount"))
27
- activeHighCount = int(poolRT.getAttribute("ActiveConnectionsHighCount"))
28
- waitSecs = int(poolRT.getAttribute("WaitSecondsHighCount"))
29
- waitingCount = poolRT.getAttribute("WaitingForConnectionCurrentCount")
30
- state = poolRT.getAttribute('State')
31
- row = [name, maxCapacity, activeCurrent, activeHighCount, waitSecs, waitingCount,
32
- state]
33
- if (maxCapacity - activeCurrent) / float(maxCapacity) < threshold:
34
- table.bad(row)
35
- else:
36
- table.good(row)
37
- except:
38
- continue
14
+ name = poolRT.getName()
15
+ maxCapacity = int(poolRT.getAttribute("MaxCapacity"))
16
+ activeCurrent = int(poolRT.getAttribute("ActiveConnectionsCurrentCount"))
17
+ activeHighCount = int(poolRT.getAttribute("ActiveConnectionsHighCount"))
18
+ waitSecs = int(poolRT.getAttribute("WaitSecondsHighCount"))
19
+ waitingCount = poolRT.getAttribute("WaitingForConnectionCurrentCount")
20
+ state = poolRT.getAttribute('State')
21
+ row = [name, maxCapacity, activeCurrent, activeHighCount, waitSecs, waitingCount,
22
+ state]
23
+ if (maxCapacity - activeCurrent) / float(maxCapacity) < threshold:
24
+ table.bad(row)
25
+ elif state != "Running":
26
+ table.bad(row)
27
+ else:
28
+ table.good(row)
39
29
  table.printData()
40
30
 
41
31
 
@@ -53,14 +43,14 @@ def monitorJVM():
53
43
  totaljvm = float(get('HeapSizeCurrent')) / (1024 * 1024)
54
44
  usedjvm = (totaljvm - freejvm)
55
45
  row = [name,
56
- str(int(totaljvm)) + " M",
57
- str(int(usedjvm)) + " M",
58
- str(int(freejvm)) + " M"]
46
+ str(int(totaljvm)) + "MB",
47
+ str(int(usedjvm)) + "MB",
48
+ str(int(freejvm)) + "MB"]
59
49
  if freejvm / totaljvm < threshold:
60
50
  table.bad(row)
61
51
  else:
62
52
  table.good(row)
63
- except WLSTException, e:
53
+ except:
64
54
  continue
65
55
  table.printData()
66
56
 
@@ -70,7 +60,10 @@ def monitorThreadPool():
70
60
  serverNames = getServerNames()
71
61
  domainRuntime()
72
62
  table.title('Thread Pool')
73
- table.header(['Server', 'Hogging', 'Idle', 'Total', 'Pending Req', 'Throughput'])
63
+ table.header(
64
+ ['Server', 'Hogging', 'Idle', 'Total', 'Pending', 'Completed', 'Queue', 'Throughput'])
65
+ table.header(
66
+ ['', 'Threads', 'Threads', 'Threads', 'Requests', 'Requests', 'Length', ''])
74
67
  for name in serverNames:
75
68
  try:
76
69
  cd("/ServerRuntimes/" + name + "/ThreadPoolRuntime/ThreadPoolRuntime")
@@ -78,14 +71,40 @@ def monitorThreadPool():
78
71
  totalThreads = cmo.getExecuteThreadTotalCount()
79
72
  idleThreads = cmo.getExecuteThreadIdleCount()
80
73
  pendingRequests = cmo.getPendingUserRequestCount()
74
+ completedRequests = cmo.getCompletedRequestCount()
75
+ queue = cmo.getQueueLength()
81
76
  throughput = float(cmo.getThroughput())
82
77
  data = [name, hoggingThreads, idleThreads, totalThreads, pendingRequests,
83
- round(throughput,4)]
78
+ completedRequests, queue, round(throughput, 4)]
84
79
  if float(idleThreads) / totalThreads < threshold:
85
80
  table.bad(data)
86
81
  else:
87
82
  table.good(data)
88
- except WLSTException, e:
83
+ except:
84
+ continue
85
+ table.printData()
86
+
87
+
88
+ def monitorServerState():
89
+ table = TableBuilder()
90
+ serverNames = getServerNames()
91
+ domainRuntime()
92
+ table.title("Server State")
93
+ table.header(["Server", "State"])
94
+ for name in serverNames:
95
+ try:
96
+ cd("/ServerLifeCycleRuntimes/" + name)
97
+ serverState = cmo.getState()
98
+ row = [name, serverState]
99
+ if serverState == "RUNNING":
100
+ table.good(row)
101
+ elif serverState == "STARTING":
102
+ table.warn(row)
103
+ elif serverState == "UNKNOWN":
104
+ table.warn(row)
105
+ else:
106
+ table.bad(row)
107
+ except:
89
108
  continue
90
109
  table.printData()
91
110
 
@@ -97,3 +116,9 @@ if args['pool'] or args['all']:
97
116
  print ''
98
117
  if args['thread'] or args['all']:
99
118
  monitorThreadPool()
119
+ print ''
120
+ if args['state'] or args['all']:
121
+ monitorServerState()
122
+ print ''
123
+
124
+ offline()
@@ -2,6 +2,10 @@ all:
2
2
  description: prints all available status
3
3
  type: boolean
4
4
  default: false
5
+ state:
6
+ description: prints server state
7
+ type: boolean
8
+ default: false
5
9
  jvm:
6
10
  description: prints jvm status
7
11
  type: boolean
@@ -38,6 +38,7 @@ module WLST
38
38
  includes.each do |include|
39
39
  @includes << File.join(base_dir, include)
40
40
  end
41
+ @redirect = params[:redirect]
41
42
  end
42
43
 
43
44
  def has_script? key
@@ -70,6 +71,9 @@ module WLST
70
71
  parser = ArgParser::new script[:definition]
71
72
  params = parser.parse *args
72
73
  content = ""
74
+ if @redirect
75
+ content << "redirect('#{@redirect}', 'false')\n"
76
+ end
73
77
  @includes.each do |include|
74
78
  content << File.read(include)
75
79
  end
@@ -172,12 +176,26 @@ module WLST
172
176
 
173
177
  class Runner
174
178
 
175
- def initialize wl_home
176
- @wl_home = wl_home
179
+ def initialize params = {}
180
+ @wl_home = params[:wl_home]
181
+ @output_file = params[:output_file]
182
+ @file = params[:script_file]
183
+ @print = params[:print]
177
184
  end
178
185
 
179
- def run file
180
- result = `#{command file}`
186
+ def run interval = nil
187
+ if interval
188
+ while true
189
+ process :clear_screen => true
190
+ sleep interval
191
+ end
192
+ else
193
+ process
194
+ end
195
+ end
196
+
197
+ def run_and_get_result
198
+ result = `#{command}`
181
199
  truncated = ""
182
200
  flag = false
183
201
  result.each_line do |line|
@@ -191,6 +209,13 @@ module WLST
191
209
  result
192
210
  end
193
211
 
212
+ def process params = {}
213
+ result = run_and_get_result
214
+ clear_screen if params[:clear_screen] and @print
215
+ puts result if @print
216
+ File.open(@output_file, 'w') { |f| f.write result } if @output_file
217
+ end
218
+
194
219
  end
195
220
 
196
221
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rlogic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-21 00:00:00.000000000Z
12
+ date: 2012-03-22 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: A tool for dealing with WebLogic Scripting Tool
15
15
  email:
@@ -29,6 +29,9 @@ files:
29
29
  - lib/wlst/include.py
30
30
  - lib/wlst/include_linux.py
31
31
  - lib/wlst/include_windows.py
32
+ - lib/wlst/scripts/control.info
33
+ - lib/wlst/scripts/control.py
34
+ - lib/wlst/scripts/control.yaml
32
35
  - lib/wlst/scripts/monitor.info
33
36
  - lib/wlst/scripts/monitor.py
34
37
  - lib/wlst/scripts/monitor.yaml