Commit fc427006 authored by chiaming2000's avatar chiaming2000
Browse files

Simulator: Handle invalid Synchronization option set in the request

message. An INVALID_REQUEST status code is set in the response message
if received invalid Synchronization option set in the PUT/DELETE request
message.

Default is set to WRITETHROUGH if not set in the PUT/DELETE request
message.  
parent 33710d40
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -155,7 +155,7 @@ public class ClientProxy {
                //set flag to true
                this.isConnectionIdSetByServer = true;
                
                logger.info("set connection Id: " + this.connectionID);
                logger.fine("set connection Id: " + this.connectionID);
            }
        }
    }
+5 −3
Original line number Diff line number Diff line
@@ -67,9 +67,10 @@ public class SslMessageServiceHandler extends
	public void channelActive(final ChannelHandlerContext ctx) throws Exception {
	    
	    // register connection info with the channel handler context
        @SuppressWarnings("unused")
        ConnectionInfo info = SimulatorEngine.registerNewConnection(ctx);
        
        logger.info("TLS channel is active, connection registered., id = " + info.getConnectionId());
        //logger.info("TLS channel is active, connection registered., id = " + info.getConnectionId());
	}

	@Override
@@ -127,12 +128,13 @@ public class SslMessageServiceHandler extends
	public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
	    
	    // remove connection info of the channel handler context from conn info map
        @SuppressWarnings("unused")
        ConnectionInfo info = SimulatorEngine.removeConnectionInfo(ctx);
       
        logger.info("connection info is removed, id=" + info.getConnectionId() );
        //logger.info("connection info is removed, id=" + info.getConnectionId() );

		if (this.queuedRequestProcessRunner != null) {
			logger.info("removing/closing ssl nio queued request process runner ...");
			//logger.info("removing/closing ssl nio queued request process runner ...");
			this.queuedRequestProcessRunner.close();
		}
	}
+6 −4
Original line number Diff line number Diff line
@@ -71,9 +71,10 @@ public class NioMessageServiceHandler extends
	    super.channelActive(ctx);
	    
	    // register connection info with the channel handler context
	    @SuppressWarnings("unused")
        ConnectionInfo info = SimulatorEngine.registerNewConnection(ctx);
	    
	    logger.info("***** connection registered., id = " + info.getConnectionId());
	    //logger.info("***** connection registered., id = " + info.getConnectionId());
	}

	@Override
@@ -133,9 +134,10 @@ public class NioMessageServiceHandler extends
	public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
	    
	 // remove connection info of the channel handler context from conn info map
	    @SuppressWarnings("unused")
        ConnectionInfo info = SimulatorEngine.removeConnectionInfo(ctx);
	   
	    logger.info("connection info is removed, id=" + info.getConnectionId() );
	    //logger.info("connection info is removed, id=" + info.getConnectionId() );
	    
		// close process runner
		if (this.queuedRequestProcessRunner != null) {
+23 −9
Original line number Diff line number Diff line
@@ -96,6 +96,8 @@ public class KVOp {

        Message.Builder respond = (Builder) kmresp.getMessage();
        
        PersistOption persistOption = PersistOption.SYNC;

        try {

            // KV in;
@@ -108,9 +110,6 @@ public class KVOp {

            boolean metadataOnly = requestKeyValue.getMetadataOnly();

            // persist option
            PersistOption persistOption = getPersistOption(requestKeyValue);

            try {

                // set ack sequence
@@ -164,6 +163,9 @@ public class KVOp {
                    break;
                case PUT:
                    
                    // persist option
                    persistOption = getPersistOption(requestKeyValue);
                    
                    try {
                        
                      //check max key length
@@ -220,7 +222,8 @@ public class KVOp {

                    break;
                case DELETE:

                 // persist option
                    persistOption = getPersistOption(requestKeyValue);
                    try {
                        
                        //check max key length
@@ -359,7 +362,7 @@ public class KVOp {

        } catch (KvException e) {

            LOG.fine("KV op Exception: " + e.status + ": " + e.getMessage());
            LOG.warning ("KV op Exception: " + e.status + ": " + e.getMessage());

            respond.getCommandBuilder().getStatusBuilder().setCode(e.status);
            respond.getCommandBuilder().getStatusBuilder()
@@ -398,11 +401,22 @@ public class KVOp {
     *            KeyValue element.
     *
     * @return persist option.
     * @throws KvException if invalid synchronization option is set in the kv parameter.
     */
    public static PersistOption getPersistOption(KeyValue kv) {
    public static PersistOption getPersistOption(KeyValue kv) throws KvException {
        
        /**
         * if not set, default is set to sync/writethrough
         */
        if (kv.hasSynchronization() == false) {
            return PersistOption.SYNC;
        }

        PersistOption option = PersistOption.SYNC;
        
        /**
         * if set, must be an valid option.
         */
        Synchronization sync = kv.getSynchronization();

        if (sync != null) {
@@ -415,7 +429,7 @@ public class KVOp {
                option = PersistOption.ASYNC;
                break;
            default:
                option = PersistOption.SYNC;
                throw new KvException (Status.StatusCode.INVALID_REQUEST, "Invalid persistent synchronization option: " + sync);
            }

        }
+4 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import com.seagate.kinetic.common.lib.KineticMessage;
import com.seagate.kinetic.proto.Kinetic.Message;
import com.seagate.kinetic.proto.Kinetic.Message.KeyValue;
import com.seagate.kinetic.proto.Kinetic.Message.MessageType;
import com.seagate.kinetic.proto.Kinetic.Message.Synchronization;

public class AsyncRequestTest extends IntegrationTestCase {

@@ -120,6 +121,9 @@ public class AsyncRequestTest extends IntegrationTestCase {

		message.getCommandBuilder().getHeaderBuilder()
		.setMessageType(MessageType.PUT);
		
		message.getCommandBuilder().getBodyBuilder().getKeyValueBuilder().setSynchronization(Synchronization.WRITETHROUGH);
		
		KeyValue.Builder kv = message.getCommandBuilder().getBodyBuilder()
				.getKeyValueBuilder();