Search in sources :

Example 11 with InternalRequestException

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

the class ActiveQueryHandler method handleReadQuery.

/**
	 * This method handles read query from the worker. 
	 * @param am 
	 * @param header 
	 * @return the response ActiveMessage
	 */
public ActiveMessage handleReadQuery(ActiveMessage am, InternalRequestHeader header) {
    ActiveMessage resp = null;
    try {
        JSONObject value = app.read(header, am.getTargetGuid(), am.getAccessor());
        resp = new ActiveMessage(am.getId(), value.toString(), null);
    } catch (InternalRequestException | ClientException e) {
        resp = new ActiveMessage(am.getId(), null, "Read failed");
    }
    return resp;
}
Also used : JSONObject(org.json.JSONObject) InternalRequestException(edu.umass.cs.gnscommon.exceptions.server.InternalRequestException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException)

Example 12 with InternalRequestException

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

the class GNSApp method execute.

/**
   *
   * @param request
   * @param doNotReplyToClient
   * @return true if the command is successfully executed
   */
@SuppressWarnings("unchecked")
// we explicitly check type
@Override
public boolean execute(Request request, boolean doNotReplyToClient) {
    boolean executed = false;
    if (executeNoop(request)) {
        return true;
    }
    try {
        Packet.PacketType packetType = request.getRequestType() instanceof Packet.PacketType ? (Packet.PacketType) request.getRequestType() : null;
        GNSConfig.getLogger().log(Level.FINE, "{0} starting execute({1}) doNotReplyToClient={2}", new Object[] { this, request.getSummary(), doNotReplyToClient });
        Request prev = null;
        // arun: enqueue request, dequeue before returning
        if (request instanceof RequestIdentifier) {
            if (enqueueCommand()) {
                prev = this.outstanding.putIfAbsent(((RequestIdentifier) request).getRequestID(), request);
            }
        } else {
            assert (false) : this + " should not be getting requests that do not implement " + RequestIdentifier.class;
        }
        switch(packetType) {
            case SELECT_REQUEST:
                Select.handleSelectRequest((SelectRequestPacket) request, this);
                break;
            case SELECT_RESPONSE:
                Select.handleSelectResponse((SelectResponsePacket) request, this);
                break;
            case COMMAND:
                CommandHandler.handleCommandPacket((CommandPacket) request, doNotReplyToClient, this);
                break;
            case ADMIN_COMMAND:
                CommandHandler.handleCommandPacket((AdminCommandPacket) request, doNotReplyToClient, this);
                break;
            default:
                assert (false) : (this + " should not be getting packets of type " + packetType + "; exiting");
                GNSConfig.getLogger().log(Level.SEVERE, " Packet type not found: {0}", request.getSummary());
                return false;
        }
        executed = true;
        // arun: always clean up all created state upon exiting
        if (request instanceof RequestIdentifier && prev == null) {
            GNSConfig.getLogger().log(Level.FINE, "{0} finished execute({1})  ->  {2}", new Object[] { this, request.getSummary(), request instanceof ClientRequest && ((ClientRequest) request).getResponse() != null ? ((ClientRequest) request).getResponse().getSummary() : null });
            this.outstanding.remove(((RequestIdentifier) request).getRequestID());
        }
    } catch (JSONException | IOException | ClientException | InternalRequestException e) {
        e.printStackTrace();
    } catch (FailedDBOperationException e) {
        // all database operations throw this exception, therefore we keep
        // throwing this exception upwards and catch this
        // here.
        // A database operation error would imply that the application
        // hasn't been able to successfully execute
        // the request. therefore, this method returns 'false', hoping that
        // whoever calls handleDecision would retry
        // the request.
        GNSConfig.getLogger().log(Level.SEVERE, "Error handling request: {0}", request.toString());
        e.printStackTrace();
    }
    return executed;
}
Also used : Packet(edu.umass.cs.gnsserver.gnsapp.packet.Packet) InternalCommandPacket(edu.umass.cs.gnsserver.gnsapp.packet.InternalCommandPacket) CommandPacket(edu.umass.cs.gnscommon.packets.CommandPacket) ResponsePacket(edu.umass.cs.gnscommon.packets.ResponsePacket) SelectRequestPacket(edu.umass.cs.gnsserver.gnsapp.packet.SelectRequestPacket) SelectResponsePacket(edu.umass.cs.gnsserver.gnsapp.packet.SelectResponsePacket) AdminCommandPacket(edu.umass.cs.gnscommon.packets.AdminCommandPacket) InternalRequestException(edu.umass.cs.gnscommon.exceptions.server.InternalRequestException) ReconfigurableRequest(edu.umass.cs.reconfiguration.interfaces.ReconfigurableRequest) Request(edu.umass.cs.gigapaxos.interfaces.Request) ClientRequest(edu.umass.cs.gigapaxos.interfaces.ClientRequest) JSONException(org.json.JSONException) IOException(java.io.IOException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) PacketType(edu.umass.cs.gnsserver.gnsapp.packet.Packet.PacketType) ClientRequest(edu.umass.cs.gigapaxos.interfaces.ClientRequest) FailedDBOperationException(edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException) RequestIdentifier(edu.umass.cs.gigapaxos.interfaces.RequestIdentifier)

Example 13 with InternalRequestException

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

the class AddMembersToGroup method execute.

@Override
public CommandResponse execute(InternalRequestHeader header, CommandPacket commandPacket, ClientRequestHandlerInterface handler) throws InvalidKeyException, InvalidKeySpecException, JSONException, NoSuchAlgorithmException, SignatureException, ParseException {
    JSONObject json = commandPacket.getCommand();
    String guid = json.getString(GNSProtocol.GUID.toString());
    String members = json.getString(GNSProtocol.MEMBERS.toString());
    // writer might be same as guid
    String writer = json.optString(GNSProtocol.WRITER.toString(), guid);
    // signature and message can be empty for unsigned cases
    String signature = json.optString(GNSProtocol.SIGNATURE.toString(), null);
    String message = json.optString(GNSProtocol.SIGNATUREFULLMESSAGE.toString(), null);
    Date timestamp = json.has(GNSProtocol.TIMESTAMP.toString()) ? Format.parseDateISO8601UTC(json.getString(GNSProtocol.TIMESTAMP.toString())) : // can be null on older client
    null;
    ResponseCode responseCode;
    try {
        if (!(responseCode = GroupAccess.addToGroup(header, guid, new ResultValue(members), writer, signature, message, timestamp, handler)).isExceptionOrError()) {
            return new CommandResponse(ResponseCode.NO_ERROR, GNSProtocol.OK_RESPONSE.toString());
        } else {
            return new CommandResponse(responseCode, GNSProtocol.BAD_RESPONSE.toString() + " " + responseCode.getProtocolCode());
        }
    } catch (ClientException | IOException | InternalRequestException e) {
        return new CommandResponse(ResponseCode.UNSPECIFIED_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.UNSPECIFIED_ERROR.toString() + " " + e.getMessage());
    }
}
Also used : ResponseCode(edu.umass.cs.gnscommon.ResponseCode) JSONObject(org.json.JSONObject) InternalRequestException(edu.umass.cs.gnscommon.exceptions.server.InternalRequestException) ResultValue(edu.umass.cs.gnsserver.utils.ResultValue) CommandResponse(edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.CommandResponse) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) IOException(java.io.IOException) Date(java.util.Date)

Example 14 with InternalRequestException

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

the class RemoveFromGroup method execute.

@Override
public CommandResponse execute(InternalRequestHeader header, CommandPacket commandPacket, ClientRequestHandlerInterface handler) throws InvalidKeyException, InvalidKeySpecException, JSONException, NoSuchAlgorithmException, SignatureException, ParseException {
    JSONObject json = commandPacket.getCommand();
    String guid = json.getString(GNSProtocol.GUID.toString());
    String member = json.getString(GNSProtocol.MEMBER.toString());
    // writer might be same as guid
    String writer = json.optString(GNSProtocol.WRITER.toString(), guid);
    // signature and message can be empty for unsigned cases
    String signature = json.optString(GNSProtocol.SIGNATURE.toString(), null);
    String message = json.optString(GNSProtocol.SIGNATUREFULLMESSAGE.toString(), null);
    Date timestamp = json.has(GNSProtocol.TIMESTAMP.toString()) ? Format.parseDateISO8601UTC(json.getString(GNSProtocol.TIMESTAMP.toString())) : // can be null on older client
    null;
    ResponseCode responseCode;
    try {
        if (!(responseCode = GroupAccess.removeFromGroup(header, commandPacket, guid, member, writer, signature, message, timestamp, handler)).isExceptionOrError()) {
            return new CommandResponse(ResponseCode.NO_ERROR, GNSProtocol.OK_RESPONSE.toString());
        } else {
            return new CommandResponse(responseCode, GNSProtocol.BAD_RESPONSE.toString() + " " + responseCode.getProtocolCode());
        }
    } catch (ClientException | IOException | InternalRequestException e) {
        return new CommandResponse(ResponseCode.UNSPECIFIED_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.UNSPECIFIED_ERROR.toString() + " " + e.getMessage());
    }
}
Also used : ResponseCode(edu.umass.cs.gnscommon.ResponseCode) JSONObject(org.json.JSONObject) InternalRequestException(edu.umass.cs.gnscommon.exceptions.server.InternalRequestException) CommandResponse(edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.CommandResponse) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) IOException(java.io.IOException) Date(java.util.Date)

Example 15 with InternalRequestException

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

the class RemoveMembersFromGroup method execute.

@Override
public CommandResponse execute(InternalRequestHeader header, CommandPacket commandPacket, ClientRequestHandlerInterface handler) throws InvalidKeyException, InvalidKeySpecException, JSONException, NoSuchAlgorithmException, SignatureException, ParseException {
    JSONObject json = commandPacket.getCommand();
    String guid = json.getString(GNSProtocol.GUID.toString());
    String members = json.getString(GNSProtocol.MEMBERS.toString());
    // writer might be same as guid
    String writer = json.optString(GNSProtocol.WRITER.toString(), guid);
    // signature and message can be empty for unsigned cases
    String signature = json.optString(GNSProtocol.SIGNATURE.toString(), null);
    String message = json.optString(GNSProtocol.SIGNATUREFULLMESSAGE.toString(), null);
    Date timestamp = json.has(GNSProtocol.TIMESTAMP.toString()) ? Format.parseDateISO8601UTC(json.getString(GNSProtocol.TIMESTAMP.toString())) : // can be null on older client
    null;
    ResponseCode responseCode;
    try {
        if (!(responseCode = GroupAccess.removeFromGroup(header, commandPacket, guid, new ResultValue(members), writer, signature, message, timestamp, handler)).isExceptionOrError()) {
            return new CommandResponse(ResponseCode.NO_ERROR, GNSProtocol.OK_RESPONSE.toString());
        } else {
            return new CommandResponse(responseCode, GNSProtocol.BAD_RESPONSE.toString() + " " + responseCode.getProtocolCode());
        }
    } catch (ClientException | IOException | InternalRequestException e) {
        return new CommandResponse(ResponseCode.UNSPECIFIED_ERROR, GNSProtocol.BAD_RESPONSE.toString() + " " + GNSProtocol.UNSPECIFIED_ERROR.toString() + " " + e.getMessage());
    }
}
Also used : ResponseCode(edu.umass.cs.gnscommon.ResponseCode) JSONObject(org.json.JSONObject) InternalRequestException(edu.umass.cs.gnscommon.exceptions.server.InternalRequestException) ResultValue(edu.umass.cs.gnsserver.utils.ResultValue) CommandResponse(edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commandSupport.CommandResponse) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException) IOException(java.io.IOException) Date(java.util.Date)

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