Exemplo n.º 1
0
def submit_job():
    """
    Endpoint to submit a database to be processed and added to the metadata database
    This is using docstring for specifications
    ---
    tags:
      - jobs
    parameters:
      - in: body
        name: body
        description: copy database job object
        required: false
        schema:
          $ref: '#/definitions/submit'
    operationId: jobs
    consumes:
      - application/json
    produces:
      - application/json
    security:
      submit_auth:
        - 'write:submit'
        - 'read:submit'
    schemes: ['http', 'https']
    deprecated: false
    externalDocs:
      description: Project repository
      url: http://github.com/rochacbruno/flasgger
    definitions:
      submit:
        title: Database copy job
        description: A job to process a database and add it to the metadata database from a source MySQL server to a target MySQL server.
        type: object
        required:
          -metadata_uri
          -database_uri
          -update_type
          -comment
          -email
          -source
        properties:
          metadata_uri:
            type: string
            example: 'mysql://*****:*****@server:port/metadata_db'
          database_uri:
            type: string
            example: 'mysql://*****:*****@server:port/db'
          e_release:
            type: integer
            example: 91
          eg_release:
            type: integer
            example: 38
          release_date:
            type: string
            example: '2017-12-06'
          current_release:
            type: integer
            example: 1
          email:
            type: string
            example: 'undefined'
          update_type:
            type: string
            example: 'new_assembly'
          comment:
            type: string
            example: 'handover of new species'
          source:
            type: string
            example: '*****@*****.**'
    responses:
      200:
        description: submit of a metadata job
        schema:
          $ref: '#/definitions/submit'
        examples:
          {metadata_uri : "mysql://*****:*****@mysql-ens-general-dev-1:4484/ensembl_metadata_new_test", database_uri : "mysql://ensro@mysql-ensembl-mirror:4240/octodon_degus_otherfeatures_91_1", update_type : "new_assembly", source : "Handover", comment : "handover new Leopard database", email : "*****@*****.**"}
    """
    if json_pattern.match(request.headers['Content-Type']):
        request.json["metadata_uri"] = app.config["METADATA_URI"]
        app.logger.debug('Submitting metadata job %s', request.json)
        try:
            job = get_hive().create_job(app.analysis, request.json)
        except ValueError as e:
            raise HTTPRequestError(str(e), 404)
        results = {
            "job_id": job.job_id
        }
        email = request.json.get('email')
        email_notification = request.json.get('email_notification')
        if email != None and email != '' and email_notification != None:
            app.logger.debug('Submitting email request for %s', email)
            email_results = email_when_complete.delay(
                request.url_root + "jobs/" + str(job.job_id) + "?format=email",
                email)
            results['email_task'] = email_results.id
        return jsonify(results)
    else:
        app.logger.error('Could not handle input of type %s',
                         request.headers['Content-Type'])
        raise HTTPRequestError('Could not handle input of type %s' %
                               request.headers['Content-Type'])
Exemplo n.º 2
0
def delete_job(process, job_id):
    """
    Endpoint to delete a given job result using job_id
    ---
    tags:
      - jobs
    parameters:
      - name: process
        in: path
        type: string
        required: true
        default: 1
        description: process name
      - name: job_id
        in: path
        type: integer
        required: true
        default: 1
        description: id of the job
    operationId: jobs
    consumes:
      - application/json
    produces:
      - application/json
    security:
      delete_auth:
        - 'write:delete'
        - 'read:delete'
    schemes: ['http', 'https']
    deprecated: false
    externalDocs:
      description: Project repository
      url: http://github.com/rochacbruno/flasgger
    definitions:
      job_id:
        type: object
        properties:
          job_id:
            type: integer
            items:
              $ref: '#/definitions/job_id'
      id:
        type: integer
        properties:
          id:
            type: integer
            items:
              $ref: '#/definitions/id'
    responses:
      200:
        description: Job_id that has been deleted
        schema:
          $ref: '#/definitions/job_id'
        examples:
          id: 1
    """
    hive = get_hive(process)
    job = hive.get_job_by_id(job_id)
    try:
        hive.delete_job(job)
    except ValueError as e:
        raise HTTPRequestError(str(e), 404)
    return jsonify({"id": job_id, "process": process})
Exemplo n.º 3
0
def job_result(job_id):
    """
    Endpoint to retrieve a given job result using job_id
    This is using docstring for specifications
    ---
    tags:
      - jobs
    parameters:
      - name: job_id
        in: path
        type: integer
        required: true
        default: 1
        description: id of the job
      - name: format
        in: query
        type: string
        required: false
        description: optional parameter (email, failures)
      - name: email
        in: query
        type: string
        required: false
        description: Email address to use in report
    operationId: jobs
    consumes:
      - application/json
    produces:
      - application/json
    security:
      results_auth:
        - 'write:results'
        - 'read:results'
    schemes: ['http', 'https']
    deprecated: false
    externalDocs:
      description: Project repository
      url: http://github.com/rochacbruno/flasgger
    definitions:
      job_id:
        type: object
        properties:
          job_id:
            type: integer
            items:
              $ref: '#/definitions/job_id'
      result:
        type: object
        properties:
          result:
            type: string
            items:
              $ref: '#/definitions/result'
    responses:
      200:
        description: Result of a metadata job
        schema:
          $ref: '#/definitions/job_id'
        examples:
          id: 1
          input:
            metadata_uri: mysql://user:password@server:port/ensembl_metadata
            database_uri: mysql://user:password@server:port/saccharomyces_cerevisiae_core_91_4
            timestamp: 1515494114.263158
          output:
            runtime: 31 seconds
            metadata_uri: mysql://user:password@server:port/ensembl_metadata
            database_uri: mysql://user:password@server:port/saccharomyces_cerevisiae_core_91_4
          status: complete
    """
    fmt = request.args.get('format')
    app.logger.debug('Format %s', fmt)
    if fmt == 'email':
        email = request.args.get('email')
        return job_email(email, job_id)
    elif fmt == 'failures':
        return failure(job_id)
    elif fmt is None:
        app.logger.info('Retrieving job with ID %s', job_id)
        try:
            job_result = get_hive().get_result_for_job_id(job_id, child=True)
        except ValueError as e:
            raise HTTPRequestError(str(e), 404)
        return jsonify(job_result)
    else:
        raise HTTPRequestError("Format " + fmt + " not valid")
Exemplo n.º 4
0
def handovers():
    """
    Endpoint to submit an handover job
    This is using docstring for specifications
    ---
    tags:
      - handovers
    parameters:
      - in: body
        name: body
        description: healthcheck object
        required: false
        schema:
          $ref: '#/definitions/handovers'
    operationId: handovers
    consumes:
      - application/json
    produces:
      - application/json
    security:
      handovers_auth:
        - 'write:handovers'
        - 'read:handovers'
    schemes: ['http', 'https']
    deprecated: false
    externalDocs:
      description: Project repository
      url: http://github.com/rochacbruno/flasgger
    definitions:
      handovers:
        title: handover job
        description: A job to handover a database, the database will be healthchecked, copied and added to metadata database
        type: object
        required:
          -src_uri
          -contact
          -type
          -comment
        properties:
          src_uri:
            type: string
            example: 'mysql://user@server:port/saccharomyces_cerevisiae_core_91_4'
          comment:
            type: string
            example: 'handover new Panda OF'
          contact:
            type: string
            example: '*****@*****.**'
    responses:
      200:
        description: submit of an handover job
        schema:
          $ref: '#/definitions/handovers'
        examples:
          {src_uri: "mysql://user@server:port/saccharomyces_cerevisiae_core_91_4", contact: "*****@*****.**", comment: "handover new Panda OF"}
    """
    if json_pattern.match(request.headers['Content-Type']):
        app.logger.debug('Submitting handover request %s', request.json)
        spec = request.json
        if 'src_uri' not in spec or 'contact' not in spec or 'comment' not in spec:
            raise HTTPRequestError(
                "Handover specification incomplete - please specify src_uri, contact and comment"
            )
        ticket = handover_database(spec)
        app.logger.info('Ticket: %s', ticket)
        return jsonify(ticket)
    else:
        raise HTTPRequestError('Could not handle input of type %s' %
                               request.headers['Content-Type'])
Exemplo n.º 5
0
def job(process, job_id):
    """
    Endpoint to retrieve a given job result for a process and job id
    ---
    tags:
      - jobs
    parameters:
      - name: process
        in: path
        type: string
        required: true
        default: 1
        description: process name
      - name: job_id
        in: path
        type: integer
        required: true
        default: 1
        description: id of the job
    operationId: jobs
    produces:
      - application/json
    security:
      results_auth:
        - 'write:results'
        - 'read:results'
    schemes: ['http', 'https']
    deprecated: false
    externalDocs:
      description: Project repository
      url: http://github.com/rochacbruno/flasgger
    definitions:
      job_id:
        type: object
        properties:
          job_id:
            type: integer
            items:
              $ref: '#/definitions/job_id'
      result:
        type: object
        properties:
          result:
            type: string
            items:
              $ref: '#/definitions/result'
    responses:
      200:
        description: Result of an event job
        schema:
          $ref: '#/definitions/job_id'
    """
    output_format = request.args.get('format')
    if output_format == 'email':
        email = request.args.get('email')
        if email == None:
            raise HTTPRequestError("Email not specified")
        return results_email(request.args.get('email'), process, job_id)
    elif output_format == None:
        return results(process, job_id)
    else:
        raise HTTPRequestError("Format {} not known".format(output_format))
Exemplo n.º 6
0
def handover_result(handover_token):
    """
    Endpoint to get an handover job detail
    This is using docstring for specifications
    ---
    tags:
      - handovers
    parameters:
      - name: handover_token
        in: path
        type: string
        required: true
        default: 15ce20fd-68cd-11e8-8117-005056ab00f0
        description: handover token for the database handed over
    operationId: handovers
    consumes:
      - application/json
    produces:
      - application/json
    security:
      handovers_auth:
        - 'write:handovers'
        - 'read:handovers'
    schemes: ['http', 'https']
    deprecated: false
    externalDocs:
      description: Project repository
      url: http://github.com/rochacbruno/flasgger
    definitions:
      handovers:
        title: Get a handover job details
        description: This will retrieve a handover job details
        type: object
        required:
          -handover_token
        properties:
          handover_token:
            type: string
            example: '15ce20fd-68cd-11e8-8117-005056ab00f0'
    responses:
      200:
        description: Retrieve an handover job ticket
        schema:
          $ref: '#/definitions/handovers'
        examples:
          [{"comment": "handover new Tiger database", "contact": "*****@*****.**", "handover_token": "605f1191-7a13-11e8-aa7e-005056ab00f0", "id": "X1qcQWQBiZ0vMed2vaAt", "message": "Metadata load complete, Handover successful", "progress_total": 3, "report_time": "2018-06-27T15:19:08.459", "src_uri": "mysql://ensro@mysql-ens-general-prod-1:4525/panthera_tigris_altaica_core_93_1", "tgt_uri": "mysql://ensro@mysql-ens-general-dev-1:4484/panthera_tigris_altaica_core_93_1"} ]
    """
    es = Elasticsearch([{'host': es_host, 'port': es_port}])
    handover_detail = []
    res_error = es.search(index=es_index,
                          body={
                              "query": {
                                  "bool": {
                                      "must": [{
                                          "term": {
                                              "params.handover_token.keyword":
                                              str(handover_token)
                                          }
                                      }, {
                                          "term": {
                                              "report_type.keyword": "ERROR"
                                          }
                                      }],
                                      "must_not": [],
                                      "should": []
                                  }
                              },
                              "from": 0,
                              "size": 1,
                              "sort": [{
                                  "report_time": {
                                      "order": "desc"
                                  }
                              }],
                              "aggs": {}
                          })
    app.logger.info('Retrieving handover data with token %s', handover_token)
    if len(res_error['hits']['hits']) != 0:
        for doc in res_error['hits']['hits']:
            result = {"id": doc['_id']}
            result['message'] = doc['_source']['message']
            result['comment'] = doc['_source']['params']['comment']
            result['handover_token'] = doc['_source']['params'][
                'handover_token']
            result['contact'] = doc['_source']['params']['contact']
            result['src_uri'] = doc['_source']['params']['src_uri']
            result['tgt_uri'] = doc['_source']['params']['tgt_uri']
            result['report_time'] = doc['_source']['report_time']
            handover_detail.append(result)
    else:
        res = es.search(index=es_index,
                        body={
                            "query": {
                                "bool": {
                                    "must": [{
                                        "term": {
                                            "params.handover_token.keyword":
                                            str(handover_token)
                                        }
                                    }, {
                                        "term": {
                                            "report_type.keyword": "INFO"
                                        }
                                    }],
                                    "must_not": [],
                                    "should": []
                                }
                            },
                            "from": 0,
                            "size": 1,
                            "sort": [{
                                "report_time": {
                                    "order": "desc"
                                }
                            }],
                            "aggs": {}
                        })
        for doc in res['hits']['hits']:
            result = {"id": doc['_id']}
            result['message'] = doc['_source']['message']
            result['comment'] = doc['_source']['params']['comment']
            result['handover_token'] = doc['_source']['params'][
                'handover_token']
            result['contact'] = doc['_source']['params']['contact']
            result['src_uri'] = doc['_source']['params']['src_uri']
            result['tgt_uri'] = doc['_source']['params']['tgt_uri']
            result['progress_complete'] = doc['_source']['params'][
                'progress_complete']
            result['progress_total'] = doc['_source']['params'][
                'progress_total']
            result['report_time'] = doc['_source']['report_time']
            handover_detail.append(result)
    if len(handover_detail) == 0:
        raise HTTPRequestError('Handover token %s not found' % handover_token,
                               404)
    else:
        return jsonify(handover_detail)
Exemplo n.º 7
0
def delete_handover(handover_token):
    """
    Endpoint to delete all the reports linked to a handover_token
    This is using docstring for specifications
    ---
    tags:
      - handovers
    parameters:
      - name: handover_token
        in: path
        type: string
        required: true
        default: 15ce20fd-68cd-11e8-8117-005056ab00f0
        description: handover token for the database handed over
    operationId: handovers
    consumes:
      - application/json
    produces:
      - application/json
    security:
      delete_auth:
        - 'write:delete'
        - 'read:delete'
    schemes: ['http', 'https']
    deprecated: false
    externalDocs:
      description: Project repository
      url: http://github.com/rochacbruno/flasgger
    definitions:
      handover_token:
        type: object
        properties:
          handover_token:
            type: integer
            items:
              $ref: '#/definitions/handover_token'
      id:
        type: integer
        properties:
          id:
            type: integer
            items:
              $ref: '#/definitions/id'
    responses:
      200:
        description: handover_token of the reports that need deleting
        schema:
          $ref: '#/definitions/handover_token'
        examples:
          id: 15ce20fd-68cd-11e8-8117-005056ab00f0
    """
    try:
        app.logger.info('Retrieving handover data with token %s',
                        handover_token)
        es = Elasticsearch([{'host': es_host, 'port': es_port}])
        es.delete_by_query(index=es_index,
                           doc_type='report',
                           body={
                               "query": {
                                   "bool": {
                                       "must": [{
                                           "term": {
                                               "params.handover_token.keyword":
                                               str(handover_token)
                                           }
                                       }]
                                   }
                               }
                           })
        return jsonify(str(handover_token))
    except NotFoundError as e:
        raise HTTPRequestError(
            'Error while looking for handover token: {} - {}:{}'.format(
                handover_token, e.error, e.info['error']['reason']), 404)
Exemplo n.º 8
0
def job_result(job_id):
    """
    Endpoint to retrieve a given job result using job_id
    This is using docstring for specifications
    ---
    tags:
      - jobs
    parameters:
      - name: job_id
        in: path
        type: integer
        required: true
        default: 1
        description: id of the job
      - name: format
        in: query
        type: string
        required: false
        description: optional parameter (email, failures)
      - name: email
        in: query
        type: string
        required: false
        description: Email address to use in report
    operationId: jobs
    consumes:
      - application/json
    produces:
      - application/json
    security:
      results_auth:
        - 'write:results'
        - 'read:results'
    schemes: ['http', 'https']
    deprecated: false
    externalDocs:
      description: Project repository
      url: http://github.com/rochacbruno/flasgger
    definitions:
      job_id:
        type: object
        properties:
          job_id:
            type: integer
            items:
              $ref: '#/definitions/job_id'
      result:
        type: object
        properties:
          result:
            type: string
            items:
              $ref: '#/definitions/result'
    responses:
      200:
        description: Result of an healthcheck job
        schema:
          $ref: '#/definitions/job_id'
        examples:
          id: 1
          input:
             compara_uri: mysql://user@server:port/ensembl_compara_master
             data_files_path: /nfs/panda/ensembl/production/ensemblftp/data_files/
             db_uri: mysql://user@server:port/ailuropoda_melanoleuca_core_91_1
             hc_names: ['org.ensembl.healthcheck.testcase.eg_core.GeneSource']
             live_uri: mysql://user@server:port/
             production_uri: mysql://user@server:port/ensembl_production_91
             staging_uri: mysql://user@server:port/
             timestamp: 1515494166.015124
          output:
             db_name: ailuropoda_melanoleuca_core_91_1
             db_uri: mysql://user@server:port/ailuropoda_melanoleuca_core_91_1
             results:
                org.ensembl.healthcheck.testcase.eg_core.GeneSource:
                    messages: ['PROBLEM: Found 23262 genes with source Ensembl which should be replaced with an appropriate GOA compatible name for the original source']
                    status: failed
             status: failed
          status: complete
    """
    fmt = request.args.get('format')
    logger.debug("Format " + str(fmt))
    if fmt == 'email':
        email = request.args.get('email')
        return job_email(email, job_id)
    elif fmt == 'failures':
        return job_failures(job_id)
    elif fmt is None:
        logger.info("Retrieving job with ID " + str(job_id))
        try:
            job_result = get_hive().get_result_for_job_id(job_id)
        except ValueError as e:
            raise HTTPRequestError(str(e), 404)
        return jsonify(job_result)
    else:
        raise HTTPRequestError("Format " + fmt + " not valid")
Exemplo n.º 9
0
def submit_job():
    """
    Endpoint to submit an healthcheck job
    This is using docstring for specifications
    ---
    tags:
      - jobs
    parameters:
      - in: body
        name: body
        description: healthcheck object
        required: false
        schema:
          $ref: '#/definitions/submit'
    operationId: jobs
    consumes:
      - application/json
    produces:
      - application/json
    security:
      submit_auth:
        - 'write:submit'
        - 'read:submit'
    schemes: ['http', 'https']
    deprecated: false
    externalDocs:
      description: Project repository
      url: http://github.com/rochacbruno/flasgger
    definitions:
      submit:
        title: Healthcheck job
        description: A job to run multiple healthchecks or healthchecks groups on a given database URI.
        type: object
        required:
          -db_uri
          -compara_uri
          -live_uri
          -production_uri
          -staging_uri
          -hc_names
          -data_files_path
        properties:
          db_uri:
            type: string
            example: 'mysql://user@server:port/saccharomyces_cerevisiae_core_91_4'
          compara_uri:
            type: string
            example: 'mysql://*****:*****@server:port/compara_master'
          live_uri:
            type: string
            example: 'mysql://*****:*****@server:port/'
          staging_uri:
            type: string
            example: 'mysql://*****:*****@server:port/'
          production_uri:
            type: string
            example: 'mysql://*****:*****@server:port/ensembl_production_xx'
          hc_names:
            type: array
            items:
              type: string
              example: 'org.ensembl.healthcheck.testcase.generic.StableID'
          hc_groups:
            type: array
            items:
              type: string
              example: ''
          data_files_path:
            type: string
            example: '/nfs/panda/ensembl/production/ensemblftp/data_files/'
          email:
            type: string
            example: 'undefined'
    responses:
      200:
        description: submit of an healthcheck job
        schema:
          $ref: '#/definitions/submit'
        examples:
          {db_uri: "mysql://user@server:port/saccharomyces_cerevisiae_core_91_4", staging_uri: "mysql://user@server:port/", live_uri: "mysql://user@server:port/", production_uri: "mysql://user@server:port/ensembl_production_91", compara_uri: "mysql://user@server:port/ensembl_compara_master", hc_names: ["org.ensembl.healthcheck.testcase.generic.StableID"]}
    """
    if json_pattern.match(request.headers['Content-Type']):
        logger.debug("Submitting HC " + str(request.json))
        try:
            job = get_hive().create_job(app.analysis, request.json)
        except ValueError as e:
            raise HTTPRequestError(str(e), 404)
        results = {"job_id": job.job_id};
        email = request.json.get('email')
        if email is not None and email != '':
            logger.debug("Submitting email request for  " + email)
            email_results = email_when_complete.delay(request.url_root + "jobs/" + str(job.job_id) + "?format=email",
                                                      email)
            results['email_task'] = email_results.id
        return jsonify(results), 201
    else:
        logger.error("Could not handle input of type " + request.headers['Content-Type'])
        raise HTTPRequestError("Could not handle input of type " + request.headers['Content-Type'])
Exemplo n.º 10
0
def delete(job_id):
    """
    Endpoint to delete a given job result using job_id
    This is using docstring for specifications
    ---
    tags:
      - jobs
    parameters:
      - name: job_id
        in: path
        type: integer
        required: true
        description: id of the job
      - name: kill
        in: query
        type: integer
        required: false
        default: 0
        description: set to 1 to kill the process
    operationId: jobs
    consumes:
      - application/json
    produces:
      - application/json
    security:
      delete_auth:
        - 'write:delete'
        - 'read:delete'
    schemes: ['http', 'https']
    deprecated: false
    externalDocs:
      description: Project repository
      url: http://github.com/rochacbruno/flasgger
    definitions:
      job_id:
        type: object
        properties:
          job_id:
            type: integer
            items:
              $ref: '#/definitions/job_id'
      id:
        type: integer
        properties:
          id:
            type: integer
            items:
              $ref: '#/definitions/id'
    responses:
      200:
        description: Job_id that has been deleted
        schema:
          $ref: '#/definitions/job_id'
        examples:
          id: 1
    """
    try:
        if 'kill' in request.args.keys() and request.args['kill'] == 1:
            kill_job(job_id)
        job = get_hive().get_job_by_id(job_id)
        hive.delete_job(job)
    except ValueError as e:
        raise HTTPRequestError(str(e), 404)
    return jsonify({"id": job_id})
Exemplo n.º 11
0
def list_databases_endpoint():
    """
    Endpoint to retrieve a list of databases from a server given as URI
    This is using docstring for specifications
    ---
    tags:
      - databases
    parameters:
      - in : query
        name: db_uri
        type: string
        required: true
        default: mysql://user@server:port/
        description: MySQL server db_uri
      - in : query
        name: query
        type: string
        required: true
        default: homo_sapiens
        description: query use to find databases
    operationId: databases
    consumes:
      - application/json
    produces:
      - application/json
    security:
      list_databases_auth:
        - 'write:list_databases'
        - 'read:list_databases'
    schemes: ['http', 'https']
    deprecated: false
    externalDocs:
      description: Project repository
      url: http://github.com/rochacbruno/flasgger
    definitions:
      db_uri:
        type: db_uri
        properties:
          db_uri:
            type: string
            items:
              $ref: '#/definitions/db_uri'
      query:
        type: query
        properties:
          query:
            type: string
            items:
              $ref: '#/definitions/query'
      list_databases:
        type: object
        properties:
          list_databases:
            type: string
            items:
              $ref: '#/definitions/list_databases'
    responses:
      200:
        description: list_databases of a MySQL server
        schema:
          $ref: '#/definitions/list_databases'
        examples:
          ["homo_sapiens_cdna_91_38", "homo_sapiens_core_91_38","homo_sapiens_funcgen_91_38","homo_sapiens_otherfeatures_91_38","homo_sapiens_rnaseq_91_38","homo_sapiens_variation_91_38"]
    """
    db_uri = request.args.get('db_uri')
    query = request.args.get('query')
    logger.debug("Finding dbs matching " + query + " on " + db_uri)
    try:
        db_list = list_databases(db_uri, query)
    except ValueError as e:
        raise HTTPRequestError(str(e))
    return jsonify(db_list)
Exemplo n.º 12
0
def jobs(job_id):
    """
    Endpoint to retrieve a given job result using job_id
    This is using docstring for specifications
    ---
    tags:
      - jobs
    parameters:
      - name: job_id
        in: path
        type: integer
        required: true
        description: id of the job
      - name: format
        in: query
        type: string
        required: false
        description: optional output format (failures, email)
    operationId: jobs
    consumes:
      - application/json
    produces:
      - application/json
    security:
      results_auth:
        - 'write:results'
        - 'read:results'
    schemes: ['http', 'https']
    deprecated: false
    externalDocs:
      description: Project repository
      url: http://github.com/rochacbruno/flasgger
    definitions:
      job_id:
        type: object
        properties:
          job_id:
            type: integer
            items:
              $ref: '#/definitions/job_id'
      result:
        type: object
        properties:
          result:
            type: string
            items:
              $ref: '#/definitions/result'
    responses:
      200:
        description: Result of an healthcheck job
        schema:
          $ref: '#/definitions/job_id'
        examples:
          id: 1
          input:
            drop: 1
            source_db_uri: mysql://user@server:port/saccharomyces_cerevisiae_core_91_4
            target_db_uri: mysql://user:password@server:port/saccharomyces_cerevisiae_core_91_4
            timestamp: 1515494114.263158
          output:
            runtime: 31 seconds
            source_db_uri: mysql://user@server:port/saccharomyces_cerevisiae_core_91_4
            target_db_uri: mysql://user:password@server:port/saccharomyces_cerevisiae_core_91_4
          status: complete
    """
    fmt = request.args.get('format')
    if fmt == 'email':
        return job_email(request.args.get('email'), job_id)
    elif fmt == 'failures':
        return failure(job_id)
    elif fmt is None:
        logger.info("Retrieving job with ID " + str(job_id))
        try:
            job_results = get_hive().get_result_for_job_id(job_id)
        except ValueError as e:
            raise HTTPRequestError(str(e), 404)
        return jsonify(job_results)
    else:
        raise HTTPRequestError("Format " + str(fmt) + " not known")
Exemplo n.º 13
0
def submit():
    """
    Endpoint to submit a database copy job
    This is using docstring for specifications
    ---
    tags:
      - jobs
    parameters:
      - in: body
        name: body
        description: copy database job object
        requiered: false
        schema:
          $ref: '#/definitions/submit'
    operationId: jobs
    consumes:
      - application/json
    produces:
      - application/json
    security:
      submit_auth:
        - 'write:submit'
        - 'read:submit'
    schemes: ['http', 'https']
    deprecated: false
    externalDocs:
      description: Project repository
      url: http://github.com/rochacbruno/flasgger
    definitions:
      submit:
        title: Database copy job
        description: A job to copy a database from a source MySQL server to a target MySQL server.
        type: object
        required:
          -source_db_uri
          -target_db_uri
        properties:
          source_db_uri:
            type: string
            example: 'mysql://user@server:port/saccharomyces_cerevisiae_core_91_4'
          target_db_uri:
            type: string
            example: 'mysql://*****:*****@server:port/'
          only_tables:
            type: string
            example: 'undefined'
          skip_tables:
            type: string
            example: 'undefined'
          update:
            type: integer
            example: 0
          drop:
            type: integer
            example: 0
          convert_innodb:
            type: integer
            example: 0
          email:
            type: string
            example: 'undefined'
    responses:
      200:
        description: submit of a copy job
        schema:
          $ref: '#/definitions/submit'
        examples:
          {source_db_uri: "mysql://user@server:port/saccharomyces_cerevisiae_core_91_4", target_db_uri: "mysql://*****:*****@server:port/saccharomyces_cerevisiae_core_91_4", only_tables: undefined, skip_tables: undefined, update: undefined, drop: 1, convert_innodb: 0, skip_optimize: 0, email: undefined }
    """
    if json_pattern.match(request.headers['Content-Type']):
        logger.debug("Submitting Database copy " + str(request.json))
        try:
            job = get_hive().create_job(app.analysis, request.json)
        except ValueError as e:
            raise HTTPRequestError(str(e))
        results = {
            "job_id": job.job_id
        }
        email = request.json.get('email')
        if email != None and email != '':
            logger.debug("Submitting email request for  " + email)
            email_results = email_when_complete.delay(
                request.url_root + "jobs/" + str(job.job_id) + "?format=email",
                email)
            results['email_task'] = email_results.id
        return jsonify(results)
    else:
        logger.error("Could not handle input of type " +
                     request.headers['Content-Type'])
        raise HTTPRequestError("Could not handle input of type " +
                               request.headers['Content-Type'])
Exemplo n.º 14
0
def list_servers_endpoint(user):
    """
    Endpoint to list the mysql servers accesible by a given user
    This is using docstring for specifications
    ---
    tags:
      - servers
    parameters:
      - name: user
        in: path
        type: string
        required: true
        default: ensro
        description: MySQL server user name
      - in: query
        name: query
        type: string
        required: true
        default: server_name
        description: MySQL server host name used to filter down the list
    operationId: servers
    consumes:
      - application/json
    produces:
      - application/json
    security:
      list_servers_auth:
        - 'write:list_servers'
        - 'read:list_servers'
    schemes: ['http', 'https']
    deprecated: false
    externalDocs:
      description: Project repository
      url: http://github.com/rochacbruno/flasgger
    definitions:
      user:
        type: object
        properties:
          user:
            type: string
            items:
              $ref: '#/definitions/user'
      query:
        type: object
        properties:
          query:
            type: string
            items:
              $ref: '#/definitions/query'
      list_servers:
        type: object
        properties:
          list_servers:
            type: string
            items:
              $ref: '#/definitions/list_servers'
    responses:
      200:
        description: list_servers of a MySQL server
        schema:
          $ref: '#/definitions/host'
        examples:
          ["mysql://user@server:port/"]
    """
    query = request.args.get('query')
    if query is None:
        raise HTTPRequestError("Query not specified")
    if user in get_servers():
        logger.debug("Finding servers matching " + query + " for " + user)
        user_urls = get_servers()[user] or []
        urls = filter(lambda x: query in x, user_urls)
        return jsonify(list(urls))
    else:
        raise HTTPRequestError("User " + user + " not found", 404)
Exemplo n.º 15
0
def get_status_endpoint(host):
    """
    Endpoint to retrieve the status of a give MySQL host
    This is using docstring for specifications
    ---
    tags:
      - hosts
    parameters:
      - name: host
        in: path
        type: string
        required: true
        default: server_name
        description: MySQL server host name
      - name: dir_name
        in: query
        type: string
        description: database directory name on MySQL server
    operationId: hosts
    consumes:
      - application/json
    produces:
      - application/json
    security:
      status_auth:
        - 'write:status'
        - 'read:status'
    schemes: ['http', 'https']
    deprecated: false
    externalDocs:
      description: Project repository
      url: http://github.com/rochacbruno/flasgger
    definitions:
      host:
        type: object
        properties:
          host:
            type: string
            items:
              $ref: '#/definitions/host'
      status:
        type: object
        properties:
          status:
            type: string
            items:
              $ref: '#/definitions/status'
      dir_name:
        type: dir_name
        properties:
          dir_name:
            type: string
            items:
              $ref: '#/definitions/dir_name'
    responses:
      200:
        description: Status of a MySQL server
        schema:
          $ref: '#/definitions/host'
        examples:
          dir: /instances
          disk_available_g: 1504
          disk_total_g: 6048
          disk_used_g: 4258
          disk_used_pct: 70.4
          host: server_name
          load_15m: 0.05
          load_1m: 0.0
          load_5m: 0.01
          memory_available_m: 270
          memory_total_m: 48394
          memory_used_m: 23624
          memory_used_pct: 48.8
          n_cpus: 16
    """
    dir_name = request.args.get('dir_name')
    if (dir_name is None):
        dir_name = '/instances'
    logger.debug("Finding status of " + host + " (dir " + dir_name + ")")
    try:
        status = get_status(host=host, dir_name=dir_name)
    except OSError as e:
        raise HTTPRequestError(str(e))
    return jsonify(status)
Exemplo n.º 16
0
def database_sizes_endpoint():
    """
    Endpoint to retrieve a list of databases and their size from a MySQL server given as URI
    This is using docstring for specifications
    ---
    tags:
      - databases
    parameters:
      - in : query
        name: db_uri
        type: string
        required: true
        default: mysql://user@server:port/
        description: MySQL server db_uri
      - in : query
        name: query
        type: string
        required: true
        default: homo_sapiens
        description: query use to find databases
      - in : query
        name: dir_name
        type: string
        required: false
        default: /instances
        description: Directory name where the database files are located on the MySQL server
    operationId: database_sizes
    consumes:
      - application/json
    produces:
      - application/json
    security:
      database_sizes_auth:
        - 'write:database_sizes'
        - 'read:database_sizes'
    schemes: ['http', 'https']
    deprecated: false
    externalDocs:
      description: Project repository
      url: http://github.com/rochacbruno/flasgger
    definitions:
      db_uri:
        type: db_uri
        properties:
          db_uri:
            type: string
            items:
              $ref: '#/definitions/db_uri'
      query:
        type: query
        properties:
          query:
            type: string
            items:
              $ref: '#/definitions/query'
      dir_name:
        type: dir_name
        properties:
          dir_name:
            type: string
            items:
              $ref: '#/definitions/dir_name'
      database_sizes:
        type: object
        properties:
          database_sizes:
            type: string
            items:
              $ref: '#/definitions/database_sizes'
    responses:
      200:
        description: database_sizes of all the databases from a MySQL server
        schema:
          $ref: '#/definitions/database_sizes'
        examples:
          {  "mus_caroli_core_91_11": 4890, "ncbi_taxonomy": 362 }
    """
    db_uri = request.args.get('db_uri')
    query = request.args.get('query')
    dir_name = request.args.get('dir_name')
    if (dir_name is None):
        dir_name = '/instances'
    logger.debug("Finding sizes of dbs matching " + str(query) + " on " +
                 db_uri)
    try:
        db_sizes = get_database_sizes(db_uri, query, dir_name)
    except ValueError as e:
        raise HTTPRequestError(str(e))
    return jsonify(db_sizes)