-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from MobilityFirst/sanity_check_config
Configurable sanity check before request update
- Loading branch information
Showing
9 changed files
with
191 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#Sat, 18 Feb 2017 17:11:23 -0500 | ||
#Sun, 28 May 2017 23:06:01 +0530 | ||
build.major.number=1 | ||
build.minor.number=19 | ||
build.revision.number=13 | ||
build.revision.number=15 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/edu/umass/cs/gnsserver/extensions/sanitycheck/AbstractSanityCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* | ||
* Copyright (c) 2015 University of Massachusetts | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you | ||
* may not use this file except in compliance with the License. You | ||
* may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
* implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
* | ||
* Initial developer(s): Karthik A. | ||
* | ||
*/ | ||
|
||
package edu.umass.cs.gnsserver.extensions.sanitycheck; | ||
|
||
import edu.umass.cs.gigapaxos.interfaces.Request; | ||
import edu.umass.cs.reconfiguration.reconfigurationutils.RequestParseException; | ||
|
||
public abstract class AbstractSanityCheck { | ||
|
||
public abstract void check(Request request) throws RequestParseException; | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
src/edu/umass/cs/gnsserver/extensions/sanitycheck/GeoSanityCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* | ||
* Copyright (c) 2015 University of Massachusetts | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you | ||
* may not use this file except in compliance with the License. You | ||
* may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
* implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
* | ||
* Initial developer(s): Karthik A. | ||
* | ||
*/ | ||
|
||
package edu.umass.cs.gnsserver.extensions.sanitycheck; | ||
|
||
import edu.umass.cs.gigapaxos.interfaces.Request; | ||
import edu.umass.cs.gnscommon.CommandType; | ||
import edu.umass.cs.gnscommon.GNSProtocol; | ||
import edu.umass.cs.reconfiguration.reconfigurationutils.RequestParseException; | ||
import org.json.JSONArray; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
/* This is an implementation of sanity checker */ | ||
public class GeoSanityCheck extends AbstractSanityCheck { | ||
|
||
@Override | ||
public void check(Request request) throws RequestParseException { | ||
|
||
try { | ||
JSONObject requestJSON = new JSONObject(request.toString()); | ||
JSONObject commandQuery = requestJSON.getJSONObject(GNSProtocol.COMMAND_QUERY.toString()); | ||
|
||
if (commandQuery.has(GNSProtocol.COMMAND_INT.toString()) && | ||
commandQuery.getInt(GNSProtocol.COMMAND_INT.toString()) == CommandType.ReplaceUserJSON.getInt()) { | ||
JSONObject userJSON = new JSONObject(commandQuery.getString(GNSProtocol.USER_JSON.toString())); | ||
if (userJSON.has(GNSProtocol.LOCATION_FIELD_NAME_2D_SPHERE.toString())) { | ||
JSONObject geoLocCurrent = userJSON.getJSONObject(GNSProtocol.LOCATION_FIELD_NAME_2D_SPHERE.toString()); | ||
if (geoLocCurrent.has("coordinates")) { | ||
JSONArray coordinates = geoLocCurrent.getJSONArray("coordinates"); | ||
if(coordinates.get(0).getClass().equals(String.class) || coordinates.get(1).getClass().equals(String.class)) { | ||
throw new RequestParseException(new Exception("Numeric value expected for location coordinates, string provided")); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} catch (JSONException e) { | ||
//Pass | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/edu/umass/cs/gnsserver/extensions/sanitycheck/NullSanityCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* | ||
* Copyright (c) 2015 University of Massachusetts | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you | ||
* may not use this file except in compliance with the License. You | ||
* may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
* implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
* | ||
* Initial developer(s): Karthik A. | ||
* | ||
*/ | ||
|
||
package edu.umass.cs.gnsserver.extensions.sanitycheck; | ||
|
||
import edu.umass.cs.gigapaxos.interfaces.Request; | ||
import edu.umass.cs.reconfiguration.reconfigurationutils.RequestParseException; | ||
|
||
public class NullSanityCheck extends AbstractSanityCheck { | ||
|
||
public void check(Request request) throws RequestParseException { | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters