Commit 33710d40 authored by chiaming2000's avatar chiaming2000
Browse files

Added Ping example to ping kinetic drive or simulator.

parent 526dbde6
Loading
Loading
Loading
Loading

bin/ping.sh

0 → 100755
+31 −0
Original line number Diff line number Diff line
#! /usr/bin/env bash

BASE_DIR=`dirname "$0"`/..
BASE_DIR=`cd "$BASE_DIR"; pwd`
#echo "BASE_DIR=$BASE_DIR"

JAVA=""
if [ "$JAVA_HOME" != "" ]; then
    JAVA=$JAVA_HOME/bin/java
else
   echo "JAVA_HOME must be set."
   exit 1
fi

#Set the classpath

if [ "$CLASSPATH" != "" ]; then
   CLASSPATH=${CLASSPATH}:$JAVA_HOME/lib/tools.jar
else
   CLASSPATH=$JAVA_HOME/lib/tools.jar
fi

for f in $BASE_DIR/kinetic-test/target/*.jar; do
   CLASSPATH=${CLASSPATH}:$f
done

CLASSPATH=${CLASSPATH}:$BASE_DIR/kinetic-test/target/test-classes

echo "CLASSPATH=$CLASSPATH"

exec "$JAVA" -classpath "$CLASSPATH" com.seagate.kinetic.example.client.Ping "$@"
+7 −3
Original line number Diff line number Diff line
@@ -5,8 +5,8 @@ Kinetic Simulator/Admin Command Line Interface (CLI).
1. Define JAVA_HOME environment variable (example: google 'how to set JAVA_HOME on Mac).

2. Run "mvn clean package" in <Kinetic-Folder>, verify 
   <Kinetic-Folder>/kinetic-simulator/target/kinetic-simulator-0.6.0.2-SNAPSHOT-jar-with-dependencies.jar 
   <Kinetic-Folder>/kinetic-client/target/kinetic-client-0.6.0.2-SNAPSHOT-jar-with-dependencies.jar
   <Kinetic-Folder>/kinetic-simulator/target/kinetic-simulator-0.7.0.2-SNAPSHOT-jar-with-dependencies.jar 
   <Kinetic-Folder>/kinetic-client/target/kinetic-client-0.7.0.2-SNAPSHOT-jar-with-dependencies.jar
   exist.

3. To start Kinetic simulator:
@@ -42,12 +42,16 @@ Kinetic Simulator/Admin Command Line Interface (CLI).
            cd <Kinetic-Folder>/bin
            sh startSimulator.sh -help
            
7. To ping the drive or simulator (Linux & Mac):
	    cd <Kinetic-Folder>/bin
	    sh ping.sh [host] [host port]

Run smoke test against simulator or kinetic drive
==================================
Make sure one instance of simulator or kinetic drive is running.

1. Run "mvn clean package" in <Kinetic-Folder> or <Kinetic-Folder>/kinetic-test, verify 
   <Kinetic-Folder>/kinetic-test/target/kinetic-test-0.6.0.2-SNAPSHOT-jar-with-dependencies.jar 
   <Kinetic-Folder>/kinetic-test/target/kinetic-test-0.7.0.2-SNAPSHOT-jar-with-dependencies.jar 
   <Kinetic-Folder>/kinetic-test/target/smoke-tests.jar
   exist.

+91 −0
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 program 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.
 *
 */
package com.seagate.kinetic.example.client;

import kinetic.client.ClientConfiguration;

import kinetic.client.KineticClient;
import kinetic.client.KineticClientFactory;
import kinetic.client.KineticException;

/**
 * Kinetic Ping usage example.
 */
public class Ping {

    public static void ping(String host, int port) throws KineticException, InterruptedException {

        // kinetic client
        KineticClient client = null;

        // Client configuration and initialization
        ClientConfiguration clientConfig = new ClientConfiguration();
        
        clientConfig.setHost(host);
        clientConfig.setPort(port);
        
        // create client instance
        client = KineticClientFactory.createInstance(clientConfig);

        while (true) {
            // ping server
            long time = client.noop();
            //write output to console
            System.out.println("kinetic ping runtrip time: " + time
                    + " milli seconds., ping host=" + clientConfig.getHost()
                    + ", port=" + clientConfig.getPort());
            
            //sleep for two seconds.
            Thread.sleep(1000);
        }

        // close kinetic client
        // client.close();
    }

    /**
     * Ping a kinetic service and prints the rundtrip time.
     * 
     * @param args no used.
     * @throws KineticException if any errors occurred.
     * @throws InterruptedException if interrupted.
     */
	public static void main(String[] args) throws KineticException,
	InterruptedException {
	    
	    // default host/port
	    String host = System.getProperty("kinetic.host", "localhost");
	    String sport = System.getProperty("kinetic.port", "8123");
	    int port = Integer.parseInt(sport);
	    
	    // over-ride the default host
	    if (args.length > 0) {
	        host = args[0];
	    }
	    
	    //over-ride the default port
	    if (args.length > 1) {
	        port = Integer.parseInt(args[1]);
	    }
	    
	    // launch ping
	    Ping.ping(host, port);
	}
}