Commit 691fb379 authored by chiaming2000's avatar chiaming2000
Browse files

Added message validation to check if a request batchId exists. If true,

it must be valid.

If not, response status code is set to INVALID_REQUEST and the request
command is not performed. 
parent a53f53e7
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -52,6 +52,9 @@ public class KineticMessage {
    // set to true if this is the first message in the batch
    private volatile boolean isFirstBatchMessage = false;

    // set to true if this message is marked as invalid batch
    private volatile boolean isInvalidBatchMessage = false;

	/**
	 * Set protocol buffer message.
	 *
@@ -162,4 +165,23 @@ public class KineticMessage {
        this.isFirstBatchMessage = flag;
    }

    /**
     * Get if this message is not a valid batch message
     * 
     * @return true if this is NOT a valid batch message
     */
    public boolean getIsInvalidBatchMessage() {
        return this.isInvalidBatchMessage;
    }

    /**
     * Set if this message is an invalid batch message.
     * 
     * @param flag
     *            true if this is an invalid batch message.
     */
    public void setIsInvalidBatchMessage(boolean flag) {
        this.isInvalidBatchMessage = flag;
    }

}
+10 −14
Original line number Diff line number Diff line
/**
 *
 * Copyright (C) 2014 Seagate Technology.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

//
package com.seagate.kinetic.proto;

option java_outer_classname = "Kinetic";
+12 −1
Original line number Diff line number Diff line
@@ -557,6 +557,10 @@ public class SimulatorEngine implements MessageService {
            commandBuilder.getHeaderBuilder().setMessageType(
                    MessageType.valueOf(number));

            commandBuilder.getStatusBuilder().setCode(
                    StatusCode.INVALID_REQUEST);
            commandBuilder.getStatusBuilder().setStatusMessage(e.getMessage());

            logger.log(Level.WARNING, e.getMessage(), e);
        } finally {

@@ -1059,7 +1063,14 @@ public class SimulatorEngine implements MessageService {
        logger.info("batch op ended/released ...");
    }

    private synchronized void checkBatchMode(KineticMessage kmreq) {
    private synchronized void checkBatchMode(KineticMessage kmreq)
            throws InvalidRequestException {

        if (kmreq.getIsInvalidBatchMessage()) {
            throw new InvalidRequestException(
                    "Invalid batch Id found in message: "
                            + kmreq.getCommand().getHeader().getBatchID());
        }

        if (this.isInBatchMode == false) {
            return;
+7 −4
Original line number Diff line number Diff line
@@ -240,13 +240,10 @@ public class NioMessageServiceHandler extends

        BatchQueue batchQueue = this.batchMap.get(key);

        MessageType mtype = null;
        MessageType mtype = request.getCommand().getHeader().getMessageType();

        if (batchQueue != null) {

            mtype = request.getCommand().getHeader()
                    .getMessageType();

            if (mtype == MessageType.PUT || mtype == MessageType.DELETE) {

                // is added to batch queue
@@ -258,6 +255,12 @@ public class NioMessageServiceHandler extends
                // add to batch queue
                batchQueue.add(request);
            }
        } else {
            // there is a batch ID not known at this point
            // the only allowed message type is start message.
            if (mtype != MessageType.START_BATCH) {
                request.setIsInvalidBatchMessage(true);
            }
        }

        return flag;