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
Branches
No related tags found
No related merge requests found
......@@ -39,7 +39,6 @@ public class VIPSCoreManagerApplication extends Application
private void addRestResourceClasses(Set<Class<?>> resources) {
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.ManagerResource.class);
resources.add(no.bioforsk.vips.coremanager.service.ManagerResourceImpl.class);
}
}
\ No newline at end of file
......@@ -5,7 +5,7 @@ import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Date;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
......@@ -29,7 +29,7 @@ import no.bioforsk.vips.coremanager.entity.ModelUsageLog;
import no.bioforsk.vips.coremanager.entity.VIPSCoreCredentials;
import no.bioforsk.vips.coremanager.entity.VipsCoreUser;
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.util.ServletUtil;
import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
......@@ -195,7 +195,10 @@ public class ManagerResourceImpl implements ManagerResource{
{
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)
{
throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).entity("Not accepted!").build());
......@@ -211,7 +214,7 @@ public class ManagerResourceImpl implements ManagerResource{
/**
* Instantiates and runs the requested model
* @param modelId
* @param config input data for the model
* @param input input data for the model
* @return list of result objects
*/
@POST
......@@ -219,12 +222,12 @@ public class ManagerResourceImpl implements ManagerResource{
@Consumes("application/json")
@Produces("application/json")
@Override
public Response runModel(@PathParam("modelId") String modelId, Map<String,Object> input)
public Response runModel(@PathParam("modelId") String modelId, ModelRunRequest request)
{
try
{
// 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)
{
throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).entity("Ikke godtatt!").build());
......@@ -238,7 +241,7 @@ public class ManagerResourceImpl implements ManagerResource{
{
// TODO: Check IP of caller to be sure that this is not someone
// 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();
......@@ -247,9 +250,11 @@ public class ManagerResourceImpl implements ManagerResource{
log.setTimeStarted(new Date());
// Then we generate the Model Configuration
ModelConfiguration config = new ModelConfiguration();
config.setModelId(modelId);
config.setConfigParameters((Map<String,Object>)input.get("configParameters"));
config.setModelId(request.getModelId());
config.setConfigParameters(request.getConfigParameters());
// Call the backend service, run the model
Response resp = this.getModelResource().runModel(modelId, config);
......@@ -269,9 +274,10 @@ public class ManagerResourceImpl implements ManagerResource{
}
else
{
List<Result> result = resp.readEntity(List.class);
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)
......
......@@ -2,6 +2,7 @@ package no.bioforsk.vips.coremanager.session;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.Properties;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
......@@ -34,12 +35,12 @@ public class UserController {
* @return The credentials object. null if combination of username and password is not found
* @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);
q.setParameter("username", username);
q.setParameter("username", loginInfo.get("username"));
String salt = this.getVIPSCoreServerProperties().getProperty("MD5_SALT");
q.setParameter("password", MD5Encrypter.getMD5HexString(password,salt));
q.setParameter("password", MD5Encrypter.getMD5HexString(loginInfo.get("password"),salt));
try
{
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