diff options
author | emaclee <lee.anjella.macabuhay@est.tech> | 2024-01-17 11:59:29 +0000 |
---|---|---|
committer | emaclee <lee.anjella.macabuhay@est.tech> | 2024-01-17 17:51:19 +0000 |
commit | 723994d3a9fb5909c1035db7f520a07fb6995ee0 (patch) | |
tree | 3a6ec9af664959753ed8c02e4a680b1ecd6a3f09 /cps-ncmp-service/src/main/java/org | |
parent | f66fb4f4a8fb85ce717e97ef660c21fc70dd98a8 (diff) |
Create datastores for NCMP w/subscription model
Issue-ID: CPS-2035
Change-Id: I80234c7ca93c5774ee50082803cdc102f693a5a7
Signed-off-by: emaclee <lee.anjella.macabuhay@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/main/java/org')
3 files changed, 34 insertions, 10 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 bd8dec4dc8..a3ebec3c54 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 @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2023 Nordix Foundation + * Copyright (C) 2023-2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,8 +47,8 @@ abstract class AbstractModelLoader implements ModelLoader { private final CpsDataspaceService cpsDataspaceService; private final CpsModuleService cpsModuleService; - private final CpsDataService cpsDataService; private final CpsAnchorService cpsAnchorService; + protected final CpsDataService cpsDataService; private static final int EXIT_CODE_ON_ERROR = 1; 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 c0f0279ad4..81055db847 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 @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2023 Nordix Foundation + * Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,12 +21,16 @@ package org.onap.cps.ncmp.init; import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DATASPACE_NAME; +import static org.onap.cps.utils.ContentType.JSON; +import java.time.OffsetDateTime; import lombok.extern.slf4j.Slf4j; 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.exceptions.AlreadyDefinedException; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -38,6 +42,8 @@ public class CmDataSubscriptionModelLoader extends AbstractModelLoader { private static final String SCHEMASET_NAME = "cm-data-subscriptions"; private static final String ANCHOR_NAME = "cm-data-subscriptions"; private static final String REGISTRY_DATANODE_NAME = "datastores"; + private static final String DATASTORE_PASSTHROUGH_OPERATIONAL = "ncmp-datastores:passthrough-operational"; + private static final String DATASTORE_PASSTHROUGH_RUNNING = "ncmp-datastores:passthrough-running"; private static final String DEPRECATED_MODEL_FILENAME = "subscription.yang"; private static final String DEPRECATED_ANCHOR_NAME = "AVC-Subscriptions"; @@ -48,9 +54,9 @@ public class CmDataSubscriptionModelLoader extends AbstractModelLoader { public CmDataSubscriptionModelLoader(final CpsDataspaceService cpsDataspaceService, final CpsModuleService cpsModuleService, - final CpsDataService cpsDataService, - final CpsAnchorService cpsAnchorService) { - super(cpsDataspaceService, cpsModuleService, cpsDataService, cpsAnchorService); + final CpsAnchorService cpsAnchorService, + final CpsDataService cpsDataService) { + super(cpsDataspaceService, cpsModuleService, cpsAnchorService, cpsDataService); } @Value("${ncmp.model-loader.subscription:true}") @@ -75,5 +81,23 @@ public class CmDataSubscriptionModelLoader extends AbstractModelLoader { 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); + createDatastore(DATASTORE_PASSTHROUGH_OPERATIONAL, DATASTORE_PASSTHROUGH_RUNNING); } + + private void createDatastore(final String... datastoreNames) { + for (final String datastoreName : datastoreNames) { + final String nodeData = "{\"datastore\":[{\"name\":\"" + datastoreName + "\",\"cm-handles\":{}}]}"; + try { + cpsDataService.saveData(NCMP_DATASPACE_NAME, ANCHOR_NAME, "/" + REGISTRY_DATANODE_NAME, nodeData, + OffsetDateTime.now(), JSON); + } catch (final AlreadyDefinedException exception) { + log.info("Creating new child data node '{}' for data node '{}' failed as data node already exists", + datastoreName, REGISTRY_DATANODE_NAME); + } catch (final Exception exception) { + log.error("Creating data node failed: {}", exception.getMessage()); + throw new NcmpStartUpException("Creating data node failed", exception.getMessage()); + } + } + } + } 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 0e562cdd8b..01bfc2b5d4 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 @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2023 Nordix Foundation + * Copyright (C) 2023-2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,9 +39,9 @@ public class InventoryModelLoader extends AbstractModelLoader { public InventoryModelLoader(final CpsDataspaceService cpsDataspaceService, final CpsModuleService cpsModuleService, - final CpsDataService cpsDataService, - final CpsAnchorService cpsAnchorService) { - super(cpsDataspaceService, cpsModuleService, cpsDataService, cpsAnchorService); + final CpsAnchorService cpsAnchorService, + final CpsDataService cpsDataService) { + super(cpsDataspaceService, cpsModuleService, cpsAnchorService, cpsDataService); } @Override |