Use the passed namespace while installing chart
[ric-plt/ricdms.git] / pkg / health / health.go
index d007da4..3046559 100644 (file)
 
 package health
 
-import "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/models"
+import (
+       "fmt"
+       "net/http"
+
+       "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/models"
+       "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/ricdms"
+)
 
 var (
        HEALTHY = "Service is running healthy"
@@ -28,6 +34,7 @@ var (
 
 type IHealthChecker interface {
        GetStatus() *models.Status
+       GetxAppStatus(appName, namespace string) *models.Status
 }
 
 type HealthChecker struct {
@@ -41,3 +48,20 @@ func (h *HealthChecker) GetStatus() *models.Status {
                Status: &HEALTHY,
        }
 }
+
+func (h *HealthChecker) GetxAppStatus(appName, namespace string) *models.Status {
+       resp, err := http.Get(fmt.Sprintf(ricdms.Config.GETxAPPHealthURL, appName, namespace))
+       if err != nil {
+               ricdms.Logger.Error("Received error while fetching health info: %v", err)
+               return nil
+       }
+
+       if resp.StatusCode != http.StatusOK {
+               ricdms.Logger.Error("xApp is not healthy (http status=%s)", resp.Status)
+               return nil
+       }
+
+       return &models.Status{
+               Status: &HEALTHY,
+       }
+}