Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add topo timestamp api #172

Merged
merged 3 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions sdx_lc/controllers/topology_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ def get_topology(): # noqa: E501
return "do some magic!"


def get_topology_timestamp(): # noqa: E501
"""get timestamp of latest topology pulling from OXP"""
latest_topology_ts = db_instance.read_from_db("latest_topology_ts")
if not latest_topology_ts:
return "No topology was pulled from OXP yet", 404
return latest_topology_ts["latest_topology_ts"]


def get_topologyby_version(topology_id, version): # noqa: E501
"""Find topology by version

Expand Down
4 changes: 2 additions & 2 deletions sdx_lc/jobs/pull_topo_changes.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import argparse
import json
import logging
import os.path
import sys
import threading
import time
import urllib.request

Expand Down Expand Up @@ -82,6 +80,8 @@ def process_domain_controller_topo(db_instance):
f"topoVersion{json_pulled_topology['version']}", pulled_topology
)
db_instance.add_key_value_pair_to_db("latest_topology", pulled_topology)
topology_ts = int(time.time())
db_instance.add_key_value_pair_to_db("latest_topology_ts", str(topology_ts))
logger.debug("Added pulled topo to db")
# initiate rpc producer with 5 seconds timeout
rpc_producer = RpcProducer(5, "", "topo")
Expand Down
18 changes: 18 additions & 0 deletions sdx_lc/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,24 @@ paths:
"404":
description: topology not found
x-openapi-router-controller: sdx_lc.controllers.topology_controller
/topology/time:
get:
tags:
- topology
summary: get timestamp of latest topology pulling from OXP
description: ID of the topology
operationId: get_topology_timestamp
responses:
"200":
description: ok
content:
text/plain:
schema:
type: string
x-content-type: text/plain
"404":
description: Topology timestamp not found
x-openapi-router-controller: sdx_lc.controllers.topology_controller
/topology/version:
get:
tags:
Expand Down
Loading