Impleted health check API for the RICDMS service.
Signed-off-by: subhash kumar singh <subh.singh@samsung.com>
Change-Id: I770499e6164b72864414c646d14d64f0ce9585b4
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
+ github.com/stretchr/objx v0.1.1 // indirect
go.mongodb.org/mongo-driver v1.8.3 // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
--- /dev/null
+//==================================================================================
+// Copyright (c) 2022 Samsung
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// This source code is part of the near-RT RIC (RAN Intelligent Controller)
+// platform project (RICP).
+//==================================================================================
+//
+
+package health
+
+import "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/models"
+
+var (
+ HEALTHY = "Service is running healthy"
+)
+
+type IHealthChecker interface {
+ GetStatus() *models.Status
+}
+
+type HealthChecker struct {
+}
+
+func NewHealthChecker() IHealthChecker {
+ return &HealthChecker{}
+}
+func (h *HealthChecker) GetStatus() *models.Status {
+ return &models.Status{
+ Status: &HEALTHY,
+ }
+}
"log"
"os"
+ ph "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/health"
"gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/restapi"
"gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/restapi/operations"
+ "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/restapi/operations/health"
+ "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/resthooks"
"gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/ricdms"
"github.com/go-openapi/loads"
+ "github.com/go-openapi/runtime/middleware"
)
func NewRestful() *Restful {
- r := &Restful{}
+ r := &Restful{
+ rh: resthooks.NewResthook(
+ ph.NewHealthChecker(),
+ ),
+ }
r.setupHandler()
return r
}
}
api := operations.NewRICDMSAPI(swaggerSpec)
+
+ api.HealthGetHealthCheckHandler = health.GetHealthCheckHandlerFunc(func(ghcp health.GetHealthCheckParams) middleware.Responder {
+ ricdms.Logger.Debug("==> HealthCheck API invoked.")
+ resp := r.rh.GetDMSHealth()
+ return resp
+ })
+
r.api = api
}
--- /dev/null
+//==================================================================================
+// Copyright (c) 2022 Samsung
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// This source code is part of the near-RT RIC (RAN Intelligent Controller)
+// platform project (RICP).
+//==================================================================================
+//
+
+package resthooks
+
+import (
+ ph "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/health"
+ "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/restapi/operations/health"
+ "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/ricdms"
+ "github.com/go-openapi/runtime/middleware"
+)
+
+func NewResthook(h ph.IHealthChecker) *Resthook {
+ return &Resthook{
+ HealthChecker: h,
+ }
+}
+
+func (rh *Resthook) GetDMSHealth() (resp middleware.Responder) {
+ ricdms.Logger.Debug("healthchecker : %v\n", rh.HealthChecker)
+ return health.NewGetHealthCheckOK().WithPayload(rh.HealthChecker.GetStatus())
+}
--- /dev/null
+//==================================================================================
+// Copyright (c) 2022 Samsung
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// This source code is part of the near-RT RIC (RAN Intelligent Controller)
+// platform project (RICP).
+//==================================================================================
+//
+package resthooks
+
+import (
+ "os"
+ "testing"
+
+ "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/health"
+ "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/models"
+ h "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/restapi/operations/health"
+ "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/ricdms"
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/mock"
+)
+
+var rh *Resthook
+var successStatus *models.Status
+
+func TestMain(m *testing.M) {
+
+ successStatus = &models.Status{
+ Status: &health.HEALTHY,
+ }
+ ricdms.Init()
+ rh = &Resthook{
+ HealthChecker: HealthCheckerMock{},
+ }
+ code := m.Run()
+ os.Exit(code)
+}
+
+func TestHealth(t *testing.T) {
+ resp := rh.GetDMSHealth()
+ switch resp.(type) {
+ case *h.GetHealthCheckOK:
+ assert.Equal(t, successStatus, resp.(*h.GetHealthCheckOK).Payload)
+
+ case *h.GetHealthCheckInternalServerError:
+ assert.Fail(t, "Internal Server generated: %v", resp)
+
+ default:
+ assert.Fail(t, "Unknown type of resp : %v", resp)
+ }
+}
+
+type HealthCheckerMock struct {
+ mock.Mock
+}
+
+func (h HealthCheckerMock) GetStatus() *models.Status {
+ return successStatus
+}
//
package resthooks
+import (
+ "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/health"
+)
+
type Resthook struct {
+ HealthChecker health.IHealthChecker
}