Use go module as dependency tool instead of glide
[src/xds/xds-agent.git] / lib / agent / agent.go
index d1a3d05..506976d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017 "IoT.bzh"
+ * Copyright (C) 2017-2018 "IoT.bzh"
  * Author Sebastien Douheret <sebastien@iot.bzh>
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -27,9 +27,10 @@ import (
        "syscall"
        "time"
 
+       st "gerrit.automotivelinux.org/gerrit/src/xds/xds-agent.git/lib/syncthing"
+
+       "gerrit.automotivelinux.org/gerrit/src/xds/xds-agent.git/lib/xdsconfig"
        "github.com/Sirupsen/logrus"
-       "github.com/iotbzh/xds-agent/lib/syncthing"
-       "github.com/iotbzh/xds-agent/lib/xdsconfig"
        "github.com/urfave/cli"
 )
 
@@ -41,15 +42,17 @@ type Context struct {
        Config        *xdsconfig.Config
        Log           *logrus.Logger
        LogLevelSilly bool
+       LogSillyf     func(format string, args ...interface{})
        SThg          *st.SyncThing
        SThgCmd       *exec.Cmd
        SThgInotCmd   *exec.Cmd
 
-       webServer  *WebServer
-       xdsServers map[string]*XdsServer
-       sessions   *Sessions
-       events     *Events
-       projects   *Projects
+       webServer     *WebServer
+       xdsServers    map[string]*XdsServer
+       XdsSupervisor *XdsSupervisor
+       sessions      *Sessions
+       events        *Events
+       projects      *Projects
 
        Exit chan os.Signal
 }
@@ -71,13 +74,21 @@ func NewAgent(cliCtx *cli.Context) *Context {
        }
        log.Formatter = &logrus.TextFormatter{}
 
+       // Support silly logging (printed on log.debug)
        sillyVal, sillyLog := os.LookupEnv("XDS_LOG_SILLY")
+       logSilly := sillyLog && sillyVal == "1"
+       sillyFunc := func(format string, args ...interface{}) {
+               if logSilly {
+                       log.Debugf("SILLY: "+format, args...)
+               }
+       }
 
        // Define default configuration
        ctx := Context{
                ProgName:      cliCtx.App.Name,
                Log:           log,
-               LogLevelSilly: (sillyLog && sillyVal == "1"),
+               LogLevelSilly: logSilly,
+               LogSillyf:     sillyFunc,
                Exit:          make(chan os.Signal, 1),
 
                webServer:  nil,
@@ -123,7 +134,10 @@ func (ctx *Context) Run() (int, error) {
                ctx._logPrint("Logging file for HTTP requests: %s\n", logFileHTTPReq)
        }
 
-       // Create syncthing instance when section "syncthing" is present in config.json
+       // Create events management
+       ctx.events = NewEvents(ctx)
+
+       // Create syncthing instance when section "syncthing" is present in agent-config.json
        if ctx.Config.FileConf.SThgConf != nil {
                ctx.SThg = st.NewSyncThing(ctx.Config, ctx.Log)
        }
@@ -177,9 +191,6 @@ func (ctx *Context) Run() (int, error) {
        // Sessions manager
        ctx.sessions = NewClientSessions(ctx, cookieMaxAge)
 
-       // Create events management
-       ctx.events = NewEvents(ctx)
-
        // Create projects management
        ctx.projects = NewProjects(ctx, ctx.SThg)