aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPriyank Maheshwari <priyank.maheshwari@est.tech>2025-02-20 17:13:33 +0000
committerGerrit Code Review <gerrit@onap.org>2025-02-20 17:13:33 +0000
commit5114f2d5a05721531074d79261346751beb269d8 (patch)
treedfb1a18e93b8e815587a2af105b61a0a7f2474b4
parent138cae7d9d060c0f194eccb213fa2aa4cbac7105 (diff)
parentdfc9aa481470129710746d3e614f0b394548312a (diff)
Merge "Handle duplicated yang resource exception when creating schema set"
-rw-r--r--cps-service/src/main/java/org/onap/cps/init/AbstractModelLoader.java13
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/init/AbstractModelLoaderSpec.groovy13
2 files changed, 22 insertions, 4 deletions
diff --git a/cps-service/src/main/java/org/onap/cps/init/AbstractModelLoader.java b/cps-service/src/main/java/org/onap/cps/init/AbstractModelLoader.java
index a80239039a..df068c68a6 100644
--- a/cps-service/src/main/java/org/onap/cps/init/AbstractModelLoader.java
+++ b/cps-service/src/main/java/org/onap/cps/init/AbstractModelLoader.java
@@ -34,6 +34,7 @@ import org.onap.cps.api.CpsDataService;
import org.onap.cps.api.CpsDataspaceService;
import org.onap.cps.api.CpsModuleService;
import org.onap.cps.api.exceptions.AlreadyDefinedException;
+import org.onap.cps.api.exceptions.DuplicatedYangResourceException;
import org.onap.cps.api.exceptions.ModelOnboardingException;
import org.onap.cps.api.parameters.CascadeDeleteAllowed;
import org.onap.cps.utils.JsonObjectMapper;
@@ -57,10 +58,10 @@ public abstract class AbstractModelLoader implements ModelLoader {
public void onApplicationEvent(final ApplicationStartedEvent applicationStartedEvent) {
try {
onboardOrUpgradeModel();
- } catch (final Exception modelOnboardUpException) {
+ } catch (final Exception exception) {
log.error("Exiting application due to failure in onboarding model: {} ",
- modelOnboardUpException.getMessage());
- SpringApplication.exit(applicationStartedEvent.getApplicationContext(), () -> EXIT_CODE_ON_ERROR);
+ exception.getMessage());
+ exitApplication(applicationStartedEvent);
}
}
@@ -76,6 +77,8 @@ public abstract class AbstractModelLoader implements ModelLoader {
cpsModuleService.createSchemaSet(dataspaceName, schemaSetName, yangResourcesContentByResourceName);
} catch (final AlreadyDefinedException alreadyDefinedException) {
log.warn("Creating new schema set failed as schema set already exists");
+ } catch (final DuplicatedYangResourceException duplicatedYangResourceException) {
+ log.warn("Ignoring yang resource duplication exception. Assuming model was created by another instance");
} catch (final Exception exception) {
log.error("Creating schema set {} failed: {} ", schemaSetName, exception.getMessage());
throw new ModelOnboardingException("Creating schema set failed", exception.getMessage());
@@ -180,4 +183,8 @@ public abstract class AbstractModelLoader implements ModelLoader {
throw new ModelOnboardingException(message, exception.getMessage());
}
}
+
+ private void exitApplication(final ApplicationStartedEvent applicationStartedEvent) {
+ SpringApplication.exit(applicationStartedEvent.getApplicationContext(), () -> EXIT_CODE_ON_ERROR);
+ }
}
diff --git a/cps-service/src/test/groovy/org/onap/cps/init/AbstractModelLoaderSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/init/AbstractModelLoaderSpec.groovy
index 0618cad951..c3cb4f205b 100644
--- a/cps-service/src/test/groovy/org/onap/cps/init/AbstractModelLoaderSpec.groovy
+++ b/cps-service/src/test/groovy/org/onap/cps/init/AbstractModelLoaderSpec.groovy
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2023-2024 Nordix Foundation
+ * Copyright (C) 2023-2025 Nordix Foundation
* Modification Copyright (C) 2024 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -28,6 +28,7 @@ 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.exceptions.DuplicatedYangResourceException
import org.onap.cps.api.exceptions.ModelOnboardingException
import org.onap.cps.api.parameters.CascadeDeleteAllowed
import org.onap.cps.api.exceptions.AlreadyDefinedException
@@ -117,6 +118,16 @@ class AbstractModelLoaderSpec extends Specification {
1 * mockCpsModuleService.createSchemaSet('some dataspace','new name',_)
}
+ def 'Creating a schema set handles duplicated yang resource exception'() {
+ given: 'module service throws duplicated yang resource exception'
+ mockCpsModuleService.createSchemaSet(*_) >> { throw new DuplicatedYangResourceException('my-yang-resource', 'my-yang-resource-checksum', null) }
+ when: 'attempt to create a schema set'
+ objectUnderTest.createSchemaSet('some dataspace','some schema set','cps-notification-subscriptions@2024-07-03.yang')
+ then: 'exception is ignored, and correct exception message is logged'
+ noExceptionThrown()
+ assertLogContains('Ignoring yang resource duplication exception. Assuming model was created by another instance')
+ }
+
def 'Creating a schema set handles already defined exception.'() {
given: 'the module service throws an already defined exception'
mockCpsModuleService.createSchemaSet(*_) >> { throw AlreadyDefinedException.forSchemaSet('name','context',null) }