From: Sebastien Douheret Date: Wed, 11 Oct 2017 07:36:05 +0000 (+0200) Subject: Add Server UUID and use it build CmdID. X-Git-Tag: v1.0.0-rc1~21 X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?p=src%2Fxds%2Fxds-server.git;a=commitdiff_plain;h=8119c1641e88ee5020e380c08119f508c6e24222 Add Server UUID and use it build CmdID. --- diff --git a/lib/apiv1/events.go b/lib/apiv1/events.go index da8298c..b87486f 100644 --- a/lib/apiv1/events.go +++ b/lib/apiv1/events.go @@ -112,6 +112,9 @@ func (s *APIService) eventsRegister(c *gin.Context) { Folder: *cfg, } + s.log.Debugf("Event emit %s - ID=%s, Status=%s IsInSync=%v", EventEventType+evType, cfg.ID, + cfg.Status, cfg.IsInSync) + if err := (*so).Emit(EventEventType+evType, msg); err != nil { s.log.Errorf("WS Emit Folder StateChanged event : %v", err) } diff --git a/lib/apiv1/exec.go b/lib/apiv1/exec.go index fd0f8bb..0167196 100644 --- a/lib/apiv1/exec.go +++ b/lib/apiv1/exec.go @@ -19,7 +19,8 @@ type ( // ExecArgs JSON parameters of /exec command ExecArgs struct { ID string `json:"id" binding:"required"` - SdkID string `json:"sdkid"` // sdk ID to use for setting env + SdkID string `json:"sdkID"` // sdk ID to use for setting env + CmdID string `json:"cmdID"` // command unique ID Cmd string `json:"cmd" binding:"required"` Args []string `json:"args"` Env []string `json:"env"` @@ -168,11 +169,13 @@ func (s *APIService) execCmd(c *gin.Context) { } // Unique ID for each commands - cmdID := strconv.Itoa(execCommandID) - execCommandID++ + if args.CmdID == "" { + args.CmdID = s.cfg.ServerUID[:18] + "_" + strconv.Itoa(execCommandID) + execCommandID++ + } // Create new execution over WS context - execWS := eows.New(strings.Join(cmd, " "), cmdArgs, sop, sess.ID, cmdID) + execWS := eows.New(strings.Join(cmd, " "), cmdArgs, sop, sess.ID, args.CmdID) execWS.Log = s.log // Append client project dir to environment diff --git a/lib/apiv1/make.go b/lib/apiv1/make.go index cf76476..223d4bf 100644 --- a/lib/apiv1/make.go +++ b/lib/apiv1/make.go @@ -15,7 +15,8 @@ import ( // MakeArgs is the parameters (json format) of /make command type MakeArgs struct { ID string `json:"id"` - SdkID string `json:"sdkid"` // sdk ID to use for setting env + SdkID string `json:"sdkID"` // sdk ID to use for setting env + CmdID string `json:"cmdID"` // command unique ID Args []string `json:"args"` // args to pass to make command Env []string `json:"env"` RPath string `json:"rpath"` // relative path into project @@ -171,8 +172,11 @@ func (s *APIService) buildMake(c *gin.Context) { } } - cmdID := strconv.Itoa(makeCommandID) - makeCommandID++ + // Unique ID for each commands + if args.CmdID == "" { + args.CmdID = s.cfg.ServerUID[:18] + "_" + strconv.Itoa(makeCommandID) + makeCommandID++ + } cmd := []string{} // Retrieve env command regarding Sdk ID @@ -186,14 +190,14 @@ func (s *APIService) buildMake(c *gin.Context) { cmd = append(cmd, args.Args...) } - s.log.Debugf("Execute [Cmd ID %d]: %v", cmdID, cmd) + s.log.Debugf("Execute [Cmd ID %d]: %v", args.CmdID, cmd) data := make(map[string]interface{}) data["ID"] = prj.ID data["RootPath"] = prj.RootPath data["ExitImmediate"] = args.ExitImmediate - err := common.ExecPipeWs(cmd, args.Env, sop, sess.ID, cmdID, execTmo, s.log, oCB, eCB, &data) + err := common.ExecPipeWs(cmd, args.Env, sop, sess.ID, args.CmdID, execTmo, s.log, oCB, eCB, &data) if err != nil { common.APIError(c, err.Error()) return @@ -202,6 +206,6 @@ func (s *APIService) buildMake(c *gin.Context) { c.JSON(http.StatusOK, gin.H{ "status": "OK", - "cmdID": cmdID, + "cmdID": args.CmdID, }) } diff --git a/lib/syncthing/folder-st.go b/lib/syncthing/folder-st.go index ae95b27..27a43e6 100644 --- a/lib/syncthing/folder-st.go +++ b/lib/syncthing/folder-st.go @@ -58,7 +58,7 @@ func (f *STFolder) Add(cfg folder.FolderConfig) (*folder.FolderConfig, error) { f.fConfig = cfg // Update Syncthing folder - // (expect if status is ErrorConfig) + // (except if status is ErrorConfig) // TODO: add cache to avoid multiple requests on startup if f.fConfig.Status != folder.StatusErrorConfig { id, err := f.st.FolderChange(f.fConfig) diff --git a/lib/xdsconfig/config.go b/lib/xdsconfig/config.go index 2f1fa96..0fc1346 100644 --- a/lib/xdsconfig/config.go +++ b/lib/xdsconfig/config.go @@ -88,6 +88,8 @@ func Init(cliCtx *cli.Context, log *logrus.Logger) (*Config, error) { Log: log, } + c.Log.Infoln("Server UUID: ", uuid) + // config file settings overwrite default config err = readGlobalConfig(&c, c.Options.ConfigFile) if err != nil { @@ -130,8 +132,9 @@ func Init(cliCtx *cli.Context, log *logrus.Logger) (*Config, error) { return nil, fmt.Errorf("Cannot create logs dir: %v", err) } } - c.Log.Infoln("Logs file: ", c.Options.LogFile) - c.Log.Infoln("Logs directory: ", c.FileConf.LogsDir) + + c.Log.Infoln("Logs file: ", c.Options.LogFile) + c.Log.Infoln("Logs directory: ", c.FileConf.LogsDir) return &c, nil } diff --git a/lib/xdsconfig/fileconfig.go b/lib/xdsconfig/fileconfig.go index 39560a4..dafb034 100644 --- a/lib/xdsconfig/fileconfig.go +++ b/lib/xdsconfig/fileconfig.go @@ -84,7 +84,7 @@ func readGlobalConfig(c *Config, confFile string) error { // No config file found return nil } - c.Log.Infof("Use config file: %s", *cFile) + c.Log.Infof("Use config file: %s", *cFile) // TODO move on viper package to support comments in JSON and also // bind with flags (command line options) diff --git a/main.go b/main.go index 89d2f65..8af553d 100644 --- a/main.go +++ b/main.go @@ -148,7 +148,7 @@ func xdsApp(cliCtx *cli.Context) error { } ctx.Config.LogVerboseOut = fdLH - logPrint(ctx, "Logging file for HTTP requests: %s\n", logFileHTTPReq) + logPrint(ctx, "Logging file for HTTP requests: %s\n", logFileHTTPReq) } // Create syncthing instance when section "syncthing" is present in config.json diff --git a/test/test_stdoutstderr.sh b/test/test_stdoutstderr.sh new file mode 100755 index 0000000..652c4f8 --- /dev/null +++ b/test/test_stdoutstderr.sh @@ -0,0 +1,7 @@ +#!/bin/bash +echo "1:STDOUT" +>&2 echo "2:STDERR" +echo "3:STDOUT" +>&2 echo "4:STDERR" +>&2 echo "5:STDERR" +echo "6:STDOUT"