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
ce3eb817
Commit
ce3eb817
authored
8 years ago
by
Mirco Nasuti
Browse files
Options
Downloads
Patches
Plain Diff
add api to list exareme algorithms -> GET <backend>/mining/exareme/algorithms
parent
ff6eead5
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
config/application.yml
+1
-0
1 addition, 0 deletions
config/application.yml
src/main/java/org/hbp/mip/controllers/MiningApi.java
+48
-11
48 additions, 11 deletions
src/main/java/org/hbp/mip/controllers/MiningApi.java
with
49 additions
and
11 deletions
config/application.yml
+
1
−
0
View file @
ce3eb817
...
...
@@ -40,3 +40,4 @@ server:
workflow
:
miningUrl
:
http://mip.humanbrainproject.eu/services/mining
exaremeMiningUrl
:
http://hbps2.chuv.ch:9090/mining/
This diff is collapsed.
Click to expand it.
src/main/java/org/hbp/mip/controllers/MiningApi.java
+
48
−
11
View file @
ce3eb817
...
...
@@ -15,6 +15,7 @@ import java.io.DataOutputStream;
import
java.io.InputStreamReader
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.net.UnknownHostException
;
@RestController
@RequestMapping
(
value
=
"/mining"
)
...
...
@@ -24,34 +25,70 @@ public class MiningApi {
@Value
(
"#{'${workflow.miningUrl:http://localhost:8087/mining}'}"
)
private
String
miningUrl
;
@Value
(
"#{'${workflow.exaremeMiningUrl:http://localhost:9090/mining}'}"
)
private
String
exaremeMiningUrl
;
@ApiOperation
(
value
=
"Send a request to the workflow for data mining"
,
response
=
String
.
class
)
@ApiResponses
(
value
=
{
@ApiResponse
(
code
=
200
,
message
=
"Success"
)
})
@RequestMapping
(
method
=
RequestMethod
.
POST
)
public
ResponseEntity
<
String
>
postMining
(
@RequestBody
@ApiParam
(
value
=
"Query for the data mining"
,
required
=
true
)
String
query
)
throws
Exception
{
try
{
StringBuilder
results
=
new
StringBuilder
();
int
code
=
sendPost
(
miningUrl
,
query
,
results
);
return
new
ResponseEntity
<>(
results
.
toString
(),
HttpStatus
.
valueOf
(
code
));
}
catch
(
UnknownHostException
uhe
)
{
uhe
.
printStackTrace
();
return
new
ResponseEntity
<>(
HttpStatus
.
BAD_GATEWAY
);
}
}
@ApiOperation
(
value
=
"Send a request to the Exareme service to list available algorithms"
,
response
=
String
.
class
)
@ApiResponses
(
value
=
{
@ApiResponse
(
code
=
200
,
message
=
"Success"
)
})
@RequestMapping
(
path
=
"/exareme/algorithms"
,
method
=
RequestMethod
.
GET
)
public
ResponseEntity
<
String
>
getExaremeAlgoList
(
)
throws
Exception
{
String
url
=
exaremeMiningUrl
+
"algorithm/"
;
StringBuilder
results
=
new
StringBuilder
();
int
code
=
sendPost
(
miningUrl
,
query
,
results
);
try
{
StringBuilder
results
=
new
StringBuilder
();
int
code
=
sendGet
(
url
,
results
);
return
new
ResponseEntity
<>(
results
.
toString
(),
HttpStatus
.
valueOf
(
code
));
return
new
ResponseEntity
<>(
results
.
toString
(),
HttpStatus
.
valueOf
(
code
));
}
catch
(
UnknownHostException
uhe
)
{
uhe
.
printStackTrace
();
return
new
ResponseEntity
<>(
HttpStatus
.
BAD_GATEWAY
);
}
}
private
static
int
sendGet
(
String
url
,
StringBuilder
resp
)
throws
Exception
{
return
sendHTTP
(
url
,
""
,
resp
,
"GET"
);
}
private
static
int
sendPost
(
String
url
,
String
query
,
StringBuilder
resp
)
throws
Exception
{
return
sendHTTP
(
url
,
query
,
resp
,
"POST"
);
}
private
static
int
sendHTTP
(
String
url
,
String
query
,
StringBuilder
resp
,
String
httpVerb
)
throws
Exception
{
URL
obj
=
new
URL
(
url
);
HttpURLConnection
con
=
(
HttpURLConnection
)
obj
.
openConnection
();
con
.
setRequestMethod
(
"POST"
);
con
.
addRequestProperty
(
"Content-Type"
,
"application/json"
);
con
.
setRequestProperty
(
"Content-Length"
,
Integer
.
toString
(
query
.
length
()));
if
(!
httpVerb
.
equals
(
"GET"
))
{
con
.
setRequestMethod
(
httpVerb
);
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
(
"UTF8"
));
wr
.
flush
();
wr
.
close
();
con
.
setDoOutput
(
true
);
DataOutputStream
wr
=
new
DataOutputStream
(
con
.
getOutputStream
());
wr
.
write
(
query
.
getBytes
(
"UTF8"
));
wr
.
flush
();
wr
.
close
();
}
int
respCode
=
con
.
getResponseCode
();
...
...
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