- for the submitQuery the file result management has been modified. The file is retrieved from the statistical. GWTdbManagerServiceImpl, GxtBorderLayoutPanel, ComputationOutput, SubmitQueryResultWithFileFromServlet modified.

- pom file version changed in 1.3.0
- check added on data object in loadSubmitQuery method
- UriResolver used to generate an http link from smp url. Dependency added in the pom file.

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/databases-manager-portlet@101654 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Loredana Liccardo 2014-11-19 15:00:35 +00:00
parent c5d19b629c
commit aec88a2b18
5 changed files with 145 additions and 50 deletions

View File

@ -19,7 +19,7 @@
<groupId>org.gcube.portlets.user</groupId>
<artifactId>databases-manager-portlet</artifactId>
<packaging>war</packaging>
<version>1.2.0-SNAPSHOT</version>
<version>1.3.0-SNAPSHOT</version>
<name>DatabasesResourceManagerPortlet</name>
<description>Databases Resource Manager Portlet</description>
@ -168,6 +168,12 @@
<version>2.8.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>uri-resolver-manager</artifactId>
<version>[1.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
</dependency>
<!-- <dependency> -->
<!-- <groupId>jcs</groupId> -->

View File

@ -6,10 +6,12 @@ public class ComputationOutput {
private LinkedHashMap<String, String> mapValues;
private LinkedHashMap<String, String> mapKeys;
private String urlFile;
public ComputationOutput() {
mapKeys = new LinkedHashMap<String, String>();
mapValues = new LinkedHashMap<String, String>();
urlFile="";
}
public void setMapValues(LinkedHashMap<String, String> mapValues) {
@ -27,4 +29,12 @@ public class ComputationOutput {
public LinkedHashMap<String, String> getmapKeys() {
return mapKeys;
}
public void setUrlFile(String url){
this.urlFile=url;
}
public String getUrlFile(){
return this.urlFile;
}
}

View File

@ -12,16 +12,27 @@ public class SubmitQueryResultWithFileFromServlet extends BaseModelData
private List<String> attributes;
private String convertedQuery;
private String fileName;
private String urlFile;
public SubmitQueryResultWithFileFromServlet() {
}
// public SubmitQueryResultWithFileFromServlet(List<String> attributes,
// String query, String fileName, String urlFile) {
// set("attributes", attributes);
// set("convertedQuery", query);
// set("fileName", fileName);
// set("urlFile", urlFile);
//
// }
public SubmitQueryResultWithFileFromServlet(List<String> attributes,
String query, String fileName) {
String query, String urlFile) {
set("attributes", attributes);
set("convertedQuery", query);
set("fileName", fileName);
// set("fileName", fileName);
set("urlFile", urlFile);
}
@ -29,12 +40,16 @@ public class SubmitQueryResultWithFileFromServlet extends BaseModelData
return get("attributes");
}
public String getFileName() {
return get("fileName");
}
// public String getFileName() {
// return get("fileName");
// }
public String getConvertedQuery() {
return get("convertedQuery");
}
public String getUrlFile(){
return get("urlFile");
}
}

View File

@ -997,9 +997,10 @@ public class GxtBorderLayoutPanel extends ContentPanel {
// listAttributes, dataQuery.getQuery());
// get path
String fileName = obj.getFileName();
// String fileName = obj.getFileName();
String urlFile = obj.getUrlFile();
parseSubmitQueryResult(form, dialogID,
listAttributes, query, fileName, UID);
listAttributes, query, urlFile, UID);
}
@ -1009,7 +1010,7 @@ public class GxtBorderLayoutPanel extends ContentPanel {
// start the parsing of the submit result in order to obtain a table
private void parseSubmitQueryResult(Dialog dialog, final int dialogID,
final List<String> listAttributes, String query, String fileName,
final List<String> listAttributes, String query, final String urlFile,
final String UID) {
final Dialog form = dialog;
@ -1278,8 +1279,8 @@ public class GxtBorderLayoutPanel extends ContentPanel {
});
// add the button to download the result
final String urlFile = Window.Location.getProtocol() + "//"
+ Window.Location.getHost() + fileName;
// final String urlFile = Window.Location.getProtocol() + "//"
// + Window.Location.getHost() + fileName;
Button download = new Button("Download",
new SelectionListener<ButtonEvent>() {

View File

@ -72,6 +72,8 @@ import org.gcube.portlets.user.databasesmanager.server.util.SessionUtil;
import org.gcube.portlets.user.databasesmanager.shared.ConstantsPortlet;
import org.gcube.portlets.user.databasesmanager.shared.SessionExpiredException;
import org.gcube.portlets.user.databasesmanager.shared.StatisticalManagerException;
import org.gcube.portlets.user.uriresolvermanager.UriResolverManager;
import com.extjs.gxt.ui.client.data.BasePagingLoadResult;
import com.extjs.gxt.ui.client.data.PagingLoadConfig;
import com.extjs.gxt.ui.client.data.PagingLoadResult;
@ -150,6 +152,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
} else {
cacheManager.addCache(DBCache);
logger.info("dbmanager-> cache added to the cacheManager");
logger.info("dbmanager-> ** SIZE OF THE MEMORY STORE: "+ DBCache.calculateInMemorySize());
// logger.trace("dbmanager-> ** SIZE OF THE OFF HEAP"+ DBCache.calculateOffHeapSize());
logger.info("dbmanager-> ** SIZE OF THE DISK STORE SIZE: "+ DBCache.calculateOnDiskSize());
}
}
@ -211,6 +217,9 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
// size.maxDepthExceededBehavior(MaxDepthExceededBehavior.ABORT);
// config.sizeOfPolicy(size);
DBCache = new Cache(config);
} catch (Exception e) {
// logger.error("dbmanager-> Error while starting the servlet. Failed to create the cache",
// e);
@ -358,6 +367,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
if ((value == null) || (value.booleanValue() == false)) {
DataExchangedThroughQueue dataqueue = new DataExchangedThroughQueue(
scope);
queue.offer(dataqueue);
Thread t = new Thread(dataLoader);
t.start();
@ -700,9 +710,12 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
// create data structure
ComputationOutput outputData = new ComputationOutput();
//file name
String FileName = "QueryResult"+"_" + System.currentTimeMillis() + ".csv";
// computation id
String computationId = startComputation(algorithmId,
inputParameters, outputData, scope, UID);
inputParameters, outputData, scope, UID, FileName);
// get JobID
@ -757,25 +770,32 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
// updateSubmitQueryResultMap(UID, output);
// remove job with the specified uid
removeJob(UID);
//TODO ** COMMENTED
// generate the file csv output
String name = "SubmitQuery";
String fileName = storeResultIntoCSVFile(output, name);
// String name = "SubmitQuery";
// String fileName = storeResultIntoCSVFile(output, name);
// get the web application path
HttpServletRequest request = this
.getThreadLocalRequest();
String applicationPath = request.getContextPath();
// logger.info("dbmanager-> Application Path: " +
// applicationPath);
String partialPathFile = applicationPath
+ "/computationResult/" + fileName;
// HttpServletRequest request = this
// .getThreadLocalRequest();
// String applicationPath = request.getContextPath();
// // logger.info("dbmanager-> Application Path: " +
// // applicationPath);
// String partialPathFile = applicationPath
// + "/computationResult/" + fileName;
String urlFile=outputData.getUrlFile();
// result = new SubmitQueryResultWithFileFromServlet(
// listAttributes, convertedQuery, partialPathFile, urlFile);
result = new SubmitQueryResultWithFileFromServlet(
listAttributes, convertedQuery, partialPathFile);
listAttributes, convertedQuery, urlFile);
// put the two data in cache
net.sf.ehcache.Element dataToCache = new net.sf.ehcache.Element(
keyData, result);
insertDataIntoCache(dataToCache);
// remove the header in order to parse only the result
@ -783,6 +803,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
net.sf.ehcache.Element submitQueryResultToCache = new net.sf.ehcache.Element(
keySubmitQueryResult, output);
//TODO **TO DECOMMENT
// updateListSubmitQueryResult(UID, output);
insertDataIntoCache(submitQueryResultToCache);
}
@ -806,7 +828,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
if (!(e instanceof StatisticalManagerException)) {
// GWT can't serialize all exceptions
throw new Exception(
"Error in server while loading data. Exception: " + e);
"Error in server while loading data.");
}
throw e;
} finally {
@ -1381,6 +1403,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
}
if (value != null) {
result = (List<Result>) value;
logger.trace("dbmanager-> ** Data get from cache");
updateListSubmitQueryResult(UID, result);
// data = parseCVSString(result, listAttributes);
@ -1404,6 +1427,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
//get the result bound to session
result = getSubmitQueryResult(UID);
logger.trace("dbmanager-> ** Data get from ASL session");
// logger.error("dbmanager-> Error in server while loading data. variable value null");
// throw new Exception("Error in server while loading data.");
@ -1411,23 +1435,27 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
}
data = parseCVSString(result, listAttributes);
if(data!=null){
int start = config.getOffset();
int limit = data.size();
int start = config.getOffset();
int limit = data.size();
if (config.getLimit() > 0) {
limit = Math.min(start + config.getLimit(), limit);
}
if (config.getLimit() > 0) {
limit = Math.min(start + config.getLimit(), limit);
int totalNumber = data.size();
sublist = new ArrayList<Row>(data.subList(start, limit));
loadResult = new BasePagingLoadResult<Row>(sublist,
config.getOffset(), totalNumber);
// System.out.println("start: " + start);
// System.out.println("limit: " + limit);
// System.out.println("sublist size: " + sublist.size());
}else{
logger.error("dbmanager-> Error in server while loading data. object data null");
throw new Exception("Error in server while loading data.");
}
int totalNumber = data.size();
sublist = new ArrayList<Row>(data.subList(start, limit));
loadResult = new BasePagingLoadResult<Row>(sublist,
config.getOffset(), totalNumber);
// System.out.println("start: " + start);
// System.out.println("limit: " + limit);
// System.out.println("sublist size: " + sublist.size());
} else {
logger.error("dbmanager-> Error in server while loading data. key null");
throw new Exception("Error in server while loading data.");
@ -1752,12 +1780,12 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
List<Parameter> parameters, ComputationOutput outputData,
String scope) throws Exception {
return startComputation(algorithmName, parameters, outputData, scope,
null);
null, null);
}
private String startComputation(String algorithmName,
List<Parameter> parameters, ComputationOutput outputData,
String scopeValue, String jobID) throws Exception {
String scopeValue, String jobID, String FileName) throws Exception {
SMComputationConfig config = new SMComputationConfig();
SMInputEntry[] list = new SMInputEntry[parameters.size()];
@ -1788,7 +1816,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
logger.info("dbmanager-> startComputation: the computation has started!");
while (percentage < 100) {
percentage = checkComputationStatus(scope, computationId,
username, outputData);
username, outputData, FileName);
Thread.sleep(3000);
}
logger.info("dbmanager-> startComputation: the computation has finished!");
@ -1805,7 +1833,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
}
private float checkComputationStatus(String scope, String computationId,
String user, ComputationOutput outputData) throws Exception {
String user, ComputationOutput outputData, String FileName) throws Exception {
// System.out.println("checkComputation " + computationId);
ScopeProvider.instance.set(scope);
@ -1836,7 +1864,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
int resourceTypeIndex = smResource.resourceType();
SMResourceType smResType = SMResourceType.values()[resourceTypeIndex];
displayOutput(smResource, smResType, outputData);
displayOutput(smResource, smResType, outputData, scope, FileName);
// print check
// logger.info("SM resource Name: " + smResource.name());
@ -1851,7 +1879,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
}
private void displayOutput(SMResource smResource, SMResourceType smResType,
ComputationOutput outputData) throws Exception {
ComputationOutput outputData, String scope, String FileName) throws Exception {
if (smResType.equals(SMResourceType.OBJECT)) {
// switch (smResType) {
@ -1863,7 +1891,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
SMObject objRes = (SMObject) smResource;
if (objRes.name().contentEquals(PrimitiveTypes.MAP.toString())) {
logger.info("dbmanager-> Output is a map");
getMap(objRes, outputData);
getMap(objRes, outputData, scope, FileName);
} else if (objRes.name().contentEquals(
PrimitiveTypes.IMAGES.toString())) {
@ -1885,14 +1913,14 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
}
// get output result
private void getMap(SMObject objRes, ComputationOutput outputData)
private void getMap(SMObject objRes, ComputationOutput outputData, String scope, String FileName)
throws Exception {
// output data values
LinkedHashMap<String, String> mapValues = new LinkedHashMap<String, String>();
// output data keys
LinkedHashMap<String, String> mapKeys = new LinkedHashMap<String, String>();
// logger.info("getStorageInputStream - started");
// logger.info("**getStorageInputStream - started");
InputStream is = getStorageClientInputStream(objRes.url());
// object serializer
XStream xstream = new XStream();
@ -1914,11 +1942,41 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
Map<String, SMResource> smMap = (Map<String, SMResource>) (xstream
.fromXML(is));
is.close();
// logger.info("getStorageInputStream - finished");
// logger.info("**getStorageInputStream - finished");
// logger.info("build the resultMap - started");
// logger.info("**build the resultMap - started");
int i = 0;
for (String key : smMap.keySet()) {
if (key.equals("File")){
logger.info("dbmanager-> " + "the map contains file");
SMResource smres = smMap.get("File");
int resourceTypeIndex = smres.resourceType();
SMResourceType smsubResType = SMResourceType.values()[resourceTypeIndex];
// logger.info("dbmanager-> Output is a file");
SMFile fileRes = (SMFile) smres;
// logger.info("dbmanager-> **FILE URL " + fileRes.url());
// logger.info("dbmanager-> **FILE MIMETYPE " + fileRes.mimeType());
ScopeProvider.instance.set(scope);
UriResolverManager resolver = new UriResolverManager("SMP");
Map<String, String> params = new HashMap<String, String>();
params.put("smp-uri", fileRes.url());
params.put("fileName", FileName);
params.put("contentType", "text/plain");
String shortLink = resolver.getLink(params, true);
if ((shortLink!=null)&&(!shortLink.equals(""))){
outputData.setUrlFile(shortLink);
logger.info("dbmanager-> Http link of the generated File: " + shortLink);
}else{
logger.error("dbmanager-> Error in server while generating the file. Http link null");
throw new Exception("Error in server while generating the file.");
}
} else{
// add key value
mapKeys.put(String.valueOf(i), key);
SMResource smres = smMap.get(key);
@ -1934,10 +1992,11 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
mapValues.put(String.valueOf(i), outstring);
i++;
}
}
}
outputData.setMapValues(mapValues);
outputData.setmapKeys(mapKeys);
// logger.info("build the resultMap - finished");
// logger.info("**build the resultMap - finished");
}
private InputStream getStorageClientInputStream(String url)
@ -2076,6 +2135,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
if (DBCache.getStatus().toString().equals(Status.STATUS_ALIVE.toString())){
DBCache.put(data);
logger.trace("dbmanager-> element with key: " + data.getKey().toString()+" added in cache");
logger.info("dbmanager-> ** SIZE OF THE MEMORY STORE: "+ DBCache.calculateInMemorySize());
// logger.trace("dbmanager-> ** SIZE OF THE OFF HEAP"+ DBCache.calculateOffHeapSize());
logger.info("dbmanager-> ** SIZE OF THE DISK STORE SIZE: "+ DBCache.calculateOnDiskSize());
}
}
}
@ -2767,7 +2830,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
}
//TODO ****TO REMOVE
if (outputParameters!=null){
logger.info("dbmanager-> ***print output ");
// logger.info("dbmanager-> ***print output ");
Set<String> keys = outputParameters.keySet();
Object[] array = keys.toArray();