@@ -33,23 +33,8 @@ func newHTTPInvoker(cfg *config.LoaderConfiguration) *httpInvoker {
3333 }
3434}
3535
36- func (i * httpInvoker ) Invoke (function * common.Function , runtimeSpec * common.RuntimeSpecification ) (bool , * mc.ExecutionRecord ) {
37- isDandelion := strings .Contains (strings .ToLower (i .cfg .Platform ), "dandelion" )
38- isKnative := strings .Contains (strings .ToLower (i .cfg .Platform ), "knative" )
39-
40- log .Tracef ("(Invoke)\t %s: %d[ms], %d[MiB]" , function .Name , runtimeSpec .Runtime , runtimeSpec .Memory )
41-
42- record := & mc.ExecutionRecord {
43- ExecutionRecordBase : mc.ExecutionRecordBase {
44- RequestedDuration : uint32 (runtimeSpec .Runtime * 1e3 ),
45- },
46- }
47-
48- ////////////////////////////////////
49- // INVOKE FUNCTION
50- ////////////////////////////////////
51- start := time .Now ()
52- record .StartTime = start .UnixMicro ()
36+ func functionInvocationRequest (function * common.Function , runtimeSpec * common.RuntimeSpecification ,
37+ isKnative bool , isDandelion bool ) * http.Request {
5338
5439 requestBody := & bytes.Buffer {}
5540 /*if body := composeDandelionMatMulBody(function.Name); isDandelion && body != nil {
@@ -62,11 +47,7 @@ func (i *httpInvoker) Invoke(function *common.Function, runtimeSpec *common.Runt
6247 req , err := http .NewRequest ("POST" , "http://" + function .Endpoint , requestBody )
6348 if err != nil {
6449 log .Errorf ("Failed to create a HTTP request - %v\n " , err )
65-
66- record .ResponseTime = time .Since (start ).Microseconds ()
67- record .ConnectionTimeout = true
68-
69- return false , record
50+ return nil
7051 }
7152
7253 // add system specific stuff
@@ -85,6 +66,60 @@ func (i *httpInvoker) Invoke(function *common.Function, runtimeSpec *common.Runt
8566 req .URL .Path = "/hot/matmul"
8667 }
8768
69+ return req
70+ }
71+
72+ func workflowInvocationRequest (wf * common.Function ) * http.Request {
73+ if wf .WorkflowMetadata == nil {
74+ log .Fatal ("Failed to create workflow invocation request: workflow metadata is nil" )
75+ }
76+
77+ // create request
78+ reqBody := bytes .NewBufferString (wf .WorkflowMetadata .InvocationRequest )
79+ req , err := http .NewRequest ("POST" , "http://" + wf .Endpoint + "/workflow" , reqBody )
80+ if err != nil {
81+ log .Errorf ("Failed to create a HTTP request - %v\n " , err )
82+ return nil
83+ }
84+ req .Header .Set ("Content-Type" , "application/x-www-form-urlencoded" )
85+ req .Host = wf .Name // dirigent takes request name from this
86+
87+ return req
88+ }
89+
90+ func (i * httpInvoker ) Invoke (function * common.Function , runtimeSpec * common.RuntimeSpecification ) (bool , * mc.ExecutionRecord ) {
91+ isDandelion := strings .Contains (strings .ToLower (i .cfg .Platform ), "dandelion" )
92+ isKnative := strings .Contains (strings .ToLower (i .cfg .Platform ), "knative" )
93+ isWorkflow := strings .Contains (strings .ToLower (i .cfg .Platform ), "workflow" )
94+
95+ log .Tracef ("(Invoke)\t %s: %d[ms], %d[MiB]" , function .Name , runtimeSpec .Runtime , runtimeSpec .Memory )
96+
97+ record := & mc.ExecutionRecord {
98+ ExecutionRecordBase : mc.ExecutionRecordBase {
99+ RequestedDuration : uint32 (runtimeSpec .Runtime * 1e3 ),
100+ },
101+ }
102+ start := time .Now ()
103+ record .StartTime = start .UnixMicro ()
104+ record .Instance = function .Name // may get overwritten
105+
106+ // create request
107+ var req * http.Request
108+ if ! isWorkflow {
109+ req = functionInvocationRequest (function , runtimeSpec , isKnative , isDandelion )
110+ } else {
111+ if ! isDandelion {
112+ log .Fatalf ("Dirigent workflows are only supported for Dandelion so far!" )
113+ }
114+ req = workflowInvocationRequest (function )
115+ }
116+ if req == nil {
117+ record .ResponseTime = time .Since (start ).Microseconds ()
118+ record .ConnectionTimeout = true
119+ return false , record
120+ }
121+
122+ // send request
88123 resp , err := i .client .Do (req )
89124 if err != nil {
90125 log .Errorf ("%s - Failed to send an HTTP request to the server - %v\n " , function .Name , err )
@@ -116,7 +151,7 @@ func (i *httpInvoker) Invoke(function *common.Function, runtimeSpec *common.Runt
116151 }
117152
118153 if isDandelion {
119- err = DeserializeDandelionResponse (function , body , record )
154+ err = DeserializeDandelionResponse (function , body , record , isWorkflow )
120155 if err != nil {
121156 log .Warnf ("Failed to deserialize Dandelion response - %v - %v" , string (body ), err )
122157 }
0 commit comments