Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added more cases as Bad User Input Exception. #296

Merged
merged 1 commit into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package madgik.exareme.master.gateway.async.handler.HBP.Exceptions;

public class BadUserInputException extends Exception{
public BadUserInputException(String message) {
super(message);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -88,12 +88,12 @@ public static HashMap<String, String> 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<String, String> algorithmParameters)
throws ConsulException, UserException, RemoteException {
throws ConsulException, BadUserInputException, RemoteException {
ConsulNodesPathologiesAndDatasetsInfo consulNodesPathologiesAndDatasetsInfo =
new ConsulNodesPathologiesAndDatasetsInfo();

Expand Down Expand Up @@ -139,7 +139,7 @@ public static ContainerProxy[] getAlgorithmNodes(HashMap<String, String> algorit

} else {
// If an algorithm parameter exists, a pathology should be provided.
throw new UserException(pathologyNotProvided);
throw new BadUserInputException(pathologyNotProvided);
}
}

Expand All @@ -151,14 +151,14 @@ public static ContainerProxy[] getAlgorithmNodes(HashMap<String, String> 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<String> datasets,
ConsulNodesPathologiesAndDatasetsInfo consulNodesPathologiesAndDatasetsInfo
) throws RemoteException, UserException {
) throws RemoteException, BadUserInputException {

HashMap<String, ArrayList<String>> algorithmNodeIPsAndDatasets = consulNodesPathologiesAndDatasetsInfo.getNodeDatasets(pathology, datasets);
ArrayList<String> algorithmNodes = new ArrayList<>(algorithmNodeIPsAndDatasets.keySet());
Expand All @@ -179,7 +179,7 @@ private static ContainerProxy[] getAlgorithmNodes(
}
}
}
throw new UserException(
throw new BadUserInputException(
String.format(
datasetsXYZAreInactive,
String.join(", ", inactiveDatasets)
Expand All @@ -191,25 +191,25 @@ private static void validatePathologyAndDatasets(
String pathology,
ArrayList<String> 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<String> 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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand All @@ -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")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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.");
}

/**
Expand All @@ -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<String, String> algorithmParameters)
throws AlgorithmException, CDEsMetadataException, UserException {
throws AlgorithmException, CDEsMetadataException, BadUserInputException {
if (algorithmParameters == null)
return;

Expand All @@ -151,15 +150,15 @@ public void mergeWithAlgorithmParameters(HashMap<String, String> 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);
validateAlgorithmParameterType(value, parameterProperties, pathology);

} 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.");
}

Expand All @@ -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) {
Expand All @@ -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<String> 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()) + " .");
}
}
Expand All @@ -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.");
}
}
Expand All @@ -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);
Expand All @@ -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.");
}
Expand Down
Loading