summaryrefslogtreecommitdiffstats
path: root/lib/xdsserver/sdk.go
diff options
context:
space:
mode:
Diffstat (limited to 'lib/xdsserver/sdk.go')
-rw-r--r--lib/xdsserver/sdk.go83
1 files changed, 52 insertions, 31 deletions
diff --git a/lib/xdsserver/sdk.go b/lib/xdsserver/sdk.go
index d5b2b43..633fbee 100644
--- a/lib/xdsserver/sdk.go
+++ b/lib/xdsserver/sdk.go
@@ -267,12 +267,12 @@ func (s *CrossSDK) Install(file string, force bool, timeout int, args []string,
// IO socket can be nil when disconnected
so := s.sessions.IOSocketGet(e.Sid)
if so == nil {
- s.Log.Infof("%s not emitted: WS closed (sid:%s, msgid:%s)", xsapiv1.EVTSDKInstall, e.Sid, e.CmdID)
+ s.Log.Infof("%s not emitted: WS closed (sid:%s, msgid:%s)", xsapiv1.EVTSDKManagement, e.Sid, e.CmdID)
return
}
if s.LogLevelSilly {
- s.Log.Debugf("%s emitted - WS sid[4:] %s - id:%s - SDK ID:%s:", xsapiv1.EVTSDKInstall, e.Sid[4:], e.CmdID, sdkID[:16])
+ s.Log.Debugf("%s emitted - WS sid[4:] %s - id:%s - SDK ID:%s:", xsapiv1.EVTSDKManagement, e.Sid[4:], e.CmdID, sdkID[:16])
if stdout != "" {
s.Log.Debugf("STDOUT <<%v>>", strings.Replace(stdout, "\n", "\\n", -1))
}
@@ -287,9 +287,10 @@ func (s *CrossSDK) Install(file string, force bool, timeout int, args []string,
s.bufStderr += stderr
if len(s.bufStdout) > SizeBufStdout || len(s.bufStderr) > SizeBufStderr {
// Emit event
- err := (*so).Emit(xsapiv1.EVTSDKInstall, xsapiv1.SDKManagementMsg{
+ err := (*so).Emit(xsapiv1.EVTSDKManagement, xsapiv1.SDKManagementMsg{
CmdID: e.CmdID,
Timestamp: time.Now().String(),
+ Action: xsapiv1.SdkMgtActionInstall,
Sdk: s.sdk,
Progress: 0, // TODO add progress
Exited: false,
@@ -318,15 +319,16 @@ func (s *CrossSDK) Install(file string, force bool, timeout int, args []string,
// IO socket can be nil when disconnected
so := s.sessions.IOSocketGet(e.Sid)
if so == nil {
- s.Log.Infof("%s (exit) not emitted - WS closed (id:%s)", xsapiv1.EVTSDKInstall, e.CmdID)
+ s.Log.Infof("%s (exit) not emitted - WS closed (id:%s)", xsapiv1.EVTSDKManagement, e.CmdID)
return
}
// Emit event remaining data in bufStdout/err
if len(s.bufStderr) > 0 || len(s.bufStdout) > 0 {
- err := (*so).Emit(xsapiv1.EVTSDKInstall, xsapiv1.SDKManagementMsg{
+ err := (*so).Emit(xsapiv1.EVTSDKManagement, xsapiv1.SDKManagementMsg{
CmdID: e.CmdID,
Timestamp: time.Now().String(),
+ Action: xsapiv1.SdkMgtActionInstall,
Sdk: s.sdk,
Progress: 50, // TODO add progress
Exited: false,
@@ -377,9 +379,10 @@ func (s *CrossSDK) Install(file string, force bool, timeout int, args []string,
}
// Emit event
- errSoEmit := (*so).Emit(xsapiv1.EVTSDKInstall, xsapiv1.SDKManagementMsg{
+ errSoEmit := (*so).Emit(xsapiv1.EVTSDKManagement, xsapiv1.SDKManagementMsg{
CmdID: e.CmdID,
Timestamp: time.Now().String(),
+ Action: xsapiv1.SdkMgtActionInstall,
Sdk: s.sdk,
Progress: 100,
Exited: true,
@@ -387,7 +390,12 @@ func (s *CrossSDK) Install(file string, force bool, timeout int, args []string,
Error: emitErr,
})
if errSoEmit != nil {
- s.Log.Errorf("WS Emit : %v", errSoEmit)
+ s.Log.Errorf("WS Emit EVTSDKManagement : %v", errSoEmit)
+ }
+
+ errSoEmit = s.events.Emit(xsapiv1.EVTSDKStateChange, s.sdk, e.Sid)
+ if errSoEmit != nil {
+ s.Log.Errorf("WS Emit EVTSDKStateChange : %v", errSoEmit)
}
// Cleanup command for the next time
@@ -436,8 +444,8 @@ func (s *CrossSDK) Remove(timeout int, sess *ClientSession) error {
s.sdk.Status = xsapiv1.SdkStatusUninstalling
- // Emit Remove event
- if err := (*so).Emit(xsapiv1.EVTSDKStateChange, s.sdk); err != nil {
+ // Notify state change
+ if err := s.events.Emit(xsapiv1.EVTSDKStateChange, s.sdk, sess.ID); err != nil {
s.Log.Warningf("Cannot notify SDK remove: %v", err)
}
@@ -445,43 +453,56 @@ func (s *CrossSDK) Remove(timeout int, sess *ClientSession) error {
args := s.sdk.Path
s.Log.Infof("Uninstall SDK %s: script=%v args=%v", s.sdk.Name, script, args)
+ // Notify start removing
+ evData := xsapiv1.SDKManagementMsg{
+ Timestamp: time.Now().String(),
+ Action: xsapiv1.SdkMgtActionRemove,
+ Sdk: s.sdk,
+ Progress: 0,
+ Exited: false,
+ Code: 0,
+ Error: "",
+ }
+ if errEmit := (*so).Emit(xsapiv1.EVTSDKManagement, evData); errEmit != nil {
+ s.Log.Warningf("Cannot notify EVTSDKManagement end: %v", errEmit)
+ }
+
+ // Run command to remove SDK
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)
- }
-
- // Emit Remove event
- evData := xsapiv1.SDKManagementMsg{
+ // Emit end of removing process
+ evData = xsapiv1.SDKManagementMsg{
Timestamp: time.Now().String(),
+ Action: xsapiv1.SdkMgtActionRemove,
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)
+
+ // Update error code on error
+ if err != nil {
+ evData.Code = 1
+ evData.Error = err.Error()
+ }
+
+ if errEmit := (*so).Emit(xsapiv1.EVTSDKManagement, evData); errEmit != nil {
+ s.Log.Warningf("Cannot notify EVTSDKManagement end: %v", errEmit)
+ }
+
+ // Notify state change
+ if errEmit := s.events.Emit(xsapiv1.EVTSDKStateChange, s.sdk, sess.ID); errEmit != nil {
+ s.Log.Warningf("Cannot notify EVTSDKStateChange end: %v", errEmit)
}
+ if err != nil {
+ return fmt.Errorf("Error while uninstalling sdk: %v", err)
+ }
return nil
}