update workflow execution status
This commit is contained in:
parent
98b6cdaae5
commit
1871e067df
69
main.go
69
main.go
@ -10,7 +10,6 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
|
||||||
|
|
||||||
"oc-monitor/conf"
|
"oc-monitor/conf"
|
||||||
"oc-monitor/models"
|
"oc-monitor/models"
|
||||||
@ -29,11 +28,11 @@ import (
|
|||||||
|
|
||||||
var logger zerolog.Logger
|
var logger zerolog.Logger
|
||||||
var wf_logger zerolog.Logger
|
var wf_logger zerolog.Logger
|
||||||
|
var pods_logger zerolog.Logger
|
||||||
var parser argparse.Parser
|
var parser argparse.Parser
|
||||||
var monitorLocal bool
|
var monitorLocal bool
|
||||||
var workflowName string
|
var workflowName string
|
||||||
|
|
||||||
const namespace = "-n argo"
|
|
||||||
const defaultConfigFile = "/etc/oc/ocmonitor_conf.json"
|
const defaultConfigFile = "/etc/oc/ocmonitor_conf.json"
|
||||||
const localConfigFile = "./conf/ocmonitor_conf.json"
|
const localConfigFile = "./conf/ocmonitor_conf.json"
|
||||||
|
|
||||||
@ -105,6 +104,7 @@ func retrieveWorkflowId(exec_id string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func executeWorkflow(argo_file_path string) {
|
func executeWorkflow(argo_file_path string) {
|
||||||
|
// var stdout, stderr, stdout_logs, stderr_logs io.ReadCloser
|
||||||
var stdout, stderr io.ReadCloser
|
var stdout, stderr io.ReadCloser
|
||||||
// var stderr io.ReadCloser
|
// var stderr io.ReadCloser
|
||||||
var err error
|
var err error
|
||||||
@ -120,26 +120,50 @@ func executeWorkflow(argo_file_path string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cmd_logs := exec.Command("argo","logs","oc-monitor-"+workflowName,"-f" , "-n", "argo")
|
||||||
|
|
||||||
|
// // if stdout_logs, err = cmd_logs.StdoutPipe(); err != nil{
|
||||||
|
// // wf_logger.Error().Msg("Could not retrieve stdoutpipe " + err.Error())
|
||||||
|
// // return
|
||||||
|
// // }
|
||||||
|
|
||||||
|
// // if stderr_logs, err = cmd_logs.StderrPipe(); err != nil{
|
||||||
|
// // wf_logger.Error().Msg("Could not retrieve stderrpipe " + err.Error())
|
||||||
|
// // return
|
||||||
|
// // }
|
||||||
|
|
||||||
if err := cmd.Start(); err != nil {
|
if err := cmd.Start(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if err := cmd_logs.Start(); err != nil {
|
||||||
|
// panic(err)
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
go logWorkflow(stdout, &wg)
|
go logWorkflow(stdout, &wg)
|
||||||
go logWorkflow(stderr,&wg)
|
// go logWorkflow(stderr,&wg)
|
||||||
|
|
||||||
|
|
||||||
time.Sleep(time.Second * 1)
|
// time.Sleep(time.Second * 1)
|
||||||
go logPods(workflowName)
|
// go logPods(stdout_logs,"out")
|
||||||
|
// go logPods(stderr_logs,"err")
|
||||||
|
|
||||||
|
|
||||||
if err := cmd.Wait(); err != nil {
|
if err := cmd.Wait(); err != nil {
|
||||||
wf_logger.Error().Msg("Could not execute argo submit")
|
wf_logger.Error().Msg("Could not execute argo submit")
|
||||||
wf_logger.Error().Msg(err.Error() + bufio.NewScanner(stderr).Text())
|
wf_logger.Error().Msg(err.Error() + bufio.NewScanner(stderr).Text())
|
||||||
// updateStatus(exec_id, FATAL)
|
updateStatus("fatal")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if err := cmd_logs.Wait(); err != nil {
|
||||||
|
// wf_logger.Error().Msg("Could not execute argo logs")
|
||||||
|
// wf_logger.Error().Msg(err.Error() + bufio.NewScanner(stdout_logs).Text())
|
||||||
|
// wf_logger.Error().Msg(err.Error() + bufio.NewScanner(stderr_logs).Text())
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,15 +179,12 @@ func logWorkflow(pipe io.ReadCloser, wg *sync.WaitGroup) {
|
|||||||
watch_output = append(watch_output, log)
|
watch_output = append(watch_output, log)
|
||||||
|
|
||||||
if(strings.HasPrefix(log, "Progress:")){
|
if(strings.HasPrefix(log, "Progress:")){
|
||||||
|
|
||||||
current_watch = *models.NewArgoLogs(watch_output)
|
current_watch = *models.NewArgoLogs(watch_output)
|
||||||
fmt.Println("Status : " + current_watch.Status)
|
fmt.Println("Status : " + current_watch.Status)
|
||||||
workflowName = current_watch.Name
|
workflowName = current_watch.Name
|
||||||
if(!current_watch.Equals(previous_watch)){
|
if(!current_watch.Equals(previous_watch)){
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
defer wg.Done()
|
|
||||||
if(current_watch.Status == "Succeeded"){
|
|
||||||
fmt.Print()
|
|
||||||
}
|
|
||||||
checkStatus(current_watch.Status, previous_watch.Status)
|
checkStatus(current_watch.Status, previous_watch.Status)
|
||||||
jsonified, err := json.Marshal(current_watch)
|
jsonified, err := json.Marshal(current_watch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -172,36 +193,20 @@ func logWorkflow(pipe io.ReadCloser, wg *sync.WaitGroup) {
|
|||||||
wf_logger.Info().Msg(string(jsonified))
|
wf_logger.Info().Msg(string(jsonified))
|
||||||
previous_watch = current_watch
|
previous_watch = current_watch
|
||||||
current_watch = models.ArgoWatch{}
|
current_watch = models.ArgoWatch{}
|
||||||
|
wg.Done()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debug, no logs sent
|
// Debug, no logs sent
|
||||||
func logPods(workflow_name string){
|
func logPods(pipe io.ReadCloser,name string){
|
||||||
var stderr io.ReadCloser
|
pods_logger = wf_logger.With().Str("sortie name",name).Logger()
|
||||||
var err error
|
scanner := bufio.NewScanner(pipe)
|
||||||
|
|
||||||
cmd := exec.Command("argo","logs",workflow_name, "-n", "argo")
|
|
||||||
|
|
||||||
if stderr, err = cmd.StderrPipe(); err != nil{
|
|
||||||
wf_logger.Error().Msg("Could not retrieve stderrpipe " + err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := cmd.Start(); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
scanner := bufio.NewScanner(stderr)
|
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
log := scanner.Text()
|
log := scanner.Text()
|
||||||
// fmt.Println(log)
|
// fmt.Println(log)
|
||||||
wf_logger.Info().Msg(log)
|
pods_logger.Info().Msg(log)
|
||||||
}
|
|
||||||
|
|
||||||
if err := cmd.Wait(); err != nil {
|
|
||||||
wf_logger.Error().Msg("Could not execute argo logs")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ type Workflow struct {
|
|||||||
ApiVersion string `yaml:"apiVersion"`
|
ApiVersion string `yaml:"apiVersion"`
|
||||||
Kind string `yaml:"kind"`
|
Kind string `yaml:"kind"`
|
||||||
Metadata struct {
|
Metadata struct {
|
||||||
GenerateName string `yaml:"generateName"`
|
Name string `yaml:"Name"`
|
||||||
} `yaml:"metadata"`
|
} `yaml:"metadata"`
|
||||||
Spec Spec `yaml:"spec,omitempty"`
|
Spec Spec `yaml:"spec,omitempty"`
|
||||||
}
|
}
|
||||||
@ -49,7 +49,7 @@ func (b *ArgoBuilder) CreateDAG() (string, error) {
|
|||||||
b.Workflow.ApiVersion = "argoproj.io/v1alpha1"
|
b.Workflow.ApiVersion = "argoproj.io/v1alpha1"
|
||||||
b.Workflow.Kind = "Workflow"
|
b.Workflow.Kind = "Workflow"
|
||||||
random_name := generateWfName()
|
random_name := generateWfName()
|
||||||
b.Workflow.Metadata.GenerateName = "oc-monitor-" + random_name
|
b.Workflow.Metadata.Name = "oc-monitor-" + random_name
|
||||||
|
|
||||||
yamlified, err := yaml.Marshal(b.Workflow)
|
yamlified, err := yaml.Marshal(b.Workflow)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user