@ -41,6 +41,19 @@ class Process():
mMSTdNInt = None
mMSTStartTimeList = [ ]
mAgentMuteBool = False # Mute any sends to agent while some action is perfomed
def MuteWait ( self ) :
"""
Internal def . Wait when class is apply to send new activities to the agent
: return :
"""
lIntervalSecFloat = 0.3
while self . mAgentMuteBool == True :
time . sleep ( lIntervalSecFloat )
return None
def __init__ ( self , inAgentHostNameStr , inAgentUserNameStr , inProcessNameWOExeStr , inStartPathStr = None , inStartCMDStr = None , inStopSafeTimeoutSecFloat = 120 ) :
self . mAgentHostNameStr = inAgentHostNameStr
self . mAgentUserNameStr = inAgentUserNameStr
@ -83,9 +96,21 @@ class Process():
if ldTSecFloat < self . mMSTdTSecFloat : lMSTStartTimeList . append ( lTimeItemSecFloat )
self . mMSTStartTimeList = lMSTStartTimeList # Set new list
# Check count in list
if len ( lMSTStartTimeList ) > self . mMSTdNInt : self . mStatusStr = " 1_STOPPED_MANUAL "
if len ( lMSTStartTimeList ) > self . mMSTdNInt :
self . mStatusStr = " 1_STOPPED_MANUAL "
# Log info about process
lL = __Orchestrator__ . OrchestratorLoggerGet ( )
lL . info ( f " Managers.Process ( { self . mAgentHostNameStr } , { self . mAgentUserNameStr } , { self . mProcessNameWOExeStr } ): ManualStopTrigger is activated. { self . mMSTdNInt } start tries in { self . mMSTdTSecFloat } sec. " )
return self . mStatusStr
def ManualStopListClear ( self ) - > None :
"""
Clear the last start tries list .
: return : None
"""
self . mMSTStartTimeList = [ ]
def Manual2Auto ( self ) - > str :
"""
Remove Manual flag from process ( if exists ) - it will allow the schedule operations via def StatusCheckStart ( self ) : def StatusCheckStorForce ( self ) : def StatusCheckStopSafe ( self ) :
@ -108,17 +133,18 @@ class Process():
: param inIsManualBool : Default is True - Mark this operation as manual - StatusCheckStart / Stop will be blocked - only StatusCheck will be working . False - Auto operation
: return : Process status . See self . mStatusStr . 0 _STOPPED 1 _STOPPED_MANUAL 2 _STOP_SAFE 3 _STOP_SAFE_MANUAL 4 _STARTED 5 _STARTED_MANUAL
"""
if inIsManualBool == False : self . ManualStopTriggerNewStart ( ) # Set the time
if ( self . mStatusStr == " 1_STOPPED_MANUAL " or " STOP_SAFE " in self . mStatusStr ) and inIsManualBool == False :
lStr = f " Managers.Process ( { self . mAgentHostNameStr } , { self . mAgentUserNameStr } , { self . mProcessNameWOExeStr } ): Process will not start because of stopped manual or stop safe is now. "
__Orchestrator__ . OrchestratorLoggerGet ( ) . warning ( lStr )
return self . mStatusStr
if inIsManualBool == False : self . ManualStopTriggerNewStart ( ) # Set the time
# Send activity item to agent - wait result
if self . mStartPathStr is not None : lCMDStr = f " start { os . path . abspath ( self . mStartPathStr ) } "
elif self . mStartCMDStr is not None : lCMDStr = f " start { self . mStartCMDStr } "
#import pdb
#pdb.set_trace()
self . MuteWait ( )
self . mAgentMuteBool = True
lActivityItemStart = __Orchestrator__ . ProcessorActivityItemCreate ( inDef = " OSCMD " ,
inArgDict = { " inCMDStr " : lCMDStr , " inSendOutputToOrchestratorLogsBool " : False } ,
inArgGSettingsStr = " inGSettings " )
@ -132,6 +158,7 @@ class Process():
self . mStatusStr = " 4_STARTED "
# Log info about process
self . StatusChangeLog ( )
self . mAgentMuteBool = False
return self . mStatusStr
def StartCheck ( self ) - > str :
@ -140,6 +167,7 @@ class Process():
: return : Process status . See self . mStatusStr . 0 _STOPPED 1 _STOPPED_MANUAL 2 _STOP_SAFE 3 _STOP_SAFE_MANUAL 4 _STARTED 5 _STARTED_MANUAL
"""
self . MuteWait ( )
if self . mStatusStr == " 0_STOPPED " :
self . Start ( inIsManualBool = False )
return self . mStatusStr
@ -152,7 +180,8 @@ class Process():
: param inIsManualBool : Default is True - Mark this operation as manual - StatusCheckStart / Stop will be blocked - only StatusCheck will be working . False - Auto operation
: return : Process status . See self . mStatusStr . 0 _STOPPED 1 _STOPPED_MANUAL 2 _STOP_SAFE 3 _STOP_SAFE_MANUAL 4 _STARTED 5 _STARTED_MANUAL
"""
self . MuteWait ( )
self . mAgentMuteBool = True
# Send activity item to agent - wait result
lCMDStr = f ' taskkill /im " { self . mProcessNameWOExeStr } .exe " /fi " username eq %USERNAME% " '
lActivityItemStart = __Orchestrator__ . ProcessorActivityItemCreate (
@ -180,6 +209,7 @@ class Process():
self . StopForce ( inIsManualBool = inIsManualBool )
# Log info about process
self . StatusChangeLog ( )
self . mAgentMuteBool = False
return self . mStatusStr
def StopSafeCheck ( self ) - > str :
@ -188,6 +218,7 @@ class Process():
: return : Process status . See self . mStatusStr . 0 _STOPPED 1 _STOPPED_MANUAL 2 _STOP_SAFE 3 _STOP_SAFE_MANUAL 4 _STARTED 5 _STARTED_MANUAL
"""
self . MuteWait ( )
if self . mStatusStr == " 4_STARTED " :
self . StopSafe ( inIsManualBool = False )
return self . mStatusStr
@ -200,6 +231,8 @@ class Process():
: param inIsManualBool : Default is True - Mark this operation as manual - StatusCheckStart / Stop will be blocked - only StatusCheck will be working . False - Auto operation
: return : Process status . See self . mStatusStr . 0 _STOPPED 1 _STOPPED_MANUAL 2 _STOP_SAFE 3 _STOP_SAFE_MANUAL 4 _STARTED 5 _STARTED_MANUAL
"""
self . MuteWait ( )
self . mAgentMuteBool = True
# Send activity item to agent - wait result
lCMDStr = f ' taskkill /F /im " { self . mProcessNameWOExeStr } .exe " /fi " username eq %USERNAME% " '
lActivityItemStart = __Orchestrator__ . ProcessorActivityItemCreate (
@ -214,6 +247,7 @@ class Process():
self . mStatusStr = " 0_STOPPED "
# Log info about process
self . StatusChangeLog ( )
self . mAgentMuteBool = False
return self . mStatusStr
def StopForceCheck ( self ) - > str :
@ -222,6 +256,7 @@ class Process():
: return : Process status . See self . mStatusStr . 0 _STOPPED 1 _STOPPED_MANUAL 2 _STOP_SAFE 3 _STOP_SAFE_MANUAL 4 _STARTED 5 _STARTED_MANUAL
"""
self . MuteWait ( )
if self . mStatusStr == " 4_STARTED " :
self . StopForce ( inIsManualBool = False )
return self . mStatusStr
@ -268,6 +303,8 @@ class Process():
# Send activity item to agent - wait result
lLogBool = False
lActivityItemUserProcessList = __Orchestrator__ . ProcessorActivityItemCreate ( inDef = " ProcessWOExeUpperUserListGet " )
self . MuteWait ( )
self . mAgentMuteBool = True
lGUIDStr = __Orchestrator__ . AgentActivityItemAdd ( inHostNameStr = self . mAgentHostNameStr , inUserStr = self . mAgentUserNameStr , inActivityItemDict = lActivityItemUserProcessList )
lUserProcessList = __Orchestrator__ . AgentActivityItemReturnGet ( inGUIDStr = lGUIDStr )
if self . mProcessNameWOExeStr . upper ( ) in lUserProcessList :
@ -282,6 +319,7 @@ class Process():
if self . mStatusStr is None : self . mStatusStr = " 0_STOPPED " ; lLogBool = True
# Log info about process
if lLogBool == True : self . StatusChangeLog ( )
self . mAgentMuteBool = False
return self . mStatusStr
def StatusCheckStart ( self ) :
"""
@ -465,3 +503,32 @@ def ProcessManual2Auto(inAgentHostNameStr: str, inAgentUserNameStr: str, inProce
lProcess = ProcessGet ( inAgentHostNameStr = inAgentHostNameStr , inAgentUserNameStr = inAgentUserNameStr ,
inProcessNameWOExeStr = inProcessNameWOExeStr )
if lProcess is not None : return lProcess . Manual2Auto ( )
def ProcessManualStopTriggerSet ( inAgentHostNameStr : str , inAgentUserNameStr : str , inProcessNameWOExeStr : str , inMSTdTSecFloat : float , inMSTdNInt : int ) - > None :
"""
Remove Manual flag from process ( if exists ) - it will allow the schedule operations via def StatusCheckStart ( self ) : def StatusCheckStorForce ( self ) : def StatusCheckStopSafe ( self ) :
: param inAgentHostNameStr : Agent hostname in any case . Required to identify Process
: param inAgentUserNameStr : Agent user name in any case . Required to identify Process
: param inProcessNameWOExeStr : The process name without extension . exe ( the key of the Process instance ) . Any case - will be processed to the upper case
: param inMSTdTSecFloat : Time periods in seconds
: param inMSTdNInt : Counts of the start tries
: return : None
"""
lProcess = ProcessGet ( inAgentHostNameStr = inAgentHostNameStr , inAgentUserNameStr = inAgentUserNameStr ,
inProcessNameWOExeStr = inProcessNameWOExeStr )
if lProcess is not None : lProcess . ManualStopTriggerSet ( inMSTdTSecFloat = inMSTdTSecFloat , inMSTdNInt = inMSTdNInt )
def ProcessManualStopListClear ( inAgentHostNameStr : str , inAgentUserNameStr : str , inProcessNameWOExeStr : str ) - > None :
"""
Clear the last start tries list .
: param inAgentHostNameStr : Agent hostname in any case . Required to identify Process
: param inAgentUserNameStr : Agent user name in any case . Required to identify Process
: param inProcessNameWOExeStr : The process name without extension . exe ( the key of the Process instance ) . Any case - will be processed to the upper case
: return : None
"""
lProcess = ProcessGet ( inAgentHostNameStr = inAgentHostNameStr , inAgentUserNameStr = inAgentUserNameStr ,
inProcessNameWOExeStr = inProcessNameWOExeStr )
if lProcess is not None : lProcess . ManualStopListClear ( )