Commit 95c72650 authored by chiaming2000's avatar chiaming2000
Browse files

Java simulator:

Added "world_wide_name", "manufacturer" ,"model" etc to the heart beat
message.  
parent ae039e1f
Loading
Loading
Loading
Loading
+109 −46
Original line number Diff line number Diff line
@@ -30,14 +30,29 @@ import com.google.gson.Gson;
 */
public class HeartbeatMessage {

    // firmware version
    private String firmware_version = "0.8.0.2";

    // manufacturer
    private String manufacturer = "Seagate";

    // model
    private String model = "Simulator";

    private final List<KineticNetworkInterface> network_interfaces = new ArrayList<KineticNetworkInterface>();

    // message source port
    private int port = 8123;

    private String protocol_version = "3.0.0";

    private String serial_number = "Z3008QP0";

    // message source tls port
    private int tlsPort = 8443;

    private String world_wide_name = "7 000c50 05008d357";

    // gson to
    private static Gson gson = new Gson();

@@ -69,6 +84,54 @@ public class HeartbeatMessage {
        return this.network_interfaces;
    }

    public void setFirmwareVersion(String firmwareVersion) {
        this.firmware_version = firmwareVersion;
    }

    public String getFirmwareVersion() {
        return this.firmware_version;
    }

    public void setManufacturer(String manufacturer) {
        this.manufacturer = manufacturer;
    }

    public String getManufacturer() {
        return this.manufacturer;
    }

    public void setModel(String model) {
        this.model = model;
    }

    public String getModel() {
        return this.model;
    }

    public void setProtocolVersion(String protocolVersion) {
        this.protocol_version = protocolVersion;
    }

    public String getProtocolVersion() {
        return this.protocol_version;
    }

    public void setSerialNumber(String sn) {
        this.serial_number = sn;
    }

    public String getSerialNumber() {
        return this.serial_number;
    }

    public void setWorldWideName(String wwn) {
        this.world_wide_name = wwn;
    }

    public String getWorldWideName() {
        return this.world_wide_name;
    }

    public static String toJson(Object obj) {
        return gson.toJson(obj, HeartbeatMessage.class);
    }
+6 −0
Original line number Diff line number Diff line
@@ -196,6 +196,12 @@
			<artifactId>guava</artifactId>
			<version>14.0.1</version>
		</dependency>
		<dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
        <version>1.9</version>
        </dependency>
		
		<dependency>
			<groupId>${project.groupId}</groupId>
			<artifactId>kinetic-common</artifactId>
+170 −152
Original line number Diff line number Diff line
@@ -125,10 +125,12 @@ public class MulticastHeartbeatProvider implements HeartbeatProvider {

        try {
            // this host name
		    //this.thisHostIp = InetAddress.getByName(thisHostIp).getHostAddress();
            // this.thisHostIp =
            // InetAddress.getByName(thisHostIp).getHostAddress();

            // this host address
			//this.thisHostPort = this.thisHostIp + ":" + config.getPort() + ":"
            // this.thisHostPort = this.thisHostIp + ":" + config.getPort() +
            // ":"
            // + config.getSslPort();

            // multicast socket
@@ -160,6 +162,22 @@ public class MulticastHeartbeatProvider implements HeartbeatProvider {

        try {

            // protocol_version
            this.heartbeatMessage.setProtocolVersion(SimulatorConfiguration
                    .getProtocolVersion());

            this.heartbeatMessage.setFirmwareVersion(SimulatorConfiguration
                    .getSimulatorVersion());

            this.heartbeatMessage
                    .setManufacturer(SimulatorConfiguration.VENDER);

            this.heartbeatMessage.setModel(SimulatorConfiguration.MODEL);

            this.heartbeatMessage.setSerialNumber(config.getSerialNumber());

            this.heartbeatMessage.setWorldWideName(config.getWorldWideName());

            // set port to heart beat message
            this.heartbeatMessage.setPort(config.getPort());

+136 −132
Original line number Diff line number Diff line
@@ -40,14 +40,13 @@ import com.seagate.kinetic.heartbeat.message.OperationCounter;
import com.seagate.kinetic.proto.Kinetic.Command;
import com.seagate.kinetic.proto.Kinetic.Command.GetLog.Configuration;
import com.seagate.kinetic.proto.Kinetic.Command.GetLog.Limits;
import com.seagate.kinetic.proto.Kinetic.Command.MessageType;
import com.seagate.kinetic.proto.Kinetic.Command.PinOperation.PinOpType;

import com.seagate.kinetic.proto.Kinetic.Command.Security.ACL;
import com.seagate.kinetic.proto.Kinetic.Command.Status.StatusCode;
import com.seagate.kinetic.proto.Kinetic.Local;
import com.seagate.kinetic.proto.Kinetic.Message;
import com.seagate.kinetic.proto.Kinetic.Message.AuthType;
import com.seagate.kinetic.proto.Kinetic.Command.MessageType;
import com.seagate.kinetic.proto.Kinetic.Command.Security.ACL;
import com.seagate.kinetic.simulator.heartbeat.Heartbeat;
import com.seagate.kinetic.simulator.internal.p2p.P2POperationHandler;
import com.seagate.kinetic.simulator.io.provider.nio.NioEventLoopGroupManager;
@@ -95,8 +94,8 @@ public class SimulatorEngine implements MessageService {
            .getName());

    // protocol version
    public static final String PROTOCOL_VERSION = 
            Local.getDefaultInstance().getProtocolVersion();
    public static final String PROTOCOL_VERSION = Local.getDefaultInstance()
            .getProtocolVersion();

    private SimulatorConfiguration config = null;

@@ -217,7 +216,8 @@ public class SimulatorEngine implements MessageService {
            // init network io service
            this.initIoService();

            logger.info("simulator protocol version = " + SimulatorConfiguration.getProtocolVersion());
            logger.info("simulator protocol version = "
                    + SimulatorConfiguration.getProtocolVersion());

        } catch (Exception e) {
            e.printStackTrace();
@@ -418,12 +418,9 @@ public class SimulatorEngine implements MessageService {
        logger.fine(sb.toString());
    }

    private static String kineticHome(SimulatorConfiguration config) {
    public static String kineticHome(SimulatorConfiguration config) {

        String defaultHome = System.getProperty("user.home") + File.separator
                + "kinetic";
        String kineticHome = config.getProperty(
                SimulatorConfiguration.KINETIC_HOME, defaultHome);
        String kineticHome = config.getSimulatorHome();

        File lchome = new File(kineticHome);
        if (!lchome.exists()) {
@@ -463,25 +460,22 @@ public class SimulatorEngine implements MessageService {
                // perform pin op
                PinOperationHandler.handleOperation(kmreq, kmresp, this);
            } else if (mtype == MessageType.FLUSHALLDATA) {
                commandBuilder.getHeaderBuilder()
                .setMessageType(MessageType.FLUSHALLDATA_RESPONSE);
                commandBuilder.getHeaderBuilder().setMessageType(
                        MessageType.FLUSHALLDATA_RESPONSE);
                logger.warning("received flush data command, this is a no op on simulator at this time ...");
            } else if (mtype == MessageType.NOOP) {
                commandBuilder.getHeaderBuilder()
                .setMessageType(MessageType.NOOP_RESPONSE);
            } else if (kmreq.getCommand().getBody()
                    .hasKeyValue()) {
                commandBuilder.getHeaderBuilder().setMessageType(
                        MessageType.NOOP_RESPONSE);
            } else if (kmreq.getCommand().getBody().hasKeyValue()) {
                KVOp.Op(aclmap, store, kmreq, kmresp);
            } else if (mtype == MessageType.GETKEYRANGE) {
                RangeOp.operation(store, kmreq, kmresp, aclmap);
            } else if (kmreq.getCommand().getBody()
                    .hasSecurity()) {
                boolean hasPermission = SecurityHandler.checkPermission(
                        kmreq, kmresp, aclmap);
            } else if (kmreq.getCommand().getBody().hasSecurity()) {
                boolean hasPermission = SecurityHandler.checkPermission(kmreq,
                        kmresp, aclmap);
                if (hasPermission) {
                    synchronized (this.hmacKeyMap) {
                        SecurityHandler.handleSecurity(kmreq,
                                kmresp, this);
                        SecurityHandler.handleSecurity(kmreq, kmresp, this);
                        this.hmacKeyMap = HmacStore.getHmacKeyMap(aclmap);
                    }
                }
@@ -503,8 +497,7 @@ public class SimulatorEngine implements MessageService {
                if (hasPermission) {
                    GetLogHandler.handleGetLog(this, kmreq, kmresp);
                }
            } else if (kmreq.getCommand().getBody()
                    .hasP2POperation()) {
            } else if (kmreq.getCommand().getBody().hasP2POperation()) {

                // check permission
                boolean hasPermission = P2POperationHandler.checkPermission(
@@ -520,28 +513,26 @@ public class SimulatorEngine implements MessageService {
            }
        } catch (DeviceLockedException ire) {

            int number = kmreq.getCommand().getHeader()
                    .getMessageType()
            int number = kmreq.getCommand().getHeader().getMessageType()
                    .getNumber() - 1;

            commandBuilder.getHeaderBuilder()
            .setMessageType(MessageType.valueOf(number));
            commandBuilder.getHeaderBuilder().setMessageType(
                    MessageType.valueOf(number));

            commandBuilder.getStatusBuilder().setCode(
                    StatusCode.DEVICE_LOCKED);
            commandBuilder.getStatusBuilder().setCode(StatusCode.DEVICE_LOCKED);

            commandBuilder.getStatusBuilder().setStatusMessage("Device is locked");
            commandBuilder.getStatusBuilder().setStatusMessage(
                    "Device is locked");

        } catch (Exception e) {

            logger.log(Level.WARNING, e.getMessage(), e);

            int number = kmreq.getCommand().getHeader()
                    .getMessageType()
            int number = kmreq.getCommand().getHeader().getMessageType()
                    .getNumber() - 1;

            commandBuilder.getHeaderBuilder()
            .setMessageType(MessageType.valueOf(number));
            commandBuilder.getHeaderBuilder().setMessageType(
                    MessageType.valueOf(number));

            logger.log(Level.WARNING, e.getMessage(), e);
        } finally {
@@ -604,8 +595,7 @@ public class SimulatorEngine implements MessageService {

            Message response = ((Message.Builder) kmresp.getMessage()).build();

            MessageType mtype = kmreq.getCommand().getHeader()
                    .getMessageType();
            MessageType mtype = kmreq.getCommand().getHeader().getMessageType();

            int inCount = 0;

@@ -819,20 +809,26 @@ public class SimulatorEngine implements MessageService {
    /**
     * put connection/connection info into the connection map.
     * 
     * @param connection the key for the entry
     * @param cinfo value of the entry
     * @return the previous value associated with key, or null if there was no mapping for key
     * @param connection
     *            the key for the entry
     * @param cinfo
     *            value of the entry
     * @return the previous value associated with key, or null if there was no
     *         mapping for key
     */
    public static ConnectionInfo putConnectionInfo (Object connection, ConnectionInfo cinfo) {
    public static ConnectionInfo putConnectionInfo(Object connection,
            ConnectionInfo cinfo) {
        return connectionMap.put(connection, cinfo);
    }

    /**
     * Get connection info based on the specified key.
     * 
     * @param connection key to get the connection info.
     * @param connection
     *            key to get the connection info.
     * 
     * @return the value to which the specified key is mapped, or null if this map contains no mapping for the key
     * @return the value to which the specified key is mapped, or null if this
     *         map contains no mapping for the key
     */
    public static ConnectionInfo getConnectionInfo(Object connection) {
        return connectionMap.get(connection);
@@ -840,20 +836,26 @@ public class SimulatorEngine implements MessageService {

    /**
     * remove the value of the specified key.
     * @param connection the key od the entry that needs to be removed
     * @return the previous value associated with key, or null if there was no mapping for key
     * 
     * @param connection
     *            the key od the entry that needs to be removed
     * @return the previous value associated with key, or null if there was no
     *         mapping for key
     */
    public static ConnectionInfo removeConnectionInfo(Object connection) {
        return connectionMap.remove(connection);
    }

    /**
     * register a new connection. A new connection info instance is created and associated with the connection.
     * register a new connection. A new connection info instance is created and
     * associated with the connection.
     * 
     * @param connection the new connection to be added to the connection map.
     * @param connection
     *            the new connection to be added to the connection map.
     * 
     * @return the connection info instance associated with the connection.
     */
    @Override
    public ConnectionInfo registerNewConnection(ChannelHandlerContext ctx) {
        ConnectionInfo info = newConnectionInfo();
        putConnectionInfo(ctx, info);
@@ -928,8 +930,8 @@ public class SimulatorEngine implements MessageService {
    }

    /**
     * Get next available unique connection id based on timestamp. The Id is guarantees to be unique for simulators 
     * running within the same JVM.
     * Get next available unique connection id based on timestamp. The Id is
     * guarantees to be unique for simulators running within the same JVM.
     * 
     * @return next available unique connection ID based on timestamp.
     */
@@ -938,7 +940,8 @@ public class SimulatorEngine implements MessageService {
        // current time
        long id = System.currentTimeMillis();

        // check if duplicate.  enforce so that it is later than the time that this JVM is started.
        // check if duplicate. enforce so that it is later than the time that
        // this JVM is started.
        if (id <= lastConnectionId) {
            // increase one so its unique.
            id = lastConnectionId + 1;
@@ -980,6 +983,7 @@ public class SimulatorEngine implements MessageService {

    /**
     * Lock/unlock the device/simulator
     * 
     * @param flag
     */
    public void setDeviceLocked(boolean flag) {
+15 −66
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;

import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
@@ -44,13 +43,10 @@ public abstract class ConfigurationUtil {

    private final static Logger logger = Logger
            .getLogger(ConfigurationUtil.class.getName());
    public final static String VENDER = "Seagate";
    public final static String MODEL = "Simulator";
    
    public static final String SERIAL_PREFIX = "SIMULATOR-SN-";
    public final static String VENDER = SimulatorConfiguration.VENDER;
    public final static String MODEL = SimulatorConfiguration.MODEL;

    //public final static byte[] SERIAL_NUMBER = "93C3DAFD-C894-3C88-A4B0-632A90D2A04B"
    //        .getBytes(Charset.forName("UTF-8"));
    // public static final String SERIAL_PREFIX = "SIMULATOR-SN-";

    public final static String COMPILATION_DATE = new Date().toString();
    public final static String PROTOCOL_COMPILATION_DATE = new Date()
@@ -66,10 +62,11 @@ public abstract class ConfigurationUtil {
        configuration.setVendor(VENDER);
        configuration.setModel(MODEL);

        // get serial no for this instance
        String sn = getSerialNumber(engine);
        configuration.setSerialNumber(ByteString.copyFrom(
                config.getSerialNumber(), "UTF8"));

        configuration.setSerialNumber(ByteString.copyFrom(sn, "UTF8"));
        configuration.setWorldWideName(ByteString.copyFrom(
                config.getWorldWideName(), "UTF8"));

        configuration.setCompilationDate(COMPILATION_DATE);
        configuration.setProtocolCompilationDate(PROTOCOL_COMPILATION_DATE);
@@ -159,52 +156,4 @@ public abstract class ConfigurationUtil {

        return sb.toString();
    }
    
    /**
     * calculate serial no.
     * <p>
     * A simulator instance serial number is calculated as follows.
     * <p> 
     * SN = SERIAL_PREFIX + ip + "-" + khomeHash + "-" + persistHome;
     * 
     * @param engine simulator engine
     * 
     * @return serial number for the specified instance of simulator
     */
    private static String getSerialNumber (SimulatorEngine engine) {
        
        SimulatorConfiguration config = engine.getServiceConfiguration();
        
        int khomeHash = Math.abs(engine.getKineticHome().hashCode());
        
        // get persist home name, use port# if not set
        String persistHome = config.getProperty(SimulatorConfiguration.PERSIST_HOME, String.valueOf(config.getPort()));
        
        //int phomeHash = Math.abs(persistHome.hashCode());
        
        // default ip of this instance
        String ip = "127.0.0.1";
        
        try {
            // get from Java API
            ip = InetAddress.getLocalHost().getHostAddress();
        } catch (Exception e) {
            ;
        }
        
        // construct sn
        String sn = SERIAL_PREFIX + ip + "-" + khomeHash + "-" + persistHome;
        
        // replace '_' with '-'
        sn = sn.replace('_', '-');
        
        // replace '.' with '-'
        sn = sn.replace('.', '-');
        
        // convert to upper case
        sn = sn.toUpperCase();
        
        // return sn for this instance
        return sn;
    }
}
Loading