diff options
author | 2022-02-07 13:44:29 +0000 | |
---|---|---|
committer | 2022-02-07 13:44:29 +0000 | |
commit | e1537e7c389950dd8ad845e46a9e7b647f427eba (patch) | |
tree | 91bbaabf716db8b691303b2500e36aa569a5156e /cps-service | |
parent | c70300200de2ccc2a8db8a5a905c46c73c50de75 (diff) | |
parent | c9af4eac4dc7f86bd3f33d923f9efe4a8523ed57 (diff) |
Merge "Refactor Delete Anchor functionality"
Diffstat (limited to 'cps-service')
7 files changed, 91 insertions, 78 deletions
diff --git a/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java b/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java index f455e47ef..d2482d50a 100644 --- a/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java +++ b/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation * Modifications Copyright (C) 2021 Pantheon.tech - * Modifications Copyright (C) 2021 Bell Canada + * Modifications Copyright (C) 2021-2022 Bell Canada * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,6 @@ package org.onap.cps.api; import java.time.OffsetDateTime; -import org.checkerframework.checker.nullness.qual.NonNull; import org.onap.cps.spi.FetchDescendantsOption; import org.onap.cps.spi.model.DataNode; @@ -40,8 +39,7 @@ public interface CpsDataService { * @param jsonData json data * @param observedTimestamp observedTimestamp */ - void saveData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String jsonData, - OffsetDateTime observedTimestamp); + void saveData(String dataspaceName, String anchorName, String jsonData, OffsetDateTime observedTimestamp); /** * Persists child data fragment under existing data node for the given anchor and dataspace. @@ -52,8 +50,8 @@ public interface CpsDataService { * @param jsonData json data * @param observedTimestamp observedTimestamp */ - void saveData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath, - @NonNull String jsonData, OffsetDateTime observedTimestamp); + void saveData(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData, + OffsetDateTime observedTimestamp); /** * Persists child data fragment representing one or more list elements under existing data node for the @@ -65,9 +63,8 @@ public interface CpsDataService { * @param jsonData json data representing list element(s) * @param observedTimestamp observedTimestamp */ - void saveListElements(@NonNull String dataspaceName, @NonNull String anchorName, - @NonNull String parentNodeXpath, - @NonNull String jsonData, OffsetDateTime observedTimestamp); + void saveListElements(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData, + OffsetDateTime observedTimestamp); /** * Retrieves datanode by XPath for given dataspace and anchor. @@ -79,8 +76,8 @@ public interface CpsDataService { * (recursively) as well * @return data node object */ - DataNode getDataNode(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String xpath, - @NonNull FetchDescendantsOption fetchDescendantsOption); + DataNode getDataNode(String dataspaceName, String anchorName, String xpath, + FetchDescendantsOption fetchDescendantsOption); /** * Updates data node for given dataspace and anchor using xpath to parent node. @@ -91,8 +88,8 @@ public interface CpsDataService { * @param jsonData json data * @param observedTimestamp observedTimestamp */ - void updateNodeLeaves(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath, - @NonNull String jsonData, OffsetDateTime observedTimestamp); + void updateNodeLeaves(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData, + OffsetDateTime observedTimestamp); /** * Replaces existing data node content including descendants. @@ -103,8 +100,8 @@ public interface CpsDataService { * @param jsonData json data * @param observedTimestamp observedTimestamp */ - void replaceNodeTree(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath, - @NonNull String jsonData, OffsetDateTime observedTimestamp); + void replaceNodeTree(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData, + OffsetDateTime observedTimestamp); /** * Replaces list content by removing all existing elements and inserting the given new elements as json @@ -116,8 +113,8 @@ public interface CpsDataService { * @param jsonData json data representing the new list elements * @param observedTimestamp observedTimestamp */ - void replaceListContent(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath, - @NonNull String jsonData, OffsetDateTime observedTimestamp); + void replaceListContent(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData, + OffsetDateTime observedTimestamp); /** * Deletes data node for given anchor and dataspace. @@ -127,8 +124,17 @@ public interface CpsDataService { * @param dataNodeXpath data node xpath * @param observedTimestamp observed timestamp */ - void deleteDataNode(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String dataNodeXpath, - OffsetDateTime observedTimestamp); + void deleteDataNode(String dataspaceName, String anchorName, String dataNodeXpath, + OffsetDateTime observedTimestamp); + + /** + * Deletes all data nodes for a given anchor in a dataspace. + * + * @param dataspaceName dataspace name + * @param anchorName anchor name + * @param observedTimestamp observed timestamp + */ + void deleteDataNodes(String dataspaceName, String anchorName, OffsetDateTime observedTimestamp); /** * Deletes a list or a list-element under given anchor and dataspace. @@ -138,8 +144,8 @@ public interface CpsDataService { * @param listElementXpath list element xpath * @param observedTimestamp observedTimestamp */ - void deleteListOrListElement(@NonNull String dataspaceName, @NonNull String anchorName, - @NonNull String listElementXpath, OffsetDateTime observedTimestamp); + void deleteListOrListElement(String dataspaceName, String anchorName, String listElementXpath, + OffsetDateTime observedTimestamp); /** * Updates leaves of DataNode for given dataspace and anchor using xpath, along with the leaves of each Child Data diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsAdminServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsAdminServiceImpl.java index d30a6571d..1013addbe 100755 --- a/cps-service/src/main/java/org/onap/cps/api/impl/CpsAdminServiceImpl.java +++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsAdminServiceImpl.java @@ -22,19 +22,24 @@ package org.onap.cps.api.impl; +import java.time.OffsetDateTime; import java.util.Collection; import java.util.stream.Collectors; +import lombok.AllArgsConstructor; import org.onap.cps.api.CpsAdminService; +import org.onap.cps.api.CpsDataService; import org.onap.cps.spi.CpsAdminPersistenceService; import org.onap.cps.spi.model.Anchor; -import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; @Component("CpsAdminServiceImpl") +@AllArgsConstructor(onConstructor = @__(@Lazy)) public class CpsAdminServiceImpl implements CpsAdminService { - @Autowired - private CpsAdminPersistenceService cpsAdminPersistenceService; + private final CpsAdminPersistenceService cpsAdminPersistenceService; + @Lazy + private final CpsDataService cpsDataService; @Override public void createDataspace(final String dataspaceName) { @@ -68,6 +73,7 @@ public class CpsAdminServiceImpl implements CpsAdminService { @Override public void deleteAnchor(final String dataspaceName, final String anchorName) { + cpsDataService.deleteDataNodes(dataspaceName, anchorName, OffsetDateTime.now()); cpsAdminPersistenceService.deleteAnchor(dataspaceName, anchorName); } diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java index a23bc95f3..e292bbe77 100755 --- a/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java +++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java @@ -24,6 +24,7 @@ package org.onap.cps.api.impl; import java.time.OffsetDateTime; import java.util.Collection; +import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.onap.cps.api.CpsAdminService; import org.onap.cps.api.CpsDataService; @@ -37,26 +38,19 @@ import org.onap.cps.spi.model.DataNodeBuilder; import org.onap.cps.utils.YangUtils; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service @Slf4j +@AllArgsConstructor public class CpsDataServiceImpl implements CpsDataService { private static final String ROOT_NODE_XPATH = "/"; - @Autowired - private CpsDataPersistenceService cpsDataPersistenceService; - - @Autowired - private CpsAdminService cpsAdminService; - - @Autowired - private YangTextSchemaSourceSetCache yangTextSchemaSourceSetCache; - - @Autowired - private NotificationService notificationService; + private final CpsDataPersistenceService cpsDataPersistenceService; + private final CpsAdminService cpsAdminService; + private final YangTextSchemaSourceSetCache yangTextSchemaSourceSetCache; + private final NotificationService notificationService; @Override public void saveData(final String dataspaceName, final String anchorName, final String jsonData, @@ -138,6 +132,12 @@ public class CpsDataServiceImpl implements CpsDataService { } @Override + public void deleteDataNodes(final String dataspaceName, final String anchorName, + final OffsetDateTime observedTimestamp) { + cpsDataPersistenceService.deleteDataNodes(dataspaceName, anchorName); + } + + @Override public void deleteListOrListElement(final String dataspaceName, final String anchorName, final String listNodeXpath, final OffsetDateTime observedTimestamp) { cpsDataPersistenceService.deleteListDataNode(dataspaceName, anchorName, listNodeXpath); diff --git a/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java b/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java index b8c472f27..fd658861c 100644 --- a/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java +++ b/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation. * Modifications Copyright (C) 2021 Pantheon.tech + * Modifications Copyright (C) 2022 Bell Canada * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +24,6 @@ package org.onap.cps.spi; import java.util.Collection; import java.util.Map; -import org.checkerframework.checker.nullness.qual.NonNull; import org.onap.cps.spi.model.DataNode; /* @@ -40,8 +40,7 @@ public interface CpsDataPersistenceService { * @param anchorName anchor name * @param dataNode data node */ - void storeDataNode(@NonNull String dataspaceName, @NonNull String anchorName, - @NonNull DataNode dataNode); + void storeDataNode(String dataspaceName, String anchorName, DataNode dataNode); /** * Add a child to a Fragment. @@ -51,8 +50,7 @@ public interface CpsDataPersistenceService { * @param parentXpath parent xpath * @param dataNode dataNode */ - void addChildDataNode(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentXpath, - @NonNull DataNode dataNode); + void addChildDataNode(String dataspaceName, String anchorName, String parentXpath, DataNode dataNode); /** * Adds list child elements to a Fragment. @@ -63,8 +61,8 @@ public interface CpsDataPersistenceService { * @param listElementsCollection collection of data nodes representing list elements */ - void addListElements(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath, - @NonNull Collection<DataNode> listElementsCollection); + void addListElements(String dataspaceName, String anchorName, String parentNodeXpath, + Collection<DataNode> listElementsCollection); /** * Retrieves datanode by XPath for given dataspace and anchor. @@ -76,8 +74,8 @@ public interface CpsDataPersistenceService { * (recursively) as well * @return data node object */ - DataNode getDataNode(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String xpath, - @NonNull FetchDescendantsOption fetchDescendantsOption); + DataNode getDataNode(String dataspaceName, String anchorName, String xpath, + FetchDescendantsOption fetchDescendantsOption); /** @@ -88,8 +86,7 @@ public interface CpsDataPersistenceService { * @param xpath xpath * @param leaves the leaves as a map where key is a leaf name and a value is a leaf value */ - void updateDataLeaves(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String xpath, - @NonNull Map<String, Object> leaves); + void updateDataLeaves(String dataspaceName, String anchorName, String xpath, Map<String, Object> leaves); /** * Replaces existing data node content including descendants. @@ -98,7 +95,7 @@ public interface CpsDataPersistenceService { * @param anchorName anchor name * @param dataNode data node */ - void replaceDataNodeTree(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull DataNode dataNode); + void replaceDataNodeTree(String dataspaceName, String anchorName, DataNode dataNode); /** * Replaces list content by removing all existing elements and inserting the given new elements @@ -109,8 +106,8 @@ public interface CpsDataPersistenceService { * @param parentNodeXpath parent node xpath * @param newListElements collection of data nodes representing the new list content */ - void replaceListContent(@NonNull String dataspaceName, @NonNull String anchorName, - @NonNull String parentNodeXpath, @NonNull Collection<DataNode> newListElements); + void replaceListContent(String dataspaceName, String anchorName, + String parentNodeXpath, Collection<DataNode> newListElements); /** * Deletes any dataNode, yang container or yang list or yang list element. @@ -119,8 +116,15 @@ public interface CpsDataPersistenceService { * @param anchorName anchor name * @param targetXpath xpath to list or list element (include [@key=value] to delete a single list element) */ - void deleteDataNode(@NonNull String dataspaceName, @NonNull String anchorName, - @NonNull String targetXpath); + void deleteDataNode(String dataspaceName, String anchorName, String targetXpath); + + /** + * Deletes all dataNodes in a given anchor. + * + * @param dataspaceName dataspace name + * @param anchorName anchor name + */ + void deleteDataNodes(String dataspaceName, String anchorName); /** * Deletes existing a single list element or the whole list. @@ -129,8 +133,7 @@ public interface CpsDataPersistenceService { * @param anchorName anchor name * @param targetXpath xpath to list or list element (include [@key=value] to delete a single list element) */ - void deleteListDataNode(@NonNull String dataspaceName, @NonNull String anchorName, - @NonNull String targetXpath); + void deleteListDataNode(String dataspaceName, String anchorName, String targetXpath); /** * Get a datanode by cps path. @@ -142,7 +145,7 @@ public interface CpsDataPersistenceService { * included in the output * @return the data nodes found i.e. 0 or more data nodes */ - Collection<DataNode> queryDataNodes(@NonNull String dataspaceName, @NonNull String anchorName, - @NonNull String cpsPath, @NonNull FetchDescendantsOption fetchDescendantsOption); + Collection<DataNode> queryDataNodes(String dataspaceName, String anchorName, + String cpsPath, FetchDescendantsOption fetchDescendantsOption); } diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy index fe6e46086..bb122d1ae 100755 --- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy @@ -22,17 +22,16 @@ package org.onap.cps.api.impl +import org.onap.cps.api.CpsDataService import org.onap.cps.spi.CpsAdminPersistenceService import org.onap.cps.spi.model.Anchor import spock.lang.Specification +import java.time.OffsetDateTime class CpsAdminServiceImplSpec extends Specification { def mockCpsAdminPersistenceService = Mock(CpsAdminPersistenceService) - def objectUnderTest = new CpsAdminServiceImpl() - - def setup() { - objectUnderTest.cpsAdminPersistenceService = mockCpsAdminPersistenceService - } + def mockCpsDataService = Mock(CpsDataService) + def objectUnderTest = new CpsAdminServiceImpl(mockCpsAdminPersistenceService, mockCpsDataService) def 'Create dataspace method invokes persistence service.'() { when: 'create dataspace method is invoked' @@ -75,7 +74,9 @@ class CpsAdminServiceImplSpec extends Specification { def 'Delete anchor.'() { when: 'delete anchor is invoked' objectUnderTest.deleteAnchor('someDataspace','someAnchor') - then: 'associated persistence service method is invoked with same parameters' + then: 'delete data nodes is invoked on the data service with expected parameters' + 1 * mockCpsDataService.deleteDataNodes('someDataspace','someAnchor', _ as OffsetDateTime ) + and: 'the persistence service method is invoked with same parameters to delete anchor' 1 * mockCpsAdminPersistenceService.deleteAnchor('someDataspace','someAnchor') } diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy index a302eb5e7..56b0e2d53 100644 --- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy @@ -44,14 +44,8 @@ class CpsDataServiceImplSpec extends Specification { def mockYangTextSchemaSourceSetCache = Mock(YangTextSchemaSourceSetCache) def mockNotificationService = Mock(NotificationService) - def objectUnderTest = new CpsDataServiceImpl() - - def setup() { - objectUnderTest.cpsDataPersistenceService = mockCpsDataPersistenceService - objectUnderTest.cpsAdminService = mockCpsAdminService - objectUnderTest.yangTextSchemaSourceSetCache = mockYangTextSchemaSourceSetCache - objectUnderTest.notificationService = mockNotificationService - } + def objectUnderTest = new CpsDataServiceImpl(mockCpsDataPersistenceService, mockCpsAdminService, + mockYangTextSchemaSourceSetCache, mockNotificationService) def dataspaceName = 'some dataspace' def anchorName = 'some anchor' @@ -237,6 +231,15 @@ class CpsDataServiceImplSpec extends Specification { 1 * mockNotificationService.processDataUpdatedEvent(dataspaceName, anchorName, observedTimestamp, '/data-node', Operation.DELETE) } + def 'Delete all data nodes for a given anchor and dataspace.'() { + given: 'schema set for given anchor and dataspace references test tree model' + setupSchemaSetMocks('test-tree.yang') + when: 'delete data node method is invoked with correct parameters' + objectUnderTest.deleteDataNodes(dataspaceName, anchorName, observedTimestamp) + then: 'the persistence service method is invoked with the correct parameters' + 1 * mockCpsDataPersistenceService.deleteDataNodes(dataspaceName, anchorName) + } + def setupSchemaSetMocks(String... yangResources) { def anchor = Anchor.builder().name(anchorName).schemaSetName(schemaSetName).build() mockCpsAdminService.getAnchor(dataspaceName, anchorName) >> anchor diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/E2ENetworkSliceSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/E2ENetworkSliceSpec.groovy index d18bcf55e..52389522f 100755 --- a/cps-service/src/test/groovy/org/onap/cps/api/impl/E2ENetworkSliceSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/E2ENetworkSliceSpec.groovy @@ -37,23 +37,17 @@ class E2ENetworkSliceSpec extends Specification { def mockDataStoreService = Mock(CpsDataPersistenceService)
def mockCpsAdminService = Mock(CpsAdminService)
def mockNotificationService = Mock(NotificationService)
- def cpsDataServiceImpl = new CpsDataServiceImpl()
def mockYangTextSchemaSourceSetCache = Mock(YangTextSchemaSourceSetCache)
def cpsModuleServiceImpl = new CpsModuleServiceImpl(mockModuleStoreService,
mockYangTextSchemaSourceSetCache,mockCpsAdminService )
+ def cpsDataServiceImpl = new CpsDataServiceImpl(mockDataStoreService, mockCpsAdminService,
+ mockYangTextSchemaSourceSetCache, mockNotificationService)
def dataspaceName = 'someDataspace'
def anchorName = 'someAnchor'
def schemaSetName = 'someSchemaSet'
def noTimestamp = null
- def setup() {
- cpsDataServiceImpl.cpsDataPersistenceService = mockDataStoreService
- cpsDataServiceImpl.cpsAdminService = mockCpsAdminService
- cpsDataServiceImpl.yangTextSchemaSourceSetCache = mockYangTextSchemaSourceSetCache
- cpsDataServiceImpl.notificationService = mockNotificationService
- }
-
def 'E2E model can be parsed by CPS.'() {
given: 'Valid yang resource as name-to-content map'
def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap(
|