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 {
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 {
String userName = null;
@ -128,9 +159,9 @@ public class DataMinerService {
return serviceCredential;
}
private ServiceCredentials getServiceCredentials(String token) throws ServiceException {
private ServiceCredentials getServiceCredentials(String token)
throws ServiceException {
String userName = null;
String scope = null;
@ -141,11 +172,13 @@ public class DataMinerService {
token = Constants.DEFAULT_TOKEN;
} else {
logger.debug("Production Mode");
if(token==null|| token.isEmpty()){
logger.error("Error Retrieving token credentials: token="+token);
throw new ServiceException("Error Retrieving token credentials: token="+token);
if (token == null || token.isEmpty()) {
logger.error("Error Retrieving token credentials: token="
+ token);
throw new ServiceException(
"Error Retrieving token credentials: token=" + token);
}
try {
logger.debug("Retrieving token credentials");
AuthorizationEntry entry = authorizationService().get(token);
@ -168,6 +201,5 @@ public class DataMinerService {
return serviceCredential;
}
}

View File

@ -94,6 +94,11 @@ public class SClient4WPS extends SClient {
private SClient4WPSSession wpsClient;
/**
*
* @param serviceCredentials
* @throws ServiceException
*/
public SClient4WPS(ServiceCredentials serviceCredentials)
throws ServiceException {
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() {
if (wpsClient == null) {
wpsClient = new SClient4WPSSession(wpsUser, wpsToken);
@ -612,12 +673,11 @@ public class SClient4WPS extends SClient {
if (node == null)
return;
logger.debug("Node Name: " + node.getNodeName());
if (node.getNodeName() == null) {
return;
}
if (node.getFirstChild() != null) {
logger.debug("Node Value: " + node.getFirstChild().getNodeValue());
} else {
@ -625,7 +685,6 @@ public class SClient4WPS extends SClient {
return;
}
String text;
switch (node.getNodeName()) {
case "d4science:Data":

View File

@ -1,6 +1,5 @@
package org.gcube.data.analysis.dataminermanagercl.server.dmservice;
import org.gcube.data.analysis.dataminermanagercl.server.util.ServiceCredentials;
import org.gcube.data.analysis.dataminermanagercl.shared.exception.ServiceException;
import org.slf4j.Logger;
@ -17,10 +16,30 @@ public class SClient4WPSBuilder extends SClientBuilder {
private static Logger logger = LoggerFactory
.getLogger(SClient4WPSBuilder.class);
private ServiceCredentials serviceCredendials;
private String serviceAddressUrl;
private boolean useUrl;
/**
*
* @param 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
@ -28,13 +47,20 @@ public class SClient4WPSBuilder extends SClientBuilder {
try {
logger.debug("Build SC4WPS");
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);
} catch (Throwable e) {
logger.error(e.getLocalizedMessage());
e.printStackTrace();
throw new ServiceException(e.getLocalizedMessage(),e);
throw new ServiceException(e.getLocalizedMessage(), e);
}
}