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
c97039cb
Commit
c97039cb
authored
5 years ago
by
Manuel Spuhler
Browse files
Options
Downloads
Patches
Plain Diff
Exareme mining
parent
c70f20cb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/eu/hbp/mip/controllers/MiningApi.java
+47
-22
47 additions, 22 deletions
src/main/java/eu/hbp/mip/controllers/MiningApi.java
with
47 additions
and
22 deletions
src/main/java/eu/hbp/mip/controllers/MiningApi.java
+
47
−
22
View file @
c97039cb
package
eu.hbp.mip.controllers
;
import
eu.hbp.mip.utils.HTTPUtil
;
import
com.google.gson.Gson
;
import
eu.hbp.mip.akka.WokenClientController
;
import
eu.hbp.mip.model.Mining
;
...
...
@@ -21,6 +23,8 @@ import org.springframework.web.bind.annotation.RestController;
import
scala.Option
;
import
java.sql.Date
;
import
java.util.*
;
import
java.io.IOException
;
import
static
org
.
springframework
.
http
.
MediaType
.
APPLICATION_JSON_VALUE
;
...
...
@@ -28,7 +32,7 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
* Created by mirco on 06.01.17.
*/
@RestController
@RequestMapping
(
value
=
"/mining"
,
produces
=
{
APPLICATION_JSON_VALUE
})
@RequestMapping
(
value
=
"/mining"
,
produces
=
{
APPLICATION_JSON_VALUE
})
@Api
(
value
=
"/mining"
,
description
=
"the mining API"
)
public
class
MiningApi
extends
WokenClientController
{
...
...
@@ -38,33 +42,54 @@ public class MiningApi extends WokenClientController {
@Autowired
private
UserInfo
userInfo
;
@Value
(
"#{'${services.exareme.miningExaremeUrl:http://localhost:9090/mining/query}'}"
)
public
String
miningExaremeQueryUrl
;
@ApiOperation
(
value
=
"Run an algorithm"
,
response
=
String
.
class
)
@Cacheable
(
value
=
"mining"
,
condition
=
"#query != null and (#query.getAlgorithm().getCode() == 'histograms' or #query.getAlgorithm().getCode() == 'histograms')"
,
key
=
"#query.toString()"
,
unless
=
"#result.getStatusCode().value()!=200"
)
@Cacheable
(
value
=
"mining"
,
condition
=
"#query != null and (#query.getAlgorithm().getCode() == 'histograms' or #query.getAlgorithm().getCode() == 'histograms')"
,
key
=
"#query.toString()"
,
unless
=
"#result.getStatusCode().value()!=200"
)
@RequestMapping
(
method
=
RequestMethod
.
POST
)
public
ResponseEntity
runAlgorithm
(
@RequestBody
eu
.
hbp
.
mip
.
model
.
MiningQuery
query
)
{
LOGGER
.
info
(
"Run an algorithm"
);
User
user
=
userInfo
.
getUser
();
return
askWokenQuery
(
query
.
prepareQuery
(
user
.
getUsername
()),
120
,
result
->
{
if
(
result
.
error
().
nonEmpty
())
{
LOGGER
.
error
(
result
.
error
().
get
());
return
ResponseEntity
.
status
(
HttpStatus
.
BAD_REQUEST
).
body
(
"{\"error\":\""
+
result
.
error
().
get
()
+
"\"}"
);
}
else
{
Mining
mining
=
new
Mining
(
result
.
jobId
(),
result
.
node
(),
unwrap
(
result
.
algorithm
()),
result
.
type
().
mime
(),
Date
.
from
(
result
.
timestamp
().
toInstant
()),
result
.
data
().
get
().
compactPrint
()
);
return
ResponseEntity
.
ok
(
gson
.
toJson
(
mining
.
jsonify
()));
}
});
return
askWokenQuery
(
query
.
prepareQuery
(
user
.
getUsername
()),
120
,
result
->
{
if
(
result
.
error
().
nonEmpty
())
{
LOGGER
.
error
(
result
.
error
().
get
());
return
ResponseEntity
.
status
(
HttpStatus
.
BAD_REQUEST
)
.
body
(
"{\"error\":\""
+
result
.
error
().
get
()
+
"\"}"
);
}
else
{
Mining
mining
=
new
Mining
(
result
.
jobId
(),
result
.
node
(),
unwrap
(
result
.
algorithm
()),
result
.
type
().
mime
(),
Date
.
from
(
result
.
timestamp
().
toInstant
()),
result
.
data
().
get
().
compactPrint
());
return
ResponseEntity
.
ok
(
gson
.
toJson
(
mining
.
jsonify
()));
}
});
}
@ApiOperation
(
value
=
"Create an experiment on Exareme"
,
response
=
String
.
class
)
@RequestMapping
(
value
=
"/exareme"
,
method
=
RequestMethod
.
POST
)
public
ResponseEntity
runExaremeMining
(
@RequestBody
List
<
HashMap
<
String
,
String
>>
queryList
)
{
LOGGER
.
info
(
"Run an histogram"
);
// Mining mining = new Mining();
String
query
=
gson
.
toJson
(
queryList
);
String
url
=
miningExaremeQueryUrl
+
"/"
+
"HISTOGRAMS"
;
try
{
StringBuilder
results
=
new
StringBuilder
();
int
code
=
HTTPUtil
.
sendPost
(
url
,
query
,
results
);
if
(
code
>=
500
)
{
return
new
ResponseEntity
<>(
"Internal Server Error"
,
HttpStatus
.
INTERNAL_SERVER_ERROR
);
}
if
(
code
>=
400
)
{
return
new
ResponseEntity
<>(
"Bad request"
,
HttpStatus
.
BAD_REQUEST
);
}
return
ResponseEntity
.
ok
(
gson
.
toJson
(
results
.
toString
()));
}
catch
(
IOException
e
)
{
return
new
ResponseEntity
<>(
"Not found"
,
HttpStatus
.
BAD_REQUEST
);
}
}
private
static
String
unwrap
(
Option
<
String
>
option
)
{
...
...
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