...

Source file src/scheduler/scheduler_service/services.go

Documentation: scheduler/scheduler_service

     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 scheduler_service
    20  
    21  import (
    22  	"scheduler/api/api_monitoring"
    23  	"scheduler/log"
    24  	"scheduler/types"
    25  	"strconv"
    26  )
    27  
    28  // GetLoad allows to get the load of another machine, from a machine
    29  func GetLoad(host string) (int, *APIResponse, error) {
    30  	res, err := monitoringLoadGetApiCall(host)
    31  	if err != nil {
    32  		log.Log.Debugf("Cannot get load from scheduler service: %s", err.Error())
    33  		return -1, res, err
    34  	}
    35  
    36  	currentRunningFunctions, err := strconv.Atoi(res.Headers.Get(api_monitoring.ApiMonitoringLoadHeaderKey))
    37  	if err != nil {
    38  		log.Log.Debugf("Cannot get load from scheduler service: %s", err.Error())
    39  		return -1, res, err
    40  	}
    41  
    42  	queueLen, err := strconv.Atoi(res.Headers.Get(api_monitoring.ApiMonitoringQueueLengthHeaderKey))
    43  	if err != nil {
    44  		log.Log.Debugf("Cannot get load from scheduler service: %s", err.Error())
    45  		return -1, res, err
    46  	}
    47  
    48  	return currentRunningFunctions + queueLen, nil, nil
    49  }
    50  
    51  // ExecuteFunction allows to request another machine to execute a function
    52  func ExecuteFunction(host string, peerRequest *types.PeerJobRequest) (*APIResponse, error) {
    53  	res, err := peerFunctionApiCall(host, peerRequest)
    54  	if err != nil {
    55  		log.Log.Errorf("[R#%d,T%s] Cannot execute function on peer: %s", peerRequest.ServiceIdRequest, peerRequest.ServiceIdTracing, err.Error())
    56  		return res, err
    57  	}
    58  
    59  	return res, nil
    60  }
    61  

View as plain text