Skip to content

Commit

Permalink
Use URLs to specify data sources
Browse files Browse the repository at this point in the history
  • Loading branch information
adamnovak committed Nov 10, 2015
1 parent 58b228b commit 07c896c
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
25 changes: 15 additions & 10 deletions ga4gh/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,13 @@ def configure(configFile=None, baseConfig="ProductionConfig",
cors.CORS(app, allow_headers='Content-Type')
app.serverStatus = ServerStatus()
# Allocate the backend
# TODO is this a good way to determine what type of backend we should
# instantiate? We should think carefully about this. The approach of
# using the special strings __SIMULATED__ and __EMPTY__ seems OK for
# now, but is certainly not ideal.
dataSource = app.config["DATA_SOURCE"]
if dataSource == "__SIMULATED__":
# We use URLs to specify the backend. Currently we have file:// URLs (or
# URLs with no scheme) for the FileSystemBackend, and special empty:// and
# simulated:// URLs for empty or simulated data sources.
dataSource = urlparse.urlparse(app.config["DATA_SOURCE"], "file")

if dataSource.scheme == "simulated":
# Ignore the query string
randomSeed = app.config["SIMULATED_BACKEND_RANDOM_SEED"]
numCalls = app.config["SIMULATED_BACKEND_NUM_CALLS"]
variantDensity = app.config["SIMULATED_BACKEND_VARIANT_DENSITY"]
Expand All @@ -186,18 +187,22 @@ def configure(configFile=None, baseConfig="ProductionConfig",
"SIMULATED_BACKEND_NUM_REFERENCE_SETS"]
numReferencesPerReferenceSet = app.config[
"SIMULATED_BACKEND_NUM_REFERENCES_PER_REFERENCE_SET"]
numAlignments = app.config[
numAlignmentsPerReadGroup = app.config[
"SIMULATED_BACKEND_NUM_ALIGNMENTS_PER_READ_GROUP"]
theBackend = backend.SimulatedBackend(
randomSeed=randomSeed, numCalls=numCalls,
variantDensity=variantDensity, numVariantSets=numVariantSets,
numReferenceSets=numReferenceSets,
numReferencesPerReferenceSet=numReferencesPerReferenceSet,
numAlignments=numAlignments)
elif dataSource == "__EMPTY__":
numAlignments=numAlignmentsPerReadGroup)
elif dataSource.scheme == "empty":
theBackend = backend.EmptyBackend()
elif dataSource.scheme == "file":
theBackend = backend.FileSystemBackend(os.path.join(
dataSource.netLoc, dataSource.path))
else:
theBackend = backend.FileSystemBackend(dataSource)
raise exceptions.ConfigurationException(
"Unsupported data source scheme: " + dataSource.scheme)
theBackend.setRequestValidation(app.config["REQUEST_VALIDATION"])
theBackend.setResponseValidation(app.config["RESPONSE_VALIDATION"])
theBackend.setDefaultPageSize(app.config["DEFAULT_PAGE_SIZE"])
Expand Down
2 changes: 1 addition & 1 deletion ga4gh/serverconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class BaseConfig(object):
REQUEST_VALIDATION = False
RESPONSE_VALIDATION = False
DEFAULT_PAGE_SIZE = 100
DATA_SOURCE = "__EMPTY__"
DATA_SOURCE = "empty://"

# Options for the simulated backend.
SIMULATED_BACKEND_RANDOM_SEED = 0
Expand Down
2 changes: 1 addition & 1 deletion tests/end_to_end/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def getConfig(self):
config = """
SIMULATED_BACKEND_NUM_VARIANT_SETS = 10
SIMULATED_BACKEND_VARIANT_DENSITY = 1
DATA_SOURCE = "__SIMULATED__"
DATA_SOURCE = "simulated://"
DEBUG = True
"""
if self.useOidc:
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_oidc.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ class TestFrontendOidc(unittest.TestCase):
@classmethod
def setUpClass(cls):
config = {
"DATA_SOURCE": "__SIMULATED__",
"SIMULATED_BACKEND_RANDOM_SEED": 1111,
"SIMULATED_BACKEND_NUM_CALLS": 1,
"SIMULATED_BACKEND_VARIANT_DENSITY": 1.0,
"SIMULATED_BACKEND_NUM_VARIANT_SETS": 1,
"DATA_SOURCE": "simulated://",
"OIDC_CLIENT_ID": "123",
"OIDC_CLIENT_SECRET": RANDSTR,
"OIDC_PROVIDER": "http://auth.com"
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_simulated_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def setUpClass(cls):
# Set the random seed to make tests reproducible.
random.seed(1)
config = {
"DATA_SOURCE": "__SIMULATED__",
"DATA_SOURCE": "simulated://",
"SIMULATED_BACKEND_RANDOM_SEED": 1111,
"SIMULATED_BACKEND_NUM_CALLS": 5,
"SIMULATED_BACKEND_VARIANT_DENSITY": 1.0,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TestFrontend(unittest.TestCase):
@classmethod
def setUpClass(cls):
config = {
"DATA_SOURCE": "__SIMULATED__",
"DATA_SOURCE": "simulated://",
"SIMULATED_BACKEND_RANDOM_SEED": 1111,
"SIMULATED_BACKEND_NUM_CALLS": 1,
"SIMULATED_BACKEND_VARIANT_DENSITY": 1.0,
Expand Down

0 comments on commit 07c896c

Please sign in to comment.