def getFromMOBEDAC(cls, id, source, sess_obj):
        conn = None
        complete_url = ""
        try:
            # dev mode?
            my_remote_objects_are_local = get_parm("remote_objects_are_local")
            if get_parm("remote_objects_are_local").lower() == 'true':
                new_obj = cls.get_instance(id, sess_obj)
                if new_obj == None:
                    raise ObjectRetrievalException(
                        "Unable to retrieve object: " + id + " from db")
            else:
                headers = {'content-type': 'application/json'}
                conn = httplib.HTTPConnection(get_parm("mobedac_host"))
                object_path = cls.get_REST_sub_path()
                #                complete_url = get_parm("mobedac_base_path") + object_path + "/" + id + "?auth=" + get_parm("mobedac_auth_key")
                #                complete_url = get_parm("mobedac_base_path") + object_path + "/" + id + "?auth=" + get_parm("mobedac_auth_     38 key")
                complete_url = get_parm(
                    "mobedac_base_path") + "r/" + object_path + "/" + id
                if (conn.host == "localhost"
                        or conn.host == "api.metagenomics.anl.gov"):
                    complete_url = get_parm(
                        "mobedac_base_path"
                    ) + object_path + "/" + id + "?auth=" + get_parm(
                        "mobedac_auth_key")
                complete_url += "&template=1"
                conn.request("GET", complete_url)
                response = conn.getresponse()
                data = response.read()
                # if all went ok then build an object
                if response.status != httplib.OK:
                    raise ObjectRetrievalException(
                        "Unable to retrieve object: " + id + " from host: " +
                        get_parm('mobedac_host') + " url: " + complete_url)
                new_obj = cls({})
                decoded_data = unidecode(data).strip()
                mobedac_logger.info("complete_url: " + complete_url)
                mobedac_logger.info("json string for object id_1: " + id +
                                    " json: " + decoded_data)
                json_obj = json.loads(decoded_data)
                #mobedac_logger.info("json obj: " + str(json_obj))
                new_obj.from_json(True, json_obj, sess_obj)
            return new_obj
        except ObjectRetrievalException as ore:
            exc_type, exc_value, exc_traceback = sys.exc_info()
            traceback.print_exception(exc_type, exc_value, exc_traceback)
            raise ore
        except Exception as e:
            raise ObjectRetrievalException("Unable to retrieve object: " + id +
                                           " from host: " +
                                           get_parm('mobedac_host') +
                                           " url: " + complete_url +
                                           " error: " + str(e))

        finally:
            if conn != None:
                conn.close()
    def getFromMOBEDAC(cls, id, source, sess_obj):
        conn = None
        complete_url = ""
        try:
            # dev mode?
            my_remote_objects_are_local = get_parm("remote_objects_are_local")
            if get_parm("remote_objects_are_local").lower() == 'true':
                new_obj = cls.get_instance(id, sess_obj)
                if new_obj == None:
                    raise ObjectRetrievalException("Unable to retrieve object: " + id + " from db");
            else:
                headers = {'content-type': 'application/json'}
                conn = httplib.HTTPConnection(get_parm("mobedac_host"))
                object_path = cls.get_REST_sub_path()
#                complete_url = get_parm("mobedac_base_path") + object_path + "/" + id + "?auth=" + get_parm("mobedac_auth_key")
#                complete_url = get_parm("mobedac_base_path") + object_path + "/" + id + "?auth=" + get_parm("mobedac_auth_     38 key")
                complete_url = get_parm("mobedac_base_path") + "r/" + object_path + "/" + id
                if (conn.host == "localhost" or conn.host == "api.metagenomics.anl.gov"):
                    complete_url = get_parm("mobedac_base_path") + object_path + "/" + id + "?auth=" + get_parm("mobedac_auth_key")
                complete_url +=  "&template=1" 
                conn.request("GET", complete_url)
                response = conn.getresponse()
                data = response.read()
                # if all went ok then build an object
                if response.status != httplib.OK:
                    raise ObjectRetrievalException("Unable to retrieve object: " + id + " from host: " + get_parm('mobedac_host') + " url: " + complete_url)
                new_obj = cls({})
                decoded_data = unidecode(data).strip()
                mobedac_logger.info("complete_url: "+complete_url)
                mobedac_logger.info("json string for object id_1: " + id + " json: " + decoded_data)
                json_obj = json.loads(decoded_data)
                #mobedac_logger.info("json obj: " + str(json_obj))
                new_obj.from_json(True, json_obj, sess_obj)
            return new_obj
        except ObjectRetrievalException as ore:
            exc_type, exc_value, exc_traceback = sys.exc_info()
            traceback.print_exception(exc_type, exc_value, exc_traceback)   
            raise ore
        except Exception as e:
            raise ObjectRetrievalException("Unable to retrieve object: " + id + " from host: " + get_parm('mobedac_host') + " url: " + complete_url + " error: " + str(e))

        
        finally:
            if conn != None:
                conn.close() 
示例#3
0
# -*- coding: utf-8 -*-
#
# Copyright (C) 2011, Marine Biological Laboratory
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# Please read the COPYING file.
#

import MySQLdb
import sys
import traceback
from sqlalchemy import *
from sqlalchemy.orm import scoped_session, sessionmaker
from initparms import get_parm

test_engine = create_engine(get_parm("ws_connection_url"), echo=False)
Session = scoped_session(sessionmaker(bind=test_engine))
vamps_engine = create_engine(get_parm("vamps_connection_url"), echo=False)
vampsSession = scoped_session(sessionmaker(bind=vamps_engine))
示例#4
0
def set_error_file_logging_debug():
    global mobedac_logger
    mobedac_logger.setLevel(logging.DEBUG)


def set_error_file_logging_info():
    global mobedac_logger
    mobedac_logger.setLevel(logging.INFO)


# Remove the default FileHandlers if present.
log.error_file = ""
log.access_file = ""
maxBytes = getattr(log, "rot_maxBytes", 10000000)
backupCount = getattr(log, "rot_backupCount", 10)
# Make a new RotatingFileHandler for the error log.
fname = getattr(log, "rot_error_file", get_parm("error_log_path"))
h = RotatingFileHandler(fname, 'a', maxBytes, backupCount)
h.doRollover()
h.setFormatter(logging.Formatter("%(asctime)s - %(levelname)s - %(message)s"))
log.error_log.addHandler(h)

# Make a new RotatingFileHandler for the access log.
fname = getattr(log, "rot_access_file", get_parm("access_log_path"))
h = RotatingFileHandler(fname, 'a', maxBytes, backupCount)
h.setFormatter(cherrypy._cplogging.logfmt)
log.access_log.addHandler(h)

# this is to be what is visible
mobedac_logger = log.error_log
mobedac_logger.setLevel(logging.DEBUG)
            # wait here for the processor to stop
            self.submission_processor_thread.join(20.0)
            # did it stop? do we need to to whack it?
            if self.submission_processor_thread.is_alive():
                self.submission_processor_thread.stop_processing()
        except:
            mobedac_logger.exception("Got error trying to stop submission processor thread")
        cherrypy.engine.exit()

if __name__ == '__main__':
    import argparse
    the_root = None
    try:
        from initparms import get_parm
        
        port = get_parm('port')
        logicalpath = get_parm('logicalpath')
        workingfiledir = get_parm('workingfiledir')

        mobedac_logger.debug("in main of mobedac_server")

        submission_processor_thread = Submission_Processor(10, get_parm('vamps_data_post_url'), get_parm('vamps_data_gast_url'), workingfiledir)
        # do we want to not start listening to requests on startup
        disable_processor_flag = get_parm("processor_disabled_on_startup")
        if disable_processor_flag != None and disable_processor_flag.lower() == 'true':
            submission_processor_thread.disable_processing()
        submission_processor_thread.start()
        # force cherrypy to use the port WE want
        cherrypy.config.update({'server.socket_port': int(port),})
        
        the_root = Root(submission_processor_thread)