summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service
diff options
context:
space:
mode:
authorToine Siebelink <toine.siebelink@est.tech>2024-03-26 16:38:50 +0000
committerGerrit Code Review <gerrit@onap.org>2024-03-26 16:38:50 +0000
commitbdc3fae4230ea23accfae66f250526d51f3b3210 (patch)
treeb762ee11348917894cc20d2d033e3d14e1511ee0 /cps-ncmp-service
parent13a9b02bb46f77c6300a93f5e581206e58947e1e (diff)
parent23378b5639b0563382ac98761ae4cf2d9786453b (diff)
Merge "Condense Liquibase steps"
Diffstat (limited to 'cps-ncmp-service')
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/AbstractModelLoader.java29
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/CmDataSubscriptionModelLoader.java2
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/InventoryModelLoader.java9
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/AbstractModelLoaderSpec.groovy8
4 files changed, 19 insertions, 29 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/AbstractModelLoader.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/AbstractModelLoader.java
index a3ebec3c54..4cc8cdaa66 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/AbstractModelLoader.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/AbstractModelLoader.java
@@ -70,24 +70,6 @@ abstract class AbstractModelLoader implements ModelLoader {
}
}
- void waitUntilDataspaceIsAvailable(final String dataspaceName) {
- log.info("Model Loader start-up, waiting for database to be ready");
- int attemptCount = 0;
- while (cpsDataspaceService.getDataspace(dataspaceName) == null) {
- if (attemptCount < maximumAttemptCount) {
- try {
- Thread.sleep(attemptCount * retryTimeMs);
- log.info("Retrieving dataspace {} ... {} attempt(s) ", dataspaceName, ++attemptCount);
- } catch (final InterruptedException e) {
- Thread.currentThread().interrupt();
- }
- } else {
- throw new NcmpStartUpException("Retrieval of NCMP dataspace failed",
- dataspaceName + " not available (yet)");
- }
- }
- }
-
void createSchemaSet(final String dataspaceName, final String schemaSetName, final String... resourceNames) {
try {
final Map<String, String> yangResourcesContentMap = createYangResourcesToContentMap(resourceNames);
@@ -100,6 +82,17 @@ abstract class AbstractModelLoader implements ModelLoader {
}
}
+ void createDataspace(final String dataspaceName) {
+ try {
+ cpsDataspaceService.createDataspace(dataspaceName);
+ } catch (final AlreadyDefinedException alreadyDefinedException) {
+ log.debug("Dataspace already exists");
+ } catch (final Exception exception) {
+ log.error("Creating dataspace failed: {} ", exception.getMessage());
+ throw new NcmpStartUpException("Creating dataspace failed", exception.getMessage());
+ }
+ }
+
void deleteUnusedSchemaSets(final String dataspaceName, final String... schemaSetNames) {
for (final String schemaSetName : schemaSetNames) {
try {
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/CmDataSubscriptionModelLoader.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/CmDataSubscriptionModelLoader.java
index 4c31719a29..a0b7bd5826 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/CmDataSubscriptionModelLoader.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/CmDataSubscriptionModelLoader.java
@@ -51,12 +51,12 @@ public class CmDataSubscriptionModelLoader extends AbstractModelLoader {
@Override
public void onboardOrUpgradeModel() {
- waitUntilDataspaceIsAvailable(NCMP_DATASPACE_NAME);
onboardSubscriptionModels();
log.info("Subscription Models onboarded successfully");
}
private void onboardSubscriptionModels() {
+ createDataspace(NCMP_DATASPACE_NAME);
createSchemaSet(NCMP_DATASPACE_NAME, SCHEMASET_NAME, MODEL_FILENAME);
createAnchor(NCMP_DATASPACE_NAME, SCHEMASET_NAME, ANCHOR_NAME);
createTopLevelDataNode(NCMP_DATASPACE_NAME, ANCHOR_NAME, REGISTRY_DATANODE_NAME);
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/InventoryModelLoader.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/InventoryModelLoader.java
index d0d63ab8eb..7c25953f0d 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/InventoryModelLoader.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/init/InventoryModelLoader.java
@@ -22,6 +22,7 @@ package org.onap.cps.ncmp.init;
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.ncmp.api.impl.ncmppersistence.NcmpPersistence.NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME;
import lombok.extern.slf4j.Slf4j;
import org.onap.cps.api.CpsAnchorService;
@@ -33,9 +34,9 @@ import org.springframework.stereotype.Service;
@Slf4j
@Service
public class InventoryModelLoader extends AbstractModelLoader {
-
private static final String NEW_MODEL_FILE_NAME = "dmi-registry@2024-02-23.yang";
private static final String NEW_SCHEMA_SET_NAME = "dmi-registry-2024-02-23";
+ private static final String REGISTRY_DATANODE_NAME = "dmi-registry";
public InventoryModelLoader(final CpsDataspaceService cpsDataspaceService,
final CpsModuleService cpsModuleService,
@@ -46,20 +47,24 @@ public class InventoryModelLoader extends AbstractModelLoader {
@Override
public void onboardOrUpgradeModel() {
- waitUntilDataspaceIsAvailable(NCMP_DATASPACE_NAME);
updateInventoryModel();
log.info("Inventory Model updated successfully");
}
private void updateInventoryModel() {
+ createDataspace(NCMP_DATASPACE_NAME);
+ createDataspace(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME);
createSchemaSet(NCMP_DATASPACE_NAME, NEW_SCHEMA_SET_NAME, NEW_MODEL_FILE_NAME);
+ createAnchor(NCMP_DATASPACE_NAME, NEW_SCHEMA_SET_NAME, NCMP_DMI_REGISTRY_ANCHOR);
updateAnchorSchemaSet(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, NEW_SCHEMA_SET_NAME);
+ createTopLevelDataNode(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, REGISTRY_DATANODE_NAME);
deleteOldButNotThePreviousSchemaSets();
}
private void deleteOldButNotThePreviousSchemaSets() {
//No schema sets passed in yet, but wil be required for future updates
deleteUnusedSchemaSets(NCMP_DATASPACE_NAME);
+ deleteUnusedSchemaSets(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME);
}
}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/AbstractModelLoaderSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/AbstractModelLoaderSpec.groovy
index f122b57634..b0be29d933 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/AbstractModelLoaderSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/init/AbstractModelLoaderSpec.groovy
@@ -81,14 +81,6 @@ class AbstractModelLoaderSpec extends Specification {
assert logs.contains('test message')
}
- def 'Wait for non-existing dataspace'() {
- when: 'wait for the dataspace'
- objectUnderTest.waitUntilDataspaceIsAvailable('some dataspace')
- then: 'a startup exception is thrown'
- def thrown = thrown(NcmpStartUpException)
- assert thrown.message.contains('Retrieval of NCMP dataspace failed')
- }
-
def 'Create schema set.'() {
when: 'creating a schema set'
objectUnderTest.createSchemaSet('some dataspace','new name','cm-data-subscriptions@2024-02-12.yang')