blob: 51eff39aa93d4f2aa9d91112ec303b27040037d6 [file] [log] [blame]
///////////////////////////////////////////////////////////////////////////////
// //
// Copyright (c) 2000-2019 Ericsson Telecom AB //
// //
// All rights reserved. This program and the accompanying materials //
// are made available under the terms of the Eclipse Public License v2.0 //
// which accompanies this distribution, and is available at //
// https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html //
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
// Module: EPTF_CLL_HostAdmin_DSFunctions
//
// Purpose:
// This module contains the implementation of EPTF_CLL_HostAdmin_DSFunctions functions.
//
// Module depends on:
// <EPTF_CLL_Common_Definitions>
// <EPTF_CLL_HostAdmin_Definitions>
// <EPTF_CLL_DataSource_Definitions>
// <EPTF_CLL_DataSource_Functions>
// <EPTF_CLL_Variable_Definitions>
// <EPTF_CLL_Variable_Functions>
// <EPTF_CLL_Base_Functions>
// <EPTF_CLL_Logging_Functions>
//
// Module Parameters:
//
// Current Owner:
// Janos Zoltan Svaner (ejnosvn)
//
// Last Review Date:
// 2011-06-17
//
// Detailed Comments:
//
// Public functions:
// -
//
// All other functions in this module are private!
//
///////////////////////////////////////////////////////////////
module EPTF_CLL_HostAdmin_DSFunctions {
//=========================================================================
// Import Part
//=========================================================================
import from EPTF_CLL_Common_Definitions all;
import from EPTF_CLL_HostAdmin_Definitions all;
import from EPTF_CLL_DataSource_Definitions all;
import from EPTF_CLL_DataSource_Functions all;
import from EPTF_CLL_Variable_Definitions all;
import from EPTF_CLL_Variable_Functions all;
import from EPTF_CLL_Base_Functions all;
import from EPTF_CLL_Logging_Functions all;
friend module EPTF_CLL_HostAdmin_Functions;
//=========================================================================
// Functions
//========================================================================
///////////////////////////////////////////////////////////
// Function: f_EPTF_HostAdmin_warning
//
// Purpose:
// Function to log a warning from HostAdmin feature.
//
// Parameters:
// - pl_message - *in* *charstring* - the message to log
//
// Return Value:
// -
//
// Errors & assertions:
// -
//
// Detailed Comments:
// -
//
///////////////////////////////////////////////////////////
friend function f_EPTF_HostAdmin_warning(in @lazy charstring pl_message)
runs on EPTF_HostAdmin_CT
{
f_EPTF_Logging_warningV2(pl_message, v_HostAdmin_loggingMaskId, {c_EPTF_HostAdmin_loggingClassIdx_Warning});
}
///////////////////////////////////////////////////////////
// Group: DataSourceClient
//
// Purpose:
// Functions related to DataSourceClient feature of the HostAdmin
//
///////////////////////////////////////////////////////////
group DataSourceClient {
///////////////////////////////////////////////////////////
// Function: f_EPTF_HostAdmin_DSCreateIteratorVars
//
// Purpose:
// Creates the iterator variables that are needed for the implementation of the HostAdmin DataSourceClient feature.
// Called from f_EPTF_HostAdmin_init_CT
//
// Parameters:
// -
//
// Return Value:
// -
//
// Detailed Comments:
// -
//
///////////////////////////////////////////////////////////
friend function f_EPTF_HostAdmin_DSCreateIteratorVars() runs on EPTF_HostAdmin_CT {
var EPTF_CharstringList vl_cList := {}
var integer vl_idx := 0;
for(var integer i:=0; i<v_EPTF_HostAdmin_processStatDB.nofProcesses; i:=i+1) {
vl_cList[sizeof(vl_cList)] := int2str(v_EPTF_HostAdmin_processStatDB.processes[i].pid_k);
}
f_EPTF_Var_newCharstringlist(c_HostAdmin_iteratorVar_prefix & c_HostAdmin_iteratorProcesses_varName, vl_cList ,vl_idx);
vl_cList := {}
vl_idx := 0;
for(var integer i:=0; i<v_EPTF_HostAdmin_numCPUs; i:=i+1) {
vl_cList[sizeof(vl_cList)] := int2str(i);
}
f_EPTF_Var_newCharstringlist(c_HostAdmin_iteratorVar_prefix & c_HostAdmin_iteratorCPUs_varName, vl_cList ,vl_idx);
}
///////////////////////////////////////////////////////////
// Function: f_EPTF_HostAdmin_DSProcessData
//
// Purpose:
// Processes the incoming Data requests - iterators and external data elements - and gives back a variable name.
// It should be registered in the HostAdmin_init_CT. Type function fcb_EPTF_DataSourceClient_dataHandler
//
// Parameters:
// *out charstring pl_dataVarName* - this variable contains the value of the data or the iterator result
// *in charstring pl_source* - the name of the data source 'feature'
// *in charstring pl_ptcName* - the name of the ptc (ID of the PTC)
// *in charstring pl_element* - the name of the data element
// *in* <EPTF_DataSource_Params> *pl_params* - the parameters
// of the data for the dataElement
//
// Return Value:
// integer - error code (0 of OK, non zero if unsuccessful: e.g. invalid parameters given in pl_params)
//
// Detailed Comments:
// -
//
///////////////////////////////////////////////////////////
friend function f_EPTF_HostAdmin_DSProcessData(out charstring pl_dataVarName,
in charstring pl_source,
in charstring pl_ptcName,
in charstring pl_element,
in EPTF_DataSource_Params pl_params)
runs on EPTF_HostAdmin_CT return integer{
var EPTF_CharstringList pl_result := {}
pl_dataVarName := "";
var charstring vl_prefix := f_EPTF_Base_selfName() & ".";
select(pl_element){
case(c_HostAdmin_iteratorProcesses){
if(0 == f_EPTF_HostAdmin_getParams(pl_params, {}, pl_result)){
pl_dataVarName := c_HostAdmin_iteratorVar_prefix & c_HostAdmin_iteratorProcesses_varName;
}
}
case(c_HostAdmin_iteratorCPUs){
if(0 == f_EPTF_HostAdmin_getParams(pl_params, {}, pl_result)){
pl_dataVarName := c_HostAdmin_iteratorVar_prefix & c_HostAdmin_iteratorCPUs_varName;
}
}
case(c_HostAdmin_dataElementCPULoad){
if(0 == f_EPTF_HostAdmin_getParams(pl_params, {c_HostAdmin_paramNameCPU_ID}, pl_result)){
//var integer vl_cpuid := pl_result[0];
pl_dataVarName := vl_prefix & c_EPTF_HostAdmin_CPULoads_name & "." & pl_result[0];
}
}
case(c_HostAdmin_dataElementHostNumCPUs){
if(0 == f_EPTF_HostAdmin_getParams(pl_params, {}, pl_result)){
pl_dataVarName := vl_prefix & c_EPTF_HostAdmin_numCPUs_name;
}
}
case(c_HostAdmin_dataElementHostPhysicalMemory){
if(0 == f_EPTF_HostAdmin_getParams(pl_params, {}, pl_result)){
pl_dataVarName := vl_prefix & c_EPTF_HostAdmin_physicalMemory_name;
}
}
case(c_HostAdmin_dataElementHostFreeMemory){
if(0 == f_EPTF_HostAdmin_getParams(pl_params, {}, pl_result)){
pl_dataVarName := vl_prefix & c_EPTF_HostAdmin_freeMemory_name;
}
}
case(c_HostAdmin_dataElementHostName){
if(0 == f_EPTF_HostAdmin_getParams(pl_params, {}, pl_result)){
pl_dataVarName := vl_prefix & c_EPTF_HostAdmin_hostName_name;
}
}
case(c_HostAdmin_dataElementIPv4Addr){
if(0 == f_EPTF_HostAdmin_getParams(pl_params, {}, pl_result)){
pl_dataVarName := vl_prefix & c_EPTF_HostAdmin_ipv4Addr_name;
}
}
case(c_HostAdmin_dataElementIPv6Addr){
if(0 == f_EPTF_HostAdmin_getParams(pl_params, {}, pl_result)){
pl_dataVarName := vl_prefix & c_EPTF_HostAdmin_ipv6Addr_name;
}
}
case(c_HostAdmin_dataElementHostCPULoad){
if(0 == f_EPTF_HostAdmin_getParams(pl_params, {}, pl_result)){
pl_dataVarName := vl_prefix & c_EPTF_HostAdmin_testerHostLoad_name;
}
}
case(c_HostAdmin_dataElementMinCPULoad){
if(0 == f_EPTF_HostAdmin_getParams(pl_params, {}, pl_result)){
pl_dataVarName := f_EPTF_Var_getName(v_EPTF_HostAdmin_minHostLoad_k);
}
}
case(c_HostAdmin_dataElementMaxCPULoad){
if(0 == f_EPTF_HostAdmin_getParams(pl_params, {}, pl_result)){
pl_dataVarName := f_EPTF_Var_getName(v_EPTF_HostAdmin_maxHostLoad_k);
}
}
case(c_HostAdmin_dataElementAvgCPULoad){
if(0 == f_EPTF_HostAdmin_getParams(pl_params, {}, pl_result)){
pl_dataVarName := f_EPTF_Var_getName(v_EPTF_HostAdmin_avgHostLoad_k);
}
}
case(c_HostAdmin_dataElementResetMinMaxAvgCPULoad){
if(0 == f_EPTF_HostAdmin_getParams(pl_params, {}, pl_result)){
pl_dataVarName := vl_prefix & c_EPTF_HostAdmin_resetMinMaxAvgCPULoad_name;
}
}
case(c_HostAdmin_dataElementProcName){
var charstring vl_procID := "";
if(0 == f_EPTF_HostAdmin_getParams(pl_params, { c_HostAdmin_paramNameProcID}, pl_result)){
vl_procID := pl_result[0];
for(var integer i:=0; i<v_EPTF_HostAdmin_processStatDB.nofProcesses; i:=i+1) {
if(v_EPTF_HostAdmin_processStatDB.processes[i].pid_k == str2int(vl_procID)){
vl_prefix := f_EPTF_Base_selfName() & "." & c_EPTF_HostAdmin_processPrefix & "." & int2str(i) & ".";
pl_dataVarName := vl_prefix & c_EPTF_HostAdmin_processName;
i := v_EPTF_HostAdmin_processStatDB.nofProcesses;
}
}
if(pl_dataVarName == ""){
f_EPTF_HostAdmin_warning(%definitionId&": Invalid processID on this host");
}
}
}
case(c_HostAdmin_dataElementProcCPULoad){
var charstring vl_procID := "";
if(0 == f_EPTF_HostAdmin_getParams(pl_params, { c_HostAdmin_paramNameProcID}, pl_result)){
vl_procID := pl_result[0];
for(var integer i:=0; i<v_EPTF_HostAdmin_processStatDB.nofProcesses; i:=i+1) {
if(v_EPTF_HostAdmin_processStatDB.processes[i].pid_k == str2int(vl_procID)){
vl_prefix := f_EPTF_Base_selfName() & "." & c_EPTF_HostAdmin_processPrefix & "." & int2str(i) & ".";
pl_dataVarName := vl_prefix & c_EPTF_HostAdmin_processCpuLoad;
i := v_EPTF_HostAdmin_processStatDB.nofProcesses;
}
}
if(pl_dataVarName == ""){
f_EPTF_HostAdmin_warning(%definitionId&": Invalid processID on this host");
}
}
}
case(c_HostAdmin_dataElementProcMEMUsage){
var charstring vl_procID := "";
if(0 == f_EPTF_HostAdmin_getParams(pl_params, { c_HostAdmin_paramNameProcID}, pl_result)){
vl_procID := pl_result[0];
for(var integer i:=0; i<v_EPTF_HostAdmin_processStatDB.nofProcesses; i:=i+1) {
if(v_EPTF_HostAdmin_processStatDB.processes[i].pid_k == str2int(vl_procID)){
vl_prefix := f_EPTF_Base_selfName() & "." & c_EPTF_HostAdmin_processPrefix & "." & int2str(i) & ".";
pl_dataVarName := vl_prefix & c_EPTF_HostAdmin_processMemUsage;
i := v_EPTF_HostAdmin_processStatDB.nofProcesses;
}
}
if(pl_dataVarName == ""){
f_EPTF_HostAdmin_warning(%definitionId&": Invalid processID on this host");
}
}
}
case else { //error, no rule for that
pl_dataVarName := "";
f_EPTF_HostAdmin_warning(%definitionId& ": unhandled element: "& pl_element);
return -1;
}
}
var integer vl_iteratorVarIdx := f_EPTF_Var_getId(pl_dataVarName);
if(vl_iteratorVarIdx == -1){
f_EPTF_HostAdmin_warning(%definitionId&": Invalid iterator or externalData or parameter: "&
"\nSource: "&pl_source&
"\nPTC : "&pl_ptcName &
"\nElement Name : " &pl_element&
"\nParams: " & log2str(pl_params));
return -1;
}
return 0;
}
///////////////////////////////////////////////////////////
// Function: f_EPTF_HostAdmin_DSProcessDataValue
//
// Purpose:
// Processes the incoming DataValue requests - iterators and external data elements - and gives back the value.
// It should be registered in the HostAdmin_init_CT. Type function fcb_EPTF_DataSourceClient_dataValueHandler
//
// Parameters:
// *out *<EPTF_Var_DirectContent>* pl_dataValue* - the value of the data or the iterator result
// *in charstring pl_source* - the name of the data source 'feature'
// *in charstring pl_ptcName* - the name of the ptc (ID of the PTC)
// *in charstring pl_element* - the name of the data element
// *in* <EPTF_DataSource_Params> *pl_params* - the parameters
// of the data for the dataElement
//
// Return Value:
// integer - error code (0 of OK, non zero if unsuccessful: e.g. invalid parameters given in pl_params)
//
// Detailed Comments:
// -
//
///////////////////////////////////////////////////////////
friend function f_EPTF_HostAdmin_DSProcessDataValue(out EPTF_Var_DirectContent pl_dataValue,
in charstring pl_source,
in charstring pl_ptcName,
in charstring pl_element,
in EPTF_DataSource_Params pl_params)
runs on EPTF_HostAdmin_CT return integer{
var integer vl_errorCode := -1;
pl_dataValue := {unknownVal := {omit}}; // set it to invalid
select( pl_element )
{
case(c_EPTF_DataSource_dataElement_Help) {
vl_errorCode := f_EPTF_DataSource_handleHelp(pl_dataValue,pl_source,pl_params,c_EPTF_HostAdmin_help);
}
case else
{
}
}
return vl_errorCode;
}
private function f_EPTF_HostAdmin_getParams(in EPTF_DataSource_Params pl_params,
in EPTF_CharstringList pl_needed,
out EPTF_CharstringList pl_result,
in boolean pl_noWarning := false)
runs on EPTF_HostAdmin_CT return integer {
pl_result := {};
if(sizeof(pl_params) == sizeof(pl_needed)){
for(var integer j := 0; j < sizeof(pl_needed); j := j + 1){
for(var integer i := 0; i < sizeof(pl_params); i:= i + 1){
if(pl_params[i].paramName == pl_needed[j]){
pl_result[sizeof(pl_result)] := pl_params[i].paramValue;
}
}
}
if(sizeof(pl_result) != sizeof(pl_needed)){
if(not pl_noWarning){
var EPTF_CharstringList vl_error := {};
for(var integer i := 0; i < sizeof(pl_params); i:= i + 1){
vl_error[i] := pl_params[i].paramName;
}
f_EPTF_HostAdmin_warning(%definitionId& ": Parameters are not correct: "&
"\nReceived: "& log2str(vl_error)&
"\nNeeded : "& log2str(pl_needed) );
}
return -1;
}
return 0;
} else{
if(not pl_noWarning){
var EPTF_CharstringList vl_error := {};
for(var integer i := 0; i < sizeof(pl_params); i:= i + 1){
vl_error[i] := pl_params[i].paramName;
}
if(sizeof(pl_params) < sizeof(pl_needed)){
f_EPTF_HostAdmin_warning(%definitionId& ": Too few parameter is given: "&
"\nReceived: "& log2str(vl_error)&
"\nNeeded : "& log2str(pl_needed));
} else {
f_EPTF_HostAdmin_warning(%definitionId& ": Too many parameters are given: "&
"\nReceived: "& log2str(vl_error)&
"\nNeeded : "& log2str(pl_needed));
}
}
return -1;
}
}
} // group
} // module