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    => [
            {
                command => 'list comps',
                action  => 'Siebel::Srvrmgr::Daemon::Action'
            },
            {
                command => 'list params',
                action  => 'Siebel::Srvrmgr::Daemon::Action'
            },
            {
                command => 'list comp defs for component XXX',
                action  => 'Siebel::Srvrmgr::Daemon::Action'
            }
        ]
    }
);

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 required attribute during object creation with the new method.

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 hash references with the keys command and action. The command key should have the command to be executed and the action key the name of the class to be instantied as an action to be executed.

The commands will be executed in the exactly order as given by the indexes in the array reference (as FIFO).

The action key value could be the full package name of the class or only the class name of a subclass from Siebel::Srvrmgr::Daemon::Action (consider this as a shortcut).

Additionally, the optional key params might by used to pass parameters to the class given by the action key. The content of such key must be an array reference, which in case will make it possible to pass an arbitrary number of the parameters to the class. How the action class will deal with the parameters is left to the class.

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.

pin

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