Skip to content
Snippets Groups Projects
Commit 47c95ce2 authored by Mirco Nasuti's avatar Mirco Nasuti
Browse files

work in progress

parent 6bb8d011
No related branches found
No related tags found
No related merge requests found
package eu.hbp.mip.akka; package eu.hbp.mip.akka;
import akka.actor.UntypedActor; import akka.actor.UntypedActor;
import eu.hbp.mip.messages.external.QueryResult;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import javax.inject.Inject; import javax.inject.Inject;
...@@ -14,24 +15,6 @@ import javax.inject.Named; ...@@ -14,24 +15,6 @@ import javax.inject.Named;
@Scope("prototype") @Scope("prototype")
public class ListenerActor extends UntypedActor { public class ListenerActor extends UntypedActor {
public static class AlgoQuery {
private final String query;
public AlgoQuery(String query) {
this.query = query;
}
public String getQuery() {
return query;
}
}
public static class AlgoResult {
private final String result;
public AlgoResult(String result) {
this.result = result;
}
public String getResult() {
return result;
}
}
final ListeningService listeningService; final ListeningService listeningService;
@Inject @Inject
public ListenerActor(@Named("ListeningService") ListeningService listeningService) { public ListenerActor(@Named("ListeningService") ListeningService listeningService) {
...@@ -40,9 +23,9 @@ public class ListenerActor extends UntypedActor { ...@@ -40,9 +23,9 @@ public class ListenerActor extends UntypedActor {
@Override @Override
public void onReceive(Object message) throws Exception { public void onReceive(Object message) throws Exception {
if (message instanceof AlgoResult) { if (message instanceof QueryResult) {
AlgoResult algoResult = (AlgoResult) message; QueryResult queryResult = (QueryResult) message;
listeningService.listen(algoResult.getResult()); listeningService.listen(queryResult.data().get());
} }
else { else {
unhandled(message); unhandled(message);
......
...@@ -7,7 +7,6 @@ import eu.hbp.mip.model.User; ...@@ -7,7 +7,6 @@ import eu.hbp.mip.model.User;
import eu.hbp.mip.repositories.UserRepository; import eu.hbp.mip.repositories.UserRepository;
import eu.hbp.mip.utils.CORSFilter; import eu.hbp.mip.utils.CORSFilter;
import eu.hbp.mip.utils.CustomLoginUrlAuthenticationEntryPoint; import eu.hbp.mip.utils.CustomLoginUrlAuthenticationEntryPoint;
import eu.hbp.mip.utils.HTTPUtil;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -301,22 +300,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { ...@@ -301,22 +300,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
query.append("\"").append(idToken).append("\""); query.append("\"").append(idToken).append("\"");
query.append("}"); query.append("}");
// TODO send request
try {
int responseCode = HTTPUtil.sendPost(revokeTokenURI, query.toString(), new StringBuilder());
if (responseCode != 200)
{
LOGGER.warn("Cannot send request to OIDC server for revocation ! ");
}
else{
LOGGER.info("Should be logged out");
}
} catch (IOException e) {
LOGGER.warn("Cannot notify logout to OIDC server !");
LOGGER.trace(e);
}
} }
} }
} }
\ No newline at end of file
package eu.hbp.mip.controllers; package eu.hbp.mip.controllers;
import akka.actor.ActorRef; import akka.actor.ActorSelection;
import akka.actor.ActorSystem; import akka.actor.ActorSystem;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.gson.Gson; import com.google.gson.Gson;
...@@ -13,7 +13,6 @@ import eu.hbp.mip.model.ExperimentQuery; ...@@ -13,7 +13,6 @@ import eu.hbp.mip.model.ExperimentQuery;
import eu.hbp.mip.model.User; import eu.hbp.mip.model.User;
import eu.hbp.mip.repositories.ExperimentRepository; import eu.hbp.mip.repositories.ExperimentRepository;
import eu.hbp.mip.repositories.ModelRepository; import eu.hbp.mip.repositories.ModelRepository;
import eu.hbp.mip.utils.HTTPUtil;
import eu.hbp.mip.utils.JSONUtil; import eu.hbp.mip.utils.JSONUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
...@@ -216,10 +215,8 @@ public class ExperimentApi { ...@@ -216,10 +215,8 @@ public class ExperimentApi {
StringBuilder response = new StringBuilder(); StringBuilder response = new StringBuilder();
int code = HTTPUtil.sendGet(listMethodsUrl, response); // TODO: Use akka
if (code < 200 || code > 299) { int code = 500;
return new ResponseEntity<>(response.toString(), HttpStatus.valueOf(code));
}
JsonObject catalog = new JsonParser().parse(response.toString()).getAsJsonObject(); JsonObject catalog = new JsonParser().parse(response.toString()).getAsJsonObject();
...@@ -293,16 +290,10 @@ public class ExperimentApi { ...@@ -293,16 +290,10 @@ public class ExperimentApi {
private void sendExperiment(Experiment experiment) throws MalformedURLException { private void sendExperiment(Experiment experiment) throws MalformedURLException {
// this runs in the background. For future optimization: use a thread pool // this runs in the background. For future optimization: use a thread pool
final String url = experimentUrl; final String url = experimentUrl;
final String query = experiment.computeQuery(); final eu.hbp.mip.messages.external.ExperimentQuery experimentQuery = experiment.computeQuery();
ActorRef wokenActor = actorSystem.actorFor(wokenPath);
// Should maybe use this instead ???
// ActorRef wokenActor = actorSystem.actorOf(
// SpringExtension.SpringExtProvider.get(actorSystem).props("Woken"), "woken");
wokenActor.tell(query, null);
ActorSelection wokenActor = actorSystem.actorSelection(wokenPath);
wokenActor.tell(experimentQuery, null);
} }
private void sendExaremeExperiment(Experiment experiment) { private void sendExaremeExperiment(Experiment experiment) {
...@@ -341,7 +332,8 @@ public class ExperimentApi { ...@@ -341,7 +332,8 @@ public class ExperimentApi {
private static void executeExperiment(String url, String query, Experiment experiment) throws IOException { private static void executeExperiment(String url, String query, Experiment experiment) throws IOException {
StringBuilder results = new StringBuilder(); StringBuilder results = new StringBuilder();
int code = HTTPUtil.sendPost(url, query, results); // TODO: use akka
int code = 500;
experiment.setResult(results.toString()); experiment.setResult(results.toString());
experiment.setHasError(code >= 400); experiment.setHasError(code >= 400);
experiment.setHasServerError(code >= 500); experiment.setHasServerError(code >= 500);
......
...@@ -2,8 +2,13 @@ package eu.hbp.mip.model; ...@@ -2,8 +2,13 @@ package eu.hbp.mip.model;
import com.google.gson.*; import com.google.gson.*;
import com.google.gson.annotations.Expose; import com.google.gson.annotations.Expose;
import eu.hbp.mip.messages.external.*;
import eu.hbp.mip.messages.external.Algorithm;
import eu.hbp.mip.messages.external.ExperimentQuery;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.hibernate.annotations.Cascade; import org.hibernate.annotations.Cascade;
import scala.collection.JavaConverters;
import scala.collection.Seq;
import javax.persistence.*; import javax.persistence.*;
import java.util.Date; import java.util.Date;
...@@ -11,6 +16,7 @@ import java.util.LinkedList; ...@@ -11,6 +16,7 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
/** /**
* Created by habfast on 21/04/16. * Created by habfast on 21/04/16.
*/ */
...@@ -85,16 +91,39 @@ public class Experiment { ...@@ -85,16 +91,39 @@ public class Experiment {
*/ */
} }
public String computeQuery() { public ExperimentQuery computeQuery() {
JsonObject outgoingQuery = new JsonObject(); List<VariableId> variables = new LinkedList<>();
outgoingQuery.add("algorithms", gsonOnlyExposed.fromJson(algorithms, JsonArray.class)); List<VariableId> covariables = new LinkedList<>();
outgoingQuery.add("validations", gsonOnlyExposed.fromJson(validations, JsonArray.class)); List<VariableId> grouping = new LinkedList<>();
List<Filter> filters = new LinkedList<>();
List<eu.hbp.mip.messages.external.Algorithm> algorithms = new LinkedList<>();
List<Validation> validations = new LinkedList<>();
for (Variable v: model.getQuery().getVariables()
) {
variables.add(new VariableId(v.getCode()));
}
for (Variable v: model.getQuery().getCovariables()
) {
covariables.add(new VariableId(v.getCode()));
}
for (Variable v: model.getQuery().getGrouping()
) {
grouping.add(new VariableId(v.getCode()));
}
// TODO: convert algorithms and so on
Seq<VariableId> variablesSeq = JavaConverters.asScalaIteratorConverter(variables.iterator()).asScala().toSeq();
Seq<VariableId> covariablesSeq = JavaConverters.asScalaIteratorConverter(covariables.iterator()).asScala().toSeq();
Seq<VariableId> groupingSeq = JavaConverters.asScalaIteratorConverter(grouping.iterator()).asScala().toSeq();
Seq<Filter> filtersSeq = JavaConverters.asScalaIteratorConverter(filters.iterator()).asScala().toSeq();
Seq<Algorithm> algorithmsSeq = JavaConverters.asScalaIteratorConverter(algorithms.iterator()).asScala().toSeq();
Seq<Validation> validationsSeq = JavaConverters.asScalaIteratorConverter(validations.iterator()).asScala().toSeq();
outgoingQuery.add("covariables", gsonOnlyExposed.toJsonTree(model.getQuery().getCovariables())); return new ExperimentQuery(variablesSeq, covariablesSeq, groupingSeq, filtersSeq, algorithmsSeq, validationsSeq);
outgoingQuery.add("variables", gsonOnlyExposed.toJsonTree(model.getQuery().getVariables()));
outgoingQuery.add("filters", gsonOnlyExposed.toJsonTree(model.getQuery().getFilters()));
outgoingQuery.add("grouping", gsonOnlyExposed.toJsonTree(model.getQuery().getGrouping()));
return outgoingQuery.toString();
} }
public String computeExaremeQuery() { public String computeExaremeQuery() {
......
package eu.hbp.mip.utils;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
/**
* Created by mirco on 20.06.16.
*/
public class HTTPUtil {
private HTTPUtil()
{
/* Hide implicit public constructor */
throw new IllegalAccessError("HTTPUtil class");
}
public static int sendGet(String url, StringBuilder resp) throws IOException {
return sendHTTP(url, "", resp, "GET");
}
public static int sendPost(String url, String query, StringBuilder resp) throws IOException {
return sendHTTP(url, query, resp, "POST");
}
public static int sendHTTP(String url, String query, StringBuilder resp, String httpVerb) throws IOException {
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
if(!"GET".equals(httpVerb)) {
con.setRequestMethod(httpVerb);
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("UTF8"));
wr.flush();
wr.close();
}
}
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;
}
}
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