use of edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException in project GNS by MobilityFirst.
the class Select method aclCheckFilterFields.
/**
* This filters individual fields if the cannot be accessed by the reader.
*
* @param packet
* @param records
* @param reader
* @param app
* @return
*/
private static JSONArray aclCheckFilterFields(SelectRequestPacket packet, JSONArray records, String reader, GNSApplicationInterface<String> app) {
for (int i = 0; i < records.length(); i++) {
try {
JSONObject record = records.getJSONObject(i);
String guid = record.getString(NameRecord.NAME.getName());
// Look at the keys in the values map
JSONObject valuesMap = record.getJSONObject(NameRecord.VALUES_MAP.getName());
Iterator<?> keys = valuesMap.keys();
while (keys.hasNext()) {
String field = (String) keys.next();
if (!InternalField.isInternalField(field)) {
LOGGER.log(Level.FINE, "{0} Checking: {1}", new Object[] { app.getNodeID(), field });
ResponseCode responseCode = NSAuthentication.signatureAndACLCheck(null, guid, field, null, reader, null, null, MetaDataTypeName.READ_WHITELIST, app, true);
if (!responseCode.isOKResult()) {
LOGGER.log(Level.FINE, "{0} Removing: {1}", new Object[] { app.getNodeID(), field });
// removing the offending field
keys.remove();
}
}
}
} catch (JSONException | InvalidKeyException | InvalidKeySpecException | SignatureException | NoSuchAlgorithmException | FailedDBOperationException | UnsupportedEncodingException e) {
// ignore json errros
LOGGER.log(Level.FINE, "{0} Problem getting guid from json: {1}", new Object[] { app.getNodeID(), e.getMessage() });
}
}
return records;
}
use of edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException in project GNS by MobilityFirst.
the class Select method aclCheckFilterForRecordsArray.
/**
* This filters entire records if the query uses fields that cannot be accessed in the
* returned record by the reader. Otherwise the user would be able to determine that
* some GUIDS contain specific values for fields they can't access.
*
* @param packet
* @param records
* @param reader
* @param app
* @return
*/
private static JSONArray aclCheckFilterForRecordsArray(SelectRequestPacket packet, JSONArray records, String reader, GNSApplicationInterface<String> app) {
JSONArray result = new JSONArray();
for (int i = 0; i < records.length(); i++) {
try {
JSONObject record = records.getJSONObject(i);
String guid = record.getString(NameRecord.NAME.getName());
List<String> queryFields = getFieldsForQueryType(packet);
ResponseCode responseCode = NSAuthentication.signatureAndACLCheck(null, guid, null, queryFields, reader, null, null, MetaDataTypeName.READ_WHITELIST, app, true);
LOGGER.log(Level.FINE, "{0} ACL check for select: guid={0} queryFields={1} responsecode={2}", new Object[] { app.getNodeID(), guid, queryFields, responseCode });
if (responseCode.isOKResult()) {
result.put(record);
}
} catch (JSONException | InvalidKeyException | InvalidKeySpecException | SignatureException | NoSuchAlgorithmException | FailedDBOperationException | UnsupportedEncodingException e) {
// ignore json errros
LOGGER.log(Level.FINE, "{0} Problem getting guid from json: {1}", new Object[] { app.getNodeID(), e.getMessage() });
}
}
return result;
}
use of edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException in project GNS by MobilityFirst.
the class Select method handleSelectRequestFromNS.
/**
* Handle a select request from the collecting NS. This is what other NSs do when they
* get a SelectRequestPacket from the NS that originally received the packet (the one that is collecting
* all the records).
* This NS looks up the records and returns them.
*
* @param incomingJSON
* @param app
* @throws JSONException
*/
@SuppressWarnings("unchecked")
private static void handleSelectRequestFromNS(SelectRequestPacket request, GNSApplicationInterface<String> app) throws JSONException {
LOGGER.log(Level.FINE, "NS {0} {1} received query {2}", new Object[] { Select.class.getSimpleName(), app.getNodeID(), request.getSummary() });
try {
// grab the records
JSONArray jsonRecords = getJSONRecordsForSelect(request, app);
jsonRecords = aclCheckFilterReturnedRecord(request, jsonRecords, request.getReader(), app);
@SuppressWarnings("unchecked") SelectResponsePacket response = SelectResponsePacket.makeSuccessPacketForFullRecords(request.getId(), request.getClientAddress(), request.getCcpQueryId(), request.getNsQueryId(), app.getNodeAddress(), jsonRecords);
LOGGER.log(Level.FINE, "NS {0} sending back {1} record(s) in response to {2}", new Object[] { app.getNodeID(), jsonRecords.length(), request.getSummary() });
// and send them back to the originating NS
app.sendToAddress(request.getNSReturnAddress(), response.toJSONObject());
} catch (FailedDBOperationException | JSONException | IOException e) {
LOGGER.log(Level.SEVERE, "Exception while handling select request: {0}", e);
SelectResponsePacket failResponse = SelectResponsePacket.makeFailPacket(request.getId(), request.getClientAddress(), request.getNsQueryId(), app.getNodeAddress(), e.getMessage());
try {
app.sendToAddress(request.getNSReturnAddress(), failResponse.toJSONObject());
} catch (IOException f) {
LOGGER.log(Level.SEVERE, "Unable to send Failure SelectResponsePacket: {0}", f);
}
}
}
use of edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException in project GNS by MobilityFirst.
the class NoSQLRecordsThroughputTest method testlookupMultipleSystemAndUserFields.
private static void testlookupMultipleSystemAndUserFields(String node, String guid, String field) {
//NoSQLRecords instance = new MongoRecords<String>(node);
NoSQLRecords instance = new DiskMapRecords(node);
GNSRecordMap<String> recordMap = new GNSRecordMap<String>(instance, COLLECTION_NAME);
JSONObject json = new JSONObject();
try {
json.put(field, "some value");
} catch (JSONException e) {
System.out.println("Problem creating json " + e);
}
ValuesMap valuesMap = new ValuesMap(json);
NameRecord nameRecord = new NameRecord(recordMap, guid, valuesMap);
try {
instance.insert(COLLECTION_NAME, guid, nameRecord.toJSONObject());
} catch (JSONException e) {
System.out.println("Problem writing json " + e);
} catch (FailedDBOperationException e) {
System.out.println("Problem adding " + json.toString() + " as value of " + guid + ": " + e);
} catch (RecordExistsException e) {
System.out.println(guid + " record already exists in database. Try something else." + e);
}
// and try to read it as fast as possible
try {
ArrayList<ColumnField> userFields = new ArrayList<>(Arrays.asList(new ColumnField(field, ColumnFieldType.USER_JSON)));
int frequency = 10000;
reset();
do {
Map<ColumnField, Object> map = instance.lookupSomeFields(COLLECTION_NAME, guid, NameRecord.NAME, NameRecord.VALUES_MAP, userFields);
if (incrCount() % frequency == 0) {
System.out.println(map);
System.out.println(DelayProfiler.getStats());
System.out.println("op/s = " + Format.formatTime(getCount() * 1000.0 / (System.currentTimeMillis() - initTime)));
if (getCount() > frequency * 20) {
System.out.println("**********************resetting************************");
reset();
}
}
} while (true);
} catch (FailedDBOperationException | RecordNotFoundException e) {
System.out.println("Lookup failed: " + e);
}
}
use of edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException in project GNS by MobilityFirst.
the class MongoRecords method doUpdate.
private void doUpdate(String collectionName, String guid, BasicDBObject updates) throws FailedDBOperationException {
String primaryKey = mongoCollectionSpecs.getCollectionSpec(collectionName).getPrimaryKey().getName();
DBCollection collection = db.getCollection(collectionName);
BasicDBObject query = new BasicDBObject(primaryKey, guid);
if (updates.keySet().size() > 0) {
long startTime = System.currentTimeMillis();
try {
collection.update(query, new BasicDBObject("$set", updates));
} catch (MongoException e) {
DatabaseConfig.getLogger().log(Level.SEVERE, "{0} doUpdate failed: {1}", new Object[] { dbName, e.getMessage() });
throw new FailedDBOperationException(collectionName, updates.toString(), "Original mongo exception:" + e.getMessage());
}
DelayProfiler.updateDelay("mongoSetUpdate", startTime);
long finishTime = System.currentTimeMillis();
if (finishTime - startTime > 10) {
DatabaseConfig.getLogger().log(Level.FINE, "{0} Long latency mongoUpdate {1}", new Object[] { dbName, (finishTime - startTime) });
}
}
}
Aggregations