use of com.eightkdata.mongowp.exceptions.TypesMismatchException in project torodb by torodb.
the class ReplicaSetConfig method parseCustomWriteConcerns.
private static Map<String, ReplicaSetTagPattern> parseCustomWriteConcerns(BsonDocument bson) throws TypesMismatchException, NoSuchKeyException, BadValueException {
Map<String, ReplicaSetTagPattern> map = new HashMap<>(bson.size());
for (Entry<?> customWriteNameEntry : bson) {
BsonDocument constraintDoc = BsonReaderTool.getDocument(bson, customWriteNameEntry.getKey());
Map<String, Integer> constraintMap = new HashMap<>(constraintDoc.size());
for (Entry<?> tagEntry : constraintDoc) {
int intValue;
try {
intValue = tagEntry.getValue().asNumber().intValue();
} catch (UnsupportedOperationException ex) {
String fieldName = SETTINGS_FIELD.getFieldName() + '.' + GET_LAST_ERROR_MODES_FIELD.getFieldName() + '.' + customWriteNameEntry + '.' + constraintDoc;
BsonType tagType = tagEntry.getValue().getType();
throw new TypesMismatchException(fieldName, "number", tagType, "Expected " + fieldName + " to be a number, not " + tagType.toString().toLowerCase(Locale.ROOT));
}
if (intValue <= 0) {
String fieldName = SETTINGS_FIELD.getFieldName() + '.' + GET_LAST_ERROR_MODES_FIELD.getFieldName() + '.' + customWriteNameEntry + '.' + constraintDoc;
throw new BadValueException("Value of " + fieldName + " must be positive, but found " + intValue);
}
constraintMap.put(tagEntry.getKey(), intValue);
}
map.put(customWriteNameEntry.getKey(), new ReplicaSetTagPattern(constraintMap));
}
return map;
}
use of com.eightkdata.mongowp.exceptions.TypesMismatchException in project torodb by torodb.
the class ReplSetHeartbeatReplyMarshaller method parseAppliedOpTime.
private static void parseAppliedOpTime(BsonDocument bson, ReplSetHeartbeatReplyBuilder builder, long term) throws TypesMismatchException, NoSuchKeyException {
// In order to support both the 3.0(V0) and 3.2(V1) heartbeats we must parse the OpTime
// field based on its type. If it is a Date, we parse it as the timestamp and use
// initialize's term argument to complete the OpTime type. If it is an Object, then it's
// V1 and we construct an OpTime out of its nested fields.
Entry<?> entry = BsonReaderTool.getEntry(bson, APPLIED_OP_TIME_FIELD_NAME, null);
if (entry == null) {
return;
}
BsonValue<?> value = entry.getValue();
OpTime opTime;
switch(value.getType()) {
case TIMESTAMP:
opTime = new OpTime(value.asTimestamp(), term);
break;
case DATETIME:
BsonTimestamp ts = BsonReaderTool.getTimestampFromDateTime(entry);
opTime = new OpTime(ts, term);
break;
case //repl v1
DOCUMENT:
opTime = OpTime.fromBson(value.asDocument());
builder.setIsReplSet(true);
break;
default:
throw new TypesMismatchException(APPLIED_OP_TIME_FIELD_NAME, "Date or Timestamp", value.getType());
}
builder.setAppliedOpTime(opTime);
}
Aggregations