Esempio n. 1
0
    def __init__(self, host, port, queue_name, exchange, exchange_type, routing_key, timeout=50):
        prefix = "[RabbitMQ] QUEUE={0}".format(routing_key)
        self.host = host
        self.port = port
        self.log = getLogger("server", prefix)
        self.queue_name = queue_name
        self.exchange = exchange
        self.exchange_type = exchange_type
        self.routing_key = routing_key
        self.exchange = exchange
        self.timeout = timeout

        retry_time = 5
        while retry_time > 0:
            try:
                self.connect()
            except Exception as e:
                if (retry_time > 1):
                    self.log.warn("Can not connect to rabbitmq server. Retry after 2 second.")
                    time.sleep(2)
                else:
                    self.log.error("Can not connect to rabbitmq server. Error: %s.", e)
            else:
                self.log.info("Connect to rabbitmq server.")
                self.last_connect_time = time.time()
                break
            finally:
                retry_time -= 1
Esempio n. 2
0
 def __init__(self, host, user, passwd, db, port=3306, timeout=120):
     self.reconnect_time = time.time() + timeout
     self.connection_info = {
         "host": host,
         "user": user,
         "passwd": passwd,
         "db": db,
         "port": port,
         "charset": "ascii",
     }
     self.timeout = timeout
     prefix = "[MySQL] DB={0}".format(db)
     self.log = getLogger("server", prefix)
     self.connect()
Esempio n. 3
0
from handlers.main.MainHandler import MainHandler
from handlers.rejudge.RejudgeHandler import RejudgeHandler
from handlers.submission.SubmissionHandler import SubmissionHandler

if len(sys.argv) != 2:
    sys.stderr.write('{0}: 1 argument needed, {1} given\n'.format(
        sys.argv[0],
        len(sys.argv) - 1))
    print("Usage: {0} [config file]".format(sys.argv[0]))
    sys.exit(2)

application = tornado.web.Application([(r"/", MainHandler),
                                       (r"/rejudge", RejudgeHandler),
                                       (r"/submission", SubmissionHandler)])

if __name__ == "__main__":
    port = int(g_config.get('HostInfo', 'port'))
    access_log = logger.tornadoLogAdapter()
    server_log = logger.getLogger("server", "[Server] Main")
    application.settings["log_function"] = access_log
    try:
        application.listen(port)
    except OSError as error:
        server_log.error("Server can not listen port %d. What: %s", port,
                         error)
    except Exception as error:
        server_log.critical("Server got Unexcepted Error. What: %s", error)
    else:
        server_log.debug("Server running on port %d.", port)
        tornado.ioloop.IOLoop.current().start()
Esempio n. 4
0
import json
import tornado.web
from utils.logger.loggerUtils import getLogger
from utils.mysql.mysqller import getDatabase
from utils.rabbitmq.rabbitmqer import submissionMQ

submission_log = getLogger("server", "[RejudgeHandler]")
matrix_database = getDatabase("Matrix_database")

GET_SUBMISSION_SQL = """SELECT sub_id, submission.prob_id as prob_id, config, detail, updated_at, ptype_id, is_standard
                        FROM submission, library_problem
                        WHERE sub_id = %(sub_id)s AND submission.prob_id=library_problem.prob_id
                     """


class RejudgeHandler(tornado.web.RequestHandler):
    def get(self):
        sub_id = None
        try:
            sub_id = self.get_argument('sub_id', None)
        except Exception as e:
            submission_log.warn("Request missing sub_id")
            return

        result = matrix_database.query(GET_SUBMISSION_SQL, sub_id=sub_id)
        if not result or len(result) == 0:
            submission_log.warn("sub_id not found")
            return

        body = {
            "submissionId": sub_id,
Esempio n. 5
0
import json
import tornado.web
from utils.logger.loggerUtils import getLogger
from utils.common import validator
from utils.mysql.mysqller import getDatabase
from utils.rabbitmq.rabbitmqer import submissionMQ

submission_log = getLogger("server", "[SubmissionHandler]")
matrix_database = getDatabase("Matrix_database")

GET_SUBMISSION_SQL = """SELECT sub_id, prob_id, config, detail, updated_at, ptype_id
                        FROM submission NATURAL JOIN library_problem
                        WHERE sub_id = %(sub_id)s AND prob_id = %(prob_id)s AND grade IS NULL
                     """


class SubmissionHandler(tornado.web.RequestHandler):
    def __init__(self, *args, **kwargs):
        super(SubmissionHandler, self).__init__(*args, **kwargs)
        self.is_sent = False

    def set_default_headers(self):
        self.set_header('Content-type', 'application/json;charset=utf-8')

    def post(self):
        body = None
        try:
            body = json.loads(self.request.body.decode())
            body = validator.requestBodyValidator(body)
        except Exception as e:
            submission_log.warn("submission body load failed. Error: %s", e)
Esempio n. 6
0
import configparser
import os
import sys
from utils.logger.loggerUtils import getLogger

g_config = configparser.ConfigParser()
log = getLogger("server", "[Configuration]")
g_config.read(sys.argv[1])