import java.util.List;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
-import org.onap.cps.api.CpsAdminService;
+import org.onap.cps.api.CpsAnchorService;
import org.onap.cps.api.CpsDataService;
import org.onap.cps.api.CpsModuleService;
import org.onap.cps.ncmp.api.impl.utils.YangDataConverter;
public class InventoryPersistenceImpl extends NcmpPersistenceImpl implements InventoryPersistence {
private final CpsModuleService cpsModuleService;
- private final CpsAdminService cpsAdminService;
+ private final CpsAnchorService cpsAnchorService;
private final CpsValidator cpsValidator;
/**
* @param cpsDataService cps data service instance
* @param cpsModuleService cps module service instance
* @param cpsValidator cps validation service instance
- * @param cpsAdminService cps admin service instance
+ * @param cpsAnchorService cps anchor service instance
*/
public InventoryPersistenceImpl(final JsonObjectMapper jsonObjectMapper, final CpsDataService cpsDataService,
final CpsModuleService cpsModuleService, final CpsValidator cpsValidator,
- final CpsAdminService cpsAdminService) {
+ final CpsAnchorService cpsAnchorService) {
super(jsonObjectMapper, cpsDataService, cpsModuleService, cpsValidator);
this.cpsModuleService = cpsModuleService;
- this.cpsAdminService = cpsAdminService;
+ this.cpsAnchorService = cpsAnchorService;
this.cpsValidator = cpsValidator;
}
@Override
public Collection<String> getCmHandleIdsWithGivenModules(final Collection<String> moduleNamesForQuery) {
- return cpsAdminService.queryAnchorNames(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, moduleNamesForQuery);
+ return cpsAnchorService.queryAnchorNames(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, moduleNamesForQuery);
}
private static String createCmHandleXPath(final String cmHandleId) {
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
-import org.onap.cps.api.CpsAdminService;
+import org.onap.cps.api.CpsAnchorService;
import org.onap.cps.api.CpsDataService;
import org.onap.cps.api.CpsModuleService;
import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueries;
private final DmiModelOperations dmiModelOperations;
private final CpsModuleService cpsModuleService;
- private final CpsAdminService cpsAdminService;
private final CmHandleQueries cmHandleQueries;
private final CpsDataService cpsDataService;
+ private final CpsAnchorService cpsAnchorService;
private final JsonObjectMapper jsonObjectMapper;
private final Map<String, Collection<ModuleReference>> moduleSetTagCache;
private static final Map<String, String> NO_NEW_MODULES = Collections.emptyMap();
}
}
if (!inUpgrade) {
- cpsAdminService.createAnchor(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleId, cmHandleId);
+ cpsAnchorService.createAnchor(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleId, cmHandleId);
}
setCmHandleModuleSetTag(yangModelCmHandle, moduleSetTag);
}
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
-import org.onap.cps.api.CpsAdminService;
+import org.onap.cps.api.CpsAnchorService;
import org.onap.cps.api.CpsDataService;
+import org.onap.cps.api.CpsDataspaceService;
import org.onap.cps.api.CpsModuleService;
import org.onap.cps.ncmp.api.impl.exception.NcmpStartUpException;
import org.onap.cps.spi.CascadeDeleteAllowed;
@RequiredArgsConstructor
abstract class AbstractModelLoader implements ModelLoader {
- private final CpsAdminService cpsAdminService;
+ private final CpsDataspaceService cpsDataspaceService;
private final CpsModuleService cpsModuleService;
private final CpsDataService cpsDataService;
+ private final CpsAnchorService cpsAnchorService;
private static final int EXIT_CODE_ON_ERROR = 1;
void waitUntilDataspaceIsAvailable(final String dataspaceName) {
log.info("Model Loader start-up, waiting for database to be ready");
int attemptCount = 0;
- while (cpsAdminService.getDataspace(dataspaceName) == null) {
+ while (cpsDataspaceService.getDataspace(dataspaceName) == null) {
if (attemptCount < maximumAttemptCount) {
try {
Thread.sleep(attemptCount * retryTimeMs);
void createAnchor(final String dataspaceName, final String schemaSetName, final String anchorName) {
try {
- cpsAdminService.createAnchor(dataspaceName, schemaSetName, anchorName);
+ cpsAnchorService.createAnchor(dataspaceName, schemaSetName, anchorName);
} catch (final AlreadyDefinedException alreadyDefinedException) {
log.warn("Creating new anchor failed as anchor already exists");
} catch (final Exception exception) {
void updateAnchorSchemaSet(final String dataspaceName, final String anchorName, final String schemaSetName) {
try {
- cpsAdminService.updateAnchorSchemaSet(dataspaceName, anchorName, schemaSetName);
+ cpsAnchorService.updateAnchorSchemaSet(dataspaceName, anchorName, schemaSetName);
} catch (final Exception exception) {
log.error("Updating schema set failed: {}", exception.getMessage());
throw new NcmpStartUpException("Updating schema set failed", exception.getMessage());
import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DATASPACE_NAME;
import lombok.extern.slf4j.Slf4j;
-import org.onap.cps.api.CpsAdminService;
+import org.onap.cps.api.CpsAnchorService;
import org.onap.cps.api.CpsDataService;
+import org.onap.cps.api.CpsDataspaceService;
import org.onap.cps.api.CpsModuleService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
- public CmDataSubscriptionModelLoader(final CpsAdminService cpsAdminService,
+ public CmDataSubscriptionModelLoader(final CpsDataspaceService cpsDataspaceService,
final CpsModuleService cpsModuleService,
- final CpsDataService cpsDataService) {
- super(cpsAdminService, cpsModuleService, cpsDataService);
+ final CpsDataService cpsDataService,
+ final CpsAnchorService cpsAnchorService) {
+ super(cpsDataspaceService, cpsModuleService, cpsDataService, cpsAnchorService);
}
@Value("${ncmp.model-loader.subscription:true}")
import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_ANCHOR;
import lombok.extern.slf4j.Slf4j;
-import org.onap.cps.api.CpsAdminService;
+import org.onap.cps.api.CpsAnchorService;
import org.onap.cps.api.CpsDataService;
+import org.onap.cps.api.CpsDataspaceService;
import org.onap.cps.api.CpsModuleService;
import org.springframework.stereotype.Service;
private static final String NEW_MODEL_FILE_NAME = "dmi-registry@2023-11-27.yang";
private static final String NEW_SCHEMA_SET_NAME = "dmi-registry-2023-11-27";
- public InventoryModelLoader(final CpsAdminService cpsAdminService,
+ public InventoryModelLoader(final CpsDataspaceService cpsDataspaceService,
final CpsModuleService cpsModuleService,
- final CpsDataService cpsDataService) {
- super(cpsAdminService, cpsModuleService, cpsDataService);
+ final CpsDataService cpsDataService,
+ final CpsAnchorService cpsAnchorService) {
+ super(cpsDataspaceService, cpsModuleService, cpsDataService, cpsAnchorService);
}
@Override
}
and: 'state handler is invoked with the expected parameters'
1 * mockLcmEventsCmHandleStateHandler.initiateStateAdvised(_) >> {
- args ->
- {
- def cmHandleStatePerCmHandle = (args[0] as List)
- cmHandleStatePerCmHandle.each {
- assert (it.id == 'cmhandle' && it.dmiServiceName == 'my-server')
- }
+ args -> {
+ def yangModelCmHandles = args[0]
+ assert yangModelCmHandles.id == ['cmhandle']
+ assert yangModelCmHandles.dmiServiceName == ['my-server']
}
}
where:
package org.onap.cps.ncmp.api.impl.inventory
+import org.onap.cps.api.CpsAnchorService
+
import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME
import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DATASPACE_NAME
import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_ANCHOR
import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
import com.fasterxml.jackson.databind.ObjectMapper
-import org.onap.cps.api.CpsAdminService
import org.onap.cps.api.CpsDataService
import org.onap.cps.api.CpsModuleService
-import org.onap.cps.ncmp.api.impl.inventory.CmHandleState
-import org.onap.cps.ncmp.api.impl.inventory.CompositeState
-import org.onap.cps.ncmp.api.impl.inventory.InventoryPersistenceImpl
import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
import org.onap.cps.spi.CascadeDeleteAllowed
import org.onap.cps.spi.FetchDescendantsOption
def mockCpsModuleService = Mock(CpsModuleService)
- def mockCpsAdminService = Mock(CpsAdminService)
+ def mockCpsAnchorService = Mock(CpsAnchorService)
def mockCpsValidator = Mock(CpsValidator)
def objectUnderTest = new InventoryPersistenceImpl(spiedJsonObjectMapper, mockCpsDataService, mockCpsModuleService,
- mockCpsValidator, mockCpsAdminService)
+ mockCpsValidator, mockCpsAnchorService)
def formattedDateAndTime = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
.format(OffsetDateTime.of(2022, 12, 31, 20, 30, 40, 1, ZoneOffset.UTC))
when: 'the method to get cm handles is called'
objectUnderTest.getCmHandleIdsWithGivenModules(['sample-module-name'])
then: 'the admin persistence service method to query anchors is invoked once with the same parameter'
- 1 * mockCpsAdminService.queryAnchorNames(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, ['sample-module-name'])
+ 1 * mockCpsAnchorService.queryAnchorNames(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, ['sample-module-name'])
}
def 'Replace list content'() {
package org.onap.cps.ncmp.api.impl.inventory.sync
+import org.onap.cps.api.CpsAnchorService
+
import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME
import static org.onap.cps.ncmp.api.impl.inventory.LockReasonCategory.MODULE_UPGRADE
import org.onap.cps.ncmp.api.impl.inventory.CmHandleState
import org.onap.cps.spi.FetchDescendantsOption
import org.onap.cps.spi.model.DataNode
-import org.onap.cps.api.CpsAdminService
import org.onap.cps.api.CpsDataService
import org.onap.cps.api.CpsModuleService
import org.onap.cps.spi.model.DataNodeBuilder
def mockCpsModuleService = Mock(CpsModuleService)
def mockDmiModelOperations = Mock(DmiModelOperations)
- def mockCpsAdminService = Mock(CpsAdminService)
+ def mockCpsAnchorService = Mock(CpsAnchorService)
def mockCmHandleQueries = Mock(CmHandleQueries)
def mockCpsDataService = Mock(CpsDataService)
def mockJsonObjectMapper = Mock(JsonObjectMapper)
def mockModuleSetTagCache = [:]
- def objectUnderTest = new ModuleSyncService(mockDmiModelOperations, mockCpsModuleService, mockCpsAdminService,
- mockCmHandleQueries, mockCpsDataService, mockJsonObjectMapper, mockModuleSetTagCache)
+ def objectUnderTest = new ModuleSyncService(mockDmiModelOperations, mockCpsModuleService,
+ mockCmHandleQueries, mockCpsDataService, mockCpsAnchorService, mockJsonObjectMapper, mockModuleSetTagCache)
def expectedDataspaceName = NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME
def static cmHandleWithModuleSetTag = new DataNodeBuilder().withXpath("//cm-handles[@module-set-tag='tag-1'][@id='otherId']").withAnchor('otherId').build()
then: 'create schema set from module is invoked with correct parameters'
1 * mockCpsModuleService.createSchemaSetFromModules(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, 'ch-1', newModuleNameContentToMap, moduleReferences)
and: 'anchor is created with the correct parameters'
- 1 * mockCpsAdminService.createAnchor(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, 'ch-1', 'ch-1')
+ 1 * mockCpsAnchorService.createAnchor(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, 'ch-1', 'ch-1')
where: 'the following parameters are used'
scenario | existingModuleResourcesInCps | identifiedNewModuleReferences | newModuleNameContentToMap | moduleSetTag
'one new module' | [['module2': '2'], ['module3': '3']] | [['module1': '1']] | [module1: 'some yang source'] | ''
and: 'create schema set from module is invoked for the upgraded cm handle'
expectedCallsToCeateSchemaSet * mockCpsModuleService.createSchemaSetFromModules(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, 'upgraded-ch', [:], moduleReferences)
and: 'No anchor is created for the upgraded cm handle'
- 0 * mockCpsAdminService.createAnchor(*_)
+ 0 * mockCpsAnchorService.createAnchor(*_)
where: 'the following parameters are used'
scenario | populateCache | existingCmHandlesWithSameTag || expectedCallsToUpgradeSchemaSet | expectedCallsToCeateSchemaSet
'new' | false | [] || 0 | 1
import ch.qos.logback.classic.Level
import ch.qos.logback.classic.Logger
import ch.qos.logback.core.read.ListAppender
-import org.onap.cps.api.CpsAdminService
+import org.onap.cps.api.CpsDataspaceService
+import org.onap.cps.api.CpsAnchorService
import org.onap.cps.api.CpsDataService
import org.onap.cps.api.CpsModuleService
import org.onap.cps.ncmp.api.impl.exception.NcmpStartUpException
class AbstractModelLoaderSpec extends Specification {
- def mockCpsAdminService = Mock(CpsAdminService)
+ def mockCpsDataspaceService = Mock(CpsDataspaceService)
def mockCpsModuleService = Mock(CpsModuleService)
def mockCpsDataService = Mock(CpsDataService)
- def objectUnderTest = Spy(new TestModelLoader(mockCpsAdminService, mockCpsModuleService, mockCpsDataService))
+ def mockCpsAnchorService = Mock(CpsAnchorService)
+ def objectUnderTest = Spy(new TestModelLoader(mockCpsDataspaceService, mockCpsModuleService, mockCpsDataService, mockCpsAnchorService))
def applicationContext = new AnnotationConfigApplicationContext()
when: 'creating an anchor'
objectUnderTest.createAnchor('some dataspace','some schema set','new name')
then: 'the operation is delegated to the admin service'
- 1 * mockCpsAdminService.createAnchor('some dataspace','some schema set', 'new name')
+ 1 * mockCpsAnchorService.createAnchor('some dataspace','some schema set', 'new name')
}
def 'Create anchor with already defined exception.'() {
given: 'the admin service throws an already defined exception'
- mockCpsAdminService.createAnchor(*_)>> { throw AlreadyDefinedException.forAnchor('name','context',null) }
+ mockCpsAnchorService.createAnchor(*_)>> { throw AlreadyDefinedException.forAnchor('name','context',null) }
when: 'attempt to create anchor'
objectUnderTest.createAnchor('some dataspace','some schema set','new name')
then: 'the exception is ignored i.e. no exception thrown up'
def 'Create anchor with any other exception.'() {
given: 'the admin service throws a exception'
- mockCpsAdminService.createAnchor(*_)>> { throw new RuntimeException('test message') }
+ mockCpsAnchorService.createAnchor(*_)>> { throw new RuntimeException('test message') }
when: 'attempt to create anchor'
objectUnderTest.createAnchor('some dataspace','some schema set','new name')
then: 'a startup exception with correct message and details is thrown'
when: 'a schema set for an anchor is updated'
objectUnderTest.updateAnchorSchemaSet('some dataspace', 'anchor', 'new schema set')
then: 'the request is delegated to the admin service'
- 1 * mockCpsAdminService.updateAnchorSchemaSet('some dataspace', 'anchor', 'new schema set')
+ 1 * mockCpsAnchorService.updateAnchorSchemaSet('some dataspace', 'anchor', 'new schema set')
}
def 'Update anchor schema set with exception.'() {
given: 'the admin service throws an exception'
- mockCpsAdminService.updateAnchorSchemaSet(*_) >> { throw new RuntimeException('test message') }
+ mockCpsAnchorService.updateAnchorSchemaSet(*_) >> { throw new RuntimeException('test message') }
when: 'a schema set for an anchor is updated'
objectUnderTest.updateAnchorSchemaSet('some dataspace', 'anchor', 'new schema set')
then: 'a startup exception with correct message and details is thrown'
class TestModelLoader extends AbstractModelLoader {
- TestModelLoader(final CpsAdminService cpsAdminService,
+ TestModelLoader(final CpsDataspaceService cpsDataspaceService,
final CpsModuleService cpsModuleService,
- final CpsDataService cpsDataService) {
- super(cpsAdminService, cpsModuleService, cpsDataService)
+ final CpsDataService cpsDataService,
+ final CpsAnchorService cpsAnchorService) {
+ super(cpsDataspaceService, cpsModuleService, cpsDataService, cpsAnchorService)
super.maximumAttemptCount = 2
super.retryTimeMs = 1
}
package org.onap.cps.ncmp.init
+import org.onap.cps.api.CpsAnchorService
+
import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DATASPACE_NAME
import ch.qos.logback.classic.Level
import ch.qos.logback.classic.Logger
import ch.qos.logback.core.read.ListAppender
-import org.onap.cps.api.CpsAdminService
+import org.onap.cps.api.CpsDataspaceService
import org.onap.cps.api.CpsDataService
import org.onap.cps.api.CpsModuleService
import org.onap.cps.spi.model.Dataspace
class CmDataSubscriptionModelLoaderSpec extends Specification {
- def mockCpsAdminService = Mock(CpsAdminService)
+ def mockCpsDataspaceService = Mock(CpsDataspaceService)
def mockCpsModuleService = Mock(CpsModuleService)
def mockCpsDataService = Mock(CpsDataService)
- def objectUnderTest = new CmDataSubscriptionModelLoader(mockCpsAdminService, mockCpsModuleService, mockCpsDataService)
+ def mockCpsAnchorService = Mock(CpsAnchorService)
+ def objectUnderTest = new CmDataSubscriptionModelLoader(mockCpsDataspaceService, mockCpsModuleService, mockCpsDataService, mockCpsAnchorService)
def applicationContext = new AnnotationConfigApplicationContext()
given:'model loader is enabled'
objectUnderTest.subscriptionModelLoaderEnabled = true
and: 'dataspace is ready for use'
- mockCpsAdminService.getDataspace(NCMP_DATASPACE_NAME) >> new Dataspace('')
+ mockCpsDataspaceService.getDataspace(NCMP_DATASPACE_NAME) >> new Dataspace('')
when: 'the application is ready'
objectUnderTest.onApplicationEvent(Mock(ApplicationReadyEvent))
then: 'the module service to create schema set is called once'
1 * mockCpsModuleService.createSchemaSet(NCMP_DATASPACE_NAME, 'cm-data-subscriptions', expectedYangResourcesToContentMap)
and: 'the admin service to create an anchor set is called once'
- 1 * mockCpsAdminService.createAnchor(NCMP_DATASPACE_NAME, 'cm-data-subscriptions', 'cm-data-subscriptions')
+ 1 * mockCpsAnchorService.createAnchor(NCMP_DATASPACE_NAME, 'cm-data-subscriptions', 'cm-data-subscriptions')
and: 'the data service to create a top level datanode is called once'
1 * mockCpsDataService.saveData(NCMP_DATASPACE_NAME, 'cm-data-subscriptions', '{"datastores":{}}', _)
}
when: 'application is ready'
objectUnderTest.onApplicationEvent(Mock(ApplicationReadyEvent))
then: 'no interaction with admin service'
- 0 * mockCpsAdminService.getDataspace(_)
+ 0 * mockCpsDataspaceService.getDataspace(_)
then: 'a message is logged that the function is disabled'
def logs = loggingListAppender.list.toString()
assert logs.contains('Subscription Model Loader is disabled')
package org.onap.cps.ncmp.init
+import org.onap.cps.api.CpsAnchorService
+
import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DATASPACE_NAME
import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_ANCHOR
import ch.qos.logback.classic.Level
import ch.qos.logback.classic.Logger
import ch.qos.logback.core.read.ListAppender
-import org.onap.cps.api.CpsAdminService
+import org.onap.cps.api.CpsDataspaceService
import org.onap.cps.api.CpsDataService
import org.onap.cps.api.CpsModuleService
import org.onap.cps.spi.model.Dataspace
class InventoryModelLoaderSpec extends Specification {
- def mockCpsAdminService = Mock(CpsAdminService)
+ def mockCpsAdminService = Mock(CpsDataspaceService)
def mockCpsModuleService = Mock(CpsModuleService)
def mockCpsDataService = Mock(CpsDataService)
- def objectUnderTest = new InventoryModelLoader(mockCpsAdminService, mockCpsModuleService, mockCpsDataService)
+ def mockCpsAnchorService = Mock(CpsAnchorService)
+ def objectUnderTest = new InventoryModelLoader(mockCpsAdminService, mockCpsModuleService, mockCpsDataService, mockCpsAnchorService)
def applicationContext = new AnnotationConfigApplicationContext()
then: 'the module service is used to create the new schema set from the correct resource'
1 * mockCpsModuleService.createSchemaSet(NCMP_DATASPACE_NAME, 'dmi-registry-2023-11-27', expectedYangResourceToContentMap)
and: 'the admin service is used to update the anchor'
- 1 * mockCpsAdminService.updateAnchorSchemaSet(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, 'dmi-registry-2023-11-27')
+ 1 * mockCpsAnchorService.updateAnchorSchemaSet(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, 'dmi-registry-2023-11-27')
and: 'No schema sets are being removed by the module service (yet)'
0 * mockCpsModuleService.deleteSchemaSet(NCMP_DATASPACE_NAME, _, _)
}
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
-import org.onap.cps.api.CpsAdminService;
+import org.onap.cps.api.CpsAnchorService;
+import org.onap.cps.api.CpsDataspaceService;
import org.onap.cps.api.CpsModuleService;
import org.onap.cps.rest.api.CpsAdminApi;
import org.onap.cps.rest.model.AnchorDetails;
@RequiredArgsConstructor
public class AdminRestController implements CpsAdminApi {
- private final CpsAdminService cpsAdminService;
+ private final CpsDataspaceService cpsDataspaceService;
private final CpsModuleService cpsModuleService;
private final CpsRestInputMapper cpsRestInputMapper;
+ private final CpsAnchorService cpsAnchorService;
/**
* Create a dataspace.
*/
@Override
public ResponseEntity<String> createDataspace(@NotNull @Valid final String dataspaceName) {
- cpsAdminService.createDataspace(dataspaceName);
+ cpsDataspaceService.createDataspace(dataspaceName);
return new ResponseEntity<>(dataspaceName, HttpStatus.CREATED);
}
*/
@Override
public ResponseEntity<Void> createDataspaceV2(@NotNull @Valid final String dataspaceName) {
- cpsAdminService.createDataspace(dataspaceName);
+ cpsDataspaceService.createDataspace(dataspaceName);
return new ResponseEntity<>(HttpStatus.CREATED);
}
*/
@Override
public ResponseEntity<Void> deleteDataspace(final String apiVersion, final String dataspaceName) {
- cpsAdminService.deleteDataspace(dataspaceName);
+ cpsDataspaceService.deleteDataspace(dataspaceName);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@Override
public ResponseEntity<String> createAnchor(final String dataspaceName, @NotNull @Valid final String schemaSetName,
@NotNull @Valid final String anchorName) {
- cpsAdminService.createAnchor(dataspaceName, schemaSetName, anchorName);
+ cpsAnchorService.createAnchor(dataspaceName, schemaSetName, anchorName);
return new ResponseEntity<>(anchorName, HttpStatus.CREATED);
}
@Override
public ResponseEntity<Void> createAnchorV2(final String dataspaceName, @NotNull @Valid final String schemaSetName,
@NotNull @Valid final String anchorName) {
- cpsAdminService.createAnchor(dataspaceName, schemaSetName, anchorName);
+ cpsAnchorService.createAnchor(dataspaceName, schemaSetName, anchorName);
return new ResponseEntity<>(HttpStatus.CREATED);
}
@Override
public ResponseEntity<Void> deleteAnchor(final String apiVersion,
final String dataspaceName, final String anchorName) {
- cpsAdminService.deleteAnchor(dataspaceName, anchorName);
+ cpsAnchorService.deleteAnchor(dataspaceName, anchorName);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@Override
public ResponseEntity<AnchorDetails> getAnchor(final String apiVersion,
final String dataspaceName, final String anchorName) {
- final var anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
+ final var anchor = cpsAnchorService.getAnchor(dataspaceName, anchorName);
final var anchorDetails = cpsRestInputMapper.toAnchorDetails(anchor);
return new ResponseEntity<>(anchorDetails, HttpStatus.OK);
}
@Override
public ResponseEntity<List<AnchorDetails>> getAnchors(final String apiVersion,
final String dataspaceName) {
- final Collection<Anchor> anchors = cpsAdminService.getAnchors(dataspaceName);
+ final Collection<Anchor> anchors = cpsAnchorService.getAnchors(dataspaceName);
final List<AnchorDetails> anchorDetails = anchors.stream().map(cpsRestInputMapper::toAnchorDetails)
.collect(Collectors.toList());
return new ResponseEntity<>(anchorDetails, HttpStatus.OK);
@Override
public ResponseEntity<List<DataspaceDetails>> getAllDataspaces(final String apiVersion) {
- final Collection<Dataspace> dataspaces = cpsAdminService.getAllDataspaces();
+ final Collection<Dataspace> dataspaces = cpsDataspaceService.getAllDataspaces();
final List<DataspaceDetails> dataspaceDetails = dataspaces.stream().map(cpsRestInputMapper::toDataspaceDetails)
.collect(Collectors.toList());
return new ResponseEntity<>(dataspaceDetails, HttpStatus.OK);
@Override
public ResponseEntity<DataspaceDetails> getDataspace(final String apiVersion, final String dataspaceName) {
- final Dataspace dataspace = cpsAdminService.getDataspace(dataspaceName);
+ final Dataspace dataspace = cpsDataspaceService.getDataspace(dataspaceName);
final DataspaceDetails dataspaceDetails = cpsRestInputMapper.toDataspaceDetails(dataspace);
return new ResponseEntity<>(dataspaceDetails, HttpStatus.OK);
}
package org.onap.cps.rest.controller
+import org.onap.cps.api.CpsAnchorService
+
import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_PROHIBITED
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post
import org.mapstruct.factory.Mappers
-import org.onap.cps.api.CpsAdminService
+import org.onap.cps.api.CpsDataspaceService
import org.onap.cps.api.CpsModuleService
import org.onap.cps.spi.exceptions.AlreadyDefinedException
import org.onap.cps.spi.exceptions.SchemaSetInUseException
CpsModuleService mockCpsModuleService = Mock()
@SpringBean
- CpsAdminService mockCpsAdminService = Mock()
+ CpsDataspaceService mockCpsDataspaceService = Mock()
+
+ @SpringBean
+ CpsAnchorService mockCpsAnchorService = Mock()
@SpringBean
CpsRestInputMapper cpsRestInputMapper = Mappers.getMapper(CpsRestInputMapper)
def 'Create new dataspace with #scenario.'() {
when: 'post is invoked'
def response =
- mvc.perform(
- post("/cps/api/${apiVersion}/dataspaces")
- .param('dataspace-name', dataspaceName))
- .andReturn().response
+ mvc.perform(
+ post("/cps/api/${apiVersion}/dataspaces")
+ .param('dataspace-name', dataspaceName))
+ .andReturn().response
then: 'service method is invoked with expected parameters'
- 1 * mockCpsAdminService.createDataspace(dataspaceName)
+ 1 * mockCpsDataspaceService.createDataspace(dataspaceName)
and: 'dataspace is create successfully'
response.status == HttpStatus.CREATED.value()
assert response.getContentAsString() == expectedResponseBody
where: 'following cases are tested'
- scenario | apiVersion || expectedResponseBody
- 'V1 API' | 'v1' || 'my_dataspace'
- 'V2 API' | 'v2' || ''
- }
+ scenario | apiVersion || expectedResponseBody
+ 'V1 API' | 'v1' || 'my_dataspace'
+ 'V2 API' | 'v2' || ''
+ }
+
def 'Create dataspace over existing with same name.'() {
given: 'an endpoint'
def createDataspaceEndpoint = "$basePath/v1/dataspaces"
and: 'the service method throws an exception indicating the dataspace is already defined'
def thrownException = new AlreadyDefinedException(dataspaceName, new RuntimeException())
- mockCpsAdminService.createDataspace(dataspaceName) >> { throw thrownException }
+ mockCpsDataspaceService.createDataspace(dataspaceName) >> { throw thrownException }
when: 'post is invoked'
def response =
mvc.perform(
def 'Get a dataspace.'() {
given: 'service method returns a dataspace'
- mockCpsAdminService.getDataspace(dataspaceName) >> dataspace
+ mockCpsDataspaceService.getDataspace(dataspaceName) >> dataspace
and: 'an endpoint'
def getDataspaceEndpoint = "$basePath/v1/admin/dataspaces/$dataspaceName"
when: 'get dataspace API is invoked'
def 'Get all dataspaces.'() {
given: 'service method returns all dataspace'
- mockCpsAdminService.getAllDataspaces() >> [dataspace, new Dataspace(name: "dataspace-test2")]
+ mockCpsDataspaceService.getAllDataspaces() >> [dataspace, new Dataspace(name: "dataspace-test2")]
and: 'an endpoint'
def getAllDataspaceEndpoint = "$basePath/v1/admin/dataspaces"
when: 'get all dataspace API is invoked'
.params(requestParams as MultiValueMap))
.andReturn().response
then: 'anchor is created successfully'
- 1 * mockCpsAdminService.createAnchor(dataspaceName, schemaSetName, anchorName)
+ 1 * mockCpsAnchorService.createAnchor(dataspaceName, schemaSetName, anchorName)
assert response.status == HttpStatus.CREATED.value()
assert response.getContentAsString() == expectedResponseBody
where: 'following cases are tested'
def 'Get existing anchor.'() {
given: 'service method returns a list of anchors'
- mockCpsAdminService.getAnchors(dataspaceName) >> [anchor]
+ mockCpsAnchorService.getAnchors(dataspaceName) >> [anchor]
and: 'an endpoint'
def anchorEndpoint = "$basePath/v1/dataspaces/$dataspaceName/anchors"
when: 'get all anchors API is invoked'
def 'Get existing anchor by dataspace and anchor name.'() {
given: 'service method returns an anchor'
- mockCpsAdminService.getAnchor(dataspaceName, anchorName) >>
+ mockCpsAnchorService.getAnchor(dataspaceName, anchorName) >>
new Anchor(name: anchorName, dataspaceName: dataspaceName, schemaSetName: schemaSetName)
and: 'an endpoint'
def anchorEndpoint = "$basePath/v1/dataspaces/$dataspaceName/anchors/$anchorName"
when: 'delete method is invoked on anchor endpoint'
def response = mvc.perform(delete(anchorEndpoint)).andReturn().response
then: 'associated service method is invoked with expected parameters'
- 1 * mockCpsAdminService.deleteAnchor(dataspaceName, anchorName)
+ 1 * mockCpsAnchorService.deleteAnchor(dataspaceName, anchorName)
and: 'response code indicates success'
response.status == HttpStatus.NO_CONTENT.value()
}
.param('dataspace-name', dataspaceName))
.andReturn().response
then: 'associated service method is invoked with expected parameter'
- 1 * mockCpsAdminService.deleteDataspace(dataspaceName)
+ 1 * mockCpsDataspaceService.deleteDataspace(dataspaceName)
and: 'response code indicates success'
response.status == HttpStatus.NO_CONTENT.value()
}
import com.fasterxml.jackson.databind.ObjectMapper
import groovy.json.JsonSlurper
-import org.onap.cps.api.CpsAdminService
+import org.onap.cps.api.CpsDataspaceService
+import org.onap.cps.api.CpsAnchorService
import org.onap.cps.api.CpsDataService
import org.onap.cps.api.CpsModuleService
import org.onap.cps.api.CpsQueryService
class CpsRestExceptionHandlerSpec extends Specification {
@SpringBean
- CpsAdminService mockCpsAdminService = Stub()
+ CpsDataspaceService mockCpsAdminService = Stub()
+
+ @SpringBean
+ CpsAnchorService mockCpsAnchorService = Stub()
@SpringBean
CpsModuleService mockCpsModuleService = Stub()
*/
def setupTestException(exception) {
- mockCpsAdminService.getAnchors(_) >> { throw exception }
+ mockCpsAnchorService.getAnchors(_) >> { throw exception }
}
def performTestRequest() {
/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2020-2023 Nordix Foundation
- * Modifications Copyright (C) 2020-2022 Bell Canada.
- * Modifications Copyright (C) 2021 Pantheon.tech
- * Modifications Copyright (C) 2022 TechMahindra Ltd.
+ * ============LICENSE_START=======================================================
+ * 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.
package org.onap.cps.api;
import java.util.Collection;
-import org.onap.cps.spi.exceptions.AlreadyDefinedException;
import org.onap.cps.spi.exceptions.CpsException;
import org.onap.cps.spi.model.Anchor;
-import org.onap.cps.spi.model.Dataspace;
-/**
- * CPS Admin Service.
- */
-public interface CpsAdminService {
-
- /**
- * Create dataspace.
- *
- * @param dataspaceName dataspace name
- * @throws AlreadyDefinedException if dataspace with same name already exists
- */
- void createDataspace(String dataspaceName);
-
- /**
- * Delete dataspace.
- *
- * @param dataspaceName the name of the dataspace to delete
- */
- void deleteDataspace(String dataspaceName);
-
- /**
- * Get dataspace by given dataspace name.
- *
- * @param dataspaceName dataspace name
- * @return a dataspace
- */
- Dataspace getDataspace(String dataspaceName);
-
- /**
- * Get All Dataspaces.
- *
- *
- * @return a collection of dataspaces
- */
- Collection<Dataspace> getAllDataspaces();
+public interface CpsAnchorService {
/**
* Create an Anchor.
--- /dev/null
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020-2023 Nordix Foundation
+ * Modifications Copyright (C) 2020-2022 Bell Canada.
+ * Modifications Copyright (C) 2021 Pantheon.tech
+ * Modifications Copyright (C) 2022 TechMahindra Ltd.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.api;
+
+import java.util.Collection;
+import org.onap.cps.spi.exceptions.AlreadyDefinedException;
+import org.onap.cps.spi.model.Dataspace;
+
+/**
+ * CPS Admin Service.
+ */
+public interface CpsDataspaceService {
+
+ /**
+ * Create dataspace.
+ *
+ * @param dataspaceName dataspace name
+ * @throws AlreadyDefinedException if dataspace with same name already exists
+ */
+ void createDataspace(String dataspaceName);
+
+ /**
+ * Delete dataspace.
+ *
+ * @param dataspaceName the name of the dataspace to delete
+ */
+ void deleteDataspace(String dataspaceName);
+
+ /**
+ * Get dataspace by given dataspace name.
+ *
+ * @param dataspaceName dataspace name
+ * @return a dataspace
+ */
+ Dataspace getDataspace(String dataspaceName);
+
+ /**
+ * Get All Dataspaces.
+ *
+ *
+ * @return a collection of dataspaces
+ */
+ Collection<Dataspace> getAllDataspaces();
+
+}
/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2020-2023 Nordix Foundation
- * Modifications Copyright (C) 2020-2022 Bell Canada.
- * Modifications Copyright (C) 2021 Pantheon.tech
- * Modifications Copyright (C) 2022 TechMahindra Ltd.
+ * ============LICENSE_START=======================================================
+ * 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.
package org.onap.cps.api.impl;
-import java.time.OffsetDateTime;
import java.util.Collection;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
-import org.onap.cps.api.CpsAdminService;
-import org.onap.cps.api.CpsDataService;
+import org.onap.cps.api.CpsAnchorService;
import org.onap.cps.spi.CpsAdminPersistenceService;
+import org.onap.cps.spi.CpsDataPersistenceService;
import org.onap.cps.spi.model.Anchor;
-import org.onap.cps.spi.model.Dataspace;
import org.onap.cps.spi.utils.CpsValidator;
-import org.springframework.context.annotation.Lazy;
-import org.springframework.stereotype.Component;
+import org.springframework.stereotype.Service;
-@Component("CpsAdminServiceImpl")
-@RequiredArgsConstructor(onConstructor = @__(@Lazy))
-public class CpsAdminServiceImpl implements CpsAdminService {
+@Service
+@RequiredArgsConstructor
+public class CpsAnchorServiceImpl implements CpsAnchorService {
private final CpsAdminPersistenceService cpsAdminPersistenceService;
- @Lazy
- private final CpsDataService cpsDataService;
+ private final CpsDataPersistenceService cpsDataPersistenceService;
private final CpsValidator cpsValidator;
- @Override
- public void createDataspace(final String dataspaceName) {
- cpsValidator.validateNameCharacters(dataspaceName);
- cpsAdminPersistenceService.createDataspace(dataspaceName);
- }
-
- @Override
- public void deleteDataspace(final String dataspaceName) {
- cpsValidator.validateNameCharacters(dataspaceName);
- cpsAdminPersistenceService.deleteDataspace(dataspaceName);
- }
-
- @Override
- public Dataspace getDataspace(final String dataspaceName) {
- cpsValidator.validateNameCharacters(dataspaceName);
- return cpsAdminPersistenceService.getDataspace(dataspaceName);
- }
-
- @Override
- public Collection<Dataspace> getAllDataspaces() {
- return cpsAdminPersistenceService.getAllDataspaces();
- }
-
@Override
public void createAnchor(final String dataspaceName, final String schemaSetName, final String anchorName) {
cpsValidator.validateNameCharacters(dataspaceName, schemaSetName, anchorName);
@Override
public void deleteAnchor(final String dataspaceName, final String anchorName) {
cpsValidator.validateNameCharacters(dataspaceName, anchorName);
- cpsDataService.deleteDataNodes(dataspaceName, anchorName, OffsetDateTime.now());
+ cpsDataPersistenceService.deleteDataNodes(dataspaceName, anchorName);
cpsAdminPersistenceService.deleteAnchor(dataspaceName, anchorName);
}
public void deleteAnchors(final String dataspaceName, final Collection<String> anchorNames) {
cpsValidator.validateNameCharacters(dataspaceName);
cpsValidator.validateNameCharacters(anchorNames);
- cpsDataService.deleteDataNodes(dataspaceName, anchorNames, OffsetDateTime.now());
+ cpsDataPersistenceService.deleteDataNodes(dataspaceName, anchorNames);
cpsAdminPersistenceService.deleteAnchors(dataspaceName, anchorNames);
}
@Override
public void updateAnchorSchemaSet(final String dataspaceName,
- final String anchorName,
- final String schemaSetName) {
+ final String anchorName,
+ final String schemaSetName) {
cpsAdminPersistenceService.updateAnchorSchemaSet(dataspaceName, anchorName, schemaSetName);
}
}
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
-import org.onap.cps.api.CpsAdminService;
+import org.onap.cps.api.CpsAnchorService;
import org.onap.cps.api.CpsDataService;
import org.onap.cps.api.CpsDeltaService;
import org.onap.cps.cpspath.parser.CpsPathUtil;
private static final long DEFAULT_LOCK_TIMEOUT_IN_MILLISECONDS = 300L;
private final CpsDataPersistenceService cpsDataPersistenceService;
- private final CpsAdminService cpsAdminService;
+ private final CpsAnchorService cpsAnchorService;
private final YangTextSchemaSourceSetCache yangTextSchemaSourceSetCache;
private final CpsValidator cpsValidator;
private final TimedYangParser timedYangParser;
public void saveData(final String dataspaceName, final String anchorName, final String nodeData,
final OffsetDateTime observedTimestamp, final ContentType contentType) {
cpsValidator.validateNameCharacters(dataspaceName, anchorName);
- final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
+ final Anchor anchor = cpsAnchorService.getAnchor(dataspaceName, anchorName);
final Collection<DataNode> dataNodes = buildDataNodes(anchor, ROOT_NODE_XPATH, nodeData, contentType);
cpsDataPersistenceService.storeDataNodes(dataspaceName, anchorName, dataNodes);
}
final String nodeData, final OffsetDateTime observedTimestamp,
final ContentType contentType) {
cpsValidator.validateNameCharacters(dataspaceName, anchorName);
- final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
+ final Anchor anchor = cpsAnchorService.getAnchor(dataspaceName, anchorName);
final Collection<DataNode> dataNodes = buildDataNodes(anchor, parentNodeXpath, nodeData, contentType);
cpsDataPersistenceService.addChildDataNodes(dataspaceName, anchorName, parentNodeXpath, dataNodes);
}
public void saveListElements(final String dataspaceName, final String anchorName,
final String parentNodeXpath, final String jsonData, final OffsetDateTime observedTimestamp) {
cpsValidator.validateNameCharacters(dataspaceName, anchorName);
- final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
+ final Anchor anchor = cpsAnchorService.getAnchor(dataspaceName, anchorName);
final Collection<DataNode> listElementDataNodeCollection =
buildDataNodes(anchor, parentNodeXpath, jsonData, ContentType.JSON);
if (isRootNodeXpath(parentNodeXpath)) {
public void saveListElementsBatch(final String dataspaceName, final String anchorName, final String parentNodeXpath,
final Collection<String> jsonDataList, final OffsetDateTime observedTimestamp) {
cpsValidator.validateNameCharacters(dataspaceName, anchorName);
- final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
+ final Anchor anchor = cpsAnchorService.getAnchor(dataspaceName, anchorName);
final Collection<Collection<DataNode>> listElementDataNodeCollections =
buildDataNodes(anchor, parentNodeXpath, jsonDataList, ContentType.JSON);
cpsDataPersistenceService.addMultipleLists(dataspaceName, anchorName, parentNodeXpath,
public void updateNodeLeaves(final String dataspaceName, final String anchorName, final String parentNodeXpath,
final String jsonData, final OffsetDateTime observedTimestamp) {
cpsValidator.validateNameCharacters(dataspaceName, anchorName);
- final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
+ final Anchor anchor = cpsAnchorService.getAnchor(dataspaceName, anchorName);
final Collection<DataNode> dataNodesInPatch = buildDataNodes(anchor, parentNodeXpath, jsonData,
ContentType.JSON);
final Map<String, Map<String, Serializable>> xpathToUpdatedLeaves = dataNodesInPatch.stream()
final String dataNodeUpdatesAsJson,
final OffsetDateTime observedTimestamp) {
cpsValidator.validateNameCharacters(dataspaceName, anchorName);
- final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
+ final Anchor anchor = cpsAnchorService.getAnchor(dataspaceName, anchorName);
final Collection<DataNode> dataNodeUpdates =
buildDataNodes(anchor, parentNodeXpath, dataNodeUpdatesAsJson, ContentType.JSON);
for (final DataNode dataNodeUpdate : dataNodeUpdates) {
final String parentNodeXpath, final String jsonData,
final OffsetDateTime observedTimestamp) {
cpsValidator.validateNameCharacters(dataspaceName, anchorName);
- final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
+ final Anchor anchor = cpsAnchorService.getAnchor(dataspaceName, anchorName);
final Collection<DataNode> dataNodes = buildDataNodes(anchor, parentNodeXpath, jsonData, ContentType.JSON);
cpsDataPersistenceService.updateDataNodesAndDescendants(dataspaceName, anchorName, dataNodes);
}
final Map<String, String> nodesJsonData,
final OffsetDateTime observedTimestamp) {
cpsValidator.validateNameCharacters(dataspaceName, anchorName);
- final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
+ final Anchor anchor = cpsAnchorService.getAnchor(dataspaceName, anchorName);
final Collection<DataNode> dataNodes = buildDataNodes(anchor, nodesJsonData);
cpsDataPersistenceService.updateDataNodesAndDescendants(dataspaceName, anchorName, dataNodes);
}
public void replaceListContent(final String dataspaceName, final String anchorName, final String parentNodeXpath,
final String jsonData, final OffsetDateTime observedTimestamp) {
cpsValidator.validateNameCharacters(dataspaceName, anchorName);
- final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
+ final Anchor anchor = cpsAnchorService.getAnchor(dataspaceName, anchorName);
final Collection<DataNode> newListElements =
buildDataNodes(anchor, parentNodeXpath, jsonData, ContentType.JSON);
replaceListContent(dataspaceName, anchorName, parentNodeXpath, newListElements, observedTimestamp);
--- /dev/null
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020-2023 Nordix Foundation
+ * Modifications Copyright (C) 2020-2022 Bell Canada.
+ * Modifications Copyright (C) 2021 Pantheon.tech
+ * Modifications Copyright (C) 2022 TechMahindra Ltd.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.api.impl;
+
+import java.util.Collection;
+import lombok.RequiredArgsConstructor;
+import org.onap.cps.api.CpsDataspaceService;
+import org.onap.cps.spi.CpsAdminPersistenceService;
+import org.onap.cps.spi.model.Dataspace;
+import org.onap.cps.spi.utils.CpsValidator;
+import org.springframework.stereotype.Service;
+
+@Service
+@RequiredArgsConstructor
+public class CpsDataspaceServiceImpl implements CpsDataspaceService {
+
+ private final CpsAdminPersistenceService cpsAdminPersistenceService;
+ private final CpsValidator cpsValidator;
+
+ @Override
+ public void createDataspace(final String dataspaceName) {
+ cpsValidator.validateNameCharacters(dataspaceName);
+ cpsAdminPersistenceService.createDataspace(dataspaceName);
+ }
+
+ @Override
+ public void deleteDataspace(final String dataspaceName) {
+ cpsValidator.validateNameCharacters(dataspaceName);
+ cpsAdminPersistenceService.deleteDataspace(dataspaceName);
+ }
+
+ @Override
+ public Dataspace getDataspace(final String dataspaceName) {
+ cpsValidator.validateNameCharacters(dataspaceName);
+ return cpsAdminPersistenceService.getDataspace(dataspaceName);
+ }
+
+ @Override
+ public Collection<Dataspace> getAllDataspaces() {
+ return cpsAdminPersistenceService.getAllDataspaces();
+ }
+
+}
import java.util.Map;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
-import org.onap.cps.api.CpsAdminService;
+import org.onap.cps.api.CpsAnchorService;
import org.onap.cps.api.CpsModuleService;
import org.onap.cps.spi.CascadeDeleteAllowed;
import org.onap.cps.spi.CpsModulePersistenceService;
private final CpsModulePersistenceService cpsModulePersistenceService;
private final YangTextSchemaSourceSetCache yangTextSchemaSourceSetCache;
- private final CpsAdminService cpsAdminService;
+ private final CpsAnchorService cpsAnchorService;
private final CpsValidator cpsValidator;
private final TimedYangTextSchemaSourceSetBuilder timedYangTextSchemaSourceSetBuilder;
public void deleteSchemaSet(final String dataspaceName, final String schemaSetName,
final CascadeDeleteAllowed cascadeDeleteAllowed) {
cpsValidator.validateNameCharacters(dataspaceName, schemaSetName);
- final Collection<Anchor> anchors = cpsAdminService.getAnchors(dataspaceName, schemaSetName);
+ final Collection<Anchor> anchors = cpsAnchorService.getAnchors(dataspaceName, schemaSetName);
if (!anchors.isEmpty() && isCascadeDeleteProhibited(cascadeDeleteAllowed)) {
throw new SchemaSetInUseException(dataspaceName, schemaSetName);
}
for (final Anchor anchor : anchors) {
- cpsAdminService.deleteAnchor(dataspaceName, anchor.getName());
+ cpsAnchorService.deleteAnchor(dataspaceName, anchor.getName());
}
cpsModulePersistenceService.deleteSchemaSet(dataspaceName, schemaSetName);
yangTextSchemaSourceSetCache.removeFromCache(dataspaceName, schemaSetName);
public void deleteSchemaSetsWithCascade(final String dataspaceName, final Collection<String> schemaSetNames) {
cpsValidator.validateNameCharacters(dataspaceName);
cpsValidator.validateNameCharacters(schemaSetNames);
- final Collection<String> anchorNames = cpsAdminService.getAnchors(dataspaceName, schemaSetNames)
+ final Collection<String> anchorNames = cpsAnchorService.getAnchors(dataspaceName, schemaSetNames)
.stream().map(Anchor::getName).collect(Collectors.toSet());
- cpsAdminService.deleteAnchors(dataspaceName, anchorNames);
+ cpsAnchorService.deleteAnchors(dataspaceName, anchorNames);
cpsModulePersistenceService.deleteUnusedYangResourceModules();
cpsModulePersistenceService.deleteSchemaSets(dataspaceName, schemaSetNames);
for (final String schemaSetName : schemaSetNames) {
import java.util.Map;
import java.util.concurrent.TimeUnit;
import lombok.RequiredArgsConstructor;
-import org.onap.cps.api.CpsAdminService;
+import org.onap.cps.api.CpsAnchorService;
import org.onap.cps.api.impl.YangTextSchemaSourceSetCache;
import org.onap.cps.cache.AnchorDataCacheEntry;
import org.onap.cps.cpspath.parser.CpsPathPrefixType;
private static final String CACHE_ENTRY_PROPERTY_NAME = "prefixPerContainerName";
- private final CpsAdminService cpsAdminService;
+ private final CpsAnchorService cpsAnchorService;
private final YangTextSchemaSourceSetCache yangTextSchemaSourceSetCache;
* @return the prefix of the module the top level element of given xpath
*/
public String getPrefix(final String dataspaceName, final String anchorName, final String xpath) {
- final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
+ final Anchor anchor = cpsAnchorService.getAnchor(dataspaceName, anchorName);
return getPrefix(anchor, xpath);
}
/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2020-2023 Nordix Foundation
- * Modifications Copyright (C) 2020-2022 Bell Canada.
- * Modifications Copyright (C) 2021 Pantheon.tech
- * Modifications Copyright (C) 2022 TechMahindra Ltd.
+ * ============LICENSE_START=======================================================
+ * 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.
package org.onap.cps.api.impl
-import org.onap.cps.api.CpsDataService
import org.onap.cps.spi.CpsAdminPersistenceService
+import org.onap.cps.spi.CpsDataPersistenceService
import org.onap.cps.spi.exceptions.ModuleNamesNotFoundException
import org.onap.cps.spi.model.Anchor
-import org.onap.cps.spi.model.Dataspace
import org.onap.cps.spi.utils.CpsValidator
import spock.lang.Specification
-import java.time.OffsetDateTime
-class CpsAdminServiceImplSpec extends Specification {
+class CpsAnchorServiceImplSpec extends Specification {
+
def mockCpsAdminPersistenceService = Mock(CpsAdminPersistenceService)
- def mockCpsDataService = Mock(CpsDataService)
+ def mockCpsDataPersistenceService = Mock(CpsDataPersistenceService)
def mockCpsValidator = Mock(CpsValidator)
- def objectUnderTest = new CpsAdminServiceImpl(mockCpsAdminPersistenceService, mockCpsDataService,mockCpsValidator)
- def 'Create dataspace method invokes persistence service.'() {
- when: 'create dataspace method is invoked'
- objectUnderTest.createDataspace('someDataspace')
- then: 'the persistence service method is invoked with same parameters'
- 1 * mockCpsAdminPersistenceService.createDataspace('someDataspace')
- and: 'the CpsValidator is called on the dataspaceName'
- 1 * mockCpsValidator.validateNameCharacters('someDataspace')
- }
+ def objectUnderTest = new CpsAnchorServiceImpl(mockCpsAdminPersistenceService, mockCpsDataPersistenceService, mockCpsValidator)
def 'Create anchor method invokes persistence service.'() {
when: 'create anchor method is invoked'
1 * mockCpsValidator.validateNameCharacters('someDataspace', 'someAnchor')
}
- def 'Retrieve dataspace.'() {
- given: 'a dataspace is already created'
- def dataspace = new Dataspace(name: "someDataspace")
- mockCpsAdminPersistenceService.getDataspace('someDataspace') >> dataspace
- expect: 'the dataspace provided by persistence service is returned as result'
- assert objectUnderTest.getDataspace('someDataspace') == dataspace
- }
-
- def 'Retrieve all dataspaces.'() {
- given: 'that all given dataspaces are already created'
- def dataspaces = [new Dataspace(name: "test-dataspace1"), new Dataspace(name: "test-dataspace2")]
- mockCpsAdminPersistenceService.getAllDataspaces() >> dataspaces
- expect: 'the dataspace provided by persistence service is returned as result'
- assert objectUnderTest.getAllDataspaces() == dataspaces
- }
-
def 'Delete anchor.'() {
when: 'delete anchor is invoked'
objectUnderTest.deleteAnchor('someDataspace','someAnchor')
then: 'delete data nodes is invoked on the data service with expected parameters'
- 1 * mockCpsDataService.deleteDataNodes('someDataspace','someAnchor', _ as OffsetDateTime )
+ 1 * mockCpsDataPersistenceService.deleteDataNodes('someDataspace','someAnchor')
and: 'the persistence service method is invoked with same parameters to delete anchor'
- 1 * mockCpsAdminPersistenceService.deleteAnchor('someDataspace','someAnchor')
+ 1 * mockCpsAdminPersistenceService.deleteAnchor('someDataspace','someAnchor')
and: 'the CpsValidator is called on the dataspaceName, anchorName'
1 * mockCpsValidator.validateNameCharacters('someDataspace', 'someAnchor')
}
when: 'delete anchors is invoked'
objectUnderTest.deleteAnchors('someDataspace', ['anchor1', 'anchor2'])
then: 'delete data nodes is invoked on the data service with expected parameters'
- 1 * mockCpsDataService.deleteDataNodes('someDataspace', _ as Collection<String>, _ as OffsetDateTime)
+ 1 * mockCpsDataPersistenceService.deleteDataNodes('someDataspace', _ as Collection<String>)
and: 'the persistence service method is invoked with same parameters to delete anchor'
1 * mockCpsAdminPersistenceService.deleteAnchors('someDataspace',_ as Collection<String>)
and: 'the CpsValidator is called on the dataspace name and anchor names'
def 'Query all anchors with Module Names Not Found Exception in persistence layer.'() {
given: 'the persistence layer throws a Module Names Not Found Exception'
- def originalException = new ModuleNamesNotFoundException('exception-ds', [ 'm1', 'm2'])
+ def originalException = new ModuleNamesNotFoundException('exception-ds', ['m1', 'm2'])
mockCpsAdminPersistenceService.queryAnchors(*_) >> { throw originalException}
when: 'attempt query anchors'
objectUnderTest.queryAnchorNames('some-dataspace-name', [])
assert thrownUp.details.contains('m2')
}
- def 'Delete dataspace.'() {
- when: 'delete dataspace is invoked'
- objectUnderTest.deleteDataspace('someDataspace')
- then: 'associated persistence service method is invoked with correct parameter'
- 1 * mockCpsAdminPersistenceService.deleteDataspace('someDataspace')
- and: 'the CpsValidator is called on the dataspaceName'
- 1 * mockCpsValidator.validateNameCharacters('someDataspace')
- }
-
def 'Update anchor schema set.'() {
when: 'update anchor is invoked'
objectUnderTest.updateAnchorSchemaSet('someDataspace', 'someAnchor', 'someSchemaSetName')
then: 'associated persistence service method is invoked with correct parameter'
1 * mockCpsAdminPersistenceService.updateAnchorSchemaSet('someDataspace', 'someAnchor', 'someSchemaSetName')
}
+
}
package org.onap.cps.api.impl
import org.onap.cps.TestUtils
-import org.onap.cps.api.CpsAdminService
+import org.onap.cps.api.CpsAnchorService
import org.onap.cps.api.CpsDeltaService
import org.onap.cps.spi.CpsDataPersistenceService
import org.onap.cps.spi.FetchDescendantsOption
import org.onap.cps.yang.YangTextSchemaSourceSetBuilder
import spock.lang.Shared
import spock.lang.Specification
-
import java.time.OffsetDateTime
import java.util.stream.Collectors
class CpsDataServiceImplSpec extends Specification {
def mockCpsDataPersistenceService = Mock(CpsDataPersistenceService)
- def mockCpsAdminService = Mock(CpsAdminService)
+ def mockCpsAnchorService = Mock(CpsAnchorService)
def mockYangTextSchemaSourceSetCache = Mock(YangTextSchemaSourceSetCache)
def mockCpsValidator = Mock(CpsValidator)
def timedYangParser = new TimedYangParser()
def mockCpsDeltaService = Mock(CpsDeltaService);
- def objectUnderTest = new CpsDataServiceImpl(mockCpsDataPersistenceService, mockCpsAdminService,
+ def objectUnderTest = new CpsDataServiceImpl(mockCpsDataPersistenceService, mockCpsAnchorService,
mockYangTextSchemaSourceSetCache, mockCpsValidator, timedYangParser, mockCpsDeltaService)
def setup() {
-
- mockCpsAdminService.getAnchor(dataspaceName, anchorName) >> anchor
- mockCpsAdminService.getAnchor(dataspaceName, ANCHOR_NAME_1) >> anchor1
- mockCpsAdminService.getAnchor(dataspaceName, ANCHOR_NAME_2) >> anchor2
+ mockCpsAnchorService.getAnchor(dataspaceName, anchorName) >> anchor
+ mockCpsAnchorService.getAnchor(dataspaceName, ANCHOR_NAME_1) >> anchor1
+ mockCpsAnchorService.getAnchor(dataspaceName, ANCHOR_NAME_2) >> anchor2
}
@Shared
def 'Delete all data nodes for given dataspace and multiple anchors.'() {
given: 'schema set for given anchors and dataspace references test tree model'
setupSchemaSetMocks('test-tree.yang')
- mockCpsAdminService.getAnchors(dataspaceName, ['anchor1', 'anchor2']) >>
+ mockCpsAnchorService.getAnchors(dataspaceName, ['anchor1', 'anchor2']) >>
[new Anchor(name: 'anchor1', dataspaceName: dataspaceName),
new Anchor(name: 'anchor2', dataspaceName: dataspaceName)]
when: 'delete data node method is invoked with correct parameters'
--- /dev/null
+/*
+ * ============LICENSE_START=======================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.api.impl
+
+import org.onap.cps.spi.CpsAdminPersistenceService
+import org.onap.cps.spi.model.Dataspace
+import org.onap.cps.spi.utils.CpsValidator
+import spock.lang.Specification
+
+class CpsDataspaceServiceImplSpec extends Specification {
+ def mockCpsAdminPersistenceService = Mock(CpsAdminPersistenceService)
+ def mockCpsValidator = Mock(CpsValidator)
+ def objectUnderTest = new CpsDataspaceServiceImpl(mockCpsAdminPersistenceService,mockCpsValidator)
+
+ def 'Create dataspace method invokes persistence service.'() {
+ when: 'create dataspace method is invoked'
+ objectUnderTest.createDataspace('someDataspace')
+ then: 'the persistence service method is invoked with same parameters'
+ 1 * mockCpsAdminPersistenceService.createDataspace('someDataspace')
+ and: 'the CpsValidator is called on the dataspaceName'
+ 1 * mockCpsValidator.validateNameCharacters('someDataspace')
+ }
+
+ def 'Retrieve dataspace.'() {
+ given: 'a dataspace is already created'
+ def dataspace = new Dataspace(name: "someDataspace")
+ mockCpsAdminPersistenceService.getDataspace('someDataspace') >> dataspace
+ expect: 'the dataspace provided by persistence service is returned as result'
+ assert objectUnderTest.getDataspace('someDataspace') == dataspace
+ }
+
+ def 'Retrieve all dataspaces.'() {
+ given: 'that all given dataspaces are already created'
+ def dataspaces = [new Dataspace(name: "test-dataspace1"), new Dataspace(name: "test-dataspace2")]
+ mockCpsAdminPersistenceService.getAllDataspaces() >> dataspaces
+ expect: 'the dataspace provided by persistence service is returned as result'
+ assert objectUnderTest.getAllDataspaces() == dataspaces
+ }
+
+ def 'Delete dataspace.'() {
+ when: 'delete dataspace is invoked'
+ objectUnderTest.deleteDataspace('someDataspace')
+ then: 'associated persistence service method is invoked with correct parameter'
+ 1 * mockCpsAdminPersistenceService.deleteDataspace('someDataspace')
+ and: 'the CpsValidator is called on the dataspaceName'
+ 1 * mockCpsValidator.validateNameCharacters('someDataspace')
+ }
+
+}
package org.onap.cps.api.impl
+import org.onap.cps.api.CpsAnchorService
+
import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED
import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_PROHIBITED
import org.onap.cps.TestUtils
-import org.onap.cps.api.CpsAdminService
import org.onap.cps.spi.CpsModulePersistenceService
import org.onap.cps.spi.exceptions.DuplicatedYangResourceException
import org.onap.cps.spi.exceptions.ModelValidationException
class CpsModuleServiceImplSpec extends Specification {
def mockCpsModulePersistenceService = Mock(CpsModulePersistenceService)
- def mockCpsAdminService = Mock(CpsAdminService)
def mockYangTextSchemaSourceSetCache = Mock(YangTextSchemaSourceSetCache)
+ def mockCpsAnchorService = Mock(CpsAnchorService)
def mockCpsValidator = Mock(CpsValidator)
def timedYangTextSchemaSourceSetBuilder = new TimedYangTextSchemaSourceSetBuilder()
- def objectUnderTest = new CpsModuleServiceImpl(mockCpsModulePersistenceService, mockYangTextSchemaSourceSetCache, mockCpsAdminService, mockCpsValidator,timedYangTextSchemaSourceSetBuilder)
+ def objectUnderTest = new CpsModuleServiceImpl(mockCpsModulePersistenceService, mockYangTextSchemaSourceSetCache, mockCpsAnchorService, mockCpsValidator,timedYangTextSchemaSourceSetBuilder)
def 'Create schema set.'() {
when: 'Create schema set method is invoked'
def 'Delete schema-set when cascade is allowed.'() {
given: '#numberOfAnchors anchors are associated with schemaset'
def associatedAnchors = createAnchors(numberOfAnchors)
- mockCpsAdminService.getAnchors('my-dataspace', 'my-schemaset') >> associatedAnchors
+ mockCpsAnchorService.getAnchors('my-dataspace', 'my-schemaset') >> associatedAnchors
when: 'schema set deletion is requested with cascade allowed'
objectUnderTest.deleteSchemaSet('my-dataspace', 'my-schemaset', CASCADE_DELETE_ALLOWED)
then: 'anchor deletion is called #numberOfAnchors times'
- numberOfAnchors * mockCpsAdminService.deleteAnchor('my-dataspace', _)
+ numberOfAnchors * mockCpsAnchorService.deleteAnchor('my-dataspace', _)
and: 'persistence service method is invoked with same parameters'
1 * mockCpsModulePersistenceService.deleteSchemaSet('my-dataspace', 'my-schemaset')
and: 'schema set will be removed from the cache'
def 'Delete schema-set when cascade is prohibited.'() {
given: 'no anchors are associated with schemaset'
- mockCpsAdminService.getAnchors('my-dataspace', 'my-schemaset') >> Collections.emptyList()
+ mockCpsAnchorService.getAnchors('my-dataspace', 'my-schemaset') >> Collections.emptyList()
when: 'schema set deletion is requested with cascade allowed'
objectUnderTest.deleteSchemaSet('my-dataspace', 'my-schemaset', CASCADE_DELETE_PROHIBITED)
then: 'no anchors are deleted'
- 0 * mockCpsAdminService.deleteAnchor(_, _)
+ 0 * mockCpsAnchorService.deleteAnchor(_, _)
and: 'persistence service method is invoked with same parameters'
1 * mockCpsModulePersistenceService.deleteSchemaSet('my-dataspace', 'my-schemaset')
and: 'schema set will be removed from the cache'
def 'Delete schema-set when cascade is prohibited and schema-set has anchors.'() {
given: '2 anchors are associated with schemaset'
- mockCpsAdminService.getAnchors('my-dataspace', 'my-schemaset') >> createAnchors(2)
+ mockCpsAnchorService.getAnchors('my-dataspace', 'my-schemaset') >> createAnchors(2)
when: 'schema set deletion is requested with cascade allowed'
objectUnderTest.deleteSchemaSet('my-dataspace', 'my-schemaset', CASCADE_DELETE_PROHIBITED)
then: 'Schema-Set in Use exception is thrown'
def 'Delete multiple schema-sets when cascade is allowed.'() {
given: '#numberOfAnchors anchors are associated with each schemaset'
- mockCpsAdminService.getAnchors('my-dataspace', ['my-schemaset1', 'my-schemaset2']) >> createAnchors(numberOfAnchors * 2)
+ mockCpsAnchorService.getAnchors('my-dataspace', ['my-schemaset1', 'my-schemaset2']) >> createAnchors(numberOfAnchors * 2)
when: 'schema set deletion is requested with cascade allowed'
objectUnderTest.deleteSchemaSetsWithCascade('my-dataspace', ['my-schemaset1', 'my-schemaset2'])
then: 'anchor deletion is called #numberOfAnchors times'
- mockCpsAdminService.deleteAnchors('my-dataspace', _)
+ mockCpsAnchorService.deleteAnchors('my-dataspace', _)
and: 'persistence service method is invoked with same parameters'
mockCpsModulePersistenceService.deleteSchemaSets('my-dataspace', _)
and: 'schema sets will be removed from the cache'
package org.onap.cps.api.impl\r
\r
import org.onap.cps.TestUtils\r
-import org.onap.cps.api.CpsAdminService\r
+import org.onap.cps.api.CpsAnchorService\r
import org.onap.cps.api.CpsDeltaService\r
import org.onap.cps.spi.CpsDataPersistenceService\r
import org.onap.cps.spi.CpsDataPersistenceService\r
class E2ENetworkSliceSpec extends Specification {\r
def mockModuleStoreService = Mock(CpsModulePersistenceService)\r
def mockDataStoreService = Mock(CpsDataPersistenceService)\r
- def mockCpsAdminService = Mock(CpsAdminService)\r
+ def mockCpsAnchorService = Mock(CpsAnchorService)\r
def mockYangTextSchemaSourceSetCache = Mock(YangTextSchemaSourceSetCache)\r
def mockCpsValidator = Mock(CpsValidator)\r
def timedYangTextSchemaSourceSetBuilder = new TimedYangTextSchemaSourceSetBuilder()\r
def mockCpsDeltaService = Mock(CpsDeltaService)\r
\r
def cpsModuleServiceImpl = new CpsModuleServiceImpl(mockModuleStoreService,\r
- mockYangTextSchemaSourceSetCache, mockCpsAdminService, mockCpsValidator,timedYangTextSchemaSourceSetBuilder)\r
+ mockYangTextSchemaSourceSetCache, mockCpsAnchorService, mockCpsValidator,timedYangTextSchemaSourceSetBuilder)\r
\r
- def cpsDataServiceImpl = new CpsDataServiceImpl(mockDataStoreService, mockCpsAdminService,\r
+ def cpsDataServiceImpl = new CpsDataServiceImpl(mockDataStoreService, mockCpsAnchorService,\r
mockYangTextSchemaSourceSetCache, mockCpsValidator, timedYangParser, mockCpsDeltaService)\r
\r
def dataspaceName = 'someDataspace'\r
and : 'a valid json is provided for the model'\r
def jsonData = TestUtils.getResourceFileContent('e2e/basic/cps-Cavsta-Data.txt')\r
and : 'all the further dependencies are mocked '\r
- mockCpsAdminService.getAnchor(dataspaceName, anchorName) >>\r
+ mockCpsAnchorService.getAnchor(dataspaceName, anchorName) >>\r
new Anchor().builder().name(anchorName).schemaSetName(schemaSetName).dataspaceName(dataspaceName).build()\r
mockYangTextSchemaSourceSetCache.get(dataspaceName, schemaSetName) >>\r
YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap)\r
and : 'a valid json is provided for the model'\r
def jsonData = TestUtils.getResourceFileContent('e2e/basic/cps-ran-inventory-data.json')\r
and : 'all the further dependencies are mocked '\r
- mockCpsAdminService.getAnchor('someDataspace', 'someAnchor') >>\r
+ mockCpsAnchorService.getAnchor('someDataspace', 'someAnchor') >>\r
new Anchor().builder().name('someAnchor').schemaSetName('someSchemaSet').dataspaceName(dataspaceName).build()\r
mockYangTextSchemaSourceSetCache.get('someDataspace', 'someSchemaSet') >> YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap)\r
mockModuleStoreService.getYangSchemaResources('someDataspace', 'someSchemaSet') >> schemaContext\r
import com.hazelcast.map.IMap
import org.onap.cps.TestUtils
-import org.onap.cps.api.CpsAdminService
+import org.onap.cps.api.CpsAnchorService
import org.onap.cps.api.impl.YangTextSchemaSourceSetCache
import org.onap.cps.cache.AnchorDataCacheEntry
import org.onap.cps.spi.model.Anchor
class PrefixResolverSpec extends Specification {
- def mockCpsAdminService = Mock(CpsAdminService)
+ def mockCpsAnchorService = Mock(CpsAnchorService)
def mockYangTextSchemaSourceSetCache = Mock(YangTextSchemaSourceSetCache)
def mockAnchorDataCache = Mock(IMap<String, AnchorDataCacheEntry>)
- def objectUnderTest = new PrefixResolver(mockCpsAdminService, mockYangTextSchemaSourceSetCache, mockAnchorDataCache)
+ def objectUnderTest = new PrefixResolver(mockCpsAnchorService, mockYangTextSchemaSourceSetCache, mockAnchorDataCache)
def mockYangTextSchemaSourceSet = Mock(YangTextSchemaSourceSet)
given: 'an anchor for the test-tree model'
def anchor = new Anchor(dataspaceName: 'testDataspace', name: 'testAnchor')
and: 'the system can get this anchor'
- mockCpsAdminService.getAnchor('testDataspace', 'testAnchor') >> anchor
+ mockCpsAnchorService.getAnchor('testDataspace', 'testAnchor') >> anchor
and: 'the schema source cache contains the schema context for the test-tree module'
mockYangTextSchemaSourceSet.getSchemaContext() >> schemaContext
}
package org.onap.cps.integration.base
+import org.onap.cps.api.CpsAnchorService
+import org.onap.cps.api.CpsDataService
+import org.onap.cps.api.CpsDataspaceService
+import org.onap.cps.api.CpsModuleService
import org.onap.cps.api.CpsQueryService
-import org.onap.cps.api.impl.CpsAdminServiceImpl
-import org.onap.cps.api.impl.CpsDataServiceImpl
-import org.onap.cps.api.impl.CpsModuleServiceImpl
import org.onap.cps.integration.DatabaseTestContainer
import org.onap.cps.spi.config.CpsSessionFactory
import org.onap.cps.spi.exceptions.DataspaceNotFoundException
import java.time.OffsetDateTime
-@SpringBootTest(classes = [TestConfig, CpsAdminServiceImpl, CpsValidatorImpl, SessionManager, CpsSessionFactory])
+@SpringBootTest(classes = [TestConfig, CpsValidatorImpl, SessionManager, CpsSessionFactory])
@Testcontainers
@EnableAutoConfiguration
@EnableJpaRepositories(basePackageClasses = [DataspaceRepository])
@Autowired
@Lazy
- CpsAdminServiceImpl cpsAdminService
+ CpsDataspaceService cpsDataspaceService
@Autowired
@Lazy
- CpsDataServiceImpl cpsDataService
+ CpsAnchorService cpsAnchorService
@Autowired
@Lazy
- CpsModuleServiceImpl cpsModuleService
+ CpsDataService cpsDataService
+
+ @Autowired
+ @Lazy
+ CpsModuleService cpsModuleService
@Autowired
@Lazy
def setup() {
if (!initialized) {
- cpsAdminService.createDataspace(GENERAL_TEST_DATASPACE)
+ cpsDataspaceService.createDataspace(GENERAL_TEST_DATASPACE)
def bookstoreModelFileContent = readResourceDataFile('bookstore/bookstore.yang')
cpsModuleService.createSchemaSet(GENERAL_TEST_DATASPACE, BOOKSTORE_SCHEMA_SET, [bookstore : bookstoreModelFileContent])
initialized = true;
def dataspaceExists(dataspaceName) {
try {
- cpsAdminService.getDataspace(dataspaceName)
+ cpsDataspaceService.getDataspace(dataspaceName)
} catch (DataspaceNotFoundException dataspaceNotFoundException) {
return false
}
def addAnchorsWithData(numberOfAnchors, dataspaceName, schemaSetName, anchorNamePrefix, data) {
(1..numberOfAnchors).each {
- cpsAdminService.createAnchor(dataspaceName, schemaSetName, anchorNamePrefix + it)
+ cpsAnchorService.createAnchor(dataspaceName, schemaSetName, anchorNamePrefix + it)
cpsDataService.saveData(dataspaceName, anchorNamePrefix + it, data.replace("Easons", "Easons-"+it.toString()), OffsetDateTime.now())
}
}
}
def setupBookstoreInfraStructure() {
- cpsAdminService.createDataspace(FUNCTIONAL_TEST_DATASPACE_1)
- cpsAdminService.createDataspace(FUNCTIONAL_TEST_DATASPACE_2)
- cpsAdminService.createDataspace(FUNCTIONAL_TEST_DATASPACE_3)
+ cpsDataspaceService.createDataspace(FUNCTIONAL_TEST_DATASPACE_1)
+ cpsDataspaceService.createDataspace(FUNCTIONAL_TEST_DATASPACE_2)
+ cpsDataspaceService.createDataspace(FUNCTIONAL_TEST_DATASPACE_3)
def bookstoreYangModelAsString = readResourceDataFile('bookstore/bookstore.yang')
cpsModuleService.createSchemaSet(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_SCHEMA_SET, [bookstore: bookstoreYangModelAsString])
cpsModuleService.createSchemaSet(FUNCTIONAL_TEST_DATASPACE_2, BOOKSTORE_SCHEMA_SET, [bookstore: bookstoreYangModelAsString])
def restoreBookstoreDataAnchor(anchorNumber) {
def anchorName = 'bookstoreAnchor' + anchorNumber
- cpsAdminService.deleteAnchor(FUNCTIONAL_TEST_DATASPACE_1, anchorName)
- cpsAdminService.createAnchor(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_SCHEMA_SET, anchorName)
+ cpsAnchorService.deleteAnchor(FUNCTIONAL_TEST_DATASPACE_1, anchorName)
+ cpsAnchorService.createAnchor(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_SCHEMA_SET, anchorName)
cpsDataService.saveData(FUNCTIONAL_TEST_DATASPACE_1, anchorName, bookstoreJsonData.replace("Easons", "Easons-"+anchorNumber.toString()), OffsetDateTime.now())
}
package org.onap.cps.integration.functional
-import org.onap.cps.api.CpsAdminService
+import org.onap.cps.api.CpsAnchorService
import org.onap.cps.integration.base.CpsIntegrationSpecBase
import org.onap.cps.spi.FetchDescendantsOption
import org.onap.cps.spi.exceptions.AlreadyDefinedException
import org.onap.cps.spi.exceptions.AnchorNotFoundException
-import org.onap.cps.spi.exceptions.DataspaceInUseException
-import org.onap.cps.spi.exceptions.DataspaceNotFoundException
-import java.time.OffsetDateTime
-
-class CpsAdminServiceIntegrationSpec extends CpsIntegrationSpecBase {
-
- CpsAdminService objectUnderTest
- def setup() { objectUnderTest = cpsAdminService }
-
- def 'Dataspace CRUD operations.'() {
- when: 'a dataspace is created'
- objectUnderTest.createDataspace('newDataspace')
- then: 'the dataspace can be read'
- assert objectUnderTest.getDataspace('newDataspace').name == 'newDataspace'
- and: 'it can be deleted'
- objectUnderTest.deleteDataspace('newDataspace')
- then: 'the dataspace no longer exists i.e. an exception is thrown if an attempt is made to retrieve it'
- def thrown = null
- try {
- objectUnderTest.getDataspace('newDataspace')
- } catch(Exception exception) {
- thrown = exception
- }
- assert thrown instanceof DataspaceNotFoundException
- }
+import java.time.OffsetDateTime
- def 'Delete dataspace with error; #scenario.'() {
- setup: 'add some anchors if needed'
- numberOfAnchors.times {
- objectUnderTest.createAnchor(GENERAL_TEST_DATASPACE, BOOKSTORE_SCHEMA_SET, 'anchor' + it)
- }
- when: 'attempt to delete dataspace'
- objectUnderTest.deleteDataspace(dataspaceName)
- then: 'the correct exception is thrown with the relevant details'
- def thrownException = thrown(expectedException)
- thrownException.details.contains(expectedMessageDetails)
- cleanup:
- numberOfAnchors.times {
- objectUnderTest.deleteAnchor(GENERAL_TEST_DATASPACE, 'anchor' + it)
- }
- where: 'the following data is used'
- scenario | dataspaceName | numberOfAnchors || expectedException | expectedMessageDetails
- 'dataspace name does not exist' | 'unknown' | 0 || DataspaceNotFoundException | 'unknown does not exist'
- 'dataspace contains schemasets' | GENERAL_TEST_DATASPACE | 0 || DataspaceInUseException | 'contains 1 schemaset(s)'
- 'dataspace contains anchors' | GENERAL_TEST_DATASPACE | 2 || DataspaceInUseException | 'contains 2 anchor(s)'
- }
+class CpsAnchorServiceIntegrationSpec extends CpsIntegrationSpecBase {
- def 'Retrieve all dataspaces (depends on total test suite).'() {
- given: 'two addtional dataspaces are created'
- objectUnderTest.createDataspace('dataspace1')
- objectUnderTest.createDataspace('dataspace2')
- when: 'all datespaces are retreived'
- def result = objectUnderTest.getAllDataspaces()
- then: 'there are at least 3 dataspaces (2 new ones plus the general test dataspace)'
- result.size() >= 3
- assert result.name.containsAll([GENERAL_TEST_DATASPACE, 'dataspace1', 'dataspace2'])
- }
+ CpsAnchorService objectUnderTest
- def 'Duplicate dataspaces.'() {
- when: 'attempting to create a dataspace with the same name as an existing one'
- objectUnderTest.createDataspace(GENERAL_TEST_DATASPACE)
- then: 'an exception is thrown indicating the dataspace already exists'
- thrown(AlreadyDefinedException)
- }
+ def setup() { objectUnderTest = cpsAnchorService }
def 'Anchor CRUD operations.'() {
when: 'an anchor is created'
then: 'an empty result is returned (no error)'
assert result == []
where:
- scenario | dataspaceName
- 'non existing database' | 'nonExistingDataspace'
- 'just unknown module(s)' | GENERAL_TEST_DATASPACE
+ scenario | dataspaceName
+ 'non existing database' | 'nonExistingDataspace'
+ 'just unknown module(s)' | GENERAL_TEST_DATASPACE
}
def 'Update anchor schema set.'() {
import org.onap.cps.spi.exceptions.DataspaceNotFoundException
import org.onap.cps.spi.model.DeltaReport
-import java.time.OffsetDateTime
-
import static org.onap.cps.spi.FetchDescendantsOption.DIRECT_CHILDREN_ONLY
import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS
def 'Attempt to create a top level data node using root.'() {
given: 'a new anchor'
- cpsAdminService.createAnchor(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_SCHEMA_SET, 'newAnchor1');
+ cpsAnchorService.createAnchor(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_SCHEMA_SET, 'newAnchor1');
when: 'attempt to save new top level datanode'
def json = '{"bookstore": {"bookstore-name": "New Store"} }'
objectUnderTest.saveData(FUNCTIONAL_TEST_DATASPACE_1, 'newAnchor1' , '/', json, now)
--- /dev/null
+/*
+ * ============LICENSE_START=======================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.integration.functional
+
+import org.onap.cps.api.CpsDataspaceService
+import org.onap.cps.integration.base.CpsIntegrationSpecBase
+import org.onap.cps.spi.exceptions.AlreadyDefinedException
+import org.onap.cps.spi.exceptions.DataspaceInUseException
+import org.onap.cps.spi.exceptions.DataspaceNotFoundException
+
+class CpsDataspaceServiceIntegrationSpec extends CpsIntegrationSpecBase {
+
+ CpsDataspaceService objectUnderTest
+
+ def setup() { objectUnderTest = cpsDataspaceService }
+
+ def 'Dataspace CRUD operations.'() {
+ when: 'a dataspace is created'
+ objectUnderTest.createDataspace('newDataspace')
+ then: 'the dataspace can be read'
+ assert objectUnderTest.getDataspace('newDataspace').name == 'newDataspace'
+ and: 'it can be deleted'
+ objectUnderTest.deleteDataspace('newDataspace')
+ then: 'the dataspace no longer exists i.e. an exception is thrown if an attempt is made to retrieve it'
+ def thrown = null
+ try {
+ objectUnderTest.getDataspace('newDataspace')
+ } catch(Exception exception) {
+ thrown = exception
+ }
+ assert thrown instanceof DataspaceNotFoundException
+ }
+
+ def 'Attempt to delete a non-existing dataspace'() {
+ when: 'attempt to delete a non-existing dataspace'
+ objectUnderTest.deleteDataspace('non-existing-name')
+ then: 'a not found exception is thrown with the relevant dataspace name'
+ def thrownException = thrown(DataspaceNotFoundException)
+ assert thrownException.details.contains('non-existing-name does not exist')
+ }
+
+ def 'Attempt Delete dataspace with a schema set and anchor'() {
+ setup: 'a dataspace with a schema set and anchor'
+ objectUnderTest.createDataspace('targetDataspace')
+ cpsModuleService.createSchemaSet('targetDataspace','someSchemaSet',[:])
+ cpsAnchorService.createAnchor('targetDataspace', 'someSchemaSet', 'some_anchor')
+ when: 'attempt to delete dataspace'
+ objectUnderTest.deleteDataspace('targetDataspace')
+ then: 'an in-use exception is thrown mentioning anchors'
+ def thrownException = thrown(DataspaceInUseException)
+ assert thrownException.details.contains('contains 1 anchor(s)')
+ cleanup:
+ cpsModuleService.deleteSchemaSetsWithCascade('targetDataspace',['someSchemaSet'])
+ objectUnderTest.deleteDataspace('targetDataspace')
+ }
+
+ def 'Attempt to delete dataspace with just a schema set'() {
+ setup: 'a dataspace with a schema set'
+ objectUnderTest.createDataspace('targetDataspace')
+ cpsModuleService.createSchemaSet('targetDataspace','someSchemaSet',[:])
+ when: 'attempt to delete dataspace'
+ objectUnderTest.deleteDataspace('targetDataspace')
+ then: 'an in-use exception is thrown mentioning schemasets'
+ def thrownException = thrown(DataspaceInUseException)
+ assert thrownException.details.contains('contains 1 schemaset(s)')
+ cleanup:
+ cpsModuleService.deleteSchemaSetsWithCascade('targetDataspace',['someSchemaSet'])
+ objectUnderTest.deleteDataspace('targetDataspace')
+ }
+
+ def 'Retrieve all dataspaces (depends on total test suite).'() {
+ given: 'two addtional dataspaces are created'
+ objectUnderTest.createDataspace('dataspace1')
+ objectUnderTest.createDataspace('dataspace2')
+ when: 'all datespaces are retreived'
+ def result = objectUnderTest.getAllDataspaces()
+ then: 'there are at least 3 dataspaces (2 new ones plus the general test dataspace)'
+ result.size() >= 3
+ assert result.name.containsAll([GENERAL_TEST_DATASPACE, 'dataspace1', 'dataspace2'])
+ }
+
+ def 'Duplicate dataspaces.'() {
+ when: 'attempting to create a dataspace with the same name as an existing one'
+ objectUnderTest.createDataspace(GENERAL_TEST_DATASPACE)
+ then: 'an exception is thrown indicating the dataspace already exists'
+ thrown(AlreadyDefinedException)
+ }
+
+}
package org.onap.cps.integration.functional
+import org.onap.cps.api.CpsModuleService
import org.onap.cps.api.impl.CpsModuleServiceImpl
import org.onap.cps.integration.base.FunctionalSpecBase
import org.onap.cps.spi.CascadeDeleteAllowed
class CpsModuleServiceIntegrationSpec extends FunctionalSpecBase {
- CpsModuleServiceImpl objectUnderTest
+ CpsModuleService objectUnderTest
private static def originalNumberOfModuleReferences = 1
private static def existingModuleReference = new ModuleReference('stores','2020-09-15')
def schemaSetName = "NewSchemaWith${numberOfNewModules}Modules"
objectUnderTest.createSchemaSetFromModules(FUNCTIONAL_TEST_DATASPACE_1, schemaSetName, newYangResourcesNameToContentMap, moduleReferences)
and: 'associated with a new anchor'
- cpsAdminService.createAnchor(FUNCTIONAL_TEST_DATASPACE_1, schemaSetName, 'newAnchor')
+ cpsAnchorService.createAnchor(FUNCTIONAL_TEST_DATASPACE_1, schemaSetName, 'newAnchor')
then: 'the new anchor has the correct number of modules'
def yangResourceModuleReferences = objectUnderTest.getYangResourcesModuleReferences(FUNCTIONAL_TEST_DATASPACE_1, 'newAnchor')
assert expectedNumberOfModulesForAnchor == yangResourceModuleReferences.size()
objectUnderTest.createSchemaSet(FUNCTIONAL_TEST_DATASPACE_1, 'newSchemaSet', newYangResourcesNameToContentMap)
and: 'optionally create anchor for the schema set'
if (associateWithAnchor) {
- cpsAdminService.createAnchor(FUNCTIONAL_TEST_DATASPACE_1, 'newSchemaSet', 'newAnchor')
+ cpsAnchorService.createAnchor(FUNCTIONAL_TEST_DATASPACE_1, 'newSchemaSet', 'newAnchor')
}
when: 'attempt to delete the schema set'
try {
given: 'an anchor and schema set with 2 modules (to be upgraded)'
populateNewYangResourcesNameToContentMapAndAllModuleReferences('original', 2)
objectUnderTest.createSchemaSetFromModules(FUNCTIONAL_TEST_DATASPACE_1, 'targetSchema', newYangResourcesNameToContentMap, [])
- cpsAdminService.createAnchor(FUNCTIONAL_TEST_DATASPACE_1, 'targetSchema', 'targetAnchor')
+ cpsAnchorService.createAnchor(FUNCTIONAL_TEST_DATASPACE_1, 'targetSchema', 'targetAnchor')
def yangResourceModuleReferencesBeforeUpgrade = objectUnderTest.getYangResourcesModuleReferences(FUNCTIONAL_TEST_DATASPACE_1, 'targetAnchor')
assert yangResourceModuleReferencesBeforeUpgrade.size() == 2
assert yangResourceModuleReferencesBeforeUpgrade.containsAll([new ModuleReference('original_0','2000-01-01'),new ModuleReference('original_1','2001-01-01')])
cleanup:
objectUnderTest.deleteSchemaSetsWithCascade(FUNCTIONAL_TEST_DATASPACE_1, ['targetSchema'])
}
-
+
def 'Upgrade existing schema set from another anchor (used in NCMP for matching module set tag)'() {
given: 'an anchor and schema set with 1 module (target)'
populateNewYangResourcesNameToContentMapAndAllModuleReferences('target', 1)
objectUnderTest.createSchemaSetFromModules(FUNCTIONAL_TEST_DATASPACE_1, 'targetSchema', newYangResourcesNameToContentMap, [])
- cpsAdminService.createAnchor(FUNCTIONAL_TEST_DATASPACE_1, 'targetSchema', 'targetAnchor')
+ cpsAnchorService.createAnchor(FUNCTIONAL_TEST_DATASPACE_1, 'targetSchema', 'targetAnchor')
def moduleReferencesBeforeUpgrade = objectUnderTest.getYangResourcesModuleReferences(FUNCTIONAL_TEST_DATASPACE_1, 'targetAnchor')
assert moduleReferencesBeforeUpgrade.size() == 1
and: 'another anchor and schema set with 2 other modules (source for upgrade)'
populateNewYangResourcesNameToContentMapAndAllModuleReferences('source', 2)
objectUnderTest.createSchemaSetFromModules(FUNCTIONAL_TEST_DATASPACE_1, 'sourceSchema', newYangResourcesNameToContentMap, [])
- cpsAdminService.createAnchor(FUNCTIONAL_TEST_DATASPACE_1, 'sourceSchema', 'sourceAnchor')
+ cpsAnchorService.createAnchor(FUNCTIONAL_TEST_DATASPACE_1, 'sourceSchema', 'sourceAnchor')
assert objectUnderTest.getYangResourcesModuleReferences(FUNCTIONAL_TEST_DATASPACE_1, 'sourceAnchor').size() == 2
when: 'the target schema is upgraded using the module references from the source anchor'
def moduleReferencesFromSourceAnchor = objectUnderTest.getYangResourcesModuleReferences(FUNCTIONAL_TEST_DATASPACE_1, 'sourceAnchor')
}
def setupPerformanceInfraStructure() {
- cpsAdminService.createDataspace(CPS_PERFORMANCE_TEST_DATASPACE)
+ cpsDataspaceService.createDataspace(CPS_PERFORMANCE_TEST_DATASPACE)
def modelAsString = readResourceDataFile('bookstore/bookstore.yang')
cpsModuleService.createSchemaSet(CPS_PERFORMANCE_TEST_DATASPACE, BOOKSTORE_SCHEMA_SET, [bookstore: modelAsString])
}
}
def setupPerformanceInfraStructure() {
- cpsAdminService.createDataspace(NCMP_PERFORMANCE_TEST_DATASPACE)
+ cpsDataspaceService.createDataspace(NCMP_PERFORMANCE_TEST_DATASPACE)
createRegistrySchemaSet()
createCmDataSubscriptionsSchemaSet()
addCmSubscriptionData()
}
def createInitialData() {
- cpsAdminService.createAnchor(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_SCHEMA_SET, REGISTRY_ANCHOR)
+ cpsDataspaceService.createAnchor(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_SCHEMA_SET, REGISTRY_ANCHOR)
def data = readResourceDataFile('ncmp-registry/1000-cmhandles.json')
cpsDataService.saveData(NCMP_PERFORMANCE_TEST_DATASPACE, REGISTRY_ANCHOR, data, OffsetDateTime.now())
}
}
def addCmSubscriptionData() {
- cpsAdminService.createAnchor(NCMP_PERFORMANCE_TEST_DATASPACE, CM_DATA_SUBSCRIPTIONS_SCHEMA_SET, CM_DATA_SUBSCRIPTIONS_ANCHOR)
+ cpsDataspaceService.createAnchor(NCMP_PERFORMANCE_TEST_DATASPACE, CM_DATA_SUBSCRIPTIONS_SCHEMA_SET, CM_DATA_SUBSCRIPTIONS_ANCHOR)
cpsDataService.saveData(NCMP_PERFORMANCE_TEST_DATASPACE, CM_DATA_SUBSCRIPTIONS_ANCHOR, datastore1cmHandlePlaceHolder, now)
def subscribers = createLeafList('subscribers',numberOfCmDataSubscribers, subscriberIdPrefix)
def filters = '"filters":' + createJsonArray('filter',numberOfFiltersPerCmHandle,'xpath',xpathPrefix,subscribers)
def 'Create 33,000 books (note further tests depend on this running first).'() {
given: 'an anchor containing a bookstore with one category'
- cpsAdminService.createAnchor(CPS_PERFORMANCE_TEST_DATASPACE, BOOKSTORE_SCHEMA_SET, 'limitsAnchor')
+ cpsAnchorService.createAnchor(CPS_PERFORMANCE_TEST_DATASPACE, BOOKSTORE_SCHEMA_SET, 'limitsAnchor')
def parentNodeData = '{"bookstore": { "categories": [{ "code": 1, "name": "Test", "books" : [] }] }}'
cpsDataService.saveData(CPS_PERFORMANCE_TEST_DATASPACE, 'limitsAnchor', parentNodeData, OffsetDateTime.now())
when: '33,000 books are added'
when:
resourceMeter.start()
cpsDataService.deleteDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, 'limitsAnchor', OffsetDateTime.now())
- cpsAdminService.deleteAnchor(CPS_PERFORMANCE_TEST_DATASPACE, 'limitsAnchor')
+ cpsAnchorService.deleteAnchor(CPS_PERFORMANCE_TEST_DATASPACE, 'limitsAnchor')
resourceMeter.stop()
def durationInSeconds = resourceMeter.getTotalTimeInSeconds()
then: 'test data is deleted in 1 second'
package org.onap.cps.integration.performance.cps
-import org.onap.cps.api.CpsAdminService
+import org.onap.cps.api.CpsAnchorService
import org.onap.cps.integration.performance.base.CpsPerfTestBase
-class CpsAdminServiceLimitsPerfTest extends CpsPerfTestBase {
+class CpsDataspaceServiceLimitsPerfTest extends CpsPerfTestBase {
- CpsAdminService objectUnderTest
+ CpsAnchorService objectUnderTest
- def setup() { objectUnderTest = cpsAdminService }
+ def setup() { objectUnderTest = cpsAnchorService }
def 'Get anchors from multiple schema set names limit exceeded: 32,766 (~ 2^15) schema set names.'() {
given: 'more than 32,766 schema set names'
def anchorNames = (1..10).collect {'delete' + it}
when: 'data nodes are deleted'
resourceMeter.start()
- cpsAdminService.deleteAnchors(CPS_PERFORMANCE_TEST_DATASPACE, anchorNames)
+ cpsAnchorService.deleteAnchors(CPS_PERFORMANCE_TEST_DATASPACE, anchorNames)
resourceMeter.stop()
def deleteDurationInSeconds = resourceMeter.getTotalTimeInSeconds()
then: 'delete duration is within expected time and memory used is within limit'
def 'Writing openroadm data has linear time.'() {
given: 'an empty anchor exists for openroadm'
- cpsAdminService.createAnchor(CPS_PERFORMANCE_TEST_DATASPACE, LARGE_SCHEMA_SET, 'writeAnchor')
+ cpsAnchorService.createAnchor(CPS_PERFORMANCE_TEST_DATASPACE, LARGE_SCHEMA_SET, 'writeAnchor')
and: 'a list of device nodes to add'
def jsonData = generateOpenRoadData(totalNodes)
when: 'device nodes are added'
recordAndAssertResourceUsage("Writing ${totalNodes} devices", expectedDuration, durationInSeconds, memoryLimit, resourceMeter.getTotalMemoryUsageInMB())
cleanup:
cpsDataService.deleteDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, 'writeAnchor', OffsetDateTime.now())
- cpsAdminService.deleteAnchor(CPS_PERFORMANCE_TEST_DATASPACE, 'writeAnchor')
+ cpsAnchorService.deleteAnchor(CPS_PERFORMANCE_TEST_DATASPACE, 'writeAnchor')
where:
totalNodes || expectedDuration | memoryLimit
50 || 4 | 100
def 'Writing bookstore data has exponential time.'() {
given: 'an anchor containing a bookstore with a single category'
- cpsAdminService.createAnchor(CPS_PERFORMANCE_TEST_DATASPACE, BOOKSTORE_SCHEMA_SET, 'writeAnchor')
+ cpsAnchorService.createAnchor(CPS_PERFORMANCE_TEST_DATASPACE, BOOKSTORE_SCHEMA_SET, 'writeAnchor')
def parentNodeData = '{"bookstore": { "categories": [{ "code": 1, "name": "Test", "books" : [] }] }}'
cpsDataService.saveData(CPS_PERFORMANCE_TEST_DATASPACE, 'writeAnchor', parentNodeData, OffsetDateTime.now())
and: 'a list of books to add'
recordAndAssertResourceUsage("Writing ${totalBooks} books", expectedDuration, durationInSeconds, memoryLimit, resourceMeter.getTotalMemoryUsageInMB())
cleanup:
cpsDataService.deleteDataNodes(CPS_PERFORMANCE_TEST_DATASPACE, 'writeAnchor', OffsetDateTime.now())
- cpsAdminService.deleteAnchor(CPS_PERFORMANCE_TEST_DATASPACE, 'writeAnchor')
+ cpsAnchorService.deleteAnchor(CPS_PERFORMANCE_TEST_DATASPACE, 'writeAnchor')
where:
totalBooks || expectedDuration | memoryLimit
800 || 1 | 50