Sample script
Find below a template script that you can use for developing your application module script. A sample script is also provided with hard coded data that can be modified to develop your script.
Sample script
use strict;
use warnings;
use VRTS::AppSDK::AppEnablementSDK::Application;
use VRTS::AppSDK::AppEnablementSDK::Constants qw(:LOG_LEVELS :
APP_INST_ATTRS :APP_UNIT_ATTRS :APP_FILE_ATTRS :
APP_CUSTOM_ATTRS :APP_INPUT_KEYS);
# Define an application here
my $appObj = new VRTS::AppSDK::AppEnablementSDK::Application("SampleApp");
if(defined $appObj)
{
# Set and register various operations that this application script
# supports.
$appObj->set_discovery_types("DEEP, PROBE");
$appObj->set_operation_types("START, STOP");
$appObj->register_operation_callback("START",\&start);
$appObj->register_operation_callback("STOP",\&stop);
$appObj->register_discovery_callback("PROBE",\&probe);
$appObj->register_discovery_callback("DEEP",\&deep);
print ($appObj->commit());
}
#################################
#Function: start
#
#Starts an application instance
#
#Parameters:
#arg - hash containing the application instance name
#
#Returns:
# 0 if successful else 1
# you can also return success or failure message which is optional.
#################################
sub start
{
my ($arg) = @_;
my $FuncName = ( caller 0 )[3];
$appObj->log(LOGLEVEL_DEBUG,"Inside $FuncName");
my $inst_name = $arg->{INSTANCE_NAME};
$appObj->log(LOGLEVEL_DEBUG,"Application instance name: [$inst_name]");
#Write the code here to start an application instance
#and return an appropriate status code and message.
#Return 0 for success and 1 for failure.
return 0, "Start is successful";
}
#################################
#Function: stop
#
#Stops an application instance
#
#Parameters:
#arg - hash containing the application instance name
#
#Returns:
# 0 if successful else 1
# you can also return success or failure message which is optional.
#################################
sub stop
{
my ($arg) = @_;
my $FuncName = ( caller 0 )[3];
$appObj->log(LOGLEVEL_DEBUG,"Inside $FuncName");
my $inst_name = $arg->{INSTANCE_NAME};
$appObj->log(LOGLEVEL_DEBUG,"Application instance name: [$inst_name]");
#Write the code here to stop an application instance
#and return an appropriate status code and message.
#Return 0 for success and 1 for failure.
return 0, "Stop is successful";
}
#################################
#Function: probe
#
#Discovers and reports the application instance state
#
#Parameters:
#arg - hash containing the application instance name
#
#Returns:
# 0 if successful else 1
# you can also return success or failure message which is optional.
#################################
sub probe
{
my ($arg) = @_;
my $FuncName = ( caller 0 )[3];
$appObj->log(LOGLEVEL_DEBUG,"Inside $FuncName");
#Write the code here to discover and report the application instance name.
#Report the state of the discovered application instance
# on the Resiliency Platform.
my $inst_name = $appObj->add_application_inst("app_inst");
if (defined $inst)
{
# The state must be reported either 'online' or 'offline'
$inst_name->set_property(APP_INST_STATE,"Online");
}
#return 0 if successful else 1
return 0, "Probe is successful";
}
#################################
#Function: deep
#
#Discovers and reports the sub-components and data file information of
#an application instance.
#
#Parameters:
#arg - hash containing the application instance name
#
#Returns:
# 0 if successful else 1
# you can also return success or failure message which is optional.
#################################
sub deep
{
my ($arg) = @_;
my $FuncName = ( caller 0 )[3];
$appObj->log(LOGLEVEL_DEBUG,"Inside $FuncName");
#Write the code here to discover and report the sub-components
# and the data file information of an application instance.
my $inst_name = $appObj->add_application_inst("app_inst");
if (defined $inst)
{
# Set application instance properties
# Ensure that the following property is set, else the application
# state is not displayed on the Resiliency Platform web console.
# You cannot perform operations if the state is not displayed
# on the console.
# Accepted values are 'online' and 'offline'
$inst_name->set_property(APP_INST_STATE,"Online");
# Following properties are optional
$inst->set_property(APP_INST_VERSION,"1.0");
$inst->set_property(APP_INST_OWNER,"Administrator");
$inst->set_property(APP_INST_ISPARALLEL,"false");
$inst->set_property(APP_INST_HOMEDIR,"inst_homedir");
$inst->set_property(APP_INST_APP_TYPE,"emp_database");
$inst->set_property(APP_INST_APP_CATEGORY,"database");
$inst->set_property(APP_INST_TOTAL_SIZE,"100");
$inst->set_property(APP_INST_USED_SIZE,"90");
# Set application instance custom properties
# Setting custom properties is optional.
$inst->set_custom_property("app_disp_name", "sample_instance");
#################################
# If your application is clustered using any high availability
# technology, then you need to set the following custom properties.
# $inst->set_custom_property("ClusterType", "MSCS");
# $inst->set_custom_property("ServiceGroupName", "sample_sg");
# $inst->set_custom_property("IsClustered", "true");
#-------------------------------
# Check if your application module script requires additional
# information such as user name and password from the user
# who is accessing the Resiliency Platform web console.
# If information is required, then check if the information
# is already asked and do we have its responses available here
# using the following API. Use those responses to complete
# your task.
# Use following API with QID as input
my $response1 = $inst->get_qresponse('1');
my $response2 = $inst->get_qresponse('2');
#-------------------------------
# If response is not available then ask for information
# again using the following API:
# Define questions to be asked in a hash
my $qid1 = {
'QID' => '1',
'QText' => 'Administrator user name',
'Mandatory' => 'yes',
'QDescription' => 'Specify the administrator user name
to discover its data files.',
'Encrypted' => 'no'};
my $qid2 = {
'QID' => '2',
'QText' => 'Administrator password',
'Mandatory' => 'yes',
'QDescription' => 'Specify the administrator user password
to discover its data files.',
'Encrypted' => 'yes'};
# Add the hash using the following API:
$inst->add_question($qid1);
$inst->add_question($qid2);
#-------------------------------
# Write the code here to discover an application unit (application
# sub-components) and application files information.
# Note: Discovering application unit is not mandatory
# but discovering application files is mandatory.
# Add application sub-component here
my $unit = $inst->add_application_unit("app_unit");
# Add properties for application unit
# Following properties are optional:
$unit->set_property(APP_UNIT_OWNER, "unit_owner");
$unit->set_property(APP_UNIT_VERSION, "1.0");
$unit->set_property(APP_UNIT_STATE, "online");
$unit->set_property(APP_UNIT_ISPARALLEL, "false");
$unit->set_property(APP_UNIT_HOMEDIR, "unit_homedir");
$unit->set_property(APP_UNIT_TYPE, "database");
$unit->set_property(APP_UNIT_TOTAL_SIZE, "100");
$unit->set_property(APP_UNIT_USED_SIZE, "50");
# Setting custom properties is optional.
$unit->set_custom_property("unit_disp_name", "sample_unit");
#-------------------------------
# Write the code here to discover information of application data files.
my $file = $inst->add_application_file("app_file");
# Following property is important and mandatory if you want to
# configure your application for disaster recovery.
# Value of this property could be data, log, etc. but the
# Resiliency Platform considers only those DR configuration files
# which are marked as 'data'.
$file->set_property(APP_FILE_TYPE, "data");
# Following property is important and mandatory if you want to
# configure your application for disaster recovery.
# Value of the property must be full file path
# e.g. '/root/app_inst/app_file.data' or
# 'c:\\app_inst\\app_file.data'
$file->set_property(APP_FILE_PATH, "c:\\app_inst\\app_file.data");
# Following properties are optional:
$file->set_property(APP_FILE_NAME, "app_file.data");
$file->set_property(APP_FILE_VERSION, "1.0");
$file->set_property(APP_FILE_OWNER, "administrator");
$file->set_property(APP_FILE_STATE, "online");
$file->set_property(APP_FILE_SIZE, "10");
$file->set_property(APP_FILE_PERMISSION, "all");
# Setting custom properties is optional.
$file->set_custom_property("file_desc", "Database file");
}
#return 0 if successful else 1
return 0, "deep discovery is successful";
}
More Information