References:
Jira Legacy server System Jira serverId 4733707d-2057-3a0f-ae5e-4fd8aff50176 key CPS-875 - CPS-898 Create method to lock and unlock an anchor
- https://wiki.onap.org/display/DW/CPS-899+Start+and+stop+sessions+on+Java+API
- https://docs.onap.org/projects/onap-cps/en/latest/cps-path.html
Spring '@Schedule' annotation
Using Spring '@Schedule' annotation, it is possible to schdule schedule tasks which allows that allow us to create a watchdog.
To enable spring boot to recognise and support scheduled tasks, it is necessary to add '@EnableScheduling' as shown below
Then, all methods that is are annotated with '@Schedule' is reccognised are recognised as a scheduled taskes task depending on the configuration placed.
For the example below, the method 'sayHello()' is configured to run at a fixed rate of 1000ms. Fixed-rate will invoke the task at every every n millisecond and is useful for independent tasks.
...
Scheduled tasks can be configured in the following ways :
Description | Notes | |
---|---|---|
Fixed-rate |
| |
Fixed-delay |
| |
Initial delay |
|
...
| ||
Cron |
|
Querying state and timestamp
In NCMP, dataspace and acnhor anchor is hardcoded
name | value |
---|---|
NCMP_DATASPACE_NAME | NCMP-Admin |
NCMP_DMI_REGISTRY_ANCHOR | ncmp-dmi-registry |
NCMP_DMI_REGISTRY_PARENT | /dmi-registry |
Gliffy | ||||||||
---|---|---|---|---|---|---|---|---|
|
...
The following tree diagram reflects the new dmi-registry yan yang model which will have the leaves 'state' and 'lock-reason'
Based on the CPS path formats (see https://docs.onap.org/projects/onap-cps/en/latest/cps-path.html) and the above tree diagrams, it was tested that the following path allows accessing the 'state' leaf node attribute:
Wherein the test values are:
Code Block | ||
---|---|---|
| ||
INSERT INTO FRAGMENT (ID, DATASPACE_ID, ANCHOR_ID, PARENT_ID, XPATH, ATTRIBUTES) VALUES
(21, 1001, 1003, 1, '/dmi-registry', '{}'),
(22, 1001, 1003, 9, '/dmi-registry/cm-handles[@id="PNFDemo"]', '{"id": "PNFDemo","dmi-service-name": "http://172.18.192.19:8783","dmi-data-service-name": "","dmi-model-service-name": ""}'),
(23, 1001, 1003, 10,'/dmi-registry/cm-handles[@id="sampleId_1"]/additional-properties[@name="Book1"]', '{"name": "Book1", "value": "Romance Book"}'),
(24, 1001, 1003, 9, '/dmi-registry/cm-handles[@id="sampleId_2"]', '{"id": "sampleId_2","dmi-service-name": "http://172.18.192.19:8783","state": "ADVISED"}'),
(25, 1001, 1003, 9, '/dmi-registry/cm-handles[@id="sampleId_3"]', '{"id": "sampleId_3","dmi-service-name": "http://172.18.192.19:8783","state": "READY"}'),
(26, 1001, 1003, 9, '/dmi-registry/cm-handles[@id="sampleId_4"]', '{"id": "sampleId_4","dmi-service-name": "http://172.18.192.19:8783","state": "ADVISED"}'); |
and the groovy test:
Code Block | ||
---|---|---|
| ||
@Sql([CLEAR_DATA, SET_DATA])
def 'SAMPLE: Cps Path query to determine nodes with #scenario'() {
when: 'a query is executed to get a data node by the given cps path'
def result = objectUnderTest.queryDataNodes(DATASPACE_NAME, ANCHOR_FOR_SHOP_EXAMPLE, cpsPath, OMIT_DESCENDANTS)
then: 'the correct number of data nodes are retrieved'
result.size() == expectedXPaths.size()
and: 'xpaths of the retrieved data nodes are as expected'
for (int i = 0; i < result.size(); i++) {
assert result[i].getXpath() == expectedXPaths[i]
}
where: 'the following data is used'
scenario | cpsPath || expectedXPaths
' ' | '//cm-handles[@id="PNFDemo"]' || ['/dmi-registry/cm-handles[@id="PNFDemo"]']
' ' | '//additional-properties[@value="Romance Book"]' || ['/dmi-registry/cm-handles[@id="sampleId_1"]/additional-properties[@name="Book1"]']
' ' | '//cm-handles[@state="ADVISED"]' || ['/dmi-registry/cm-handles[@id="sampleId_2"]','/dmi-registry/cm-handles[@id="sampleId_4"]'] |
DB locking
Database locking is performed after retrieving a node with the status of 'ADVISED'. This is to ensure that we prevent multiple instances of NCMP accessing a cm handle, this will also ensure that model syncs will not fail.
For more information on issues and decisions for DB locking, please see CPS-898 Create method to lock and unlock an anchor.