NAME
Siebel::Srvrmgr::Daemon - super class for sessions with Siebel srvrmgr program
SYNOPSIS
package MyDaemon;
extends 'Siebel::Srvrmgr::Daemon';
DESCRIPTION
This is a super class, and alone it does not provide any functionaly to use srvrmgr to send commands and process returned data.
The "private" method _setup_commands
must be overrided by subclasses of it or commands will not be sent to srvrmgr
.
Logging of this class can be enabled by using Siebel::Srvrmgr logging feature.
The logic behind this class is easy: you can submit a pair of command/action to the class. It will then connect to the server by executing srvrmgr
, submit the command to the server and recover the output generated. The action will be executed having this output as parameter. Anything could be considered as an action, from simple storing the output to even generating new commands to be executed in the server.
A command is an instance of Siebel::Srvrmgr::Daemon::Command class. Any "list" command is supported, and also load preferences
and exit
. Anything else is considered dangerous and will generated an exception. Beware that you will need to have an Siebel::Srvrmgr::ListParser::Output class available to be able to parse the command output.
An action can be any class but is obligatory to create a subclass of Siebel::Srvrmgr::Daemon::Action base class. See the <commands> attribute for details.
Implementation details are reserved to subclasses of Siebel::Srvrmgr::Daemon: be sure to check them for real usage cenarios.
ATTRIBUTES
commands
An array reference containing one or more references of Siebel::Srvrmgr::Daemon::Commands class.
The commands will be executed in the exactly order as given by the indexes in the array reference (as FIFO).
This is a required attribute during object creation with the new
method.
time_zone
Required attribute.
A string representing the time zone to be considered for all date/time values recovered from srvrmgr
.
See DateTime::TimeZone all_names
methods to list the available time zones that you can use. The on-liner below will show you them so you can find a proper value:
perl -MDateTime::TimeZone -e 'foreach ( DateTime::TimeZone->all_names ) { print "$_\n" }'
alarm_timeout
An integer value that will raise an ALARM signal generated by alarm
. The default value is 30 seconds. This is avoid leaving the daemon blocking forever waiting for something to read.
This attribute will be reset every time a read can be done from the STDOUT or STDERR from srvrmgr.
use_perl
A boolean attribute used mostly for testing of this class.
If true, if will prepend the complete path of the Perl interpreter to the parameters before calling the srvrmgr
program (of course the "srvrmgr" must be itself a Perl script).
It defaults to false.
child_runs
An integer representing the number of times the child object was used in run
invocations. This is reset to zero if a new child process is created.
clear_raw
A boolean attribute that defines if the raw data recovered from srvrmgr
should be kept or discarded as soon as possibly.
Having a default value of true, it should help reducing memory usage or debugging, if set false.
has_lock
Optional parameter.
This is a boolean attribute (in the sense of Perl) that identifies if the Daemon needs to use a lock or not. Default is false.
Using a lock is useful to avoid two instances of the same Daemon
running. See also lock_dir
attribute.
lock_dir
Optional parameter.
This parameter is used to determine the location in the filesystem to create the lock file.
Expects a string as parameter. The directory must be readable and writable to the user running the Daemon
.
It defaults to the "home" directory of the user. The sense of "home" is the following as defined by the platform:
This attribute is lazy and defined by the _define_lock_dir
"private" method.
Microsoft Windows:
$ENV{HOMEDIR}
UNIX-like:
$ENV{HOME}
cmd_stack
This is an array reference with the stack of commands to be executed. It is maintained automatically by the class, so the attribute is read-only.
METHODS
get_time_zone
Returns the content of the attribute time_zone
.
get_cmd_stack
Returns the content of the attribute cmd_stack
.
clear_raw
Getter for the clear_raw
attribute.
set_clear_raw
Setter for the clear_raw
attribute.
get_alarm
Returns the content of the alarm_timeout
attribute.
set_alarm
Sets the attribute alarm_timeout
. Expects an integer as parameter, in seconds.
get_child_runs
Returns the value of the attribute child_runs
.
use_perl
Returns the content of the attribute use_perl
.
get_buffer_size
Returns the value of the attribute ipc_buffer_size
.
set_buffer_size
Sets the attribute ipc_buffer_size
. Expects an integer as parameter, multiple of 1024.
get_commands
Returns the content of the attribute commands
.
set_commands
Set the content of the attribute commands
. Expects an array reference as parameter.
get_pid
Returns the content of pid
attribute as an integer.
BUILD
Moose BUILD method is used by this class to install signal handlers for the following signals:
INT
PIPE
ALRM
Also the method sets the environment variable SIEBEL_TZ
if a time zone was set.
If the logging is set to DEBUG
level all attribute values will be logged.
cmds_vs_tree
This method compares the number of commands
defined in a instance of this class with the number of nodes passed as parameter.
If their are equal, the number is returned. If their are different (and there is a problem with the parsed output of srvrmgr) this method returns undef
.
check_cmd
This methods expects as parameter a string representing a srvrmgr
command.
The command will be checked and if considered insecure, an exception will be raised.
Commands considered secure are:
load preferences
list <anything>
exit
set delimiter
This method is also used internally through the _setup_commands
method.
shift_command
Does a shift
in the commands
attribute.
Does not expects any parameter. Returns the shift
ed Siebel::Srvrmgr::Daemon::Command instance or undef
if there is only one command left (which is not shift
ed).
This method is useful specially if the Daemon will keep executing commands, but setup commands (like load preferences
) are not necessary to be executed again.
push_command
Does a push
in the commands
attribute.
Expects as parameter a Siebel::Srvrmgr::Daemon::Command instance.
run
This is the method used to execute commands in srvrmgr program and must be overrided by subclasses of Siebel::Srvrmgr::Daemon. Subclasses should invoke Moose super
to when doing override because this implementation will apply lock control when appropriate. Expects as parameters a Siebel::Srvrmgr::Connection, or it will confess
with an exception.
normalize_eol
Expects an array reference as parameter.
Changes any EOL character to LF from each index value.
See perlport -> Issues -> Newlines for details on this.
create_parser
Returns an instance of a Siebel::Srvrmgr::ListParser class.
Optionally, it can receive as parameter a string representing the field delimiter that is expected. If received, the parameter will be used to create the instance.
get_lock_file
Returns the complete path to the lock file as a string.
DEMOLISH
This method is invoked before the object instance is destroyed. It does really few things like writting messages to the define configuration of Log::Log4perl logger. It will also log if ALRM, INT or PIPE signals were received.
Subclasses may want to override
the method "private" _my_cleanup
to do their properly laundry since the definition of _my_cleanup
for this class is just to return
true. _my_cleanup
is called with a reference of a Log::Log4perl::Logger instance for usage.
CONSTANTS
The following constants are available in this class:
- LOCK_EX
- LOCK_NB
All of them from the Fcntl module.
SEE ALSO
AUTHOR
Alceu Rodrigues de Freitas Junior, <arfreitas@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2012 of Alceu Rodrigues de Freitas Junior, <arfreitas@cpan.org>
This file is part of Siebel Monitoring Tools.
Siebel Monitoring Tools is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Siebel Monitoring Tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Siebel Monitoring Tools. If not, see <http://www.gnu.org/licenses/>.