Skip to content

Commit

Permalink
OSCAR workflow v1
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioLangaritaBenitez committed Oct 31, 2024
1 parent f0bf60d commit 6e0fa0d
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 0 deletions.
23 changes: 23 additions & 0 deletions OSCAR_flow/upload/upload.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env cwl-runner

cwlVersion: v1.0
class: CommandLineTool
baseCommand: python
arguments: [$(inputs.uploadScript),"--bucket",$(inputs.bucket),"--filename", $(inputs.file), "--endpoint",$(inputs.minioEndpoint),"--accesskey",$(inputs.minioAccesskey),"--secretkey",$(inputs.minioSecretkey)]
inputs:
file:
type: File?
uploadScript:
type: File?
bucket:
type: string
minioEndpoint:
type: string
minioAccesskey:
type: string
minioSecretkey:
type: string
outputs:
example_out:
type: stdout
stdout: output.txt
33 changes: 33 additions & 0 deletions OSCAR_flow/upload/upload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from minio import Minio
import argparse


parser = argparse.ArgumentParser()

parser.add_argument("--bucket")
parser.add_argument("--filename")
parser.add_argument("--endpoint")
parser.add_argument("--accesskey")
parser.add_argument("--secretkey")

args = parser.parse_args()
variables = vars(args)
#print(variables)

bucket=variables['bucket']
filename=variables['filename']
endpoint=variables['endpoint']
accesskey=variables['accesskey']
secretkey=variables['secretkey']

#print (bucket.split("/")[0],)
#print('/'.join(sys.argv[1].split("/")[1:]))
#print(filename.split("/")[-1])
#print(filename)

# Create client with access and secret key.
client = Minio(str(endpoint), accesskey, secretkey)

result = client.fput_object(
bucket.split("/")[0], '/'.join(bucket.split("/")[1:])+"/"+filename.split("/")[-1], filename,
)
21 changes: 21 additions & 0 deletions OSCAR_flow/wait_output/wait.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env cwl-runner

cwlVersion: v1.0
class: CommandLineTool
baseCommand: python
arguments: [$(inputs.waitScript),"--bucket",$(inputs.bucket), "--endpoint",$(inputs.minioEndpoint),"--accesskey",$(inputs.minioAccesskey),"--secretkey",$(inputs.minioSecretkey)]
inputs:
waitScript:
type: File?
bucket:
type: string
minioEndpoint:
type: string
minioAccesskey:
type: string
minioSecretkey:
type: string
outputs:
example_out:
type: stdout
stdout: output.txt
36 changes: 36 additions & 0 deletions OSCAR_flow/wait_output/wait.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from minio import Minio
import argparse

parser = argparse.ArgumentParser()

parser.add_argument("--bucket")
parser.add_argument("--filename")
parser.add_argument("--endpoint")
parser.add_argument("--accesskey")
parser.add_argument("--secretkey")

args = parser.parse_args()
variables = vars(args)
#print(variables)

bucket=variables['bucket']
filename=variables['filename']
endpoint=variables['endpoint']
accesskey=variables['accesskey']
secretkey=variables['secretkey']


# Create client with access and secret key.
client = Minio(str(endpoint), accesskey, secretkey)

with client.listen_bucket_notification(
bucket.split("/")[0],
prefix='/'.join(bucket.split("/")[1:]),
events=["s3:ObjectCreated:*", "s3:ObjectRemoved:*"],
) as events:
for event in events:
print(event["Records"][0]["s3"]["object"]["key"])
break
#if(resultfile in event["Records"][0]["s3"]["object"]["key"]):
# info=event
# break
51 changes: 51 additions & 0 deletions OSCAR_flow/workflow-minio.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env cwl-runner

cwlVersion: v1.2
class: Workflow

requirements:
InlineJavascriptRequirement: {}

inputs:
file:
type: File?
uploadScript:
type: File?
waitScript:
type: File?
minioEndpoint:
type: string
minioAccesskey:
type: string
minioSecretkey:
type: string
bucketInput:
type: string
bucketOutput:
type: string
outputs:
out:
type: File?
outputSource: wait/example_out
steps:
upload:
run: upload/upload.cwl
in:
file: file
uploadScript: uploadScript
bucket: bucketInput
minioEndpoint: minioEndpoint
minioAccesskey: minioAccesskey
minioSecretkey: minioSecretkey
out: [example_out]
wait:
run: wait_output/wait.cwl
in:
waitScript: waitScript
bucket: bucketOutput
minioEndpoint: minioEndpoint
minioAccesskey: minioAccesskey
minioSecretkey: minioSecretkey
data:
source: upload/example_out
out: [example_out]
21 changes: 21 additions & 0 deletions OSCAR_flow/workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
file:
class: File
path: wflow_input.tar


minioEndpoint:
minioAccesskey:
minioSecretkey:


bucketInput: wflow/in
bucketOutput: wflow/out


uploadScript:
class: File
path: upload/upload.py

waitScript:
class: File
path: wait_output/wait.py

0 comments on commit 6e0fa0d

Please sign in to comment.