def received_message(self, message): '''Defines behavior for when a client sends a message to the server In this case we don't expect the clients to send us data so we just log the message. ''' self.log = logs.Logger(WSEcho.app_name).getLogger() self.log.info('websocket app: Message: ' + str(message))
def __init__(self, host, port): threading.Thread.__init__(self) self.log = logs.Logger('WebSocketsServer').getLogger() self.port = int(port) self.host = host self.daemon = True self.flag = True self.server = WSGIServer((self.host, self.port), WSDemoApp()) pass
def closed(self, code, reason=None): '''Defines behavior for when a client disconnects from the websocket server In this case when a client disconnects we check and remove them from the client list. ''' self.log = logs.Logger(WSEcho.app_name).getLogger() app = self.environ.pop('ws4py.app') if self in app.clients: self.log.info('websocket app: client disconnected') app.clients.remove(self) self.log.debug('closed - Clients: ' + str(app.clients))
def opened(self): '''Defines behavior for when a new client connects to the server In this case we add the client to our list of clients so we know who we can send messages too. The clients are accessed through ``environ``. ''' self.log = logs.Logger(WSEcho.app_name).getLogger() app = self.environ['ws4py.app'] if not self in app.clients: app.clients.append(self) self.log.info('websocket app: client connected') self.log.debug('opened - Clients: ' + str(app.clients))
''' # First thing to do... # Import the demo_utils module :) import sys, os filedir = os.path.dirname(os.path.realpath(__file__)) sys.path.append(filedir + '/../demo_utils') import threading, time, json, flask, cluster, logging from flask import Flask, request from demo_utils import config, generator from cluster import ThreadedGenerator from demo_utils import logs from ws4py import configure_logger from flask_cors import CORS log = logs.Logger('DEMO_SERVER.py').getLogger() OUTPUTS = ['FILE', 'KAFKA', 'HTTP', 'HDFS'] '''The three different types of outputs from the generator''' conf = config.read_config('global.conf') app = Flask(__name__, static_url_path='') CORS(app) app_port = int(conf['DEMO']['server_port']) schema = conf['DEMO']['data_schema'] throughput = conf['DEMO']['bytes_per_second'] log_level = conf['LOGGING']['log-level'] # The Websockets will always be the demo_server port + 1 ws_port = app_port + 1
# First thing to do... # Import the demo_utils module :) import sys, os filedir = os.path.dirname(os.path.realpath(__file__)) sys.path.append(filedir + '/../demo_utils') # Use demo_utils if necessary import demo_utils, logging from demo_utils import config, ambari from demo_utils.ambari import Ambari from demo_utils import service_installer from demo_utils import logs rootLogger = logging.getLogger() rootLogger.setLevel(logging.DEBUG) log = logs.Logger('SERVICE.py').getLogger() def on_service_start(): '''This method will run every time the service start Fill in this method with any necessary commands to set up and start other services for the demo Note that this method will always be the very last thing to be executed upon starting the demo service ''' print 'Running on_service_start' cfg = config.read_config('global.conf') # Ambari Client amc = Ambari(config=cfg['AMBARI'])
def __init__(self): self.log = logs.Logger('WebSocketHandler').getLogger() self.log.info('InitWebsocket app') self.ws = WebSocketWSGIApplication(handler_cls=WSEcho) self.clients = []
"string": "STRING", "boolean": "BOOLEAN", "map": "STRING" # This will change in the future - possibly add mapType? } '''Maps types from datum types to Hive types''' SPARK_TYPE_MAP = { "int": "Int", "decimal": "Double", "string": "String", "boolean": "Boolean", "map": "String" # This will change in the future - possibly add mapType? } '''Maps types from datum types to Scala types''' logger = logs.Logger('CLUSTER.py').getLogger() def kerberize(): '''Kerberize the cluster using a script. Untested. Can take 10-15 minutes. This utilizes a script found at https://github.com/crazyadmins/useful-scripts/tree/master/ambari If you're running this script on a cluster you should look in ``configuration/kerberos/ambari.props`` to make sure the proper values are present in the file or else the script will fail. Args: N/A Returns: N/A '''