...
1
18
19 package scheduler_service
20
21 import (
22 "encoding/json"
23 "io/ioutil"
24 "scheduler/log"
25 "scheduler/types"
26 "scheduler/utils"
27 )
28
29 func peerFunctionApiCall(host string, peerRequest *types.PeerJobRequest) (*APIResponse, error) {
30 payload, err := json.Marshal(peerRequest)
31 if err != nil {
32 log.Log.Errorf("Cannot encode to json payload")
33 return nil, err
34 }
35
36 log.Log.Debugf("Calling POST to %s", GetPeerFunctionUrl(host, peerRequest.FunctionName))
37
38
39
40 var headers *[]utils.HttpHeader = nil
41 if peerRequest.ServiceIdTracing != "" {
42 headers = &[]utils.HttpHeader{
43 {Key: utils.HttpHeaderP2PFaaSSchedulerTracingId, Value: peerRequest.ServiceIdTracing},
44 }
45 }
46
47 res, err := utils.HttpMachinePostJSONWithHeaders(GetPeerFunctionUrl(host, peerRequest.FunctionName), string(payload), headers)
48 if err != nil {
49 log.Log.Errorf("Cannot create POST peerRequest to %s: %s", GetPeerFunctionUrl(host, peerRequest.FunctionName), err.Error())
50 return nil, err
51 }
52 defer res.Body.Close()
53
54 body, _ := ioutil.ReadAll(res.Body)
55 response := APIResponse{
56 Headers: res.Header,
57 Body: body,
58 StatusCode: res.StatusCode,
59 }
60
61 return &response, err
62 }
63
View as plain text