prep
This commit is contained in:
@@ -3,7 +3,9 @@ package daemons
|
||||
import (
|
||||
"fmt"
|
||||
"oc-schedulerd/conf"
|
||||
"os"
|
||||
"os/exec"
|
||||
"time"
|
||||
|
||||
oclib "cloud.o-forge.io/core/oc-lib"
|
||||
"cloud.o-forge.io/core/oc-lib/models/common/enum"
|
||||
@@ -11,22 +13,21 @@ import (
|
||||
)
|
||||
|
||||
type LocalMonitor struct {
|
||||
ExecutionID string
|
||||
PeerID string
|
||||
Duration int
|
||||
LokiUrl string
|
||||
MongoUrl string
|
||||
DBName string
|
||||
ExecutionID string
|
||||
PeerID string
|
||||
Duration int
|
||||
LokiUrl string
|
||||
MongoUrl string
|
||||
DBName string
|
||||
ScheduledTime time.Time
|
||||
}
|
||||
|
||||
func NewLocalMonitor(UUID string, peerId string, duration int) Executor {
|
||||
func NewLocalMonitor(UUID string, peerId string, duration int, scheduledTime time.Time) Executor {
|
||||
return &LocalMonitor{
|
||||
ExecutionID: UUID,
|
||||
PeerID: peerId,
|
||||
Duration: duration,
|
||||
LokiUrl: oclib.GetConfig().LokiUrl,
|
||||
MongoUrl: oclib.GetConfig().MongoUrl,
|
||||
DBName: oclib.GetConfig().MongoDatabase,
|
||||
ExecutionID: UUID,
|
||||
PeerID: peerId,
|
||||
Duration: duration,
|
||||
ScheduledTime: scheduledTime,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,11 +43,12 @@ func (lm *LocalMonitor) PrepareMonitorExec() []string {
|
||||
args := []string{
|
||||
"-e", lm.ExecutionID,
|
||||
"-p", lm.PeerID,
|
||||
"-u", lm.LokiUrl,
|
||||
"-m", lm.MongoUrl,
|
||||
"-d", lm.DBName,
|
||||
"-H", conf.GetConfig().KubeHost,
|
||||
"-c", conf.GetConfig().KubeCA,
|
||||
"-C", conf.GetConfig().KubeCert,
|
||||
"-D", conf.GetConfig().KubeData,
|
||||
"-s", fmt.Sprintf("%d", lm.ScheduledTime.Unix()),
|
||||
}
|
||||
|
||||
if lm.Duration > 0 {
|
||||
args = append(args, "-t", fmt.Sprintf("%d", lm.Duration))
|
||||
}
|
||||
@@ -54,13 +56,29 @@ func (lm *LocalMonitor) PrepareMonitorExec() []string {
|
||||
return args
|
||||
}
|
||||
|
||||
func (lm *LocalMonitor) LaunchMonitor(args []string, execID string, l zerolog.Logger) {
|
||||
func (lm *LocalMonitor) LaunchMonitor(args []string, execID string, ns string, l zerolog.Logger) {
|
||||
cmd := exec.Command(conf.GetConfig().MonitorPath, args...)
|
||||
fmt.Printf("Command : %v\n", cmd)
|
||||
cmd.Env = append(os.Environ(),
|
||||
"OC_MONGO_URL="+oclib.GetConfig().MongoUrl,
|
||||
"OC_MONGO_DATABASE="+oclib.GetConfig().MongoDatabase,
|
||||
"OC_LOKI_URL="+oclib.GetConfig().LokiUrl,
|
||||
"OC_NATS_URL="+oclib.GetConfig().NATSUrl,
|
||||
)
|
||||
fmt.Println("LaunchMonitor LOCAL")
|
||||
l.Info().Str("binary", conf.GetConfig().MonitorPath).Strs("args", args).Msg("Starting oc-monitord")
|
||||
|
||||
stdoutMonitord, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
l.Error().Msg("Could not retrieve stdoutpipe for execution of oc-monitord" + err.Error())
|
||||
l.Error().Err(err).Msg("Could not retrieve stdout pipe for oc-monitord")
|
||||
oclib.NewRequestAdmin(oclib.LibDataEnum(oclib.WORKFLOW_EXECUTION), nil).UpdateOne(map[string]interface{}{
|
||||
"state": enum.FAILURE.EnumIndex(),
|
||||
}, execID)
|
||||
return
|
||||
}
|
||||
|
||||
stderrMonitord, err := cmd.StderrPipe()
|
||||
if err != nil {
|
||||
l.Error().Err(err).Msg("Could not retrieve stderr pipe for oc-monitord")
|
||||
oclib.NewRequestAdmin(oclib.LibDataEnum(oclib.WORKFLOW_EXECUTION), nil).UpdateOne(map[string]interface{}{
|
||||
"state": enum.FAILURE.EnumIndex(),
|
||||
}, execID)
|
||||
@@ -69,11 +87,14 @@ func (lm *LocalMonitor) LaunchMonitor(args []string, execID string, l zerolog.Lo
|
||||
|
||||
err = cmd.Start()
|
||||
if err != nil {
|
||||
l.Error().Msg("Could not start oc-monitor for " + lm.ExecutionID + " : " + err.Error())
|
||||
l.Error().Err(err).Str("execution", lm.ExecutionID).Msg("Could not start oc-monitord")
|
||||
oclib.NewRequestAdmin(oclib.LibDataEnum(oclib.WORKFLOW_EXECUTION), nil).UpdateOne(map[string]interface{}{
|
||||
"state": enum.FAILURE.EnumIndex(),
|
||||
}, execID)
|
||||
return
|
||||
}
|
||||
|
||||
l.Info().Int("pid", cmd.Process.Pid).Msg("oc-monitord started")
|
||||
go logExecution(stderrMonitord, l)
|
||||
logExecution(stdoutMonitord, l)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user