Skip to content

Commit

Permalink
Merge pull request #6 from aerospike/rest-1.1.1
Browse files Browse the repository at this point in the history
Rest 1.1.1
  • Loading branch information
aerospikerobertmarks authored Jul 1, 2019
2 parents 672d609 + 4864142 commit 4cb37f8
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
appVersion=1.1.0
appVersion=1.1.1
warBaseName=as-rest-client
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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";

}
16 changes: 16 additions & 0 deletions src/main/java/com/aerospike/restclient/util/RestClientErrors.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ public class OperationConverter {

@SuppressWarnings("unchecked")
public static Operation convertMapToOperation(Map<String, Object>operationMap) {
/* 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");
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/com/aerospike/restclient/ASTestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Map<String, Object>opValues = new HashMap<>();
Map<String, Object>op = 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() {
/*
Expand Down

0 comments on commit 4cb37f8

Please sign in to comment.