summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2017-12-22 23:05:20 +0100
committerSebastien Douheret <sebastien.douheret@iot.bzh>2017-12-23 00:41:58 +0100
commitf2eecfb601acc6c67fb52bf2edda93505bc44da5 (patch)
treec66957356bb6a706b5b6847254a18fdb09906e6a
parent1ecdc95d837e73509243d436fcafea0920599fbe (diff)
Fixed SDKs management when running in xds VM.v1.0.0-rc2
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
-rw-r--r--lib/xdsserver/apiv1-sdks.go9
-rw-r--r--lib/xdsserver/sdk.go54
-rw-r--r--lib/xdsserver/sdks.go9
-rw-r--r--lib/xsapiv1/events.go2
-rwxr-xr-xscripts/sdks/agl/add2
-rwxr-xr-xscripts/sdks/agl/list7
-rwxr-xr-xscripts/sdks/agl/remove2
-rwxr-xr-xscripts/sdks/agl/update2
8 files changed, 70 insertions, 17 deletions
diff --git a/lib/xdsserver/apiv1-sdks.go b/lib/xdsserver/apiv1-sdks.go
index b38c418..ba32dc9 100644
--- a/lib/xdsserver/apiv1-sdks.go
+++ b/lib/xdsserver/apiv1-sdks.go
@@ -114,9 +114,16 @@ func (s *APIService) removeSdk(c *gin.Context) {
return
}
+ // Retrieve session info
+ sess := s.sessions.Get(c)
+ if sess == nil {
+ common.APIError(c, "Unknown sessions")
+ return
+ }
+
s.Log.Debugln("Remove SDK id ", id)
- delEntry, err := s.sdks.Remove(id)
+ delEntry, err := s.sdks.Remove(id, -1, sess)
if err != nil {
common.APIError(c, err.Error())
return
diff --git a/lib/xdsserver/sdk.go b/lib/xdsserver/sdk.go
index c011d09..cafd182 100644
--- a/lib/xdsserver/sdk.go
+++ b/lib/xdsserver/sdk.go
@@ -277,7 +277,7 @@ func (s *CrossSDK) Install(file string, force bool, timeout int, sess *ClientSes
s.Log.Errorln("BUG: sdk ID differs: %v != %v", sdkID, s.sdk.ID)
}
- s.Log.Debugf("Command SDK ID %s [Cmd ID %s] exited: code %d, exitError: %v", sdkID[:16], e.CmdID, code, exitError)
+ s.Log.Infof("Command SDK ID %s [Cmd ID %s] exited: code %d, exitError: %v", sdkID[:16], e.CmdID, code, exitError)
// IO socket can be nil when disconnected
so := s.sessions.IOSocketGet(e.Sid)
@@ -371,21 +371,65 @@ func (s *CrossSDK) AbortInstallRemove(timeout int) error {
}
// Remove Used to remove/uninstall a SDK
-func (s *CrossSDK) Remove() error {
+func (s *CrossSDK) Remove(timeout int, sess *ClientSession) error {
if s.sdk.Status != xsapiv1.SdkStatusInstalled {
return fmt.Errorf("this sdk is not installed")
}
+ // IO socket can be nil when disconnected
+ so := s.sessions.IOSocketGet(sess.ID)
+ if so == nil {
+ return fmt.Errorf("Cannot retrieve socket ")
+ }
+
s.sdk.Status = xsapiv1.SdkStatusUninstalling
- cmdline := s.scripts[scriptRemove] + " " + s.sdk.Path
- cmd := exec.Command(cmdline)
+ // Emit Remove event
+ if err := (*so).Emit(xsapiv1.EVTSDKStateChange, s.sdk); err != nil {
+ s.Log.Warningf("Cannot notify SDK remove: %v", err)
+ }
+
+ script := s.scripts[scriptRemove]
+ args := s.sdk.Path
+ s.Log.Infof("Uninstall SDK %s: script=%v args=%v", s.sdk.Name, script, args)
+
+ cmd := exec.Command(script, args)
stdout, err := cmd.CombinedOutput()
+
+ s.sdk.Status = xsapiv1.SdkStatusNotInstalled
+ s.Log.Debugf("SDK uninstall err %v, output:\n %v", err, string(stdout))
+
if err != nil {
+
+ // Emit Remove event
+ evData := xsapiv1.SDKManagementMsg{
+ Timestamp: time.Now().String(),
+ Sdk: s.sdk,
+ Progress: 100,
+ Exited: true,
+ Code: 1,
+ Error: err.Error(),
+ }
+ if err := (*so).Emit(xsapiv1.EVTSDKRemove, evData); err != nil {
+ s.Log.Warningf("Cannot notify SDK remove end: %v", err)
+ }
+
return fmt.Errorf("Error while uninstalling sdk: %v", err)
}
- s.Log.Debugf("SDK uninstall output:\n %v", stdout)
+
+ // Emit Remove event
+ evData := xsapiv1.SDKManagementMsg{
+ Timestamp: time.Now().String(),
+ Sdk: s.sdk,
+ Progress: 100,
+ Exited: true,
+ Code: 0,
+ Error: "",
+ }
+ if err := (*so).Emit(xsapiv1.EVTSDKRemove, evData); err != nil {
+ s.Log.Warningf("Cannot notify SDK remove end: %v", err)
+ }
return nil
}
diff --git a/lib/xdsserver/sdks.go b/lib/xdsserver/sdks.go
index 38e380d..9c10747 100644
--- a/lib/xdsserver/sdks.go
+++ b/lib/xdsserver/sdks.go
@@ -75,7 +75,8 @@ func NewSDKs(ctx *Context) (*SDKs, error) {
sdksList, err := ListCrossSDK(d, s.Log)
if err != nil {
- return &s, err
+ // allow to use XDS even if error on list
+ s.Log.Errorf("Cannot retrieve SDK list: %v", err)
}
s.LogSillyf("'%s' SDKs list: %v", d, sdksList)
@@ -309,9 +310,7 @@ func (s *SDKs) AbortInstall(id string, timeout int) (*xsapiv1.SDK, error) {
}
// Remove Used to uninstall a SDK
-func (s *SDKs) Remove(id string) (*xsapiv1.SDK, error) {
- s.mutex.Lock()
- defer s.mutex.Unlock()
+func (s *SDKs) Remove(id string, timeout int, sess *ClientSession) (*xsapiv1.SDK, error) {
cSdk, exist := s.Sdks[id]
if !exist {
@@ -323,7 +322,7 @@ func (s *SDKs) Remove(id string) (*xsapiv1.SDK, error) {
// Launch script to remove/uninstall
// (note that remove event will be generated by monitoring thread)
- if err := cSdk.Remove(); err != nil {
+ if err := cSdk.Remove(timeout, sess); err != nil {
return &cSdk.sdk, err
}
diff --git a/lib/xsapiv1/events.go b/lib/xsapiv1/events.go
index 84e62c1..1eb981c 100644
--- a/lib/xsapiv1/events.go
+++ b/lib/xsapiv1/events.go
@@ -53,6 +53,7 @@ const (
EVTFolderStateChange = EventTypePrefix + "folder-state-change" // type EventMsg with Data type xsapiv1.FolderConfig
EVTSDKInstall = EventTypePrefix + "sdk-install" // type EventMsg with Data type xsapiv1.SDKManagementMsg
EVTSDKRemove = EventTypePrefix + "sdk-remove" // type EventMsg with Data type xsapiv1.SDKManagementMsg
+ EVTSDKStateChange = EventTypePrefix + "sdk-state-change" // type EventMsg with Data type xsapiv1.SDK
)
// EVTAllList List of all supported events
@@ -61,6 +62,7 @@ var EVTAllList = []string{
EVTFolderStateChange,
EVTSDKInstall,
EVTSDKRemove,
+ EVTSDKStateChange,
}
// DecodeFolderConfig Helper to decode Data field type FolderConfig
diff --git a/scripts/sdks/agl/add b/scripts/sdks/agl/add
index dcb3833..e9a9fd1 100755
--- a/scripts/sdks/agl/add
+++ b/scripts/sdks/agl/add
@@ -76,7 +76,7 @@ if [ "$URL" != "" ]; then
TMPDIR=$(mktemp -d)
SDK_FILE=${TMPDIR}/$(basename ${URL})
echo "Downloading $(basename ${SDK_FILE}) ..."
- wget "$URL" -O "${SDK_FILE}" || exit 1
+ wget --no-check-certificate "$URL" -O "${SDK_FILE}" || exit 1
fi
# Retreive default install dir to extract version
diff --git a/scripts/sdks/agl/list b/scripts/sdks/agl/list
index dc748a4..af1d19f 100755
--- a/scripts/sdks/agl/list
+++ b/scripts/sdks/agl/list
@@ -1,4 +1,4 @@
-#! /usr/bin/env node
+#! /usr/bin/env nodejs
/**************************************************************************
* Copyright 2017 IoT.bzh
@@ -39,11 +39,12 @@ const opts = {
};
// Get list of available SDKs
-sdksDBFile = path.join(__dirname, "sdks_latest.json")
+sdksDBFile = path.join(envMap["SDK_ROOT_DIR"], "sdks_latest.json")
try {
// Fetch SDK Json database file when not existing
if (!fs.existsSync(sdksDBFile)) {
- var data = execSync(path.join(__dirname, 'update'), opts);
+
+ var data = execSync(path.join(__dirname, 'update ' + sdksDBFile), opts);
}
// Read SDK Json database file
var data = fs.readFileSync(sdksDBFile);
diff --git a/scripts/sdks/agl/remove b/scripts/sdks/agl/remove
index 99a4022..d0f30b1 100755
--- a/scripts/sdks/agl/remove
+++ b/scripts/sdks/agl/remove
@@ -29,4 +29,4 @@ if [ ! -d "${1}" ]; then
exit 1
fi
-rm -rf "${1}"
+rm -rf "${1}" && echo "SDK successfully removed."
diff --git a/scripts/sdks/agl/update b/scripts/sdks/agl/update
index e59c8fa..a222db9 100755
--- a/scripts/sdks/agl/update
+++ b/scripts/sdks/agl/update
@@ -19,4 +19,4 @@
. $(dirname "$0")/_env-init.sh
-wget -q --connect-timeout=30 ${SDK_DATABASE}
+wget -q --connect-timeout=30 ${SDK_DATABASE} -O $1