project BLF > class BBaseDaemon > method ApiValidateStatus

Description

Checks for all the daemon processes that were originally started (fcDaemon.DaemonProcessIDs), whether the physical process is still operational. The logic should 1. update the DaemonProcessIDs field with the right situation, and 2. update the DaemonStatus from "running" to "inactive" if none of the physical processes are available anymore.


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


BLF
method BBaseDaemon.ApiDaemonIsRunning
method BBaseDaemonProcessor.ValidateCurrentDaemonStatus
method BReportComm.apiReportDaemonIsRunning


program code (program3/bbasedaemon.p)

/* Find information about the Daemon */
<Q-1 run DaemonInfo (all) (Read) (NoCache)
   (input ?, (DaemonId)
    input vcFcDaemonName, (DaemonName)
    input ?, (DaemonStatus)
    input ?, (DaemonStatusDiffersFrom)
    output dataset tqDaemonInfo) in BBaseDaemon >
    
find first tqDaemonInfo where
           tqDaemonInfo.tcDaemonName = vcFcDaemonName
           no-error.
if not available tqDaemonInfo /*daemon is not yet configured*/
then return.

/*if the status is not running and not stopping, just return*/
if tqDaemonInfo.tcDaemonStatus <> {&DAEMONSTATUS-RUNNING} and
   tqDaemonInfo.tcDaemonStatus <> {&DAEMONSTATUS-STOPPING}
then return.

assign vcProcessIds = tqDaemonInfo.tcDaemonProcessIDs.

do viFcCount1 = 1 to num-entries(vcProcessIds):

    /*check if process is active on server*/
    viProcessId = 0.
    
    if num-entries (entry(viFcCount1,vcProcessIds),":") = 2
    then assign vcProcessHostname = entry(1,entry(viFcCount1,vcProcessIds),":")
                viProcessId  = integer (entry(2,entry(viFcCount1,vcProcessIds),":")) no-error.
    else assign viProcessId = integer(entry(viFcCount1,vcProcessIds)) no-error.
    
    if viProcessId = 0 or
       viProcessId = ?
    then vlValid = no.
    else do:
        <M-23 run Main  (input  viSessionId (iiSessionId)) in TDaemonUtility>
        <M-25 run ProcessIsValid
           (input  vcFcDaemonName (icDaemonName), 
            input  vcProcessHostname (icProcessHostname), 
            input  viProcessId (iiProcessNr), 
            input  tqDaemonInfo.tcDaemonAppserver (icDaemonAppserverURL), 
            output vlValid (olValid), 
            output vcMessage (ocMessage), 
            output viFcReturnSuper (oiReturnStatus)) in TDaemonUtility>
        run gipr_DeleteProcedure in vhFcComponent.
        delete procedure vhFcComponent.
        
        if vcMessage <> ""
        then do:
            <M-26 run SetMessage
               (input  vcMessage (icMessage), 
                input  '' (icArguments), 
                input  '' (icFieldName), 
                input  '' (icFieldValue), 
                input  'D' (icType), 
                input  3 (iiSeverity), 
                input  '' (icRowid), 
                input  'BLF-16':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BBaseDaemon>
        end.
    end.

    if vlValid = false 
    then do:
        assign entry(viFcCount1,vcProcessIds) = ''
               vcMessage = trim(#T-22'The daemon process with id $1 was not found. The daemon status might have been changed to reflect the current situation.':255(5115)T-22#)
               oiReturnStatus = 1.
        <M-19 run SetMessage
           (input  vcMessage (icMessage), 
            input  string(viProcessId) (icArguments), 
            input  '' (icFieldName), 
            input  '' (icFieldValue), 
            input  'W':U (icType), 
            input  3 (iiSeverity), 
            input  '' (icRowid), 
            input  'BLF-15':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BBaseDaemon>
    end.
end.

/*remove overhead comma's*/
assign vcProcessIds = trim(replace(vcProcessIds,',,',','),',').

/*if there are no processes left, uncontitional stop the daemon*/
if vcProcessIds = ''
then do:
    <M-6 run ApiUnconditionalStop
       (output viFcReturnSuper (oiReturnStatus)) in BBaseDaemon>
    if viFcReturnSuper <> 0
    then assign oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then return.
end.
else if trim(vcProcessIds) <> trim(tqDaemonInfo.tcDaemonProcessIDs)
then do: /*update the processes list of the daemon*/
    <M-7 run DataLoad
       (input  '':U (icRowids), 
        input  tqDaemonInfo.tiDaemonId (icPkeys), 
        input  '':U (icObjectIds), 
        input  '' (icFreeform), 
        input  false (ilKeepPrevious), 
        output viFcReturnSuper (oiReturnStatus)) in BBaseDaemon>    
    if viFcReturnSuper <> 0
    then assign oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then return.
    
    find tfcDaemon where 
         tfcDaemon.DaemonId = tqDaemonInfo.tiDaemonId
         no-error.
    if not available tfcDaemon 
    then do :
        assign oiReturnStatus = -3
               vcMessage      = trim(substitute(#T-13'Internal error: the &1 daemon cannot be loaded.':255(53)T-13#, trim(tqDaemonInfo.tcDaemonName))) + chr(10) + 
                                trim(#T-14'Please contact your system administrator.':255(54)T-14#).
        <M-8 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  1 (iiSeverity), 
            input  '':U (icRowid), 
            input  'BLF-14':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BBaseDaemon>
        Return.
    end. /* if not available tfcDaemon */    
            
    assign tfcDaemon.DaemonProcessIDs       = vcProcessIds
           tfcDaemon.tc_Status              = "C":U.

    <M-10 run ValidateBC
       (output viFcReturnSuper (oiReturnStatus)) in BBaseDaemon>    
    if viFcReturnSuper <> 0
    then assign oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then return.
    
    <M-11 run AdditionalUpdates
       (output viFcReturnSuper (oiReturnStatus)) in BBaseDaemon> 
    if viFcReturnSuper <> 0
    then assign oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then return.
    
    <M-12 run DataSave
       (output viFcReturnSuper (oiReturnStatus)) in BBaseDaemon>
    if viFcReturnSuper <> 0
    then assign oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then return.
end.


Sample code: how to call this method through RPCRequestService (QXtend Inbound)

define temp-table ttContext no-undo
    field propertyQualifier as character
    field propertyName as character
    field propertyValue as character
    index entityContext is primary unique
        propertyQualifier
        propertyName
    index propertyQualifier
        propertyQualifier.

define dataset dsContext for ttContext.

define variable vhContextDS as handle no-undo.
define variable vhExceptionDS as handle no-undo.
define variable vhServer as handle no-undo.
define variable vhInputDS as handle no-undo.
define variable vhInputOutputDS as handle no-undo.
define variable vhOutputDS as handle no-undo.
define variable vhParameter as handle no-undo.

/* Create context */
create ttContext.
assign ttContext.propertyName = "programName"
       ttContext.propertyValue = "BBaseDaemon".
create ttContext.
assign ttContext.propertyName = "methodName"
       ttContext.propertyValue = "ApiValidateStatus".
create ttContext.
assign ttContext.propertyName = "applicationId"
       ttContext.propertyValue = "fin".
create ttContext.
assign ttContext.propertyName = "entity"
       ttContext.propertyValue = "1000".
create ttContext.
assign ttContext.propertyName = "userName"
       ttContext.propertyValue = "mfg".
create ttContext.
assign ttContext.propertyName = "password"
       ttContext.propertyValue = "".

/* Connect the AppServer */
create server vhServer.
vhServer:connect("-URL <appserver-url>").

if not vhServer:connected()
then do:
    message "Could not connect AppServer" view-as alert-box error title "Error".
    return.
end.

/* Run */
assign vhContextDS = dataset dsContext:handle.

run program/rpcrequestservice.p on vhServer
    (input-output dataset-handle vhContextDS by-reference,
           output dataset-handle vhExceptionDS,
     input        dataset-handle vhInputDS by-reference,
     input-output dataset-handle vhInputOutputDS by-reference,
           output dataset-handle vhOutputDS).

/* Handle output however you want, in this example, we dump it to xml */
if valid-handle(vhExceptionDS)
then vhExceptionDS:write-xml("file", "Exceptions.xml", true).

if valid-handle(vhOutputDS)
then vhOutputDS:write-xml("file", "Output.xml", true).

/* Cleanup */
vhServer:disconnect().
assign vhServer = ?.

if valid-handle(vhInputDS)
then delete object vhInputDS.

if valid-handle(vhOutputDS)
then delete object vhOutputDS.

if valid-handle(vhExceptionDS)
then delete object vhExceptionDS.