blob: 3046559c366a8728a39c51b20606f9960252bd63 [file] [log] [blame]
subhash kumar singhcd6cc6a2022-08-23 10:26:13 +00001//==================================================================================
2// Copyright (c) 2022 Samsung
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16// This source code is part of the near-RT RIC (RAN Intelligent Controller)
17// platform project (RICP).
18//==================================================================================
19//
20
21package health
22
subhash kumar singhc1e43742022-11-16 18:02:21 +000023import (
24 "fmt"
25 "net/http"
26
27 "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/models"
28 "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/ricdms"
29)
subhash kumar singhcd6cc6a2022-08-23 10:26:13 +000030
31var (
32 HEALTHY = "Service is running healthy"
33)
34
35type IHealthChecker interface {
36 GetStatus() *models.Status
subhash kumar singhc1e43742022-11-16 18:02:21 +000037 GetxAppStatus(appName, namespace string) *models.Status
subhash kumar singhcd6cc6a2022-08-23 10:26:13 +000038}
39
40type HealthChecker struct {
41}
42
43func NewHealthChecker() IHealthChecker {
44 return &HealthChecker{}
45}
46func (h *HealthChecker) GetStatus() *models.Status {
47 return &models.Status{
48 Status: &HEALTHY,
49 }
50}
subhash kumar singhc1e43742022-11-16 18:02:21 +000051
52func (h *HealthChecker) GetxAppStatus(appName, namespace string) *models.Status {
53 resp, err := http.Get(fmt.Sprintf(ricdms.Config.GETxAPPHealthURL, appName, namespace))
54 if err != nil {
55 ricdms.Logger.Error("Received error while fetching health info: %v", err)
56 return nil
57 }
58
59 if resp.StatusCode != http.StatusOK {
60 ricdms.Logger.Error("xApp is not healthy (http status=%s)", resp.Status)
61 return nil
62 }
63
64 return &models.Status{
65 Status: &HEALTHY,
66 }
67}