sampling and smartSampling cached

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/databases-manager-portlet@100288 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Loredana Liccardo 2014-09-30 12:32:27 +00:00
parent 358c98db4c
commit 53ac9390b7
2 changed files with 212 additions and 86 deletions

View File

@ -1324,12 +1324,12 @@ public class GxtBorderLayoutPanel extends ContentPanel {
}
@Override
public void onSuccess(SamplingResultWithFileFromServlet obj) {
public void onSuccess(SamplingResultWithFileFromServlet samplingResult) {
rootLogger.log(Level.SEVERE, "SUCCESS RPC sample");
if (obj != null) {
if (samplingResult != null) {
// get data
List<Result> result = obj.getListOutput();
List<Result> result = samplingResult.getListOutput();
// get the attributes list for the result
// table
List<String> listAttributes = new ArrayList<String>();
@ -1342,11 +1342,19 @@ public class GxtBorderLayoutPanel extends ContentPanel {
+ result.size());
// get path
String fileName = obj.getFileName();
String fileName = samplingResult.getFileName();
// parse the result in order to obtain a
// table
parseResult(result, listAttributes, fileName);
} else{
MessageBox.alert("Error ",
"<br/>Message: " + "no data available", null);
if (obj.isMasked()) {
obj.unmask();
}
}
}
@ -1468,12 +1476,12 @@ public class GxtBorderLayoutPanel extends ContentPanel {
}
@Override
public void onSuccess(SamplingResultWithFileFromServlet obj) {
public void onSuccess(SamplingResultWithFileFromServlet samplingResult) {
rootLogger.log(Level.SEVERE, "SUCCESS RPC smartSample");
if (obj != null) {
if (samplingResult != null) {
// get data
List<Result> result = obj.getListOutput();
List<Result> result = samplingResult.getListOutput();
// get the attributes list for the result
// table
List<String> listAttributes = new ArrayList<String>();
@ -1485,10 +1493,18 @@ public class GxtBorderLayoutPanel extends ContentPanel {
rootLogger.log(Level.SEVERE, "output size: "
+ result.size());
// get path
String fileName = obj.getFileName();
String fileName = samplingResult.getFileName();
// parse the result in order to obtain a
// table
parseResult(result, listAttributes, fileName);
}else{
MessageBox.alert("Error ",
"<br/>Message: " + "no data available", null);
if (obj.isMasked()) {
obj.unmask();
}
}
}
});
@ -1578,13 +1594,13 @@ public class GxtBorderLayoutPanel extends ContentPanel {
}
@Override
public void onSuccess(SamplingResultWithFileFromServlet obj) {
public void onSuccess(SamplingResultWithFileFromServlet samplingResult) {
rootLogger
.log(Level.SEVERE, "SUCCESS RPC randomSample");
if (obj != null) {
if (samplingResult != null) {
// get data
List<Result> result = obj.getListOutput();
List<Result> result = samplingResult.getListOutput();
// get the attributes list for the result
// table
List<String> listAttributes = new ArrayList<String>();
@ -1596,10 +1612,18 @@ public class GxtBorderLayoutPanel extends ContentPanel {
rootLogger.log(Level.SEVERE, "output size: "
+ result.size());
// get path
String fileName = obj.getFileName();
String fileName = samplingResult.getFileName();
// parse the result in order to obtain a
// table
parseResult(result, listAttributes, fileName);
} else{
MessageBox.alert("Error ",
"<br/>Message: " + "no data available", null);
if (obj.isMasked()) {
obj.unmask();
}
}
}
});

View File

@ -189,8 +189,11 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
} catch (Exception e) {
// TODO: handle exception
// logger.error("dbmanager-> Error while starting the servlet. Failed to create the cache", e);
throw new Exception("Error while starting the servlet. Failed to create the cache. Exception: " +e);
// logger.error("dbmanager-> Error while starting the servlet. Failed to create the cache",
// e);
throw new Exception(
"Error while starting the servlet. Failed to create the cache. Exception: "
+ e);
}
}
@ -721,7 +724,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
} catch (Exception e) {
// e.printStackTrace();
// throw new Exception("Failed to load data. " + e);
// logger.error("dbmanager-> ", e);
// logger.error("dbmanager-> ", e);
if (!(e instanceof StatisticalManagerException)) {
// GWT can't serialize all exceptions
@ -904,6 +907,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
// data output
// List<Result> output = new ArrayList<Result>();
List<Result> output = null;
SubmitQueryResultWithFileFromServlet result;
// list that contains table attributes
List<String> listAttributes = null;
@ -960,6 +964,31 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
inputParameters.get(4).setValue(language);
inputParameters.get(5).setValue(query);
// get data from cache
// check if data exist considering as key the input parameters
// parse the query in order to remove spaces
String queryParsed = parseQuery(inputParameters.get(5).getValue());
String key = inputParameters.get(0).getValue()
+ inputParameters.get(1).getValue()
+ inputParameters.get(2).getValue()
+ inputParameters.get(3).getValue()
+ inputParameters.get(4).getValue()
+ queryParsed;
net.sf.ehcache.Element dataFromCache = getDataFromCache(key);
Object value = null;
if (dataFromCache != null) {
value = dataFromCache.getObjectValue();
// System.out.println("***GETTING DATA FROM CACHE");
}
if (value != null) {
result = (SubmitQueryResultWithFileFromServlet) value;
} else {
// create data structure
ComputationOutput outputData = new ComputationOutput();
@ -1027,10 +1056,17 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
String partialPathFile = applicationPath + "/computationResult/"
+ fileName;
SubmitQueryResultWithFileFromServlet obj = new SubmitQueryResultWithFileFromServlet(
result = new SubmitQueryResultWithFileFromServlet(
listAttributes, convertedQuery, partialPathFile);
// put data in cache
net.sf.ehcache.Element dataToCache = new net.sf.ehcache.Element(
key, result);
insertDataIntoCache(dataToCache);
}
return obj;
return result;
} catch (Exception e) {
// e.printStackTrace();
@ -1068,6 +1104,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
List<Parameter> inputParameters = new ArrayList<Parameter>();
// output sample result
List<Result> output = new ArrayList<Result>();
SamplingResultWithFileFromServlet result;
String algorithmId = "SAMPLEONTABLE";
@ -1126,41 +1163,70 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
inputParameters.get(2).setValue(scm);
inputParameters.get(3).setValue(tab);
// create data structure
ComputationOutput outputData = new ComputationOutput();
// computation id
String computationId = startComputation(algorithmId,
inputParameters, outputData);
// get data from cache
// check if data exist considering as key the input parameters
String key = algorithmId + inputParameters.get(0).getValue()
+ inputParameters.get(1).getValue()
+ inputParameters.get(2).getValue()
+ inputParameters.get(3).getValue();
// print check on retrieving data
// logger.info("output data retrieved");
net.sf.ehcache.Element dataFromCache = getDataFromCache(key);
// data output values
LinkedHashMap<String, String> mapValues = new LinkedHashMap<String, String>();
// data output keys
LinkedHashMap<String, String> mapKeys = new LinkedHashMap<String, String>();
Object value = null;
if (dataFromCache != null) {
value = dataFromCache.getObjectValue();
// System.out.println("***GETTING DATA FROM CACHE");
}
if (value != null) {
result = (SamplingResultWithFileFromServlet) value;
mapValues = outputData.getMapValues();
mapKeys = outputData.getmapKeys();
} else {
// start computation
// create data structure
ComputationOutput outputData = new ComputationOutput();
// computation id
String computationId = startComputation(algorithmId,
inputParameters, outputData);
// print check on retrieving data
// logger.info("output data retrieved");
// data output values
LinkedHashMap<String, String> mapValues = new LinkedHashMap<String, String>();
// data output keys
LinkedHashMap<String, String> mapKeys = new LinkedHashMap<String, String>();
mapValues = outputData.getMapValues();
mapKeys = outputData.getmapKeys();
for (int i = 0; i < mapValues.size(); i++) {
Result row = new Result(mapKeys.get(String.valueOf(i)),
mapValues.get(String.valueOf(i)));
output.add(row);
}
String name = "Sampling" + "_" + tab;
String fileName = storeResultIntoCSVFile(output, name);
HttpServletRequest request = this.getThreadLocalRequest();
String applicationPath = request.getContextPath();
// logger.info("dbmanager-> Application Path: " +
// applicationPath);
String partialPathFile = applicationPath
+ "/computationResult/" + fileName;
result = new SamplingResultWithFileFromServlet(output,
partialPathFile);
// put data in cache
net.sf.ehcache.Element dataToCache = new net.sf.ehcache.Element(
key, result);
insertDataIntoCache(dataToCache);
for (int i = 0; i < mapValues.size(); i++) {
Result row = new Result(mapKeys.get(String.valueOf(i)),
mapValues.get(String.valueOf(i)));
output.add(row);
}
String name = "Sampling" + "_" + tab;
String fileName = storeResultIntoCSVFile(output, name);
HttpServletRequest request = this.getThreadLocalRequest();
String applicationPath = request.getContextPath();
// logger.info("dbmanager-> Application Path: " + applicationPath);
String partialPathFile = applicationPath + "/computationResult/"
+ fileName;
SamplingResultWithFileFromServlet obj = new SamplingResultWithFileFromServlet(
output, partialPathFile);
return obj;
return result;
} catch (Exception e) {
logger.error("dbmanager-> ", e);
@ -1187,6 +1253,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
List<Parameter> inputParameters = new ArrayList<Parameter>();
// output sample result
List<Result> output = new ArrayList<Result>();
SamplingResultWithFileFromServlet result;
String algorithmId = "SMARTSAMPLEONTABLE";
@ -1245,41 +1312,68 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
inputParameters.get(2).setValue(scm);
inputParameters.get(3).setValue(tab);
// create data structure
ComputationOutput outputData = new ComputationOutput();
// computation id
String computationId = startComputation(algorithmId,
inputParameters, outputData);
// get data from cache
// check if data exist considering as key the input parameters
String key = algorithmId + inputParameters.get(0).getValue()
+ inputParameters.get(1).getValue()
+ inputParameters.get(2).getValue()
+ inputParameters.get(3).getValue();
// print check on retrieving data
// logger.info("dbmanager-> output data retrieved");
net.sf.ehcache.Element dataFromCache = getDataFromCache(key);
// data output values
LinkedHashMap<String, String> mapValues = new LinkedHashMap<String, String>();
// data output keys
LinkedHashMap<String, String> mapKeys = new LinkedHashMap<String, String>();
Object value = null;
if (dataFromCache != null) {
value = dataFromCache.getObjectValue();
// System.out.println("***GETTING DATA FROM CACHE");
}
if (value != null) {
result = (SamplingResultWithFileFromServlet) value;
mapValues = outputData.getMapValues();
mapKeys = outputData.getmapKeys();
} else {
// create data structure
ComputationOutput outputData = new ComputationOutput();
// computation id
String computationId = startComputation(algorithmId,
inputParameters, outputData);
// print check on retrieving data
// logger.info("dbmanager-> output data retrieved");
// data output values
LinkedHashMap<String, String> mapValues = new LinkedHashMap<String, String>();
// data output keys
LinkedHashMap<String, String> mapKeys = new LinkedHashMap<String, String>();
mapValues = outputData.getMapValues();
mapKeys = outputData.getmapKeys();
for (int i = 0; i < mapValues.size(); i++) {
Result row = new Result(mapKeys.get(String.valueOf(i)),
mapValues.get(String.valueOf(i)));
output.add(row);
}
String name = "SmartSampling" + "_" + tab;
String fileName = storeResultIntoCSVFile(output, name);
HttpServletRequest request = this.getThreadLocalRequest();
String applicationPath = request.getContextPath();
// logger.info("dbmanager-> Application Path: " +
// applicationPath);
String partialPathFile = applicationPath
+ "/computationResult/" + fileName;
result = new SamplingResultWithFileFromServlet(output,
partialPathFile);
// put data in cache
net.sf.ehcache.Element dataToCache = new net.sf.ehcache.Element(
key, result);
insertDataIntoCache(dataToCache);
for (int i = 0; i < mapValues.size(); i++) {
Result row = new Result(mapKeys.get(String.valueOf(i)),
mapValues.get(String.valueOf(i)));
output.add(row);
}
String name = "SmartSampling" + "_" + tab;
String fileName = storeResultIntoCSVFile(output, name);
HttpServletRequest request = this.getThreadLocalRequest();
String applicationPath = request.getContextPath();
// logger.info("dbmanager-> Application Path: " + applicationPath);
String partialPathFile = applicationPath + "/computationResult/"
+ fileName;
SamplingResultWithFileFromServlet obj = new SamplingResultWithFileFromServlet(
output, partialPathFile);
return obj;
return result;
} catch (Exception e) {
logger.error("dbmanager-> ", e);
@ -1915,7 +2009,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
} catch (Exception e) {
logger.info("dbmanager-> startComputation: the job submit has failed!");
// e.printStackTrace();
// logger.error("dbmanager-> ", e);
// logger.error("dbmanager-> ", e);
throw e;
}
}
@ -1994,7 +2088,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
StatisticalManagerException e = new StatisticalManagerException(
smResource.description());
// e.printStackTrace();
// logger.error("dbmanager-> ", e);
// logger.error("dbmanager-> ", e);
throw e;
}
}
@ -2289,15 +2383,15 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
}
private synchronized void refreshCache(String key) throws Exception {
// try {
employeeCache.remove(key);
// } catch (Exception e) {
// TODO: handle exception
// logger.error("dbmanager-> ", e);
// throw new Exception("Failure to clear the cache. " + e);
// throw new Exception(
// "Error in server while loading data. Exception: " + e);
// }
// try {
employeeCache.remove(key);
// } catch (Exception e) {
// TODO: handle exception
// logger.error("dbmanager-> ", e);
// throw new Exception("Failure to clear the cache. " + e);
// throw new Exception(
// "Error in server while loading data. Exception: " + e);
// }
}
private String storeResultIntoCSVFile(List<Result> result, String n)
@ -2348,4 +2442,12 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
return SessionUtil.isSessionExpired(this.getThreadLocalRequest()
.getSession());
}
private String parseQuery(String query) {
String queryParsed;
queryParsed = query.trim();
queryParsed = queryParsed.replaceAll(" +", " ");
return queryParsed;
}
}