Change so that unlocks are always defered.
Issue-ID: NONRTRIC-814
Signed-off-by: elinuxhenrik <henrik.b.andersson@est.tech>
Change-Id: Ie1801e3b6d44c716282637ca8c48f3d8f6540d71
}
func (es *EventService) DeleteSubscriberIdSubscriptionsSubscriptionId(ctx echo.Context, subscriberId string, subscriptionId string) error {
- es.lock.Lock()
log.Debug(es.subscriptions)
if _, ok := es.subscriptions[subscriptionId]; ok {
- log.Debug("Deleting subscription", subscriptionId)
- delete(es.subscriptions, subscriptionId)
+ es.deleteSubscription(subscriptionId)
}
- es.lock.Unlock()
return ctx.NoContent(http.StatusNoContent)
}
+func (es *EventService) deleteSubscription(subscriptionId string) {
+ log.Debug("Deleting subscription", subscriptionId)
+ es.lock.Lock()
+ defer es.lock.Unlock()
+ delete(es.subscriptions, subscriptionId)
+}
+
func getEventSubscriptionFromRequest(ctx echo.Context) (eventsapi.EventSubscription, error) {
var subscription eventsapi.EventSubscription
err := ctx.Bind(&subscription)
func (es *EventService) addSubscription(subId string, subscription eventsapi.EventSubscription) {
es.lock.Lock()
+ defer es.lock.Unlock()
es.subscriptions[subId] = subscription
- es.lock.Unlock()
}
func (es *EventService) getSubscription(subId string) *eventsapi.EventSubscription {
}
func (im *InvokerManager) GetInvokerApiList(invokerId string) *invokerapi.APIList {
+ var apiList invokerapi.APIList = im.publishRegister.GetAllPublishedServices()
+ im.lock.Lock()
+ defer im.lock.Unlock()
invoker, ok := im.onboardedInvokers[invokerId]
if ok {
- var apiList invokerapi.APIList = im.publishRegister.GetAllPublishedServices()
- im.lock.Lock()
- defer im.lock.Unlock()
invoker.ApiList = &apiList
return &apiList
}
// Deletes an individual API Invoker.
func (im *InvokerManager) DeleteOnboardedInvokersOnboardingId(ctx echo.Context, onboardingId string) error {
- im.lock.Lock()
- delete(im.onboardedInvokers, onboardingId)
- im.lock.Unlock()
+ if _, ok := im.onboardedInvokers[onboardingId]; ok {
+ im.deleteInvoker(onboardingId)
+ }
go im.sendEvent(onboardingId, eventsapi.CAPIFEventAPIINVOKEROFFBOARDED)
return ctx.NoContent(http.StatusNoContent)
}
+func (im *InvokerManager) deleteInvoker(onboardingId string) {
+ im.lock.Lock()
+ defer im.lock.Unlock()
+ delete(im.onboardedInvokers, onboardingId)
+}
+
// Updates an individual API invoker details.
func (im *InvokerManager) PutOnboardedInvokersOnboardingId(ctx echo.Context, onboardingId string) error {
var invoker invokerapi.APIInvokerEnrolmentDetails
}
if _, ok := im.onboardedInvokers[onboardingId]; ok {
- im.lock.Lock()
- im.onboardedInvokers[*invoker.ApiInvokerId] = invoker
- im.lock.Unlock()
+ im.updateInvoker(invoker)
} else {
return sendCoreError(ctx, http.StatusNotFound, "The invoker to update has not been onboarded")
}
return nil
}
+func (im *InvokerManager) updateInvoker(invoker invokerapi.APIInvokerEnrolmentDetails) {
+ im.lock.Lock()
+ defer im.lock.Unlock()
+ im.onboardedInvokers[*invoker.ApiInvokerId] = invoker
+}
+
func (im *InvokerManager) ModifyIndApiInvokeEnrolment(ctx echo.Context, onboardingId string) error {
return ctx.NoContent(http.StatusNotImplemented)
}
log.Debug(pm.onboardedProviders)
if _, ok := pm.onboardedProviders[registrationId]; ok {
- log.Debug("Deleting provider", registrationId)
- pm.lock.Lock()
- delete(pm.onboardedProviders, registrationId)
- pm.lock.Unlock()
+ pm.deleteProvider(registrationId)
}
return ctx.NoContent(http.StatusNoContent)
}
+func (pm *ProviderManager) deleteProvider(registrationId string) {
+ log.Debug("Deleting provider", registrationId)
+ pm.lock.Lock()
+ defer pm.lock.Unlock()
+ delete(pm.onboardedProviders, registrationId)
+}
+
func (pm *ProviderManager) PutRegistrationsRegistrationId(ctx echo.Context, registrationId string) error {
pm.lock.Lock()
defer pm.lock.Unlock()