Divided the execution between local and container and created an interface responsible for preparing and launching the execution
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
package daemons
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"oc-schedulerd/conf"
|
||||
"os/exec"
|
||||
|
||||
oclib "cloud.o-forge.io/core/oc-lib"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
@@ -14,50 +12,62 @@ type LocalMonitor struct {
|
||||
ExecutionID string
|
||||
PeerID string
|
||||
Duration int
|
||||
Logger zerolog.Logger
|
||||
LokiUrl string
|
||||
MongoUrl string
|
||||
DBName string
|
||||
|
||||
}
|
||||
|
||||
func (lm *LocalMonitor) LaunchLocalMonitor() {
|
||||
if lm.ExecutionID == "" {
|
||||
lm.Logger.Error().Msg("Missing parameter in LocalMonitor")
|
||||
func NewLocalMonitor(executionsId string, peerId string, duration int) (Executor){
|
||||
return &LocalMonitor{
|
||||
ExecutionID: executionsId,
|
||||
PeerID: peerId,
|
||||
Duration: duration,
|
||||
LokiUrl: conf.GetConfig().LokiUrl,
|
||||
MongoUrl: conf.GetConfig().MongoUrl,
|
||||
DBName: conf.GetConfig().DBName,
|
||||
}
|
||||
lm.execKube()
|
||||
}
|
||||
|
||||
func (lm *LocalMonitor) execKube() {
|
||||
// func (lm *LocalMonitor) LaunchLocalMonitor() {
|
||||
// if lm.ExecutionID == "" {
|
||||
// lm.Logger.Error().Msg("Missing parameter in LocalMonitor")
|
||||
// }
|
||||
|
||||
l := oclib.GetLogger()
|
||||
// }
|
||||
|
||||
func (lm *LocalMonitor) PrepareMonitorExec() []string {
|
||||
|
||||
args := []string{
|
||||
"-e", lm.ExecutionID, "-p", lm.PeerID, "-u", conf.GetConfig().LokiUrl, "-m", conf.GetConfig().MongoUrl,
|
||||
"-d", conf.GetConfig().DBName,
|
||||
"-e", lm.ExecutionID,
|
||||
"-p", lm.PeerID,
|
||||
"-u", lm.LokiUrl,
|
||||
"-m", lm.MongoUrl,
|
||||
"-d", lm.DBName,
|
||||
}
|
||||
|
||||
if conf.GetConfig().Mode == "kubernetes" {
|
||||
args = append(args, []string{"-M", conf.GetConfig().Mode, "-H", conf.GetConfig().KubeHost, "-P", conf.GetConfig().KubePort,
|
||||
"-C", conf.GetConfig().KubeCert, "-D", conf.GetConfig().KubeData, "-c", conf.GetConfig().KubeCA}...)
|
||||
}
|
||||
|
||||
if lm.Duration > 0 {
|
||||
args = append(args, "-t", fmt.Sprintf("%d", lm.Duration))
|
||||
}
|
||||
|
||||
return args
|
||||
}
|
||||
|
||||
func (lm *LocalMonitor) LaunchMonitor(args []string, l zerolog.Logger) {
|
||||
cmd := exec.Command(conf.GetConfig().MonitorPath, args...)
|
||||
fmt.Printf("Command : %v\n", cmd)
|
||||
|
||||
stdoutMonitord, err := cmd.StdoutPipe();
|
||||
stdoutMonitord, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
l.Error().Msg("Could not retrieve stdoutpipe for execution of oc-monitord" + err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
err = cmd.Start()
|
||||
if err != nil {
|
||||
lm.Logger.Error().Msg("Could not start oc-monitor for " + lm.ExecutionID + " : " + err.Error())
|
||||
l.Error().Msg("Could not start oc-monitor for " + lm.ExecutionID + " : " + err.Error())
|
||||
}
|
||||
|
||||
scanner := bufio.NewScanner(stdoutMonitord)
|
||||
for scanner.Scan() {
|
||||
output := scanner.Text()
|
||||
l.Debug().Msg(output)
|
||||
}
|
||||
logExecution(stdoutMonitord, l)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user