Merge branch 'master' into 'master'

Fix: create log dir after validating cmdline args.

See merge request spdf/elektron!1
This commit is contained in:
Pradyumna Kaushik 2018-11-13 00:12:15 +00:00
commit fca8887adf
2 changed files with 38 additions and 47 deletions

View file

@ -1,20 +1,20 @@
// Copyright (C) 2018 spdf // Copyright (C) 2018 spdf
// //
// This file is part of Elektron. // This file is part of Elektron.
// //
// Elektron is free software: you can redistribute it and/or modify // Elektron is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// Elektron is distributed in the hope that it will be useful, // Elektron is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Elektron. If not, see <http://www.gnu.org/licenses/>. // along with Elektron. If not, see <http://www.gnu.org/licenses/>.
// //
package main package main
@ -95,19 +95,9 @@ func main() {
os.Exit(1) os.Exit(1)
} }
// Creating logger and attaching different logging platforms.
startTime := time.Now()
formattedStartTime := startTime.Format("20060102150405")
// Checking if prefix contains any special characters
if strings.Contains(*pcplogPrefix, "/") {
log.Fatal("log file prefix should not contain '/'.")
}
logPrefix := *pcplogPrefix + "_" + formattedStartTime
logger := elekLogDef.BuildLogger(startTime, logPrefix)
// Logging channels. // Logging channels.
logMType := make(chan elekLogDef.LogMessageType) logMType := make(chan elekLogDef.LogMessageType)
logMsg := make(chan string) logMsg := make(chan string)
go logger.Listen(logMType, logMsg)
// First we need to build the scheduler using scheduler options. // First we need to build the scheduler using scheduler options.
var schedOptions []schedulers.SchedulerOptions = make([]schedulers.SchedulerOptions, 0, 10) var schedOptions []schedulers.SchedulerOptions = make([]schedulers.SchedulerOptions, 0, 10)
@ -149,9 +139,7 @@ func main() {
if *enableSchedPolicySwitch { if *enableSchedPolicySwitch {
// Scheduling policy config file required. // Scheduling policy config file required.
if spcf := *schedPolConfigFile; spcf == "" { if spcf := *schedPolConfigFile; spcf == "" {
logger.WriteLog(elekLogDef.ERROR, "No file containing characteristics for"+ log.Fatal("Scheduling policy characteristics file not provided.")
" scheduling policies")
os.Exit(1)
} else { } else {
// Initializing the characteristics of the scheduling policies. // Initializing the characteristics of the scheduling policies.
schedulers.InitSchedPolicyCharacteristics(spcf) schedulers.InitSchedPolicyCharacteristics(spcf)
@ -169,7 +157,7 @@ func main() {
// If CMW is disabled, then the Median of Medians Max Peak Power Usage value is used // If CMW is disabled, then the Median of Medians Max Peak Power Usage value is used
// as the watts value for each task. // as the watts value for each task.
if *wattsAsAResource { if *wattsAsAResource {
logger.WriteLog(elekLogDef.GENERAL, "WaaR enabled...") log.Println("WaaR enabled...")
schedOptions = append(schedOptions, schedulers.WithWattsAsAResource(*wattsAsAResource)) schedOptions = append(schedOptions, schedulers.WithWattsAsAResource(*wattsAsAResource))
schedOptions = append(schedOptions, schedulers.WithClassMapWatts(*classMapWatts)) schedOptions = append(schedOptions, schedulers.WithClassMapWatts(*classMapWatts))
} }
@ -186,8 +174,7 @@ func main() {
"prog-extrema": {}, "prog-extrema": {},
} }
if _, ok := powercapValues[*powerCapPolicy]; !ok { if _, ok := powercapValues[*powerCapPolicy]; !ok {
logger.WriteLog(elekLogDef.ERROR, "Incorrect power-capping algorithm specified.") log.Fatal("Incorrect power-capping algorithm specified.")
os.Exit(1)
} else { } else {
// Indicating which power capping algorithm to use, if any. // Indicating which power capping algorithm to use, if any.
// The pcp-logging with/without power capping will be run after the // The pcp-logging with/without power capping will be run after the
@ -207,9 +194,8 @@ func main() {
// These values are not used to configure the scheduler. // These values are not used to configure the scheduler.
// hiThreshold and loThreshold are passed to the powercappers. // hiThreshold and loThreshold are passed to the powercappers.
if *hiThreshold < *loThreshold { if *hiThreshold < *loThreshold {
logger.WriteLog(elekLogDef.ERROR, "High threshold is of a"+ log.Fatal("High threshold is of a lower value than low " +
" lower value than low threshold.") "threshold.")
os.Exit(1)
} }
} }
} }
@ -218,15 +204,11 @@ func main() {
// Tasks // Tasks
// If httpServer is disabled, then path of file containing workload needs to be provided. // If httpServer is disabled, then path of file containing workload needs to be provided.
if *tasksFile == "" { if *tasksFile == "" {
logger.WriteLog(elekLogDef.ERROR, "No file containing tasks specification"+ log.Fatal("Tasks specifications file not provided.")
" provided.")
os.Exit(1)
} }
tasks, err := def.TasksFromJSON(*tasksFile) tasks, err := def.TasksFromJSON(*tasksFile)
if err != nil || len(tasks) == 0 { if err != nil || len(tasks) == 0 {
logger.WriteLog(elekLogDef.ERROR, "Invalid tasks specification file "+ log.Fatal("Invalid tasks specification file provided.")
"provided.")
os.Exit(1)
} }
schedOptions = append(schedOptions, schedulers.WithTasks(tasks)) schedOptions = append(schedOptions, schedulers.WithTasks(tasks))
@ -243,11 +225,22 @@ func main() {
Scheduler: scheduler, Scheduler: scheduler,
}) })
if err != nil { if err != nil {
logger.WriteLog(elekLogDef.ERROR, fmt.Sprintf("Unable to create scheduler driver:"+ log.Fatal(fmt.Sprintf("Unable to create scheduler driver: %s", err))
" %s", err))
os.Exit(1)
} }
// If here, then all command-line arguments validate.
// Creating logger and attaching different logging platforms.
startTime := time.Now()
formattedStartTime := startTime.Format("20060102150405")
// Checking if prefix contains any special characters.
if strings.Contains(*pcplogPrefix, "/") {
log.Fatal("log file prefix should not contain '/'.")
}
logPrefix := *pcplogPrefix + "_" + formattedStartTime
logger := elekLogDef.BuildLogger(startTime, logPrefix)
// Starting the logging go-routine.
go logger.Listen(logMType, logMsg)
// Starting PCP logging. // Starting PCP logging.
if noPowercap { if noPowercap {
go pcp.Start(pcpLog, &recordPCP, logMType, logMsg, *pcpConfigFile) go pcp.Start(pcpLog, &recordPCP, logMType, logMsg, *pcpConfigFile)

View file

@ -1,24 +1,25 @@
// Copyright (C) 2018 spdf // Copyright (C) 2018 spdf
// //
// This file is part of Elektron. // This file is part of Elektron.
// //
// Elektron is free software: you can redistribute it and/or modify // Elektron is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// Elektron is distributed in the hope that it will be useful, // Elektron is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Elektron. If not, see <http://www.gnu.org/licenses/>. // along with Elektron. If not, see <http://www.gnu.org/licenses/>.
// //
package schedulers package schedulers
import ( import (
"fmt"
mesos "github.com/mesos/mesos-go/api/v0/mesosproto" mesos "github.com/mesos/mesos-go/api/v0/mesosproto"
sched "github.com/mesos/mesos-go/api/v0/scheduler" sched "github.com/mesos/mesos-go/api/v0/scheduler"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -27,6 +28,7 @@ import (
elekLogDef "gitlab.com/spdf/elektron/logging/def" elekLogDef "gitlab.com/spdf/elektron/logging/def"
"gitlab.com/spdf/elektron/utilities" "gitlab.com/spdf/elektron/utilities"
"gitlab.com/spdf/elektron/utilities/mesosUtils" "gitlab.com/spdf/elektron/utilities/mesosUtils"
"log"
) )
func coLocated(tasks map[string]bool, s BaseScheduler) { func coLocated(tasks map[string]bool, s BaseScheduler) {
@ -150,10 +152,8 @@ func WithSchedPolSwitchEnabled(enableSchedPolicySwitch bool, switchingCriteria s
func WithNameOfFirstSchedPolToFix(nameOfFirstSchedPol string) SchedulerOptions { func WithNameOfFirstSchedPolToFix(nameOfFirstSchedPol string) SchedulerOptions {
return func(s ElectronScheduler) error { return func(s ElectronScheduler) error {
if nameOfFirstSchedPol == "" { if nameOfFirstSchedPol == "" {
lmt := elekLogDef.WARNING log.Println("First scheduling policy to deploy not mentioned. This is now" +
msgColor := elekLogDef.LogMessageColors[lmt] " going to be determined at runtime.")
msg := msgColor.Sprintf("First scheduling policy to deploy not mentioned. This is now going to be determined at runtime.")
s.(*BaseScheduler).Log(lmt, msg)
return nil return nil
} }
if _, ok := SchedPolicies[nameOfFirstSchedPol]; !ok { if _, ok := SchedPolicies[nameOfFirstSchedPol]; !ok {
@ -170,15 +170,13 @@ func WithFixedSchedulingWindow(toFixSchedWindow bool, fixedSchedWindowSize int)
if fixedSchedWindowSize <= 0 { if fixedSchedWindowSize <= 0 {
return errors.New("Invalid value of scheduling window size. Please provide a value > 0.") return errors.New("Invalid value of scheduling window size. Please provide a value > 0.")
} }
lmt := elekLogDef.WARNING log.Println(fmt.Sprintf("Fixing the size of the scheduling window to %d.."+
msgColor := elekLogDef.LogMessageColors[lmt] ".", fixedSchedWindowSize))
msg := msgColor.Sprintf("Fixing the size of the scheduling window to %d...", fixedSchedWindowSize)
s.(*BaseScheduler).Log(lmt, msg)
s.(*BaseScheduler).toFixSchedWindow = toFixSchedWindow s.(*BaseScheduler).toFixSchedWindow = toFixSchedWindow
s.(*BaseScheduler).schedWindowSize = fixedSchedWindowSize s.(*BaseScheduler).schedWindowSize = fixedSchedWindowSize
} }
// There shouldn't be any error for this scheduler option. // There shouldn't be any error for this scheduler option.
// If toFixSchedWindow is set to false, then the fixedSchedWindowSize would be ignored. In this case, // If fixSchedWindow is set to false, then the fixedSchedWindowSize would be ignored. In this case,
// the size of the scheduling window would be determined at runtime. // the size of the scheduling window would be determined at runtime.
return nil return nil
} }