Skip to content

Commit

Permalink
Fixed unmarshaling of composition report. Now it is correctly printed
Browse files Browse the repository at this point in the history
  • Loading branch information
redjack96 committed Sep 8, 2024
1 parent b9da69a commit ada0b0d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 15 deletions.
8 changes: 7 additions & 1 deletion internal/api/composition.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,16 @@ func InvokeFunctionComposition(e echo.Context) error {
}
return e.JSON(http.StatusInternalServerError, v)
} else {
reports := make(map[string]*function.ExecutionReport)
fcReq.ExecReport.Reports.Range(func(id fc.ExecutionReportId, report *function.ExecutionReport) bool {
reports[string(id)] = report
return true
})

return e.JSON(http.StatusOK, fc.CompositionResponse{
Success: true,
Result: fcReq.ExecReport.Result,
Reports: fcReq.ExecReport.String(),
Reports: reports,
ResponseTime: fcReq.ExecReport.ResponseTime,
})
}
Expand Down
2 changes: 1 addition & 1 deletion internal/fc/fc_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func NewCompositionRequest(reqId string, composition *FunctionComposition, param
type CompositionResponse struct {
Success bool
Result map[string]interface{}
Reports string
Reports map[string]*function.ExecutionReport
ResponseTime float64 // time waited by the user to get the output of the entire composition (in seconds)
}

Expand Down
6 changes: 3 additions & 3 deletions internal/fc/function_composition.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,9 @@ func (cer *CompositionExecutionReport) UnmarshalJSON(data []byte) error {
}

func (cer *CompositionExecutionReport) String() string {
str := "{"
str += fmt.Sprintf("\n\t'ResponseTime': %f,", cer.ResponseTime)
str += "\n\t'Reports': ["
str := "["
str += fmt.Sprintf("\n\tResponseTime: %f,", cer.ResponseTime)
str += "\n\tReports: ["
if cer.Reports.Len() > 0 {
j := 0
cer.Reports.Range(func(id ExecutionReportId, report *function.ExecutionReport) bool {
Expand Down
8 changes: 7 additions & 1 deletion internal/fc_scheduling/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fc_scheduling

import (
"github.com/grussorusso/serverledge/internal/fc"
"github.com/grussorusso/serverledge/internal/function"
"time"
)

Expand All @@ -24,10 +25,15 @@ func SubmitAsyncCompositionRequest(fcReq *fc.CompositionRequest) {
PublishAsyncCompositionResponse(fcReq.ReqId, fc.CompositionResponse{Success: false})
return
}
reports := make(map[string]*function.ExecutionReport)
fcReq.ExecReport.Reports.Range(func(id fc.ExecutionReportId, report *function.ExecutionReport) bool {
reports[string(id)] = report
return true
})
PublishAsyncCompositionResponse(fcReq.ReqId, fc.CompositionResponse{
Success: true,
Result: fcReq.ExecReport.Result,
Reports: fcReq.ExecReport.String(),
Reports: reports,
ResponseTime: fcReq.ExecReport.ResponseTime,
})
fcReq.ExecReport = executionReport
Expand Down
22 changes: 13 additions & 9 deletions internal/test/fc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,7 @@ func TestMarshalingFunctionComposition(t *testing.T) {
}

func TestUnmarshalFunctionCompositionResult(t *testing.T) {
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}"
var retrieved fc.CompositionExecutionReport
errUnmarshal := json.Unmarshal([]byte(composition), &retrieved)
fmt.Println(retrieved.String())
u.AssertNilMsg(t, errUnmarshal, "failed to unmarshal composition result")
u.AssertNonNilMsg(t, retrieved.Result, "the unmarshalled composition result should not have been nil")
u.AssertNonNilMsg(t, retrieved.Reports, "the unmarshalled composition result should not have been nil")
// 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}"

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

expected := fc.CompositionExecutionReport{
expected := &fc.CompositionExecutionReport{
Result: resultMap,
Reports: reportsMap,
ResponseTime: 0.000000,
// Progress is not checked
}

u.AssertTrueMsg(t, retrieved.Equals(&expected), fmt.Sprintf("execution report differs first: %s\n second: %s", retrieved.String(), expected.String()))
marshal, errMarshal := json.Marshal(expected)
u.AssertNil(t, errMarshal)

var retrieved fc.CompositionExecutionReport
errUnmarshal := json.Unmarshal(marshal, &retrieved)

u.AssertNilMsg(t, errUnmarshal, "failed to unmarshal composition result")
u.AssertNonNilMsg(t, retrieved.Result, "the unmarshalled composition result should not have been nil")
u.AssertNonNilMsg(t, retrieved.Reports, "the unmarshalled composition result should not have been nil")

u.AssertTrueMsg(t, retrieved.Equals(expected), fmt.Sprintf("execution report differs first: %v\n second: %v", retrieved, expected))
}

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

0 comments on commit ada0b0d

Please sign in to comment.