-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.py
110 lines (94 loc) · 3.97 KB
/
settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import json
import os
from logging.config import dictConfig, logging
class Settings(object):
"""
This class contains all settings for the cumulonimbi project
"""
class ParanoidPirateProtocolSetting(object):
"""
These are the socket timing settings and protocol specs for the Paranoid Pirate Protocol (PPP) implementation
Change these at your own risk :)
"""
HEARTBEAT_LIVELINESS = 3
HEARTBEAT_INTERVAL = 1
INTERVAL_INIT = 1
INTERVAL_MAX = 32
# Paranoid Pirate Protocol constants
PPP_READY = '\x01'.encode() # Signals worker is ready
PPP_HEARTBEAT = '\x02'.encode() # Signals worker heartbeat
debug = False # False seems better
try:
with open("../Config.json") as json_data_file:
data = json.load(json_data_file)
print data
azure_topic_namespace = data['azure']['topic']['namespace']
azure_topic_keyname = data['azure']['topic']['keyname']
azure_topic_key = data['azure']['topic']['key']
azure_queue_account = data['azure']['queue']['account']
azure_queue_key = data['azure']['queue']['key']
job_manager_api_bind = data['jm']['api']['bind']
job_manager_api_connect = data['jm']['api']['connect']
job_manager_api_port = data['jm']['api']['port']
cagaas_super_user = data['cagaas']['user']
except IOError as e:
azure_topic_namespace = 'abc'
azure_topic_keyname = 'abc'
azure_topic_key = 'abc'
job_manager_api_bind = '0.0.0.0'.encode()
job_manager_api_connect = 'docker-cluster.cloudapp.net'.encode()
job_manager_api_port = 5000
cagaas_super_user = 'abc'
job_manager_mongo_host = 'mongodb://docker-cluster.cloudapp.net'
job_manager_router_port = 5559
machine_manager_api_port = 8888
simulator_api_port = 8080
log_file_level = 'DEBUG'
log_file_size = 1024 * 1024 * 100
log_file_rotate = 10
log_stash_level = 'INFO'
log_stash_host = 'docker-cluster.cloudapp.net'
log_stash_port = 9300
repository = None
def configure_logging(self, file_path, module_name):
"""
Configure logging per instance, set the file path for the rotating file logger
"""
path_dir = os.path.dirname(file_path)
if not os.path.exists(path_dir):
os.makedirs(path_dir)
logging_config = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'standard': {'format': '[' + module_name + ']-%(asctime)s[%(levelname)s](%(name)s):%(message)s',
'datefmt': '%Y-%m-%d %H:%M:%S'},
'logstash': {'format': '[' + module_name + ']-[%(levelname)s] %(message)s'}
},
'handlers': {
'fh': {'class': 'logging.handlers.RotatingFileHandler',
'formatter': 'standard',
'level': self.log_file_level,
'filename': file_path,
'mode': 'a',
'maxBytes': self.log_file_size,
'backupCount': self.log_file_rotate},
'console':{'class':'logging.StreamHandler',
'level':'DEBUG',
'formatter': 'standard'},
'ls': {'class': 'logstash.TCPLogstashHandler',
'formatter': 'logstash',
'level': self.log_stash_level,
'host': self.log_stash_host,
'port': self.log_stash_port,
'version': 1}
},
'loggers': {
'': {'handlers': ['fh', 'ls', 'console'],
'level': 'DEBUG',
'propagate': True}
}
}
dictConfig(logging_config)
# always send an initial debug message so we can see if the logger is working as desired
logging.info('logging configured')