aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src')
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/common/healthCheck.py55
-rwxr-xr-xcatalog-be/src/main/resources/scripts/sdcBePy/common/sdcBeProxy.py10
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/consumers/__init__.py0
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/consumers/models/__init__.py0
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/consumers/models/consumerCandidate.py15
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/consumers/models/consumerCandidateList.py11
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/consumers/run.py35
7 files changed, 126 insertions, 0 deletions
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/common/healthCheck.py b/catalog-be/src/main/resources/scripts/sdcBePy/common/healthCheck.py
new file mode 100644
index 0000000000..7d8558d644
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/common/healthCheck.py
@@ -0,0 +1,55 @@
+#!/usr/bin/env python3
+import sys
+import time
+from argparse import ArgumentParser
+from datetime import datetime
+
+from sdcBePy.common.bColors import BColors
+from sdcBePy.common.sdcBeProxy import SdcBeProxy
+
+colors = BColors()
+
+RETRY_TIME = 10
+RETRY_ATTEMPTS = 10
+
+
+def check_backend(sdc_be_proxy=None, reply_append_count=1, be_host=None, be_port=None, scheme=None, debug=False):
+ if sdc_be_proxy is None:
+ sdc_be_proxy = SdcBeProxy(be_host, be_port, scheme, debug=debug)
+
+ for i in range(1, reply_append_count + 1):
+ if sdc_be_proxy.check_backend() == 200:
+ print('[INFO]: Backend is up and running')
+ return True
+ else:
+ print('[WARRING]: ' + datetime.now().strftime('%Y/%m/%d %H:%M:%S') + colors.FAIL
+ + ' Backend not responding, try #' + str(i) + colors.END_C)
+ time.sleep(RETRY_TIME)
+
+ return False
+
+
+def run(be_host, be_port, protocol):
+ if not check_backend(reply_append_count=RETRY_ATTEMPTS, be_host=be_host, be_port=be_port, scheme=protocol):
+ print('[ERROR]: ' + time.strftime('%Y/%m/%d %H:%M:%S') + colors.FAIL + ' Backend is DOWN :-(' + colors.END_C)
+ sys.exit()
+
+
+def get_args():
+ parser = ArgumentParser()
+
+ parser.add_argument('-i', '--ip', required=True)
+ parser.add_argument('-p', '--port', required=True)
+ parser.add_argument('--https', action='store_true')
+
+ args = parser.parse_args()
+
+ return [args.ip, args.port, 'https' if args.https else 'http']
+
+
+def main():
+ run(*get_args())
+
+
+if __name__ == '__main__':
+ main()
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/common/sdcBeProxy.py b/catalog-be/src/main/resources/scripts/sdcBePy/common/sdcBeProxy.py
index 48261704f7..6fea657fab 100755
--- a/catalog-be/src/main/resources/scripts/sdcBePy/common/sdcBeProxy.py
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/common/sdcBeProxy.py
@@ -35,6 +35,16 @@ class SdcBeProxy:
'role': role
}))
+ def check_consumer(self, consumer_name):
+ return self.con.get("/sdc2/rest/v1/consumers/" + consumer_name)
+
+ def create_consumer(self, consumer_name, slat, password):
+ return self.con.post("/sdc2/rest/v1/consumers/", json.dumps({
+ 'consumerName': consumer_name,
+ 'consumerSalt': slat,
+ 'consumerPassword': password
+ }))
+
def post_file(self, path, multi_part_form_data):
return self.con.post_file(path, multi_part_form_data)
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/consumers/__init__.py b/catalog-be/src/main/resources/scripts/sdcBePy/consumers/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/consumers/__init__.py
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/consumers/models/__init__.py b/catalog-be/src/main/resources/scripts/sdcBePy/consumers/models/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/consumers/models/__init__.py
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/consumers/models/consumerCandidate.py b/catalog-be/src/main/resources/scripts/sdcBePy/consumers/models/consumerCandidate.py
new file mode 100644
index 0000000000..1fd2ad8929
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/consumers/models/consumerCandidate.py
@@ -0,0 +1,15 @@
+from sdcBePy.common.helpers import check_arguments_not_none
+
+
+class ConsumerCandidate:
+
+ def __init__(self, consumer_name, slat, password):
+ if not check_arguments_not_none(consumer_name, slat, password):
+ raise AttributeError("The consumer_name, slat or password are missing!")
+
+ self.consumer_name = consumer_name
+ self.slat = slat
+ self.password = password
+
+ def get_parameters(self):
+ return self.consumer_name, self.slat, self.password
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/consumers/models/consumerCandidateList.py b/catalog-be/src/main/resources/scripts/sdcBePy/consumers/models/consumerCandidateList.py
new file mode 100644
index 0000000000..b1904d5e48
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/consumers/models/consumerCandidateList.py
@@ -0,0 +1,11 @@
+from sdcBePy.consumers.models.consumerCandidate import ConsumerCandidate
+
+consumersList = ["aai", "appc", "dcae", "mso", "sdnc", "vid", "cognita",
+ "clamp", "vfc", "workflow", "policy", "pomba",
+ "multicloud", "cds", "modeling"]
+salt = "9cd4c3ad2a6f6ce3f3414e68b5157e63"
+password = "35371c046f88c603ccba152cb3db34ec4475cb2e5713f2fc0a43bf18a5243495"
+
+
+def get_consumers():
+ return [ConsumerCandidate(name, slat=salt, password=password) for name in consumersList]
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/consumers/run.py b/catalog-be/src/main/resources/scripts/sdcBePy/consumers/run.py
new file mode 100644
index 0000000000..59a0b610d8
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/consumers/run.py
@@ -0,0 +1,35 @@
+import time
+
+from sdcBePy.common.healthCheck import check_backend, RETRY_ATTEMPTS, get_args
+from sdcBePy.common.sdcBeProxy import SdcBeProxy
+from sdcBePy.consumers.models.consumerCandidateList import get_consumers
+from sdcBePy.users.run import colors
+
+
+def be_consumers_init(be_ip, be_port, protocol, consumer_candidate_list):
+ sdc_be_proxy = SdcBeProxy(be_ip, be_port, protocol)
+ if check_backend(sdc_be_proxy, RETRY_ATTEMPTS):
+ for consumer in consumer_candidate_list:
+ if sdc_be_proxy.check_user(consumer.consumer_name) != 200:
+ result = sdc_be_proxy.create_consumer(*consumer.get_parameters())
+ if result == 201:
+ print('[INFO]: ' + consumer.consumer_name +
+ ' created, result: [' + str(result) + ']')
+ else:
+ print('[ERROR]: ' + colors.FAIL + consumer.consumer_name + colors.END_C +
+ ' error creating , result: [' + str(result) + ']')
+ else:
+ print('[INFO]: ' + consumer.consumer_name + ' already exists')
+ else:
+ print('[ERROR]: ' + time.strftime('%Y/%m/%d %H:%M:%S') + colors.FAIL
+ + ' Backend is DOWN :-(' + colors.END_C)
+ raise Exception("Cannot communicate with the backend!")
+
+
+def main():
+ be_ip, be_port, protocol = get_args()
+ be_consumers_init(be_ip, be_port, protocol, get_consumers())
+
+
+if __name__ == '__main__':
+ main()