Project

General

Profile

1
#!/bin/bash
2
#Call a java client class to query metacat automatically and metacat server
3
#will record the performance data into a file. Since we need restart postgres,
4
#this script should be run as root user
5
#Note: before running the script, user should run both "ant jar" and "ant clientjar"
6
#in Metacat to get metaca-client.jar and metacat.jar in build directory. 
7

    
8
#variables
9
JUNIT=/usr/local/devtools/apache-ant/lib/junit-4.3.1.jar
10
METACAT=../build/metacat.jar
11
METACAT_CLIENT=../build/metacat-client.jar
12
UTILITIES=../lib/utilities.jar
13
METACATURL=http://chico.dyndns.org:8081/metacat/metacat
14
QUERY=../test/performance_measure_query
15
TIME=2
16
TOMCATUSER=tao
17

    
18
#copy the java client to build directory
19
rm -rf ../build/tests/
20
mkdir ../build/tests
21
mkdir ../build/tests/edu
22
mkdir ../build/tests/edu/ucsb
23
mkdir ../build/tests/edu/ucsb/nceas
24
mkdir ../build/tests/edu/ucsb/nceas/metacattest
25
cp ../test/edu/ucsb/nceas/metacattest/MetaCatQueryPerformanceTest.java ../build/tests/edu/ucsb/nceas/metacattest/.
26

    
27
#compile the class
28
javac -classpath $JUNIT:$METACAT:$METACAT_CLIENT:$UTILITIES ../build/tests/edu/ucsb/nceas/metacattest/MetaCatQueryPerformanceTest.java 
29

    
30

    
31

    
32

    
33
#Iterate to restart postgres and tomcat, and call java client class
34
for (( i = 0; i < $TIME; i++))
35
do
36
    #retart postgres
37
    /etc/init.d/postgresql-8.2 restart
38
    #Check if posgres restart successfully
39
    successPQL=false;
40
    while [ $successPQL = false ]
41
    do
42
      #if found netstat command has posgres lisenter is ready,
43
      #reset the success value to jump the while loop.
44
      for fn in `netstat -plt | grep postgres`
45
      do
46
        #reset success value
47
        successPQL=true
48
      done
49
    done
50
    echo "success value for restarting postgres is $successPQL"
51

    
52
    #stop tomcat
53
    su - $TOMCATUSER /usr/local/devtools/apache-tomcat-5.5.23/bin/shutdown.sh
54
     #Check if tomcat start successfully
55
    successStop=false;
56
    tomcatRunning=false
57
    while [ $successStop = false ]
58
    do
59
      #if found netstat command still has tcomat lisenter (port 8005) ,
60
      #reset the tomcatRunning value to true
61
      for fn in `netstat -plt | grep 8005`
62
      do
63
        #reset success value
64
        tomcatRunning=true;
65
      done
66
      if [ $tomcatRunning = true ]
67
         then
68
           successStop=false
69
         else
70
           successStop=true
71
      fi
72
    done
73
    echo "success value for stoping tomcat is $successStop"
74
     
75
    #start tomcat
76
   su - $TOMCATUSER  /usr/local/devtools/apache-tomcat-5.5.23/bin/startup.sh
77
    #Check if tomcat start successfully
78
    successStart=false;
79
    while [ $successStart = false ]
80
    do
81
      #if found netstat command has tcomat lisenter (port 8005) is ready,
82
      #reset the success value to jump the while loop.
83
      for fn in `netstat -plt | grep 8005`
84
      do
85
        #reset success value
86
        successStart=true
87
      done
88
    done
89
    echo "success value for starting tomcat is $successStart"
90

    
91

    
92
    #run the class -- query the remote metacat
93
    java -cp $JUNIT:$METACAT:$METACAT_CLIENT:$UTILITIES:../build/tests edu.ucsb.nceas.metacattest.MetaCatQueryPerformanceTest $METACATURL $QUERY
94
    echo "Successfully query the metacat"
95
done
(5-5/6)