Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# ============LICENSE_START==================================================== 

2# org.onap.dcaegen2 

3# ============================================================================= 

4# Copyright (c) 2017-2020 AT&T Intellectual Property. All rights reserved. 

5# Copyright (c) 2020 Pantheon.tech. All rights reserved. 

6# ============================================================================= 

7# Licensed under the Apache License, Version 2.0 (the "License"); 

8# you may not use this file except in compliance with the License. 

9# You may obtain a copy of the License at 

10# 

11# http://www.apache.org/licenses/LICENSE-2.0 

12# 

13# Unless required by applicable law or agreed to in writing, software 

14# distributed under the License is distributed on an "AS IS" BASIS, 

15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

16# See the License for the specific language governing permissions and 

17# limitations under the License. 

18# ============LICENSE_END====================================================== 

19 

20## Get parameters for accessing the DMaaP controller 

21from consulif.consulif import ConsulHandle 

22from cloudify.exceptions import NonRecoverableError 

23import os 

24 

25os.environ["REQUESTS_CA_BUNDLE"]="/opt/onap/certs/cacert.pem" # This is to handle https request thru plugin 

26 

27CONSUL_HOST = "consul" # Should always be a local consul agent on Cloudify Manager 

28DBCL_KEY_NAME = "dmaap-plugin" # Consul key containing DMaaP data bus credentials 

29# In the ONAP Kubernetes environment, bus controller address is always "dmaap-bc", on port 8080 (http) and 8443 (https) 

30ONAP_SERVICE_ADDRESS = "dmaap-bc" 

31HTTP_PORT = "8080" 

32HTTPS_PORT = "8443" 

33 

34try: 

35 _ch = ConsulHandle("http://{0}:8500".format(CONSUL_HOST), None, None, None) 

36except Exception as e: 

37 raise NonRecoverableError("Error getting ConsulHandle when configuring dmaap plugin: {0}".format(e)) 

38 

39try: 

40 config = _ch.get_config(DBCL_KEY_NAME) 

41except Exception as e: 

42 raise NonRecoverableError("Error getting config for '{0}' from ConsulHandle when configuring dmaap plugin: {1}".format(DBCL_KEY_NAME, e)) 

43 

44try: 

45 DMAAP_USER = config['dmaap']['username'] 

46except Exception as e: 

47 raise NonRecoverableError("Error setting DMAAP_USER while configuring dmaap plugin: {0}".format(e)) 

48 

49try: 

50 DMAAP_PASS = config['dmaap']['password'] 

51except Exception as e: 

52 raise NonRecoverableError("Error setting DMAAP_PASS while configuring dmaap plugin: {0}".format(e)) 

53 

54try: 

55 DMAAP_OWNER = config['dmaap']['owner'] 

56except Exception as e: 

57 raise NonRecoverableError("Error setting DMAAP_OWNER while configuring dmaap plugin: {0}".format(e)) 

58 

59try: 

60 if 'protocol' in config['dmaap']: 

61 DMAAP_PROTOCOL = config['dmaap']['protocol'] 

62 service_port = HTTP_PORT 

63 else: 

64 DMAAP_PROTOCOL = 'https' # Default to https (service discovery should give us this but doesn't 

65 service_port = HTTPS_PORT 

66except Exception as e: 

67 raise NonRecoverableError("Error setting DMAAP_PROTOCOL while configuring dmaap plugin: {0}".format(e)) 

68 

69try: 

70 if 'path' in config['dmaap']: 

71 DMAAP_PATH = config['dmaap']['path'] 

72 else: 

73 DMAAP_PATH = 'webapi' # SHould come from service discovery but Consul doesn't support it 

74except Exception as e: 

75 raise NonRecoverableError("Error setting DMAAP_PATH while configuring dmaap plugin: {0}".format(e)) 

76 

77try: 

78 service_address = ONAP_SERVICE_ADDRESS 

79 DMAAP_API_URL = '{0}://{1}:{2}/{3}'.format(DMAAP_PROTOCOL, service_address, service_port, DMAAP_PATH) 

80except Exception as e: 

81 raise NonRecoverableError("Error setting DMAAP_API_URL while configuring dmaap plugin: {0}".format(e)) 

82