...
Source file
src/scheduler/api/function_scale_function.go
1
18
19 package api
20
21 import (
22 "encoding/json"
23 "github.com/gorilla/mux"
24 "io/ioutil"
25 "net/http"
26 "scheduler/errors"
27 "scheduler/faas_openfaas"
28 "scheduler/log"
29 "scheduler/utils"
30 )
31
32 func SystemScaleFunctionPost(w http.ResponseWriter, r *http.Request) {
33 vars := mux.Vars(r)
34 function := vars["function"]
35 if function == "" {
36 errors.ReplyWithError(&w, errors.GenericError, nil)
37 log.Log.Debugf("service is not specified")
38 return
39 }
40
41 bytes, err := ioutil.ReadAll(r.Body)
42 if err != nil {
43 log.Log.Debugf("Cannot parse input: %s", err)
44 errors.ReplyWithError(&w, errors.InputNotValid, nil)
45 return
46 }
47
48 var params faas_openfaas.FunctionScalePayload
49 err = json.Unmarshal(bytes, ¶ms)
50 if err != nil {
51 log.Log.Debugf("Cannot parse json input: %s", err)
52 errors.ReplyWithError(&w, errors.InputNotValid, nil)
53 return
54 }
55 res, err := faas_openfaas.FunctionScale(function, params.Replicas)
56 if err != nil {
57 log.Log.Debugf("Cannot scale function: %s", err)
58 errors.ReplyWithError(&w, errors.GenericOpenFaasError, nil)
59 return
60 }
61
62 utils.HttpSendJSONResponseByte(&w, res.StatusCode, res.Body, nil)
63 }
64
View as plain text