summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2017-10-11 09:36:05 +0200
committerSebastien Douheret <sebastien.douheret@iot.bzh>2017-11-06 15:57:04 +0100
commit8119c1641e88ee5020e380c08119f508c6e24222 (patch)
tree5b295fb9e210b9bf5cee52fdb4fcb16d6878fd27 /lib
parenta3d2ca72d05d28b1ae5820787ff696dd75fd17cc (diff)
Add Server UUID and use it build CmdID.
Diffstat (limited to 'lib')
-rw-r--r--lib/apiv1/events.go3
-rw-r--r--lib/apiv1/exec.go11
-rw-r--r--lib/apiv1/make.go16
-rw-r--r--lib/syncthing/folder-st.go2
-rw-r--r--lib/xdsconfig/config.go7
-rw-r--r--lib/xdsconfig/fileconfig.go2
6 files changed, 27 insertions, 14 deletions
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)