Skip to content
Snippets Groups Projects
Commit f6692796 authored by Malte Bauch's avatar Malte Bauch
Browse files

database updated for current mock

- added StoreLinks() for the new GetLinks() function in our RESTCONF client.
- updated the queries for the new json format
- removed the function for error handling -> not really go like
- added Shutdown() function
parent e6c5ad6a
No related branches found
No related tags found
2 merge requests!27Resolve "neo4j",!18Develop
Pipeline #52186 passed with warnings
...@@ -67,7 +67,7 @@ func (d Database) StorePND(pnd *PND) { ...@@ -67,7 +67,7 @@ func (d Database) StorePND(pnd *PND) {
ON CREATE SET pnd.description = $description, ON CREATE SET pnd.description = $description,
pnd.southboundInterfaces = $southboundInterfaces pnd.southboundInterfaces = $southboundInterfaces
` `
//refactor map[string]interface... in own function
_, err := d.session.Run( _, err := d.session.Run(
query, map[string]interface{}{ query, map[string]interface{}{
"name": pnd.name, "name": pnd.name,
...@@ -75,15 +75,15 @@ func (d Database) StorePND(pnd *PND) { ...@@ -75,15 +75,15 @@ func (d Database) StorePND(pnd *PND) {
"southboundInterfaces": pnd.southboundInterfaces, "southboundInterfaces": pnd.southboundInterfaces,
}) })
logError("failed storing PND into database", err) if err != nil {
log.Info("failed storing PND into database:", err)
}
log.Info("successfully added PND into database") log.Info("successfully added PND into database")
} }
//RemovePND removes the given principle network domain by id. //RemovePND removes the given principle network domain by id.
func (d Database) RemovePND(id string) { func (d Database) RemovePND(id string) {}
}
//StoreNodes stores the given nodes to the database and adds them to a //StoreNodes stores the given nodes to the database and adds them to a
//principle networt domain (PND). It is required for a node to belong to a PND. //principle networt domain (PND). It is required for a node to belong to a PND.
...@@ -98,11 +98,11 @@ func (d Database) StoreNodes(json string) { ...@@ -98,11 +98,11 @@ func (d Database) StoreNodes(json string) {
AS value AS value
UNWIND value.data as d UNWIND value.data as d
MERGE (device:Device {id: d.object_id}) MERGE (device:Device {id: d.object_id})
ON CREATE SET device.nativeName = d.object_data.name[0].value, ON CREATE SET device.nativeName = d.object_data.` + "`tapi-object-data`.name[0].value," + `
device.deviceType = d.object_data.name[1].value, device.deviceType = d.object_data.` + "`tapi-object-data`.name[1].value," + `
device.serialNumber = d.object_data.name[2].value, device.serialNumber = d.object_data.` + "`tapi-object-data`.name[2].value," + `
device.softwareVersion = d.object_data.name[3].value, device.softwareVersion = d.object_data.` + "`tapi-object-data`.name[3].value," + `
device.` + "`operational-state` = d.object_data.`operational-state`" + ` device.` + "`operational-state` = d.object_data.`tapi-object-data`.`operational-state`" + `
WITH device WITH device
MATCH (pnd:PND) MATCH (pnd:PND)
WHERE pnd.name = $pnd WHERE pnd.name = $pnd
...@@ -128,21 +128,48 @@ func (d Database) RemoveNodes(json string) {} ...@@ -128,21 +128,48 @@ func (d Database) RemoveNodes(json string) {}
//RemoveSingleNode removes the given node and their relationship by id. //RemoveSingleNode removes the given node and their relationship by id.
func (d Database) RemoveSingleNode(id string) {} func (d Database) RemoveSingleNode(id string) {}
//StoreLinks stores the links between nodes
func (d Database) StoreLinks(json string) {
query :=
`
WITH apoc.convert.fromJsonMap($stringToAdd)
AS value
UNWIND value.data as l
MATCH (d:Device), (d2:Device)
WHERE d.id = l.object_data.` + "`tapi-object-data`.`node-edge-point`[0].`node-uuid`" + `
AND d2.id = l.object_data.` + "`tapi-object-data`.`node-edge-point`[1].`node-uuid`" + `
CALL apoc.merge.relationship(d,l.object_data.` + "`tapi-object-data`.`layer-qualifier`,{},{}, d2,{})" + `
YIELD rel
RETURN rel
`
_, err := d.session.Run(
query, map[string]interface{}{
"stringToAdd": json,
})
if err != nil {
log.Info("failed storing Links into database:", err)
}
log.Info("successfully added Links into database")
}
//StoreNodeEdgePoints stores the given node edge points (interfaces) //StoreNodeEdgePoints stores the given node edge points (interfaces)
func (d Database) StoreNodeEdgePoints(json string) { func (d Database) StoreNodeEdgePoints(json string) {
queryEdgePoints := query :=
` `
WITH apoc.convert.fromJsonMap($stringToAdd) WITH apoc.convert.fromJsonMap($stringToAdd)
AS value AS value
UNWIND value.data as i UNWIND value.data as i
MERGE (interface:Interface {id: i.object_id}) MERGE (interface:Interface {id: i.object_id})
ON CREATE SET interface.object_type =i.object_type, ON CREATE SET interface.object_type =i.object_type,
interface.localId = i.object_data.name[0].value, interface.localId = i.object_data.` + "`tapi-object-data`.name[0].value," + `
interface.location = i.object_data.name[1].value, interface.location = i.object_data.` + "`tapi-object-data`.name[1].value," + `
interface.` + "`containing-node` = i.object_data.`containing-node`" interface.` + "`containing-node` = i.object_data.`tapi-object-data`.`containing-node`"
_, err := d.session.Run( _, err := d.session.Run(
queryEdgePoints, map[string]interface{}{ query, map[string]interface{}{
"stringToAdd": json, "stringToAdd": json,
}) })
...@@ -186,9 +213,4 @@ func (d Database) Shutdown() { ...@@ -186,9 +213,4 @@ func (d Database) Shutdown() {
if err := d.driver.Close(); err != nil { if err := d.driver.Close(); err != nil {
} }
}
//logError logs error with custom and error message
func logError(message string, err error) {
} }
...@@ -60,7 +60,7 @@ func (c *MCPClient) GetConnections() error { ...@@ -60,7 +60,7 @@ func (c *MCPClient) GetConnections() error {
func (c *MCPClient) GetLinks() error { func (c *MCPClient) GetLinks() error {
defer c.buffer.Reset() defer c.buffer.Reset()
_, err := c.client.TapiTopologyCore.GetTapiCoreContextTopologyMcpBaseTopologyLink(nil) _, err := c.client.TapiTopologyCore.GetTapiCoreContextTopologyMcpBaseTopologyLink(nil)
c.database.StoreConnections(c.buffer.String()) c.database.StoreLinks(c.buffer.String())
log.Debug(c.buffer.Next(25)) log.Debug(c.buffer.Next(25))
return err return err
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment