aboutsummaryrefslogtreecommitdiffstats
path: root/lib/xdsserver
diff options
context:
space:
mode:
Diffstat (limited to 'lib/xdsserver')
-rw-r--r--lib/xdsserver/apiv1-sdks.go9
-rw-r--r--lib/xdsserver/sdk.go54
-rw-r--r--lib/xdsserver/sdks.go9
3 files changed, 61 insertions, 11 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
}