Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Issues/Decisions

Add/Remove/Update properties as part of CM-handle registration update
#IssueNotesDecision
1Existing property not part of the update should not be updated/removed.
In the updatedCmHandles request , if we don't provide any existing property in the update , then we don't touch that property and it will remain as it is.
See below : Req-002 has "prop3": "value3" which is not part of the update , hence it will remain as it is.

Scope

  • Within the NCMP CM-Handle registration post request add functionality to add/remove properties of an existing CM-Handle.
  • Properties are removed by setting the value to null in the update registration request. (Only applicable when updatedCmHandles json tag is present)
  • Both Additional and Public properties should be taken care off as part of the update.
  • Update Open API docs with details on property updates.

Analysis

REST layer

  • No change as there is no update in the incoming request structure.

Service layer (cps-ncmp-service)

  • NetworkCmProxyDataServiceImpl#parseAndUpdateCmHandlesInDmiRegistration(dmiPluginRegistration): already present , we iterate over the incoming request and call the method to handle add or remove attributes from cmHandle.
  • NetworkCmProxyDataServiceImpl#handleAddOrRemoveCmHandleProperties(leaves, targetAttributeKey, targetAttributeValue) : new method which will have logic to handle addition or removal of attributes based on the value.
  • CpsDataServiceImpl#replaceListContent(dataspaceName,anchorName,parentNodeXpath,dataNodes,observedTimestamp) : new overloaded method for replaceListContent.

Proposal

ScenarioURIPayload/Input RequestSuggested Code / ChangesComments
Req-001
Request to create the cmHandle

POST

{ncmpRoot}/ncmpInventory/v1/ch/

Input

JSON Viewer
{
   "dmiPlugin": "onap.dmi.plugin",                  
  
  "createdCmHandles": [
      {
         "cmHandle": "myHandle1",
         "cmHandleProperties": {
            "prop1": "value1",
            "prop2": "value2",
            "prop3": "value3"
         }
      }
   ]
}
{
  "dmiPlugin": "onap.dmi.plugin",                  
  "createdCmHandles": [
    {
      "cmHandle": "myHandle1",
      "cmHandleProperties": {
        "prop1": "value1",
        "prop2": "value2",
        "prop3": "value3"
     
}
    }
  ]
}


No Impact. It will create the cmHandle.Existing behaviour.
Req-002
Request has updatedCmHandles tag present in the incoming request.

POST

{ncmpRoot}/ncmpInventory/v1/ch/


Input

JSON Viewer
{
   "dmiPlugin": "onap.dmi.plugin",                  
 
  "updatedCmHandles": [
      {
         "cmHandle": "myHandle1",
         "cmHandleProperties": {
            "prop1": null, 
       //case-1
        "prop2": "newValue2", //case-2
       
        "prop4": "value4" 
      //case-3 
      }
      }
   ]
}

{
  "dmiPlugin": "onap.dmi.plugin",                  
  "updatedCmHandles": [
    {
      "cmHandle": "myHandle1",
      "cmHandleProperties": {
        "prop1": null,       //case-1
        "prop2": "newValue2", //case-2
        "prop4": "value4"       //case-3 
      }
    }
  ]
}

case-1 :



CaseAction
case-1 [ "prop1": null ]Property which needs to be removed must be explicitly set to null 
case-2 [ "prop2": "newValue2" ]Property which needs to be updated can have the new values in the incoming request.
case-3 [ "prop4": "value4" ]Property which needs to be added can be present in the form of "name" : "value" as seen above.





Result

JSON Viewer
{
        "cmHandle": "myHandle1",
        "cmHandleProperties": {
          "prop2": "newValue2",
          "prop3": "value3",
          "prop4": "value4"
        }
}


CaseDescription
"prop2": "newValue2"As this was updated from value2 to newValue2.
"prop3": "value3"This was not touched , hence this should remain as is.
"prop4": "value4"This was newly added.


Code Block
languagejava
titleConstants
NCMP_DATASPACE_NAME = "NCMP-Admin";
NCMP_DMI_REGISTRY_ANCHOR = "ncmp-dmi-registry";


Changes:
 – NetworkCmProxyDataServiceImpl [ step1 to step3 ]
 – 
CpsDataServiceImpl [ step4 ]


  1. Since the incoming request has updatedCmHandles tag hence we need to check if there are properties eligible to be updated.

  2. Iterate over the incoming cmHandles and for each cmHandle do the following.
    1. Form the xpath from the incoming request using the below expression.

      Code Block
      languagejava
      titleForm xpath
      final String targetXpath = "/dmi-registry/cm-handles[@id='" + cmHandleID + "']";
      eg : "/dmi-registry/cm-handles[@id=myHandle1]"


    2. Get the dataNodes using the above xpath been created including all the leaves (leaves denotes the attributes).

      Code Block
      languagejava
      titleGet Data Nodes using xpath
      final DataNode dataNode = cpsDataService.getDataNode(NCMP_DATASPACE_NAME, 	NCMP_DMI_REGISTRY_ANCHOR, 
      targetXpath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS);


    3. Get handle of the leaves(with existing data) and apply the changes only to the attribute which are present in the incoming request. The attributes which are explicitly set to null will be removed  and others which are present will be updated. The attributes which are not specified will not be touched.

      Code Block
      languagejava
      titleCore logic to add or remove attributes
      private void handleAddOrRemoveCmHandleProperties(final DataNode dataNode, final String targetAttributeKey,
                  final String targetAttributeValue) {
              final Map<String, Object> leaves = dataNode.getLeaves();
              if (leaves.containsKey(targetAttributeKey)) {
                  if (targetAttributeValue == null) {
                      log.info("Removing the attribute with ( key : {} , existingValue : {} )", targetAttributeKey,
                              leaves.get(targetAttributeKey));
                      leaves.remove(targetAttributeKey);
                  } else {
                      log.info("Updating the attribute with ( key : {} , existingValue : {} to newValue : {} )",
                              targetAttributeKey, leaves.get(targetAttributeKey), targetAttributeValue);
                      leaves.put(targetAttributeKey, targetAttributeValue);
                  }
      
              } else {
                  log.info("Adding the attribute with ( key : {} , value : {} )", targetAttributeKey, targetAttributeValue);
                  leaves.put(targetAttributeKey, targetAttributeValue);
              }
          }




  3. Perform step-2 for all the cmHandles and collect the updated dataNodes.
  4. Now since from step-3 we have a Collection<DataNode> which have the updated changes , we can make use of replaceListContent method to apply our changes.

    Note[V1 can be done as is but make a note and propose to the team if we can create an overloaded version] : We are creating an overloaded version of replaceListContent method which takes in Collection<DataNode> directly instead of String jsonData as we directly have the dataNode from step 2.b.

    Code Block
    languagejava
    titlereplaceListContent(final String dataspaceName, final String anchorName, final String parentNodeXpath, final Collection<DataNode> dataNodes, final OffsetDateTime observedTimestamp)
    @Override
    public void replaceListContent(final String dataspaceName, final String anchorName, final String parentNodeXpath,
                                       final Collection<DataNode> dataNodes, final OffsetDateTime observedTimestamp) {
            cpsDataPersistenceService.replaceListContent(dataspaceName, anchorName, parentNodeXpath, dataNodes);
            processDataUpdatedEventAsync(dataspaceName, anchorName, observedTimestamp, parentNodeXpath, Operation.UPDATE);
        }
Requirement URICommentNCMP-008

Register or update public cmhandle properties

{ncmpRoot}/ncmpInventory/v1/ch/Scenario : DMI notifies NCMP of new, updated or removed cmhandles
Method : POST
URI :


Req-003

Request to remove all the cmHandles for a particular cmHandleId.

POST

{ncmpRoot}/ncmpInventory/v1/ch/


Header :
Content-Type: application/json


JSON Viewer
{
  
Request BodyRequest Body : {
      
"dmiPlugin": "onap.dmi.plugin",

      "createdCmHandles" : [ {   "cmHandle" : "cmHandle1",
                                 "cmHandleProperties" : {
                                    "prop1" : "value1",
                                    "prop2" : "value2",

                                    "prop3" : "value3"
                                  }        

                                                                         "publicCmHandleProperties" :  {     
                                                                                "hostedBy" : "cmhandle-5678"                                                                                       
                                                                                 "samplePropertyName2" : "samplePropertyValue2

                                  }

                             },
                             {..}
                           ],

      "updatedCmHandles" : [
                             {

                                 "cmHandle" : "ds4errr77",
                                 "cmHandleProperties" : { # To remove a property, set the value to null
                                    "samplePropertyName1" : "updatedSamplePropertyValue1",
                                    "samplePropertyName2" : null  # This property will be removed
                                  }        

                                                                         "publicCmHandleProperties" :  {      # To remove a property, set the value to null
                                                                               "hostedBy" : "cmhandle-11213",
                                                                                "samplePublicPropertyName1" : "updatedSamplePublicPropertyValue2"

                                  }

                             },
                             {..}

                           ],
      "removedCmHandles" : [ "node-1", "node-2" , ... ]
  }

json attributes:

  • "dmiPlugin" resolvable servicename
  • "createdCmHandles" used for initial cm handle registrations or subsequent
    cmhandle creations
  • "updatedCmHandles"
    Used for updates to cmhandles. Same structure as for create handles
  • "removedCmHandles"  array of cmhandles that have been deleted
    from the network (no additional properties

December 2021 Yang Model for Public Properties Support

...

themeEmacs
titleDecember 2021 Yang Model
linenumberstrue
collapsetrue

...


  "updatedCmHandles": [
    {
      "cmHandle": "myHandle1",
      "cmHandleProperties": {
        "prop1": null,
        "prop2": null,
        "prop3": null,
		"propx": null
      }
    }
  ]
}



JSON Viewer
{
        

...

"cmHandle": "myHandle1",
      

...

  

...

"cmHandleProperties": {}
}
  • All properties will be removed.
  • "propx" : we are trying to remove a non-existent property so it should be ignored and should not result in any issue.

Req-004

Request doesn't have updatedCmHandles tag present in the incoming request.

POST

{ncmpRoot}/ncmpInventory/v1/ch/


JSON Viewer
{
  "dmiPlugin": "my-dmi-plugin",
  "removedCmHandles": [
    "[\"my-cm-handle1\",\"my-cm-handle2\",\"my-cm-handle3\"]"
  ]
}



No Change from the code pespective.

Existing behaviour.