-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwork_unit_hello_world.py
51 lines (46 loc) · 1.65 KB
/
work_unit_hello_world.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import os
from pyhpcc.models.auth import Auth
from pyhpcc.models.hpcc import HPCC
from pyhpcc.models.workunit_submit import WorkunitSubmit as ws
# Example to show how to compile and run an inline ECL query
# Configurations
environment = (
"university.us-hpccsystems-dev.azure.lnrsg.io" # Eg: myuniversity.hpccsystems.io
)
port = "8010" # Eg: 8010
user_name = "user_name" # HPCC username
password = "password" # HPCC password
protocol = "http" # Specify HTTP or HTTPS
cluster = "thor" # Specify the cluster name to be used
ecl_query = """OUTPUT('HELLO WORLD!');""" # ECL Query to execute
job_name = "Basic job submission"
working_folder = os.getcwd() # Folder to generate .ecl, .eclxml, .eclxml.xml
try:
auth_object = Auth(
environment,
port,
user_name,
password,
require_auth=True,
protocol=protocol,
)
hpcc_object = HPCC(auth=auth_object)
work_s = ws(hpcc_object, (cluster,), remove_temp_files=True)
# Create a file for the ECL query we want to execute
file_name = work_s.create_file_name(
query_text=ecl_query,
working_folder=working_folder,
job_name=job_name,
)
# Compile the ECL file
output, output_file = work_s.bash_compile(file_name)
# check if the query is compiled without any errors
if output["status"] == "success":
# Run the ECL file that's compiled
output = work_s.bash_run(output_file)
# Check if workunit is created and wait on it for completion
if (wuid := output["wu_info"]["wuid"]) is not None:
resp = work_s.wu_wait_complete(wuid)
print(resp.json())
except Exception as e:
print(e)