Updated to support DataMiner on specific Url

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-analysis/data-miner-manager-cl@141837 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2017-01-26 17:02:47 +00:00
parent 108a8a2d20
commit 1d79c41a3b
3 changed files with 137 additions and 20 deletions

View File

@ -61,8 +61,7 @@ public class DataMinerService {
*/ */
} }
public SClient getClient(String token) throws Exception { public SClient getClient(String token) throws Exception {
ServiceCredentials serviceCredential = getServiceCredentials(token); ServiceCredentials serviceCredential = getServiceCredentials(token);
@ -85,8 +84,40 @@ public class DataMinerService {
*/ */
} }
/**
*
* @param token
* @param serviceAddressUrl
* valid url for example:
* <span>http://dataminer1-devnext.d4science.org/wps/</span>
* @return
* @throws Exception
*/
public SClient getClient(String token, String serviceAddressUrl)
throws Exception {
ServiceCredentials serviceCredential = getServiceCredentials(token);
/*
* if (cachedSClients.isEmpty() ||
* !cachedSClients.containsKey(serviceCredential.getScope())) {
*/
SClientBuilder sBuilder = new SClient4WPSBuilder(serviceCredential,
serviceAddressUrl);
SClientDirector director = new SClientDirector();
director.setSClientBuilder(sBuilder);
director.constructSClient();
SClient sClient = director.getSClient();
logger.debug("" + sClient);
// cachedSClients.put(serviceCredential.getScope(), sClient);
return sClient;
/*
* } else { return cachedSClients.get(serviceCredential.getScope()); }
*/
}
private ServiceCredentials getServiceCredentials() throws ServiceException { private ServiceCredentials getServiceCredentials() throws ServiceException {
String userName = null; String userName = null;
@ -128,9 +159,9 @@ public class DataMinerService {
return serviceCredential; return serviceCredential;
} }
private ServiceCredentials getServiceCredentials(String token)
private ServiceCredentials getServiceCredentials(String token) throws ServiceException { throws ServiceException {
String userName = null; String userName = null;
String scope = null; String scope = null;
@ -141,11 +172,13 @@ public class DataMinerService {
token = Constants.DEFAULT_TOKEN; token = Constants.DEFAULT_TOKEN;
} else { } else {
logger.debug("Production Mode"); logger.debug("Production Mode");
if(token==null|| token.isEmpty()){ if (token == null || token.isEmpty()) {
logger.error("Error Retrieving token credentials: token="+token); logger.error("Error Retrieving token credentials: token="
throw new ServiceException("Error Retrieving token credentials: token="+token); + token);
throw new ServiceException(
"Error Retrieving token credentials: token=" + token);
} }
try { try {
logger.debug("Retrieving token credentials"); logger.debug("Retrieving token credentials");
AuthorizationEntry entry = authorizationService().get(token); AuthorizationEntry entry = authorizationService().get(token);
@ -168,6 +201,5 @@ public class DataMinerService {
return serviceCredential; return serviceCredential;
} }
} }

View File

@ -94,6 +94,11 @@ public class SClient4WPS extends SClient {
private SClient4WPSSession wpsClient; private SClient4WPSSession wpsClient;
/**
*
* @param serviceCredentials
* @throws ServiceException
*/
public SClient4WPS(ServiceCredentials serviceCredentials) public SClient4WPS(ServiceCredentials serviceCredentials)
throws ServiceException { throws ServiceException {
super(); super();
@ -164,6 +169,62 @@ public class SClient4WPS extends SClient {
} }
/**
*
* @param serviceCredentials
* @param serviceAddressUrl
* valid url for example:
* <span>http://dataminer1-devnext.d4science.org/wps/</span>
* @throws ServiceException
*/
public SClient4WPS(ServiceCredentials serviceCredentials,
String serviceAddressUrl) throws ServiceException {
super();
process = new HashMap<>();
runningProcess = new HashMap<>();
if (serviceCredentials == null) {
logger.error("Error credetials are null!");
throw new ServiceException("Error credetials are null!");
} else {
String token = serviceCredentials.getToken();
if (token == null || token.isEmpty()) {
logger.error("Error authorization token invalid: " + token);
throw new ServiceException(
"Error authorization token invalid: " + token);
} else {
wpsToken = token;
}
String userName = serviceCredentials.getUsername();
if (userName == null || userName.isEmpty()) {
logger.error("Error invalid user name: " + userName);
throw new ServiceException("Error invalid user name: "
+ userName);
} else {
wpsUser = userName;
}
logger.debug("Service Address:" + serviceAddressUrl);
if (serviceAddressUrl == null || serviceAddressUrl.isEmpty()) {
logger.error("Invalid DataMiner service address: "
+ serviceAddressUrl);
throw new ServiceException(
"Invalid DataMiner service address: "
+ serviceAddressUrl);
} else {
logger.info("DataMiner service address: " + serviceAddressUrl);
// http://dataminer1-devnext.d4science.org/wps/WebProcessingService
wpsProcessingServlet = serviceAddressUrl
+ Constants.WPSWebProcessingService;
wpsCancelComputationServlet = serviceAddressUrl
+ Constants.WPSCancelComputationServlet;
}
}
}
private SClient4WPSSession createWPSClientSession() { private SClient4WPSSession createWPSClientSession() {
if (wpsClient == null) { if (wpsClient == null) {
wpsClient = new SClient4WPSSession(wpsUser, wpsToken); wpsClient = new SClient4WPSSession(wpsUser, wpsToken);
@ -612,12 +673,11 @@ public class SClient4WPS extends SClient {
if (node == null) if (node == null)
return; return;
logger.debug("Node Name: " + node.getNodeName()); logger.debug("Node Name: " + node.getNodeName());
if (node.getNodeName() == null) { if (node.getNodeName() == null) {
return; return;
} }
if (node.getFirstChild() != null) { if (node.getFirstChild() != null) {
logger.debug("Node Value: " + node.getFirstChild().getNodeValue()); logger.debug("Node Value: " + node.getFirstChild().getNodeValue());
} else { } else {
@ -625,7 +685,6 @@ public class SClient4WPS extends SClient {
return; return;
} }
String text; String text;
switch (node.getNodeName()) { switch (node.getNodeName()) {
case "d4science:Data": case "d4science:Data":

View File

@ -1,6 +1,5 @@
package org.gcube.data.analysis.dataminermanagercl.server.dmservice; package org.gcube.data.analysis.dataminermanagercl.server.dmservice;
import org.gcube.data.analysis.dataminermanagercl.server.util.ServiceCredentials; import org.gcube.data.analysis.dataminermanagercl.server.util.ServiceCredentials;
import org.gcube.data.analysis.dataminermanagercl.shared.exception.ServiceException; import org.gcube.data.analysis.dataminermanagercl.shared.exception.ServiceException;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -17,10 +16,30 @@ public class SClient4WPSBuilder extends SClientBuilder {
private static Logger logger = LoggerFactory private static Logger logger = LoggerFactory
.getLogger(SClient4WPSBuilder.class); .getLogger(SClient4WPSBuilder.class);
private ServiceCredentials serviceCredendials; private ServiceCredentials serviceCredendials;
private String serviceAddressUrl;
private boolean useUrl;
/**
*
* @param serviceCredentials
*/
public SClient4WPSBuilder(ServiceCredentials serviceCredentials) { public SClient4WPSBuilder(ServiceCredentials serviceCredentials) {
this.serviceCredendials= serviceCredentials; this.serviceCredendials = serviceCredentials;
this.useUrl = false;
}
/**
*
* @param serviceCredentials
* @param serviceAddressUrl
* valid url for example:
* <span>http://dataminer1-devnext.d4science.org/wps/</span>
*/
public SClient4WPSBuilder(ServiceCredentials serviceCredentials,
String serviceAddressUrl) {
this.serviceCredendials = serviceCredentials;
this.serviceAddressUrl = serviceAddressUrl;
this.useUrl = true;
} }
@Override @Override
@ -28,13 +47,20 @@ public class SClient4WPSBuilder extends SClientBuilder {
try { try {
logger.debug("Build SC4WPS"); logger.debug("Build SC4WPS");
logger.debug("ServiceCredentials: " + serviceCredendials); logger.debug("ServiceCredentials: " + serviceCredendials);
SClient sClient = new SClient4WPS(serviceCredendials); SClient sClient;
if (useUrl) {
logger.debug("Use Url: " + useUrl);
logger.debug("DataMiner Service Address: " + serviceAddressUrl);
sClient = new SClient4WPS(serviceCredendials, serviceAddressUrl);
} else {
logger.debug("Use Url: " + useUrl);
sClient = new SClient4WPS(serviceCredendials);
}
sClientSpec.setSClient(sClient); sClientSpec.setSClient(sClient);
} catch (Throwable e) { } catch (Throwable e) {
logger.error(e.getLocalizedMessage()); logger.error(e.getLocalizedMessage());
e.printStackTrace(); e.printStackTrace();
throw new ServiceException(e.getLocalizedMessage(),e); throw new ServiceException(e.getLocalizedMessage(), e);
} }
} }