-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:
Loredana Liccardo 2014-08-01 16:11:36 +00:00
parent 9c21766b70
commit e5274527bf
7 changed files with 540 additions and 326 deletions

View File

@ -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;
}

View File

@ -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);
@ -43,5 +43,7 @@ public interface GWTdbManagerServiceAsync {
void LoadTables(PagingLoadConfig config,
LinkedHashMap<String, String> dataInput, boolean SearchTable,
String keyword, AsyncCallback<PagingLoadResult<Result>> callback);
void removeComputation(String uidSubmitQuery,
AsyncCallback<Boolean> callback);
}

View File

@ -792,6 +792,12 @@ public class GxtBorderLayoutPanel extends ContentPanel {
final Dialog form = dialogList.get(dialogID);
// 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: "
@ -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());
@ -903,11 +919,11 @@ public class GxtBorderLayoutPanel extends ContentPanel {
// convertedQuery = result.get(1);
}
// get the attributes list for the result table
getListAttributes(result.get(0).getValue());
// remove the header in order to parse only the result
result.remove(0);
// get the attributes list for the result table
getListAttributes(result.get(0).getValue());
// remove the header in order to parse only the result
result.remove(0);
// parse the result in order to obtain a table
boolean submitQueryEventManaged = true;
parseResult(result, form, dialogID,

View File

@ -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,11 +250,7 @@ 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,
dialogID);
@ -265,8 +270,40 @@ public class GxtToolbarFunctionality {
rootLogger.log(Level.INFO,
"button Cancel event");
//remove computation
// 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();
}
});
@ -435,16 +472,26 @@ public class GxtToolbarFunctionality {
SubmitQueryData data = form.getSubmitQueryData();
// data = form.getSubmitQueryData();
String query = data.getQuery();
if ((query == null) || (query.equals(""))) {
MessageBox.alert("Warning", "Query field null", null);
} 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
eventBus.fireEvent(new SubmitQueryEvent(dialogID));
}
@ -466,6 +513,10 @@ public class GxtToolbarFunctionality {
public LinkedHashMap<Integer, SubmitQueryData> getSubmitQueryDataList() {
return submitQueryDataList;
}
public LinkedHashMap<Integer, String> getUIDSubmitQueryList() {
return uidSubmitQueryList;
}
// public Integer getDialogID() {
// return new Integer(ID);

View File

@ -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);
}
}

View File

@ -59,18 +59,20 @@ import org.apache.log4j.Logger;
public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
GWTdbManagerService {
// // the result generated in the LoadTables method
// private List<Result> result = null;
// // the result generated in the LoadTables method
// private List<Result> result = null;
// information about a database
// private String currentDB = "";
// private String previousDB = "";
// private String currentDB = "";
// private String previousDB = "";
// information about a schema
// private String currentSchema = "";
// private String previousSchema = "";
//Hashmap that contains computationId
// HashMap<UUID, String> computationIDMap = new HashMap<UUID, String>();
// private String currentSchema = "";
// private String previousSchema = "";
// //Hashmap that contains computationId with a uid key
// HashMap<String, String> computationIDMap = new HashMap<String, String>();
String operation = "";
// logger
private static Logger logger = Logger
.getLogger(GWTdbManagerServiceImpl.class);
@ -78,37 +80,41 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
public GWTdbManagerServiceImpl() {
}
private void initVariables(){
ASLSession session = WsUtil.getAslSession(this.getThreadLocalRequest().getSession());
private void initVariables() {
ASLSession session = WsUtil.getAslSession(this.getThreadLocalRequest()
.getSession());
// the result generated in the LoadTables method
List<Result> result = new ArrayList<Result>();
session.setAttribute("TablesResult", result);
// information about a database
String currentDB = "";
session.setAttribute("currentDB", currentDB);
String previousDB = "";
session.setAttribute("previousDB", previousDB);
// information about a schema
String currentSchema = "";
session.setAttribute("currentSchema", currentSchema);
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);
}
// to get resources from IS
@Override
public List<FileModel> getResource() throws Exception {
//initialize variables with application startup
// initialize variables with application startup
initVariables();
// data input
// data input
List<Parameter> inputParameters = new ArrayList<Parameter>();
// data output
List<FileModel> outputParameters = new ArrayList<FileModel>();
@ -237,8 +243,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
@Override
public List<FileModel> getDBSchema(LinkedHashMap<String, String> dataInput)
throws Exception {
// data input
List<Parameter> inputParameters = new ArrayList<Parameter>();
// data output
@ -382,17 +387,19 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
public PagingLoadResult<Result> LoadTables(PagingLoadConfig config,
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 = "";
currentDB = dataInput.get("DatabaseName");
String previousDB = (String) session.getAttribute("previousDB");
if (!currentDB.equals(previousDB)) {
// result = null;
// result = null;
result = new ArrayList<Result>();
System.gc();
}
@ -405,7 +412,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
currentSchema = dataInput.get("SchemaName");
String previousSchema = (String) session.getAttribute("previousSchema");
if (!currentSchema.equals(previousSchema)) {
// result = null;
// result = null;
result = new ArrayList<Result>();
System.gc();
}
@ -414,9 +421,9 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
session.setAttribute("previousSchema", previousSchema);
// get tables
// if (result == null)
// result = getTables(dataInput);
if (result.size()==0)
// if (result == null)
// result = getTables(dataInput);
if (result.size() == 0)
result = getTables(dataInput);
// Create a sublist and add data to list according
@ -470,278 +477,291 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
loadResult = new BasePagingLoadResult<Result>(sublist,
config.getOffset(), totalNumber);
session.setAttribute("TablesResult", result);
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 {
logger.info("Dialect used for smart correction: " + language);
// data input
List<Parameter> inputParameters = new ArrayList<Parameter>();
// data output
List<Result> output = new ArrayList<Result>();
// get list of algorithms
List<String> algorithms = new ArrayList<String>();
algorithms = getDatabaseManagerAlgorithms();
// get algorithmId
String algorithmId = null;
for (int i = 0; i < algorithms.size(); i++) {
if (algorithms.get(i).equals("SUBMITQUERY")) {
algorithmId = algorithms.get(i);
// print check
// logger.info("algorithmId: " + algorithmId);
}
}
// get input parameters of the algorithm
inputParameters = getParameters(algorithmId);
if (inputParameters.size() != 0) {
// print check
logger.info("algorithm input parameters retrieved");
}
// print check
// for (int i = 0; i < inputParameters.size(); i++) {
// logger.info(inputParameters.get(i).getName());
// }
// print check
logger.info("ResourceName: " + dataDB.get("ResourceName"));
logger.info("DatabaseName: " + dataDB.get("DatabaseName"));
logger.info("Query: " + query);
logger.info("SmartCorrections check: " + smartCorrectionQuery);
inputParameters.get(0).setValue(dataDB.get("ResourceName"));
inputParameters.get(1).setValue(dataDB.get("DatabaseName"));
inputParameters.get(2).setValue(String.valueOf(valueReadOnlyQuery));
inputParameters.get(3).setValue(String.valueOf(smartCorrectionQuery));
inputParameters.get(4).setValue(language);
inputParameters.get(5).setValue(query);
// create data structure
ComputationOutput outputData = new ComputationOutput();
// computation id
String computationId = startComputation(algorithmId, inputParameters,
outputData);
// computationIDMap.put(id, computationId);
// 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);
}
return output;
}
// to submit a query
@Override
public List<Result> submitQuery(LinkedHashMap<String, String> dataDB,
String query, boolean valueReadOnlyQuery,
boolean smartCorrectionQuery, String language, String UID)
throws Exception {
// // to submit a query
// public String startSubmitQueryComputation(
// LinkedHashMap<String, String> dataDB, String query,
// boolean valueReadOnlyQuery, boolean smartCorrectionQuery,
// String language) {
//
// logger.info("Dialect used for smart correction: " + language);
//
// // data input
// List<Parameter> inputParameters = new ArrayList<Parameter>();
// // data output
// List<Result> output = new ArrayList<Result>();
//
// // get list of algorithms
// List<String> algorithms = new ArrayList<String>();
// algorithms = getDatabaseManagerAlgorithms();
//
// // get algorithmId
// String algorithmId = null;
//
// for (int i = 0; i < algorithms.size(); i++) {
// if (algorithms.get(i).equals("SUBMITQUERY")) {
// algorithmId = algorithms.get(i);
//
// // print check
// // logger.info("algorithmId: " + algorithmId);
// }
// }
//
// // get input parameters of the algorithm
// inputParameters = getParameters(algorithmId);
//
// if (inputParameters.size() != 0) {
// // print check
// logger.info("algorithm input parameters retrieved");
// }
//
// // print check
// // for (int i = 0; i < inputParameters.size(); i++) {
// // logger.info(inputParameters.get(i).getName());
// // }
//
// // print check
// logger.info("ResourceName: " + dataDB.get("ResourceName"));
// logger.info("DatabaseName: " + dataDB.get("DatabaseName"));
// logger.info("Query: " + query);
// logger.info("SmartCorrections check: " + smartCorrectionQuery);
//
// inputParameters.get(0).setValue(dataDB.get("ResourceName"));
// inputParameters.get(1).setValue(dataDB.get("DatabaseName"));
// inputParameters.get(2).setValue(String.valueOf(valueReadOnlyQuery));
// inputParameters.get(3).setValue(String.valueOf(smartCorrectionQuery));
// inputParameters.get(4).setValue(language);
// inputParameters.get(5).setValue(query);
//
// // // create data structure
// // ComputationOutput outputData = new ComputationOutput();
//
// // get computation id
//
// SMComputationConfig config = new SMComputationConfig();
// SMInputEntry[] list = new SMInputEntry[inputParameters.size()];
// int i = 0;
//
// for (Parameter p : inputParameters)
// list[i++] = new SMInputEntry(p.getName(), p.getValue());
// config.parameters(new SMEntries(list));
// config.algorithm(algorithmId);
//
// // create a computation request
// SMComputationRequest request = new SMComputationRequest();
// request.user(getUsername());
// request.config(config);
//
// // execute computation
// StatisticalManagerFactory factory = getFactory();
// String computationId = factory.executeComputation(request);
//
// return computationId;
// }
logger.info("Dialect used for smart correction: " + language);
// public float startCheckSubmitQueryComputation(String computationId) {
//
// String scope = getScope();
// String user = getUsername();
//
// ScopeProvider.instance.set(scope);
//
// StatisticalManagerFactory factory = StatisticalManagerDSL
// .createStateful().build();
//
// SMComputation computation = factory.getComputation(computationId);
//
// SMOperationStatus status = SMOperationStatus.values()[computation
// .operationStatus()];
//
// float percentage = 0;
//
// if (status == SMOperationStatus.RUNNING) {
//
// // logger.info("RUNNING");
// SMOperationInfo infos = factory.getComputationInfo(computationId,
// user);
// // percentage = Float.parseFloat(infos.percentage());
// // logger.info("Percentage:" +
// // percentage);
// // computation = factory.getComputation(computationId);
//
// status = SMOperationStatus.values()[computation.operationStatus()];
// } else if ((status == SMOperationStatus.COMPLETED)
// || (status == SMOperationStatus.FAILED)) {
//
// // logger.info("COMPLETED OR FAILED");
//
// SMAbstractResource abstractResource = computation
// .abstractResource();
// SMResource smResource = abstractResource.resource();
// int resourceTypeIndex = smResource.resourceType();
// SMResourceType smResType = SMResourceType.values()[resourceTypeIndex];
//
// // displayOutput(smResource, smResType, outputData);
//
// // print check
// // logger.info("SM resource Name: " + smResource.name());
// // logger.info("SM resource Name: " + smResource.name());
// // logger.info("SM resource ID: " + smResource.resourceId());
// // logger.info("SM resource ID: " + smResource.resourceId());
// // logger.info("SM resource Description: " +
// // smResource.description());
//
// percentage = 100;
// }
// return percentage;
//
// }
// data input
List<Parameter> inputParameters = new ArrayList<Parameter>();
// data output
// List<Result> output = new ArrayList<Result>();
List<Result> output = null;
// public List<Result> getSubmitQueryOutput(String computationId)
// throws Exception {
//
// String scope = getScope();
//
// ScopeProvider.instance.set(scope);
//
// StatisticalManagerFactory factory = StatisticalManagerDSL
// .createStateful().build();
//
// SMComputation computation = factory.getComputation(computationId);
//
// SMAbstractResource abstractResource = computation.abstractResource();
// SMResource smResource = abstractResource.resource();
// int resourceTypeIndex = smResource.resourceType();
// SMResourceType smResType = SMResourceType.values()[resourceTypeIndex];
//
// // create data structure
// ComputationOutput outputData = new ComputationOutput();
//
// displayOutput(smResource, smResType, outputData);
//
// // print check on retrieving data
// logger.info("output data retrieved");
//
// // data output
// List<Result> output = new ArrayList<Result>();
//
// // 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);
// }
//
// return output;
// }
// get list of algorithms
List<String> algorithms = new ArrayList<String>();
algorithms = getDatabaseManagerAlgorithms();
// get algorithmId
String algorithmId = null;
for (int i = 0; i < algorithms.size(); i++) {
if (algorithms.get(i).equals("SUBMITQUERY")) {
algorithmId = algorithms.get(i);
// print check
// logger.info("algorithmId: " + algorithmId);
}
}
// get input parameters of the algorithm
inputParameters = getParameters(algorithmId);
if (inputParameters.size() != 0) {
// print check
logger.info("algorithm input parameters retrieved");
}
// print check
// for (int i = 0; i < inputParameters.size(); i++) {
// logger.info(inputParameters.get(i).getName());
// }
// print check
logger.info("ResourceName: " + dataDB.get("ResourceName"));
logger.info("DatabaseName: " + dataDB.get("DatabaseName"));
logger.info("Query: " + query);
logger.info("SmartCorrections check: " + smartCorrectionQuery);
inputParameters.get(0).setValue(dataDB.get("ResourceName"));
inputParameters.get(1).setValue(dataDB.get("DatabaseName"));
inputParameters.get(2).setValue(String.valueOf(valueReadOnlyQuery));
inputParameters.get(3).setValue(String.valueOf(smartCorrectionQuery));
inputParameters.get(4).setValue(language);
inputParameters.get(5).setValue(query);
// create data structure
ComputationOutput outputData = new ComputationOutput();
try {
// computation id
String computationId = startComputation(algorithmId,
inputParameters, outputData, UID);
// computationIDMap.put(id, computationId);
// 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();
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;
}
// // to submit a query
// public String startSubmitQueryComputation(
// LinkedHashMap<String, String> dataDB, String query,
// boolean valueReadOnlyQuery, boolean smartCorrectionQuery,
// String language) {
//
// logger.info("Dialect used for smart correction: " + language);
//
// // data input
// List<Parameter> inputParameters = new ArrayList<Parameter>();
// // data output
// List<Result> output = new ArrayList<Result>();
//
// // get list of algorithms
// List<String> algorithms = new ArrayList<String>();
// algorithms = getDatabaseManagerAlgorithms();
//
// // get algorithmId
// String algorithmId = null;
//
// for (int i = 0; i < algorithms.size(); i++) {
// if (algorithms.get(i).equals("SUBMITQUERY")) {
// algorithmId = algorithms.get(i);
//
// // print check
// // logger.info("algorithmId: " + algorithmId);
// }
// }
//
// // get input parameters of the algorithm
// inputParameters = getParameters(algorithmId);
//
// if (inputParameters.size() != 0) {
// // print check
// logger.info("algorithm input parameters retrieved");
// }
//
// // print check
// // for (int i = 0; i < inputParameters.size(); i++) {
// // logger.info(inputParameters.get(i).getName());
// // }
//
// // print check
// logger.info("ResourceName: " + dataDB.get("ResourceName"));
// logger.info("DatabaseName: " + dataDB.get("DatabaseName"));
// logger.info("Query: " + query);
// logger.info("SmartCorrections check: " + smartCorrectionQuery);
//
// inputParameters.get(0).setValue(dataDB.get("ResourceName"));
// inputParameters.get(1).setValue(dataDB.get("DatabaseName"));
// inputParameters.get(2).setValue(String.valueOf(valueReadOnlyQuery));
// inputParameters.get(3).setValue(String.valueOf(smartCorrectionQuery));
// inputParameters.get(4).setValue(language);
// inputParameters.get(5).setValue(query);
//
// // // create data structure
// // ComputationOutput outputData = new ComputationOutput();
//
// // get computation id
//
// SMComputationConfig config = new SMComputationConfig();
// SMInputEntry[] list = new SMInputEntry[inputParameters.size()];
// int i = 0;
//
// for (Parameter p : inputParameters)
// list[i++] = new SMInputEntry(p.getName(), p.getValue());
// config.parameters(new SMEntries(list));
// config.algorithm(algorithmId);
//
// // create a computation request
// SMComputationRequest request = new SMComputationRequest();
// request.user(getUsername());
// request.config(config);
//
// // execute computation
// StatisticalManagerFactory factory = getFactory();
// String computationId = factory.executeComputation(request);
//
// return computationId;
// }
// public float startCheckSubmitQueryComputation(String computationId) {
//
// String scope = getScope();
// String user = getUsername();
//
// ScopeProvider.instance.set(scope);
//
// StatisticalManagerFactory factory = StatisticalManagerDSL
// .createStateful().build();
//
// SMComputation computation = factory.getComputation(computationId);
//
// SMOperationStatus status = SMOperationStatus.values()[computation
// .operationStatus()];
//
// float percentage = 0;
//
// if (status == SMOperationStatus.RUNNING) {
//
// // logger.info("RUNNING");
// SMOperationInfo infos = factory.getComputationInfo(computationId,
// user);
// // percentage = Float.parseFloat(infos.percentage());
// // logger.info("Percentage:" +
// // percentage);
// // computation = factory.getComputation(computationId);
//
// status = SMOperationStatus.values()[computation.operationStatus()];
// } else if ((status == SMOperationStatus.COMPLETED)
// || (status == SMOperationStatus.FAILED)) {
//
// // logger.info("COMPLETED OR FAILED");
//
// SMAbstractResource abstractResource = computation
// .abstractResource();
// SMResource smResource = abstractResource.resource();
// int resourceTypeIndex = smResource.resourceType();
// SMResourceType smResType = SMResourceType.values()[resourceTypeIndex];
//
// // displayOutput(smResource, smResType, outputData);
//
// // print check
// // logger.info("SM resource Name: " + smResource.name());
// // logger.info("SM resource Name: " + smResource.name());
// // logger.info("SM resource ID: " + smResource.resourceId());
// // logger.info("SM resource ID: " + smResource.resourceId());
// // logger.info("SM resource Description: " +
// // smResource.description());
//
// percentage = 100;
// }
// return percentage;
//
// }
// public List<Result> getSubmitQueryOutput(String computationId)
// throws Exception {
//
// String scope = getScope();
//
// ScopeProvider.instance.set(scope);
//
// StatisticalManagerFactory factory = StatisticalManagerDSL
// .createStateful().build();
//
// SMComputation computation = factory.getComputation(computationId);
//
// SMAbstractResource abstractResource = computation.abstractResource();
// SMResource smResource = abstractResource.resource();
// int resourceTypeIndex = smResource.resourceType();
// SMResourceType smResType = SMResourceType.values()[resourceTypeIndex];
//
// // create data structure
// ComputationOutput outputData = new ComputationOutput();
//
// displayOutput(smResource, smResType, outputData);
//
// // print check on retrieving data
// logger.info("output data retrieved");
//
// // data output
// List<Result> output = new ArrayList<Result>();
//
// // 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);
// }
//
// return output;
// }
@Override
public List<Result> sample(LinkedHashMap<String, String> dataInput)
@ -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 {
StatisticalManagerFactory factory = getFactory();
factory.removeComputation(computationId);
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));
}
}

View File

@ -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>