| /////////////////////////////////////////////////////////////////////////////// |
| // // |
| // 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_Functions |
| // |
| // Purpose: |
| // This module contains function definitions for EPTF HostAdmin |
| // |
| // Module Parameters: |
| // tsp_debug_EPTF_HostAdmin_Functions - *boolean* - debug messages on/off |
| // |
| // Module depends on: |
| // <EPTF_CLL_HostAdmin_BaseFunctions> |
| // <EPTF_CLL_HostAdmin_Definitions> |
| // <EPTF_CLL_Common_Definitions> |
| // <EPTF_CLL_Base_Definitions> |
| // <EPTF_CLL_Base_Functions> |
| // <EPTF_CLL_Variable_Definitions> |
| // <EPTF_CLL_Variable_Functions> |
| // <EPTF_CLL_Logging_Definitions> |
| // <EPTF_CLL_Logging_Functions> |
| // <EPTF_CLL_DataSource_Definitions> |
| // <EPTF_CLL_DataSourceClient_Functions> |
| // <EPTF_CLL_HostAdmin_DSFunctions> |
| // <EPTF_CLL_RBT_Definitions> |
| // <EPTF_CLL_RBT_Functions> |
| // <EPTF_CLL_StatMeasure_Functions> |
| // <TCCInterface_Functions> |
| // |
| // Current Owner: |
| // Gabor Tatarka (egbotat) |
| // Bence Molnar (ebenmol) |
| // |
| // Last Review Date: |
| // 2008-02-14 |
| // |
| // Detailed Comments: |
| // - |
| /////////////////////////////////////////////////////////// |
| |
| module EPTF_CLL_HostAdmin_Functions |
| { |
| |
| //========================================================================= |
| // Imports |
| //======================================================================= |
| |
| import from EPTF_CLL_HostAdmin_BaseFunctions all; |
| import from EPTF_CLL_HostAdmin_Definitions all; |
| |
| import from EPTF_CLL_Common_Definitions all; |
| import from EPTF_CLL_Base_Definitions all; |
| import from EPTF_CLL_Base_Functions all; |
| import from EPTF_CLL_Variable_Definitions all; |
| import from EPTF_CLL_Variable_Functions all; |
| import from EPTF_CLL_Logging_Definitions all; |
| import from EPTF_CLL_Logging_Functions all; |
| import from EPTF_CLL_DataSource_Definitions all; |
| import from EPTF_CLL_DataSourceClient_Functions all; |
| import from EPTF_CLL_HostAdmin_DSFunctions all; |
| import from EPTF_CLL_RBT_Definitions all; |
| import from EPTF_CLL_RBT_Functions all; |
| import from EPTF_CLL_StatMeasure_Functions all; |
| |
| import from TCCInterface_Functions all; |
| |
| modulepar boolean tsp_debug_EPTF_HostAdmin_Functions := false; |
| |
| friend module EPTF_HostAdmin_Test_Testcases; |
| |
| /////////////////////////////////////////////////////////// |
| // Function: f_EPTF_HostAdmin_init_CT |
| // |
| // Purpose: |
| // Initialisation for <EPTF_HostAdmin_CT> |
| // |
| // Parameters: |
| // pl_selfName - *charstring* - name of the component |
| // pl_hostName - *charstring* - host name |
| // pl_dataSource_compRef - <EPTF_DataSource_CT> - datasource component reference |
| // |
| // Return Value: |
| // - |
| // |
| // Errors: |
| // - |
| // |
| // Detailed Comments: |
| // - |
| /////////////////////////////////////////////////////////// |
| public function f_EPTF_HostAdmin_init_CT( |
| in charstring pl_selfName, |
| in charstring pl_hostName := "", |
| in EPTF_DataSource_CT pl_dataSource_compRef := null, |
| in EPTF_HostAdminServerBase_CT pl_server_Ref := null) runs on EPTF_HostAdmin_CT |
| { |
| if(v_EPTF_HostAdmin_initialized) { |
| f_EPTF_HostAdmin_debug("f_EPTF_HostAdmin_init_CT(): already initialized"); |
| return; |
| } |
| f_EPTF_Logging_init_CT(pl_selfName); |
| f_EPTF_RBT_init_CT(f_EPTF_Base_selfName()); |
| f_EPTF_StatMeasure_init_CT(f_EPTF_Base_selfName()); |
| |
| v_EPTF_HostAdmin_hostName := f_EPTF_Base_getHostName(); |
| v_EPTF_HostAdmin_ipv4Addr := f_getIpAddr(v_EPTF_HostAdmin_hostName, IPv4); |
| v_EPTF_HostAdmin_ipv6Addr := f_getIpAddr(v_EPTF_HostAdmin_hostName, IPv6); |
| |
| v_HostAdmin_loggingMaskId := f_EPTF_Logging_registerComponentMasks(tsp_EPTF_HostAdmin_loggingComponentMask, c_EPTF_HostAdmin_loggingEventClasses, EPTF_Logging_CLL); |
| if(tsp_debug_EPTF_HostAdmin_Functions) { |
| f_EPTF_Logging_enableLocalMask(v_HostAdmin_loggingMaskId, c_EPTF_HostAdmin_loggingClassIdx_Debug); |
| } else { |
| f_EPTF_Logging_disableLocalMask(v_HostAdmin_loggingMaskId, c_EPTF_HostAdmin_loggingClassIdx_Debug); |
| } |
| if(pl_hostName != "" and pl_hostName != v_EPTF_HostAdmin_hostName) { |
| f_EPTF_HostAdmin_warning(%definitionId&": obsolete parameter pl_hostName was specified incorrectly: \""& |
| pl_hostName&"\", using \""&v_EPTF_HostAdmin_hostName&"\""); |
| } |
| |
| f_EPTF_HostAdmin_debug("f_EPTF_HostAdmin_init_CT(): started"); |
| |
| // Init meas interface |
| f_EPTF_HostAdmin_Base_init_CT(f_EPTF_Base_selfName()); |
| |
| var charstring prefix := f_EPTF_Base_selfName() & "."; |
| |
| f_EPTF_Var_init_CT(f_EPTF_Base_selfName()); |
| |
| f_EPTF_Var_newCharstringRef(prefix & c_EPTF_HostAdmin_hostName_name, v_EPTF_HostAdmin_hostName, v_EPTF_HostAdmin_hostName_k); |
| f_EPTF_Var_newCharstringRef(prefix & c_EPTF_HostAdmin_ipv4Addr_name, v_EPTF_HostAdmin_ipv4Addr, v_EPTF_HostAdmin_ipv4Addr_k); |
| f_EPTF_Var_newCharstringRef(prefix & c_EPTF_HostAdmin_ipv6Addr_name, v_EPTF_HostAdmin_ipv6Addr, v_EPTF_HostAdmin_ipv6Addr_k); |
| |
| f_EPTF_Var_newFloatRef(prefix & c_EPTF_HostAdmin_testerHostLoad_name, v_EPTF_HostAdmin_testerHostLoad, v_EPTF_HostAdmin_testerHostLoad_k); |
| |
| v_EPTF_HostAdmin_minHostLoad_statKey := f_EPTF_StatMeasure_newStat_min(v_EPTF_HostAdmin_testerHostLoad_k); |
| v_EPTF_HostAdmin_minHostLoad_k := f_EPTF_StatMeasure_createVarFromStat(v_EPTF_HostAdmin_minHostLoad_statKey, prefix & c_EPTF_HostAdmin_minHostLoad_name); |
| v_EPTF_HostAdmin_maxHostLoad_statKey := f_EPTF_StatMeasure_newStat_max(v_EPTF_HostAdmin_testerHostLoad_k); |
| v_EPTF_HostAdmin_maxHostLoad_k := f_EPTF_StatMeasure_createVarFromStat(v_EPTF_HostAdmin_maxHostLoad_statKey, prefix & c_EPTF_HostAdmin_maxHostLoad_name); |
| v_EPTF_HostAdmin_avgHostLoad_statKey := f_EPTF_StatMeasure_newStat_mean(v_EPTF_HostAdmin_testerHostLoad_k); |
| v_EPTF_HostAdmin_avgHostLoad_k := f_EPTF_StatMeasure_createVarFromStat(v_EPTF_HostAdmin_avgHostLoad_statKey, prefix & c_EPTF_HostAdmin_avgHostLoad_name); |
| var integer vl_rst := -1; |
| f_EPTF_Var_newInt(prefix & c_EPTF_HostAdmin_resetMinMaxAvgCPULoad_name, 0, vl_rst); |
| f_EPTF_Var_addPostProcFn( vl_rst, |
| { funcRef := refers(f_EPTF_HostAdmin_resetMinMaxAvgCPULoad), argList := {} }); |
| |
| f_EPTF_Var_newIntRef(prefix & c_EPTF_HostAdmin_numCPUs_name, v_EPTF_HostAdmin_numCPUs, v_EPTF_HostAdmin_numCPUs_k); |
| for(var integer i:=0; i<v_EPTF_HostAdmin_numCPUs; i:=i+1) { |
| v_EPTF_HostAdmin_CPULoads_k[i] := -1; |
| f_EPTF_Var_newFloatRef(prefix & c_EPTF_HostAdmin_CPULoads_name & "." & int2str(i), |
| v_EPTF_HostAdmin_CPULoads[i], v_EPTF_HostAdmin_CPULoads_k[i]); |
| // make measurement data readonly from remote components |
| f_EPTF_Var_addGuardFn(v_EPTF_HostAdmin_CPULoads_k[i], {refers(f_EPTF_HostAdmin_VarGuardFn), {}}); |
| } |
| f_EPTF_Var_newIntRef(prefix & c_EPTF_HostAdmin_physicalMemory_name, v_EPTF_HostAdmin_physicalMemory, v_EPTF_HostAdmin_physicalMemory_k); |
| f_EPTF_Var_newIntRef(prefix & c_EPTF_HostAdmin_freeMemory_name, v_EPTF_HostAdmin_freeMemory, v_EPTF_HostAdmin_freeMemory_k); |
| |
| // make measurement data readonly from remote components |
| f_EPTF_Var_addGuardFn(v_EPTF_HostAdmin_testerHostLoad_k, {refers(f_EPTF_HostAdmin_VarGuardFn), {}}); |
| f_EPTF_Var_addGuardFn(v_EPTF_HostAdmin_numCPUs_k, {refers(f_EPTF_HostAdmin_VarGuardFn), {}}); |
| f_EPTF_Var_addGuardFn(v_EPTF_HostAdmin_physicalMemory_k, {refers(f_EPTF_HostAdmin_VarGuardFn), {}}); |
| f_EPTF_Var_addGuardFn(v_EPTF_HostAdmin_freeMemory_k, {refers(f_EPTF_HostAdmin_VarGuardFn), {}}); |
| |
| v_EPTF_HostAdmin_serverRef := pl_server_Ref; |
| if(v_EPTF_HostAdmin_serverRef != null) { |
| f_EPTF_HostAdmin_updateProcessList(); |
| } else { |
| f_EPTF_HostAdmin_addProcesses(); |
| } |
| |
| |
| if(pl_dataSource_compRef != null){ |
| f_EPTF_DataSourceClient_init_CT(f_EPTF_Base_selfName(), pl_dataSource_compRef); |
| f_EPTF_DataSourceClient_registerData(c_HostAdmin_DataSource_sourceId, f_EPTF_Base_selfName(), refers(f_EPTF_HostAdmin_DSProcessData), pl_dataSource_compRef); |
| f_EPTF_DataSourceClient_registerDataValue(c_HostAdmin_DataSource_sourceId, f_EPTF_Base_selfName(), refers(f_EPTF_HostAdmin_DSProcessDataValue), pl_dataSource_compRef); |
| f_EPTF_HostAdmin_DSCreateIteratorVars(); |
| f_EPTF_DataSourceClient_sendReady(c_HostAdmin_DataSource_sourceId, f_EPTF_Base_selfName()); |
| } |
| |
| f_EPTF_Base_registerCleanup(refers(f_EPTF_HostAdmin_cleanup_CT)); |
| v_EPTF_HostAdmin_initialized := true; |
| |
| f_EPTF_HostAdmin_debug("f_EPTF_HostAdmin_init_CT(): finished"); |
| } |
| |
| private function f_EPTF_HostAdmin_resetMinMaxAvgCPULoad(in integer pl_idx, in EPTF_IntegerList pl_argList) |
| runs on EPTF_HostAdmin_CT |
| { |
| f_EPTF_StatMeasure_resetStat(v_EPTF_HostAdmin_minHostLoad_statKey); |
| f_EPTF_StatMeasure_resetStat(v_EPTF_HostAdmin_maxHostLoad_statKey); |
| f_EPTF_StatMeasure_resetStat(v_EPTF_HostAdmin_avgHostLoad_statKey); |
| } |
| |
| private function f_EPTF_HostAdmin_addProcesses() |
| runs on EPTF_HostAdmin_CT |
| { |
| var EPTF_IntegerList vl_pids := {}; |
| var EPTF_Base_ComponentInfoList vl_compInfoList := {}; |
| var integer vl_i, vl_count; |
| for(vl_i:=0; vl_i<sizeof(tsp_EPTF_HostAdmin_pidList); vl_i:=vl_i+1) { |
| if(tsp_EPTF_HostAdmin_pidList[vl_i].hostName == v_EPTF_HostAdmin_hostName) { |
| vl_pids := tsp_EPTF_HostAdmin_pidList[vl_i].pids; |
| break; |
| } |
| } |
| |
| vl_compInfoList := f_EPTF_Base_getComponentInfoAll(); |
| vl_count := sizeof(vl_compInfoList); |
| for(vl_i:=0; vl_i<vl_count; vl_i:=vl_i+1) |
| { |
| if(match(vl_compInfoList[vl_i].hostName, pattern v_EPTF_HostAdmin_hostName&"*")) |
| { |
| vl_pids[sizeof(vl_pids)] := vl_compInfoList[vl_i].pid; |
| } |
| } |
| |
| if(c_EPTF_Common_debugSwitch) { |
| f_EPTF_HostAdmin_debug(%definitionId& ": list of PIDs: "& log2str(vl_pids)); |
| } |
| |
| f_EPTF_HostAdmin_appendProcesses(vl_pids); |
| } |
| |
| private function f_EPTF_HostAdmin_appendProcesses( |
| in EPTF_IntegerList pl_pids, |
| in EPTF_CharstringList pl_selfNames := {}) |
| runs on EPTF_HostAdmin_CT |
| { |
| var charstring prefix := f_EPTF_Base_selfName() & "."; |
| |
| if(v_EPTF_HostAdmin_processStatDB.nofProcesses_k < 0) { |
| v_EPTF_HostAdmin_processStatDB.nofProcesses := sizeof(pl_pids); |
| f_EPTF_Var_newInt(prefix & c_EPTF_HostAdmin_nofProcessStats, sizeof(pl_pids), v_EPTF_HostAdmin_processStatDB.nofProcesses_k); |
| } else { |
| v_EPTF_HostAdmin_processStatDB.nofProcesses := |
| v_EPTF_HostAdmin_processStatDB.nofProcesses + sizeof(pl_pids); |
| f_EPTF_Var_adjustContent(v_EPTF_HostAdmin_processStatDB.nofProcesses_k, |
| {intVal := v_EPTF_HostAdmin_processStatDB.nofProcesses + sizeof(pl_pids)}); |
| } |
| |
| for(var integer i:=0; i<sizeof(pl_pids); i:=i+1) { |
| var integer vl_idx := sizeof(v_EPTF_HostAdmin_processStatDB.processes); |
| prefix := f_EPTF_Base_selfName() & "." & c_EPTF_HostAdmin_processPrefix & "." & int2str(vl_idx) & "."; |
| v_EPTF_HostAdmin_processStatDB.processes[vl_idx].idx := f_EPTF_HostAdmin_Base_addProcessStat(pl_pids[i]); |
| f_EPTF_Var_newInt(prefix & c_EPTF_HostAdmin_processPID, pl_pids[i], v_EPTF_HostAdmin_processStatDB.processes[vl_idx].pid_k); |
| f_EPTF_Var_newCharstring(prefix & c_EPTF_HostAdmin_processName, f_EPTF_HostAdmin_Base_getProcessName(pl_pids[i]), v_EPTF_HostAdmin_processStatDB.processes[vl_idx].name_k); |
| if(lengthof(pl_selfNames) > i) { |
| f_EPTF_Var_newCharstring(prefix & c_EPTF_HostAdmin_processSelfName, pl_selfNames[i], v_EPTF_HostAdmin_processStatDB.processes[vl_idx].selfName_k); |
| } else { |
| f_EPTF_Var_newCharstring(prefix & c_EPTF_HostAdmin_processSelfName, "", v_EPTF_HostAdmin_processStatDB.processes[vl_idx].selfName_k); |
| } |
| f_EPTF_Var_newFloat(prefix & c_EPTF_HostAdmin_processCpuLoad, 0.0, v_EPTF_HostAdmin_processStatDB.processes[vl_idx].cpu_k); |
| f_EPTF_Var_newInt(prefix & c_EPTF_HostAdmin_processMemUsage, 0, v_EPTF_HostAdmin_processStatDB.processes[vl_idx].mem_k); |
| } |
| } |
| |
| /////////////////////////////////////////////////////////// |
| // Function: f_EPTF_HostAdmin_cleanup_CT |
| // |
| // Purpose: |
| // Cleanup function for EPTF_HostAdmin_CT |
| // |
| // Parameters: |
| // - |
| // |
| // Return Value: |
| // - |
| // |
| // Errors: |
| // - |
| // |
| // Detailed Comments: |
| // - |
| /////////////////////////////////////////////////////////// |
| private function f_EPTF_HostAdmin_cleanup_CT() runs on EPTF_HostAdmin_CT |
| { |
| if(not v_EPTF_HostAdmin_initialized) { |
| f_EPTF_HostAdmin_debug("f_EPTF_HostAdmin_cleanup_CT(): not initialized"); |
| return; |
| } |
| |
| f_EPTF_HostAdmin_debug("f_EPTF_HostAdmin_cleanup_CT(): started"); |
| |
| if(v_EPTF_HostAdmin_serverRef != null) { |
| @try { |
| Sync_PCO.send(EPTF_HostAdmin_PDU:{bye:={}}); |
| } @catch(dte_msg) { |
| v_EPTF_HostAdmin_serverRef := null; |
| } |
| } |
| |
| v_EPTF_HostAdmin_initialized := false; |
| |
| f_EPTF_HostAdmin_debug( "f_EPTF_HostAdmin_cleanup_CT(): finished"); |
| } |
| |
| /////////////////////////////////////////////////////////// |
| // Function: f_EPTF_HostAdmin_VarGuardFn |
| // |
| // Purpose: |
| // Guard function for measurement variables - makes them read-only from remote components. |
| // |
| // Parameters: |
| // pl_idx - *integer* - index of the EPTF Variable, |
| // pl_argList - <EPTF_IntegerList> - the arguments |
| // pl_newContent - <EPTF_Var_DirectContent> - the new value to be checked |
| // |
| // Return Value: |
| // *boolean* (always false) |
| // |
| // Errors: |
| // - |
| // |
| // Detailed Comments: |
| // This function always returns false, making the variables read-only from remote components. |
| /////////////////////////////////////////////////////////// |
| friend function f_EPTF_HostAdmin_VarGuardFn( |
| in integer pl_idx, |
| in EPTF_IntegerList pl_argList, |
| in EPTF_Var_DirectContent pl_newContent) |
| runs on EPTF_HostAdmin_CT |
| return boolean |
| { |
| return false; |
| } |
| |
| /////////////////////////////////////////////////////////// |
| // Function: f_EPTF_HostAdmin_behavior |
| // |
| // Purpose: |
| // Main behavior function for EPTF_HostAdmin |
| // |
| // Parameters: |
| // pl_selfName - *charstring* - name of the component |
| // pl_hostName - *charstring* - host name |
| // pl_dataSource_Ref - <EPTF_DataSource_CT> - datasource component reference |
| // Return Value: |
| // - |
| // |
| // Errors: |
| // - |
| // |
| // Detailed Comments: |
| // - |
| /////////////////////////////////////////////////////////// |
| public function f_EPTF_HostAdmin_behavior( |
| in charstring pl_selfName, |
| in charstring pl_hostName := "", |
| in EPTF_DataSource_CT pl_dataSource_Ref:= null, |
| in EPTF_HostAdminServerBase_CT pl_server_Ref := null) runs on EPTF_HostAdmin_CT |
| { |
| timer T_getLoad := tsp_EPTF_HostAdmin_loadMeasurementRefreshTime; |
| var integer i; |
| |
| // Init meas interface |
| f_EPTF_HostAdmin_init_CT(pl_selfName, pl_hostName, pl_dataSource_Ref, pl_server_Ref); |
| |
| f_EPTF_HostAdmin_debug("f_EPTF_HostAdmin_behavior(): started"); |
| |
| f_EPTF_Var_refreshContent(v_EPTF_HostAdmin_numCPUs_k); |
| f_EPTF_Var_refreshContent(v_EPTF_HostAdmin_physicalMemory_k); |
| |
| f_EPTF_HostAdmin_debug(log2str("Number of CPUs: ", v_EPTF_HostAdmin_numCPUs)); |
| f_EPTF_HostAdmin_debug(log2str("Physical memory: ", v_EPTF_HostAdmin_physicalMemory, " kB")); |
| |
| T_getLoad.start; |
| |
| f_EPTF_HostAdmin_debug("f_EPTF_HostAdmin_behavior(): entering into main EH"); |
| |
| var EPTF_HostAdmin_PDU vl_pdu; |
| |
| alt |
| { |
| [] T_getLoad.timeout |
| { |
| f_EPTF_HostAdmin_Base_update(); |
| |
| f_EPTF_Var_refreshContent(v_EPTF_HostAdmin_testerHostLoad_k); |
| for(i:=0; i<v_EPTF_HostAdmin_numCPUs; i:=i+1) { |
| f_EPTF_Var_refreshContent(v_EPTF_HostAdmin_CPULoads_k[i]); |
| } |
| f_EPTF_Var_refreshContent(v_EPTF_HostAdmin_freeMemory_k); |
| |
| if(v_EPTF_HostAdmin_serverRef != null) { |
| f_EPTF_HostAdmin_updateProcessList(); |
| } |
| |
| for(i:=0; i<v_EPTF_HostAdmin_processStatDB.nofProcesses; i:=i+1) { |
| f_EPTF_Var_adjustContent(v_EPTF_HostAdmin_processStatDB.processes[i].cpu_k, |
| {floatVal:=f_EPTF_HostAdmin_Base_getProcessCpuLoadByIdx(v_EPTF_HostAdmin_processStatDB.processes[i].idx)}); |
| f_EPTF_Var_adjustContent(v_EPTF_HostAdmin_processStatDB.processes[i].mem_k, |
| {intVal:=f_EPTF_HostAdmin_Base_getProcessMemUsageByIdx(v_EPTF_HostAdmin_processStatDB.processes[i].idx)}); |
| } |
| |
| if(tsp_debug_EPTF_HostAdmin_Functions) { |
| f_EPTF_HostAdmin_debug("======================================="); |
| if(v_EPTF_HostAdmin_numCPUs < 2) { |
| f_EPTF_HostAdmin_debug(log2str("CPU load: ", v_EPTF_HostAdmin_testerHostLoad)); |
| } else { |
| f_EPTF_HostAdmin_debug(log2str("Average CPU load: ", v_EPTF_HostAdmin_testerHostLoad)); |
| for(i:=0; i<v_EPTF_HostAdmin_numCPUs; i:=i+1) { |
| f_EPTF_HostAdmin_debug(log2str("Load of CPU", i, ": ", v_EPTF_HostAdmin_CPULoads[i])); |
| } |
| } |
| f_EPTF_HostAdmin_debug(log2str("Free memory: ", v_EPTF_HostAdmin_freeMemory, " kB")); |
| for(i:=0; i<v_EPTF_HostAdmin_processStatDB.nofProcesses; i:=i+1) { |
| f_EPTF_HostAdmin_debug(log2str( |
| "Process ", f_EPTF_Var_getCharstringValue(v_EPTF_HostAdmin_processStatDB.processes[i].name_k), |
| " pid ", f_EPTF_Var_getIntValue(v_EPTF_HostAdmin_processStatDB.processes[i].pid_k), |
| " cpu ", f_EPTF_Var_getFloatValue(v_EPTF_HostAdmin_processStatDB.processes[i].cpu_k), "%"& |
| " mem ", f_EPTF_Var_getIntValue(v_EPTF_HostAdmin_processStatDB.processes[i].mem_k), "kB" |
| )); |
| } |
| } |
| |
| if(v_EPTF_HostAdmin_serverRef != null) { |
| var EPTF_HostAdmin_PDUHostStat vl_stat; |
| f_EPTF_HostAdmin_prepareStat(vl_stat); |
| @try { |
| Sync_PCO.send(EPTF_HostAdmin_PDU:{hostStat:=vl_stat}); |
| } @catch(dte_msg) { |
| v_EPTF_HostAdmin_serverRef := null; |
| } |
| } |
| |
| T_getLoad.start; |
| repeat; |
| } |
| [] Sync_PCO.receive(EPTF_HostAdmin_PDU:?) -> value vl_pdu |
| { |
| if(ischosen(vl_pdu.sortBy)) { |
| v_EPTF_HostAdmin_sortBy := vl_pdu.sortBy; |
| } else { |
| f_EPTF_HostAdmin_warning("received unsupported PDU: "&log2str(vl_pdu)); |
| } |
| repeat; |
| } |
| |
| } // alt |
| |
| f_EPTF_Base_cleanup_CT(); |
| |
| f_EPTF_HostAdmin_debug("f_EPTF_HostAdmin_behavior(): finished"); |
| } |
| |
| private function f_EPTF_HostAdmin_prepareStat(out EPTF_HostAdmin_PDUHostStat pl_stat) |
| runs on EPTF_HostAdmin_CT |
| { |
| pl_stat.hostName := v_EPTF_HostAdmin_hostName; |
| pl_stat.ipv4Addr := v_EPTF_HostAdmin_ipv4Addr; |
| pl_stat.ipv6Addr := v_EPTF_HostAdmin_ipv6Addr; |
| pl_stat.physicalMem := f_EPTF_Var_getIntValue(v_EPTF_HostAdmin_physicalMemory_k); |
| pl_stat.freeMem := f_EPTF_Var_getIntValue(v_EPTF_HostAdmin_freeMemory_k); |
| pl_stat.cpuLoad := v_EPTF_HostAdmin_testerHostLoad; |
| pl_stat.cpuMin := f_EPTF_Var_getFloatValue(v_EPTF_HostAdmin_minHostLoad_k); |
| pl_stat.cpuMax := f_EPTF_Var_getFloatValue(v_EPTF_HostAdmin_maxHostLoad_k); |
| pl_stat.cpuAvg := f_EPTF_Var_getFloatValue(v_EPTF_HostAdmin_avgHostLoad_k); |
| pl_stat.perCpuLoad := v_EPTF_HostAdmin_CPULoads; |
| |
| pl_stat.processes := {}; |
| for(var integer vl_idx:=0;vl_idx<lengthof(v_EPTF_HostAdmin_processStatDB.processes);vl_idx:=vl_idx+1) { |
| pl_stat.processes[vl_idx] := { |
| selfName := f_EPTF_Var_getCharstringValue(v_EPTF_HostAdmin_processStatDB.processes[vl_idx].selfName_k), |
| pid := f_EPTF_Var_getIntValue(v_EPTF_HostAdmin_processStatDB.processes[vl_idx].pid_k), |
| cpuLoad := f_EPTF_Var_getFloatValue(v_EPTF_HostAdmin_processStatDB.processes[vl_idx].cpu_k), |
| memUsage := f_EPTF_Var_getIntValue(v_EPTF_HostAdmin_processStatDB.processes[vl_idx].mem_k) |
| } |
| } |
| |
| //TODO |
| select(v_EPTF_HostAdmin_sortBy) { |
| case(SelfName) { |
| pl_stat.processOrder := v_EPTF_HostAdmin_processNameOrder; |
| } |
| case(CpuLoad) { |
| var EPTF_RBT_TreeId vl_sortTree := f_EPTF_RBT_createFloatTree(); |
| for(var integer i:=0; i<lengthof(pl_stat.processes); i:=i+1) { |
| f_EPTF_RBT_insertFloatItem(vl_sortTree, pl_stat.processes[i].cpuLoad); |
| } |
| |
| // TODO: change to sortDecremental if implemented |
| //f_EPTF_RBT_sortDecremental(vl_sortTree, pl_stat.processOrder); |
| |
| var EPTF_IntegerList vl_tmp := {}; |
| f_EPTF_RBT_sortIncremental(vl_sortTree, vl_tmp); |
| for(var integer i:=0; i<lengthof(vl_tmp); i:=i+1) { |
| pl_stat.processOrder[lengthof(vl_tmp) - 1 - i] := vl_tmp[i]; |
| } |
| |
| f_EPTF_RBT_deleteTree(vl_sortTree); |
| } |
| case(MemUsage) { |
| var EPTF_RBT_TreeId vl_sortTree := f_EPTF_RBT_createIntTree(); |
| for(var integer i:=0; i<lengthof(pl_stat.processes); i:=i+1) { |
| f_EPTF_RBT_insertIntItem(vl_sortTree, pl_stat.processes[i].memUsage); |
| } |
| |
| // TODO: change to sortDecremental if implemented |
| //f_EPTF_RBT_sortDecremental(vl_sortTree, pl_stat.processOrder); |
| |
| var EPTF_IntegerList vl_tmp := {}; |
| f_EPTF_RBT_sortIncremental(vl_sortTree, vl_tmp); |
| for(var integer i:=0; i<lengthof(vl_tmp); i:=i+1) { |
| pl_stat.processOrder[lengthof(vl_tmp) - 1 - i] := vl_tmp[i]; |
| } |
| |
| f_EPTF_RBT_deleteTree(vl_sortTree); |
| } |
| case(DontSort) { |
| pl_stat.processOrder := {}; |
| } |
| case else { |
| f_EPTF_HostAdmin_error(%definitionId&": unsupported sort option "&log2str(v_EPTF_HostAdmin_sortBy)); |
| } |
| } |
| |
| } |
| |
| private function f_EPTF_HostAdmin_updateProcessList() |
| runs on EPTF_HostAdmin_CT return boolean |
| { |
| var EPTF_Base_ComponentInfoList vl_compInfoList := f_EPTF_Base_getComponentInfoAll(); |
| if(v_EPTF_HostAdmin_compInfoList == vl_compInfoList) { return false; } |
| v_EPTF_HostAdmin_compInfoList := vl_compInfoList; |
| var EPTF_IntegerList vl_pids := {}; |
| var EPTF_CharstringList vl_selfNames := {}; |
| var integer vl_idx := 0; |
| for(var integer i:=0; i<lengthof(vl_compInfoList); i:=i+1) { |
| if(vl_compInfoList[i].hostName == v_EPTF_HostAdmin_hostName) { |
| //TODO: find out if it's in the processes list already, add to vl_pids if not |
| // store selfnames of the processes! |
| var boolean vl_found := false; |
| for(var integer j:=0; j<lengthof(v_EPTF_HostAdmin_processStatDB.processes); j:=j+1) { |
| if(f_EPTF_Var_getIntValue(v_EPTF_HostAdmin_processStatDB.processes[j].pid_k) |
| == vl_compInfoList[i].pid) { |
| vl_found := true; |
| break; |
| } |
| } |
| if(not vl_found) { |
| vl_pids[vl_idx] := vl_compInfoList[i].pid; |
| vl_selfNames[vl_idx] := vl_compInfoList[i].selfName; |
| vl_idx := vl_idx + 1; |
| } |
| } |
| } |
| if(lengthof(vl_pids) > 0) { |
| f_EPTF_HostAdmin_appendProcesses(vl_pids, vl_selfNames); |
| } |
| var EPTF_RBT_TreeId vl_sortTree := f_EPTF_RBT_createCharstringTree(); |
| for(var integer i:=0; i<lengthof(v_EPTF_HostAdmin_processStatDB.processes); i:=i+1) { |
| f_EPTF_RBT_insertCharstringItem(vl_sortTree, f_EPTF_Var_getCharstringValue(v_EPTF_HostAdmin_processStatDB.processes[i].selfName_k)); |
| } |
| f_EPTF_RBT_sortIncremental(vl_sortTree, v_EPTF_HostAdmin_processNameOrder); |
| f_EPTF_RBT_deleteTree(vl_sortTree); |
| return true; |
| } |
| |
| group Logging { |
| |
| /////////////////////////////////////////////////////////// |
| // Function: f_EPTF_HostAdmin_error |
| // |
| // Purpose: |
| // Function to log an error from HostAdmin feature. |
| // |
| // Parameters: |
| // - pl_message - *in* *charstring* - the message to log |
| // |
| // Return Value: |
| // - |
| // |
| // Errors & assertions: |
| // - |
| // |
| // Detailed Comments: |
| // - |
| // |
| /////////////////////////////////////////////////////////// |
| friend function f_EPTF_HostAdmin_error(in charstring pl_message) |
| runs on EPTF_HostAdmin_CT |
| { |
| f_EPTF_Logging_error(true, tsp_EPTF_HostAdmin_loggingComponentMask&": "&pl_message); |
| f_EPTF_Base_stopAll(); |
| } |
| |
| /////////////////////////////////////////////////////////// |
| // 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}); |
| } |
| |
| /////////////////////////////////////////////////////////// |
| // Function: f_EPTF_HostAdmin_debug |
| // |
| // Purpose: |
| // Function to log a debug message from HostAdmin feature. |
| // |
| // Parameters: |
| // - pl_message - *in* *charstring* - the message to log |
| // |
| // Return Value: |
| // - |
| // |
| // Errors & assertions: |
| // - |
| // |
| // Detailed Comments: |
| // - |
| // |
| /////////////////////////////////////////////////////////// |
| friend function f_EPTF_HostAdmin_debug(in @lazy charstring pl_message) |
| runs on EPTF_HostAdmin_CT |
| { |
| f_EPTF_Logging_debugV2(pl_message, v_HostAdmin_loggingMaskId, {c_EPTF_HostAdmin_loggingClassIdx_Debug}); |
| } |
| |
| /////////////////////////////////////////////////////////// |
| // Function: f_EPTF_HostAdmin_debugEnabled |
| // |
| // Purpose: |
| // Function to check if debug is enabled for HostAdmin |
| // |
| // Parameters: |
| // - |
| // |
| // Return Value: |
| // *boolean* - true if debug enabled |
| // |
| // Errors & assertions: |
| // - |
| // |
| // Detailed Comments: |
| // - |
| // |
| /////////////////////////////////////////////////////////// |
| friend function f_EPTF_HostAdmin_debugEnabled() |
| runs on EPTF_HostAdmin_CT |
| return boolean |
| { |
| return f_EPTF_Logging_isEnabled(v_HostAdmin_loggingMaskId, c_EPTF_HostAdmin_loggingClassIdx_Debug); |
| } |
| } // group Logging |
| |
| } // module |
| |