From 0792564e8e30aa1c3efc21e8f92fb6be7be167a1 Mon Sep 17 00:00:00 2001 From: krishnaa96 Date: Tue, 5 Oct 2021 15:10:49 +0000 Subject: Add scripts to preload templates Issue-ID: CPS-708 Signed-off-by: krishnaa96 Change-Id: Id8f48c061b9556c47953c78e9c86c6a3dc9ec79c --- docker-compose/docker-compose.yml | 11 ++++++++- docker-compose/preload-templates/Dockerfile | 7 ++++++ docker-compose/preload-templates/cpspreload.py | 26 ++++++++++++++++++++++ .../preload-templates/samplepreload.json | 16 +++++++++++++ 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 docker-compose/preload-templates/Dockerfile create mode 100644 docker-compose/preload-templates/cpspreload.py create mode 100644 docker-compose/preload-templates/samplepreload.json diff --git a/docker-compose/docker-compose.yml b/docker-compose/docker-compose.yml index 961cec6..1868c89 100644 --- a/docker-compose/docker-compose.yml +++ b/docker-compose/docker-compose.yml @@ -50,4 +50,13 @@ services: depends_on: - postgres networks: - - cps-tbdmt-default \ No newline at end of file + - cps-tbdmt-default + preload-templates: + build: ../preload-templates + depends_on: + - cps-tbdmt + networks: + - cps-tbdmt-default + volumes: + - ../preload-templates/$FILENAME:/usr/src/app/samplepreload.json + diff --git a/docker-compose/preload-templates/Dockerfile b/docker-compose/preload-templates/Dockerfile new file mode 100644 index 0000000..c668ed9 --- /dev/null +++ b/docker-compose/preload-templates/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3 +WORKDIR /usr/src/app +COPY cpspreload.py . +COPY samplepreload.json . +RUN pip install requests +CMD ["cpspreload.py"] +ENTRYPOINT ["python3"] diff --git a/docker-compose/preload-templates/cpspreload.py b/docker-compose/preload-templates/cpspreload.py new file mode 100644 index 0000000..25fd568 --- /dev/null +++ b/docker-compose/preload-templates/cpspreload.py @@ -0,0 +1,26 @@ +import json +import time +import requests + +CPS_HEADERS = { + "Accept": "application/json", + "Content-Type": "application/json", + } +tbdmt_url="http://cps-tbdmt:8080/templates" + + + +with open('samplepreload.json') as template_file: + templates_json = template_file.read() +templates=json.loads(templates_json) + + +for template in templates: + print(type(template)) + print("send rest req") + print("waiting before sent req") + time.sleep(2) + response=requests.post(tbdmt_url, json=template, headers=CPS_HEADERS) + print("res",response.reason) + + diff --git a/docker-compose/preload-templates/samplepreload.json b/docker-compose/preload-templates/samplepreload.json new file mode 100644 index 0000000..d96488d --- /dev/null +++ b/docker-compose/preload-templates/samplepreload.json @@ -0,0 +1,16 @@ +[ + { + "includeDescendants": true, + "model": "ran-network", + "requestType": "get", + "templateId": "dummy-template-7", + "xpathTemplate": "/ran-network/NearRTRIC[@idNearRTRIC='{{idNearRTRIC}}']/GNBCUUPFunction[@idGNBCUUPFunction='{{idGNBCUUPFunction}}']/attributes/pLMNInfoList[@mcc='{{mcc}}' and @mnc='{{mnc}}']/sNSSAIList[@sNssai='{{sNSSAIList}}']" + }, + { + "includeDescendants": true, + "model": "ran-network", + "requestType": "get", + "templateId": "dummy-template-8", + "xpathTemplate": "/ran-network/NearRTRIC[@idNearRTRIC='{{idNearRTRIC}}']/GNBCUUPFunction[@idGNBCUUPFunction='{{idGNBCUUPFunction}}']/attributes/RRMPolicyRatio[@id='{{id}}']/attributes/rRMPolicyMemberList[@idx='{{idx}}']" + } +] -- cgit 1.2.3-korg