diff --git a/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/engine/iterations/handler/IterationsHandler.java b/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/engine/iterations/handler/IterationsHandler.java index a5c15f860..4e968ac2a 100644 --- a/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/engine/iterations/handler/IterationsHandler.java +++ b/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/engine/iterations/handler/IterationsHandler.java @@ -10,6 +10,7 @@ import madgik.exareme.master.engine.iterations.state.IterationsStateManager; import madgik.exareme.master.engine.iterations.state.IterationsStateManagerImpl; import madgik.exareme.master.engine.iterations.state.IterativeAlgorithmState; +import madgik.exareme.master.gateway.async.handler.HBP.Exceptions.BadUserInputException; import madgik.exareme.master.queryProcessor.HBP.AlgorithmProperties; import madgik.exareme.master.queryProcessor.HBP.Composer; import madgik.exareme.master.queryProcessor.HBP.Exceptions.ComposerException; @@ -65,7 +66,7 @@ public static IterationsHandler getInstance() { */ public IterativeAlgorithmState handleNewIterativeAlgorithmRequest( AdpDBManager adpDBManager, String algorithmKey, - AlgorithmProperties algorithmProperties, ContainerProxy[] usedContainerProxies) { + AlgorithmProperties algorithmProperties, ContainerProxy[] usedContainerProxies) throws BadUserInputException { // Generate the AdpDBClient for this iterative algorithm that will be used to execute all the phases' queries AdpDBClient adpDBClient; diff --git a/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HBP/Exceptions/BadUserInputException.java b/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HBP/Exceptions/BadUserInputException.java new file mode 100644 index 000000000..8f3b0b7cf --- /dev/null +++ b/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HBP/Exceptions/BadUserInputException.java @@ -0,0 +1,7 @@ +package madgik.exareme.master.gateway.async.handler.HBP.Exceptions; + +public class BadUserInputException extends Exception{ + public BadUserInputException(String message) { + super(message); + } +} \ No newline at end of file diff --git a/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HBP/Exceptions/UserException.java b/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HBP/Exceptions/UserException.java deleted file mode 100644 index 7004bcad0..000000000 --- a/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HBP/Exceptions/UserException.java +++ /dev/null @@ -1,7 +0,0 @@ -package madgik.exareme.master.gateway.async.handler.HBP.Exceptions; - -public class UserException extends Exception{ - public UserException(String message) { - super(message); - } -} \ No newline at end of file diff --git a/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HBP/HBPQueryHandler.java b/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HBP/HBPQueryHandler.java index e48228f53..67b67efc7 100644 --- a/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HBP/HBPQueryHandler.java +++ b/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HBP/HBPQueryHandler.java @@ -14,7 +14,7 @@ import madgik.exareme.master.engine.iterations.state.IterativeAlgorithmState; import madgik.exareme.master.gateway.ExaremeGatewayUtils; import madgik.exareme.master.gateway.async.handler.HBP.Exceptions.RequestException; -import madgik.exareme.master.gateway.async.handler.HBP.Exceptions.UserException; +import madgik.exareme.master.gateway.async.handler.HBP.Exceptions.BadUserInputException; import madgik.exareme.master.gateway.async.handler.entity.NQueryResultEntity; import madgik.exareme.master.queryProcessor.HBP.AlgorithmProperties; import madgik.exareme.master.queryProcessor.HBP.Algorithms; @@ -167,7 +167,7 @@ private void handleHBPAlgorithmExecution(HttpRequest request, HttpResponse respo response.setStatusCode(HttpStatus.SC_OK); response.setEntity(entity); } - } catch (UserException e) { + } catch (BadUserInputException e) { log.error(e.getMessage()); String errorType = HBPQueryHelper.ErrorResponse.ErrorResponseTypes.user_error; response.setStatusCode(HttpStatus.SC_OK); diff --git a/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HBP/HBPQueryHelper.java b/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HBP/HBPQueryHelper.java index 912ef82c3..360157cfb 100644 --- a/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HBP/HBPQueryHelper.java +++ b/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/async/handler/HBP/HBPQueryHelper.java @@ -2,7 +2,7 @@ import com.google.gson.Gson; import madgik.exareme.master.gateway.async.handler.HBP.Exceptions.ConsulException; -import madgik.exareme.master.gateway.async.handler.HBP.Exceptions.UserException; +import madgik.exareme.master.gateway.async.handler.HBP.Exceptions.BadUserInputException; import madgik.exareme.worker.art.container.ContainerProxy; import madgik.exareme.worker.art.registry.ArtRegistryLocator; import org.apache.http.HttpEntity; @@ -88,12 +88,12 @@ public static HashMap getAlgorithmParameters(HttpRequest request * @param algorithmParameters are used to get the dataset/pathology * @return the containers on which the algorithm should run * @throws ConsulException if consul is unreachable - * @throws UserException if dataset's node is inactive or doesn't exist in the pathology + * @throws BadUserInputException if dataset's node is inactive or doesn't exist in the pathology * or if the pathology is not available or not provided * @throws RemoteException if the Exareme Registry is unreachable */ public static ContainerProxy[] getAlgorithmNodes(HashMap algorithmParameters) - throws ConsulException, UserException, RemoteException { + throws ConsulException, BadUserInputException, RemoteException { ConsulNodesPathologiesAndDatasetsInfo consulNodesPathologiesAndDatasetsInfo = new ConsulNodesPathologiesAndDatasetsInfo(); @@ -139,7 +139,7 @@ public static ContainerProxy[] getAlgorithmNodes(HashMap algorit } else { // If an algorithm parameter exists, a pathology should be provided. - throw new UserException(pathologyNotProvided); + throw new BadUserInputException(pathologyNotProvided); } } @@ -151,14 +151,14 @@ public static ContainerProxy[] getAlgorithmNodes(HashMap algorit * @param datasets of the algorithm * @param consulNodesPathologiesAndDatasetsInfo are the consul information needed * @return the containers to run the algorithm - * @throws UserException if dataset's node is inactive or doesn't exist in the pathology + * @throws BadUserInputException if dataset's node is inactive or doesn't exist in the pathology * @throws RemoteException if the Exareme Registry is unreachable */ private static ContainerProxy[] getAlgorithmNodes( String pathology, ArrayList datasets, ConsulNodesPathologiesAndDatasetsInfo consulNodesPathologiesAndDatasetsInfo - ) throws RemoteException, UserException { + ) throws RemoteException, BadUserInputException { HashMap> algorithmNodeIPsAndDatasets = consulNodesPathologiesAndDatasetsInfo.getNodeDatasets(pathology, datasets); ArrayList algorithmNodes = new ArrayList<>(algorithmNodeIPsAndDatasets.keySet()); @@ -179,7 +179,7 @@ private static ContainerProxy[] getAlgorithmNodes( } } } - throw new UserException( + throw new BadUserInputException( String.format( datasetsXYZAreInactive, String.join(", ", inactiveDatasets) @@ -191,25 +191,25 @@ private static void validatePathologyAndDatasets( String pathology, ArrayList datasets, ConsulNodesPathologiesAndDatasetsInfo nodesInformation - ) throws UserException { + ) throws BadUserInputException { if (pathology != null) { log.debug("Available pathologies: " + nodesInformation.getAllAvailablePathologies()); if (!nodesInformation.getAllAvailablePathologies().contains(pathology)) { - throw new UserException(String.format(pathologyXNotAvailable, pathology)); + throw new BadUserInputException(String.format(pathologyXNotAvailable, pathology)); } if (datasets != null) { ArrayList datasetsOfPathology = nodesInformation.getDatasetsOfPathology(pathology); for (String dataset : datasets) { if (!datasetsOfPathology.contains(dataset)) { - throw new UserException(String.format(datasetXDoesNotExistInPathologyY, dataset, pathology)); + throw new BadUserInputException(String.format(datasetXDoesNotExistInPathologyY, dataset, pathology)); } } } } else { if (datasets != null) { - throw new UserException(pathologyNotProvided); + throw new BadUserInputException(pathologyNotProvided); } } } diff --git a/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/control/handler/HttpAsyncCheckWorker.java b/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/control/handler/HttpAsyncCheckWorker.java index 5274c9f9e..2f6627477 100644 --- a/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/control/handler/HttpAsyncCheckWorker.java +++ b/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/gateway/control/handler/HttpAsyncCheckWorker.java @@ -10,7 +10,7 @@ import madgik.exareme.master.engine.AdpDBManagerLocator; import madgik.exareme.master.gateway.ExaremeGatewayUtils; import madgik.exareme.master.gateway.async.handler.HBP.Exceptions.RequestException; -import madgik.exareme.master.gateway.async.handler.HBP.Exceptions.UserException; +import madgik.exareme.master.gateway.async.handler.HBP.Exceptions.BadUserInputException; import madgik.exareme.master.gateway.async.handler.entity.NQueryResultEntity; import madgik.exareme.master.queryProcessor.HBP.AlgorithmProperties; import madgik.exareme.master.queryProcessor.HBP.Algorithms; @@ -55,7 +55,7 @@ public void handle( HttpResponse response = httpexchange.getResponse(); try { handleInternal(request, response, context); - } catch (AlgorithmException | CDEsMetadataException | ComposerException | UserException | RequestException e) { + } catch (AlgorithmException | CDEsMetadataException | ComposerException | BadUserInputException | RequestException e) { e.printStackTrace(); } httpexchange.submitResponse(new BasicAsyncResponseProducer(response)); @@ -65,7 +65,7 @@ private void handleInternal( final HttpRequest request, final HttpResponse response, final HttpContext context - ) throws HttpException, IOException, AlgorithmException, CDEsMetadataException, ComposerException, UserException, RequestException { + ) throws HttpException, IOException, AlgorithmException, CDEsMetadataException, ComposerException, BadUserInputException, RequestException { String method = request.getRequestLine().getMethod().toUpperCase(Locale.ENGLISH); if (!method.equals("GET") && !method.equals("HEAD") && !method.equals("POST")) { diff --git a/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/queryProcessor/HBP/AlgorithmProperties.java b/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/queryProcessor/HBP/AlgorithmProperties.java index 653f79c4c..f25435f31 100644 --- a/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/queryProcessor/HBP/AlgorithmProperties.java +++ b/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/queryProcessor/HBP/AlgorithmProperties.java @@ -1,9 +1,8 @@ package madgik.exareme.master.queryProcessor.HBP; -import madgik.exareme.master.gateway.async.handler.HBP.Exceptions.UserException; +import madgik.exareme.master.gateway.async.handler.HBP.Exceptions.BadUserInputException; import madgik.exareme.master.queryProcessor.HBP.Exceptions.AlgorithmException; import madgik.exareme.master.queryProcessor.HBP.Exceptions.CDEsMetadataException; -import madgik.exareme.master.queryProcessor.HBP.Exceptions.ComposerException; import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONObject; @@ -114,13 +113,13 @@ public String getParameterValue(String parameterName) { * @param parameterName the name of a parameter * @param newParameterValue the new value of the parameter */ - public void setParameterValue(String parameterName, String newParameterValue) throws ComposerException { + public void setParameterValue(String parameterName, String newParameterValue) throws BadUserInputException { String allowedDynamicParameters = ComposerConstants.dbIdentifierKey; // Not all parameters are allowed to be changed. // This is a safety check if (!allowedDynamicParameters.contains(parameterName)) { - throw new ComposerException("The value of the parameter " + parameterName + " should not be set manually."); + throw new BadUserInputException("The value of the parameter " + parameterName + " should not be set manually."); } for (ParameterProperties parameter : parameters) { @@ -129,7 +128,7 @@ public void setParameterValue(String parameterName, String newParameterValue) th return; } } - throw new ComposerException("The parameter " + parameterName + " does not exist."); + throw new BadUserInputException("The parameter " + parameterName + " does not exist."); } /** @@ -140,7 +139,7 @@ public void setParameterValue(String parameterName, String newParameterValue) th * @throws AlgorithmException when algorithm's properties do not match the algorithmParameters */ public void mergeWithAlgorithmParameters(HashMap algorithmParameters) - throws AlgorithmException, CDEsMetadataException, UserException { + throws AlgorithmException, CDEsMetadataException, BadUserInputException { if (algorithmParameters == null) return; @@ -151,7 +150,7 @@ public void mergeWithAlgorithmParameters(HashMap algorithmParame if (value != null && !value.equals("")) { if (!parameterProperties.getValueMultiple() && value.contains(",") && !parameterProperties.getValueType().equals(ParameterProperties.ParameterValueType.json)) { - throw new UserException("The value of the parameter '" + parameterProperties.getName() + throw new BadUserInputException("The value of the parameter '" + parameterProperties.getName() + "' should contain only one value."); } validateAlgorithmParameterValueType(name, value, parameterProperties); @@ -159,7 +158,7 @@ public void mergeWithAlgorithmParameters(HashMap algorithmParame } else { // if value not given or it is blank if (parameterProperties.getValueNotBlank()) { - throw new UserException( + throw new BadUserInputException( "The value of the parameter '" + parameterProperties.getName() + "' should not be blank."); } @@ -184,7 +183,7 @@ private static void validateAlgorithmParameterType( String value, ParameterProperties parameterProperties, String pathology - ) throws CDEsMetadataException, UserException { + ) throws CDEsMetadataException, BadUserInputException { // First we split in case we have multiple values. String[] values = value.split(","); for (String singleValue : values) { @@ -199,17 +198,17 @@ else if (parameterProperties.getType().equals(ParameterProperties.ParameterType. if (parameterProperties.getValueType().equals(ParameterProperties.ParameterValueType.integer) || parameterProperties.getValueType().equals(ParameterProperties.ParameterValueType.real)) { if (parameterProperties.getValueMin() != null && Double.parseDouble(singleValue) < parameterProperties.getValueMin()) - throw new UserException("The value(s) of the parameter '" + parameterProperties.getName() + throw new BadUserInputException("The value(s) of the parameter '" + parameterProperties.getName() + "' should be greater than " + parameterProperties.getValueMin() + " ."); if (parameterProperties.getValueMax() != null && Double.parseDouble(singleValue) > parameterProperties.getValueMax()) - throw new UserException("The value(s) of the parameter '" + parameterProperties.getName() + throw new BadUserInputException("The value(s) of the parameter '" + parameterProperties.getName() + "' should be less than " + parameterProperties.getValueMax() + " ."); } else if (parameterProperties.getValueType().equals(ParameterProperties.ParameterValueType.string)) { if (parameterProperties.getValueEnumerations() == null) return; List enumerations = Arrays.asList(parameterProperties.getValueEnumerations()); if (!enumerations.contains(singleValue)) - throw new UserException("The value '" + singleValue + "' of the parameter '" + parameterProperties.getName() + throw new BadUserInputException("The value '" + singleValue + "' of the parameter '" + parameterProperties.getName() + "' is not included in the valueEnumerations " + Arrays.toString(parameterProperties.getValueEnumerations()) + " ."); } } @@ -229,24 +228,24 @@ private static void validateCDEVariables( String[] variables, ParameterProperties parameterProperties, String pathology - ) throws CDEsMetadataException, UserException { + ) throws CDEsMetadataException, BadUserInputException { CDEsMetadata.PathologyCDEsMetadata metadata = CDEsMetadata.getInstance().getPathologyCDEsMetadata(pathology); for (String curValue : variables) { if (!metadata.columnExists(curValue)) { - throw new UserException("The CDE '" + curValue + "' does not exist."); + throw new BadUserInputException("The CDE '" + curValue + "' does not exist."); } String allowedSQLTypeValues = parameterProperties.getColumnValuesSQLType(); String columnValuesSQLType = metadata.getColumnValuesSQLType(curValue); if (!allowedSQLTypeValues.contains(columnValuesSQLType) && !allowedSQLTypeValues.equals("")) { - throw new UserException("The CDE '" + curValue + "' does not have one of the allowed SQL Types '" + throw new BadUserInputException("The CDE '" + curValue + "' does not have one of the allowed SQL Types '" + allowedSQLTypeValues + "' for the algorithm."); } String allowedIsCategoricalValue = parameterProperties.getColumnValuesIsCategorical(); String columnValuesIsCategorical = metadata.getColumnValuesIsCategorical(curValue); if (!allowedIsCategoricalValue.equals(columnValuesIsCategorical) && !allowedIsCategoricalValue.equals("")) { - throw new UserException("The CDE '" + curValue + "' does not match the categorical value '" + throw new BadUserInputException("The CDE '" + curValue + "' does not match the categorical value '" + allowedIsCategoricalValue + "' specified for the algorithm."); } } @@ -263,7 +262,7 @@ private static void validateAlgorithmParameterValueType( String algorithmName, String value, ParameterProperties parameterProperties - ) throws AlgorithmException, UserException { + ) throws AlgorithmException, BadUserInputException { if (parameterProperties.getValueType().equals(ParameterProperties.ParameterValueType.json)) { try { new JSONObject(value); @@ -285,19 +284,19 @@ private static void validateAlgorithmParameterValueType( try { Double.parseDouble(curValue); } catch (NumberFormatException nfe) { - throw new UserException( + throw new BadUserInputException( "The value of the parameter '" + parameterProperties.getName() + "' should be a real number."); } } else if (parameterProperties.getValueType().equals(ParameterProperties.ParameterValueType.integer)) { try { Integer.parseInt(curValue); } catch (NumberFormatException e) { - throw new UserException( + throw new BadUserInputException( "The value of the parameter '" + parameterProperties.getName() + "' should be an integer."); } } else if (parameterProperties.getValueType().equals(ParameterProperties.ParameterValueType.string)) { if (curValue.equals("")) { - throw new UserException( + throw new BadUserInputException( "The value of the parameter '" + parameterProperties.getName() + "' contains an empty string."); } diff --git a/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/queryProcessor/HBP/Composer.java b/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/queryProcessor/HBP/Composer.java index 036cdc275..a94c91e74 100644 --- a/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/queryProcessor/HBP/Composer.java +++ b/Exareme-Docker/src/exareme/exareme-master/src/main/java/madgik/exareme/master/queryProcessor/HBP/Composer.java @@ -7,6 +7,7 @@ import madgik.exareme.master.engine.iterations.handler.IterationsConstants; import madgik.exareme.master.engine.iterations.handler.IterationsHandlerDFLUtils; import madgik.exareme.master.engine.iterations.state.IterativeAlgorithmState; +import madgik.exareme.master.gateway.async.handler.HBP.Exceptions.BadUserInputException; import madgik.exareme.master.queryProcessor.HBP.Exceptions.ComposerException; import madgik.exareme.utils.association.Pair; import madgik.exareme.utils.file.FileUtil; @@ -41,7 +42,7 @@ public class Composer { * @param algorithmProperties the properties of the algorithm * @return a query for the local database */ - private static String createLocalTableQuery(AlgorithmProperties algorithmProperties) throws ComposerException { + private static String createLocalTableQuery(AlgorithmProperties algorithmProperties) throws BadUserInputException { List variables = new ArrayList<>(); List datasets = new ArrayList<>(); String filters = ""; @@ -52,7 +53,7 @@ private static String createLocalTableQuery(AlgorithmProperties algorithmPropert if (parameter.getType() == ParameterProperties.ParameterType.column) { for (String variable : Arrays.asList(parameter.getValue().split("[,]"))) { if (variables.contains(variable)) { - throw new ComposerException("Column '" + variable + "' was given twice as input. This is not allowed."); + throw new BadUserInputException("Column '" + variable + "' was given twice as input. This is not allowed."); } variables.add(variable); } @@ -75,7 +76,7 @@ private static String createLocalTableQuery(AlgorithmProperties algorithmPropert } else if (parameter.getType() == ParameterProperties.ParameterType.dataset) { for (String dataset : Arrays.asList(parameter.getValue().split("[,]"))) { if (datasets.contains(dataset)) { - throw new ComposerException("Dataset '" + dataset + "' was given twice as input. This is not allowed."); + throw new BadUserInputException("Dataset '" + dataset + "' was given twice as input. This is not allowed."); } datasets.add(dataset); } @@ -132,7 +133,7 @@ public static String composeDFLScript( String algorithmKey, AlgorithmProperties algorithmProperties, int numberOfWorkers - ) throws ComposerException { + ) throws BadUserInputException, ComposerException { // Assigning the proper identifier for the defaultDB // if the dbIdentifier is provided as a parameter or not String dbIdentifier = algorithmProperties.getParameterValue(ComposerConstants.dbIdentifierKey); @@ -484,7 +485,7 @@ public static String composeIterativeAlgorithmsDFLScript( String algorithmKey, AlgorithmProperties algorithmProperties, IterativeAlgorithmState.IterativeAlgorithmPhasesModel iterativeAlgorithmPhase - ) throws ComposerException { + ) throws BadUserInputException, ComposerException { if (iterativeAlgorithmPhase == null) throw new ComposerException("Unsupported iterative algorithm phase."); @@ -790,7 +791,7 @@ public static String composePythonIterativeAlgorithmsDFLScript( String algorithmKey, AlgorithmProperties algorithmProperties, IterativeAlgorithmState.IterativeAlgorithmPhasesModel iterativeAlgorithmPhase - ) throws ComposerException { + ) throws BadUserInputException, ComposerException { if (iterativeAlgorithmPhase == null) throw new ComposerException("Unsupported iterative algorithm phase."); @@ -1042,7 +1043,7 @@ private static String getIterativeAlgorithmFolderPath( return ComposerConstants.getAlgorithmFolderPath(algorithmName) + "/" + iterativeAlgorithmPhase.name() + "/" + iteration; } - private static File[] getLocalGlobalFolders(String algorithmFolderPath){ + private static File[] getLocalGlobalFolders(String algorithmFolderPath) { File[] localGlobalFolders = new File(algorithmFolderPath).listFiles(new FileFilter() { @Override public boolean accept(File pathname) { diff --git a/Exareme-Docker/src/exareme/exareme-master/src/test/java/madgik/exareme/master/engine/iterations/IterationsFunctionalTests.java b/Exareme-Docker/src/exareme/exareme-master/src/test/java/madgik/exareme/master/engine/iterations/IterationsFunctionalTests.java deleted file mode 100644 index 09cc31265..000000000 --- a/Exareme-Docker/src/exareme/exareme-master/src/test/java/madgik/exareme/master/engine/iterations/IterationsFunctionalTests.java +++ /dev/null @@ -1,188 +0,0 @@ -package madgik.exareme.master.engine.iterations; - -import junit.framework.Assert; -import madgik.exareme.master.AlgorithmTestExecutionHelper; -import madgik.exareme.master.app.cluster.ExaremeCluster; -import madgik.exareme.master.app.cluster.ExaremeClusterFactory; -import madgik.exareme.master.gateway.ExaremeGateway; -import madgik.exareme.master.gateway.ExaremeGatewayFactory; -import org.apache.commons.lang.text.StrSubstitutor; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; -import java.rmi.RemoteException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.concurrent.ExecutionException; - -/** - * Functional tests for iterations module. - *

- * To be used in conjunction with {@link AlgorithmTestExecutionHelper}. - * - * @author Christos Aslanoglou
caslanoglou@di.uoa.gr
University of Athens / Department of - * Informatics and Telecommunications. - */ -public class IterationsFunctionalTests { - private static final Logger log = Logger.getLogger(IterationsFunctionalTests.class); - - private static final String PLACEHOLDER_MAX_ITERATIONS = "placeholder_max_iterations"; - private static final String PLACEHOLDER_CONDITION_QUERY = "placeholder_query_condition"; - private static final String ALGORITHM_JSON_PARAMETERS = - "[{\"name\":\"iterations_max_number\",\"value\":\"${" - + PLACEHOLDER_MAX_ITERATIONS + "}\"}," + - "{\"name\":\"iterations_condition_query_provided\",\"value\":\"${" - + PLACEHOLDER_CONDITION_QUERY + "}\"}]"; - private static final String SELECT_OK_ITERATIVE = "SELECT_OK_ITERATIVE"; - private static final String SAMPLE_ITERATIVE = "SAMPLE_ITERATIVE"; - - - private HashMap placeholdersMap; - private AlgorithmTestExecutionHelper executionTestsHelper; - - @BeforeClass - public static void setUp() throws Exception { - Logger.getRootLogger().setLevel(Level.ALL); - // These overwrites must happen before initializing any of the below iteration related - // fields (since they statically get an instance of Composer and thus force its - // initialization, which we want to avoid until having done the overwrites below). - IterationsTestGenericUtils.overwriteHBPConstantsDEMO_ALGOR_WORKDIR(); - IterationsTestGenericUtils.overwriteDemoRepositoryPathGatewayProperty(); - - final ExaremeCluster cluster = ExaremeClusterFactory.createMiniCluster(1098, 8088, 0); - cluster.start(); - final ExaremeGateway gateway = - ExaremeGatewayFactory.createHttpServer(cluster.getDBManager()); - gateway.start(); - Runtime.getRuntime().addShutdownHook(new Thread() { - @Override - public void run() { - gateway.stop(); - try { - cluster.stop(false); - } catch (RemoteException e) { - e.printStackTrace(); - } - } - }); - log.info("Mini cluster & gateway started."); - } - - @Before - public void SetUp() { - placeholdersMap = new HashMap<>(); - executionTestsHelper = new AlgorithmTestExecutionHelper(); - } - - @Test - public void ensureSelectOKResult() throws IOException, InterruptedException, ExecutionException { - final Integer executionId = submitSelectOkAlgorithm(2); - Assert.assertTrue( - executionTestsHelper.sendAlgorithmRequestAndWaitResponse(executionId)); - } - - @Test - public void ensureSampleIterativeResultStopDueMaxIterations() - throws IOException, InterruptedException, ExecutionException { - final Integer algorithmExecId = submitSampleIterativeAlgorithm(2); - Assert.assertTrue( - executionTestsHelper.sendAlgorithmRequestAndWaitResponse(algorithmExecId)); - } - - @Test - public void ensureSampleIterativeResultStopDueConditionQuery() - throws IOException, InterruptedException, ExecutionException { - final Integer algorithmExecId = submitSampleIterativeAlgorithm(10); - Assert.assertTrue( - executionTestsHelper.sendAlgorithmRequestAndWaitResponse(algorithmExecId)); - } - - @Test - public void testConcurrentSelectOkAlgorithm() throws IOException, InterruptedException { - ArrayList algorithmExecutionIds = new ArrayList<>(); - - algorithmExecutionIds.add(submitSelectOkAlgorithm(1)); - algorithmExecutionIds.add(submitSelectOkAlgorithm(1)); - algorithmExecutionIds.add(submitSelectOkAlgorithm(2)); - - executionTestsHelper.sendConcurrentAlgorithmRequestsAndAwaitResponses(); - - for (Integer algorithmExecutionId : algorithmExecutionIds) { - Assert.assertTrue( - executionTestsHelper.getAlgorithmExecutionMessage(algorithmExecutionId), - executionTestsHelper.gotExpectedResponse(algorithmExecutionId)); - } - } - - @Test - public void testConcurrentIterativeAlgorithms() throws IOException, InterruptedException { - ArrayList algorithmExecutionIds = new ArrayList<>(); - - // Algorithms preparation and submission - algorithmExecutionIds.add(submitSelectOkAlgorithm(1)); - algorithmExecutionIds.add(submitSampleIterativeAlgorithm(10)); - algorithmExecutionIds.add(submitSampleIterativeAlgorithm(2)); - - executionTestsHelper.sendConcurrentAlgorithmRequestsAndAwaitResponses(); - - for (Integer algorithmExecutionId : algorithmExecutionIds) { - Assert.assertTrue( - executionTestsHelper.getAlgorithmExecutionMessage(algorithmExecutionId), - executionTestsHelper.gotExpectedResponse(algorithmExecutionId)); - } - } - - - // Utilities ------------------------------------------------------------------------------ - private String prepareJSONParameters(String maxIterations, String conditionQueryProvided) { - placeholdersMap.put(PLACEHOLDER_MAX_ITERATIONS, maxIterations); - placeholdersMap.put(PLACEHOLDER_CONDITION_QUERY, conditionQueryProvided); - return StrSubstitutor.replace(ALGORITHM_JSON_PARAMETERS, placeholdersMap); - } - - - /** - * Wrapper for submitting a SelectOk algorithm with a given maximum iterations number. - * - * @return the algorithm's execution id - */ - private Integer submitSelectOkAlgorithm(int maxIterationsNumber) { - return executionTestsHelper.addAlgorithmExecutionTest( - SELECT_OK_ITERATIVE, - prepareJSONParameters( - String.valueOf(maxIterationsNumber), - "false"), - "{\"reply\":\"sufficient\"}"); - } - - /** - * Wrapper for submitting a SampleIterative algorithm with a given maximum iterations number. - * - * @return the algorithm's execution id - */ - private Integer submitSampleIterativeAlgorithm(int maxIterationsNumber) { - // Generate expected response - float sumValue = 0; - int currentIterationsNumber = 0; - // Write SampleIterative's termination condition to the respective Java Code - // so that we can generate the correct expected answer. - while (currentIterationsNumber < maxIterationsNumber && sumValue < 5) { - sumValue += currentIterationsNumber + 1; - currentIterationsNumber++; - } - - // currentIterationsNumber needs to be cast as float, since this is how it is retrieved - // from data source - return executionTestsHelper.addAlgorithmExecutionTest( - SAMPLE_ITERATIVE, - prepareJSONParameters(String.valueOf(maxIterationsNumber), "true"), - "{\"sum_value\":" + String.valueOf(sumValue) - + ",\"number_of_iterations\":" - + String.valueOf((float) currentIterationsNumber) - + "}"); - } -} diff --git a/Exareme-Docker/src/exareme/exareme-master/src/test/java/madgik/exareme/master/engine/iterations/handler/IterationsHandlerTest.java b/Exareme-Docker/src/exareme/exareme-master/src/test/java/madgik/exareme/master/engine/iterations/handler/IterationsHandlerTest.java index 63926a15b..966864695 100644 --- a/Exareme-Docker/src/exareme/exareme-master/src/test/java/madgik/exareme/master/engine/iterations/handler/IterationsHandlerTest.java +++ b/Exareme-Docker/src/exareme/exareme-master/src/test/java/madgik/exareme/master/engine/iterations/handler/IterationsHandlerTest.java @@ -58,23 +58,4 @@ public void SetUp() throws Exception { } - // Functional tests ------------------------------------------------------------------------- - @Test - public void ensureIterativeAlgorithmIsSubmittedToStateManager() throws IOException { - String algorithmKey = IterationsTestGenericUtils.generateAlgorithmKey(algorithmProperties); - - final IterativeAlgorithmState ias = handler.handleNewIterativeAlgorithmRequest( - AdpDBManagerLocator.getDBManager(), algorithmKey, algorithmProperties, - ArtRegistryLocator.getArtRegistryProxy().getContainers()); - - final Map iterativeAlgorithmMapping = - Whitebox.getInternalState(stateManager, "iterativeAlgorithmMapping"); - - TestCase.assertFalse(iterativeAlgorithmMapping.isEmpty()); - - // Remove generated files - FileUtils.deleteDirectory(new File( - HBPConstants.DEMO_ALGORITHMS_WORKING_DIRECTORY + "/" - + ias.getAlgorithmKey())); - } } diff --git a/Exareme-Docker/src/exareme/exareme-worker/src/main/java/madgik/exareme/worker/art/executionEngine/containerStatusMgr/PeriodicContainersStatusCheck.java b/Exareme-Docker/src/exareme/exareme-worker/src/main/java/madgik/exareme/worker/art/executionEngine/containerStatusMgr/PeriodicContainersStatusCheck.java index dded44882..939804acc 100644 --- a/Exareme-Docker/src/exareme/exareme-worker/src/main/java/madgik/exareme/worker/art/executionEngine/containerStatusMgr/PeriodicContainersStatusCheck.java +++ b/Exareme-Docker/src/exareme/exareme-worker/src/main/java/madgik/exareme/worker/art/executionEngine/containerStatusMgr/PeriodicContainersStatusCheck.java @@ -52,7 +52,6 @@ public void run() { log.error("Container connection error: " + e); faultyContainers.add(containerName); } - } if (!faultyContainers.isEmpty()) { if (planEventScheduler != null) {