Commit 571dd2ec authored by Zdralovic Edim's avatar Zdralovic Edim

Added route and logic to run workflow via GitURL

parent c83dd69f
......@@ -107,8 +107,8 @@ class CWLRestAPI(FlaskView):
byteData = request.data
data = json.loads(byteData.decode("utf-8"))
wf = WorkflowWrapper(data["usertoken"], self.baseDir, data["yaml"], data["cwl"], data["workflowName"])
return json.dumps(self.__wfManager.addWorkflow(wf))
#wf = WorkflowWrapper(data["usertoken"], self.baseDir, data["yaml"], data["cwl"], data["workflowName"])
return json.dumps(self.__wfManager.startWorkflow(data["workflowName"]))
@route('/workflows', methods=['GET'])
def getAllWorkflows(self):
......@@ -198,6 +198,13 @@ class CWLRestAPI(FlaskView):
else:
return jsonify({"error": "File could not be uploaded"})
@route('/workflows/gitURL', methods=['POST'])
def postGit(self):
byteData = request.data
data = json.loads(byteData.decode("utf-8"))
wf = WorkflowWrapper(data["usertoken"], self.baseDir, data["workflowName"], data["giturl"])
return json.dumps(self.__wfManager.addWorkflow(wf))
def allowed_file(self, filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
......@@ -213,6 +220,24 @@ class WorkflowManager:
This method recieves the incoming workflow from the API and starts it in a thread.
"""
self.workflowList.append(wf)
#wf.start()
#while not wf.workflowID:
# pass
return {"yaml":wf.yamlStream}
def startWorkflow(self, wfName):
"""
This method recieves the incoming workflow from the API and starts it in a thread.
"""
wf = None
for i in self.workflowList:
if i.workflowName == wfName:
wf = i
break
wf.start()
while not wf.workflowID:
......@@ -366,17 +391,19 @@ class WorkflowWrapper(threading.Thread):
############################################################
#Section: Variables
############################################################
def __init__(self, userToken="", baseDir="", yamlStream="", cwlStream="", workflowName="", gitRepoUrl=""): #Constructor
def __init__(self, userToken="", baseDir="", workflowName="", gitRepoUrl=""): #Constructor
self.restart = False
self.workflowID = ""
self.yamlStream = yamlStream
self.cwlStream = cwlStream
self.yamlStream = ""
self.cwlStream = ""
self.baseDir = baseDir
self.logFilePath = ""
self.ymlFilePath = ""
self.cwlFilePath = ""
self.toilProcess = None
self.workflowName = workflowName
self.gitRepoUrl = gitRepoUrl
self.outDir = self.baseDir+userToken+"/out/"
self.workDir = baseDir+userToken+"/work/"
......@@ -390,13 +417,14 @@ class WorkflowWrapper(threading.Thread):
self.jobs = []
self.stopped = False
self.workflowDBID = wesParser.parse_workflow(self.userToken, workflowName, self.cwlStream, wesDAO, self.yamlStream)
self.jobStoreForPipeline = self.jobStore+str(self.workflowDBID)
self.dataFilesDir = self.dataDir+str(self.workflowDBID)
self.jobStoreForPipeline = self.jobStore+str(self.workflowName)
self.dataFilesDir = self.dataDir+str(self.workflowName)
self.createDirs()
self.saveFilesToDataFileDir()
self.workflowDBID = wesParser.parse_workflow(self.userToken, workflowName, self.cwlStream, wesDAO, self.yamlStream)
self.jobs = self.getJobListFromFile()
#Problem encountered when using the file paths for the cwl and yml
......@@ -423,9 +451,11 @@ class WorkflowWrapper(threading.Thread):
def saveFilesToDataFileDir(self):
gitCloner = subprocess.Popen(['git', 'clone', self.gitRepoUrl, self.dataFilesDir], shell=False)
gitCloner.wait()
self.ymlFilePath = glob.glob(self.dataFilesDir+"/*.yml")
self.cwlFilePath = glob.glob(self.dataFilesDir+"/*.cwl")
glob.glob("/home/adam/*.txt")
self.ymlFilePath = glob.glob(self.dataFilesDir+"/*.yml")[0]
self.cwlFilePath = glob.glob(self.dataFilesDir+"/*.cwl")[0]
self.yamlStream = yaml.safe_load(open(self.ymlFilePath, "r"))
self.cwlStream = yaml.safe_load(open(self.cwlFilePath, "r"))
#glob.glob("/home/adam/*.txt")
#copying needed tools and tests, for developing only
# shutil.copytree("./data/commandLineTools", self.dataFilesDir+"/files/commandLineTools")
......@@ -460,7 +490,7 @@ class WorkflowWrapper(threading.Thread):
This method executes the workflow with the toil-cwl-runner in a sub process.
The workflow ID is extracted from the output from toil-cwl-runner and saved.
"""
self.logFilePath = self.logDir+"/log_"+str(self.workflowDBID)+".txt"
self.logFilePath = self.logDir+"/log_"+str(self.workflowName)+".txt"
logfile = open(self.logFilePath, "w")
if self.restart is False:
......
......@@ -8,13 +8,23 @@ curl -d '{"usertoken":"user1"}' -H "Content-Type: application/json" -X GET http:
curl -X GET http://localhost:5000/workflows/
DELETE workflow
curl -X DELETE http://localhost:5000/workflows/
curl -X DELETE http://localhost:5000/workflows/b9c7ef70-b363-42ed-be4a-17d6537090b4
RESTART workflow
curl -X POST http://localhost:5000/workflows/
curl -X POST http://localhost:5000/workflows/b9c7ef70-b363-42ed-be4a-17d6537090b4
testing flask:
https://damyanon.net/post/flask-series-testing/
sudo docker run -it cwlflask /bin/sh --> gets into the docker container, enables usage of terminal
docker run -p 8080:5000 cwlflask
\ No newline at end of file
docker run -p 8080:5000 cwlflask
curl -d \
'{"giturl":"https://github.com/shinra-tensei/toilCWLTest.git","usertoken":"user1","workflowName":"myHornyWorkflow"}' \
-H "Content-Type: application/json" -X POST http://localhost:5000/workflows/gitURL
curl -d \
'{"workflowName":"myHornyWorkflow"}' \
-H "Content-Type: application/json" -X POST http://localhost:5000/workflows
\ No newline at end of file
......@@ -389,7 +389,7 @@ class Workflow(Base):
__tablename__ = 'workflow'
workflowid = Column(Integer, primary_key=True)
userid = Column(Integer, ForeignKey("user.userid"), nullable=False)
workflow_name = Column(String(255))
workflow_name = Column(String(255), unique = True)
workflow_id = Column(String(255))
workflow_descriptor = Column(Text)
workflow_type = Column(String(255))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment