8ea1d1cf6432e92d3f119abf4455c369f0b1d1e4
[sdc.git] / catalog-be / src / main / resources / scripts / sdcBePy / consumers / run.py
1 import time
2
3 from sdcBePy import properties
4 from sdcBePy.common.healthCheck import check_backend, get_args
5 from sdcBePy.common.sdcBeProxy import SdcBeProxy
6 from sdcBePy.consumers.models.consumerCandidateList import get_consumers
7 from sdcBePy.users.run import colors
8
9
10 def be_consumers_init(be_ip, be_port, header, protocol, consumer_candidate_list):
11     sdc_be_proxy = SdcBeProxy(be_ip, be_port, header, protocol)
12     if check_backend(sdc_be_proxy, properties.retry_attempts):
13         for consumer in consumer_candidate_list:
14             if sdc_be_proxy.check_user(consumer.consumer_name) != 200:
15                 result = sdc_be_proxy.create_consumer(*consumer.get_parameters())
16                 if result == 201:
17                     print('[INFO]: ' + consumer.consumer_name +
18                           ' created, result: [' + str(result) + ']')
19                 else:
20                     print('[ERROR]: ' + colors.FAIL + consumer.consumer_name + colors.END_C +
21                           ' error creating , result: [' + str(result) + ']')
22             else:
23                 print('[INFO]: ' + consumer.consumer_name + ' already exists')
24     else:
25         print('[ERROR]: ' + time.strftime('%Y/%m/%d %H:%M:%S') + colors.FAIL
26               + ' Backend is DOWN :-(' + colors.END_C)
27         raise Exception("Cannot communicate with the backend!")
28
29
30 def main():
31     be_ip, be_port, header, protocol = get_args()
32     be_consumers_init(be_ip, be_port, header, protocol, get_consumers())
33
34
35 if __name__ == '__main__':
36     main()