Search in sources :

Example 16 with InternalRequestException

use of edu.umass.cs.gnscommon.exceptions.server.InternalRequestException in project GNS by MobilityFirst.

the class NSFieldAccess method lookupJSONFieldAnywhere.

/**
   * Looks up the value of a field in the guid.
   * If guid doesn't exists on this Name Server,
   * sends a read query from this Name Server to a Local Name Server.
   * Returns the value of a field in a GNSProtocol.GUID.toString() as a ValuesMap
   *
   * @param header
   * @param guid
   * @param field
   * @param gnsApp
   * @return ValuesMap containing the value of the field or null if field cannot be found
   * @throws edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException
   */
public static ValuesMap lookupJSONFieldAnywhere(InternalRequestHeader header, String guid, String field, GNSApplicationInterface<String> gnsApp) throws FailedDBOperationException {
    ValuesMap result = lookupJSONFieldLocally(null, guid, field, gnsApp);
    // if values wasn't found and the guid doesn't exist on this server and we're allowed then send a query to the LNS
    if (result == null && !gnsApp.getDB().containsName(guid)) {
        try {
            String stringResult = gnsApp.getRequestHandler().getInternalClient().execute(GNSCommandInternal.fieldRead(guid, field, header)).getResultString();
            if (stringResult != null) {
                result = new ValuesMap();
                result.put(field, stringResult);
            }
        } catch (IOException | JSONException | ClientException | InternalRequestException e) {
            ClientSupportConfig.getLogger().log(Level.SEVERE, "Problem getting record from remote server: {0}", e);
        }
        if (result != null) {
            ClientSupportConfig.getLogger().log(Level.FINE, "@@@@@@ Field {0} in {1} not found on this server but was found thru remote query.", new Object[] { field, guid });
        }
    }
    return result;
}
Also used : InternalRequestException(edu.umass.cs.gnscommon.exceptions.server.InternalRequestException) ValuesMap(edu.umass.cs.gnsserver.utils.ValuesMap) JSONException(org.json.JSONException) IOException(java.io.IOException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException)

Example 17 with InternalRequestException

use of edu.umass.cs.gnscommon.exceptions.server.InternalRequestException in project GNS by MobilityFirst.

the class NSFieldAccess method lookupJSONFieldLocalNoAuth.

/**
   * Looks up the value of a field in the guid on this NameServer.
   * Active code is handled if handleActiveCode is true.
   *
   * Returns the value of a field in a GNSProtocol.GUID.toString() as a ValuesMap.
   *
   * @param header
   * @param guid
   * @param field
   * @param gnsApp
   * @param handleActiveCode
   * @return ResultValue
   * @throws edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException
   */
public static ValuesMap lookupJSONFieldLocalNoAuth(InternalRequestHeader header, String guid, String field, GNSApplicationInterface<String> gnsApp, boolean handleActiveCode) throws FailedDBOperationException {
    ValuesMap valuesMap = lookupFieldLocalNoAuth(guid, field, ColumnFieldType.USER_JSON, gnsApp.getDB());
    if (handleActiveCode) {
        try {
            JSONObject result = ActiveCodeHandler.handleActiveCode(header, guid, field, ActiveCode.READ_ACTION, valuesMap, gnsApp.getDB());
            valuesMap = result != null ? new ValuesMap(result) : valuesMap;
        } catch (InternalRequestException e) {
        // Active code field lookup failed, do nothing and return the original value
        }
    }
    return valuesMap;
}
Also used : JSONObject(org.json.JSONObject) InternalRequestException(edu.umass.cs.gnscommon.exceptions.server.InternalRequestException) ValuesMap(edu.umass.cs.gnsserver.utils.ValuesMap)

Aggregations

InternalRequestException (edu.umass.cs.gnscommon.exceptions.server.InternalRequestException)17 ClientException (edu.umass.cs.gnscommon.exceptions.client.ClientException)15 IOException (java.io.IOException)13 JSONObject (org.json.JSONObject)13 JSONException (org.json.JSONException)10 ResponseCode (edu.umass.cs.gnscommon.ResponseCode)7 ValuesMap (edu.umass.cs.gnsserver.utils.ValuesMap)7 RandomString (edu.umass.cs.gnscommon.utils.RandomString)6 FailedDBOperationException (edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException)5 CommandResponse (edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.CommandResponse)4 Date (java.util.Date)4 ResultValue (edu.umass.cs.gnsserver.utils.ResultValue)2 ParseException (java.text.ParseException)2 ClientRequest (edu.umass.cs.gigapaxos.interfaces.ClientRequest)1 Request (edu.umass.cs.gigapaxos.interfaces.Request)1 RequestIdentifier (edu.umass.cs.gigapaxos.interfaces.RequestIdentifier)1 FieldNotFoundException (edu.umass.cs.gnscommon.exceptions.server.FieldNotFoundException)1 RecordNotFoundException (edu.umass.cs.gnscommon.exceptions.server.RecordNotFoundException)1 AdminCommandPacket (edu.umass.cs.gnscommon.packets.AdminCommandPacket)1 CommandPacket (edu.umass.cs.gnscommon.packets.CommandPacket)1