git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-analysis/wps@151046 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
ab1032edf3
commit
8df850f693
|
@ -1,6 +1,5 @@
|
|||
package org.gcube.data.analysis.wps;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
@ -14,9 +13,8 @@ import javax.servlet.http.HttpServletRequest;
|
|||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.gcube.data.analysis.wps.processes.Processes;
|
||||
import org.n52.wps.commons.XMLUtil;
|
||||
import org.n52.wps.server.database.DatabaseFactory;
|
||||
import org.n52.wps.server.database.IDatabase;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -48,16 +46,16 @@ public class CancelComputation extends HttpServlet {
|
|||
// id of result to retrieve.
|
||||
String id = request.getParameter("id");
|
||||
|
||||
LOGGER.debug("CANCEL COMPUTATION -> RETRIEVING ID " + id);
|
||||
LOGGER.debug("CANCEL COMPUTATION -> RETRIEVING ID {}", id);
|
||||
if (StringUtils.isEmpty(id)) {
|
||||
errorResponse("id parameter missing", response);
|
||||
} else {
|
||||
LOGGER.debug("CANCEL COMPUTATION -> ID RETRIEVED " + id);
|
||||
LOGGER.debug("CANCEL COMPUTATION -> ID {} RETRIEVED ", id);
|
||||
if (!isIDValid(id)) {
|
||||
errorResponse("id parameter not valid", response);
|
||||
}
|
||||
LOGGER.debug("CANCEL COMPUTATION -> ID IS VALID " + id);
|
||||
IDatabase db = DatabaseFactory.getDatabase();
|
||||
LOGGER.debug("CANCEL COMPUTATION -> ID {} IS VALID ",id);
|
||||
/*IDatabase db = DatabaseFactory.getDatabase();
|
||||
long len = db.getContentLengthForStoreResponse(id);
|
||||
LOGGER.debug("CANCEL COMPUTATION -> INITIAL ID RESPONSE LENGTH " + len);
|
||||
|
||||
|
@ -78,8 +76,14 @@ public class CancelComputation extends HttpServlet {
|
|||
} catch (Exception e) {
|
||||
LOGGER.error("error in do get",e);
|
||||
} finally {
|
||||
}
|
||||
}*/
|
||||
if (Processes.getRunningProcesses().containsKey(id)){
|
||||
boolean cancelled = Processes.getRunningProcesses().get(id).cancel();
|
||||
if(!cancelled)
|
||||
LOGGER.debug("CANCEL COMPUTATION -> process with id {} already cancelled ", id);
|
||||
} else LOGGER.debug("CANCEL COMPUTATION -> no running process with id {} (probably it already finished) ", id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void errorResponse(String error, HttpServletResponse response) throws IOException {
|
||||
|
|
|
@ -598,6 +598,7 @@ public class ExecuteRequest extends Request implements IObserver {
|
|||
}
|
||||
if (algorithm instanceof AbstractEcologicalEngineMapper) {
|
||||
((AbstractEcologicalEngineMapper) algorithm).setWpsExternalID(wpsid);
|
||||
((AbstractEcologicalEngineMapper) algorithm).setObserver(GCubeObserver.getObserver());
|
||||
}
|
||||
|
||||
if (algorithm instanceof AbstractTransactionalAlgorithm) {
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package org.gcube.data.analysis.wps;
|
||||
|
||||
import org.gcube.data.analysis.wps.processes.Processes;
|
||||
import org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mapping.AbstractEcologicalEngineMapper;
|
||||
import org.gcube.dataanalysis.wps.statisticalmanager.synchserver.utils.Observable;
|
||||
import org.gcube.dataanalysis.wps.statisticalmanager.synchserver.utils.Observer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class GCubeObserver implements Observer{
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(GCubeObserver.class);
|
||||
|
||||
public static GCubeObserver getObserver(){
|
||||
return instance;
|
||||
}
|
||||
|
||||
private static GCubeObserver instance = new GCubeObserver();
|
||||
|
||||
private GCubeObserver(){}
|
||||
|
||||
@Override
|
||||
public void isFinished(Observable o) {
|
||||
AbstractEcologicalEngineMapper algorithm = (AbstractEcologicalEngineMapper)o;
|
||||
LOGGER.debug("computation with id {} finished",algorithm.wpsExternalID);
|
||||
Processes.getRunningProcesses().remove(algorithm.wpsExternalID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void isStarted(Observable o) {
|
||||
AbstractEcologicalEngineMapper algorithm = (AbstractEcologicalEngineMapper)o;
|
||||
LOGGER.debug("computation with id {} started",algorithm.wpsExternalID);
|
||||
Processes.getRunningProcesses().put(algorithm.wpsExternalID,algorithm);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -3,22 +3,15 @@ package org.gcube.data.analysis.wps.processes;
|
|||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import org.gcube.dataanalysis.wps.statisticalmanager.synchserver.utils.Cancellable;
|
||||
|
||||
public class Processes {
|
||||
|
||||
private Map<String, Cancellable> runningProcesses = Collections.synchronizedMap(new HashMap<String, Cancellable>());
|
||||
|
||||
private Map<String, Cancellable> cancelledProcesses = Collections.synchronizedMap(new WeakHashMap<String, Cancellable>());
|
||||
private static Map<String, Cancellable> runningProcesses = Collections.synchronizedMap(new HashMap<String, Cancellable>());
|
||||
|
||||
public Map<String, Cancellable> getRunningProcesses() {
|
||||
public static Map<String, Cancellable> getRunningProcesses() {
|
||||
return runningProcesses;
|
||||
}
|
||||
|
||||
public Map<String, Cancellable> getCancelledProcesses() {
|
||||
return cancelledProcesses;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ no. 654119), SoBigData (grant no. 654024);
|
|||
Version
|
||||
--------------------------------------------------
|
||||
|
||||
1.0.0-SNAPSHOT (${maven.build.timestamp})
|
||||
1.0.0-SNAPSHOT (2017-07-12)
|
||||
|
||||
Please see the file named "changelog.xml" in this directory for the release notes.
|
||||
|
||||
|
|
Loading…
Reference in New Issue