blib/lib/Weblogic/WLST.pm

filter: Statementstmt 66.6% 4 / 6 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 2 / 2 Podpod n/a totaltotal 75.0% 6 / 8 CC 1 SCAR 1.4
CC
1
Cov
67%
BEGIN
1.3
BEGIN
1.0
CRAP 1.1
↑ Summary
1 package Weblogic::WLST;
2 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 0 ▶use Expect;
Subroutine BEGIN: called CC=1 SCAR=2.6
4 use strict;
5 use warnings;
6  
7 BEGIN {
8 use Exporter ();
9 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
10 $VERSION = '0.01';
11 @ISA = qw(Exporter);
12 #Give a hoot don't pollute, do not export more than needed by default
13 @EXPORT = qw();
14 @EXPORT_OK = qw();
15 %EXPORT_TAGS = ();
16 }
17  
18  
19  
20 =head1 NAME
21  
22 Weblogic::WLST - Communicate with weblogic server via WLST.
23  
24 =head1 SYNOPSIS
25  
26 use Weblogic::UserAdmin;
27 my $wlst->{$server} = new Weblogic::WLST(
28 {
29 wlsthome => "/home/http/Oracle/Middleware/wlserver_10.3/server/",
30 user => 'system',
31 password => 'narcolepsy',
32 server => "t3://$server"
33 }
34 ) or die "Died";
35
36
37 =cut
38  
39 =head1 DESCRIPTION
40  
41 Communicate with weblogic server via WLST.
42  
43 =cut
44  
45  
46 =head1 USAGE
47  
48 =cut
49  
50 sub new
51 {
52 my ($class, $parameters) = @_;
53  
54 my $self = bless ({}, ref ($class) || $class);
55
56
57 _connect_server($self,$parameters->{server},$parameters->{wlsthome},$parameters->{user},$parameters->{password});
58
59  
60 return $self;
61 }
62  
63  
64 sub _connect_server {
65
66 my ($self,$server, $wlsthome, $user, $password ) = @_;
67
68 $self->{exp} = Expect->spawn("$wlsthome/bin/setWLSEnv.sh;java -cp $wlsthome/lib/weblogic.jar weblogic.WLST")
69 or die "Cannot spawn WLST: $!\n";;
70  
71 #$Expect::Exp_Internal = 1;
72 #$self->{exp}->debug(1);
73
74
75 $self->{exp}->log_stdout(0);
76  
77
78  
79 $self->{exp}->send("connect('$user','$password','$server')\n");
80
81  
82 $self->{exp}->send("AS=get('AdminServerName')\n");
83
84  
85 $self->{exp}->send("\nprint 'AS#' + AS\n");
86
87
88  
89 my ($idx, $err, $string, $before, $after) = $self->{exp}->expect(30, '#');
90 $self->{exp}->clear_accum();
91 ($idx, $err, $string, $before, $after) = $self->{exp}->expect(30, '#');
92
93
94 $after =~ s/\r\n//;
95 $self->{adminServer} = $after;
96 $self->{exp}->send("serverRuntime()\n");
97
98 }
99  
100 =head2 getRunTimeValue($param)
101  
102 gets the value from the JVMRuntime stack -
103 my $heapFree=getRuntimeValue("HeapFreeCurrent")
104 =cut
105  
106 sub getRuntimeValue {
107
108 my ($self, $param) = @_;
109
110
111
112
113 my $cmd = "RESULT=get('/JVMRuntime/$self->{adminServer}/$param')\n";
114
115 $cmd .= "print
116 print 'RESULT#' + `RESULT`
117 ";
118
119 $self->{exp}->send($cmd . "\n");
120  
121 my ($idx, $err, $string, $before, $after) = $self->{exp}->expect(10, '#');
122 $self->{exp}->clear_accum();
123 ($idx, $err, $string, $before, $after) = $self->{exp}->expect(10, '#');
124
125 if(!defined $after) {
126 return undef;
127 } else {
128 $after =~ s/\r\n//;
129 return substr($after,0,length($after)-1);
130 }
131
132 }
133  
134  
135  
136  
137  
138  
139  
140 =head1 AUTHOR
141  
142 D Peters
143 CPAN ID: DAVIDP
144 davidp@electronf.com
145  
146 =cut
147  
148 =head1 COPYRIGHT
149  
150 This program is free software; you can redistribute
151 it and/or modify it under the same terms as Perl itself.
152  
153 The full text of the license can be found in the
154 LICENSE file included with this module.
155  
156 =cut
157  
158 =head1 SEE ALSO
159  
160 perl(1).
161  
162 =cut
163  
164 #################### main pod documentation end ###################
165  
166  
167 1;
168 # The preceding line will help the module return a true value
169  
↑ Summary