NAME

Siebel::Srvrmgr::Daemon - class for interactive sessions with Siebel srvrmgr.exe program

SYNOPSIS

    use Siebel::Srvrmgr::Daemon;

    my $daemon = Siebel::Srvrmgr::Daemon->new(
        {
            server      => 'servername',
            gateway     => 'gateway',
            enterprise  => 'enterprise',
            user        => 'user',
            password    => 'password',
            bin         => 'c:\\siebel\\client\\bin\\srvrmgr.exe',
            is_infinite => 1,
			commands    => [
			        Siebel::Srvrmgr::Daemon::Command->new(
                        command => 'load preferences',
                        action  => 'LoadPreferences'
                    ),
                    Siebel::Srvrmgr::Daemon::Command->new(
                        command => 'list comp type',
                        action  => 'ListCompTypes',
                        params  => [$comp_types_file]
                    ),
                    Siebel::Srvrmgr::Daemon::Command->new(
                        command => 'list comp',
                        action  => 'ListComps',
                        params  => [$comps_file]
                    ),
                    Siebel::Srvrmgr::Daemon::Command->new(
                        command => 'list comp def',
                        action  => 'ListCompDef',
                        params  => [$comps_defs_file]
                    )
                ]
        }
    );

DESCRIPTION

This class is used to execute the srvrmgr program and execute commands through it.

The sessions are not "interactive" from the user point of view but the usage of this class enable the adoption of some logic to change how the commands will be executed or even generate commands on the fly.

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 any command supported from srvrmgr program. 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.

The object will create an loop to interact with the srvrmgr program to execute the commands and actions as requested. This loop might be infinite, where the commands attribute will be restarted when the stack is finished.

The srvrmgr program will be executed by using IPC: this means that this method should be portable. Once the connection is made (see the run method) it will not be dropped after commands execution but it will be done automatically when the instance of this class goes out of scope. The instance is also able to deal with INT signal and close connection as appropriate: the class will first try to submit a exit command through srvrmgr program and if it's not terminated automatically the PID will be ripped.

ATTRIBUTES

server

This is a string representing the servername where the instance should connect. This is a optional attribute during object creation with the new method.

Beware that the run method will verify if the server attribute has a defined value or not: if it has, the run method will try to connect to the Siebel Enterprise specifying the given Siebel Server. If not, the method will try to connect to the Enterprise only, not specifying which Siebel Server to connect.

gateway

This is a string representing the gateway where the instance should connect. This is a required attribute during object creation with the new method.

enterprise

This is a string representing the enterprise where the instance should connect. This is a required attribute during object creation with the new method.

user

This is a string representing the login for authentication. This is a required attribute during object creation with the new method.

password

This is a string representing the password for authentication. This is a required attribute during object creation with the new method.

wait_time

This represent the time that the instance should wait after submitting a command to the server.

The time value is an integer in seconds. The default value is 1 second.

This should help with servers that are slow to giving a reply after a command submitted and avoid errors while trying to process generated output.

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.

bin

An string representing the full path to the srvrmgr program in the filesystem.

This is a required attribute during object creation with the new method.

write_fh

A filehandle reference to the srvrmgr STDIN. This is a read-only attribute.

write_fh

A filehandle reference to the srvrmgr STDOUT.

This is a read-only attribute.

pid

An integer presenting the process id (PID) of the process created by the OS when the srvrmgr program is executed.

This is a read-only attribute.

is_infinite

An boolean defining if the interaction loop should be infinite or not.

last_exec_cmd

This is a string representing the last command submitted to the srvrmgr program. The default value for it is an empty string (meaning that no command was submitted yet).

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.

params_stack

This is an array reference with the stack of params passed to the respective class. It is maintained automatically by the class so the attribute is read-only.

action_stack

This is an array reference with the stack of actions to be taken. It is maintained automatically by the class, so the attribute is read-only.

METHODS

get_server

Returns the content of server attribute as a string.

set_server

Sets the attribute server. Expects an string as parameter.

get_gateway

Returns the content of gateway attribute as a string.

set_gateway

Sets the attribute gateway. Expects a string as parameter.

get_enterprise

Returns the content of enterprise attribute as a string.

set_enterprise

Sets the enterprise attribute. Expects a string as parameter.

get_user

Returns the content of user attribute as a string.

set_user

Sets the user attribute. Expects a string as parameter.

get_password

Returns the content of password attribute as a string.

set_password

Sets the password attribute. Expects a string as parameter.

get_wait_time

Returns the content of the wait_time attribute as a integer.

set_wait_time

Sets the attribute wait_time. Expects a integer as parameter.

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_bin

Returns the content of the bin attribute.

set_bin

Sets the content of the bin attribute. Expects a string as parameter.

get_write

Returns the file handle of STDIN from the process executing the srvrmgr program based on the value of the attribute write_fh.

get_read

Returns the file handle of STDOUT from the process executing the srvrmgr program based on the value of the attribute read_fh.

get_pid

Returns the content of pid attribute as an integer.

is_infinite

Returns the content of the attribute is_infinite, returning true or false depending on this value.

get_last_cmd

Returns the content of the attribute last_cmd as a string.

get_cmd_stack

Returns the content of the attribute cmd_stack.

get_params_stack

Returns the content of the attribute params_stack.

setup_commands

Populates the attributes cmd_stack, action_stack and params_stack depending on the values available on the commands attribute.

This method must be invoked everytime the commands attribute is changed.

BUILD

This method is invoked right after the class instance is created. It invokes the method setup_commands.

run

This method will try to connect to a Siebel Enterprise through srvrmgr program (if it is the first time the method is invoke) or reuse an already open connection to submit the commands and respective actions defined during object creation. The path to the program is check and if it does not exists the method will issue an warning message and immediatly returns false.

Those operations will be executed in a loop as long the check method from the class Siebel::Srvrmgr::Daemon::Condition returns true.

DEMOLISH

This method is invoked before the object instance is destroyed. It will try to close the connection with the Siebel Enterprise (if opened) by submitting the command exit.

It will then try to read the string "Disconnecting from server" from the generated output after the command submission and closing the opened filehandles right after. Then it will send a kill 0 signal to the process to check if it is still running.

Finally, it will wait for 5 seconds before calling waitpid function to rip the child process.

CAVEATS

This class is still considered experimental and should be used with care.

The srvrmgr program uses buffering, which makes difficult to read the generated output as expected.

The open2 function in Win32 system is still returnin a PID even when an error occurs when executing the srvrmgr program.

IPC::Cmd looks like to a portable solution for those problems but that was not tested till now.

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/>.