Skip to content

Commit ada0b0d

Browse files
committed
Fixed unmarshaling of composition report. Now it is correctly printed
1 parent b9da69a commit ada0b0d

File tree

5 files changed

+31
-15
lines changed

5 files changed

+31
-15
lines changed

internal/api/composition.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,16 @@ func InvokeFunctionComposition(e echo.Context) error {
246246
}
247247
return e.JSON(http.StatusInternalServerError, v)
248248
} else {
249+
reports := make(map[string]*function.ExecutionReport)
250+
fcReq.ExecReport.Reports.Range(func(id fc.ExecutionReportId, report *function.ExecutionReport) bool {
251+
reports[string(id)] = report
252+
return true
253+
})
254+
249255
return e.JSON(http.StatusOK, fc.CompositionResponse{
250256
Success: true,
251257
Result: fcReq.ExecReport.Result,
252-
Reports: fcReq.ExecReport.String(),
258+
Reports: reports,
253259
ResponseTime: fcReq.ExecReport.ResponseTime,
254260
})
255261
}

internal/fc/fc_request.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func NewCompositionRequest(reqId string, composition *FunctionComposition, param
3838
type CompositionResponse struct {
3939
Success bool
4040
Result map[string]interface{}
41-
Reports string
41+
Reports map[string]*function.ExecutionReport
4242
ResponseTime float64 // time waited by the user to get the output of the entire composition (in seconds)
4343
}
4444

internal/fc/function_composition.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,9 @@ func (cer *CompositionExecutionReport) UnmarshalJSON(data []byte) error {
418418
}
419419

420420
func (cer *CompositionExecutionReport) String() string {
421-
str := "{"
422-
str += fmt.Sprintf("\n\t'ResponseTime': %f,", cer.ResponseTime)
423-
str += "\n\t'Reports': ["
421+
str := "["
422+
str += fmt.Sprintf("\n\tResponseTime: %f,", cer.ResponseTime)
423+
str += "\n\tReports: ["
424424
if cer.Reports.Len() > 0 {
425425
j := 0
426426
cer.Reports.Range(func(id ExecutionReportId, report *function.ExecutionReport) bool {

internal/fc_scheduling/scheduler.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package fc_scheduling
22

33
import (
44
"github.com/grussorusso/serverledge/internal/fc"
5+
"github.com/grussorusso/serverledge/internal/function"
56
"time"
67
)
78

@@ -24,10 +25,15 @@ func SubmitAsyncCompositionRequest(fcReq *fc.CompositionRequest) {
2425
PublishAsyncCompositionResponse(fcReq.ReqId, fc.CompositionResponse{Success: false})
2526
return
2627
}
28+
reports := make(map[string]*function.ExecutionReport)
29+
fcReq.ExecReport.Reports.Range(func(id fc.ExecutionReportId, report *function.ExecutionReport) bool {
30+
reports[string(id)] = report
31+
return true
32+
})
2733
PublishAsyncCompositionResponse(fcReq.ReqId, fc.CompositionResponse{
2834
Success: true,
2935
Result: fcReq.ExecReport.Result,
30-
Reports: fcReq.ExecReport.String(),
36+
Reports: reports,
3137
ResponseTime: fcReq.ExecReport.ResponseTime,
3238
})
3339
fcReq.ExecReport = executionReport

internal/test/fc_test.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,7 @@ func TestMarshalingFunctionComposition(t *testing.T) {
3636
}
3737

3838
func TestUnmarshalFunctionCompositionResult(t *testing.T) {
39-
composition := "{\n\t\"Reports\": {\n\t\t\"End_9TUZZdXNwgroNYp4akDKQ6\": {\n\t\t\t\"Result\": \"end\",\n\t\t\t\"ResponseTime\": 0,\n\t\t\t\"IsWarmStart\": false,\n\t\t\t\"InitTime\": 0,\n\t\t\t\"OffloadLatency\": 0,\n\t\t\t\"Duration\": 0,\n\t\t\t\"SchedAction\": \"\"\n\t\t},\n\t\t\"Simple_JyzhDkLuBzUVSmPEUiEWVm\": {\n\t\t\t\"Result\": \"3\",\n\t\t\t\"ResponseTime\": 0.00283594,\n\t\t\t\"IsWarmStart\": true,\n\t\t\t\"InitTime\": 0.000029114,\n\t\t\t\"OffloadLatency\": 0,\n\t\t\t\"Duration\": 0.002802751,\n\t\t\t\"SchedAction\": \"\"\n\t\t},\n\t\t\"Simple_c7A3CSJ9efgnW2uCvgWt3Y\": {\n\t\t\t\"Result\": \"4\",\n\t\t\t\"ResponseTime\": 0.002977264,\n\t\t\t\"IsWarmStart\": true,\n\t\t\t\"InitTime\": 0.000020023,\n\t\t\t\"OffloadLatency\": 0,\n\t\t\t\"Duration\": 0.002953664,\n\t\t\t\"SchedAction\": \"\"\n\t\t},\n\t\t\"Simple_z4Jp4LXWFoPnEFFNhJQ64j\": {\n\t\t\t\"Result\": \"2\",\n\t\t\t\"ResponseTime\": 15.901950313,\n\t\t\t\"IsWarmStart\": false,\n\t\t\t\"InitTime\": 12.705640725,\n\t\t\t\"OffloadLatency\": 0,\n\t\t\t\"Duration\": 3.196273017,\n\t\t\t\"SchedAction\": \"\"\n\t\t},\n\t\t\"Start_wxrH86t6zc2T2menLrUgYm\": {\n\t\t\t\"Result\": \"start\",\n\t\t\t\"ResponseTime\": 0,\n\t\t\t\"IsWarmStart\": false,\n\t\t\t\"InitTime\": 0,\n\t\t\t\"OffloadLatency\": 0,\n\t\t\t\"Duration\": 0,\n\t\t\t\"SchedAction\": \"\"\n\t\t}\n\t},\n\t\"ResponseTime\": 0,\n\t\"Result\": {\n\t\t\"result\": 4\n\t}\n}"
40-
var retrieved fc.CompositionExecutionReport
41-
errUnmarshal := json.Unmarshal([]byte(composition), &retrieved)
42-
fmt.Println(retrieved.String())
43-
u.AssertNilMsg(t, errUnmarshal, "failed to unmarshal composition result")
44-
u.AssertNonNilMsg(t, retrieved.Result, "the unmarshalled composition result should not have been nil")
45-
u.AssertNonNilMsg(t, retrieved.Reports, "the unmarshalled composition result should not have been nil")
39+
// composition := "{\n\t\"Reports\": {\n\t\t\"End_9TUZZdXNwgroNYp4akDKQ6\": {\n\t\t\t\"Result\": \"end\",\n\t\t\t\"ResponseTime\": 0,\n\t\t\t\"IsWarmStart\": false,\n\t\t\t\"InitTime\": 0,\n\t\t\t\"OffloadLatency\": 0,\n\t\t\t\"Duration\": 0,\n\t\t\t\"SchedAction\": \"\"\n\t\t},\n\t\t\"Simple_JyzhDkLuBzUVSmPEUiEWVm\": {\n\t\t\t\"Result\": \"3\",\n\t\t\t\"ResponseTime\": 0.00283594,\n\t\t\t\"IsWarmStart\": true,\n\t\t\t\"InitTime\": 0.000029114,\n\t\t\t\"OffloadLatency\": 0,\n\t\t\t\"Duration\": 0.002802751,\n\t\t\t\"SchedAction\": \"\"\n\t\t},\n\t\t\"Simple_c7A3CSJ9efgnW2uCvgWt3Y\": {\n\t\t\t\"Result\": \"4\",\n\t\t\t\"ResponseTime\": 0.002977264,\n\t\t\t\"IsWarmStart\": true,\n\t\t\t\"InitTime\": 0.000020023,\n\t\t\t\"OffloadLatency\": 0,\n\t\t\t\"Duration\": 0.002953664,\n\t\t\t\"SchedAction\": \"\"\n\t\t},\n\t\t\"Simple_z4Jp4LXWFoPnEFFNhJQ64j\": {\n\t\t\t\"Result\": \"2\",\n\t\t\t\"ResponseTime\": 15.901950313,\n\t\t\t\"IsWarmStart\": false,\n\t\t\t\"InitTime\": 12.705640725,\n\t\t\t\"OffloadLatency\": 0,\n\t\t\t\"Duration\": 3.196273017,\n\t\t\t\"SchedAction\": \"\"\n\t\t},\n\t\t\"Start_wxrH86t6zc2T2menLrUgYm\": {\n\t\t\t\"Result\": \"start\",\n\t\t\t\"ResponseTime\": 0,\n\t\t\t\"IsWarmStart\": false,\n\t\t\t\"InitTime\": 0,\n\t\t\t\"OffloadLatency\": 0,\n\t\t\t\"Duration\": 0,\n\t\t\t\"SchedAction\": \"\"\n\t\t}\n\t},\n\t\"ResponseTime\": 0,\n\t\"Result\": {\n\t\t\"result\": 4\n\t}\n}"
4640

4741
resultMap := make(map[string]interface{})
4842
resultMap["result"] = 4.
@@ -54,14 +48,24 @@ func TestUnmarshalFunctionCompositionResult(t *testing.T) {
5448
reportsMap.Set("Start_wxrH86t6zc2T2menLrUgYm", &function.ExecutionReport{ResponseTime: 0.000000, IsWarmStart: false, InitTime: 0.000000, OffloadLatency: 0.000000, Duration: 0.000000, SchedAction: "", Output: "", Result: "start"})
5549
reportsMap.Set("Simple_z4Jp4LXWFoPnEFFNhJQ64j", &function.ExecutionReport{ResponseTime: 15.901950313, IsWarmStart: false, InitTime: 12.705640725, OffloadLatency: 0.000000, Duration: 3.196273017, SchedAction: "", Output: "", Result: "2"})
5650

57-
expected := fc.CompositionExecutionReport{
51+
expected := &fc.CompositionExecutionReport{
5852
Result: resultMap,
5953
Reports: reportsMap,
6054
ResponseTime: 0.000000,
6155
// Progress is not checked
6256
}
6357

64-
u.AssertTrueMsg(t, retrieved.Equals(&expected), fmt.Sprintf("execution report differs first: %s\n second: %s", retrieved.String(), expected.String()))
58+
marshal, errMarshal := json.Marshal(expected)
59+
u.AssertNil(t, errMarshal)
60+
61+
var retrieved fc.CompositionExecutionReport
62+
errUnmarshal := json.Unmarshal(marshal, &retrieved)
63+
64+
u.AssertNilMsg(t, errUnmarshal, "failed to unmarshal composition result")
65+
u.AssertNonNilMsg(t, retrieved.Result, "the unmarshalled composition result should not have been nil")
66+
u.AssertNonNilMsg(t, retrieved.Reports, "the unmarshalled composition result should not have been nil")
67+
68+
u.AssertTrueMsg(t, retrieved.Equals(expected), fmt.Sprintf("execution report differs first: %v\n second: %v", retrieved, expected))
6569
}
6670

6771
// TestComposeFC checks the CREATE, GET and DELETE functionality of the Function Composition

0 commit comments

Comments
 (0)