Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
portal-backend
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
HBP Medical Informatics Platform
portal-backend
Commits
5281c187
Commit
5281c187
authored
5 years ago
by
Manuel Spuhler
Committed by
Manuel Spuhler
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Workflow enpoint POC
parent
5ade034f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/eu/hbp/mip/controllers/ExperimentApi.java
+46
-1
46 additions, 1 deletion
src/main/java/eu/hbp/mip/controllers/ExperimentApi.java
src/main/java/eu/hbp/mip/utils/HTTPUtil.java
+42
-0
42 additions, 0 deletions
src/main/java/eu/hbp/mip/utils/HTTPUtil.java
with
88 additions
and
1 deletion
src/main/java/eu/hbp/mip/controllers/ExperimentApi.java
+
46
−
1
View file @
5281c187
...
...
@@ -69,7 +69,7 @@ public class ExperimentApi extends WokenClientController {
@ApiOperation
(
value
=
"Create an experiment on Exareme"
,
response
=
Experiment
.
class
)
@RequestMapping
(
value
=
"/exareme"
,
method
=
RequestMethod
.
POST
)
public
ResponseEntity
<
String
>
runExaremeExperiment
(
@RequestBody
ExperimentQuery
expQuery
)
{
LOGGER
.
info
(
"sendExaremeExperiment"
);
LOGGER
.
info
(
"send
ExaremeExperiment"
);
Experiment
experiment
=
saveExperiment
(
expQuery
);
...
...
@@ -80,6 +80,20 @@ public class ExperimentApi extends WokenClientController {
return
new
ResponseEntity
<>(
gsonOnlyExposed
.
toJson
(
experiment
.
jsonify
()),
HttpStatus
.
OK
);
}
@ApiOperation
(
value
=
"Create a workflow"
,
response
=
Experiment
.
class
)
@RequestMapping
(
value
=
"/workflow"
,
method
=
RequestMethod
.
POST
)
public
ResponseEntity
<
String
>
runWorkflow
(
@RequestBody
ExperimentQuery
expQuery
)
{
LOGGER
.
info
(
"send Workflow"
);
Experiment
experiment
=
saveExperiment
(
expQuery
);
String
algoCode
=
expQuery
.
getAlgorithms
().
get
(
0
).
getCode
();
List
<
AlgorithmParam
>
params
=
expQuery
.
getAlgorithms
().
get
(
0
).
getParameters
();
sendWorkflow
(
experiment
,
algoCode
,
params
);
return
new
ResponseEntity
<>(
gsonOnlyExposed
.
toJson
(
experiment
.
jsonify
()),
HttpStatus
.
OK
);
}
@ApiOperation
(
value
=
"get an experiment"
,
response
=
Experiment
.
class
)
@RequestMapping
(
value
=
"/{uuid}"
,
method
=
RequestMethod
.
GET
)
public
ResponseEntity
<
String
>
getExperiment
(
...
...
@@ -297,6 +311,37 @@ public class ExperimentApi extends WokenClientController {
}).
start
();
}
private
void
sendWorkflow
(
Experiment
experiment
,
String
algoCode
,
List
<
AlgorithmParam
>
params
)
{
// this runs in the background. For future optimization: use a thread pool
new
Thread
(()
->
{
HashMap
<
String
,
String
>
queryMap
=
new
HashMap
<
String
,
String
>();
if
(
params
!=
null
)
{
for
(
AlgorithmParam
p
:
params
)
{
queryMap
.
put
(
p
.
getName
(),
p
.
getValue
());
}
}
String
query
=
gson
.
toJson
(
queryMap
);
String
url
=
"http://88.197.53.36:8080/Gateway_API-1.0.0-SNAPSHOT/api/runWorkflow/3f5830403180d620"
;
// Results are stored in the experiment object
try
{
StringBuilder
results
=
new
StringBuilder
();
int
code
=
HTTPUtil
.
sendWorkflowHTTP
(
url
,
query
,
results
);
experiment
.
setResult
(
"["
+
results
.
toString
()
+
"]"
);
experiment
.
setHasError
(
code
>=
400
);
experiment
.
setHasServerError
(
code
>=
500
);
}
catch
(
IOException
e
)
{
LOGGER
.
trace
(
"Invalid UUID"
,
e
);
LOGGER
.
warn
(
"Exareme experiment failed to run properly !"
);
experiment
.
setHasError
(
true
);
experiment
.
setHasServerError
(
true
);
experiment
.
setResult
(
e
.
getMessage
());
}
finishExperiment
(
experiment
);
}).
start
();
}
private
void
finishExperiment
(
Experiment
experiment
)
{
experiment
.
setFinished
(
new
Date
());
experimentRepository
.
save
(
experiment
);
...
...
This diff is collapsed.
Click to expand it.
src/main/java/eu/hbp/mip/utils/HTTPUtil.java
+
42
−
0
View file @
5281c187
...
...
@@ -47,6 +47,48 @@ public class HTTPUtil {
}
}
int
respCode
=
con
.
getResponseCode
();
BufferedReader
in
;
if
(
respCode
==
200
)
{
in
=
new
BufferedReader
(
new
InputStreamReader
(
con
.
getInputStream
()));
}
else
{
in
=
new
BufferedReader
(
new
InputStreamReader
(
con
.
getErrorStream
()));
}
String
inputLine
;
StringBuilder
response
=
new
StringBuilder
();
while
((
inputLine
=
in
.
readLine
())
!=
null
)
{
response
.
append
(
inputLine
);
}
in
.
close
();
resp
.
append
(
response
.
toString
());
return
respCode
;
}
/* FIXME: Authorization */
public
static
int
sendWorkflowHTTP
(
String
url
,
String
query
,
StringBuilder
resp
)
throws
IOException
{
URL
obj
=
new
URL
(
url
);
HttpURLConnection
con
=
(
HttpURLConnection
)
obj
.
openConnection
();
con
.
setRequestMethod
(
"POST"
);
if
(
query
!=
null
&&
query
.
length
()
>
0
)
{
con
.
addRequestProperty
(
"Content-Type"
,
"application/json"
);
con
.
setRequestProperty
(
"Content-Length"
,
Integer
.
toString
(
query
.
length
()));
con
.
setDoOutput
(
true
);
DataOutputStream
wr
=
new
DataOutputStream
(
con
.
getOutputStream
());
wr
.
write
(
query
.
getBytes
(
StandardCharsets
.
UTF_8
));
wr
.
flush
();
wr
.
close
();
}
int
respCode
=
con
.
getResponseCode
();
BufferedReader
in
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment