コード例 #1
0
ファイル: shared.py プロジェクト: scanon/data_api2
def setup():
    global _log, services
    _log = get_logger("doekbase.data_api.tests.shared")
    services = get_services()
    if services["redis_host"] is not None:
        cache.ObjectCache.cache_class = cache.RedisCache
        cache.ObjectCache.cache_params = {"redis_host": services["redis_host"], "redis_port": services["redis_port"]}
コード例 #2
0
def setup():
    global _log, services
    _log = get_logger('doekbase.data_api.tests.shared')
    services = get_services()
    if services["redis_host"] is not None:
        cache.ObjectCache.cache_class = cache.RedisCache
        cache.ObjectCache.cache_params = {
            'redis_host': services["redis_host"],
            'redis_port': services["redis_port"]
        }
コード例 #3
0
ファイル: cache.py プロジェクト: mlhenderson/data_api
## Imports

# System
import hashlib
import logging
import os
import time
import uuid
# Third-party
from dogpile.cache import make_region
import redis
# Local
from doekbase.data_api.util import PerfCollector, get_logger

_log = get_logger(__name__)

## Functions and Classes


class Cache(object):
    def __init__(self):
        self.region = None

    def __getattr__(self, item):
        return getattr(self.region, item)


class RedisCache(Cache):
    def __init__(self, **kwargs):
        super(self.__class__, self).__init__()
コード例 #4
0
ファイル: shared.py プロジェクト: eapearson/data_api
def setup():
    global _log, services
    _log = get_logger('doekbase.data_api.tests.shared')
    services = get_services()
コード例 #5
0
ファイル: display.py プロジェクト: mlhenderson/data_api
    import qgrid
    qgrid.nbinstall()
except ImportError:
    qgrid = None
from jinja2 import Template
# Seaborn graphing
try:
    import seaborn as sns
    sns.set_style("whitegrid")
except ImportError:
    sns = None

# Local
from doekbase.data_api.util import get_logger, log_start, log_end

_log = get_logger('doekbase.data_api.display')

_nbviewer = False


def nbviewer_mode(value=None):
    """Get/set the global nbviewer-friendly mode.
    This is currently used to tell qgrid where to get
    its JavaScript from (local or a CDN).
    """
    global _nbviewer
    if value is not None:
        _nbviewer = bool(value)
    return _nbviewer

コード例 #6
0
# Imports

# Stdlib
import json
try:
    import cStringIO as StringIO
except ImportError:
    import StringIO as StringIO
# Local
import doekbase.workspace.client
from . import thrift_service, ttypes
from doekbase.data_api.util import get_logger, log_start, log_end
from doekbase.data_api.rpc_util import thrift_validate

_log = get_logger('baseobj.impl')

class ObjectImpl(thrift_service.Iface):
    def __init__(self, services=None):
        print("IN ObjectImpl")
        if services is None or type(services) != type({}):
            raise TypeError("You must provide a service configuration "
                            "dictionary! Found {0}".format(type(services)))
        elif not services.has_key("workspace_service_url"):
            raise KeyError("Expecting workspace_service_url key!")
        
        self.services = services
        self.ws_client = None
        self.ref = None

    def init(self, auth):
コード例 #7
0
ファイル: core.py プロジェクト: mlhenderson/data_api
import os
import re
try:
    import cStringIO as StringIO
except ImportError:
    import StringIO as StringIO
# Local
from doekbase.data_api.util import get_logger, log_start, log_end
from doekbase.workspace.client import Workspace
from doekbase.data_api.wsfile import WorkspaceFile
from doekbase.data_api import cache
from doekbase.data_api.util import PerfCollector, collect_performance

# Logging

_log = get_logger('doekbase.data_api.core')

# Globals
REF_PATTERN = re.compile("(.+/.+(/[0-9].+)?)|(ws\.[1-9][0-9]+\.[1-9][0-9]+)")

g_ws_url = "https://ci.kbase.us/services/ws/"
g_shock_url = "https://ci.kbase.us/services/shock-api/"
g_handle_url = "https://ci.kbase.us/services/handle_service/"
g_use_msgpack = True

g_stats = PerfCollector('ObjectAPI')


def fix_docs(cls):
    for name, func in vars(cls).items():
        if func is not None and func.__doc__ is None:
コード例 #8
0
ファイル: shared.py プロジェクト: scanon/data_api
def setup():
    global _log, services
    _log = get_logger('doekbase.data_api.tests.shared')
    services = get_services()
コード例 #9
0
ファイル: test_cache.py プロジェクト: kbase/data_api
__date__ = '9/30/15'

# System
import os
import threading
import time
import unittest
# Third-party
from dogpile.cache.api import NO_VALUE
# Local
from doekbase.data_api import cache
from doekbase.data_api import util
from doekbase.data_api.core import ObjectAPI
from . import shared

_log = util.get_logger(__name__)

# Uncomment this line to turn off DBM tests
USE_DBM = False

def setup():
    shared.setup()

class TestCache(unittest.TestCase):
    """Test the cache.
    """
    dbm_path = None

## Setup / teardown

    @classmethod
コード例 #10
0
ファイル: driver.py プロジェクト: scanon/data_api2
import twisted.internet
import twisted.web

from thrift.transport import TTwisted
from thrift.protocol import TBinaryProtocol

# Local
from doekbase.data_api.taxonomy.taxon.service import thrift_service
from doekbase.data_api.taxonomy.taxon.service.interface import TaxonService
from doekbase.data_api.util import get_logger

DEFAULT_WS_URL = 'https://ci.kbase.us/services/ws/'
DEFAULT_SHOCK_URL = 'https://ci.kbase.us/services/shock-api/'

# set up a logger for Thrift messages
_log = get_logger('taxon_service')

def get_services_dict(ws=DEFAULT_WS_URL, shock=DEFAULT_SHOCK_URL):
    return {'workspace_service_url': ws,
            'shock_service_url': shock}

#TODO respond to kill signals
#TODO on HUP reload of config
def start_service(services = None, host = 'localhost', port = 9101):
    if services is None:
        services = get_services_dict()

    handler = TaxonService(services)
    processor = thrift_service.Processor(handler)
    pfactory = TBinaryProtocol.TBinaryProtocolFactory()
    resource = TTwisted.ThriftResource(processor, pfactory, pfactory)
コード例 #11
0
ファイル: core.py プロジェクト: scanon/data_api2
import os
import re
try:
    import cStringIO as StringIO
except ImportError:
    import StringIO as StringIO
# Local
from doekbase.data_api.util import get_logger, log_start, log_end
from doekbase.workspace.client import Workspace
from doekbase.data_api.wsfile import WorkspaceFile
from doekbase.data_api import cache
from doekbase.data_api.util import PerfCollector, collect_performance

# Logging

_log = get_logger('doekbase.data_api.core')

# Globals
REF_PATTERN = re.compile("(.+/.+(/[0-9].+)?)|(ws\.[1-9][0-9]+\.[1-9][0-9]+)")

g_ws_url = "https://ci.kbase.us/services/ws/"
g_shock_url = "https://ci.kbase.us/services/shock-api/"
g_use_msgpack = True

g_stats = PerfCollector('ObjectAPI')

# Functions and Classes

#: Name positional parts of WorkspaceInfo tuple
WorkspaceInfo = namedtuple('WorkspaceInfo', [
    'id',               # ws_id (int)
コード例 #12
0
ファイル: api.py プロジェクト: scanon/data_api
# Imports

# Stdlib
import json
import logging
import re
# Local
from doekbase.data_api.util import get_logger
from doekbase.data_api.util import log_start, log_end
from doekbase.data_api.util import get_auth_token
from . import thrift_service, ttypes

# Logging

_log = get_logger('object_api')
_log.setLevel(logging.DEBUG)

# Constants

NAMESPACE = 'Object'

REF_PATTERN = re.compile("(.+/.+(/[0-9].+)?)|(ws\.[1-9][0-9]+\.[1-9][0-9]+)")

# Classes and functions


class ObjectAPI(object):
    """API layer over the autogenerated Thrift interface.
    This can handle both local and remote modes by use of alternate
    implementations of the `client` parameter.
コード例 #13
0
ファイル: display.py プロジェクト: scanon/data_api2
except ImportError:
    qgrid = None
from jinja2 import Template

# Seaborn graphing
try:
    import seaborn as sns

    sns.set_style("whitegrid")
except ImportError:
    sns = None

# Local
from doekbase.data_api.util import get_logger, log_start, log_end

_log = get_logger("doekbase.data_api.display")

_nbviewer = False


def nbviewer_mode(value=None):
    """Get/set the global nbviewer-friendly mode.
    This is currently used to tell qgrid where to get
    its JavaScript from (local or a CDN).
    """
    global _nbviewer
    if value is not None:
        _nbviewer = bool(value)
    return _nbviewer

コード例 #14
0
ファイル: driver.py プロジェクト: kbase/data_api
"""
Service driver for Assembly API.
"""

# Imports
# -------
# Local
from doekbase.data_api import service_core
from doekbase.data_api.sequence.assembly.service import thrift_service
from doekbase.data_api.sequence.assembly.service.interface import \
    AssemblyService
from doekbase.data_api.util import get_logger

_log = get_logger(__name__)

def start_service(**kw):
    return service_core.start_service(AssemblyService, thrift_service, _log,
                                      **kw)

stop_service = service_core.stop_service
コード例 #15
0
__date__ = '9/30/15'

# System
import os
import threading
import time
import unittest
# Third-party
from dogpile.cache.api import NO_VALUE
# Local
from doekbase.data_api import cache
from doekbase.data_api import util
from doekbase.data_api.core import ObjectAPI
from . import shared

_log = util.get_logger(__name__)

# Uncomment this line to turn off DBM tests
USE_DBM = False


def setup():
    shared.setup()


class TestCache(unittest.TestCase):
    """Test the cache.
    """
    dbm_path = None

    ## Setup / teardown
コード例 #16
0
# Third-party
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TJSONProtocol
from thrift.server import THttpServer

# Local
from doekbase.data_api.taxonomy.taxon.service import thrift_service
from doekbase.data_api.taxonomy.taxon.service.interface import TaxonService
from doekbase.data_api.util import get_logger

DEFAULT_WS_URL = 'https://ci.kbase.us/services/ws/'
DEFAULT_SHOCK_URL = 'https://ci.kbase.us/services/shock-api/'

_log = get_logger('thrift')  # set up a logger for Thrift messages
_log.setLevel(logging.DEBUG)

def get_services_dict(ws=DEFAULT_WS_URL, shock=DEFAULT_SHOCK_URL):
    return {'workspace_service_url': ws,
            'shock_service_url': shock}

def taxon_service():
    handler = TaxonService(services=get_services_dict())
    processor = thrift_service.Processor(handler)
    pfactory = TJSONProtocol.TJSONProtocolFactory()
    server_address = ('127.0.0.1', 9090)

    server = THttpServer.THttpServer(processor, server_address, pfactory)
    return server
コード例 #17
0
ファイル: api.py プロジェクト: kbase/data_api
# Imports

# Stdlib
import json
import logging
import re
# Local
from doekbase.data_api.util import get_logger
from doekbase.data_api.util import log_start, log_end
from doekbase.data_api.util import get_auth_token
from . import thrift_service, ttypes

# Logging

_log = get_logger('object_api')
_log.setLevel(logging.DEBUG)

# Constants

NAMESPACE = 'Object'

REF_PATTERN = re.compile("(.+/.+(/[0-9].+)?)|(ws\.[1-9][0-9]+\.[1-9][0-9]+)")

# Classes and functions

class ObjectAPI(object):
    """API layer over the autogenerated Thrift interface.
    This can handle both local and remote modes by use of alternate
    implementations of the `client` parameter.
    """