@@ -5,6 +5,10 @@ import (
55 "encoding/json"
66 "errors"
77 "fmt"
8+ "io"
9+ "net/http"
10+ "time"
11+
812 "github.com/cornelk/hashmap"
913 "github.com/grussorusso/serverledge/internal/client"
1014 "github.com/grussorusso/serverledge/internal/container"
@@ -14,9 +18,6 @@ import (
1418 "github.com/grussorusso/serverledge/internal/node"
1519 "github.com/labstack/echo/v4"
1620 "github.com/labstack/gommon/log"
17- "io"
18- "net/http"
19- "time"
2021)
2122
2223// ===== Function Composition =====
@@ -31,7 +32,7 @@ func CreateFunctionCompositionFromASL(e echo.Context) error {
3132
3233 err := json .Unmarshal (body , & creationRequest )
3334 if err != nil && err != io .EOF {
34- log .Printf ("Could not parse request: %v" , err )
35+ log .Printf ("Could not parse compose request - error during unmarshal : %v" , err )
3536 return err
3637 }
3738
@@ -49,7 +50,8 @@ func CreateFunctionCompositionFromASL(e echo.Context) error {
4950 log .Printf ("Could not decode composition source ASL: %v" , err )
5051 return e .JSON (http .StatusBadRequest , "composition already exists" )
5152 }
52- comp , err := fc .FromASL (creationRequest .Name , decodedSrc [:])
53+
54+ comp , err := fc .FromASL (creationRequest .Name , creationRequest .RmFnOnDeletionFlag , decodedSrc [:])
5355 if err != nil {
5456 log .Printf ("Could not parse composition from ASL: %v" , err )
5557 return e .JSON (http .StatusBadRequest , "composition already exists" )
@@ -76,7 +78,7 @@ func CreateFunctionComposition(e echo.Context) error {
7678
7779 err := json .Unmarshal (body , & comp )
7880 if err != nil && err != io .EOF {
79- log .Printf ("Could not parse request: %v" , err )
81+ log .Printf ("Could not parse composition request - error during unmarshal : %v" , err )
8082 return err
8183 }
8284 // checking if the function already exists. If exists we return an error
@@ -97,6 +99,10 @@ func CreateFunctionComposition(e echo.Context) error {
9799 log .Printf ("Dropping request for composition with non-existing function '%s'" , fName )
98100 return e .JSON (http .StatusBadRequest , "composition with non-existing function" )
99101 }
102+ if f .Signature == nil {
103+ return e .JSON (http .StatusBadRequest , "function " + fName + "has nil signature" )
104+ }
105+
100106 funcs [fName ] = f
101107 }
102108 comp .Functions = funcs
@@ -137,7 +143,7 @@ func DeleteFunctionComposition(c echo.Context) error {
137143 // here we only need the name of the function composition (and if all function should be deleted with it)
138144 err := json .NewDecoder (c .Request ().Body ).Decode (& comp )
139145 if err != nil && err != io .EOF {
140- log .Printf ("Could not parse request: %v" , err )
146+ log .Printf ("Could not parse delete request - error during decoding : %v" , err )
141147 return err
142148 }
143149
@@ -189,7 +195,7 @@ func InvokeFunctionComposition(e echo.Context) error {
189195 var fcInvocationRequest client.CompositionInvocationRequest
190196 err := json .NewDecoder (e .Request ().Body ).Decode (& fcInvocationRequest )
191197 if err != nil && err != io .EOF {
192- log .Printf ("Could not parse request: %v" , err )
198+ log .Printf ("Could not parse invoke request - error during decoding : %v" , err )
193199 return e .JSON (http .StatusInternalServerError , "failed to parse composition invocation request. Check parameters and composition definition" )
194200 }
195201 // gets a fc.CompositionRequest from the pool goroutine-safe cache.
@@ -214,11 +220,6 @@ func InvokeFunctionComposition(e echo.Context) error {
214220 OffloadLatency : 0 ,
215221 SchedAction : "" ,
216222 })
217-
218- //fcReq.ExecReport.Reports[execReportId] = &function.ExecutionReport{
219- // SchedAction: "",
220- // OffloadLatency: 0.0,
221- //}
222223 }
223224
224225 if fcReq .Async {
@@ -242,6 +243,17 @@ func InvokeFunctionComposition(e echo.Context) error {
242243 }
243244 return e .JSON (http .StatusInternalServerError , v )
244245 } else {
245- return e .JSON (http .StatusOK , fc.CompositionResponse {Success : true , CompositionExecutionReport : fcReq .ExecReport })
246+ reports := make (map [string ]* function.ExecutionReport )
247+ fcReq .ExecReport .Reports .Range (func (id fc.ExecutionReportId , report * function.ExecutionReport ) bool {
248+ reports [string (id )] = report
249+ return true
250+ })
251+
252+ return e .JSON (http .StatusOK , fc.CompositionResponse {
253+ Success : true ,
254+ Result : fcReq .ExecReport .Result ,
255+ Reports : reports ,
256+ ResponseTime : fcReq .ExecReport .ResponseTime ,
257+ })
246258 }
247259}
0 commit comments