-cancel of a submit query managed removing the computation from the statistical and closing the db connection.
- class UIDGenerator added. git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/databases-manager-portlet@99195 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
9c21766b70
commit
e5274527bf
|
@ -26,7 +26,7 @@ public interface GWTdbManagerService extends RemoteService {
|
|||
|
||||
List<Result> submitQuery(LinkedHashMap<String, String> dataDB,
|
||||
String query, boolean valueReadOnlyQuery,
|
||||
boolean smartCorrectionQuery, String language) throws Exception;
|
||||
boolean smartCorrectionQuery, String language, String UID) throws Exception;
|
||||
|
||||
List<Result> sample(LinkedHashMap<String, String> dataInput)
|
||||
throws Exception;
|
||||
|
@ -47,6 +47,8 @@ public interface GWTdbManagerService extends RemoteService {
|
|||
LinkedHashMap<String, String> dataInput, boolean SearchTable,
|
||||
String keyword) throws Exception;
|
||||
|
||||
Boolean removeComputation(String uidSubmitQuery) throws Exception;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ public interface GWTdbManagerServiceAsync {
|
|||
|
||||
void submitQuery(LinkedHashMap<String, String> dataDB, String query,
|
||||
boolean valueReadOnlyQuery, boolean smartCorrectionQuery,
|
||||
String language, AsyncCallback<List<Result>> callback);
|
||||
String language, String UID, AsyncCallback<List<Result>> callback);
|
||||
|
||||
void parseCVSString(List<Result> result, List<String> attrNames,
|
||||
AsyncCallback<List<Row>> callback);
|
||||
|
@ -44,4 +44,6 @@ public interface GWTdbManagerServiceAsync {
|
|||
LinkedHashMap<String, String> dataInput, boolean SearchTable,
|
||||
String keyword, AsyncCallback<PagingLoadResult<Result>> callback);
|
||||
|
||||
void removeComputation(String uidSubmitQuery,
|
||||
AsyncCallback<Boolean> callback);
|
||||
}
|
||||
|
|
|
@ -793,6 +793,12 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
// get the data form related to the ID
|
||||
final SubmitQueryData dataQuery = submitQueryDataList.get(dialogID);
|
||||
|
||||
|
||||
//get the UID related to submitQuery operation
|
||||
LinkedHashMap<Integer, String> uidSubmitQueryList = toolbar.getUIDSubmitQueryList();
|
||||
String UID = uidSubmitQueryList.get(dialogID);
|
||||
|
||||
|
||||
// rootLogger.log(Level.INFO, "query: "+ dataQuery.getQuery() +
|
||||
// "submitquery->dialogID: "
|
||||
// + dialogID);
|
||||
|
@ -858,7 +864,7 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
|
||||
// remote rpc
|
||||
RPCservice.submitQuery(dataForSubmitQuery, dataQuery.getQuery(), true,
|
||||
dataQuery.getSmartCorrection(), language,
|
||||
dataQuery.getSmartCorrection(), language, UID,
|
||||
new AsyncCallback<List<Result>>() {
|
||||
|
||||
// TO REMOVE data "true" as input if you manage the
|
||||
|
@ -889,6 +895,16 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
|||
|
||||
@Override
|
||||
public void onSuccess(List<Result> result) {
|
||||
|
||||
if (result == null){
|
||||
|
||||
if (form.getBody().isMasked())
|
||||
form.getBody().unmask();
|
||||
|
||||
rootLogger.log(Level.SEVERE, "No results have been returned");
|
||||
return;
|
||||
}
|
||||
|
||||
rootLogger.log(Level.SEVERE, "SUCCESS RPC submitQuery");
|
||||
rootLogger.log(Level.SEVERE,
|
||||
"output size: " + result.size());
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
package org.gcube.portlets.user.databasesmanager.client.toolbar;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.gcube.portlets.user.databasesmanager.client.GWTdbManagerServiceAsync;
|
||||
import org.gcube.portlets.user.databasesmanager.client.datamodel.Result;
|
||||
import org.gcube.portlets.user.databasesmanager.client.datamodel.SubmitQueryData;
|
||||
import org.gcube.portlets.user.databasesmanager.client.events.LoadTablesEvent;
|
||||
import org.gcube.portlets.user.databasesmanager.client.events.RandomSamplingEvent;
|
||||
|
@ -17,6 +19,8 @@ import org.gcube.portlets.user.databasesmanager.client.events.SubmitQueryEvent;
|
|||
import org.gcube.portlets.user.databasesmanager.client.events.interfaces.SelectedTableEventHandler;
|
||||
import org.gcube.portlets.user.databasesmanager.client.form.GxtFormSubmitQuery;
|
||||
import org.gcube.portlets.user.databasesmanager.client.utils.ConstantsPortlet;
|
||||
import org.gcube.portlets.user.databasesmanager.client.utils.UIDGenerator;
|
||||
|
||||
import com.extjs.gxt.ui.client.Style.ButtonArrowAlign;
|
||||
import com.extjs.gxt.ui.client.Style.ButtonScale;
|
||||
import com.extjs.gxt.ui.client.event.ButtonEvent;
|
||||
|
@ -31,6 +35,7 @@ import com.extjs.gxt.ui.client.widget.layout.FitLayout;
|
|||
import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem;
|
||||
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
|
||||
import com.google.gwt.event.shared.HandlerManager;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
|
||||
//toolbar to contain buttons
|
||||
public class GxtToolbarFunctionality {
|
||||
|
@ -50,7 +55,9 @@ public class GxtToolbarFunctionality {
|
|||
// dialog list. Each dialog contains a form
|
||||
private LinkedHashMap<Integer, Dialog> dialogList = new LinkedHashMap<Integer, Dialog>();
|
||||
private LinkedHashMap<Integer, SubmitQueryData> submitQueryDataList = new LinkedHashMap<Integer, SubmitQueryData>();
|
||||
private static int ID = 0; // ID asscociated to a dialog form
|
||||
private static int ID = 0; // ID associated to a dialog form
|
||||
//uid list related to submit query operations
|
||||
private LinkedHashMap<Integer, String> uidSubmitQueryList = new LinkedHashMap<Integer, String>();
|
||||
// GWT logger
|
||||
private static Logger rootLogger = Logger
|
||||
.getLogger("GxtToolbarFunctionality");
|
||||
|
@ -208,6 +215,8 @@ public class GxtToolbarFunctionality {
|
|||
|
||||
// form to submit a query
|
||||
final GxtFormSubmitQuery form = new GxtFormSubmitQuery();
|
||||
|
||||
|
||||
dialog.add(form);
|
||||
dialog.show();
|
||||
|
||||
|
@ -241,10 +250,6 @@ public class GxtToolbarFunctionality {
|
|||
|
||||
@Override
|
||||
public void componentSelected(ButtonEvent ce) {
|
||||
//start computation and get id
|
||||
|
||||
//generate a UUID for this request
|
||||
// UUID id = UUID.randomUUID();
|
||||
|
||||
// recover info from dialog
|
||||
setInfoOnSubmitQuery(form, dialog,
|
||||
|
@ -265,7 +270,39 @@ public class GxtToolbarFunctionality {
|
|||
rootLogger.log(Level.INFO,
|
||||
"button Cancel event");
|
||||
|
||||
|
||||
// remove computation
|
||||
RPCservice.removeComputation(
|
||||
uidSubmitQueryList
|
||||
.get(dialogID),
|
||||
new AsyncCallback<Boolean>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(
|
||||
Boolean result) {
|
||||
rootLogger
|
||||
.log(Level.SEVERE,
|
||||
"SUCCESS RPC removeComputation");
|
||||
if (result
|
||||
.booleanValue() == true) {
|
||||
|
||||
rootLogger
|
||||
.log(Level.INFO,
|
||||
"computation removed with uid: "
|
||||
+ uidSubmitQueryList
|
||||
.get(dialogID));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(
|
||||
Throwable caught) {
|
||||
rootLogger
|
||||
.log(Level.SEVERE,
|
||||
"FAILURE RPC removeComputation");
|
||||
}
|
||||
});
|
||||
|
||||
dialog.hide();
|
||||
}
|
||||
|
@ -443,6 +480,16 @@ public class GxtToolbarFunctionality {
|
|||
} else {
|
||||
dialogList.put(new Integer(dialogID), SubmtQueryDialog);
|
||||
submitQueryDataList.put(new Integer(dialogID), data);
|
||||
|
||||
|
||||
//generate a UID for this request
|
||||
UIDGenerator generator = new UIDGenerator();
|
||||
String uidSubmitQuery = generator.get();
|
||||
//add uid for the submit query operation
|
||||
uidSubmitQueryList.put(new Integer(dialogID), uidSubmitQuery);
|
||||
|
||||
// System.out.println("UID: " + uidSubmitQuery);
|
||||
|
||||
SubmtQueryDialog.getBody().mask("Loading", "x-mask-loading");
|
||||
|
||||
// fire event
|
||||
|
@ -467,6 +514,10 @@ public class GxtToolbarFunctionality {
|
|||
return submitQueryDataList;
|
||||
}
|
||||
|
||||
public LinkedHashMap<Integer, String> getUIDSubmitQueryList() {
|
||||
return uidSubmitQueryList;
|
||||
}
|
||||
|
||||
// public Integer getDialogID() {
|
||||
// return new Integer(ID);
|
||||
// }
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
package org.gcube.portlets.user.databasesmanager.client.utils;
|
||||
|
||||
public class UIDGenerator {
|
||||
private static final char[] CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
||||
.toCharArray();
|
||||
|
||||
/**
|
||||
* Generate a random uuid of the specified length. Example: uuid(15) returns
|
||||
* "VcydxgltxrVZSTV"
|
||||
*
|
||||
* @param len
|
||||
* the desired number of characters
|
||||
*/
|
||||
public static String get(int len) {
|
||||
return get(len, CHARS.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a random uuid of the specified length, and radix. Examples:
|
||||
* <ul>
|
||||
* <li>uuid(8, 2) returns "01001010" (8 character ID, base=2)
|
||||
* <li>uuid(8, 10) returns "47473046" (8 character ID, base=10)
|
||||
* <li>uuid(8, 16) returns "098F4D35" (8 character ID, base=16)
|
||||
* </ul>
|
||||
*
|
||||
* @param len
|
||||
* the desired number of characters
|
||||
* @param radix
|
||||
* the number of allowable values for each character (must be <=
|
||||
* 62)
|
||||
*/
|
||||
public static String get(int len, int radix) {
|
||||
if (radix > CHARS.length) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
char[] uuid = new char[len];
|
||||
// Compact form
|
||||
for (int i = 0; i < len; i++) {
|
||||
uuid[i] = CHARS[(int) (Math.random() * radix)];
|
||||
}
|
||||
return new String(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a RFC4122, version 4 ID. Example:
|
||||
* "92329D39-6F5C-4520-ABFC-AAB64544E172"
|
||||
*/
|
||||
public static String get() {
|
||||
char[] uuid = new char[36];
|
||||
int r;
|
||||
|
||||
// rfc4122 requires these characters
|
||||
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
|
||||
uuid[14] = '4';
|
||||
|
||||
// Fill in random data. At i==19 set the high bits of clock sequence as
|
||||
// per rfc4122, sec. 4.1.5
|
||||
for (int i = 0; i < 36; i++) {
|
||||
if (uuid[i] == 0) {
|
||||
r = (int) (Math.random() * 16);
|
||||
uuid[i] = CHARS[(i == 19) ? (r & 0x3) | 0x8 : r & 0xf];
|
||||
}
|
||||
}
|
||||
return new String(uuid);
|
||||
}
|
||||
}
|
||||
|
|
@ -68,8 +68,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
// private String currentSchema = "";
|
||||
// private String previousSchema = "";
|
||||
|
||||
//Hashmap that contains computationId
|
||||
// HashMap<UUID, String> computationIDMap = new HashMap<UUID, String>();
|
||||
// //Hashmap that contains computationId with a uid key
|
||||
// HashMap<String, String> computationIDMap = new HashMap<String, String>();
|
||||
|
||||
String operation = "";
|
||||
|
||||
// logger
|
||||
private static Logger logger = Logger
|
||||
|
@ -80,7 +82,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
}
|
||||
|
||||
private void initVariables() {
|
||||
ASLSession session = WsUtil.getAslSession(this.getThreadLocalRequest().getSession());
|
||||
ASLSession session = WsUtil.getAslSession(this.getThreadLocalRequest()
|
||||
.getSession());
|
||||
|
||||
// the result generated in the LoadTables method
|
||||
List<Result> result = new ArrayList<Result>();
|
||||
|
@ -98,6 +101,9 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
String previousSchema = "";
|
||||
session.setAttribute("previousSchema", previousSchema);
|
||||
|
||||
// Hashmap that contains computationId with a uid key
|
||||
HashMap<String, String> computationIDMap = new HashMap<String, String>();
|
||||
session.setAttribute("ComputationIDList", computationIDMap);
|
||||
|
||||
}
|
||||
|
||||
|
@ -238,7 +244,6 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
public List<FileModel> getDBSchema(LinkedHashMap<String, String> dataInput)
|
||||
throws Exception {
|
||||
|
||||
|
||||
// data input
|
||||
List<Parameter> inputParameters = new ArrayList<Parameter>();
|
||||
// data output
|
||||
|
@ -383,8 +388,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
LinkedHashMap<String, String> dataInput, boolean SearchTable,
|
||||
String keyword) throws Exception {
|
||||
|
||||
ASLSession session = WsUtil.getAslSession(this.getThreadLocalRequest().getSession());
|
||||
List<Result> result = (List<Result>) session.getAttribute("TablesResult");
|
||||
ASLSession session = WsUtil.getAslSession(this.getThreadLocalRequest()
|
||||
.getSession());
|
||||
List<Result> result = (List<Result>) session
|
||||
.getAttribute("TablesResult");
|
||||
|
||||
// check on a database
|
||||
String currentDB = "";
|
||||
|
@ -476,19 +483,20 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
return loadResult;
|
||||
}
|
||||
|
||||
|
||||
// to submit a query
|
||||
@Override
|
||||
public List<Result> submitQuery(LinkedHashMap<String, String> dataDB,
|
||||
String query, boolean valueReadOnlyQuery,
|
||||
boolean smartCorrectionQuery, String language) throws Exception {
|
||||
boolean smartCorrectionQuery, String language, String UID)
|
||||
throws Exception {
|
||||
|
||||
logger.info("Dialect used for smart correction: " + language);
|
||||
|
||||
// data input
|
||||
List<Parameter> inputParameters = new ArrayList<Parameter>();
|
||||
// data output
|
||||
List<Result> output = new ArrayList<Result>();
|
||||
// List<Result> output = new ArrayList<Result>();
|
||||
List<Result> output = null;
|
||||
|
||||
// get list of algorithms
|
||||
List<String> algorithms = new ArrayList<String>();
|
||||
|
@ -534,9 +542,12 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
|
||||
// create data structure
|
||||
ComputationOutput outputData = new ComputationOutput();
|
||||
|
||||
try {
|
||||
|
||||
// computation id
|
||||
String computationId = startComputation(algorithmId, inputParameters,
|
||||
outputData);
|
||||
String computationId = startComputation(algorithmId,
|
||||
inputParameters, outputData, UID);
|
||||
|
||||
// computationIDMap.put(id, computationId);
|
||||
|
||||
|
@ -544,20 +555,27 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
// logger.info("output data retrieved");
|
||||
|
||||
// data output values
|
||||
LinkedHashMap<String, String> mapValues = new LinkedHashMap<String,
|
||||
String>();
|
||||
LinkedHashMap<String, String> mapValues = new LinkedHashMap<String, String>();
|
||||
// data output keys
|
||||
LinkedHashMap<String, String> mapKeys = new LinkedHashMap<String,
|
||||
String>();
|
||||
LinkedHashMap<String, String> mapKeys = new LinkedHashMap<String, String>();
|
||||
|
||||
mapValues = outputData.getMapValues();
|
||||
mapKeys = outputData.getmapKeys();
|
||||
|
||||
if (mapValues.size() != 0) {
|
||||
output = new ArrayList<Result>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
// e.printStackTrace();
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
@ -727,9 +745,11 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
// List<Result> output = new ArrayList<Result>();
|
||||
//
|
||||
// // data output values
|
||||
// LinkedHashMap<String, String> mapValues = new LinkedHashMap<String, String>();
|
||||
// LinkedHashMap<String, String> mapValues = new LinkedHashMap<String,
|
||||
// String>();
|
||||
// // data output keys
|
||||
// LinkedHashMap<String, String> mapKeys = new LinkedHashMap<String, String>();
|
||||
// LinkedHashMap<String, String> mapKeys = new LinkedHashMap<String,
|
||||
// String>();
|
||||
//
|
||||
// mapValues = outputData.getMapValues();
|
||||
// mapKeys = outputData.getmapKeys();
|
||||
|
@ -1161,9 +1181,44 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
return params;
|
||||
}
|
||||
|
||||
private synchronized void updateJob(String jobID, String computationId) {
|
||||
if (jobID != null) {
|
||||
// add the computation in the map
|
||||
ASLSession session = WsUtil.getAslSession(this
|
||||
.getThreadLocalRequest().getSession());
|
||||
HashMap<String, String> computationIDMap = (HashMap<String, String>) session
|
||||
.getAttribute("ComputationIDList");
|
||||
computationIDMap.put(jobID, computationId);
|
||||
session.setAttribute("ComputationIDList", computationIDMap);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized String removeJob(String jobID) {
|
||||
if (jobID != null) {
|
||||
// add the computation in the map
|
||||
ASLSession session = WsUtil.getAslSession(this
|
||||
.getThreadLocalRequest().getSession());
|
||||
HashMap<String, String> computationIDMap = (HashMap<String, String>) session
|
||||
.getAttribute("ComputationIDList");
|
||||
String computationId = computationIDMap.get(jobID);
|
||||
if (computationId != null) {
|
||||
computationIDMap.remove(jobID);
|
||||
session.setAttribute("ComputationIDList", computationIDMap);
|
||||
return computationId;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String startComputation(String algorithmName,
|
||||
List<Parameter> parameters, ComputationOutput outputData)
|
||||
throws Exception {
|
||||
return startComputation(algorithmName, parameters, outputData, null);
|
||||
}
|
||||
|
||||
private String startComputation(String algorithmName,
|
||||
List<Parameter> parameters, ComputationOutput outputData,
|
||||
String jobID) throws Exception {
|
||||
|
||||
SMComputationConfig config = new SMComputationConfig();
|
||||
SMInputEntry[] list = new SMInputEntry[parameters.size()];
|
||||
|
@ -1187,13 +1242,19 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
String scope = getScope();
|
||||
String username = getUsername();
|
||||
|
||||
updateJob(jobID, computationId);
|
||||
logger.info("startComputation->The computation has started!");
|
||||
while (percentage < 100) {
|
||||
percentage = checkComputationStatus(scope, computationId,
|
||||
username, outputData);
|
||||
Thread.sleep(3000);
|
||||
}
|
||||
logger.info("startComputation->The computation has finished!");
|
||||
removeJob(jobID);
|
||||
|
||||
return computationId;
|
||||
} catch (Exception e) {
|
||||
logger.info("startComputation->The job submit has failed!");
|
||||
// e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
|
@ -1370,11 +1431,26 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
|
||||
}
|
||||
|
||||
public void removeComputation(String computationId) throws Exception {
|
||||
public Boolean removeComputation(String uidSubmitQuery) throws Exception {
|
||||
|
||||
// System.out.println("server UID: " + uidSubmitQuery);
|
||||
|
||||
String computationId = removeJob(uidSubmitQuery);
|
||||
if (computationId != null) {
|
||||
StatisticalManagerFactory factory = getFactory();
|
||||
try {
|
||||
factory.removeComputation(computationId);
|
||||
} catch (Exception e) {
|
||||
|
||||
e.printStackTrace();
|
||||
logger.info("Could not remove the computation ID "
|
||||
+ computationId + " corresponding to jobID "
|
||||
+ uidSubmitQuery);
|
||||
logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return (new Boolean(true));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
<inherits name='com.extjs.gxt.ui.GXT' />
|
||||
|
||||
<!-- <inherits name="com.google.gwt.logging.Logging"/> -->
|
||||
<inherits name="com.google.gwt.logging.Logging"/>
|
||||
|
||||
<!-- We need the JUnit module in the main module, -->
|
||||
<!-- otherwise eclipse complains (Google plugin bug?) -->
|
||||
|
@ -27,8 +27,8 @@
|
|||
<source path='client' />
|
||||
<source path='shared' />
|
||||
|
||||
<!-- <set-property name="gwt.logging.logLevel" value="SEVERE"/> -->
|
||||
<!-- <set-property name="gwt.logging.logLevel" value="INFO"/> -->
|
||||
<!-- <set-property name="gwt.logging.enabled" value="TRUE"/> -->
|
||||
<set-property name="gwt.logging.logLevel" value="SEVERE"/>
|
||||
<set-property name="gwt.logging.logLevel" value="INFO"/>
|
||||
<set-property name="gwt.logging.enabled" value="TRUE"/>
|
||||
|
||||
</module>
|
||||
|
|
Loading…
Reference in New Issue