diff --git a/CHANGELOG.md b/CHANGELOG.md index ae17042..cf6ac08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,13 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm # Changelog for "dataminer" +## [v1.8.0-SNAPSHOT] - 2022-01-24 + +### Fixes + +- Fixed max computations support [#22700] + + ## [v1.7.1] - 2021-05-24 ### Fixes diff --git a/pom.xml b/pom.xml index e96f8d7..af68f4a 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ org.gcube.dataanalysis dataminer - 1.7.1 + 1.8.0-SNAPSHOT dataminer An e-Infrastructure service providing state-of-the art DataMining algorithms and ecological modelling approaches under the Web Processing Service (WPS) standard. diff --git a/src/main/java/org/gcube/dataanalysis/wps/statisticalmanager/synchserver/mapping/AbstractEcologicalEngineMapper.java b/src/main/java/org/gcube/dataanalysis/wps/statisticalmanager/synchserver/mapping/AbstractEcologicalEngineMapper.java index 0652b3c..f8b08ac 100644 --- a/src/main/java/org/gcube/dataanalysis/wps/statisticalmanager/synchserver/mapping/AbstractEcologicalEngineMapper.java +++ b/src/main/java/org/gcube/dataanalysis/wps/statisticalmanager/synchserver/mapping/AbstractEcologicalEngineMapper.java @@ -50,6 +50,8 @@ import org.slf4j.LoggerFactory; public class AbstractEcologicalEngineMapper extends AbstractAnnotatedAlgorithm implements Observable, Cancellable { + private static final int COMPUTATION_WAIT_FOR_RUN_REQUEST = 20000; + /** * Deploying procedure: 1 - modify configuration files 2 - modify resource * file: resources/templates/setup.cfg 3 - generate classes with @@ -85,30 +87,41 @@ public class AbstractEcologicalEngineMapper extends AbstractAnnotatedAlgorithm i this.wpsExternalID = wpsExternalID; } - public static synchronized void addComputation(String session, String user) { + private static synchronized void addComputation(String session, String user) { runningcomputations.put(session, user); } - public static synchronized void removeComputation(String session) { + private static synchronized void removeComputation(String session) { runningcomputations.remove(session); } - public static synchronized int getRuningComputations() { + private static synchronized int getRuningComputations() { return runningcomputations.size(); } - public static synchronized String displayRunningComputations() { + private static synchronized String displayRunningComputations() { return runningcomputations.toString(); } - public void waitForResources() throws Exception { - while (getRuningComputations() > ConfigurationManager.getMaxComputations()) { - Thread.sleep(20000); + private void waitForResources(String computationSession, String username, String scope) throws Exception { + while (waitCondition(computationSession, username, scope)) { + Thread.sleep(COMPUTATION_WAIT_FOR_RUN_REQUEST); LOGGER.debug("Waiting for resources to be available: " + displayRunningComputations()); } } + private static synchronized boolean waitCondition(String computationSession, String username, String scope) { + if (getRuningComputations() >= ConfigurationManager.getMaxComputations()) { + return true; + } else { + // add the computation to the global list of computations + LOGGER.debug("Add computation to run: {}", computationSession); + addComputation(computationSession, username + ":" + scope); + return false; + } + } + // inner objects public AlgorithmConfiguration config; public InfrastructureDialoguer infrastructureDialoguer; @@ -366,11 +379,9 @@ public class AbstractEcologicalEngineMapper extends AbstractAnnotatedAlgorithm i config = configManager.getConfig(); LOGGER.info("Configured algorithm with session " + computationSession); time("Configuration"); - waitForResources(); + waitForResources(computationSession, configManager.getUsername(), configManager.getScope()); LOGGER.info("Running algorithm with session " + computationSession); time("Waiting time for resources to be free"); - // add the computation to the global list of computations - addComputation(computationSession, configManager.getUsername() + ":" + configManager.getScope()); String scope = configManager.getScope(); String username = configManager.getUsername(); @@ -502,8 +513,8 @@ public class AbstractEcologicalEngineMapper extends AbstractAnnotatedAlgorithm i throw e; } finally { LOGGER.debug("accounting algorithm"); - if(operationResult==null){ - operationResult=OperationResult.FAILED; + if (operationResult == null) { + operationResult = OperationResult.FAILED; } accountAlgorithmExecution(startTimeLong, System.currentTimeMillis(), operationResult); LOGGER.debug("Deleting Input Tables");