...
To load a yang resource, create a new yang resource csv file to load the data (as outlined above) in the following format 'yang_resource_@*datadate-of-creation*'
Code Block |
---|
language | bash |
---|
title | yang_resource@2021-12-13.csv |
---|
collapse | true |
---|
|
name|content|checksum
dmi-registry@2021-12-13.yang|"module dmi-registry {
yang-version 1.1;
namespace \"org:onap:cps:ncmp\";
prefix dmi-reg;
organization \"Nordix Foundation\";
contact \"rahul.tyagi@est.tech\";
revision \"2021-12-13\" {
description
\"Added new list of public additonal properties for a Cm-Handle which are exposed to clients of the NCMP interface. \";
}
container dmi-registry {
list cm-handles {
key \"id\";
leaf id {
type string;
}
leaf dmi-service-name {
type string;
}
leaf dmi-data-service-name {
type string;
}
leaf dmi-model-service-name {
type string;
}
list additional-properties {
key \"name\";
leaf name {
type string;
}
leaf value {
type string;
}
}
list public-additional-properties {
key \"name\";
leaf name {
type string;
}
leaf value {
type string;
}
}
}
}
}
"|4899c384835ec48194ab5e3837549d32b844e02cfc81e9205234fa36354f3fe4 |
...
Generating Checksum For New Yang Resource
First copy the content from the CSV file above and create a YANG file locally with it with the format 'dmi-registry@*date-of-creation*'.
Run the following command to insert a new yang resource into the yang_resource table with a the checksum generated.
Note |
---|
CPS Application must be deployed from before running this command. |
...
Code Block |
---|
|
curl --location --request POST 'http://localhost:8080/cps/api/v1/dataspaces/*dataspacename*/schema-sets' --header 'Authorization: Basic Y3BzdXNlcjpjcHNyMGNrcyE=' --form 'file=*PATH-TO-YANG-FILE-ON-LOCAL*' --form 'schema-set-name='*NAME-OF-SCEHMA-SET-DEFINED-IN-YANG_RESOURCE*' |
Add the generated checksum into the yang resource csv above.
Once this is done, then add the change-set for yang resource you have created to load the data into the liquibase DB.
Code Block |
---|
language | yml |
---|
title | Yang resource Change set example |
---|
collapse | true |
---|
|
- changeSet:
author: cps
label: dmi-registry-schema-preload
id: 9.7
loadUpdateData:
encoding: UTF-8
file: 'changelog/db/changes/data/dmi/yang_resource@2021-12-13.csv'
onlyUpdate: 'false'
primaryKey: 'id'
quotchar: '"'
separator: '|'
tableName: 'yang_resource'
columns:
- column:
header: name
name: name
type: STRING
- column:
header: content
name: content
type: STRING
- column:
header: checksum
name: checksum
type: STRING
rollback:
- sql:
sql: delete from yang_resource where name = 'dmi-registry@2021-12-13.yang' |
Yang Resource Schema Set
Data will also need to be inserted into the yang_resource_schema_set table to create a mapping between the new yang resource and the necessary schema set.
Create a csv to define the data in the format of 'schema_set_yang_resources@*date-of-creation*'
Code Block |
---|
language | bash |
---|
title | yang_resource@2021-12-13.csv |
---|
collapse | true |
---|
|
schema_set_id|yang_resource_id
(select id from schema_set where name='ncmp-dmi-registry-model')|(select id from yang_resource where name='dmi-registry@2021-12-13.yang') |
Then add the change-set to the relevent change-log YAML file
Code Block |
---|
language | yml |
---|
title | Yang resource Change set example |
---|
collapse | true |
---|
|
- changeSet:
author: cps
label: dmi-registry-schema-preload
id: 9.8
loadUpdateData:
encoding: UTF-8
file: 'changelog/db/changes/data/dmi/schema_set_yang_resources@2021-12-13.csv'
quotchar: '"'
primaryKey: 'schema_set_id,yang_resource_id'
separator: '|'
tableName: 'schema_set_yang_resources'
usePreparedStatements: true
rollback:
- sql:
sql: >
delete from schema_set_yang_resources
where schema_set_id = (select id from schema_set where name = 'ncmp-dmi-registry-model')
and yang_resource_id = (select id from yang_resource where name = 'dmi-registry@2021-12-23.yang') |
Rollback
As seen above, the rollback tag is included within the change-set in the case that and updates made need to be reverted.
Types of Rollback
To run the rollback to revert a specified number of change-sets sequentially run the following command with the number of change-sets you want to run back.
Code Block |
---|
language | bash |
---|
title | yang_resource@2021-12-13.csv |
---|
|
mvn compile org.liquibase:liquibase-maven-plugin:4.3.1:rollback -Dliquibase.rollbackCount=*number-of-change-sets-to-rollback* -Dliquibase.url=jdbc:postgresql://localhost:5432/cpsdb -Dliquibase.username=cps -Dliquibase.password=cps -Dliquibase.changeLogFile=src/main/resources/changelog/changelog-master.yaml |
To run the rollback to revert all changes to a database that were made after a specific tag
Code Block |
---|
language | bash |
---|
title | yang_resource@2021-12-13.csv |
---|
|
mvn compile org.liquibase:liquibase-maven-plugin:4.3.1:rollback -Dliquibase.rollbackTag=*liquibase-tag-to-rollback-to* -Dliquibase.url=jdbc:postgresql://localhost:5432/cpsdb -Dliquibase.username=cps -Dliquibase.password=cps -Dliquibase.changeLogFile=src/main/resources/changelog/changelog-master.yaml |
To run the rollback to revert all changes back to a specific date run.
Code Block |
---|
language | bash |
---|
title | yang_resource@2021-12-13.csv |
---|
|
mvn compile org.liquibase:liquibase-maven-plugin:4.3.1:rollback -Dliquibase.rollbackDate=*date-to-rollback-to* -Dliquibase.url=jdbc:postgresql://localhost:5432/cpsdb -Dliquibase.username=cps -Dliquibase.password=cps -Dliquibase.changeLogFile=src/main/resources/changelog/changelog-master.yaml |
Potential Issues