atlanticwave-sdx / sdx-controller

Central Controller for AtlanticWave SDX.
https://www.atlanticwave-sdx.net
MIT License
1 stars 3 forks source link

List connections is returning string instead of JSON #265

Closed italovalcy closed 2 months ago

italovalcy commented 2 months ago

Hi,

The list connections endpoint is returning strings instead of JSON objects:

$ curl -s http://0.0.0.0:8080/SDX-Controller/1.0.0/connections
[
  {
    "bbb": "{\"id\": \"bbb\", \"name\": \"Test connection request 22\", \"start_time\": \"2000-01-23T04:56:07.000Z\", \"end_time\": \"2000-01-23T04:56:07.000Z\", \"bandwidth_required\": 10, \"latency_required\": 300, \"egress_port\": {\"id\": \"urn:sdx:port:tenet.ac.za:Tenet03:50\", \"name\": \"Tenet03:50\", \"node\": \"urn:sdx:port:tenet.ac.za:Tenet03\", \"status\": \"up\"}, \"ingress_port\": {\"id\": \"urn:sdx:port:ampath.net:Ampath3:50\", \"name\": \"Ampath3:50\", \"node\": \"urn:sdx:port:ampath.net:Ampath3\", \"status\": \"up\"}}"
  }
]

Steps to reproduce:

  1. Follow the instructions here: https://sdx-docs.readthedocs.io/en/latest/sdx_deployment.html
  2. Create one connection:
    $ curl -X POST http://0.0.0.0:8080/SDX-Controller/1.0.0/connection -H 'Content-Type: application/json' -d '{"id": "bbb", "name": "Test connection request 22", "start_time": "2000-01-23T04:56:07.000Z", "end_time": "2000-01-23T04:56:07.000Z", "bandwidth_required": 10, "latency_required": 300, "egress_port": {"id": "urn:sdx:port:tenet.ac.za:Tenet03:50", "name": "Tenet03:50", "node": "urn:sdx:port:tenet.ac.za:Tenet03", "status": "up"}, "ingress_port": {"id": "urn:sdx:port:ampath.net:Ampath3:50", "name": "Ampath3:50", "node": "urn:sdx:port:ampath.net:Ampath3", "status": "up"}}'
    {
    "connection_id": "bbb",
    "reason": "Connection published",
    "status": "OK"
    }
  3. Get the list of all connections:
    $ curl -s http://0.0.0.0:8080/SDX-Controller/1.0.0/connections
    [
    {
    "bbb": "{\"id\": \"bbb\", \"name\": \"Test connection request 22\", \"start_time\": \"2000-01-23T04:56:07.000Z\", \"end_time\": \"2000-01-23T04:56:07.000Z\", \"bandwidth_required\": 10, \"latency_required\": 300, \"egress_port\": {\"id\": \"urn:sdx:port:tenet.ac.za:Tenet03:50\", \"name\": \"Tenet03:50\", \"node\": \"urn:sdx:port:tenet.ac.za:Tenet03\", \"status\": \"up\"}, \"ingress_port\": {\"id\": \"urn:sdx:port:ampath.net:Ampath3:50\", \"name\": \"Ampath3:50\", \"node\": \"urn:sdx:port:ampath.net:Ampath3\", \"status\": \"up\"}}"
    }
    ]

Another thing to think about is that the endpoint above provides a list of dicts where each dict contains only one connection indexed by the connection ID. Nothing against it, but maybe one better approach to display this would be a dict of connections (indexed by connection id, like:

$ curl -s http://0.0.0.0:8080/SDX-Controller/1.0.0/connections
{
    "bbb": {"id": "bbb", "name": "Test connection request 22", "start_time": "2000-01-23T04:56:07.000Z", "end_time": "2000-01-23T04:56:07.000Z", "bandwidth_required": 10, "latency_required": 300, "egress_port": {"id": "urn:sdx:port:tenet.ac.za:Tenet03:50", "name": "Tenet03:50", "node": "urn:sdx:port:tenet.ac.za:Tenet03", "status": "up"}, "ingress_port": {"id": "urn:sdx:port:ampath.net:Ampath3:50", "name": "Ampath3:50", "node": "urn:sdx:port:ampath.net:Ampath3", "status": "up"}},
    "ccc111": {"id": "ccc111", "name": "Test connection request 22", "start_time": "2000-01-23T04:56:07.000Z", "end_time": "2000-01-23T04:56:07.000Z", "bandwidth_required": 10, "latency_required": 300, "egress_port": {"id": "urn:sdx:port:tenet.ac.za:Tenet03:50", "name": "Tenet03:50", "node": "urn:sdx:port:tenet.ac.za:Tenet03", "status": "up"}, "ingress_port": {"id": "urn:sdx:port:ampath.net:Ampath3:50", "name": "Ampath3:50", "node": "urn:sdx:port:ampath.net:Ampath3", "status": "up"}}
}
congwang09 commented 2 months ago

I'll look into making the API responses consistent.