Skip to content
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ pip install saagieapi==<version>
| >= 2023.02 | >= 2.6.0 |
| >= 2023.03 | >= 2.7.0 |
| >= 2023.04 | >= 2.9.0 |
| >= 2023.05 | >= 2.10.0 |
| >= 2023.05 | >= 2.10.0 |
| >= 2024.01 | >= 2.11.0 |

## Contributing

Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Compatibility with your Saagie platform
>= 2023.03 >= 2.7.0
>= 2023.04 >= 2.9.0
>= 2023.05 >= 2.10.0
>= 2024.01 >= 2.11.0
=========================== ======================

Usage
Expand Down
43 changes: 33 additions & 10 deletions saagieapi/jobs/gql_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
deletable
reasons
}
sourceUrl
}
category
technology {
Expand Down Expand Up @@ -231,13 +232,25 @@
"""

GQL_CREATE_JOB = """
mutation createJobMutation($projectId: UUID!, $name: String!, $description: String, $category: String!,
$isScheduled: Boolean!, $cronScheduling: Cron, $scheduleTimezone: TimeZone
$technologyId: UUID!, $extraTechnology: ExtraTechnologyInput,
$alerting: JobPipelineAlertingInput, $resources: JobResourceInput,
$releaseNote: String, $runtimeVersion: String, $commandLine: String,
$dockerInfo: JobDockerInput, $file: Upload) {
createJob(job: {
mutation createJobMutation($projectId: UUID!,
$name: String!,
$description: String,
$category: String!,
$isScheduled: Boolean!,
$cronScheduling: Cron,
$scheduleTimezone: TimeZone
$technologyId: UUID!,
$extraTechnology: ExtraTechnologyInput,
$alerting: JobPipelineAlertingInput,
$resources: JobResourceInput,
$releaseNote: String,
$runtimeVersion: String,
$commandLine: String,
$dockerInfo: JobDockerInput,
$file: Upload,
$sourceUrl: String) {
createJob(
job: {
projectId: $projectId
name: $name
description: $description
Expand All @@ -259,6 +272,7 @@
commandLine: $commandLine
extraTechnology: $extraTechnology
dockerInfo: $dockerInfo
sourceUrl: $sourceUrl
}
file: $file
){
Expand All @@ -273,9 +287,15 @@
"""

GQL_UPGRADE_JOB = """
mutation addJobVersionMutation($jobId: UUID!, $releaseNote: String, $runtimeVersion: String, $commandLine: String,
$extraTechnology: ExtraTechnologyInput,
$usePreviousArtifact: Boolean, $dockerInfo: JobDockerInput, $file: Upload) {
mutation addJobVersionMutation($jobId: UUID!,
$releaseNote: String,
$runtimeVersion: String,
$commandLine: String,
$extraTechnology: ExtraTechnologyInput,
$usePreviousArtifact: Boolean,
$dockerInfo: JobDockerInput,
$file: Upload,
$sourceUrl: String) {
addJobVersion(
jobId: $jobId
jobVersion: {
Expand All @@ -285,6 +305,7 @@
extraTechnology: $extraTechnology
dockerInfo: $dockerInfo
usePreviousArtifact: $usePreviousArtifact
sourceUrl: $sourceUrl
}
file: $file
){
Expand Down Expand Up @@ -355,6 +376,7 @@
deletable
reasons
}
sourceUrl
}
category
technology {
Expand Down Expand Up @@ -447,6 +469,7 @@
deletable
reasons
}
sourceUrl
}
category
technology {
Expand Down
44 changes: 34 additions & 10 deletions saagieapi/jobs/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ def create(
resources: Dict = None,
emails: List = None,
status_list: List = None,
source_url: str = "",
) -> Dict:
"""Create job in given project

Expand Down Expand Up @@ -632,6 +633,8 @@ def create(
Receive an email when the job status change to a specific status
Each item of the list should be one of these following values: "REQUESTED", "QUEUED",
"RUNNING", "FAILED", "KILLED", "KILLING", "SUCCEEDED", "UNKNOWN", "AWAITING", "SKIPPED"
source_url: str, optional
URL of the source code used for the job (link to the commit for example)

Returns
-------
Expand All @@ -657,7 +660,8 @@ def create(
... schedule_timezone='Europe/Paris',
... resources={"cpu": {"request": 0.5, "limit": 2.6}, "memory": {"request": 1.0}},
... emails=['email1@saagie.io', 'email2@saagie.io'],
... status_list=["FAILED", "KILLED"]
... status_list=["FAILED", "KILLED"],
... source_url="",
... )
{
"data":{
Expand Down Expand Up @@ -723,6 +727,9 @@ def create(
if resources:
params["resources"] = resources

if source_url:
params["source_url"] = source_url

result = self.__launch_request(file, GQL_CREATE_JOB, params)
logging.info("✅ Job [%s] successfully created", job_name)
return result
Expand Down Expand Up @@ -869,6 +876,7 @@ def upgrade(
release_note: str = "",
extra_technology: str = None,
extra_technology_version: str = None,
source_url: str = "",
) -> Dict:
"""Upgrade a job

Expand All @@ -893,6 +901,8 @@ def upgrade(
None or the request will not work
extra_technology_version: str (optional)
Version of the extra technology. Leave to None when not needed
source_url: str (optional)
URL of the source code used for the job (link to the commit for example)

Returns
-------
Expand Down Expand Up @@ -952,6 +962,10 @@ def upgrade(
# Add extra technology parameter if needed
if extra_technology is not None:
params["extraTechnology"] = {"language": extra_technology, "version": extra_technology_version}

if source_url:
params["sourceUrl"] = source_url

result = self.__launch_request(file, GQL_UPGRADE_JOB, params)
logging.info("✅ Job [%s] successfully upgraded", job_id)
return result
Expand All @@ -967,6 +981,7 @@ def upgrade_by_name(
release_note: str = None,
extra_technology: str = None,
extra_technology_version: str = None,
source_url: str = "",
) -> Dict:
"""Upgrade a job

Expand All @@ -990,6 +1005,8 @@ def upgrade_by_name(
Extra technology when needed (spark jobs). If not needed, leave to None or the request will not work
extra_technology_version: str (optional)
Version of the extra technology. Leave to None when not needed
source_url: str (optional)
URL of the source code used for the job (link to the commit for example)

Returns
-------
Expand All @@ -1016,14 +1033,15 @@ def upgrade_by_name(
}
"""
return self.upgrade(
self.get_id(job_name, project_name),
file,
use_previous_artifact,
runtime_version,
command_line,
release_note,
extra_technology,
extra_technology_version,
job_id=self.get_id(job_name, project_name),
file=file,
use_previous_artifact=use_previous_artifact,
runtime_version=runtime_version,
command_line=command_line,
release_note=release_note,
extra_technology=extra_technology,
extra_technology_version=extra_technology_version,
source_url=source_url,
)

def create_or_upgrade(
Expand All @@ -1047,6 +1065,7 @@ def create_or_upgrade(
resources: Dict = None,
emails: List = None,
status_list: List = None,
source_url: str = "",
) -> Dict:
"""Create or upgrade a job

Expand Down Expand Up @@ -1091,6 +1110,8 @@ def create_or_upgrade(
Emails
status_list: list (optional)
Status list
source_url: str (optional)
URL of the source code used for the job (link to the commit for example)

Returns
-------
Expand Down Expand Up @@ -1118,7 +1139,8 @@ def create_or_upgrade(
... schedule_timezone='Europe/Paris',
... resources={"cpu": {"request": 0.5, "limit": 2.6}, "memory": {"request": 1.0}},
... emails=['email1@saagie.io', 'email2@saagie.io'],
... status_list=["FAILED", "KILLED"]
... status_list=["FAILED", "KILLED"],
... source_url="",
... )
{
"data":{
Expand Down Expand Up @@ -1152,6 +1174,7 @@ def create_or_upgrade(
release_note=release_note,
extra_technology=extra_technology,
extra_technology_version=extra_technology_version,
source_url=source_url,
)["data"]["addJobVersion"]
}

Expand Down Expand Up @@ -1190,6 +1213,7 @@ def create_or_upgrade(
"resources": resources,
"emails": emails,
"status_list": status_list,
"source_url": source_url,
}.items()
if v is not None # Remove None values from the dict
}
Expand Down
44 changes: 27 additions & 17 deletions saagieapi/pipelines/gql_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
pipelines{
id
name
alias
}
}
}
Expand All @@ -19,6 +20,7 @@
pipelines{
id
name
alias
description
alerting{
emails
Expand Down Expand Up @@ -106,6 +108,7 @@
graphPipeline(id: $id){
id
name
alias
description
alerting{
emails
Expand Down Expand Up @@ -199,6 +202,7 @@
graphPipelineByName(projectId: $projectId, name: $pipelineName) {
id
name
alias
description
alerting{
emails
Expand Down Expand Up @@ -302,7 +306,8 @@
$isScheduled: Boolean,
$cronScheduling: Cron,
$scheduleTimezone:TimeZone,
$hasExecutionVariablesEnabled: Boolean) {
$hasExecutionVariablesEnabled: Boolean,
$alias: String) {
editPipeline(pipeline:
{
id: $id
Expand All @@ -313,10 +318,12 @@
cronScheduling: $cronScheduling
scheduleTimezone: $scheduleTimezone
hasExecutionVariablesEnabled: $hasExecutionVariablesEnabled
alias: $alias
}
){
id
name
alias
description
alerting{
emails
Expand Down Expand Up @@ -380,21 +387,24 @@
$cronScheduling: Cron,
$scheduleTimezone:TimeZone,
$jobNodes: [JobNodeInput!],
$conditionNodes: [ConditionNodeInput!]) {
createGraphPipeline(pipeline: {
name: $name
description: $description
projectId: $projectId
releaseNote : $releaseNote
alerting: $alerting
isScheduled: $isScheduled
cronScheduling: $cronScheduling
scheduleTimezone: $scheduleTimezone
graph: {
jobNodes: $jobNodes
conditionNodes: $conditionNodes
$conditionNodes: [ConditionNodeInput!],
$alias: String!) {
createGraphPipeline(
pipeline: {
name: $name
description: $description
projectId: $projectId
releaseNote : $releaseNote
alerting: $alerting
isScheduled: $isScheduled
cronScheduling: $cronScheduling
scheduleTimezone: $scheduleTimezone
graph: {
jobNodes: $jobNodes
conditionNodes: $conditionNodes
}
alias: $alias
}
}
) {
id
}
Expand Down Expand Up @@ -518,8 +528,8 @@
"""

GQL_DUPLICATE_PIPELINE = """
mutation duplicatePipeline($pipelineId: UUID!) {
duplicatePipeline(originalPipelineId: $pipelineId) {
mutation duplicatePipeline($pipelineId: UUID!, $duplicateJobs: Boolean) {
duplicatePipeline(originalPipelineId: $pipelineId, duplicateJobs: $duplicateJobs) {
id
name
}
Expand Down
Loading