From: naman.gupta Date: Thu, 5 May 2022 10:29:51 +0000 (+0530) Subject: Get All Policy Type Instance X-Git-Tag: 2.5.2~3 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=05a0f585da0bbf0c931d5667692807c512bb3238;p=ric-plt%2Fa1.git Get All Policy Type Instance Api for Get All Policy Type Instance Signed-off-by: naman.gupta Issue-ID: RIC-831 Change-Id: I649dd94059263244645e7a8236ad058c3f0ef26e --- diff --git a/a1-go/pkg/restful/restful.go b/a1-go/pkg/restful/restful.go index deb2470..28efaaa 100644 --- a/a1-go/pkg/restful/restful.go +++ b/a1-go/pkg/restful/restful.go @@ -95,6 +95,11 @@ func (r *Restful) setupHandler() *operations.A1API { return a1_mediator.NewA1ControllerGetPolicyInstanceServiceUnavailable }) + api.A1MediatorA1ControllerGetAllInstancesForTypeHandler = a1_mediator.A1ControllerGetAllInstancesForTypeHandlerFunc(func(params a1_mediator.A1ControllerGetAllInstancesForTypeParams) middleware.Responder { + a1.Logger.Debug("handler for get all policy instance") + return a1_mediator.NewA1ControllerGetPolicyInstanceOK().WithPayload(r.rh.GetAllPolicyInstance(models.PolicyTypeID(params.PolicyTypeID))) + }) + return api } diff --git a/a1-go/pkg/resthooks/resthooks.go b/a1-go/pkg/resthooks/resthooks.go index c09fb14..ea02562 100644 --- a/a1-go/pkg/resthooks/resthooks.go +++ b/a1-go/pkg/resthooks/resthooks.go @@ -376,3 +376,27 @@ func (rh *Resthook) GetPolicyInstance(policyTypeId models.PolicyTypeID, policyIn valStr := fmt.Sprint(instanceMap[instancekey]) return valStr, nil } + +func (rh *Resthook) GetAllPolicyInstance(policyTypeId models.PolicyTypeID) []models.PolicyInstanceID { + a1.Logger.Debug("GetAllPolicyInstance") + var policyTypeInstances []models.PolicyInstanceID + + keys, err := rh.db.GetAll("A1m_ns") + + if err != nil { + a1.Logger.Error("error in retrieving policy. err: %v", err) + return policyTypeInstances + } + a1.Logger.Debug("keys : %+v", keys) + typekey := a1InstancePrefix + strconv.FormatInt((int64(policyTypeId)), 10) + "." + for _, key := range keys { + if strings.HasPrefix(strings.TrimLeft(key, " "), typekey) { + pti := strings.Split(strings.Trim(key, " "), typekey)[1] + a1.Logger.Debug("pti %+v", pti) + policyTypeInstances = append(policyTypeInstances, models.PolicyInstanceID(pti)) + } + } + + a1.Logger.Debug("return : %+v", policyTypeInstances) + return policyTypeInstances +} diff --git a/a1-go/pkg/resthooks/resthooks_test.go b/a1-go/pkg/resthooks/resthooks_test.go index 50a7fe2..98d4f8c 100644 --- a/a1-go/pkg/resthooks/resthooks_test.go +++ b/a1-go/pkg/resthooks/resthooks_test.go @@ -39,6 +39,8 @@ func TestMain(m *testing.M) { sdlInst = new(SdlMock) sdlInst.On("GetAll", "A1m_ns").Return([]string{"a1.policy_instance.1006001.qos", + "a1.policy_instance.20005.123456", + "a1.policy_instance.20005.234567", "a1.policy_type.1006001", "a1.policy_type.20000", "a1.policy_inst_metadata.1006001.qos", @@ -161,6 +163,13 @@ func TestGetPolicyInstance(t *testing.T) { sdlInst.AssertExpectations(t) } +func TestGetAllPolicyIntances(t *testing.T) { + var policyTypeId models.PolicyTypeID + policyTypeId = 20005 + resp := rh.GetAllPolicyInstance(policyTypeId) + assert.Equal(t, 2, len(resp)) +} + type SdlMock struct { mock.Mock }