-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
55 lines (43 loc) · 1.72 KB
/
main.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
"""
Created on Oct 1, 2014
@author: fabiomignini
@author: gabrielecastellano
"""
import falcon
import logging
import os
import inspect
from threading import Thread
from service_layer_application_core.config import Configuration
from service_layer_application_core.service_layer_application import ServiceLayer
from service_layer_application_core.dd_client import DDClient
conf = Configuration()
# set log level
if conf.DEBUG is True:
log_level = logging.DEBUG
requests_log = logging.getLogger("requests")
requests_log.setLevel(logging.WARNING)
elif conf.VERBOSE is True:
log_level = logging.INFO
requests_log = logging.getLogger("requests")
requests_log.setLevel(logging.WARNING)
else:
log_level = logging.WARNING
# format = '%(asctime)s %(filename)s %(funcName)s %(levelname)s %(message)s'
log_format = '%(asctime)s %(levelname)s %(message)s - %(filename)s:%(lineno)s'
logging.basicConfig(filename=conf.LOG_FILE, level=log_level, format=log_format, datefmt='%m/%d/%Y %I:%M:%S %p')
logging.debug("Service Layer Starting")
print("Welcome to the User-oriented Service Layer Application")
# Falcon starts
app = falcon.API()
logging.info("Starting Service Layer application")
serviceLayer = ServiceLayer()
app.add_route('/service-layer', serviceLayer)
app.add_route('/service-layer/{mac_address}', serviceLayer)
logging.info("Falcon Successfully started")
# start the dd client to receive information about domains
base_folder = os.path.realpath(os.path.abspath(os.path.split(inspect.getfile(inspect.currentframe()))[0]))
dd_client = DDClient(conf.DD_NAME, conf.BROKER_ADDRESS, conf.DD_CUSTOMER, conf.DD_KEYFILE)
thread = Thread(target=dd_client.start)
thread.start()
logging.info("DoubleDecker Client Successfully started")