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
8
pom.xml
8
pom.xml
|
@ -91,17 +91,25 @@
|
|||
<artifactId>common-configuration-scanner</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.resources</groupId>
|
||||
<artifactId>registry-publisher</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-scope</artifactId>
|
||||
<scope>provided</scope>
|
||||
</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 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat</groupId>
|
||||
|
|
|
@ -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.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.NlpHubException;
|
||||
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,
|
||||
HttpServletResponse response) throws NlpHubException {
|
||||
try {
|
||||
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
|
||||
// dataMiner = "http://" + dataMiner;
|
||||
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 org.gcube.data.analysis.nlphub.is.DiscoverDataMinerService;
|
||||
import org.gcube.data.analysis.nlphub.legacy.AsyncHttpRequest;
|
||||
import org.gcube.data.analysis.nlphub.shared.Constants;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -24,21 +25,29 @@ public class NlpAsyncNerRunner extends AsyncHttpRequest {
|
|||
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_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,
|
||||
// dataMiner;
|
||||
private String identifier;
|
||||
private RunnerCommander commander;
|
||||
|
||||
public NlpAsyncNerRunner(String dataMiner, String identifier, String token, String publicLink, String annotations,
|
||||
String language, RunnerCommander commander) {
|
||||
String language, RunnerCommander commander) throws Exception {
|
||||
super();
|
||||
this.commander=commander;
|
||||
this.identifier=identifier;
|
||||
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
|
||||
// this.dataMiner = "http://" + dataMiner;
|
||||
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) {
|
||||
NlpAsyncNerRunner n = new NlpAsyncNerRunner(dataMiner, id, token, link, annotationList, null, this);
|
||||
logger.debug("Run algorithm: "+id);
|
||||
|
@ -93,7 +93,12 @@ public class RunnerCommander extends Thread {
|
|||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
runAlgorithms();
|
||||
} catch (Exception e1) {
|
||||
logger.error("Error in run algorithms: "+e1.getLocalizedMessage(),e1);
|
||||
return;
|
||||
}
|
||||
long counter = 0;
|
||||
try {
|
||||
while (counter <= maxWaitingTime) {
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
package org.gcube.data.analysis.nlphub.shared;
|
||||
|
||||
|
||||
public class Constants {
|
||||
public static final boolean DEBUG = false;
|
||||
public static final boolean TEST_ENABLE = false;
|
||||
|
||||
public static final String DEFAULT_USER = "giancarlo.panichi";
|
||||
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";
|
||||
|
||||
|
@ -24,6 +29,7 @@ public class Constants {
|
|||
|
||||
|
||||
|
||||
|
||||
/*public static String hexDump(byte[] bytes) {
|
||||
char[] hexArray = "0123456789ABCDEF".toCharArray();
|
||||
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/merge.js"></script>
|
||||
<script type="text/javascript">
|
||||
console.log('NLPHub start');
|
||||
var activePage = "Named Entity Recognition";
|
||||
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";
|
||||
<% } else { %>
|
||||
var gCubeToken = "<%=requestToken%>";
|
||||
var gCubeToken = '<%=requestToken%>';
|
||||
|
||||
<% } %>
|
||||
var scheme = '<%= request.getScheme() %>';
|
||||
console.log('Scheme: '+scheme);
|
||||
var contextPath = '<%= request.getContextPath() %>';
|
||||
</script>
|
||||
</head>
|
||||
|
|
Loading…
Reference in New Issue