...
1
18
19 package faas_openfaas
20
21 import (
22 "encoding/json"
23 "io/ioutil"
24 "scheduler/errors"
25 "scheduler/log"
26 "scheduler/types"
27 )
28
29 func functionScaleApiCall(host string, functionName string, replicas uint) (*types.FaasApiResponse, error) {
30 payload := FunctionScalePayload{
31 Service: functionName,
32 Replicas: replicas,
33 }
34
35 payloadJson, err := json.Marshal(payload)
36 if err != nil {
37 return nil, errors.ErrorJSONEncode{}
38 }
39
40 res, err := HttpPostJSON(GetApiScaleFunction(host, functionName), string(payloadJson))
41 if err != nil {
42 log.Log.Debugf("Cannot create POST request to %s: %s", GetApiSystemFunctionsUrl(host), err.Error())
43 return nil, err
44 }
45
46 body, _ := ioutil.ReadAll(res.Body)
47 _ = res.Body.Close()
48
49 response := types.FaasApiResponse{
50 Headers: res.Header,
51 Body: body,
52 StatusCode: res.StatusCode,
53 }
54
55 return &response, err
56 }
57
View as plain text