Example #1
0
 def post(self):
     self.set_header('Content-Type', 'application/json')
     try:
         transaction = Transaction()
         transaction.parse_json(self.request.body)
         self.write(transaction.run())
     except TransactionException as err:
         self.set_status(err.code)
         self.write(json.JSONEncoder().encode({'error': err.error}))
Example #2
0
 def post(self):
     self.set_header('Content-Type', 'application/json')
     try:
         transaction = Transaction()
         transaction.parse_json(self.request.body)
         self.write(transaction.run())
     except TransactionException as err:
         self.set_status(err.code)
         self.write(json.JSONEncoder().encode({'error': err.error}))
Example #3
0
class TransactionTest(unittest.TestCase):
    def setUp(self):
        self.trans = Transaction('test')
        self.test_data = {}

    def test_parse_json(self):
        #set up test data
        db = 'linguine-test'
        corpora = MongoClient()[db].corpus
        test_contents_id = corpora.insert({
            "title": "A Tale of Two Cities",
            "contents":
            "it was the best of times it was the worst of times it was the age of whatever it was the age of whatever",
            "tags": []
        })
        self.test_data = '{"transaction_id":"1", "operation":"NoOp", "library":"no_library", "corpora_ids":["' + str(
            test_contents_id) + '"]}'

        #execute code
        # self.agssertTrue(self.trans.parse_json(self.test_data))

        #clean up
        corpora.remove(test_contents_id)

    def test_run(self):
        #set up test data
        db = 'linguine-test'
        corpora = MongoClient()[db].corpus
        test_contents_id = corpora.insert({
            "title": "A Tale of Two Cities",
            "contents":
            "it was the best of times it was the worst of times it was the age of whatever it was the age of whatever",
            "tags": []
        })
        self.test_data = '{"transaction_id":"1", "operation":"NoOp", "library":"no_library", "corpora_ids":["' + str(
            test_contents_id) + '"]}'

        #execute code
        self.trans.parse_json(self.test_data)
        # self.assertEqual(self.trans.run(), "it was the best of times it was the worst of times it was the age of whatever it was the age of whatever")

        #clean up
        corpora.remove(test_contents_id)
Example #4
0
    def post(self):
        self.set_header('Content-Type', 'application/json')
        try:
            self.num_transactions_running += 1
            transaction = Transaction(self.database)
            self.transactions.append(transaction)
            transaction.parse_json(self.request.body)
            transaction.read_corpora()
            transaction.calc_eta(self.num_transactions_running)
            analysis_id = transaction.create_analysis_record()

            # Generate response to server before kicking off analysis
            self.write(json.JSONEncoder().encode({'analysis_id': str(analysis_id)}))
            self.finish()

            # Encapsulate running of analysis in a future
            print("Submitting analysis " + str(analysis_id) + " to analysis queue")
            self.analysis_executor.submit(transaction.run, analysis_id, self)

            for p in psutil.pids():
                if psutil.Process(p).name() in ["python", "java"]:
                    for child in psutil.Process(p).children():
                        cdict = child.as_dict(attrs=['pid', 'name', 'status', 'ppid'])
                        print("\t" + str(cdict))
                        if cdict['status'] in ['sleeping', 'zombie'] and self.num_transactions_running == 0:
                            print("There are no transactions running currently. Cleaning up idle threads.")
                            child.kill()

        except TransactionException as err:
            print("===========error==================")
            print(err.error)
            try:
                print(json.JSONEncoder().encode({'error': err.error}))
            except AttributeError as e:
                print(json.JSONEncoder().encode({'error': e}))
            print("===========end_error==================")
            self.set_status(err.code)
            self.write(json.JSONEncoder().encode({'error': err.error}))

        # Keep this error instance as a catch-all for all web requests
        except Exception as err:
            print("===========error==================")
            print(err)
            print(err.args)
            traceback.print_exc()
            print("===========end_error==================")
    def post(self):
        self.set_header('Content-Type', 'application/json')
        try:
            self.numTransactionsRunning+=1
            transaction = Transaction()
            requestObj = transaction.parse_json(self.request.body)
            transaction.read_corpora(transaction.corpora_ids)
            transaction.calcETA(self.numTransactionsRunning)
            analysis_id = transaction.create_analysis_record()

            #Generate response to server before kicking off analysis
            self.write(json.JSONEncoder().encode({'analysis_id': str(analysis_id)}))
            self.finish()

            #Encapsulate running of analysis in a future
            print("Submitting analysis " + str(analysis_id) + " to analysis queue")
            self.analysis_executor.submit(transaction.run, analysis_id, self)

        except tornado.exceptions.MultipleExceptionsRaised as multiple:
            for e in multiple.get_all_exceptions():
                print("===========error==================")
                try:
                    print(json.JSONEncoder().encode({'error': err.error}))
                except AttributeError as e:
                    print(json.JSONEncoder().encode({'error': e.error}))
                print("===========end_error==================")
        #Keep this error instance as a catch-all for all web requests
        except Exception as err:
            print("===========error==================")
            try:
                print(json.JSONEncoder().encode({'error': err.error}))
            except AttributeError as e:
                print(json.JSONEncoder().encode({'error': e.error}))
            print("===========end_error==================")
            self.set_status(err.code)
            self.write(json.JSONEncoder().encode({'error': err.error}))
 def setUp(self):
     self.trans = Transaction('test')
     self.test_data = {}