Skip to content

Commit

Permalink
Bug fixes and performance improvements (uc-cdis#5)
Browse files Browse the repository at this point in the history
* chore(graphene) upgrade to 2.0.1
* chore(travis): Pull in Rudy's PR for codacy coverage
* chore(swagger): Add swagger file
  • Loading branch information
zflamig authored Dec 19, 2017
1 parent 4bdf42e commit fca3b33
Show file tree
Hide file tree
Showing 15 changed files with 441 additions and 272 deletions.
5 changes: 5 additions & 0 deletions .codacy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
coverage:
enabled: true
exclude_paths:
- 'tests/**'
35 changes: 7 additions & 28 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,26 @@
sudo: false
dist: trusty
group: deprecated-2017Q2
sudo: false
language: python

python:
- "2.7"

cache:
# pip: true # We have overridden the default install step, caching manually
# ref: <https://docs.travis-ci.com/user/caching/#Arbitrary-directories>
- directories:
- /home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages
- $HOME/.pip-cache
- pip
- apt

addons:
postgresql: '9.4'
# fix for scipy inside SurvivalPy
apt:
packages:
- libatlas-dev
- libatlas-base-dev
- liblapack-dev
- gfortran

services:
- elasticsearch

before_install:
# bust only the the part of the cache that we are frequently changing
- pip uninstall --yes psqlgraph gdcdictionary gdcdatamodel || true

# fix for scipy inside SurvivalPy
- wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh
- bash miniconda.sh -b -p $HOME/miniconda
- export PATH="$HOME/miniconda/bin:$PATH"
- conda update --yes conda
- pip uninstall --yes gdcdictionary gdcdatamodel || true

# command to install dependencies
install:
# fix for scipy inside SurvivalPy
- conda install --yes python=$TRAVIS_PYTHON_VERSION pip numpy scipy nose future

- pip install -r requirements.txt
- pip install -r dev-requirements.txt

Expand All @@ -53,10 +32,10 @@ before_script:

# command to run tests
script:
- |
set -e
PYTHONPATH=. py.test -vv tests/system_test.py tests/graphql/test_graphql.py
set +e
- py.test -vv --cov=peregrine --cov-report xml tests/system_test.py tests/graphql/test_graphql.py

after_script:
- python-codacy-coverage -r coverage.xml

env:
global:
Expand Down
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
## Peregrine
Query interface to get insights into data in Gen3 Commons Edit
Add topics
# Peregrine

[![Build Status](https://travis-ci.org/uc-cdis/peregrine.svg?branch=master)](https://travis-ci.org/uc-cdis/peregrine)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/f6128183864d4e5da5093eb72a3c9c97)](https://www.codacy.com/app/uc-cdis/peregrine?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=uc-cdis/peregrine&amp;utm_campaign=Badge_Grade)
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/f6128183864d4e5da5093eb72a3c9c97)](https://www.codacy.com/app/uc-cdis/peregrine?utm_source=github.com&utm_medium=referral&utm_content=uc-cdis/peregrine&utm_campaign=Badge_Coverage)

Query interface to get insights into data in Gen3 Commons

## Setup

```bash
# Install requirements.
pip install -r requirements.txt
```

## API Documentation

[OpenAPI documentation available here.](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/uc-cdis/peregrine/master/openapis/swagger.yaml)

YAML file for the OpenAPI documentation is found in the `openapi` folder (in
the root directory); see the README in that folder for more details.
5 changes: 3 additions & 2 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ lockfile==0.10.2
coverage==3.7.1
mock==1.0.1
pytest-flask==0.8.1
pytest-cov==2.5.1
codacy-coverage
moto==0.4.5
Sphinx==1.3.1
sphinxcontrib-httpdomain==1.3.0
-e git+https://[email protected]/NCI-GDC/signpost.git@c5d499936943e71eefe2ec4b3d4ced6ac48f35c0#egg=signpost
-e git+https://[email protected]/NCI-GDC/signpost.git@c8e2aa5ff572c808cba9b522b64f7b497e79c524#egg=signpost
-e git+https://[email protected]/uc-cdis/[email protected]#egg=cdisutilstest
-e git+https://[email protected]/uc-cdis/[email protected]#egg=flask_postgres_session
-e git+https://[email protected]/uc-cdis/sheepdog.git@53cb3a5d69d04a3daf0cdf00957151813fcccac4#egg=sheepdog
-e git+https://[email protected]/uc-cdis/[email protected]#egg=storageclient
17 changes: 17 additions & 0 deletions openapis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# TL;DR

[Swagger](https://swagger.io/getting-started-with-swagger-i-what-is-swagger/) specification of Peregrine's REST API

## Swagger Tools

Use swagger's editor to update swagger.yaml and swagger.json using one of the following:
* [online editor](https://editor.swagger.io/)
* [Docker image](https://hub.docker.com/r/swaggerapi/swagger-editor/) - `docker run -d -p 80:8080 swaggerapi/swagger-editor`
* or pull the editor code from [github](https://github.com/swagger-api/swagger-editor), and `npm start` an editor locally.

Publish API documentation with the [swagger-ui](https://github.com/swagger-api/swagger-ui) - also easily launched with docker: `docker run -p 80:8080 -e SWAGGER_JSON=/foo/swagger.json -v /bar:/foo swaggerapi/swagger-ui`

## OpenAPI Spec

The swagger definition format has been open sourced as the OpenAPI Specification administered by the Linux Foundation. As of writing this the latest spec defining the structure and elements of a swagger.yaml file is [version 3](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md).

142 changes: 142 additions & 0 deletions openapis/swagger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
swagger: '2.0'
info:
title: Peregrine OpenAPI Specification
version: 0.1.0
description: >-
GraphQL search microservice for CDIS Gen 3 data commons. Code is available
on [GitHub](https://github.com/uc-cdis/peregrine).
termsOfService: 'http://cdis.uchicago.edu/terms/'
contact:
email: [email protected]
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
host: example.domain
basePath: /
tags:
- name: graphql
description: GraphQL Queries
- name: system
description: System endpoints
schemes:
- https
paths:
/graphql:
post:
tags:
- graphql
summary: Perform a GraphQL Query
description: >-
Perform a graphql query over the data commons given a query, variables,
and name.
consumes:
- application/json
produces:
- application/json
parameters:
- in: body
name: body
description: The GraphQL query and parameters
required: true
schema:
$ref: '#/definitions/QueryInputInfo'
responses:
'200':
description: successful operation
schema:
$ref: '#/definitions/QueryOutputRef'
'400':
description: Invalid input
'403':
description: Invalid authorization token
/getschema:
get:
tags:
- graphql
summary: Returns the data dictionary schema json
description: >-
The data dictionary for the data commons is internally converted from
yaml files to json. This endpoint returns the json schema for the
dictionary for use in generating queries.
produces:
- application/json
responses:
'200':
description: successful operation
schema:
$ref: '#/definitions/SchemaOutputRef'
/_version:
get:
tags:
- system
summary: Returns the version of Peregrine
produces:
- application/json
responses:
'200':
description: successful operation
schema:
$ref: '#/definitions/VersionOutputRef'
/_status:
get:
tags:
- system
summary: Returns if Peregrine is healthy or not
description: >-
Health check endpoint which checks if Peregrine can connect to its
backing PostgreSQL datastore or not.
produces:
- application/text
responses:
'200':
description: Healthy
default:
description: Unhealthy
definitions:
QueryInputInfo:
type: object
properties:
query:
type: string
description: the text of the GraphQL query
variables:
type: string
description: variables for the GraphQL query
operationName:
type: string
description: the name of the operation
example:
query: '{ project {project_id} }'
operationName: null
variables: null
QueryOutputRef:
type: object
properties:
data:
type: object
description: the results of the GraphQL query
SchemaOutputRef:
type: object
properties:
data:
type: object
description: the json schema for the data dictionary
VersionOutputRef:
type: object
properties:
commit:
type: string
description: the current git commit hash for this version
version:
type: string
description: the current git tag version
dictionary:
type: object
description: the version information for the data dictionary
properties:
commit:
type: string
description: the current git commit hash for the dictionary
version:
type: string
description: the current git tag version for the dictionary
2 changes: 0 additions & 2 deletions peregrine/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ def get_user_projects(self, user):
.all()
)
return_res = {}
if not results:
raise AuthError("No project access")
for item in results:
dbgap_no, user_access = item
return_res[dbgap_no] = user_access.privilege
Expand Down
2 changes: 1 addition & 1 deletion peregrine/resources/submission/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def get_open_project_ids():
.filter(models.Project.availability_type.astext == "Open")
.all()
)
return [project['code'] for project in projects]
return [project['programs'][0]['name'] + '-' + project['code'] for project in projects]


def set_read_access_projects():
Expand Down
4 changes: 2 additions & 2 deletions peregrine/resources/submission/graphql/counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ def _queries():
Query.schema(
args=ns.NodeSubclassQuery.get_node_query_args(cls),
name=NodeCountQuery._query_name(cls),
type=Int,
type=graphene.Int,
)
for cls in Node.get_subclasses()
] + [
Query.schema(
args=transaction.TransactionLogQuery._args(),
name="_{}_count".format(transaction.TransactionLogQuery.name),
type=Int,
type=graphene.Int,
)
]

Expand Down
Loading

0 comments on commit fca3b33

Please sign in to comment.