/* * P2PFaaS - A framework for FaaS Load Balancing * Copyright (c) 2019 - 2022. Gabriele Proietti Mattia * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ package api import ( "encoding/json" "github.com/gorilla/mux" "io/ioutil" "net/http" "scheduler/errors" "scheduler/faas_openfaas" "scheduler/log" "scheduler/utils" ) func SystemScaleFunctionPost(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) function := vars["function"] if function == "" { errors.ReplyWithError(&w, errors.GenericError, nil) log.Log.Debugf("service is not specified") return } bytes, err := ioutil.ReadAll(r.Body) if err != nil { log.Log.Debugf("Cannot parse input: %s", err) errors.ReplyWithError(&w, errors.InputNotValid, nil) return } var params faas_openfaas.FunctionScalePayload err = json.Unmarshal(bytes, ¶ms) if err != nil { log.Log.Debugf("Cannot parse json input: %s", err) errors.ReplyWithError(&w, errors.InputNotValid, nil) return } res, err := faas_openfaas.FunctionScale(function, params.Replicas) if err != nil { log.Log.Debugf("Cannot scale function: %s", err) errors.ReplyWithError(&w, errors.GenericOpenFaasError, nil) return } utils.HttpSendJSONResponseByte(&w, res.StatusCode, res.Body, nil) }