Added typeupdate and typeaccess
Issue-ID: NONRTRIC-814
Signed-off-by: shikha0203 <shivani.khare@est.tech>
Change-Id: I4d74454a88b5d1bb3d98375510211ddb69476e3d
diff --git a/capifcore/internal/invokermanagement/invokermanagement.go b/capifcore/internal/invokermanagement/invokermanagement.go
index c6f2db3..1fbe2f0 100644
--- a/capifcore/internal/invokermanagement/invokermanagement.go
+++ b/capifcore/internal/invokermanagement/invokermanagement.go
@@ -21,14 +21,12 @@
package invokermanagement
import (
- "errors"
"fmt"
"net/http"
"path"
"sync"
"oransc.org/nonrtric/capifcore/internal/eventsapi"
- publishapi "oransc.org/nonrtric/capifcore/internal/publishserviceapi"
"oransc.org/nonrtric/capifcore/internal/common29122"
invokerapi "oransc.org/nonrtric/capifcore/internal/invokermanagementapi"
@@ -214,20 +212,10 @@
if err := invoker.Validate(); err != nil {
return err
}
- if !im.areAPIsPublished(invoker.ApiList) {
- return errors.New("some APIs needed by invoker are not registered")
- }
return nil
}
-func (im *InvokerManager) areAPIsPublished(apis *invokerapi.APIList) bool {
- if apis == nil {
- return true
- }
- return im.publishRegister.AreAPIsPublished((*[]publishapi.ServiceAPIDescription)(apis))
-}
-
func (im *InvokerManager) sendEvent(invokerId string, eventType eventsapi.CAPIFEvent) {
invokerIds := []string{invokerId}
event := eventsapi.EventNotification{
diff --git a/capifcore/internal/publishservice/publishservice.go b/capifcore/internal/publishservice/publishservice.go
index ee3efef..bf79899 100644
--- a/capifcore/internal/publishservice/publishservice.go
+++ b/capifcore/internal/publishservice/publishservice.go
@@ -42,9 +42,6 @@
//go:generate mockery --name PublishRegister
type PublishRegister interface {
- // Checks if the provided APIs are published.
- // Returns true if all provided APIs have been published, false otherwise.
- AreAPIsPublished(serviceDescriptions *[]publishapi.ServiceAPIDescription) bool
// Checks if the provided API is published.
// Returns true if the provided API has been published, false otherwise.
IsAPIPublished(aefId, path string) bool
@@ -71,15 +68,6 @@
}
}
-func (ps *PublishService) AreAPIsPublished(serviceDescriptions *[]publishapi.ServiceAPIDescription) bool {
-
- if serviceDescriptions != nil {
- registeredApis := ps.getAllAefIds()
- return checkNewDescriptions(*serviceDescriptions, registeredApis)
- }
- return true
-}
-
func (ps *PublishService) getAllAefIds() []string {
ps.lock.Lock()
defer ps.lock.Unlock()
@@ -87,46 +75,12 @@
allIds := []string{}
for _, descriptions := range ps.publishedServices {
for _, description := range descriptions {
- allIds = append(allIds, getIdsFromDescription(description)...)
+ allIds = append(allIds, description.GetAefIds()...)
}
}
return allIds
}
-func getIdsFromDescription(description publishapi.ServiceAPIDescription) []string {
- allIds := []string{}
- if description.AefProfiles != nil {
- for _, aefProfile := range *description.AefProfiles {
- allIds = append(allIds, aefProfile.AefId)
- }
- }
- return allIds
-}
-
-func checkNewDescriptions(newDescriptions []publishapi.ServiceAPIDescription, registeredAefIds []string) bool {
- registered := true
- for _, newApi := range newDescriptions {
- if !checkProfiles(newApi.AefProfiles, registeredAefIds) {
- registered = false
- break
- }
- }
- return registered
-}
-
-func checkProfiles(newProfiles *[]publishapi.AefProfile, registeredAefIds []string) bool {
- allRegistered := true
- if newProfiles != nil {
- for _, profile := range *newProfiles {
- if !slices.Contains(registeredAefIds, profile.AefId) {
- allRegistered = false
- break
- }
- }
- }
- return allRegistered
-}
-
func (ps *PublishService) IsAPIPublished(aefId, path string) bool {
return slices.Contains(ps.getAllAefIds(), aefId)
}
@@ -181,8 +135,7 @@
}
}
- newId := "api_id_" + newServiceAPIDescription.ApiName
- newServiceAPIDescription.ApiId = &newId
+ newServiceAPIDescription.PrepareNewService()
shouldReturn, returnValue := ps.installHelmChart(newServiceAPIDescription, ctx)
if shouldReturn {
@@ -307,11 +260,11 @@
if err != nil {
return sendCoreError(ctx, http.StatusBadRequest, fmt.Sprintf(errMsg, err))
}
- ps.updateDescription(pos, apfId, &updatedServiceDescription, &publishedService)
err = ps.checkProfilesRegistered(apfId, *updatedServiceDescription.AefProfiles)
if err != nil {
return sendCoreError(ctx, http.StatusBadRequest, fmt.Sprintf(errMsg, err))
}
+ ps.updateDescription(pos, apfId, &updatedServiceDescription, &publishedService)
publishedService.AefProfiles = updatedServiceDescription.AefProfiles
ps.publishedServices[apfId][pos] = publishedService
err = ctx.JSON(http.StatusOK, publishedService)
diff --git a/capifcore/internal/publishservice/publishservice_test.go b/capifcore/internal/publishservice/publishservice_test.go
index 3c19204..b69b956 100644
--- a/capifcore/internal/publishservice/publishservice_test.go
+++ b/capifcore/internal/publishservice/publishservice_test.go
@@ -80,8 +80,6 @@
assert.Equal(t, newApiId, *resultService.ApiId)
assert.Equal(t, "http://example.com/"+apfId+"/service-apis/"+*resultService.ApiId, result.Recorder.Header().Get(echo.HeaderLocation))
newServiceDescription.ApiId = &newApiId
- wantedAPILIst := []publishapi.ServiceAPIDescription{newServiceDescription}
- assert.True(t, serviceUnderTest.AreAPIsPublished(&wantedAPILIst))
assert.True(t, serviceUnderTest.IsAPIPublished(aefId, apiName))
serviceRegisterMock.AssertCalled(t, "GetAefsForPublisher", apfId)
helmManagerMock.AssertCalled(t, "InstallHelmChart", namespace, repoName, chartName, releaseName)
diff --git a/capifcore/internal/publishserviceapi/typeaccess.go b/capifcore/internal/publishserviceapi/typeaccess.go
new file mode 100644
index 0000000..32c1a7a
--- /dev/null
+++ b/capifcore/internal/publishserviceapi/typeaccess.go
@@ -0,0 +1,30 @@
+// -
+//
+// ========================LICENSE_START=================================
+// O-RAN-SC
+// %%
+// Copyright (C) 2023: Nordix Foundation
+// %%
+// 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.
+// ========================LICENSE_END===================================
+package publishserviceapi
+
+func (sd ServiceAPIDescription) GetAefIds() []string {
+ allIds := []string{}
+ if sd.AefProfiles != nil {
+ for _, aefProfile := range *sd.AefProfiles {
+ allIds = append(allIds, aefProfile.AefId)
+ }
+ }
+ return allIds
+}
diff --git a/capifcore/internal/publishserviceapi/typeupdate.go b/capifcore/internal/publishserviceapi/typeupdate.go
new file mode 100644
index 0000000..98e059c
--- /dev/null
+++ b/capifcore/internal/publishserviceapi/typeupdate.go
@@ -0,0 +1,26 @@
+// -
+// ========================LICENSE_START=================================
+// O-RAN-SC
+// %%
+// Copyright (C) 2023: Nordix Foundation
+// %%
+// 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.
+// ========================LICENSE_END===================================
+//
+
+package publishserviceapi
+
+func (sd *ServiceAPIDescription) PrepareNewService() {
+ apiName := "api_id_" + sd.ApiName
+ sd.ApiId = &apiName
+}