import org.onap.cps.init.ModelLoaderLock;
import org.onap.cps.init.actuator.ReadinessManager;
import org.onap.cps.ncmp.utils.events.NcmpInventoryModelOnboardingFinishedEvent;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;
@Order(2)
public class InventoryModelLoader extends AbstractModelLoader {
- private final DataMigration dataMigration;
private final ApplicationEventPublisher applicationEventPublisher;
- private static final String SCHEMA_SET_NAME = "dmi-registry-2024-02-23";
- private static final String NEW_INVENTORY_SCHEMA_SET_NAME = "dmi-registry-2025-07-22";
+ private static final String CURRENT_SCHEMA_SET_NAME = "dmi-registry-2024-02-23";
private static final String INVENTORY_YANG_MODULE_NAME = "dmi-registry";
- private static final int MIGRATION_BATCH_SIZE = 300;
-
- @Value("${ignore.r20250722.model:true}")
- private boolean ignoreModelR20250722;
/**
* Creates a new {@code InventoryModelLoader} instance responsible for onboarding or upgrading
public InventoryModelLoader(final ModelLoaderLock modelLoaderLock,
final CpsServicesBundle cpsServicesBundle,
final ApplicationEventPublisher applicationEventPublisher,
- final ReadinessManager readinessManager,
- final DataMigration dataMigration) {
+ final ReadinessManager readinessManager) {
super(modelLoaderLock,
cpsServicesBundle.getDataspaceService(),
cpsServicesBundle.getModuleService(),
cpsServicesBundle.getDataService(),
readinessManager);
this.applicationEventPublisher = applicationEventPublisher;
- this.dataMigration = dataMigration;
}
@Override
public void onboardOrUpgradeModel() {
if (isMaster) {
log.info("Model Loader #2 Started: NCMP Inventory Models");
- final String schemaToInstall =
- ignoreModelR20250722 ? SCHEMA_SET_NAME : NEW_INVENTORY_SCHEMA_SET_NAME;
- final String moduleRevision = getModuleRevision(schemaToInstall);
- log.info("Model Loader #2 Schema Set: {}", schemaToInstall);
-
if (isModuleRevisionInstalled(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, INVENTORY_YANG_MODULE_NAME,
- moduleRevision)) {
- log.info("Model Loader #2: Revision {} is already installed.", moduleRevision);
- } else if (!ignoreModelR20250722 && doesAnchorExist(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR)) {
- log.info("Model Loader #2: Upgrading already installed inventory to revision {}.", moduleRevision);
- upgradeAndMigrateInventoryModel();
+ CURRENT_SCHEMA_SET_NAME)) {
+ log.info("Model Loader #2: Revision {} is already installed.", CURRENT_SCHEMA_SET_NAME);
+ } else if (doesAnchorExist(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR)) {
+ log.info("Model Loader #2: Upgrading already installed inventory to revision {}.",
+ CURRENT_SCHEMA_SET_NAME);
+ upgradeInventoryModel();
} else {
- log.info("Model Loader #2: New installation using inventory model revision {}.", moduleRevision);
- installInventoryModel(schemaToInstall);
+ log.info("Model Loader #2: New installation using inventory model revision {}.",
+ CURRENT_SCHEMA_SET_NAME);
+ installInventoryModel();
}
applicationEventPublisher.publishEvent(new NcmpInventoryModelOnboardingFinishedEvent(this));
log.info("Model Loader #2 Completed");
}
}
- private void installInventoryModel(final String schemaSetName) {
+ private void installInventoryModel() {
createDataspace(NCMP_DATASPACE_NAME);
createDataspace(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME);
- final String yangFileName = toYangFileName(schemaSetName);
- createSchemaSet(NCMP_DATASPACE_NAME, schemaSetName, yangFileName);
- createAnchor(NCMP_DATASPACE_NAME, schemaSetName, NCMP_DMI_REGISTRY_ANCHOR);
+ final String yangFileName = toYangFileName(CURRENT_SCHEMA_SET_NAME);
+ createSchemaSet(NCMP_DATASPACE_NAME, CURRENT_SCHEMA_SET_NAME, yangFileName);
+ createAnchor(NCMP_DATASPACE_NAME, CURRENT_SCHEMA_SET_NAME, NCMP_DMI_REGISTRY_ANCHOR);
createTopLevelDataNode(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, INVENTORY_YANG_MODULE_NAME);
deleteOldButNotThePreviousSchemaSets();
- log.info("Model Loader #2: Inventory model {} installed successfully,", schemaSetName);
+ log.info("Model Loader #2: Inventory model {} installed successfully,", CURRENT_SCHEMA_SET_NAME);
}
private void deleteOldButNotThePreviousSchemaSets() {
}
private void upgradeInventoryModel() {
- final String yangFileName = toYangFileName(NEW_INVENTORY_SCHEMA_SET_NAME);
- createSchemaSet(NCMP_DATASPACE_NAME, NEW_INVENTORY_SCHEMA_SET_NAME, yangFileName);
+ final String yangFileName = toYangFileName(CURRENT_SCHEMA_SET_NAME);
+ createSchemaSet(NCMP_DATASPACE_NAME, CURRENT_SCHEMA_SET_NAME, yangFileName);
cpsAnchorService.updateAnchorSchemaSet(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- NEW_INVENTORY_SCHEMA_SET_NAME);
- log.info("Model Loader #2: Inventory upgraded successfully to model {}", NEW_INVENTORY_SCHEMA_SET_NAME);
+ CURRENT_SCHEMA_SET_NAME);
+ log.info("Model Loader #2: Inventory upgraded successfully to model {}", CURRENT_SCHEMA_SET_NAME);
}
private static String toYangFileName(final String schemaSetName) {
return schemaSetName.substring(INVENTORY_YANG_MODULE_NAME.length() + 1);
}
- private void upgradeAndMigrateInventoryModel() {
- upgradeInventoryModel();
- dataMigration.migrateInventoryToModelRelease20250722(MIGRATION_BATCH_SIZE);
- }
}
def mockApplicationEventPublisher = Mock(ApplicationEventPublisher)
def mockReadinessManager = Mock(ReadinessManager)
- def mockDataMigration = Mock(DataMigration)
- def objectUnderTest = new InventoryModelLoader(mockModelLoaderLock, cpsServices, mockApplicationEventPublisher, mockReadinessManager, mockDataMigration)
+ def objectUnderTest = new InventoryModelLoader(mockModelLoaderLock, cpsServices, mockApplicationEventPublisher, mockReadinessManager)
def applicationContext = new AnnotationConfigApplicationContext()
- def expectedPreviousYangResourceToContentMap
def expectedNewYangResourceToContentMap
def logger = (Logger) LoggerFactory.getLogger(objectUnderTest.class)
def loggingListAppender
void setup() {
objectUnderTest.isMaster = true
- expectedPreviousYangResourceToContentMap = objectUnderTest.mapYangResourcesToContent('dmi-registry@2024-02-23.yang')
- expectedNewYangResourceToContentMap = objectUnderTest.mapYangResourcesToContent('dmi-registry@2025-07-22.yang')
- objectUnderTest.ignoreModelR20250722 = false
+ expectedNewYangResourceToContentMap = objectUnderTest.mapYangResourcesToContent('dmi-registry@2024-02-23.yang')
logger.setLevel(Level.DEBUG)
loggingListAppender = new ListAppender()
logger.addAppender(loggingListAppender)
def 'Onboard subscription model via application ready event.'() {
given: 'dataspace is ready for use with current model'
- objectUnderTest.ignoreModelR20250722 = true
mockCpsAdminService.getDataspace(NCMP_DATASPACE_NAME) >> new Dataspace('')
and: 'module revision does not exist'
mockCpsModuleService.getModuleDefinitionsByAnchorAndModule(_, _, _, _) >> Collections.emptyList()
when: 'the application is ready'
objectUnderTest.onApplicationEvent(Mock(ApplicationReadyEvent))
then: 'the module service is used to create the new schema set from the correct resource'
- 1 * mockCpsModuleService.createSchemaSet(NCMP_DATASPACE_NAME, 'dmi-registry-2024-02-23', expectedPreviousYangResourceToContentMap)
+ 1 * mockCpsModuleService.createSchemaSet(NCMP_DATASPACE_NAME, 'dmi-registry-2024-02-23', expectedNewYangResourceToContentMap)
and: 'No schema sets are being removed by the module service (yet)'
0 * mockCpsModuleService.deleteSchemaSet(NCMP_DATASPACE_NAME, _, _)
and: 'application event publisher is called once'
when: 'the inventory model loader is triggered'
objectUnderTest.onboardOrUpgradeModel()
then: 'a new schema set for the 2025-07-22 revision is installed'
- 1 * mockCpsModuleService.createSchemaSet(NCMP_DATASPACE_NAME, 'dmi-registry-2025-07-22', expectedNewYangResourceToContentMap)
+ 1 * mockCpsModuleService.createSchemaSet(NCMP_DATASPACE_NAME, 'dmi-registry-2024-02-23', expectedNewYangResourceToContentMap)
}
def 'Upgrade model revision'() {
when: 'the inventory model loader is triggered'
objectUnderTest.onboardOrUpgradeModel()
then: 'the new schema set for the 2025-07-22 revision is created'
- 1 * mockCpsModuleService.createSchemaSet(NCMP_DATASPACE_NAME, 'dmi-registry-2025-07-22', expectedNewYangResourceToContentMap)
+ 1 * mockCpsModuleService.createSchemaSet(NCMP_DATASPACE_NAME, 'dmi-registry-2024-02-23', expectedNewYangResourceToContentMap)
and: 'the anchor is updated to point to the new schema set'
- 1 * mockCpsAnchorService.updateAnchorSchemaSet(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, 'dmi-registry-2025-07-22')
+ 1 * mockCpsAnchorService.updateAnchorSchemaSet(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, 'dmi-registry-2024-02-23')
and: 'log messages confirm successful upgrade'
assert loggingListAppender.list.any { it.message.contains("Inventory upgraded successfully") }
}
0 * mockCpsModuleService.createSchemaSet(*_)
}
-
def 'Skip upgrade model revision when new revision already installed'() {
given: 'the anchor exists and the new model revision is already installed'
mockCpsAnchorService.getAnchor(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR) >> {}
assert loggingListAppender.list.any { it.message.contains("already installed") }
}
- def "Perform inventory data migration to Release20250722"() {
- when: 'the migration is performed'
- objectUnderTest.upgradeAndMigrateInventoryModel()
- then: 'the call is delegated to the Data Migration service'
- 1 * mockDataMigration.migrateInventoryToModelRelease20250722(_)
- }
-
-
-
}