- remove register/remove service to mdns
authorjw_wonny.cha <jw_wonny.cha@samsung.com>
Thu, 28 Mar 2019 12:35:02 +0000 (21:35 +0900)
committerjw_wonny.cha <jw_wonny.cha@samsung.com>
Thu, 28 Mar 2019 12:35:02 +0000 (21:35 +0900)
- add notification Target ( local / remote)

src/servicemgr/service_execution.go

index 1c7e400..b0a6e24 100644 (file)
@@ -5,6 +5,8 @@ import (
        "log"
        "os"
        "os/exec"
+       "strconv"
+       "strings"
 )
 
 // Service for service that execute by self
@@ -24,8 +26,6 @@ func (p Service) execute() (err error) {
        }
        log.Println("Just ran subprocess ", pid)
 
-       p.registerService()
-
        executeCh := make(chan error)
 
        go func() {
@@ -36,35 +36,21 @@ func (p Service) execute() (err error) {
 
        p.notifyServiceStatus(status)
 
-       DeleteServiceMap(p.serviceID)
-       p.removeService()
-
        return nil
 }
 
 func (p Service) setService() (cmd *exec.Cmd, pid int, err error) {
-       binary, err := exec.LookPath(p.serviceName)
-       if err != nil {
-               return
-       }
-
-       cmd, _ = GetCmd(p.serviceID)
-
        if len(p.paramStr) == 0 {
-               cmd = exec.Command(binary)
+               cmd = exec.Command(p.serviceName)
        } else {
-               cmd = exec.Command(binary, p.paramStr...)
-       }
-
-       setErr := SetCmd(p.serviceID, cmd)
-       if setErr != nil {
-               log.Println(setErr.Error())
+               cmd = exec.Command(p.serviceName, p.paramStr...)
        }
 
        cmd.Stdout = os.Stdout
 
        err = cmd.Start()
        if err != nil {
+               log.Println(err.Error())
                return
        }
 
@@ -73,37 +59,9 @@ func (p Service) setService() (cmd *exec.Cmd, pid int, err error) {
        return
 }
 
-func (p Service) registerService() {
-       registerCh := make(chan error)
-
-       appName, err := GetAppName(p.serviceID)
-       if err != nil {
-               log.Println("[Fail] GetAppName is Failed")
-       }
-
-       go RegisterService(appName, p.serviceID, p.serviceName, ConstServiceStatusStarted, registerCh)
-       if err := <-registerCh; err == nil {
-               log.Println("[Success] Service Register is Success")
-       } else {
-               log.Println("[Fail] " + err.Error())
-       }
-}
-
-func (p Service) removeService() {
-       err := RemoveService(p.serviceID)
-       if err == nil {
-               log.Println("[Success] Service Unregister is Success")
-       } else {
-               log.Println("[Fail] " + err.Error())
-       }
-}
-
 func (p Service) waitService(executeCh <-chan error) (status string) {
        e := <-executeCh
 
-       // ctlChan, _ := GetCtlChan(p.serviceID)
-       // ctlChan <- true
-
        status = ConstServiceStatusFinished
 
        if e != nil {
@@ -121,18 +79,20 @@ func (p Service) waitService(executeCh <-chan error) (status string) {
 }
 
 func (p Service) notifyServiceStatus(status string) (err error) {
-       var statusNotificationRequest map[string]interface{}
-
-       statusNotificationRequest = make(map[string]interface{})
+       statusNotificationRequest := make(map[string]interface{})
        statusNotificationRequest["ServiceID"] = p.serviceID
        statusNotificationRequest["Status"] = status
 
        reqbytes, _ := json.Marshal(statusNotificationRequest)
-       // @TODO TargetURL needs to be declared
-       // err =
-       SendPostJSONMsg(p.notificationTargetURL, reqbytes)
-       // if err != nil {
-       //      log.Println(err.Error())
-       // }
+
+       if strings.Compare(p.notificationTargetURL, ConstLocalTarget) == 0 {
+
+       } else {
+               targetURL := p.notificationTargetURL + ConstServiceStatusNotiURI + strconv.FormatUint(p.serviceID, 10)
+               _, err = sendPostJSONMsg(targetURL, reqbytes)
+               if err != nil {
+                       log.Println(err.Error())
+               }
+       }
        return
 }