Add scripts to preload templates 90/124690/3
authorkrishnaa96 <krishna.moorthy6@wipro.com>
Tue, 5 Oct 2021 15:10:49 +0000 (15:10 +0000)
committerkrishnaa96 <krishna.moorthy6@wipro.com>
Mon, 11 Oct 2021 09:08:50 +0000 (14:38 +0530)
Issue-ID: CPS-708
Signed-off-by: krishnaa96 <krishna.moorthy6@wipro.com>
Change-Id: Id8f48c061b9556c47953c78e9c86c6a3dc9ec79c

docker-compose/docker-compose.yml
docker-compose/preload-templates/Dockerfile [new file with mode: 0644]
docker-compose/preload-templates/cpspreload.py [new file with mode: 0644]
docker-compose/preload-templates/samplepreload.json [new file with mode: 0644]

index 961cec6..1868c89 100644 (file)
@@ -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 (file)
index 0000000..c668ed9
--- /dev/null
@@ -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 (file)
index 0000000..25fd568
--- /dev/null
@@ -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 (file)
index 0000000..d96488d
--- /dev/null
@@ -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}}']"
+    }
+]