fabric-testbed / ControlFramework

Basic framework for a Fabric Control Framework Actor
MIT License
1 stars 0 forks source link

Too many escapes in `GET /slivers` output #210

Closed sajith closed 1 year ago

sajith commented 1 year ago

I tried a GET /slivers?slice_id=018eb740-6452-4876-b229-2895512e0ace. In the result, the data[0].sliver part looks odd:

{
    "data": [
        {
            "graph_node_id": "8b868321-2722-447e-aff8-6c84df0d1aca",
            "join_state": "NoJoin",
            "lease_end_time": "2022-09-01 11:05:16 +0000",
            "lease_start_time": "2022-08-31 11:05:18 +0000",
            "notice": "Reservation b2257771-6765-488e-97d9-9cdcc4279ae9 (Slice MySlice(018eb740-6452-4876-b229-2895512e0ace) Graph Id:03e845d6-0f20-4745-b2f3-31c195a8c287 Owner:owner@example.net) is in state (Closed,None_) ",
            "pending_state": "None_",
            "slice_id": "018eb740-6452-4876-b229-2895512e0ace",
            "sliver": "{\"Name\": \"Node1\", \"Type\": \"VM\", \"Capacities\": \"{\\\"core\\\": 2, \\\"disk\\\": 10, \\\"ram\\\": 8}\", \"CapacityHints\": \"{\\\"instance_type\\\": \\\"fabric.c2.m8.d10\\\"}\", \"CapacityAllocations\": \"{\\\"core\\\": 2, \\\"disk\\\": 10, \\\"ram\\\": 8}\", \"LabelAllocations\": \"{\\\"instance_parent\\\": \\\"dall-w1.fabric-testbed.net\\\"}\", \"ReservationInfo\": \"{\\\"error_message\\\": \\\"\\\", \\\"reservation_id\\\": \\\"b2257771-6765-488e-97d9-9cdcc4279ae9\\\", \\\"reservation_state\\\": \\\"Active\\\"}\", \"NodeMap\": \"[\\\"508c3fa3-df17-41ab-bb95-fdf71c105a61\\\", \\\"GDXZNF3\\\"]\", \"StitchNode\": \"false\", \"ImageRef\": \"default_rocky_8,qcow2\", \"Site\": \"DALL\"}",
            "sliver_id": "b2257771-6765-488e-97d9-9cdcc4279ae9",
            "sliver_type": "NodeSliver",
            "state": "Closed"
        }
    ],
    "size": 1,
    "status": 200,
    "type": "slivers"
}
kthare10 commented 1 year ago

The escape sequences are there because it's a JSON within a JSON (default json behavior)

sajith commented 1 year ago

If the response is meant to be nested JSON, perhaps it should be of the below form?

{
    "data": [{
        "graph_node_id": "8b868321-2722-447e-aff8-6c84df0d1aca",
        "join_state": "NoJoin",
        "lease_end_time": "2022-09-01 11:05:16 +0000",
        "lease_start_time": "2022-08-31 11:05:18 +0000",
        "notice": "Reservation b2257771-6765-488e-97d9-9cdcc4279ae9 (Slice MySlice(018eb740-6452-4876-b229-2895512e0ace) Graph Id:03e845d6-0f20-4745-b2f3-31c195a8c287 Owner:owner@example.net) is in state (Closed,None_) ",
        "pending_state": "None_",
        "slice_id": "018eb740-6452-4876-b229-2895512e0ace",
        "sliver": {
            "Name": "Node1",
            "Type": "VM",
            "Capacities": {
                "core": 2,
                "disk": 10,
                "ram": 8
            },
            "CapacityHints": {
                "instance_type": "fabric.c2.m8.d10"
            },
            "CapacityAllocations": {
                "core": 2,
                "disk": 10,
                "ram": 8
            },
            "LabelAllocations": {
                "instance_parent": "dall-w1.fabric-testbed.net"
            },
            "ReservationInfo": {
                "error_message": "",
                "reservation_id": "b2257771-6765-488e-97d9-9cdcc4279ae9",
                "reservation_state": "Active"
            },
            "NodeMap": [
                "508c3fa3-df17-41ab-bb95-fdf71c105a61",
                "GDXZNF3"
            ],
            "StitchNode": false,
            "ImageRef": "default_rocky_8,qcow2",
            "Site": "DALL"
        },
        "sliver_id": "b2257771-6765-488e-97d9-9cdcc4279ae9",
        "sliver_type": "NodeSliver",
        "state": "Closed"
    }],
    "size": 1,
    "status": 200,
    "type": "slivers"
}

With this form, we can easily access sub-fields when we handle the response with tools like jq or in client programs. With jq, with the form I am proposing here, we can access jq '.data[0].sliver.Capacities.disk'; with the current response form, we can't do that without another decoding step. Similarly, with python, we should be able to do something like json.loads(response.body)['data'][0]['sliver']['Capacities']['disk'].

sajith commented 1 year ago

While we're considering this, I guess the notice field also could be made easier to parse, with a form like:

{
  "notice": {
    "Reservation": "b2257771-6765-488e-97d9-9cdcc4279ae9",
    "Slice": {
      "name": "MySlice",
      "SliceId": "018eb740-6452-4876-b229-2895512e0ace"
    },
    "GraphId": "03e845d6-0f20-4745-b2f3-31c195a8c287",
    "Owner": "owner@example.net",
    "State": "(Closed,None_)"
  }
}

That could be a little better if State sub-field is made simpler.

This is not something that needs immediate attention though. I was looking into Orchestrator API (for Reasons™) and thought that it could be made a little bit nicer from a tool writer's perspective. Since I haven't actually written any such tool yet, it is only an opinion that really should not carry much weight. :-)

kthare10 commented 1 year ago

Escape characters on the Sliver object have been removed, but the members capacity and labels will still be escaped as they are defined as a special type in FIM. Returning them as is makes it easy to convert them to FIM Sliver objects (NodeSliver and NetworkServiceSliver)

Refer: https://github.com/fabric-testbed/InformationModel/blob/master/fim/slivers/capacities_labels.py for more details on how Capacities/Labels are encoded.

Regarding Notice field, it is intended to include the last set of operations that occurred on that sliver. In the example posted above it was a state transition but it could also indicate an error message if Sliver failed to provision. The value returned is not a fixed JSON always. This API is intended to be use for debugging. All client facing information is available in the ASM graph returned by GET /slices/{slice_id}.

Below is the snapshot of the Sliver after the fix.

{
    "data": [
        {
            "graph_node_id": "b19c183a-d173-4a19-b40e-b37670c1557d",
            "join_state": "NoJoin",
            "lease_end_time": "2022-10-19 12:23:45 +0000",
            "lease_start_time": "2022-10-18 12:23:45 +0000",
            "notice": "Reservation 0255f4da-d2e3-4de4-bf9b-9a86dcae3d34 (Slice slc1(9faa6f26-b422-4133-812d-387366b5e570) Graph Id:94a22399-84ff-4375-8986-737d2c90cb89 Owner:kthare10@email.unc.edu) is in state (Closed,None_)  (Last ticket update: TicketReviewPolicy: Closing reservation due to failure in slice)",
            "pending_state": "None_",
            "slice_id": "9faa6f26-b422-4133-812d-387366b5e570",
            "sliver": {
                "Capacities": "{\"core\": 2, \"disk\": 100, \"ram\": 8}",
                "CapacityAllocations": "{\"core\": 2, \"disk\": 100, \"ram\": 8}",
                "CapacityHints": "{\"instance_type\": \"fabric.c2.m8.d100\"}",
                "ImageRef": "default_centos_8,qcow2",
                "LabelAllocations": "{\"instance_parent\": \"renc-w2.fabric-testbed.net\"}",
                "Name": "n2",
                "NodeMap": "[\"40ed6c15-f85c-4fc5-89a7-c2a47091865f\", \"HX7LQ53\"]",
                "ReservationInfo": "{\"error_message\": \"\", \"reservation_id\": \"0255f4da-d2e3-4de4-bf9b-9a86dcae3d34\", \"reservation_state\": \"Ticketed\"}",
                "Site": "RENC",
                "StitchNode": "false",
                "Type": "VM",
                "components": [
                    {
                        "CapacityAllocations": "{\"unit\": 1}",
                        "Details": "Mellanox ConnectX-6 VPI MCX653 dual port 100Gbps",
                        "LabelAllocations": "{\"bdf\": [\"0000:41:00.0\", \"0000:41:00.1\"]}",
                        "Model": "ConnectX-6",
                        "Name": "n2-nic1",
                        "NodeMap": "[\"40ed6c15-f85c-4fc5-89a7-c2a47091865f\", \"HX7LQ53-slot3\"]",
                        "StitchNode": "false",
                        "Type": "SmartNIC",
                        "network_services": [
                            {
                                "Layer": "L2",
                                "Name": "n2-n2-nic1-l2ovs",
                                "Site": "RENC",
                                "StitchNode": "false",
                                "Type": "OVS",
                                "interfaces": [
                                    {
                                        "Capacities": "{\"bw\": 100, \"unit\": 1}",
                                        "LabelAllocations": "{\"local_name\": \"p1\", \"mac\": \"04:3F:72:B7:15:74\"}",
                                        "Labels": "{\"local_name\": \"p1\"}",
                                        "Name": "n2-nic1-p1",
                                        "StitchNode": "false",
                                        "Type": "DedicatedPort"
                                    },
                                    {
                                        "Capacities": "{\"bw\": 100, \"unit\": 1}",
                                        "LabelAllocations": "{\"local_name\": \"p2\", \"mac\": \"04:3F:72:B7:15:75\"}",
                                        "Labels": "{\"local_name\": \"p2\"}",
                                        "Name": "n2-nic1-p2",
                                        "StitchNode": "false",
                                        "Type": "DedicatedPort"
                                    }
                                ]
                            }
                        ]
                    }
                ]
            },
            "sliver_id": "0255f4da-d2e3-4de4-bf9b-9a86dcae3d34",
            "sliver_type": "NodeSliver",
            "state": "Closed"
        },
        {
            "graph_node_id": "83473dc8-cbd3-4124-914a-4fcaf9516f81",
            "join_state": "NoJoin",
            "lease_end_time": "2022-10-19 12:23:45 +0000",
            "lease_start_time": "2022-10-18 12:23:45 +0000",
            "notice": "Reservation 1ec71556-1128-428b-9e0e-0b9fc72027f0 (Slice slc1(9faa6f26-b422-4133-812d-387366b5e570) Graph Id:94a22399-84ff-4375-8986-737d2c90cb89 Owner:kthare10@email.unc.edu) is in state (Closed,None_)  (Last ticket update: TicketReviewPolicy: Closing reservation due to failure in slice)",
            "pending_state": "None_",
            "slice_id": "9faa6f26-b422-4133-812d-387366b5e570",
            "sliver": {
                "Capacities": "{\"core\": 2, \"disk\": 100, \"ram\": 8}",
                "CapacityAllocations": "{\"core\": 2, \"disk\": 100, \"ram\": 8}",
                "CapacityHints": "{\"instance_type\": \"fabric.c2.m8.d100\"}",
                "ImageRef": "default_centos_8,qcow2",
                "LabelAllocations": "{\"instance_parent\": \"renc-w2.fabric-testbed.net\"}",
                "Name": "n1",
                "NodeMap": "[\"40ed6c15-f85c-4fc5-89a7-c2a47091865f\", \"HX7LQ53\"]",
                "ReservationInfo": "{\"error_message\": \"\", \"reservation_id\": \"1ec71556-1128-428b-9e0e-0b9fc72027f0\", \"reservation_state\": \"Ticketed\"}",
                "Site": "RENC",
                "StitchNode": "false",
                "Type": "VM",
                "components": [
                    {
                        "CapacityAllocations": "{\"unit\": 1}",
                        "Details": "Mellanox ConnectX-6 VPI MCX653 dual port 100Gbps",
                        "LabelAllocations": "{\"bdf\": [\"0000:a1:00.0\", \"0000:a1:00.1\"]}",
                        "Model": "ConnectX-6",
                        "Name": "n1-nic1",
                        "NodeMap": "[\"40ed6c15-f85c-4fc5-89a7-c2a47091865f\", \"HX7LQ53-slot6\"]",
                        "StitchNode": "false",
                        "Type": "SmartNIC",
                        "network_services": [
                            {
                                "Layer": "L2",
                                "Name": "n1-n1-nic1-l2ovs",
                                "Site": "RENC",
                                "StitchNode": "false",
                                "Type": "OVS",
                                "interfaces": [
                                    {
                                        "Capacities": "{\"bw\": 100, \"unit\": 1}",
                                        "LabelAllocations": "{\"local_name\": \"p1\", \"mac\": \"04:3F:72:B7:19:5C\"}",
                                        "Labels": "{\"local_name\": \"p1\"}",
                                        "Name": "n1-nic1-p1",
                                        "StitchNode": "false",
                                        "Type": "DedicatedPort"
                                    },
                                    {
                                        "Capacities": "{\"bw\": 100, \"unit\": 1}",
                                        "LabelAllocations": "{\"local_name\": \"p2\", \"mac\": \"04:3F:72:B7:19:5D\"}",
                                        "Labels": "{\"local_name\": \"p2\"}",
                                        "Name": "n1-nic1-p2",
                                        "StitchNode": "false",
                                        "Type": "DedicatedPort"
                                    }
                                ]
                            }
                        ]
                    }
                ]
            },
            "sliver_id": "1ec71556-1128-428b-9e0e-0b9fc72027f0",
            "sliver_type": "NodeSliver",
            "state": "Closed"
        },
        {
            "graph_node_id": "ba57877d-9583-4b48-a4e5-237defa9fc8e",
            "join_state": "NoJoin",
            "lease_end_time": "2022-10-19 12:23:45 +0000",
            "lease_start_time": "2022-10-18 12:23:46 +0000",
            "notice": "Reservation bd5af3cf-2a18-4299-ad51-fcd95883cbb8 (Slice slc1(9faa6f26-b422-4133-812d-387366b5e570) Graph Id:94a22399-84ff-4375-8986-737d2c90cb89 Owner:kthare10@email.unc.edu) is in state (Closed,None_)  (Last ticket update: Failure : More than 1 or 0 Network Delegations found! net_adm_ids: [])",
            "pending_state": "None_",
            "slice_id": "9faa6f26-b422-4133-812d-387366b5e570",
            "sliver": {
                "Layer": "L2",
                "Name": "bridge1",
                "ReservationInfo": "{\"error_message\": \"\", \"reservation_id\": \"bd5af3cf-2a18-4299-ad51-fcd95883cbb8\", \"reservation_state\": \"Nascent\"}",
                "Site": "RENC",
                "StitchNode": "false",
                "Type": "L2Bridge",
                "interfaces": [
                    {
                        "Capacities": "{\"bw\": 100, \"unit\": 1}",
                        "Labels": "{\"local_name\": \"p1\"}",
                        "Name": "n1-n1-nic1-p1",
                        "NodeMap": "[\"HX7LQ53\", \"HX7LQ53-slot6\"]",
                        "StitchNode": "false",
                        "Type": "ServicePort"
                    },
                    {
                        "Capacities": "{\"bw\": 100, \"unit\": 1}",
                        "Labels": "{\"local_name\": \"p1\"}",
                        "Name": "n2-n2-nic1-p1",
                        "NodeMap": "[\"HX7LQ53\", \"HX7LQ53-slot3\"]",
                        "StitchNode": "false",
                        "Type": "ServicePort"
                    }
                ]
            },
            "sliver_id": "bd5af3cf-2a18-4299-ad51-fcd95883cbb8",
            "sliver_type": "NetworkServiceSliver",
            "state": "Closed"
        }
    ],
    "size": 3,
    "status": 200,
    "type": "slivers"
}