Skip to content
Snippets Groups Projects
Commit ac9ca3cc authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

First version with support for piping of config from VIPSLogic to VIPSCore and...

First version with support for piping of config from VIPSLogic to VIPSCore and piping of results from VIPSCore all the way back to VIPSLogic.
parent 8acd0947
No related branches found
No related tags found
No related merge requests found
...@@ -39,7 +39,6 @@ public class VIPSCoreManagerApplication extends Application ...@@ -39,7 +39,6 @@ public class VIPSCoreManagerApplication extends Application
private void addRestResourceClasses(Set<Class<?>> resources) { private void addRestResourceClasses(Set<Class<?>> resources) {
resources.add(no.bioforsk.vips.core.service.ModelResource.class); resources.add(no.bioforsk.vips.core.service.ModelResource.class);
resources.add(no.bioforsk.vips.coremanager.service.JsonParseExceptionMapper.class); resources.add(no.bioforsk.vips.coremanager.service.JsonParseExceptionMapper.class);
resources.add(no.bioforsk.vips.coremanager.service.ManagerResource.class);
resources.add(no.bioforsk.vips.coremanager.service.ManagerResourceImpl.class); resources.add(no.bioforsk.vips.coremanager.service.ManagerResourceImpl.class);
} }
} }
\ No newline at end of file
...@@ -5,7 +5,7 @@ import java.io.InputStream; ...@@ -5,7 +5,7 @@ import java.io.InputStream;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
...@@ -29,7 +29,7 @@ import no.bioforsk.vips.coremanager.entity.ModelUsageLog; ...@@ -29,7 +29,7 @@ import no.bioforsk.vips.coremanager.entity.ModelUsageLog;
import no.bioforsk.vips.coremanager.entity.VIPSCoreCredentials; import no.bioforsk.vips.coremanager.entity.VIPSCoreCredentials;
import no.bioforsk.vips.coremanager.entity.VipsCoreUser; import no.bioforsk.vips.coremanager.entity.VipsCoreUser;
import no.bioforsk.vips.entity.ModelConfiguration; import no.bioforsk.vips.entity.ModelConfiguration;
import no.bioforsk.vips.entity.Result; import no.bioforsk.vips.entity.ModelRunRequest;
import no.bioforsk.vips.model.Model; import no.bioforsk.vips.model.Model;
import no.bioforsk.vips.util.ServletUtil; import no.bioforsk.vips.util.ServletUtil;
import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
...@@ -195,7 +195,10 @@ public class ManagerResourceImpl implements ManagerResource{ ...@@ -195,7 +195,10 @@ public class ManagerResourceImpl implements ManagerResource{
{ {
try try
{ {
VIPSCoreCredentials credentials = ControllerGetter.getUserController().getVIPSCoreCredentials((String)input.get("username"), (String)input.get("password")); Map<String,String> loginInfo = new HashMap<>();
loginInfo.put("username", (String)input.get("username"));
loginInfo.put("password", (String)input.get("password"));
VIPSCoreCredentials credentials = ControllerGetter.getUserController().getVIPSCoreCredentials(loginInfo);
if(credentials == null) if(credentials == null)
{ {
throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).entity("Not accepted!").build()); throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).entity("Not accepted!").build());
...@@ -211,7 +214,7 @@ public class ManagerResourceImpl implements ManagerResource{ ...@@ -211,7 +214,7 @@ public class ManagerResourceImpl implements ManagerResource{
/** /**
* Instantiates and runs the requested model * Instantiates and runs the requested model
* @param modelId * @param modelId
* @param config input data for the model * @param input input data for the model
* @return list of result objects * @return list of result objects
*/ */
@POST @POST
...@@ -219,12 +222,12 @@ public class ManagerResourceImpl implements ManagerResource{ ...@@ -219,12 +222,12 @@ public class ManagerResourceImpl implements ManagerResource{
@Consumes("application/json") @Consumes("application/json")
@Produces("application/json") @Produces("application/json")
@Override @Override
public Response runModel(@PathParam("modelId") String modelId, Map<String,Object> input) public Response runModel(@PathParam("modelId") String modelId, ModelRunRequest request)
{ {
try try
{ {
// First, we authenticate // First, we authenticate
VIPSCoreCredentials credentials = ControllerGetter.getUserController().getVIPSCoreCredentials((String)input.get("username"), (String)input.get("password")); VIPSCoreCredentials credentials = ControllerGetter.getUserController().getVIPSCoreCredentials(request.getLoginInfo());
if(credentials == null) if(credentials == null)
{ {
throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).entity("Ikke godtatt!").build()); throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).entity("Ikke godtatt!").build());
...@@ -238,7 +241,7 @@ public class ManagerResourceImpl implements ManagerResource{ ...@@ -238,7 +241,7 @@ public class ManagerResourceImpl implements ManagerResource{
{ {
// TODO: Check IP of caller to be sure that this is not someone // TODO: Check IP of caller to be sure that this is not someone
// who has hijacked the credentials for the batch system?? // who has hijacked the credentials for the batch system??
user = ControllerGetter.getUserController().getVipsCoreUser((Integer)input.get("batchSystemClientId")); user = ControllerGetter.getUserController().getVipsCoreUser(request.getBatchSystemClientId());
} }
ModelUsageLog log = new ModelUsageLog(); ModelUsageLog log = new ModelUsageLog();
...@@ -247,9 +250,11 @@ public class ManagerResourceImpl implements ManagerResource{ ...@@ -247,9 +250,11 @@ public class ManagerResourceImpl implements ManagerResource{
log.setTimeStarted(new Date()); log.setTimeStarted(new Date());
// Then we generate the Model Configuration // Then we generate the Model Configuration
ModelConfiguration config = new ModelConfiguration(); ModelConfiguration config = new ModelConfiguration();
config.setModelId(modelId); config.setModelId(request.getModelId());
config.setConfigParameters((Map<String,Object>)input.get("configParameters")); config.setConfigParameters(request.getConfigParameters());
// Call the backend service, run the model // Call the backend service, run the model
Response resp = this.getModelResource().runModel(modelId, config); Response resp = this.getModelResource().runModel(modelId, config);
...@@ -269,9 +274,10 @@ public class ManagerResourceImpl implements ManagerResource{ ...@@ -269,9 +274,10 @@ public class ManagerResourceImpl implements ManagerResource{
} }
else else
{ {
List<Result> result = resp.readEntity(List.class);
ControllerGetter.getUserController().storeModelUsageLog(log); ControllerGetter.getUserController().storeModelUsageLog(log);
return Response.ok().entity(result).build(); // Assuming that String is the quickest way of forwarding this
String resultAsString = resp.readEntity(String.class);
return Response.ok().entity(resultAsString).build();
} }
} }
catch( IOException ioe) catch( IOException ioe)
......
...@@ -2,6 +2,7 @@ package no.bioforsk.vips.coremanager.session; ...@@ -2,6 +2,7 @@ package no.bioforsk.vips.coremanager.session;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Map;
import java.util.Properties; import java.util.Properties;
import javax.ejb.LocalBean; import javax.ejb.LocalBean;
import javax.ejb.Stateless; import javax.ejb.Stateless;
...@@ -34,12 +35,12 @@ public class UserController { ...@@ -34,12 +35,12 @@ public class UserController {
* @return The credentials object. null if combination of username and password is not found * @return The credentials object. null if combination of username and password is not found
* @throws IOException * @throws IOException
*/ */
public VIPSCoreCredentials getVIPSCoreCredentials(String username, String password) throws IOException public VIPSCoreCredentials getVIPSCoreCredentials(Map<String,String> loginInfo) throws IOException
{ {
Query q = em.createNamedQuery("VIPSCoreCredentials.findByUsernameAndPassword", VIPSCoreCredentials.class); Query q = em.createNamedQuery("VIPSCoreCredentials.findByUsernameAndPassword", VIPSCoreCredentials.class);
q.setParameter("username", username); q.setParameter("username", loginInfo.get("username"));
String salt = this.getVIPSCoreServerProperties().getProperty("MD5_SALT"); String salt = this.getVIPSCoreServerProperties().getProperty("MD5_SALT");
q.setParameter("password", MD5Encrypter.getMD5HexString(password,salt)); q.setParameter("password", MD5Encrypter.getMD5HexString(loginInfo.get("password"),salt));
try try
{ {
return (VIPSCoreCredentials) q.getSingleResult(); return (VIPSCoreCredentials) q.getSingleResult();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment