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;
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);
}
}
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());
throw new ModelOnboardingException(message, exception.getMessage());
}
}
+
+ private void exitApplication(final ApplicationStartedEvent applicationStartedEvent) {
+ SpringApplication.exit(applicationStartedEvent.getApplicationContext(), () -> EXIT_CODE_ON_ERROR);
+ }
}
/*
* ============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");
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
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) }