...

Source file src/scheduler/config/config.go

Documentation: scheduler/config

     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 config implements all the configuration parameters of the system and their handling.
    20  package config
    21  
    22  import (
    23  	"io/ioutil"
    24  	"scheduler/log"
    25  	"strings"
    26  )
    27  
    28  const AppName = "p2pfaas-scheduler"
    29  const AppVersion = "0.3.0b"
    30  const AppVersionCommit = "xxx"
    31  
    32  const DataPath = "/data"
    33  
    34  // const ConfigurationFilePath = "/config"
    35  const ConfigurationFileName = "p2p_faas-scheduler.json"
    36  const ConfigurationSchedulerFileName = "p2p_faas-scheduler-config.json"
    37  
    38  // const ConfigurationFileFullPath = ConfigurationFilePath + "/" + ConfigurationFileName
    39  // const SchedulerConfigurationFullPath = ConfigurationFilePath + "/" + SchedulerConfigurationFileName
    40  
    41  const DefaultListeningPort = 18080
    42  const DefaultQueueLengthMax = 100
    43  const DefaultFunctionsRunningMax = 10
    44  const DefaultRunningEnvironment = RunningEnvironmentProduction
    45  
    46  // env
    47  const EnvRunningEnvironment = "P2PFAAS_DEV_ENV"
    48  const EnvServiceDiscoveryListeningHost = "P2PFAAS_SERVICE_DISCOVERY_HOST"
    49  const EnvServiceDiscoveryListeningPort = "P2PFAAS_SERVICE_DISCOVERY_PORT"
    50  const EnvServiceLearningListeningHost = "P2PFAAS_SERVICE_LEARNING_HOST"
    51  const EnvServiceLearningListeningPort = "P2PFAAS_SERVICE_LEARNING_PORT"
    52  const EnvOpenFaasEnabled = "P2PFAAS_OPENFAAS_ENABLED"
    53  const EnvOpenFaasListeningHost = "P2PFAAS_OPENFAAS_HOST"
    54  const EnvOpenFaasListeningPort = "P2PFAAS_OPENFAAS_PORT"
    55  const EnvFunctionsList = "P2PFAAS_FNS_LIST"
    56  const EnvDataPath = "P2PFAAS_DATA_PATH"
    57  
    58  const EnvProfiling = "P2PFAAS_PROF"
    59  
    60  const DefaultServiceDiscoveryListeningHost = "discovery"
    61  const DefaultServiceDiscoveryListeningPort = 19000
    62  
    63  const DefaultServiceLearningListeningHost = "learner"
    64  const DefaultServiceLearningListeningPort = 19020
    65  
    66  const RunningEnvironmentProduction = "production"
    67  const RunningEnvironmentDevelopment = "development"
    68  
    69  const DefaultOpenFaaSListeningHost = "faas_containers-openfaas-swarm"
    70  const DefaultOpenFaaSListeningPort = 8080
    71  
    72  const DefaultDataPath = "/data"
    73  
    74  const UserAgentMachine = "Machine"
    75  
    76  /*
    77   * Variables
    78   */
    79  
    80  var OpenFaaSUsername = "admin"
    81  var OpenFaaSPassword = "admin"
    82  
    83  var configurationStatic *ConfigurationStatic
    84  var configurationDynamic *ConfigurationDynamic
    85  
    86  var configurationDynamicReadFromFile = false
    87  
    88  func init() {
    89  	// init both configurations
    90  	InitConfigurationStatic()
    91  	InitConfigurationDynamic()
    92  
    93  	// get the secrets for accessing OpenFaas APIs
    94  	// if os.Getenv(EnvDevelopmentEnvironment) == Configuration.GetRunningEnvironment() {
    95  	log.Log.Infof("Starting in %s environment", GetRunningEnvironment())
    96  
    97  	if GetOpenFaasEnabled() {
    98  		username, _ := ioutil.ReadFile("/run/secrets/basic-auth-user")
    99  		OpenFaaSUsername = strings.TrimSpace(string(username))
   100  		password, _ := ioutil.ReadFile("/run/secrets/basic-auth-password")
   101  		OpenFaaSPassword = strings.TrimSpace(string(password))
   102  	}
   103  
   104  	// }
   105  
   106  	// log.Log.Debug("Init with user %s and password %s", OpenFaaSUsername, OpenFaaSPassword)
   107  	log.Log.Infof("Init with RunningFunctionsMax %d, QueueMaxLength %d, QueueEnabled %v",
   108  		GetRunningFunctionMax(), GetQueueLengthMax(), GetQueueEnabled())
   109  	// log.Log.Infof("Init with functions=%v", GetFunctionsList())
   110  }
   111  
   112  func Start() {
   113  
   114  }
   115  

View as plain text