From 21f7f1f86dc37c24f38cc80aa01cf3b922460c04 Mon Sep 17 00:00:00 2001 From: Ivan Maslov Date: Tue, 13 Apr 2021 18:12:39 +0300 Subject: [PATCH] Add Agent feedback about Activity Item execution :) need test! --- Sources/pyOpenRPA/Agent/A2O.py | 6 ++ Sources/pyOpenRPA/Agent/Processor.py | 12 ++- .../pyOpenRPA/Orchestrator/ServerSettings.py | 7 ++ .../Orchestrator/SettingsTemplate.py | 10 ++ .../Orchestrator/__Orchestrator__.py | 54 +++++++++-- Wiki/ENG_Guide/html/Orchestrator/02_Defs.html | 55 ++++++++++- .../Orchestrator/03_gSettingsTemplate.html | 10 ++ .../Orchestrator/__Orchestrator__.html | 58 +++++++++-- Wiki/ENG_Guide/html/genindex.html | 6 +- Wiki/ENG_Guide/html/objects.inv | Bin 1261 -> 1275 bytes Wiki/ENG_Guide/html/searchindex.js | 2 +- .../markdown/Orchestrator/02_Defs.md | 91 ++++++++++++++++-- .../Orchestrator/03_gSettingsTemplate.md | 10 ++ 13 files changed, 295 insertions(+), 26 deletions(-) diff --git a/Sources/pyOpenRPA/Agent/A2O.py b/Sources/pyOpenRPA/Agent/A2O.py index c01209ae..f16cdf1d 100644 --- a/Sources/pyOpenRPA/Agent/A2O.py +++ b/Sources/pyOpenRPA/Agent/A2O.py @@ -24,4 +24,10 @@ def _A2ODataSend(inGSettings, inDataDict): # Send some logs to orchestrator def LogListSend(inGSettings, inLogList): lDataDict = { "HostNameUpperStr": inGSettings["AgentDict"]["HostNameUpperStr"], "UserUpperStr": inGSettings["AgentDict"]["UserUpperStr"], "LogList": inLogList} + _A2ODataSend(inGSettings=inGSettings, inDataDict=lDataDict) + +# Send some def result to the orchestrator by the Activity Item GUID str +def ActivityReturnDictSend(inGSettings, inActivityItemGUIDStr, inReturn): + lDataDict = {"HostNameUpperStr": inGSettings["AgentDict"]["HostNameUpperStr"], + "UserUpperStr": inGSettings["AgentDict"]["UserUpperStr"], "ActivityReturnDict": {inActivityItemGUIDStr:inReturn}} _A2ODataSend(inGSettings=inGSettings, inDataDict=lDataDict) \ No newline at end of file diff --git a/Sources/pyOpenRPA/Agent/Processor.py b/Sources/pyOpenRPA/Agent/Processor.py index 302552b2..9413235f 100644 --- a/Sources/pyOpenRPA/Agent/Processor.py +++ b/Sources/pyOpenRPA/Agent/Processor.py @@ -1,5 +1,6 @@ # 1.2.0 - general processor - contains old orchestrator processor + RDPActive processor import time, copy, threading +from . import A2O # Run processor synchronious def ProcessorRunSync(inGSettings): """ @@ -10,7 +11,8 @@ def ProcessorRunSync(inGSettings): # "ArgList":[1,2,3], # Args list # "ArgDict":{"ttt":1,"222":2,"dsd":3}, # Args dictionary # "ArgGSettings": None # Name of GSettings attribute: str (ArgDict) or index (for ArgList) - # "ArgLogger": None # Name of GSettings attribute: str (ArgDict) or index (for ArgList) + # "ArgLogger": None, # Name of GSettings attribute: str (ArgDict) or index (for ArgList) + # "GUIDStr": "sadasd-asdas-d-asdasd", # ActivityItem GUID which identify the Activity # }, ], "AliasDefDict": {}, # Storage for def with Str alias. To use it see pyOpenRPA.Orchestrator.ControlPanel @@ -24,7 +26,13 @@ def ProcessorRunSync(inGSettings): if len(lActivityList)>0: if lL: lL.debug(f'Processor ActivityList len: {len(lActivityList)}') lActivityItem = inGSettings["ProcessorDict"]["ActivityList"].pop(0) # Extract the first item from processor queue - ActivityListExecute(inGSettings = inGSettings, inActivityList = [lActivityItem]) # execute the activity item + lResultList = ActivityListExecute(inGSettings = inGSettings, inActivityList = [lActivityItem]) # execute the activity item + #Some help code + if len(lResultList) == 0: lResultList= [None] + # Send result to Orc if we have GUIDStr + if "GUIDStr" in lActivityItem: + # Def to send to Orc + A2O.ActivityReturnDictSend(inGSettings=inGSettings, inActivityItemGUIDStr=lActivityItem["GUIDStr"],inReturn=lResultList[0]) else: time.sleep(inGSettings["ProcessorDict"]["CheckIntervalSecFloat"]) # Sleep when list is empty diff --git a/Sources/pyOpenRPA/Orchestrator/ServerSettings.py b/Sources/pyOpenRPA/Orchestrator/ServerSettings.py index fef2460e..10e29ff5 100644 --- a/Sources/pyOpenRPA/Orchestrator/ServerSettings.py +++ b/Sources/pyOpenRPA/Orchestrator/ServerSettings.py @@ -400,6 +400,7 @@ def pyOpenRPA_Agent_O2A(inRequest, inGSettings): lThisAgentDict["ConnectionCountInt"] -= 1 # Connection go to be closed - decrement the connection count # See docs in Agent (pyOpenRPA.Agent.A2O) def pyOpenRPA_Agent_A2O(inRequest, inGSettings): + lL = inGSettings["Logger"] # Recieve the data lValueStr = None if inRequest.headers.get('Content-Length') is not None: @@ -410,6 +411,12 @@ def pyOpenRPA_Agent_A2O(inRequest, inGSettings): if "LogList" in lInput: for lLogItemStr in lInput["LogList"]: inGSettings["Logger"].info(lLogItemStr) + if "ActivityReturnDict" in lInput: + for lActivityReturnItemKeyStr in lInput["ActivityReturnDict"]: + lActivityReturnItemValue = lInput["ActivityReturnDict"][lActivityReturnItemKeyStr] + # Create item in gSettings + inGSettings["AgentActivityReturnDict"][lActivityReturnItemKeyStr]=SettingsTemplate.__AgentActivityReturnDictItemCreate__(inReturn=lActivityReturnItemValue) + if lL: lL.debug(f"SERVER: pyOpenRPA_Agent_A2O:: Has recieved result of the activity items from agent! ActivityItem GUID Str: {lActivityReturnItemKeyStr}; Return value: {lActivityReturnItemValue}") def SettingsUpdate(inGlobalConfiguration): import os diff --git a/Sources/pyOpenRPA/Orchestrator/SettingsTemplate.py b/Sources/pyOpenRPA/Orchestrator/SettingsTemplate.py index 224b383a..fa08048d 100644 --- a/Sources/pyOpenRPA/Orchestrator/SettingsTemplate.py +++ b/Sources/pyOpenRPA/Orchestrator/SettingsTemplate.py @@ -7,6 +7,7 @@ def __Create__(): "Autocleaner": { # Some gurbage is collecting in g settings. So you can configure autocleaner to periodically clear gSettings "IntervalSecFloat": 3600.0, # Sec float to periodically clear gsettings + "AgentActivityReturnLifetimeSecFloat": 300.0 # Time in seconds to life for activity result recieved from the agent }, "Client": { # Settings about client web orchestrator "Session": { @@ -266,12 +267,21 @@ def __Create__(): }, "AgentDict": { # Will be filled when program runs #("HostNameUpperStr", "UserUpperStr"): { "IsListenBool": True, "QueueList": [] } + }, + "AgentActivityReturnDict": { # Will be filled when programs run - fill result of the Activity execution on the agent + # Key - Activity Item GUID str, Value {"Return": ..., "ReturnedByDatetime": datetime.datetime} + # If key exists - def has been completed } } # Create full configuration for def __AgentDictItemCreate__(): return {"IsListenBool":False, "ConnectionCountInt":0, "ConnectionFirstQueueItemCountInt":0, "ActivityList":[]} + +# Create full configuration for AgentActivityReturnDict +def __AgentActivityReturnDictItemCreate__(inReturn): + return {"Return": inReturn, "ReturnedByDatetime": datetime.datetime.now()} + # Create full configuration for def __UACClientAdminCreate__(): lResultDict = { diff --git a/Sources/pyOpenRPA/Orchestrator/__Orchestrator__.py b/Sources/pyOpenRPA/Orchestrator/__Orchestrator__.py index 5383fe52..4505684e 100644 --- a/Sources/pyOpenRPA/Orchestrator/__Orchestrator__.py +++ b/Sources/pyOpenRPA/Orchestrator/__Orchestrator__.py @@ -35,13 +35,15 @@ def AgentActivityItemAdd(inGSettings, inHostNameStr, inUserStr, inActivityItemDi :param inHostNameStr: Agent host name :param inUserStr: User login, where agent is based :param inActivityItemDict: ActivityItem - :return: None + :return: GUID String of the ActivityItem - you can wait (sync or async) result by this guid! """ lActivityItemDict = copy.deepcopy(inActivityItemDict) # Add GUIDStr if not exist + lGUIDStr = None if "GUIDStr" not in lActivityItemDict: lGUIDStr = str(uuid.uuid4()) # generate new GUID lActivityItemDict["GUIDStr"] = lGUIDStr + else: lGUIDStr = lActivityItemDict["GUIDStr"] # Add CreatedByDatetime lActivityItemDict["CreatedByDatetime"] = datetime.datetime.now() # Main alg @@ -50,7 +52,35 @@ def AgentActivityItemAdd(inGSettings, inHostNameStr, inUserStr, inActivityItemDi inGSettings["AgentDict"][lAgentDictItemKeyTurple] = SettingsTemplate.__AgentDictItemCreate__() lThisAgentDict = inGSettings["AgentDict"][lAgentDictItemKeyTurple] lThisAgentDict["ActivityList"].append(lActivityItemDict) + # Return the result + return lGUIDStr +def AgentActivityItemReturnExists(inGSettings, inGUIDStr): + """ + Check by GUID if ActivityItem has been executed and result has come to the Orchestrator + + :param inGSettings: Global settings dict (singleton) + :param inGUIDStr: GUID String of the ActivityItem - you can wait (sync or async) result by this guid! + :return: True - result has been received from the Agent to orc; False - else case + """ + # Check if GUID is exists in dict - has been recieved + return inGUIDStr in inGSettings["AgentActivityReturnDict"] + + +def AgentActivityItemReturnGet(inGSettings, inGUIDStr, inCheckIntervalSecFloat = 0.5): + """ + Work synchroniously! Wait while result will be recieved. Get the result of the ActivityItem execution on the Agent side. Before this please check by the def AgentActivityItemReturnExists that result has come to the Orchestrator + + :param inGSettings: Global settings dict (singleton) + :param inGUIDStr: GUID String of the ActivityItem - you can wait (sync or async) result by this guid! + :param inCheckIntervalSecFloat: Interval in sec of the check Activity Item result + :return: Result of the ActivityItem executed on the Agent side anr transmitted to the Orchestrator. IMPORTANT! ONLY JSON ENABLED Types CAN BE TRANSMITTED TO ORCHESTRATOR! + """ + # Wait while result will not come here + while not AgentActivityItemReturnExists(inGSettings=inGSettings, inGUIDStr=inGUIDStr): + time.sleep(inCheckIntervalSecFloat) + # Return the result + return inGSettings["AgentActivityReturnDict"][inGUIDStr] def AgentOSCMD(inGSettings, inHostNameStr, inUserStr, inCMDStr, inRunAsyncBool=True, inSendOutputToOrchestratorLogsBool=True, inCMDEncodingStr="cp1251"): """ @@ -63,7 +93,7 @@ def AgentOSCMD(inGSettings, inHostNameStr, inUserStr, inCMDStr, inRunAsyncBool=T :param inRunAsyncBool: True - Agent processor don't wait execution; False - Agent processor wait cmd execution :param inSendOutputToOrchestratorLogsBool: True - catch cmd execution output and send it to the Orchestrator logs; Flase - else case; Default True :param inCMDEncodingStr: Set the encoding of the DOS window on the Agent server session. Windows is beautiful :) . Default is "cp1251" early was "cp866" - need test - + :return: GUID String of the ActivityItem - you can wait (sync or async) result by this guid! """ lActivityItemDict = { @@ -74,7 +104,7 @@ def AgentOSCMD(inGSettings, inHostNameStr, inUserStr, inCMDStr, inRunAsyncBool=T "ArgLogger": None # Name of GSettings attribute: str (ArgDict) or index (for ArgList) } #Send item in AgentDict for the futher data transmition - AgentActivityItemAdd(inGSettings=inGSettings, inHostNameStr=inHostNameStr, inUserStr=inUserStr, inActivityItemDict=lActivityItemDict) + return AgentActivityItemAdd(inGSettings=inGSettings, inHostNameStr=inHostNameStr, inUserStr=inUserStr, inActivityItemDict=lActivityItemDict) def AgentOSFileBinaryDataBytesCreate(inGSettings, inHostNameStr, inUserStr, inFilePathStr, inFileDataBytes): """ @@ -85,6 +115,7 @@ def AgentOSFileBinaryDataBytesCreate(inGSettings, inHostNameStr, inUserStr, inFi :param inUserStr: :param inFilePathStr: :param inFileDataBytes: + :return: GUID String of the ActivityItem - you can wait (sync or async) result by this guid! """ lFileDataBase64Str = base64.b64encode(inFileDataBytes).decode("utf-8") @@ -96,7 +127,7 @@ def AgentOSFileBinaryDataBytesCreate(inGSettings, inHostNameStr, inUserStr, inFi "ArgLogger": None # Name of GSettings attribute: str (ArgDict) or index (for ArgList) } #Send item in AgentDict for the futher data transmition - AgentActivityItemAdd(inGSettings=inGSettings, inHostNameStr=inHostNameStr, inUserStr=inUserStr, inActivityItemDict=lActivityItemDict) + return AgentActivityItemAdd(inGSettings=inGSettings, inHostNameStr=inHostNameStr, inUserStr=inUserStr, inActivityItemDict=lActivityItemDict) def AgentOSFileBinaryDataBase64StrCreate(inGSettings, inHostNameStr, inUserStr, inFilePathStr, inFileDataBase64Str): @@ -108,6 +139,7 @@ def AgentOSFileBinaryDataBase64StrCreate(inGSettings, inHostNameStr, inUserStr, :param inUserStr: :param inFilePathStr: :param inFileDataBase64Str: + :return: GUID String of the ActivityItem - you can wait (sync or async) result by this guid! """ lActivityItemDict = { @@ -118,7 +150,7 @@ def AgentOSFileBinaryDataBase64StrCreate(inGSettings, inHostNameStr, inUserStr, "ArgLogger": None # Name of GSettings attribute: str (ArgDict) or index (for ArgList) } #Send item in AgentDict for the futher data transmition - AgentActivityItemAdd(inGSettings=inGSettings, inHostNameStr=inHostNameStr, inUserStr=inUserStr, inActivityItemDict=lActivityItemDict) + return AgentActivityItemAdd(inGSettings=inGSettings, inHostNameStr=inHostNameStr, inUserStr=inUserStr, inActivityItemDict=lActivityItemDict) # Send text file to Agent (string) def AgentOSFileTextDataStrCreate(inGSettings, inHostNameStr, inUserStr, inFilePathStr, inFileDataStr, inEncodingStr = "utf-8"): @@ -131,6 +163,7 @@ def AgentOSFileTextDataStrCreate(inGSettings, inHostNameStr, inUserStr, inFilePa :param inFilePathStr: :param inFileDataStr: :param inEncodingStr: + :return: GUID String of the ActivityItem - you can wait (sync or async) result by this guid! """ lActivityItemDict = { @@ -141,7 +174,7 @@ def AgentOSFileTextDataStrCreate(inGSettings, inHostNameStr, inUserStr, inFilePa "ArgLogger": None # Name of GSettings attribute: str (ArgDict) or index (for ArgList) } #Send item in AgentDict for the futher data transmition - AgentActivityItemAdd(inGSettings=inGSettings, inHostNameStr=inHostNameStr, inUserStr=inUserStr, inActivityItemDict=lActivityItemDict) + return AgentActivityItemAdd(inGSettings=inGSettings, inHostNameStr=inHostNameStr, inUserStr=inUserStr, inActivityItemDict=lActivityItemDict) # OS DEFS def OSCredentialsVerify(inUserStr, inPasswordStr, inDomainStr=""): ## @@ -1614,6 +1647,15 @@ def GSettingsAutocleaner(inGSettings): else: if lL: lL.debug(f"Client > Session > TechnicalSessionGUIDCache > lItemKeyStr: Lifetime is expired. Remove from gSettings") # Info inGSettings["Client"]["Session"]["TechnicalSessionGUIDCache"] = lTechnicalSessionGUIDCacheNew # Set updated Cache + # Clean old items in AgentActivityReturnDict > GUIDStr > ReturnedByDatetime + lTechnicalAgentActivityReturnDictNew = {} + for lItemKeyStr in inGSettings["AgentActivityReturnDict"]: + lItemValue = inGSettings["AgentActivityReturnDict"][lItemKeyStr] + if (lNowDatetime - lItemValue["ReturnedByDatetime"]).total_seconds() < inGSettings["Autocleaner"]["AgentActivityReturnLifetimeSecFloat"]: # Add if lifetime is ok + lTechnicalAgentActivityReturnDictNew[lItemKeyStr]=lItemValue # Lifetime is ok - set + else: + if lL: lL.debug(f"AgentActivityReturnDict lItemKeyStr: Lifetime is expired. Remove from gSettings") # Info + inGSettings["AgentActivityReturnDict"] = lTechnicalAgentActivityReturnDictNew # Set updated Cache # # # # # # # # # # # # # # # # # # # # # # # # # # from .. import __version__ # Get version from the package diff --git a/Wiki/ENG_Guide/html/Orchestrator/02_Defs.html b/Wiki/ENG_Guide/html/Orchestrator/02_Defs.html index 92b818ae..f8486dcf 100644 --- a/Wiki/ENG_Guide/html/Orchestrator/02_Defs.html +++ b/Wiki/ENG_Guide/html/Orchestrator/02_Defs.html @@ -256,6 +256,12 @@

AgentActivityItemAdd(inGSettings, …)

Add activity in AgentDict.

+

AgentActivityItemReturnExists(inGSettings, …)

+

Check by GUID if ActivityItem has been executed and result has come to the Orchestrator

+ +

AgentActivityItemReturnGet(inGSettings, …)

+

Work synchroniously! Wait while result will be recieved.

+

AgentOSCMD(inGSettings, inHostNameStr, …)

Send CMD to OS thought the pyOpenRPA.Agent daemon.

@@ -410,7 +416,42 @@
Returns
-

None

+

GUID String of the ActivityItem - you can wait (sync or async) result by this guid!

+
+ + + +
+
+pyOpenRPA.Orchestrator.__Orchestrator__.AgentActivityItemReturnExists(inGSettings, inGUIDStr)[source]
+

Check by GUID if ActivityItem has been executed and result has come to the Orchestrator

+
+
Parameters
+
    +
  • inGSettings – Global settings dict (singleton)

  • +
  • inGUIDStr – GUID String of the ActivityItem - you can wait (sync or async) result by this guid!

  • +
+
+
Returns
+

True - result has been received from the Agent to orc; False - else case

+
+
+
+ +
+
+pyOpenRPA.Orchestrator.__Orchestrator__.AgentActivityItemReturnGet(inGSettings, inGUIDStr, inCheckIntervalSecFloat=0.5)[source]
+

Work synchroniously! Wait while result will be recieved. Get the result of the ActivityItem execution on the Agent side. Before this please check by the def AgentActivityItemReturnExists that result has come to the Orchestrator

+
+
Parameters
+
    +
  • inGSettings – Global settings dict (singleton)

  • +
  • inGUIDStr – GUID String of the ActivityItem - you can wait (sync or async) result by this guid!

  • +
  • inCheckIntervalSecFloat – Interval in sec of the check Activity Item result

  • +
+
+
Returns
+

Result of the ActivityItem executed on the Agent side anr transmitted to the Orchestrator. IMPORTANT! ONLY JSON ENABLED Types CAN BE TRANSMITTED TO ORCHESTRATOR!

@@ -431,6 +472,9 @@
  • inCMDEncodingStr – Set the encoding of the DOS window on the Agent server session. Windows is beautiful :) . Default is “cp1251” early was “cp866” - need test

  • +
    Returns
    +

    GUID String of the ActivityItem - you can wait (sync or async) result by this guid!

    +
    @@ -448,6 +492,9 @@
  • inFileDataBase64Str

  • +
    Returns
    +

    GUID String of the ActivityItem - you can wait (sync or async) result by this guid!

    +
    @@ -465,6 +512,9 @@
  • inFileDataBytes

  • +
    Returns
    +

    GUID String of the ActivityItem - you can wait (sync or async) result by this guid!

    +
    @@ -483,6 +533,9 @@
  • inEncodingStr

  • +
    Returns
    +

    GUID String of the ActivityItem - you can wait (sync or async) result by this guid!

    +
    diff --git a/Wiki/ENG_Guide/html/Orchestrator/03_gSettingsTemplate.html b/Wiki/ENG_Guide/html/Orchestrator/03_gSettingsTemplate.html index 1c11aa2c..7b929720 100644 --- a/Wiki/ENG_Guide/html/Orchestrator/03_gSettingsTemplate.html +++ b/Wiki/ENG_Guide/html/Orchestrator/03_gSettingsTemplate.html @@ -190,6 +190,7 @@ "Autocleaner": { # Some gurbage is collecting in g settings. So you can configure autocleaner to periodically clear gSettings "IntervalSecFloat": 3600.0, # Sec float to periodically clear gsettings + "AgentActivityReturnLifetimeSecFloat": 300.0 # Time in seconds to life for activity result recieved from the agent }, "Client": { # Settings about client web orchestrator "Session": { @@ -449,12 +450,21 @@ }, "AgentDict": { # Will be filled when program runs #("HostNameUpperStr", "UserUpperStr"): { "IsListenBool": True, "QueueList": [] } + }, + "AgentActivityReturnDict": { # Will be filled when programs run - fill result of the Activity execution on the agent + # Key - Activity Item GUID str, Value {"Return": ..., "ReturnedByDatetime": datetime.datetime} + # If key exists - def has been completed } } # Create full configuration for def __AgentDictItemCreate__(): return {"IsListenBool":False, "ConnectionCountInt":0, "ConnectionFirstQueueItemCountInt":0, "ActivityList":[]} + +# Create full configuration for AgentActivityReturnDict +def __AgentActivityReturnDictItemCreate__(inReturn): + return {"Return": inReturn, "ReturnedByDatetime": datetime.datetime.now()} + # Create full configuration for def __UACClientAdminCreate__(): lResultDict = { diff --git a/Wiki/ENG_Guide/html/_modules/pyOpenRPA/Orchestrator/__Orchestrator__.html b/Wiki/ENG_Guide/html/_modules/pyOpenRPA/Orchestrator/__Orchestrator__.html index 1601c265..7cb60d63 100644 --- a/Wiki/ENG_Guide/html/_modules/pyOpenRPA/Orchestrator/__Orchestrator__.html +++ b/Wiki/ENG_Guide/html/_modules/pyOpenRPA/Orchestrator/__Orchestrator__.html @@ -212,13 +212,15 @@ :param inHostNameStr: Agent host name :param inUserStr: User login, where agent is based :param inActivityItemDict: ActivityItem - :return: None + :return: GUID String of the ActivityItem - you can wait (sync or async) result by this guid! """ lActivityItemDict = copy.deepcopy(inActivityItemDict) # Add GUIDStr if not exist + lGUIDStr = None if "GUIDStr" not in lActivityItemDict: lGUIDStr = str(uuid.uuid4()) # generate new GUID lActivityItemDict["GUIDStr"] = lGUIDStr + else: lGUIDStr = lActivityItemDict["GUIDStr"] # Add CreatedByDatetime lActivityItemDict["CreatedByDatetime"] = datetime.datetime.now() # Main alg @@ -226,8 +228,36 @@ if lAgentDictItemKeyTurple not in inGSettings["AgentDict"]: inGSettings["AgentDict"][lAgentDictItemKeyTurple] = SettingsTemplate.__AgentDictItemCreate__() lThisAgentDict = inGSettings["AgentDict"][lAgentDictItemKeyTurple] - lThisAgentDict["ActivityList"].append(lActivityItemDict) + lThisAgentDict["ActivityList"].append(lActivityItemDict) + # Return the result + return lGUIDStr +
    [docs]def AgentActivityItemReturnExists(inGSettings, inGUIDStr): + """ + Check by GUID if ActivityItem has been executed and result has come to the Orchestrator + + :param inGSettings: Global settings dict (singleton) + :param inGUIDStr: GUID String of the ActivityItem - you can wait (sync or async) result by this guid! + :return: True - result has been received from the Agent to orc; False - else case + """ + # Check if GUID is exists in dict - has been recieved + return inGUIDStr in inGSettings["AgentActivityReturnDict"]
    + + +
    [docs]def AgentActivityItemReturnGet(inGSettings, inGUIDStr, inCheckIntervalSecFloat = 0.5): + """ + Work synchroniously! Wait while result will be recieved. Get the result of the ActivityItem execution on the Agent side. Before this please check by the def AgentActivityItemReturnExists that result has come to the Orchestrator + + :param inGSettings: Global settings dict (singleton) + :param inGUIDStr: GUID String of the ActivityItem - you can wait (sync or async) result by this guid! + :param inCheckIntervalSecFloat: Interval in sec of the check Activity Item result + :return: Result of the ActivityItem executed on the Agent side anr transmitted to the Orchestrator. IMPORTANT! ONLY JSON ENABLED Types CAN BE TRANSMITTED TO ORCHESTRATOR! + """ + # Wait while result will not come here + while not AgentActivityItemReturnExists(inGSettings=inGSettings, inGUIDStr=inGUIDStr): + time.sleep(inCheckIntervalSecFloat) + # Return the result + return inGSettings["AgentActivityReturnDict"][inGUIDStr]
    [docs]def AgentOSCMD(inGSettings, inHostNameStr, inUserStr, inCMDStr, inRunAsyncBool=True, inSendOutputToOrchestratorLogsBool=True, inCMDEncodingStr="cp1251"): """ @@ -240,7 +270,7 @@ :param inRunAsyncBool: True - Agent processor don't wait execution; False - Agent processor wait cmd execution :param inSendOutputToOrchestratorLogsBool: True - catch cmd execution output and send it to the Orchestrator logs; Flase - else case; Default True :param inCMDEncodingStr: Set the encoding of the DOS window on the Agent server session. Windows is beautiful :) . Default is "cp1251" early was "cp866" - need test - + :return: GUID String of the ActivityItem - you can wait (sync or async) result by this guid! """ lActivityItemDict = { @@ -251,7 +281,7 @@ "ArgLogger": None # Name of GSettings attribute: str (ArgDict) or index (for ArgList) } #Send item in AgentDict for the futher data transmition - AgentActivityItemAdd(inGSettings=inGSettings, inHostNameStr=inHostNameStr, inUserStr=inUserStr, inActivityItemDict=lActivityItemDict)
    + return AgentActivityItemAdd(inGSettings=inGSettings, inHostNameStr=inHostNameStr, inUserStr=inUserStr, inActivityItemDict=lActivityItemDict)
    [docs]def AgentOSFileBinaryDataBytesCreate(inGSettings, inHostNameStr, inUserStr, inFilePathStr, inFileDataBytes): """ @@ -262,6 +292,7 @@ :param inUserStr: :param inFilePathStr: :param inFileDataBytes: + :return: GUID String of the ActivityItem - you can wait (sync or async) result by this guid! """ lFileDataBase64Str = base64.b64encode(inFileDataBytes).decode("utf-8") @@ -273,7 +304,7 @@ "ArgLogger": None # Name of GSettings attribute: str (ArgDict) or index (for ArgList) } #Send item in AgentDict for the futher data transmition - AgentActivityItemAdd(inGSettings=inGSettings, inHostNameStr=inHostNameStr, inUserStr=inUserStr, inActivityItemDict=lActivityItemDict)
    + return AgentActivityItemAdd(inGSettings=inGSettings, inHostNameStr=inHostNameStr, inUserStr=inUserStr, inActivityItemDict=lActivityItemDict)
    [docs]def AgentOSFileBinaryDataBase64StrCreate(inGSettings, inHostNameStr, inUserStr, inFilePathStr, inFileDataBase64Str): @@ -285,6 +316,7 @@ :param inUserStr: :param inFilePathStr: :param inFileDataBase64Str: + :return: GUID String of the ActivityItem - you can wait (sync or async) result by this guid! """ lActivityItemDict = { @@ -295,7 +327,7 @@ "ArgLogger": None # Name of GSettings attribute: str (ArgDict) or index (for ArgList) } #Send item in AgentDict for the futher data transmition - AgentActivityItemAdd(inGSettings=inGSettings, inHostNameStr=inHostNameStr, inUserStr=inUserStr, inActivityItemDict=lActivityItemDict)
    + return AgentActivityItemAdd(inGSettings=inGSettings, inHostNameStr=inHostNameStr, inUserStr=inUserStr, inActivityItemDict=lActivityItemDict) # Send text file to Agent (string)
    [docs]def AgentOSFileTextDataStrCreate(inGSettings, inHostNameStr, inUserStr, inFilePathStr, inFileDataStr, inEncodingStr = "utf-8"): @@ -308,6 +340,7 @@ :param inFilePathStr: :param inFileDataStr: :param inEncodingStr: + :return: GUID String of the ActivityItem - you can wait (sync or async) result by this guid! """ lActivityItemDict = { @@ -318,7 +351,7 @@ "ArgLogger": None # Name of GSettings attribute: str (ArgDict) or index (for ArgList) } #Send item in AgentDict for the futher data transmition - AgentActivityItemAdd(inGSettings=inGSettings, inHostNameStr=inHostNameStr, inUserStr=inUserStr, inActivityItemDict=lActivityItemDict)
    + return AgentActivityItemAdd(inGSettings=inGSettings, inHostNameStr=inHostNameStr, inUserStr=inUserStr, inActivityItemDict=lActivityItemDict) # OS DEFS
    [docs]def OSCredentialsVerify(inUserStr, inPasswordStr, inDomainStr=""): ## @@ -1790,7 +1823,16 @@ lTechnicalSessionGUIDCacheNew[lItemKeyStr]=lItemValue # Lifetime is ok - set else: if lL: lL.debug(f"Client > Session > TechnicalSessionGUIDCache > lItemKeyStr: Lifetime is expired. Remove from gSettings") # Info - inGSettings["Client"]["Session"]["TechnicalSessionGUIDCache"] = lTechnicalSessionGUIDCacheNew # Set updated Cache
    + inGSettings["Client"]["Session"]["TechnicalSessionGUIDCache"] = lTechnicalSessionGUIDCacheNew # Set updated Cache + # Clean old items in AgentActivityReturnDict > GUIDStr > ReturnedByDatetime + lTechnicalAgentActivityReturnDictNew = {} + for lItemKeyStr in inGSettings["AgentActivityReturnDict"]: + lItemValue = inGSettings["AgentActivityReturnDict"][lItemKeyStr] + if (lNowDatetime - lItemValue["ReturnedByDatetime"]).total_seconds() < inGSettings["Autocleaner"]["AgentActivityReturnLifetimeSecFloat"]: # Add if lifetime is ok + lTechnicalAgentActivityReturnDictNew[lItemKeyStr]=lItemValue # Lifetime is ok - set + else: + if lL: lL.debug(f"AgentActivityReturnDict lItemKeyStr: Lifetime is expired. Remove from gSettings") # Info + inGSettings["AgentActivityReturnDict"] = lTechnicalAgentActivityReturnDictNew # Set updated Cache # # # # # # # # # # # # # # # # # # # # # # # # # # from .. import __version__ # Get version from the package diff --git a/Wiki/ENG_Guide/html/genindex.html b/Wiki/ENG_Guide/html/genindex.html index 7af9a565..b898b740 100644 --- a/Wiki/ENG_Guide/html/genindex.html +++ b/Wiki/ENG_Guide/html/genindex.html @@ -194,10 +194,14 @@