Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable sync job to be called from the management api #884

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1670,6 +1670,57 @@ paths:
"500":
description: On server side errors.

/graph/sync-job:
post:
tags: [Graph]
x-openapi-router-controller: thoth.management_api.api_v1
operationId: schedule_sync_job
summary: Trigger the Sync job for solver documents
parameters:
- name: secret
in: query
required: true
description: A secret to schedule the job.
schema:
type: string
- name: document_type
harshad16 marked this conversation as resolved.
Show resolved Hide resolved
in: query
required: true
description: >
The type of document to trigger the sync job for. The various document options are as follows.
* `adviser` - Sync adviser ceph documents
* `solver` - Sync solver ceph documents
* `revsolver` - Sync reverse solver ceph documents
* `package-extract` - Sync package metadata documents
* `prrovenance-checker` - Sync provenance-checker ceph documents
* `security-indicators` - Synce CVE ceph documents
schema:
type: string
enum:
- adviser
- solver
- revsolver
- package-extract
- provenance-checker
- security-indicators
- name: force
in: query
required: false
description: Perform force sync of documents.
schema:
type: string
- name: graceful
in: query
required: false
description: Continue on any error during the sync.
schema:
type: string
responses:
"201":
description: The Sync Job was triggerred successfully.
"400":
description: On invalid request.

/graph/refresh:
post:
tags: [Graph]
Expand Down
18 changes: 18 additions & 0 deletions thoth/management_api/api_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from typing import Dict
from typing import Tuple


from thoth.common import OpenShift
from thoth.common import parse_datetime
from thoth.common.exceptions import NotFoundExceptionError as OpenShiftNotFound
Expand Down Expand Up @@ -327,6 +328,23 @@ def schedule_graph_refresh(secret: str):
return {"job_id": job_id}, 201


def schedule_sync_job(
secret: str,
document_type: Optional[str],
force_sync: bool = False,
graceful: bool = True,
):
"""Schedule the sync job for a document type."""
if secret != Configuration.THOTH_MANAGEMENT_API_TOKEN:
return {"error": "Wrong secret provided"}, 401
workflow_id = _OPENSHIFT.schedule_sync_job(
document_type=document_type,
force_sync=force_sync,
graceful=graceful,
)
return {"workflow_id": workflow_id}, 201


def get_dependency_monkey_report(analysis_id: str) -> tuple:
"""Retrieve a dependency monkey run report."""
parameters = {"analysis_id": analysis_id}
Expand Down