- Create Agent support in Orchestrator (/pyOpenRPA/Agent/O2A and /pyOpenRPA/Agent/A2O) Just writed prototype - start to testdev-linux
parent
caeae7c997
commit
7a6e961aa8
@ -0,0 +1,4 @@
|
||||
cd %~dp0
|
||||
copy /Y ..\Resources\WPy64-3720\python-3.7.2.amd64\python.exe ..\Resources\WPy64-3720\python-3.7.2.amd64\pyOpenRPA_Agent.exe
|
||||
.\..\Resources\WPy64-3720\python-3.7.2.amd64\pyOpenRPA_Agent.exe "AgentSettings.py"
|
||||
pause >nul
|
@ -0,0 +1,55 @@
|
||||
import psutil, datetime, logging, os, sys # stdout from logging
|
||||
|
||||
# Config settings
|
||||
lPyOpenRPASourceFolderPathStr = r"..\Sources" # Path for test pyOpenRPA package
|
||||
|
||||
# Operations
|
||||
if lPyOpenRPASourceFolderPathStr != "": sys.path.insert(0,os.path.abspath(os.path.join(lPyOpenRPASourceFolderPathStr))) # Path for test pyOpenRPA package
|
||||
|
||||
from pyOpenRPA.Agent import Agent
|
||||
|
||||
if __name__ == "__main__": # New init way
|
||||
gSettings = {
|
||||
"OrchestratorDict":{
|
||||
"IsHTTPSBool": False, # True - if server is secured HTTPS, False - if server is not secured HTTP
|
||||
"HostStr":"127.0.0.1",
|
||||
"PortInt":80,
|
||||
"SuperTokenStr":"", # Access token to Orchestrator
|
||||
},
|
||||
"O2ADict":{
|
||||
"IsOnlineBool": True, # Parameter can be changed when program executes
|
||||
"RetryTimeoutSecFloat": 10.0, # Retry interval if some error when connect
|
||||
|
||||
},
|
||||
"A2ODict": {
|
||||
"RetryTimeoutSecFloat": 10.0, # Retry interval if some error when connect
|
||||
},
|
||||
"Logger":logging.getLogger("Agent"),
|
||||
"AgentDict": { # Will be filled automatically
|
||||
"HostNameUpperStr":None, # Machine hostname
|
||||
"UserUpperStr": None, # Username string
|
||||
}
|
||||
}
|
||||
|
||||
if not os.path.exists("Reports"):
|
||||
os.makedirs("Reports")
|
||||
##########################
|
||||
# Подготовка логгера Robot
|
||||
#########################
|
||||
lL = gSettings["Logger"]
|
||||
lL.setLevel(logging.DEBUG)
|
||||
# create the logging file handler
|
||||
mRobotLoggerFH = logging.FileHandler(
|
||||
"Reports\\" + datetime.datetime.now().strftime("%Y_%m_%d") + ".log")
|
||||
mRobotLoggerFormatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
|
||||
mRobotLoggerFH.setFormatter(mRobotLoggerFormatter)
|
||||
# add handler to logger object
|
||||
lL.addHandler(mRobotLoggerFH)
|
||||
####################Add console output
|
||||
handler = logging.StreamHandler(sys.stdout)
|
||||
handler.setFormatter(mRobotLoggerFormatter)
|
||||
lL.addHandler(handler)
|
||||
############################################
|
||||
# Call the orchestrator def
|
||||
Agent.Agent(inGSettings=gSettings)
|
||||
|
@ -0,0 +1,28 @@
|
||||
import requests, time
|
||||
# A2O - Data flow Agent to Orchestrator
|
||||
|
||||
# f"{lProtocolStr}://{lHostStr}:{lPortInt}/pyOpenRPA/Agent/A2O"
|
||||
# Request BODY:
|
||||
# { "HostNameUpperStr": "", "UserUpperStr": "", "LogList":[]}
|
||||
# Response BODY:
|
||||
# {}
|
||||
|
||||
# Send logs to orchestrator
|
||||
def _A2ODataSend(inGSettings, inDataDict):
|
||||
lL = inGSettings["Logger"]
|
||||
while inGSettings["A2O"]["IsOnlineBool"]:
|
||||
# Send request to the orchestrator server
|
||||
try:
|
||||
lProtocolStr= "https" if inGSettings["OrchestratorDict"]["IsHTTPSBool"] else "http"
|
||||
lHostStr = inGSettings["OrchestratorDict"]["HostStr"]
|
||||
lPortInt = inGSettings["OrchestratorDict"]["PortInt"]
|
||||
lURLStr=f"{lProtocolStr}://{lHostStr}:{lPortInt}/pyOpenRPA/Agent/A2O"
|
||||
lResponse = requests.post(url= lURLStr, cookies = {"AuthToken":inGSettings["OrchestratorDict"]["SuperTokenStr"]}, data=inDataDict)
|
||||
except Exception as e:
|
||||
if lL: lL.exception(f"A2O Error handler. Sleep for {inGSettings['A2O']['RetryTimeoutSecFloat']} s.")
|
||||
time.sleep(inGSettings["A2O"]["RetryTimeoutSecFloat"])
|
||||
|
||||
# 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)
|
@ -0,0 +1,15 @@
|
||||
import threading, socket, getpass
|
||||
from . import O2A, A2O # Data flow Orchestrator To Agent
|
||||
|
||||
# Main def
|
||||
def Agent(inGSettings):
|
||||
# Detect Machine host name and username
|
||||
inGSettings["AgentDict"]["HostNameUpperStr"] = socket.gethostname().upper()
|
||||
inGSettings["AgentDict"]["UserUpperStr"] = getpass.getuser().upper()
|
||||
|
||||
# Start thread to wait data from Orchestrator (O2A)
|
||||
lO2AThread = threading.Thread(target=O2A.O2A_Loop, kwargs={"inGSettings":inGSettings})
|
||||
lO2AThread.start()
|
||||
|
||||
# Send log that Agent has been started
|
||||
A2O.LogListSend(inGSettings=inGSettings, inLogList=[f'Host: {inGSettings["AgentDict"]["HostNameUpperStr"]}, User: {inGSettings["AgentDict"]["UserUpperStr"]}, Agent has been started.'])
|
@ -0,0 +1,22 @@
|
||||
import requests, time
|
||||
# O2A - Data flow Orchestrator to Agent
|
||||
|
||||
# f"{lProtocolStr}://{lHostStr}:{lPortInt}/pyOpenRPA/Agent/O2A"
|
||||
# Request BODY:
|
||||
# { "HostNameUpperStr": "", "UserUpperStr": "" }
|
||||
# Response BODY:
|
||||
# {}
|
||||
|
||||
def O2A_Loop(inGSettings):
|
||||
lL = inGSettings["Logger"]
|
||||
while inGSettings["O2A"]["IsOnlineBool"]:
|
||||
# Send request to the orchestrator server
|
||||
try:
|
||||
lProtocolStr= "https" if inGSettings["OrchestratorDict"]["IsHTTPSBool"] else "http"
|
||||
lHostStr = inGSettings["OrchestratorDict"]["HostStr"]
|
||||
lPortInt = inGSettings["OrchestratorDict"]["PortInt"]
|
||||
lURLStr=f"{lProtocolStr}://{lHostStr}:{lPortInt}/pyOpenRPA/Agent/O2A"
|
||||
lDataDict = { "HostNameUpperStr": inGSettings["AgentDict"]["HostNameUpperStr"], "UserUpperStr": inGSettings["AgentDict"]["UserUpperStr"]}
|
||||
lResponse = requests.post(url= lURLStr, cookies = {"AuthToken":inGSettings["OrchestratorDict"]["SuperTokenStr"]}, data=lDataDict)
|
||||
except Exception as e:
|
||||
time.sleep(inGSettings["O2A"]["RetryTimeoutSecFloat"])
|
Loading…
Reference in new issue