예제 #1
0
파일: status_api.py 프로젝트: we1l1n/aleph
def status():
    """
    ---
    get:
      summary: Get an overview of collections being processed
      description: >
        List collections being processed currently and pending task counts
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SystemStatusResponse'
      tags:
      - System
    """
    require(request.authz.logged_in)
    status = get_active_collection_status()
    active_collections = status.pop('datasets', [])
    active_foreign_ids = set(active_collections.keys())
    collections = request.authz.collections(request.authz.READ)
    serializer = CollectionSerializer(reference=True)
    results = []
    for fid in sorted(active_foreign_ids):
        collection = Collection.by_foreign_id(fid)
        if collection is None:
            continue
        if collection.id in collections:
            result = active_collections[fid]
            result['collection'] = serializer.serialize(collection.to_dict())
            result['id'] = fid
            results.append(result)
    return jsonify({'results': results, 'total': len(results)})
예제 #2
0
def create():
    require(request.authz.logged_in)
    data = parse_request(CollectionCreateSchema)
    role = Role.by_id(request.authz.id)
    sync = get_flag('sync')
    collection = create_collection(data, role=role, sync=sync)
    return CollectionSerializer.jsonify(collection)
예제 #3
0
def view(collection_id):
    """
    ---
    get:
      summary: Get a collection
      description: Return the collection with id `collection_id`
      parameters:
      - description: The collection ID.
        in: path
        name: collection_id
        required: true
        schema:
          minimum: 1
          type: integer
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Collection'
      tags:
      - Collection
    """
    collection = get_index_collection(collection_id)
    return CollectionSerializer.jsonify(collection)
예제 #4
0
def view(collection_id):
    """
    ---
    get:
      summary: Get a collection
      description: Return the collection with id `collection_id`
      parameters:
      - description: The collection ID.
        in: path
        name: collection_id
        required: true
        schema:
          minimum: 1
          type: integer
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CollectionFull'
      tags:
      - Collection
    """
    data = get_index_collection(collection_id)
    cobj = get_db_collection(collection_id)
    if get_flag("refresh", False):
        update_collection_stats(collection_id, ["schema"])
    data.update({
        "statistics": get_collection_stats(cobj.id),
        "status": get_status(cobj),
        "shallow": False,
    })
    return CollectionSerializer.jsonify(data)
예제 #5
0
def index():
    """
    ---
    get:
      summary: List collections
      description: >-
        Returns a list of collections matching a given query. Returns all the
        collections accessible by a user if no query is given.
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                allOf:
                - $ref: '#/components/schemas/QueryResponse'
                properties:
                  results:
                    type: array
                    items:
                      $ref: '#/components/schemas/Collection'
      tags:
      - Collection
    """
    result = CollectionsQuery.handle(request)
    return CollectionSerializer.jsonify_result(result)
예제 #6
0
def create():
    require(request.authz.logged_in)
    data = parse_request(CollectionCreateSchema)
    role = Role.by_id(request.authz.id)
    sync = get_flag('sync')
    collection = create_collection(data, role=role, sync=sync)
    return CollectionSerializer.jsonify(collection)
예제 #7
0
def create():
    """
    ---
    post:
      summary: Create a collection
      description: Create a collection with the given metadata
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CollectionCreate'
      tags:
        - Collection
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Collection'
    """
    require(request.authz.logged_in)
    data = parse_request('CollectionCreate')
    sync = get_flag('sync')
    collection = create_collection(data, request.authz, sync=sync)
    return CollectionSerializer.jsonify(collection)
예제 #8
0
def update(id):
    collection = get_db_collection(id, request.authz.WRITE)
    data = parse_request(CollectionUpdateSchema)
    sync = get_flag('sync')
    collection.update(data)
    db.session.commit()
    data = update_collection(collection, sync=sync)
    return CollectionSerializer.jsonify(data)
예제 #9
0
def update(collection_id):
    collection = get_db_collection(collection_id, request.authz.WRITE)
    data = parse_request(CollectionUpdateSchema)
    sync = get_flag('sync')
    collection.update(data)
    db.session.commit()
    data = update_collection(collection, sync=sync)
    return CollectionSerializer.jsonify(data)
예제 #10
0
def status():
    require(request.authz.logged_in)
    status = get_active_collection_status()
    active_collections = status.pop('datasets', [])
    active_foreign_ids = set(active_collections.keys())
    collections = request.authz.collections(request.authz.READ)
    serializer = CollectionSerializer(reference=True)
    results = []
    for fid in sorted(active_foreign_ids):
        collection = Collection.by_foreign_id(fid)
        if collection is None:
            continue
        if collection.id in collections:
            result = active_collections[fid]
            result['collection'] = serializer.serialize(collection.to_dict())
            result['id'] = fid
            results.append(result)
    return jsonify({'results': results, 'total': len(results)})
예제 #11
0
def status():
    """
    ---
    get:
      summary: Get an overview of collections and exports being processed
      description: >
        List collections being processed currently and pending task counts
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SystemStatusResponse'
      tags:
      - System
    """
    require(request.authz.logged_in)
    request.rate_limit = None
    status = get_active_dataset_status()
    datasets = status.pop("datasets", {})
    collections = (get_dataset_collection_id(d) for d in datasets.keys())
    collections = (c for c in collections if c is not None)
    collections = Collection.all_by_ids(collections, deleted=True).all()
    collections = {c.id: c for c in collections}
    serializer = CollectionSerializer(reference=True)
    results = []
    for dataset, status in sorted(datasets.items()):
        collection_id = get_dataset_collection_id(dataset)
        if not request.authz.can(collection_id, request.authz.READ):
            continue
        collection = collections.get(collection_id)
        if collection is not None:
            status["collection"] = serializer.serialize(collection.to_dict())
        results.append(status)
    return jsonify({"results": results, "total": len(results)})
예제 #12
0
def update(collection_id):
    """
    ---
    post:
      summary: Update a collection
      description: >
        Change collection metadata and update statistics.
      parameters:
      - description: The collection ID.
        in: path
        name: collection_id
        required: true
        schema:
          minimum: 1
          type: integer
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CollectionUpdate'
      tags:
        - Collection
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Collection'
    """
    collection = get_db_collection(collection_id, request.authz.WRITE)
    data = parse_request("CollectionUpdate")
    sync = get_flag("sync")
    collection.update(data, request.authz)
    db.session.commit()
    data = update_collection(collection, sync=sync)
    return CollectionSerializer.jsonify(data)
예제 #13
0
def view(id):
    collection = get_index_collection(id)
    record_audit(Audit.ACT_COLLECTION, id=id)
    return CollectionSerializer.jsonify(collection)
예제 #14
0
def index():
    result = CollectionsQuery.handle(request)
    return CollectionSerializer.jsonify_result(result)
예제 #15
0
def index():
    result = CollectionsQuery.handle(request)
    return CollectionSerializer.jsonify_result(result)
예제 #16
0
def view(collection_id):
    collection = get_index_collection(collection_id)
    return CollectionSerializer.jsonify(collection)
예제 #17
0
def view(collection_id):
    collection = get_index_collection(collection_id)
    record_audit(Audit.ACT_COLLECTION, id=collection_id)
    return CollectionSerializer.jsonify(collection)