From c28255aa5ccb1c85d28ab566be1a1dec8d570781 Mon Sep 17 00:00:00 2001 From: Robert Marks Date: Wed, 22 May 2019 13:52:01 -0700 Subject: [PATCH 1/5] Fix incorrect documentation of replica policy default --- .../com/aerospike/restclient/util/QueryParamDescriptors.java | 2 +- src/test/java/com/aerospike/restclient/ASTestUtils.java | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/com/aerospike/restclient/util/QueryParamDescriptors.java b/src/main/java/com/aerospike/restclient/util/QueryParamDescriptors.java index f02ea4c..09de933 100644 --- a/src/main/java/com/aerospike/restclient/util/QueryParamDescriptors.java +++ b/src/main/java/com/aerospike/restclient/util/QueryParamDescriptors.java @@ -8,7 +8,7 @@ public class QueryParamDescriptors { public static final String POLICY_REPLICA_NOTES = "Replica algorithm used to determine the target node for a single record command."; public static final String POLICY_REPLICA_ALLOWABLE_VALUES = "MASTER, MASTER_PROLES, SEQUENCE, RANDOM"; - public static final String POLICY_REPLICA_DEFAULT = "false"; + public static final String POLICY_REPLICA_DEFAULT = "SEQUENCE"; public static final String KEYTYPE_NOTES = "The Type of the userKey."; public static final String KEYTYPE_ALLOWABLE_VALUES = "STRING, INTEGER, BYTES, DIGEST"; diff --git a/src/test/java/com/aerospike/restclient/ASTestUtils.java b/src/test/java/com/aerospike/restclient/ASTestUtils.java index 726bdec..0262065 100644 --- a/src/test/java/com/aerospike/restclient/ASTestUtils.java +++ b/src/test/java/com/aerospike/restclient/ASTestUtils.java @@ -24,8 +24,6 @@ import java.util.List; import java.util.Map; -import javax.net.ssl.SSLContext; - import org.mockito.ArgumentMatcher; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MockMvc; From c108208a35da8cc0d3f64553cdf7e97de2e68a8b Mon Sep 17 00:00:00 2001 From: Robert Marks Date: Wed, 22 May 2019 13:56:38 -0700 Subject: [PATCH 2/5] Update to version 1.1.1 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 5ffc5c9..4e77e95 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -appVersion=1.1.0 +appVersion=1.1.1 warBaseName=as-rest-client From 4f685b8554db7c977b2f5a69a6d39b87e6195bb2 Mon Sep 17 00:00:00 2001 From: Robert Marks Date: Tue, 28 May 2019 09:11:30 -0700 Subject: [PATCH 3/5] Throw internal server error when cluster is unstable --- .../service/AerospikeClusterServiceV1.java | 4 ++++ .../restclient/util/QueryParamDescriptors.java | 2 +- .../restclient/util/RestClientErrors.java | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/aerospike/restclient/service/AerospikeClusterServiceV1.java b/src/main/java/com/aerospike/restclient/service/AerospikeClusterServiceV1.java index bb70c0a..a30add4 100644 --- a/src/main/java/com/aerospike/restclient/service/AerospikeClusterServiceV1.java +++ b/src/main/java/com/aerospike/restclient/service/AerospikeClusterServiceV1.java @@ -28,6 +28,7 @@ import com.aerospike.restclient.handlers.ClusterHandler; import com.aerospike.restclient.handlers.InfoHandler; import com.aerospike.restclient.util.InfoResponseParser; +import com.aerospike.restclient.util.RestClientErrors; @Service public class AerospikeClusterServiceV1 implements AerospikeClusterService { @@ -124,6 +125,9 @@ private long getSetRecordCount(String namespace, String set) { } objects += InfoResponseParser.getSetObjectCountFromResponse(response); } + if (responses.size() == 0 || replFactor == 0) { + throw new RestClientErrors.ClusterUnstableError("Cluster unstable, unable to return cluster information"); + } if (found) { return objects / Math.min(responses.size(), replFactor); } diff --git a/src/main/java/com/aerospike/restclient/util/QueryParamDescriptors.java b/src/main/java/com/aerospike/restclient/util/QueryParamDescriptors.java index 09de933..281ad7e 100644 --- a/src/main/java/com/aerospike/restclient/util/QueryParamDescriptors.java +++ b/src/main/java/com/aerospike/restclient/util/QueryParamDescriptors.java @@ -43,5 +43,5 @@ public class QueryParamDescriptors { public static final String WRITE_POLICY_RECORD_EXISTS_NOTES = "How to handle the existence of the record. This is ignored for POST/PUT/UPDATE kvs methods."; public static final String WRITE_POLICY_RECORD_EXISTS_DEFAULT = "UPDATE"; public static final String WRITE_POLICY_RECORD_EXISTS_ALLOWABLE_VALUES = "UPDATE, UPDATE_ONLY, REPLACE, REPLACE_ONLY, CREATE_ONLY"; - + } diff --git a/src/main/java/com/aerospike/restclient/util/RestClientErrors.java b/src/main/java/com/aerospike/restclient/util/RestClientErrors.java index dce767b..6a665cf 100644 --- a/src/main/java/com/aerospike/restclient/util/RestClientErrors.java +++ b/src/main/java/com/aerospike/restclient/util/RestClientErrors.java @@ -150,4 +150,20 @@ public InvalidDateFormat(String dateStr) { } } + public static class ClusterUnstableError extends AerospikeRestClientError { + private static final long serialVersionUID = 1L; + @Override + public HttpStatus getStatusCode() { + return HttpStatus.INTERNAL_SERVER_ERROR; + } + + public ClusterUnstableError() { + this("Unable to complete operation, cluster is unstable."); + } + + public ClusterUnstableError(String message) { + super(message); + } + } + } \ No newline at end of file From 9c7ca02727a0eaf89b787d4780dc6949663a7004 Mon Sep 17 00:00:00 2001 From: Robert Marks Date: Mon, 17 Jun 2019 13:32:41 -0700 Subject: [PATCH 4/5] update java client version --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 4984afb..19a8ae9 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ buildscript { springBootVersion = '2.1.1.RELEASE' springfoxVersion = '2.9.2' httpclientVersion = '4.5.8' - aerospikeClientVersion = findProperty('aerospikeClientVersion') ?:'4.4.1' + aerospikeClientVersion = findProperty('aerospikeClientVersion') ?:'4.4.2' } if (findProperty("aerospikeUseLocal")) { print("using Local repo") From 48641424ccc52e1bd27b6759cb4c36de071dd577 Mon Sep 17 00:00:00 2001 From: Robert Marks Date: Mon, 24 Jun 2019 07:52:02 -0700 Subject: [PATCH 5/5] Fail faster with invalid operation --- .../util/converters/OperationConverter.java | 4 ++++ .../converters/OperationConverterErrors.java | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/main/java/com/aerospike/restclient/util/converters/OperationConverter.java b/src/main/java/com/aerospike/restclient/util/converters/OperationConverter.java index d365640..34eed6f 100644 --- a/src/main/java/com/aerospike/restclient/util/converters/OperationConverter.java +++ b/src/main/java/com/aerospike/restclient/util/converters/OperationConverter.java @@ -147,6 +147,10 @@ public class OperationConverter { @SuppressWarnings("unchecked") public static Operation convertMapToOperation(MapoperationMap) { + /* Make sure that the user is not providing additional top level keys */ + hasAllRequiredKeys(operationMap, OPERATION_FIELD_KEY, OP_VALUES_KEY); + onlyHasAllowedKeys(operationMap, OPERATION_FIELD_KEY, OP_VALUES_KEY); + String opName = (String) operationMap.get(OPERATION_FIELD_KEY); if (opName == null) { throw new InvalidOperationError("Operation must contain the \"operation\" field"); diff --git a/src/test/java/com/aerospike/restclient/converters/OperationConverterErrors.java b/src/test/java/com/aerospike/restclient/converters/OperationConverterErrors.java index 9b6e180..4140903 100644 --- a/src/test/java/com/aerospike/restclient/converters/OperationConverterErrors.java +++ b/src/test/java/com/aerospike/restclient/converters/OperationConverterErrors.java @@ -48,6 +48,20 @@ public void testMissingOpValues() { OperationConverter.convertMapToOperation(op); } + /* + * If the user accidentally provides an extra key at the top level, we should error out. + */ + @Test(expected=InvalidOperationError.class) + public void testAdditionalTopLevelValue() { + MapopValues = new HashMap<>(); + Mapop = new HashMap<>(); + op.put(AerospikeAPIConstants.OPERATION_FIELD, AerospikeAPIConstants.OPERATION_READ); + op.put("An Extra", "Field"); + opValues.put("bin", "binname"); + op.put(AerospikeAPIConstants.OPERATION_VALUES_FIELD, opValues); + OperationConverter.convertMapToOperation(op); + } + @Test(expected=InvalidOperationError.class) public void testMissingValueInOpvalue() { /*