...

Source file src/scheduler/faas_openfaas/api_function_deploy.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/log"
    25  	"scheduler/types"
    26  )
    27  
    28  func functionDeployApiCall(host string, function Function) (*types.FaasApiResponse, error) {
    29  	faas, err := json.Marshal(function)
    30  	if err != nil {
    31  		log.Log.Debugf("Passed function is not valid: %s", err.Error())
    32  		return nil, err
    33  	}
    34  	log.Log.Debugf("request json is %s", string(faas))
    35  
    36  	res, err := HttpPostJSON(GetApiSystemFunctionsUrl(host), string(faas))
    37  	if err != nil {
    38  		log.Log.Debugf("Could not contact OpenFaaS backend: %s", err.Error())
    39  		return nil, err
    40  	}
    41  
    42  	body, _ := ioutil.ReadAll(res.Body)
    43  	_ = res.Body.Close()
    44  
    45  	response := types.FaasApiResponse{
    46  		Headers:    res.Header,
    47  		Body:       body,
    48  		StatusCode: res.StatusCode,
    49  	}
    50  
    51  	return &response, err
    52  }
    53  

View as plain text