SciCatProject / SciCatProject/backend
Job workflow: use case 2
Open
@ddijken is already working on this.
Since Sep 15, 2023.
feature
Release Jobs
- Dominant language
- TypeScript
- Stars
- 27
- Forks
- 37
- Avg merge
- 17h 32m
- Merged PRs (30d)
- 38
Description
Description
We want to define a job template that allows a user to transfer a list of selected dataset/files to a globus folder where they can access them. This job should place a message to a defined topic on a kafka server which gets read by the remote service which performs the transfer. Updates are allowed only through a POST to the job update endpoint with a specific user and token. When the transfer has been completed, than an email to the user needs should be sent.
Workflow Draft
- User is logged in as user_1. She selects the following two datasets:
- 20.500.12269/e7cc85c0-3fb3-4add-8e3b-6524192d9e71
- 20.500.12269/22c45309-878b-410a-ba01-29b754c7a406
- User clicks the transfer icon on the cart
- The transfer job is defined with the following job template in configuration:
{
"type": "user_transfer",
"create": {
"authorization": [“#has_access”],
"method": {
"type" : "kafka",
"server" : "kafka.myinstitution.ext",
"topic" : "transfer_data"
}
},
"update": {
"authorization": "transfer_service",
"status" : {
"allowed" : ["TRANSFERRED", "FAILED"],
"transitions" : {
"CREATED" : ["TRANSFERRED","FAILED"]
}
},
"method": {
"type" : "url",
"server" : "scicat.myinstitution.ext",
"endpoint" : "jobs/status/update"
},
"template" : {
"status" : "<STATUS>",
"message" : "<MESSAGE>",
"job" : "<JOB_ID>",
"token" : "<JWT_TOKEN>"
}
},
"post": [
{
"method": {
"type" : "url”,
"url" : "myemailserver.myinstitution.ext",
"action" : "POST"
“arguments” : {
“emails” : [“#user_email”]
}
},
“body” : “Transfer job ${pid} has completed. Results: ${status}”
},
]
}
- A request is posted on the job create endpoint with the following information:
{
"authenticated_user": "user_1", ???
"type": "user_transfer",
"files": [
{
"dataset.pid" : "20.500.12269/e7cc85c0-3fb3-4add-8e3b-6524192d9e71",
"file" : "*"
},
{
"dataset.pid" : "20.500.12269/22c45309-878b-410a-ba01-29b754c7a406",
"file" : "*"
}
]
}
- The job creation function receives the request and check if user_1 has access to the datasets requested. We assume that it has the permissions and her token is valid
- The new job is created with the following structure:
{
"id" :"d0eb23b8-52e3-11ee-815f-7f1d70eaebe6",
"type": "user_transfer",
"created_by" : "user_1",
"created_at" : <timestamp>,
"updated_by" : "user_1",
"updated_at" : <timestamp>,
"status" : "CREATED",
"status_message" : "Job created",
"update_history" : [
{
"updated_by" : "user_1",
"updated_at" : <timestamp>,
"status" : "CREATED",
"status_message" : "Job created",
}
],
"message_sent" : { <copy of the message posted, see #7> },
"update_configuration": {
"authorization": "transfer_service",
"status" : {
"allowed" : ["TRANSFERRED", "FAILED"],
"transitions" : {
"CREATED" : ["TRANSFERRED","FAILED"]
}
},
"method": {
"type" : "url",
"server" : "scicat.myinstitution.ext",
"endpoint" : "jobs/status/update"
}
"template" : {
"status" : "<STATUS>",
"message" : "<MESSAGE>",
"job" : "<JOB_ID>",
"token" : "<JWT_TOKEN>"
}
},
"post_configuration": [
{
"method": {
"type" : "url”,
"url" : "myemailserver.myinstitution.ext",
"action" : "POST"
“arguments” : {
“emails” : [“#user_email”]
}
},
“template” : “Transfer job ${pid} has completed. Results: ${status}”
}
]
}
- A message is posted on topic transfer_data of server kafka.myinstitution.ext with body:
{
“job_id” : d0eb23b8-52e3-11ee-815f-7f1d70eaebe6”,
"type" : "archive",
“files” : [
{
“pid” : “20.500.12269/e7cc85c0-3fb3-4add-8e3b-6524192d9e71”,
“file” : “<file_full_path>”
},
...
{
“pid” : “20.500.12269/22c45309-878b-410a-ba01-29b754c7a406”,
“file” : “<full_file_path>”
},
...
],
“updates_configuration” : {
"method" : {
“type: “url”,
“authorization”: “archiver_service”,
“server” : “scicat.myinstitution.ext”,
“endpoint” : “jobs/status/update”
},
“template” : {
“job_id” : “d0eb23b8-52e3-11ee-815f-7f1d70eaebe6”,
"status" : "<STATUS>",
"message" : "<MESSAGE>",
"token" : "<JWT_TOKEN>"
}
}
- the backend returns 200 on the job creation request
- the transfer service reads the request from the kafka topic and initiate the action
- the transfer is completed
- the transfer service sends a request to endpoint https://scicat.myinstitution.ext/jobs/status/update with the following data:
{
“job_id” : “d0eb23b8-52e3-11ee-815f-7f1d70eaebe6”,
"status" : "TRANSFERRED",
"message" : "The requested files have been transferred",
"token" : "<JWT_TOKEN_FOR_TRANSFER_SERVICE>"
}
- credetianls are verified and they are valid
- The job is updated as follow:
{
"id" :"d0eb23b8-52e3-11ee-815f-7f1d70eaebe6",
"type": "user_transfer",
"created_by" : "user_1",
"created_at" : <timestamp>,
"updated_by" : "archive_service",
"updated_at" : <timestamp>,
"status" : "TRANSFERRED",
"status_message" : "The requested files have been transferred",
"update_history" : [
{
"updated_by" : "user_1",
"updated_at" : <timestamp>,
"status" : "CREATED",
"status_message" : "Job created",
},
{
"updated_by" : "archive_service",
"updated_at" : <timestamp>,
"status" : "TRANSFERRED",
"status_message" : "The requested files have been transferred",
}
],
"message_sent" : { <copy of the message posted, see #7> },
"update_configuration": ...
"post_configuration": ...
}
- The status reached by the job is an end state, so the job is completed and we need to run the post actions
- The only post action is executed. It is defined as:
{
"method": {
"type" : "url”,
"url" : "https://myemailserver.myinstitution.ext",
"action" : "POST"
“arguments” : {
“emails” : ["#user_email"]
},
}
“template” : “The requested files have been transferred: ${status}”
}
- A POST request to the URL https://myemailserver.myinstitution.ext?email=email_user with the correct data associated.
- The external service receive the request and return a status code 200 and message "Email sent"
- The job is update accordingly
{
"id" :"d0eb23b8-52e3-11ee-815f-7f1d70eaebe6",
"type": "user_transfer",
"created_by" : "user_1",
"created_at" : <timestamp>,
"updated_by" : "archive_service",
"updated_at" : <timestamp>,
"status" : "TRANSFERRED",
"status_message" : "The requested files have been transferred",
"update_history" : [
{
"updated_by" : "user_1",
"updated_at" : <timestamp>,
"status" : "CREATED",
"status_message" : "Job created",
},
{
"updated_by" : "archive_service",
"updated_at" : <timestamp>,
"status" : "TRANSFERRED",
"status_message" : "The requested files have been transferred",
}
],
"message_sent" : { <copy of the message posted, see #7> },
"update_conmfiguration": ...
"post_configuration": [
{
"method": {
"type" : "url”,
"url" : "myemailserver.myinstitution.ext",
"action" : "POST"
“arguments” : {
“emails” : [“#user_email”]
}
},
“template” : “Transfer job ${pid} has completed. Results: ${status}”
"status_code" : 200,
"message" : "Email sent"
},
]
}
- the job is completed
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.