Added support to discover DataMiner service by user token
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-analysis/nlphub@178538 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
98c4e2e87c
commit
b847f5df4d
16
pom.xml
16
pom.xml
|
@ -1,6 +1,6 @@
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>maven-parent</artifactId>
|
<artifactId>maven-parent</artifactId>
|
||||||
<groupId>org.gcube.tools</groupId>
|
<groupId>org.gcube.tools</groupId>
|
||||||
|
@ -8,13 +8,13 @@
|
||||||
<relativePath />
|
<relativePath />
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>org.gcube.data.analysis</groupId>
|
<groupId>org.gcube.data.analysis</groupId>
|
||||||
<artifactId>nlphub</artifactId>
|
<artifactId>nlphub</artifactId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<tomcat.version>7.0.70</tomcat.version>
|
<tomcat.version>7.0.70</tomcat.version>
|
||||||
<websocket.version>1.1</websocket.version>
|
<websocket.version>1.1</websocket.version>
|
||||||
|
@ -91,17 +91,25 @@
|
||||||
<artifactId>common-configuration-scanner</artifactId>
|
<artifactId>common-configuration-scanner</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.resources</groupId>
|
<groupId>org.gcube.resources</groupId>
|
||||||
<artifactId>registry-publisher</artifactId>
|
<artifactId>registry-publisher</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.core</groupId>
|
<groupId>org.gcube.core</groupId>
|
||||||
<artifactId>common-scope</artifactId>
|
<artifactId>common-scope</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Information System Client IC-Client -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.resources.discovery</groupId>
|
||||||
|
<artifactId>ic-client</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- Sevlet jars for compilation, provided by Tomcat -->
|
<!-- Sevlet jars for compilation, provided by Tomcat -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.tomcat</groupId>
|
<groupId>org.apache.tomcat</groupId>
|
||||||
|
@ -159,7 +167,7 @@
|
||||||
</resource> </webResources> -->
|
</resource> </webResources> -->
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.5.1</version>
|
<version>3.5.1</version>
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
package org.gcube.data.analysis.nlphub.is;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||||
|
import org.gcube.data.analysis.nlphub.shared.Constants;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
||||||
|
|
||||||
|
public class DiscoverDataMinerService {
|
||||||
|
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(DiscoverDataMinerService.class);
|
||||||
|
|
||||||
|
public String retrieveServiceUrl(String token) throws Exception {
|
||||||
|
logger.debug("Retrieve DataMiner Service by token: " + token);
|
||||||
|
String scope = retrieveScope(token);
|
||||||
|
logger.debug("Retrieve DataMiner Service in scope: "+scope);
|
||||||
|
String url= retrieveServiceInScope(scope);
|
||||||
|
logger.debug("DataMiner url: "+url);
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String retrieveServiceInScope(String scope) throws Exception {
|
||||||
|
List<String> serviceAddress = InformationSystemUtils
|
||||||
|
.retrieveServiceAddress(Constants.DATAMINER_SERVICE_CATEGORY, Constants.DATA_MINER_SERVICE_NAME, scope);
|
||||||
|
logger.debug("Service Address retrieved:" + serviceAddress);
|
||||||
|
if (serviceAddress == null || serviceAddress.size() < 1) {
|
||||||
|
logger.error("No DataMiner service address available!");
|
||||||
|
throw new Exception("No DataMiner service address available!");
|
||||||
|
} else {
|
||||||
|
logger.info("DataMiner service address found: " + serviceAddress.get(0));
|
||||||
|
return serviceAddress.get(0);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String retrieveScope(String token) throws Exception {
|
||||||
|
|
||||||
|
String userName = null;
|
||||||
|
String scope = null;
|
||||||
|
|
||||||
|
if (Constants.DEBUG) {
|
||||||
|
logger.debug("Debug Mode");
|
||||||
|
userName = Constants.DEFAULT_USER;
|
||||||
|
scope = Constants.DEFAULT_SCOPE;
|
||||||
|
token = Constants.DEFAULT_TOKEN;
|
||||||
|
} else {
|
||||||
|
logger.debug("Production Mode");
|
||||||
|
if (token == null || token.isEmpty()) {
|
||||||
|
logger.error("Error retrieving user credentials: token=" + token);
|
||||||
|
throw new Exception("Error retrieving user credentials");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
logger.debug("Retrieving user credentials");
|
||||||
|
AuthorizationEntry entry = authorizationService().get(token);
|
||||||
|
userName = entry.getClientInfo().getId();
|
||||||
|
scope = entry.getContext();
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error retrieving user credentials: " + e.getLocalizedMessage());
|
||||||
|
throw new Exception(e.getLocalizedMessage(), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
logger.debug("UserName: " + userName);
|
||||||
|
logger.debug("Scope: " + scope);
|
||||||
|
return scope;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
package org.gcube.data.analysis.nlphub.is;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||||
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||||
|
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||||
|
import org.gcube.resources.discovery.icclient.ICFactory;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class InformationSystemUtils {
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(InformationSystemUtils.class);
|
||||||
|
|
||||||
|
public static List<String> retrieveServiceAddress(String category, String name, String scope) throws Exception {
|
||||||
|
try {
|
||||||
|
|
||||||
|
if (scope == null || scope.length() == 0)
|
||||||
|
return new ArrayList<String>();
|
||||||
|
|
||||||
|
ScopeProvider.instance.set(scope);
|
||||||
|
|
||||||
|
SimpleQuery query = ICFactory.queryFor(ServiceEndpoint.class);
|
||||||
|
query.addCondition("$resource/Profile/Category/text() eq '" + category + "'")
|
||||||
|
.addCondition("$resource/Profile/Name/text() eq '" + name + "'")
|
||||||
|
.setResult("$resource/Profile/AccessPoint/Interface/Endpoint/text()");
|
||||||
|
DiscoveryClient<String> client = ICFactory.client();
|
||||||
|
List<String> addresses = client.submit(query);
|
||||||
|
|
||||||
|
return addresses;
|
||||||
|
|
||||||
|
} catch (Throwable e) {
|
||||||
|
logger.error("Error in discovery DataMiner Service Endpoint in scope: " + scope);
|
||||||
|
logger.error("Error: " + e.getLocalizedMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -9,6 +9,7 @@ import java.net.URLEncoder;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
|
||||||
|
import org.gcube.data.analysis.nlphub.is.DiscoverDataMinerService;
|
||||||
import org.gcube.data.analysis.nlphub.legacy.JsonManager;
|
import org.gcube.data.analysis.nlphub.legacy.JsonManager;
|
||||||
import org.gcube.data.analysis.nlphub.legacy.NlpHubException;
|
import org.gcube.data.analysis.nlphub.legacy.NlpHubException;
|
||||||
import org.gcube.data.analysis.nlphub.shared.Constants;
|
import org.gcube.data.analysis.nlphub.shared.Constants;
|
||||||
|
@ -47,8 +48,14 @@ public class NLpLanguageRecognizer {
|
||||||
public static void run(String dataMiner, String sentence, String token, String publicLink,
|
public static void run(String dataMiner, String sentence, String token, String publicLink,
|
||||||
HttpServletResponse response) throws NlpHubException {
|
HttpServletResponse response) throws NlpHubException {
|
||||||
try {
|
try {
|
||||||
if (dataMiner == null)
|
try {
|
||||||
dataMiner = Constants.DEFAULT_DATAMINER_URL;
|
DiscoverDataMinerService discoverDataMinerService=new DiscoverDataMinerService();
|
||||||
|
dataMiner=discoverDataMinerService.retrieveServiceUrl(token);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error retrieving DataMiner service:" + e.getMessage(),e);
|
||||||
|
throw new Exception("Error retrieving DataMiner service:" + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
//else
|
//else
|
||||||
// dataMiner = "http://" + dataMiner;
|
// dataMiner = "http://" + dataMiner;
|
||||||
String urlService = dataMiner + "?request=Execute&service=WPS&Version=1.0.0";
|
String urlService = dataMiner + "?request=Execute&service=WPS&Version=1.0.0";
|
||||||
|
|
|
@ -11,6 +11,7 @@ import java.util.ArrayList;
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
|
||||||
|
import org.gcube.data.analysis.nlphub.is.DiscoverDataMinerService;
|
||||||
import org.gcube.data.analysis.nlphub.legacy.AsyncHttpRequest;
|
import org.gcube.data.analysis.nlphub.legacy.AsyncHttpRequest;
|
||||||
import org.gcube.data.analysis.nlphub.shared.Constants;
|
import org.gcube.data.analysis.nlphub.shared.Constants;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -24,21 +25,29 @@ public class NlpAsyncNerRunner extends AsyncHttpRequest {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(NlpAsyncNerRunner.class);
|
private static final Logger logger = LoggerFactory.getLogger(NlpAsyncNerRunner.class);
|
||||||
public static final String WPS_EXECUTE_URL = "?request=Execute&service=WPS&Version=1.0.0";
|
public static final String WPS_EXECUTE_URL = "?request=Execute&service=WPS&Version=1.0.0";
|
||||||
public static final String WPS_DESCRIBE_PROCESS_URL = "?request=DescribeProcess&service=WPS&Version=1.0.0";
|
public static final String WPS_DESCRIBE_PROCESS_URL = "?request=DescribeProcess&service=WPS&Version=1.0.0";
|
||||||
public static final String DATAMINER_DEFAULT="http://dataminer-prototypes.d4science.org/wps/WebProcessingService";
|
|
||||||
// private String identifier, token, httpMethod, annotations, publicLink,
|
// private String identifier, token, httpMethod, annotations, publicLink,
|
||||||
// dataMiner;
|
// dataMiner;
|
||||||
private String identifier;
|
private String identifier;
|
||||||
private RunnerCommander commander;
|
private RunnerCommander commander;
|
||||||
|
|
||||||
public NlpAsyncNerRunner(String dataMiner, String identifier, String token, String publicLink, String annotations,
|
public NlpAsyncNerRunner(String dataMiner, String identifier, String token, String publicLink, String annotations,
|
||||||
String language, RunnerCommander commander) {
|
String language, RunnerCommander commander) throws Exception {
|
||||||
super();
|
super();
|
||||||
this.commander=commander;
|
this.commander=commander;
|
||||||
this.identifier=identifier;
|
this.identifier=identifier;
|
||||||
String httpMethod = "GET";
|
String httpMethod = "GET";
|
||||||
|
|
||||||
if (dataMiner == null)
|
|
||||||
dataMiner = Constants.DEFAULT_DATAMINER_URL;
|
try {
|
||||||
|
DiscoverDataMinerService discoverDataMinerService=new DiscoverDataMinerService();
|
||||||
|
dataMiner=discoverDataMinerService.retrieveServiceUrl(token);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error retrieving DataMiner service:" + e.getMessage(),e);
|
||||||
|
throw new Exception("Error retrieving DataMiner service:" + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// else
|
// else
|
||||||
// this.dataMiner = "http://" + dataMiner;
|
// this.dataMiner = "http://" + dataMiner;
|
||||||
logger.debug("NlpAsyncNerRunner: Create Excution Request");
|
logger.debug("NlpAsyncNerRunner: Create Excution Request");
|
||||||
|
|
|
@ -84,7 +84,7 @@ public class RunnerCommander extends Thread {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runAlgorithms() {
|
private void runAlgorithms() throws Exception {
|
||||||
for (String id : identifiers) {
|
for (String id : identifiers) {
|
||||||
NlpAsyncNerRunner n = new NlpAsyncNerRunner(dataMiner, id, token, link, annotationList, null, this);
|
NlpAsyncNerRunner n = new NlpAsyncNerRunner(dataMiner, id, token, link, annotationList, null, this);
|
||||||
logger.debug("Run algorithm: "+id);
|
logger.debug("Run algorithm: "+id);
|
||||||
|
@ -93,7 +93,12 @@ public class RunnerCommander extends Thread {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
runAlgorithms();
|
try {
|
||||||
|
runAlgorithms();
|
||||||
|
} catch (Exception e1) {
|
||||||
|
logger.error("Error in run algorithms: "+e1.getLocalizedMessage(),e1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
long counter = 0;
|
long counter = 0;
|
||||||
try {
|
try {
|
||||||
while (counter <= maxWaitingTime) {
|
while (counter <= maxWaitingTime) {
|
||||||
|
|
|
@ -1,12 +1,17 @@
|
||||||
package org.gcube.data.analysis.nlphub.shared;
|
package org.gcube.data.analysis.nlphub.shared;
|
||||||
|
|
||||||
|
|
||||||
public class Constants {
|
public class Constants {
|
||||||
public static final boolean DEBUG = false;
|
public static final boolean DEBUG = false;
|
||||||
public static final boolean TEST_ENABLE = false;
|
public static final boolean TEST_ENABLE = false;
|
||||||
|
|
||||||
public static final String DEFAULT_USER = "giancarlo.panichi";
|
public static final String DEFAULT_USER = "giancarlo.panichi";
|
||||||
public static final String DEFAULT_SCOPE = "/gcube/devNext/NextNext";
|
public static final String DEFAULT_SCOPE = "/gcube/devNext/NextNext";
|
||||||
|
public static final String DEFAULT_TOKEN = "";
|
||||||
|
|
||||||
|
public static final String DATA_MINER_SERVICE_NAME = "DataMiner";
|
||||||
|
public static final String DATAMINER_SERVICE_CATEGORY = "DataAnalysis";
|
||||||
|
|
||||||
public static final String DEFAULT_DATAMINER_URL = "http://dataminer-prototypes.d4science.org/wps/WebProcessingService";
|
public static final String DEFAULT_DATAMINER_URL = "http://dataminer-prototypes.d4science.org/wps/WebProcessingService";
|
||||||
|
|
||||||
public static final String TOKEN_PARAMETER = "gcube-token";
|
public static final String TOKEN_PARAMETER = "gcube-token";
|
||||||
|
@ -24,6 +29,7 @@ public class Constants {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*public static String hexDump(byte[] bytes) {
|
/*public static String hexDump(byte[] bytes) {
|
||||||
char[] hexArray = "0123456789ABCDEF".toCharArray();
|
char[] hexArray = "0123456789ABCDEF".toCharArray();
|
||||||
char[] hexChars = new char[bytes.length * 3];
|
char[] hexChars = new char[bytes.length * 3];
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
<script type="text/javascript" src="js/main.js"></script>
|
<script type="text/javascript" src="js/main.js"></script>
|
||||||
<script type="text/javascript" src="js/merge.js"></script>
|
<script type="text/javascript" src="js/merge.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
console.log('NLPHub start');
|
||||||
var activePage = "Named Entity Recognition";
|
var activePage = "Named Entity Recognition";
|
||||||
var inputFile = '<%= ((request.getParameter(Constants.INPUT_FILE_PARAMETER) == null) ? "" : "" + request.getParameter(Constants.INPUT_FILE_PARAMETER)) %>';
|
var inputFile = '<%= ((request.getParameter(Constants.INPUT_FILE_PARAMETER) == null) ? "" : "" + request.getParameter(Constants.INPUT_FILE_PARAMETER)) %>';
|
||||||
<%
|
<%
|
||||||
|
@ -29,10 +30,11 @@
|
||||||
%>
|
%>
|
||||||
var gCubeToken = "fea75a5a-d84c-495f-b0ca-09cdd95bacce-843339462";
|
var gCubeToken = "fea75a5a-d84c-495f-b0ca-09cdd95bacce-843339462";
|
||||||
<% } else { %>
|
<% } else { %>
|
||||||
var gCubeToken = "<%=requestToken%>";
|
var gCubeToken = '<%=requestToken%>';
|
||||||
|
|
||||||
<% } %>
|
<% } %>
|
||||||
var scheme = '<%= request.getScheme() %>';
|
var scheme = '<%= request.getScheme() %>';
|
||||||
|
console.log('Scheme: '+scheme);
|
||||||
var contextPath = '<%= request.getContextPath() %>';
|
var contextPath = '<%= request.getContextPath() %>';
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
Loading…
Reference in New Issue