Search in sources :

Example 6 with NameRecord

use of edu.umass.cs.gnsserver.gnsapp.recordmap.NameRecord in project GNS by MobilityFirst.

the class Admintercessor method handleIncomingDumpResponsePackets.

/**
   * Processes incoming Dump packets.
   *
   * @param json
   * @param handler
   */
public void handleIncomingDumpResponsePackets(JSONObject json, ClientRequestHandlerInterface handler) {
    try {
        switch(Packet.getPacketType(json)) {
            case DUMP_REQUEST:
                try {
                    DumpRequestPacket<String> dumpResponse = new DumpRequestPacket<>(json, handler.getGnsNodeConfig());
                    int id = dumpResponse.getId();
                    // grab or make a new recordsMap
                    Map<String, TreeSet<NameRecord>> recordsMap = dumpStorage.get(id);
                    if (recordsMap == null) {
                        recordsMap = new TreeMap<>();
                        dumpStorage.put(id, recordsMap);
                    }
                    // pull the records out of the dump response and put them in dumpStorage
                    JSONArray jsonArray = dumpResponse.getJsonArray();
                    String serverID = dumpResponse.getPrimaryNameServer();
                    TreeSet<NameRecord> records = new TreeSet<>();
                    for (int i = 0; i < jsonArray.length(); i++) {
                        records.add(new NameRecord(null, jsonArray.getJSONObject(i)));
                    }
                    recordsMap.put(serverID, records);
                } catch (JSONException e) {
                    ClientCommandProcessorConfig.getLogger().log(Level.WARNING, "JSON error during dump reponse processing: {0}", e);
                }
                break;
            case SENTINAL:
                // put the records in dumpResult and let the folks waiting know they are ready
                try {
                    SentinalPacket sentinal = new SentinalPacket(json);
                    int id = sentinal.getId();
                    ClientCommandProcessorConfig.getLogger().log(Level.FINER, "Processing sentinel for {0}", id);
                    synchronized (dumpMonitor) {
                        dumpResult.put(id, dumpStorage.get(id));
                        dumpStorage.remove(id);
                        dumpMonitor.notifyAll();
                    }
                } catch (JSONException e) {
                    ClientCommandProcessorConfig.getLogger().log(Level.WARNING, "JSON error during dump sentinel processing: {0}", e);
                }
                break;
        }
    } catch (JSONException e) {
        ClientCommandProcessorConfig.getLogger().log(Level.WARNING, "JSON error while getting packet type: {0}", e);
    }
}
Also used : DumpRequestPacket(edu.umass.cs.gnsserver.gnsapp.packet.admin.DumpRequestPacket) NameRecord(edu.umass.cs.gnsserver.gnsapp.recordmap.NameRecord) SentinalPacket(edu.umass.cs.gnsserver.gnsapp.packet.admin.SentinalPacket) TreeSet(java.util.TreeSet) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException)

Example 7 with NameRecord

use of edu.umass.cs.gnsserver.gnsapp.recordmap.NameRecord in project GNS by MobilityFirst.

the class NoSQLTest method test_21_UpdateEntireRecord.

/**
   *
   */
@Test
public void test_21_UpdateEntireRecord() {
    JSONObject json = new JSONObject();
    try {
        JSONObject innerJson = new JSONObject();
        innerJson.put("key", "value");
        json.put("map", innerJson);
    } catch (JSONException e) {
        fail("Problem creating json " + e);
    }
    ValuesMap valuesMap = new ValuesMap(json);
    NameRecord nameRecord = new NameRecord(recordMap, guid2, valuesMap);
    try {
        instance.updateEntireRecord(collection, guid2, nameRecord.getValuesMap());
    } catch (FailedDBOperationException | FieldNotFoundException e) {
        fail("Problem during insert " + e);
    }
}
Also used : NameRecord(edu.umass.cs.gnsserver.gnsapp.recordmap.NameRecord) JSONObject(org.json.JSONObject) ValuesMap(edu.umass.cs.gnsserver.utils.ValuesMap) FieldNotFoundException(edu.umass.cs.gnscommon.exceptions.server.FieldNotFoundException) JSONException(org.json.JSONException) FailedDBOperationException(edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException) Test(org.junit.Test)

Example 8 with NameRecord

use of edu.umass.cs.gnsserver.gnsapp.recordmap.NameRecord in project GNS by MobilityFirst.

the class NoSQLTest method test_01_Insert.

/**
   *
   */
@Test
public void test_01_Insert() {
    JSONObject json = new JSONObject();
    try {
        json.put(field, "some value");
    } catch (JSONException e) {
        fail("Problem creating json " + e);
    }
    ValuesMap valuesMap = new ValuesMap(json);
    NameRecord nameRecord = new NameRecord(recordMap, guid, valuesMap);
    try {
        instance.insert(collection, guid, nameRecord.toJSONObject());
    } catch (FailedDBOperationException | JSONException | RecordExistsException e) {
        fail("Problem during insert " + e);
    }
}
Also used : RecordExistsException(edu.umass.cs.gnscommon.exceptions.server.RecordExistsException) NameRecord(edu.umass.cs.gnsserver.gnsapp.recordmap.NameRecord) JSONObject(org.json.JSONObject) ValuesMap(edu.umass.cs.gnsserver.utils.ValuesMap) JSONException(org.json.JSONException) FailedDBOperationException(edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException) Test(org.junit.Test)

Example 9 with NameRecord

use of edu.umass.cs.gnsserver.gnsapp.recordmap.NameRecord in project GNS by MobilityFirst.

the class NoSQLTest method test_20_InsertRecord.

/**
   *
   */
@Test
public void test_20_InsertRecord() {
    JSONObject json = new JSONObject();
    try {
        json.put(field, "some value");
    } catch (JSONException e) {
        fail("Problem creating json " + e);
    }
    ValuesMap valuesMap = new ValuesMap(json);
    NameRecord nameRecord = new NameRecord(recordMap, guid2, valuesMap);
    try {
        instance.insert(collection, guid2, nameRecord.toJSONObject());
    } catch (FailedDBOperationException | JSONException | RecordExistsException e) {
        fail("Problem during insert " + e);
    }
}
Also used : RecordExistsException(edu.umass.cs.gnscommon.exceptions.server.RecordExistsException) NameRecord(edu.umass.cs.gnsserver.gnsapp.recordmap.NameRecord) JSONObject(org.json.JSONObject) ValuesMap(edu.umass.cs.gnsserver.utils.ValuesMap) JSONException(org.json.JSONException) FailedDBOperationException(edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException) Test(org.junit.Test)

Example 10 with NameRecord

use of edu.umass.cs.gnsserver.gnsapp.recordmap.NameRecord 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);
    }
}
Also used : RecordExistsException(edu.umass.cs.gnscommon.exceptions.server.RecordExistsException) ValuesMap(edu.umass.cs.gnsserver.utils.ValuesMap) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) FailedDBOperationException(edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException) GNSRecordMap(edu.umass.cs.gnsserver.gnsapp.recordmap.GNSRecordMap) RecordNotFoundException(edu.umass.cs.gnscommon.exceptions.server.RecordNotFoundException) NameRecord(edu.umass.cs.gnsserver.gnsapp.recordmap.NameRecord) JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject)

Aggregations

NameRecord (edu.umass.cs.gnsserver.gnsapp.recordmap.NameRecord)15 JSONObject (org.json.JSONObject)9 FieldNotFoundException (edu.umass.cs.gnscommon.exceptions.server.FieldNotFoundException)8 JSONException (org.json.JSONException)8 FailedDBOperationException (edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException)7 ValuesMap (edu.umass.cs.gnsserver.utils.ValuesMap)6 RecordNotFoundException (edu.umass.cs.gnscommon.exceptions.server.RecordNotFoundException)5 RecordExistsException (edu.umass.cs.gnscommon.exceptions.server.RecordExistsException)3 TreeSet (java.util.TreeSet)3 Test (org.junit.Test)3 DumpRequestPacket (edu.umass.cs.gnsserver.gnsapp.packet.admin.DumpRequestPacket)2 HashSet (java.util.HashSet)2 JSONArray (org.json.JSONArray)2 ResponseCode (edu.umass.cs.gnscommon.ResponseCode)1 InternalRequestException (edu.umass.cs.gnscommon.exceptions.server.InternalRequestException)1 AbstractRecordCursor (edu.umass.cs.gnsserver.database.AbstractRecordCursor)1 GuidInfo (edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.GuidInfo)1 AdminRequestPacket (edu.umass.cs.gnsserver.gnsapp.packet.admin.AdminRequestPacket)1 SentinalPacket (edu.umass.cs.gnsserver.gnsapp.packet.admin.SentinalPacket)1 GNSRecordMap (edu.umass.cs.gnsserver.gnsapp.recordmap.GNSRecordMap)1