DockerFile - based on which the image will be build to run your function
Python file - application logic to run the action/function (Here, in this example this is "test.py")
requirements.txt - add all dependant pip packages in this file. In case you dont have any library dependancies,submit a blank requirements.txt
import requests
import sys
import json
def server():
url = "http://10.129.28.219:5001/register/function/testaction"
files = [
('pythonfile', open(sys.argv[1],'rb')),
('dockerfile', open(sys.argv[2],'rb')),
('requirements.txt', open(sys.argv[3],'rb'))
]
reply = requests.post(url = url,files = files,verify=False)
print(reply.json())
def main():
server()
if __name__=="__main__":
main()
import requests
import sys
import json
def server():
url = "http://10.129.28.219:5001/register/dag"
input_json_file = open(sys.argv[1])
params = json.load(input_json_file)
reply = requests.post(url = url,json = params,verify=False)
print(reply.json())
def main():
server()
if __name__=="__main__":
main()
DAG specification includes both control dependancy as well as the control dependancy
"trigger_name" : Name of the trigger. Type accepted is string
"type": Type specifies whether the trigger is for function or dag. Accepted values are "dag" and "function"
"trigger": Specifies the endpoint route
"dags": If "type" field is specified as "dag","dags" will accept a list of dags to trigger (type = list). Else keep it as ""
"functions": If "type" field is specified as "function","functions" will accept a list of functions to trigger (type = list). Else keep it as ""
{
"trigger_name": "mydagtrigger",
"type":"dag",
"dags": ["odd-even-test","dummy-dag"],
"functions":""
}
{
"trigger_name": "myfunctiontrigger",
"type":"function",
"dags":"",
"functions": ["odd-even-action"]
}
import requests
import sys
import json
def server():
url = "http://10.129.28.219:5001/register/trigger/"
input_json_file = open(sys.argv[1])
params = json.load(input_json_file)
reply = requests.post(url = url,json = params,verify=False)
print(reply.json())
def main():
server()
if __name__=="__main__":
main()
DAG specification includes both control dependancy as well as the control dependancy
"name" : Name of the DAG
"node_id": Name of the function/action
"node_id_label": Name you want to give to the node
"primitive": Type of primitive the action supports - condition,parallel,serial(sequential)
"condition": If primitive type is "condition", then you should provide the following fields "source", "operator" and "target", else you should leave it as ""
"source": Specify any one of the response keys of the current node_id. For e.g. if one of the keys in response json is "result", and you want to provide a condition that if result=="even", then specify "source" as "result" and "target" as "even"
"operator": Mathematical operations like "equals", "greater_than" , "less_than", "greater_than_equals", "less_than_equals" are accepted.
"target": Specify the target value. It can accept both integer and string.
"next": Specify the name of next node_id to be executed. If primitive = "parallel", "next" will take list of node_ids, else it will accept a single node_id in "
"branch_1": Specify node_id if primitive == condition else keep "". This is the target branch which will execute if condition is true
"branch_2": Specify node_id if primitive == condition else keep "". This is the alternate branch which will execute if condition is false
"arguments": Keep it blank for each node_id. It will get populated with json when the DAG is instantiated with the trigger
"outputs_from": Specify the list of node_id/node_ids whose output current node_id needs to consume. This is for data dependancy.
{
"name":<string>
"dag":[
{
"node_id": "<string>",
"properties":
{
"node_id_label": "<string>"
"primitive":"<condition | parallel | serial>",
"condition":
{
"source":"<key obtained from node)id result json>",
"operator":"<equals || greater_than || less_than || ..>",
"target":"<string|integer>"
},
"next": "<next node_id to be executed : if primitive=parallel, "next" will take list of node_ids, if primitive: serial then specify a single node_id >",
"branch_1": "<node_id if type==condition else keep "">",
"branch_2": "<node_id if type==condition else keep "">",
"arguments": {} ---> Keep it blank for all action. It will get updated when the DAG is run
"outputs_from": "<list>"
}
},
{
},
.
.
.
{
}
]
}
{
"name": "odd-even-test",
"dag": [
{
"node_id": "odd-even-action",
"properties":
{
"label": "Odd Even Action",
"primitive": "condition",
"condition":
{
"source":"result",
"operator":"equals",
"target":"even"
},
"next": "",
"branch_1": "even-print-action",
"branch_2": "odd-print-action",
"arguments": {},
"outputs_from":[]
}
},
{
"node_id": "even-print-action",
"properties":
{
"label": "Even Print Action",
"primitive": "parallel",
"condition": {},
"next": ["increment-action","multiply-action"],
"branch_1": "",
"branch_2": "",
"arguments":{},
"outputs_from":["odd-even-action"]
}
},
{
"node_id": "increment-action",
"properties":
{
"label": "INCREMENT ACTION",
"primitive": "serial",
"condition": {},
"next": "",
"branch_1": "",
"branch_2": "",
"arguments":{},
"outputs_from":["even-print-action"]
}
},
{
"node_id": "multiply-action",
"properties":
{
"label": "MULTIPLY ACTION",
"primitive": "serial",
"condition": {},
"next": "",
"branch_1": "",
"branch_2": "",
"arguments":{},
"outputs_from":["even-print-action"]
}
},
{
"node_id": "odd-print-action",
"properties":
{
"label": "Odd Print Action",
"primitive": "serial",
"condition":{},
"next": "prime-check-action",
"branch_1": "",
"branch_2": "",
"arguments":{},
"outputs_from":["odd-even-action"]
}
},
{
"node_id": "prime-check-action",
"properties":
{
"label": "Prime Check Action",
"primitive": "serial",
"condition":{},
"next": "",
"branch_1": "",
"branch_2": "",
"arguments":{},
"outputs_from":["odd-print-action"]
}
}
]
}