Skip to main content

UOFast is a U2 UOPY based restful service which pools U2 UOPY connections and accepts GET/PUT type requests

Project description

Installation

UOFast is a U2 UOPY based restful service which pools U2 UOPY connections and accepts GET/PUT type requests to U2 databases. Its based on FastAPI, gsocketpool, pydantic and uopy. This is an opensource sample, to demonstrate the capabilities of UOPY connectivity using a restful service. #U2 #uopy #sample #python #Unidata #example.

Check Python installation - Since uofast is based on python, it need python version 3.9.1 and above to function.

  1. How to check python version ?

> Python -V

If the version installed on the machine is > 3.9.1, then skip to step 3. Tip : If you have an Older version of Python already installed, please remove that from the PATH in your environment and leave the new one in.

  1. How to install python?

Please download python 3.9.1 from the below site.

https://www.python.org/downloads/release/python-391/

  1. Install required packages

The below step will install all the required "include" packages for uofast.

>pip install -r requirements.txt

Setup

UOFast.cfg - Edit required configuration settings for uofast.

Edit uofast.cfg in the uofast installation directory. Some of the setting have been marked with <Do not change> - which means these are recommended and tested, so there is no need to change.

[UOConnectionSettings]

UOhost = <Server name or IP Address\>
UOaccount = <Account path e.g. C:\U2\UD82\DEMO\>
UOservice = <udcs for Unidata\>
UOport = <UniRPC port in UniObjects e.g. 31438\>
UOuser = <Unidata user id \>
UOpassword = <Unidata password\>

[ApplicationSettings]

Mainlogname=UOFastMainAPI.log <Main application Log file name\>
UOConnectionLogs=UOConnectionProcesses.log <Log file pertinent to each UOPY connection\>

[PoolSettings]
Initial\_connections : 2 <Number of minimum connection to establish in Uniobjects/uopy\>
max\_connections : 2 <Number of MAX connection to establish in Uniobjects/uopy\>
session\_timeout : 600 <Do not change\>
reap\_interval : 180 <Do not change\>

Runtime

Startup of UOFast in included in a .bat file – uofaststart.bat. The primary command used to startup UOFast is :

python -m uvicorn main:app --port 8200

Tip : The port number can be manipulated, to select a port of your choice.

After invoking >uofaststart.bat, the output should look similar to below :

Tip : Please check uofastlogs directory to check for UOPY connection status. If you are not able to connect to the target U2 database, there might be some configuration issues in uofast.cfg.

Usage

Testing UOFast service

As per the above screenshot example, your UOFast service has been invoked at http://127.0.0.1:8200. Since UOFast uses FastAPI, it has an in-built "Swagger" interface for testing purposes. You can invoke the swagger documentation of the API by invoking the Url http://127.0.0.1:8200/docs for your UOFast installation.

Sample requests

Requests to UOFast, can be made using any platform supporting restful requests e.g. .NET, Java or Python.

The below example is based on python "requests" model. The assumption is that,

  1. a basic program is compiled & cataloged in the DEMO account of U2 Unidata.
  2. The UOFast connections point to the sample Unidata DEMO account

A Sample program has been included in the UOFast install directory – (Example = TEST.SUB)

Tip – The standard UOFast API uses 3 parameters within BASIC programs to pass data to the U2 database and return as output. Ie. SUBROUTINE SUBNAME(INPUTDATA, OUTPUTDATA, ERRORDATA). NOTE: Additional parameters are not supported.

A Tkinter based GUI program has been included in the root directory to invoke the above program. This will give you an example to invoke restful services and consume them in GUI/Web programs. (Example = uofast_tk_sample.py)

Additional Tip : A Successful connection will return 200, the standard OK status code. An error will return 418, with the error returned from the basic program.

Examples :

BASIC CODE : (Should be compiled and cataloged on the server, in the install account)

SUBROUTINE TEST.SUB(INPUTDATA, OUTPUTDATA, ERRORDATA)

\* Sample subroutine to get information from INPUTDATA and send output
\* using OUTPUTDATA using **UOFast**
\*
\*****************************************************************************

OUTPUTDATA = ""; ERRORDATA = ""
OPEN 'CUSTOMER' TO CUSTOMER ELSE ERRORDATA = "NO CUSTOMER OPEN";RETURN
CUST.ID = INPUTDATA\<1\>
READ CUST.REC FROM CUSTOMER, CUST.ID ELSE ERRORDATA\<1\> = CUST.ID:" NOT FOUND..."
OUTPUTDATA = CUST.REC
RETURN

PYTHON CODE (to invoke the above program)

rec = UOFastDataArray.mrecord()
rec[0] = "10"

#Create the request Object
mObject = UOFastDataArray.multi_svr_object(ProcessName="TEST.SUB", ProcessParams=rec)

#Post the Request object to UOFast URL
x = requests.post(api_url, data = mObject.json(indent=2))

if x.status_code != 200:
	rettext = "**error returned = ",x.status_code, json.loads(x.text).get("detail")
else:
	#200 is successful response
	uo_obj = json.loads(x.text)
	print(str(uo_obj))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uofast-0.1.25.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

uofast-0.1.25-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

Details for the file uofast-0.1.25.tar.gz.

File metadata

  • Download URL: uofast-0.1.25.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for uofast-0.1.25.tar.gz
Algorithm Hash digest
SHA256 6e27ec0e67c95f3ed934f51cacb3b84539000b4d2845f4790225f62aa719a4e1
MD5 125958640e2e68e1ba23c8de5dd9229f
BLAKE2b-256 9aeaf120757af15b36a06e08d8f22c5d66241675e90173ed7e522ab2d56d78b0

See more details on using hashes here.

File details

Details for the file uofast-0.1.25-py3-none-any.whl.

File metadata

  • Download URL: uofast-0.1.25-py3-none-any.whl
  • Upload date:
  • Size: 17.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for uofast-0.1.25-py3-none-any.whl
Algorithm Hash digest
SHA256 77f3469282ff8e70fc9178daa6c2f61b530e3423be11f2bc62b8094343f5e334
MD5 307b2c758e4c19e3d90a7959fb16bc2e
BLAKE2b-256 41ab7c6ee1d3720ff48d32bf8f19e89daca94b92642a8ddeb55ad00e2e9f8c71

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page