- Simplified conditional flow by removing duplicate revision checks.
Issue-ID: CPS-2974
Change-Id: I8e5ca62c60a33eb01abffbd917a98e18fefb22f0
Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech>
@Override
public void onboardOrUpgradeModel() {
final String schemaToInstall = newRevisionEnabled ? NEW_INVENTORY_SCHEMA_SET_NAME : PREVIOUS_SCHEMA_SET_NAME;
- if (newRevisionEnabled) {
- if (doesAnchorExist(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR)) {
- final String moduleRevision = getModuleRevision(schemaToInstall);
- if (isModuleRevisionInstalled(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, INVENTORY_YANG_MODULE_NAME,
- moduleRevision)) {
- log.info("Revision {} is already installed.", moduleRevision);
- } else {
- upgradeInventoryModel();
- performInventoryDataMigration();
- }
- } else {
- installInventoryModel(schemaToInstall);
- }
+ final String moduleRevision = getModuleRevision(schemaToInstall);
+
+ if (isModuleRevisionInstalled(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, INVENTORY_YANG_MODULE_NAME,
+ moduleRevision)) {
+ log.info("Revision {} is already installed.", moduleRevision);
+ } else if (newRevisionEnabled && doesAnchorExist(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR)) {
+ upgradeAndMigrateInventoryModel();
} else {
installInventoryModel(schemaToInstall);
}
+
applicationEventPublisher.publishEvent(new NcmpInventoryModelOnboardingFinishedEvent(this));
}
// TODO further implementation is pending
//1. Load all the cm handles (in batch)
//2. Copy the state and known properties
- log.info("Starting inventory module data migration...");
-
- // Simulate a 4-minute migration (240 seconds total)
- final int totalSeconds = 240;
- final int stepSeconds = 30; // log progress every 30 seconds
- final int steps = totalSeconds / stepSeconds;
-
- for (int i = 1; i <= steps; i++) {
- try {
- Thread.sleep(stepSeconds * 1000L);
- } catch (final InterruptedException e) {
- Thread.currentThread().interrupt();
- log.warn("Migration interrupted!", e);
- return;
- }
- final int progress = (i * 100) / steps;
- log.info("Migration progress: {}%", progress);
- }
log.info("Inventory module data migration is completed successfully.");
}
// Extract the revision part ( for example: 2024-02-23)
return schemaSetName.substring(INVENTORY_YANG_MODULE_NAME.length() + 1);
}
+
+ private void upgradeAndMigrateInventoryModel() {
+ upgradeInventoryModel();
+ performInventoryDataMigration();
+ }
}
}
def 'Onboard subscription model via application ready event.'() {
- given: 'dataspace is ready for use'
+ given: 'dataspace is ready for use with default newRevisionEnabled flag'
objectUnderTest.newRevisionEnabled = false
mockCpsAdminService.getDataspace(NCMP_DATASPACE_NAME) >> new Dataspace('')
+ and: 'module revision does not exist'
+ mockCpsModuleService.getModuleDefinitionsByAnchorAndModule(_, _, _, _) >> Collections.emptyList()
when: 'the application is started'
objectUnderTest.onApplicationEvent(Mock(ApplicationStartedEvent))
then: 'the module service is used to create the new schema set from the correct resource'
}
def 'Install new model revision'() {
- given: 'the anchor does not exist'
+ given: 'the anchor and module revision does not exist'
mockCpsAnchorService.getAnchor(_, _) >> { throw new AnchorNotFoundException('', '') }
+ mockCpsModuleService.getModuleDefinitionsByAnchorAndModule(_, _, _, _) >> Collections.emptyList()
when: 'the inventory model loader is triggered'
objectUnderTest.onboardOrUpgradeModel()
then: 'a new schema set for the 2025-07-22 revision is installed'
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-actuator</artifactId>
- </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-actuator</artifactId>
+ </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
}
}
+ /**
+ * Checks if the specified revision of a module is installed.
+ */
+ protected boolean isModuleRevisionInstalled(final String dataspaceName, final String anchorName,
+ final String moduleName, final String moduleRevision) {
+ final Collection<ModuleDefinition> moduleDefinitions =
+ cpsModuleService.getModuleDefinitionsByAnchorAndModule(dataspaceName, anchorName, moduleName,
+ moduleRevision);
+ return !moduleDefinitions.isEmpty();
+ }
+
Map<String, String> mapYangResourcesToContent(final String... resourceNames) {
final Map<String, String> yangResourceContentByName = new HashMap<>();
for (final String resourceName: resourceNames) {
}
}
- /**
- * Checks if the specified revision of a module is installed.
- */
- protected boolean isModuleRevisionInstalled(final String dataspaceName, final String anchorName,
- final String moduleName, final String moduleRevision) {
- final Collection<ModuleDefinition> moduleDefinitions =
- cpsModuleService.getModuleDefinitionsByAnchorAndModule(dataspaceName, anchorName, moduleName,
- moduleRevision);
- return !moduleDefinitions.isEmpty();
- }
-
private void exitApplication(final ApplicationStartedEvent applicationStartedEvent) {
SpringApplication.exit(applicationStartedEvent.getApplicationContext(), () -> EXIT_CODE_ON_ERROR);
}
return Health.up()
.withDetail("Startup Processes", "All startup processes completed")
.build();
- } else {
- return Health.down()
- .withDetail("Startup Processes active", readinessManager.getStartupProcessesAsString())
- .build();
}
+ return Health.down()
+ .withDetail("Startup Processes active", readinessManager.getStartupProcessesAsString())
+ .build();
}
}