...

Source file src/scheduler/faas_openfaas/api_function_scale.go

Documentation: scheduler/faas_openfaas

     1  /*
     2   * P2PFaaS - A framework for FaaS Load Balancing
     3   * Copyright (c) 2019 - 2022. Gabriele Proietti Mattia <pm.gabriele@outlook.com>
     4   *
     5   * This program is free software: you can redistribute it and/or modify
     6   * it under the terms of the GNU General Public License as published by
     7   * the Free Software Foundation, either version 3 of the License, or
     8   * (at your option) any later version.
     9   *
    10   * This program is distributed in the hope that it will be useful,
    11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13   * GNU General Public License for more details.
    14   *
    15   * You should have received a copy of the GNU General Public License
    16   * along with this program.  If not, see <https://www.gnu.org/licenses/>.
    17   */
    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