From 4813a730b923672879e0e3f928507697d18c72f0 Mon Sep 17 00:00:00 2001
From: Mirco Nasuti <mirco.nasuti@chuv.ch>
Date: Fri, 17 Jun 2016 16:19:25 +0200
Subject: [PATCH] work in progress

---
 config/application.yml                        |  6 +--
 config/application_hbps1.yml                  | 46 +++++++++++++++++
 pom.xml                                       |  6 ++-
 .../hbp/mip/controllers/ExperimentApi.java    |  4 +-
 .../org/hbp/mip/controllers/MiningApi.java    | 51 ++++++++-----------
 5 files changed, 76 insertions(+), 37 deletions(-)
 create mode 100644 config/application_hbps1.yml

diff --git a/config/application.yml b/config/application.yml
index aba6d24c8..d8a9f7180 100644
--- a/config/application.yml
+++ b/config/application.yml
@@ -40,7 +40,7 @@ server:
     timeout: 2592000
 
 workflow:
-  miningUrl: http://mip.humanbrainproject.eu/services/mining
-  exaremeListAlgoUrl: http://hbps2.chuv.ch:9090/mining/algorithms
-  exaremeQueryUrl: http://hbps2.chuv.ch:9090/mining/query
+  listMethodsUrl: http://dockerhost:8087/list-methods
+  miningMipUrl: http://dockerhost:8087/mining
+  miningExaremeUrl: http://hbps2.chuv.ch:9090/mining/query
 
diff --git a/config/application_hbps1.yml b/config/application_hbps1.yml
new file mode 100644
index 000000000..d8a9f7180
--- /dev/null
+++ b/config/application_hbps1.yml
@@ -0,0 +1,46 @@
+# Configuration for the portal running inside a Docker container for development
+
+connection:
+  url: "jdbc:postgresql://portaldb:5432/postgres"
+  username: "postgres"
+  password: "test"
+
+security:
+  enabled: false
+
+hbp:
+  client:
+    clientId: 996f97c5-a3ca-460e-b18b-00df3e2be89a
+    clientSecret: aD0Tueb3KkNkcZqZgQbNyDWgnM95IfZ0xPCQ_6Z9dQNHXY00RIrnAD_m7sNJh1oofYSX8aHkl72MkwI0K626Ug
+    accessTokenUri: https://services.humanbrainproject.eu/oidc/token
+    userAuthorizationUri: https://services.humanbrainproject.eu/oidc/authorize
+    tokenName: oauth_token
+    authenticationScheme: query
+    clientAuthenticationScheme: form
+    # use-current-uri: false  # For both production and HBPS1 deployments
+    # pre-established-redirect-uri: https://mip.humanbrainproject.eu/services/login/hbp  # For production deployment
+    # pre-established-redirect-uri: http://hbps1.chuv.ch/services/login/hbp  # For HBPS1 deployment
+  resource:
+    userInfoUri: https://services.humanbrainproject.eu/oidc/userinfo
+
+logging:
+  level:
+    org.springframework.security: DEBUG
+
+spring:
+  resources:
+    chain:
+      enabled: true
+
+server:
+  contextPath: /services
+  port: 8080
+  use-forward-headers: true
+  session:
+    timeout: 2592000
+
+workflow:
+  listMethodsUrl: http://dockerhost:8087/list-methods
+  miningMipUrl: http://dockerhost:8087/mining
+  miningExaremeUrl: http://hbps2.chuv.ch:9090/mining/query
+
diff --git a/pom.xml b/pom.xml
index 265cb8ff9..74b2de554 100644
--- a/pom.xml
+++ b/pom.xml
@@ -68,8 +68,10 @@
                 <hibernate.dialect>org.hibernate.dialect.PostgreSQL82Dialect</hibernate.dialect>
                 <schema.deploy>false</schema.deploy>
                 <frontend.redirect>http://frontend/home</frontend.redirect>
-                <workflow.experimentUrl>http://hbps1.chuv.ch:8087/experiment</workflow.experimentUrl>
-                <workflow.listMethodsUrl>http://hbps1.chuv.ch:8087/list-methods</workflow.listMethodsUrl>
+                <workflow.experimentUrl>http://dockerhost:8087/experiment</workflow.experimentUrl>
+                <workflow.listMethodsUrl>http://dockerhost:8087/list-methods</workflow.listMethodsUrl>
+                <workflow.miningMipUrl>http://dockerhost:8087/mining</workflow.miningMipUrl>
+                <workflow.miningExaremeUrl>http://dockerhost:8087/mining/query</workflow.miningExaremeUrl>
                 <flyway.url>${connection.url}</flyway.url>
                 <flyway.user>${connection.username}</flyway.user>
                 <flyway.password>${connection.password}</flyway.password>
diff --git a/src/main/java/org/hbp/mip/controllers/ExperimentApi.java b/src/main/java/org/hbp/mip/controllers/ExperimentApi.java
index e71ee947f..ed54ed0b4 100644
--- a/src/main/java/org/hbp/mip/controllers/ExperimentApi.java
+++ b/src/main/java/org/hbp/mip/controllers/ExperimentApi.java
@@ -43,11 +43,11 @@ public class ExperimentApi {
             .excludeFieldsWithoutExposeAnnotation()
             .create();
 
-    @Value("#{'${workflow.experimentUrl:http://hbps1.chuv.ch:8087/experiment}'}")
+    @Value("#{'${workflow.experimentUrl:http://dockerhost:8087/experiment}'}")
     private String experimentUrl;
 
 
-    @Value("#{'${workflow.listMethodsUrl:http://hbps1.chuv.ch:8087/list-methods}'}")
+    @Value("#{'${workflow.listMethodsUrl:http://dockerhost:8087/list-methods}'}")
     private String listMethodsUrl;
 
     @Autowired
diff --git a/src/main/java/org/hbp/mip/controllers/MiningApi.java b/src/main/java/org/hbp/mip/controllers/MiningApi.java
index 2fc2882d7..cc99c1fce 100644
--- a/src/main/java/org/hbp/mip/controllers/MiningApi.java
+++ b/src/main/java/org/hbp/mip/controllers/MiningApi.java
@@ -23,14 +23,14 @@ import java.net.UnknownHostException;
 @Api(value = "/mining", description = "Forward mining API")
 public class MiningApi {
 
-    @Value("#{'${workflow.miningUrl:http://localhost:8087/mining}'}")
-    private String miningUrl;
+    @Value("#{'${workflow.listMethodsUrl:http://hbps1.chuv.ch:8087/list-methods}'}")
+    private String listMethodsUrl;
 
-    @Value("#{'${workflow.exaremeListAlgoUrl:http://localhost:9090/mining/algorithms}'}")
-    private String exaremeListAlgoUrl;
+    @Value("#{'${workflow.miningMipUrl:http://hbps1.chuv.ch:8087/mining}'}")
+    private String miningMipUrl;
 
-    @Value("#{'${workflow.exaremeQueryUrl:http://localhost:9090/mining/query}'}")
-    private String exaremeQueryUrl;
+    @Value("#{'${workflow.miningExaremeUrl:http://hbps2.chuv.ch:9090/mining/query}'}")
+    private String miningExaremeQueryUrl;
 
     @ApiOperation(value = "Send a request to the workflow for data mining", response = String.class)
     @ApiResponses(value = { @ApiResponse(code = 200, message = "Success") })
@@ -38,26 +38,22 @@ public class MiningApi {
     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);
+        // TODO : switch between sources
 
-            return new ResponseEntity<>(results.toString(), HttpStatus.valueOf(code));
-        }
-        catch(UnknownHostException uhe) {
-            uhe.printStackTrace();
-            return new ResponseEntity<>(HttpStatus.BAD_GATEWAY);
+        StringBuilder response = new StringBuilder();
+
+        int code = sendGet(listMethodsUrl, response);
+        if (code < 200 || code > 299) {
+            return new ResponseEntity<>(response.toString(), HttpStatus.valueOf(code));
         }
+
+        return null;
     }
 
-    @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 {
+    private ResponseEntity<String> postMipMining(String query) throws Exception {
         try {
             StringBuilder results = new StringBuilder();
-            int code = sendGet(exaremeListAlgoUrl, results);
+            int code = sendPost(miningMipUrl, query, results);
 
             return new ResponseEntity<>(results.toString(), HttpStatus.valueOf(code));
         }
@@ -67,18 +63,13 @@ public class MiningApi {
         }
     }
 
-    @ApiOperation(value = "Send a request to the Exareme service to run an algorithm", response = String.class)
-    @ApiResponses(value = { @ApiResponse(code = 200, message = "Success") })
-    @RequestMapping(path = "/exareme/query/{algo}", method = RequestMethod.POST)
-    public ResponseEntity<String> postExaremeQuery(
-            @ApiParam(value = "algo", required = true) @PathVariable("algo") String algo,
-            @RequestBody(required = false) @ApiParam(value = "Query for the data mining") String query
-    ) throws Exception {
+
+    public ResponseEntity<String> postExaremeMining(String algo, String query) throws Exception {
         try {
 
             /* Launch computation */
 
-            String url = exaremeQueryUrl+"/"+algo+"/?format=true";
+            String url = miningExaremeQueryUrl +"/"+algo+"/?format=true";
             StringBuilder results = new StringBuilder();
             int code = sendPost(url, query, results);
             if (code < 200 || code > 299)
@@ -91,7 +82,7 @@ public class MiningApi {
 
             /* Wait for result */
 
-            url = exaremeQueryUrl+"/"+key+"/status";
+            url = miningExaremeQueryUrl +"/"+key+"/status";
             double progress = 0;
 
             while (progress < 100) {
@@ -107,7 +98,7 @@ public class MiningApi {
 
             /* Get result */
 
-            url = exaremeQueryUrl+"/"+key+"/result";
+            url = miningExaremeQueryUrl +"/"+key+"/result";
             results = new StringBuilder();
             code = sendPost(url, query, results);
 
-- 
GitLab