To use Sheepdog with puppy, please run following commands on each machine. $ autoconf $ ./configure --with-corosync $ make $ ./script/start-puppies If you don't specify `--with-corosync' argument, Java dog program will be used as a cluster manager daemon. Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp> --- Makefile.in | 6 +- configure.in | 66 ++++++++++++++---------- script/check-puppy.pl | 137 +++++++++++++++++++++++++++++++++++++++++++++++++ script/start-puppies | 65 +++++++++++++++++++++++ script/stop-puppies | 33 ++++++++++++ 5 files changed, 277 insertions(+), 30 deletions(-) create mode 100755 script/check-puppy.pl create mode 100755 script/start-puppies create mode 100755 script/stop-puppies diff --git a/Makefile.in b/Makefile.in index 2d12375..826e7f4 100644 --- a/Makefile.in +++ b/Makefile.in @@ -2,17 +2,17 @@ all: cd shepherd; make cd sheep; make - cd dog; make + cd @DOG@; make .PHONY:clean clean: cd shepherd; make clean cd sheep; make clean - cd dog; make clean + cd @DOG@; make clean cd lib; make clean .PHONY:install install: cd shepherd; make install cd sheep; make install - cd dog; make install + cd @DOG@; make install diff --git a/configure.in b/configure.in index a16677b..f6778e1 100644 --- a/configure.in +++ b/configure.in @@ -1,7 +1,7 @@ # -*- Autoconf -*- # Process this file with autoconf to produce a configure script. -AC_PREREQ([2.64]) +AC_PREREQ([2.61]) AC_INIT AC_CONFIG_SRCDIR([lib/net.c]) @@ -9,30 +9,33 @@ AC_CONFIG_SRCDIR([lib/net.c]) AC_PROG_CC AC_PROG_INSTALL AC_PROG_MAKE_SET -if test "$JAVA_HOME" = ""; then - JAVA_HOME=/usr/lib/jvm/java-6-sun -fi -AC_SUBST(JAVA_HOME, $JAVA_HOME) -AC_CHECK_FILE($JAVA_HOME/bin/java, , AC_MSG_ERROR("install sun-java6-sdk and define JAVA_HOME to be the root of your Java installation")) -AC_CHECK_FILE($JAVA_HOME/bin/javac, , AC_MSG_ERROR("install sun-java6-sdk and define JAVA_HOME to be the root of your Java installation")) -AC_CHECK_FILE($JAVA_HOME/bin/jar, , AC_MSG_ERROR("install sun-java6-sdk and define JAVA_HOME to be the root of your Java installation")) -if test "$JAVA_LIB" = ""; then - JAVA_LIB=/usr/share/java -fi -AC_SUBST(JAVA_LIB, $JAVA_LIB) -AC_CHECK_FILE($JAVA_LIB/jgroups-all.jar, , AC_MSG_ERROR("install libjgroups-java and define JAVA_LIB to be the root of the installation")) -AC_CHECK_FILE($JAVA_LIB/commons-daemon.jar, , AC_MSG_ERROR("install libcommons-daemon-java and define JAVA_LIB to be the root of the installation")) -AC_CHECK_FILE($JAVA_LIB/commons-cli.jar, , AC_MSG_ERROR("install libcommons-cli-java and define JAVA_LIB to be the root of the installation")) -AC_CHECK_FILE($JAVA_LIB/commons-logging.jar, , AC_MSG_ERROR("install libcommons-logging-java and define JAVA_LIB to be the root of the installation")) -AC_CHECK_FILE($JAVA_LIB/log4j-1.2.jar, , AC_MSG_ERROR("install liblog4j1.2-java and define JAVA_LIB to be the root of the installation")) -AC_CHECK_PROG(ANT, ant, ant, no) -if test "$ANT" = no ; then - AC_MSG_ERROR(could not find ant) -fi -AC_CHECK_PROG(JSVC, jsvc, jsvc, no) -if test "$JSVC" = no ; then - AC_MSG_ERROR(could not find jsvc) -fi + +AC_ARG_WITH([corosync], [AS_HELP_STRING([--with-corosync], + [enable experimental support for corosync])], + [AC_SUBST(DOG, puppy)], + [AC_SUBST(DOG, dog)]) + +AS_IF([test "$DOG" = "puppy"], [ + AC_CHECK_LIB([cpg], [main], , AC_MSG_ERROR("could not find CPG library")) +], [ + # use JVM + AS_IF([test "$JAVA_HOME" = ""], [JAVA_HOME=/usr/lib/jvm/java-6-sun]) + AC_SUBST(JAVA_HOME, $JAVA_HOME) + AC_CHECK_FILE($JAVA_HOME/bin/java, , AC_MSG_ERROR("install sun-java6-sdk and define JAVA_HOME to be the root of your Java installation")) + AC_CHECK_FILE($JAVA_HOME/bin/javac, , AC_MSG_ERROR("install sun-java6-sdk and define JAVA_HOME to be the root of your Java installation")) + AC_CHECK_FILE($JAVA_HOME/bin/jar, , AC_MSG_ERROR("install sun-java6-sdk and define JAVA_HOME to be the root of your Java installation")) + AS_IF([test "$JAVA_LIB" = ""], [JAVA_LIB=/usr/share/java]) + AC_SUBST(JAVA_LIB, $JAVA_LIB) + AC_CHECK_FILE($JAVA_LIB/jgroups-all.jar, , AC_MSG_ERROR("install libjgroups-java and define JAVA_LIB to be the root of the installation")) + AC_CHECK_FILE($JAVA_LIB/commons-daemon.jar, , AC_MSG_ERROR("install libcommons-daemon-java and define JAVA_LIB to be the root of the installation")) + AC_CHECK_FILE($JAVA_LIB/commons-cli.jar, , AC_MSG_ERROR("install libcommons-cli-java and define JAVA_LIB to be the root of the installation")) + AC_CHECK_FILE($JAVA_LIB/commons-logging.jar, , AC_MSG_ERROR("install libcommons-logging-java and define JAVA_LIB to be the root of the installation")) + AC_CHECK_FILE($JAVA_LIB/log4j-1.2.jar, , AC_MSG_ERROR("install liblog4j1.2-java and define JAVA_LIB to be the root of the installation")) + AC_CHECK_PROG(ANT, ant, ant, no) + AS_IF([test "$ANT" = no], AC_MSG_ERROR(could not find ant)) + AC_CHECK_PROG(JSVC, jsvc, jsvc, no) + AS_IF([test "$JSVC" = no], AC_MSG_ERROR(could not find jsvc)) +]) # Checks for libraries. AC_CHECK_LIB([crypto], [main], , AC_MSG_ERROR("could not find SSL development libraries")) @@ -40,17 +43,22 @@ AC_CHECK_LIB([ncurses], [main], , AC_MSG_ERROR("could not find ncurses libraries AC_CHECK_LIB([pthread], [main], , AC_MSG_ERROR("could not find pthread libraries")) # Checks for header files. +AC_HEADER_DIRENT +AC_HEADER_SYS_WAIT AC_CHECK_HEADERS([arpa/inet.h fcntl.h inttypes.h mntent.h netdb.h netinet/in.h stdint.h stdlib.h string.h sys/ioctl.h sys/socket.h sys/statvfs.h sys/time.h syslog.h unistd.h]) # Checks for archtecture. AC_C_BIGENDIAN([AC_MSG_ERROR("big endian architecture is not supported")]) # Checks for typedefs, structures, and compiler characteristics. +AC_C_CONST AC_C_INLINE AC_TYPE_INT32_T AC_TYPE_INT64_T AC_TYPE_PID_T AC_TYPE_SIZE_T +AC_HEADER_TIME +AC_STRUCT_TM AC_TYPE_UINT16_T AC_TYPE_UINT32_T AC_TYPE_UINT64_T @@ -60,10 +68,14 @@ AC_TYPE_UINT8_T AC_FUNC_FORK AC_FUNC_GETMNTENT AC_FUNC_MALLOC -AC_CHECK_FUNCS([dup2 ftruncate getmntent localtime_r memset mkdir socket strcasecmp strchr strdup strerror strtoul]) +AC_FUNC_MEMCMP +AC_FUNC_STAT +AC_FUNC_STRFTIME +AC_FUNC_VPRINTF +AC_CHECK_FUNCS([dup2 ftruncate gethostname getmntent gettimeofday localtime_r memset mkdir socket strcasecmp strchr strdup strerror strtoul]) AC_CONFIG_FILES([Makefile - dog/Makefile + $DOG/Makefile lib/Makefile sheep/Makefile shepherd/Makefile]) diff --git a/script/check-puppy.pl b/script/check-puppy.pl new file mode 100755 index 0000000..591618f --- /dev/null +++ b/script/check-puppy.pl @@ -0,0 +1,137 @@ +#!/usr/bin/perl + +use strict; + +my ($store, $min_node, $max_node) = @ARGV; + +$store = "/tmp/".rand(100) unless $store; +$min_node = 3 unless $min_node; +$max_node = 5 unless $max_node; + +sub command { + my ($cmd) = @_; + print "$cmd\n"; + system "$cmd"; +} + +sub start_sdog { + my ($n) = @_; + my $dport = 7000 + $n; + my $sport = 9000 + $n; + &command("./sheep/sheep --dport $dport --sport $sport $store/$n/ -d"); + &command("./puppy/puppy --dport $dport --sport $sport -d"); +} + +sub stop_sdog { + my ($n) = @_; + &command("./script/stop-puppies $n"); +} + +sub shuffle { + my @list =@_; + + for my $i ( 0..$#list ) { + my $rand=int(rand(@list)); + my $tmp=$list[$i]; + $list[$i]=$list[$rand]; + $list[$rand]=$tmp; + } + @list +} + +print("** setup **"); +&command("make clean"); +&command("make"); + +print("kill all sheeps and dogs\n"); +foreach my $n (0..10) { + &stop_sdog($n); +} + +print("clean up $store\n"); +&command("rm $store/[0-9]/*; rm /tmp/sheepdog-700*"); + +print("start up sdogs\n"); +my $node = int(($min_node + $max_node) / 2); +foreach my $n (shuffle(0..$node - 1)) { + &start_sdog($n); +} + +my @join_node = (0..$node-1); +my @leave_node = ($node..$max_node-1); + +sleep(5); +print("make fs\n"); +&command("shepherd mkfs --copies=3"); + +my $min_epoch = 1; +my $max_epoch = 1; +my $vdi = 0; +for (;;) { + my $op = int(rand(9)); + print("op: $op\n"); + if ($op == 0) { # join + next; + } elsif ($op == 1) { # leave + next; + } elsif ($op == 2) { # create + next if (!grep(/0/, @join_node)); + + printf("** create test **\n"); + + &command("qemu-img create -f sheepdog test$vdi ".int(rand(256))."G", 1); + $vdi++; + &command("shepherd info -t vdi -D ".(7000+$join_node[0]), 1); + } elsif ($op == 3) { # snapshot + next if ($vdi == 0); + next if (!grep(/0/, @join_node)); + + printf("** snapshot test **\n"); + + &command("qemu-img snapshot -c name sheepdog:test".int(rand($vdi)), 1); + &command("shepherd info -t vdi -D ".(7000+$join_node[0]), 1); + } elsif ($op == 4) { # clone + next if (!grep(/0/, @join_node)); + my $target_vdi; + my $tag; + my $list=`shepherd info -t vdi | tail -n 3`; + if ($list=~/ : test(\d+)[^g]+g:\s+(\w+), not current/) { + $target_vdi = $1; + $tag = $2; + } else { + next + } + + printf("** clone test **\n"); + + &command("qemu-img create -b sheepdog:test$target_vdi:$tag -f sheepdog test$vdi", 1); + $vdi++; + &command("shepherd info -t vdi -D ".(7000+$join_node[0]), 1); + } elsif ($op == 5) { # lock + next if ($vdi == 0); + + printf("** lock test **\n"); + + &command("shepherd info -t vm -D ".(7000+$join_node[0]), 1); + &command("shepherd debug -o lock_vdi test".int(rand($vdi))); + &command("shepherd info -t vm -D ".(7000+$join_node[1]), 1); + } elsif ($op == 6) { # release + next if ($vdi == 0); + + printf("** release test **\n"); + + &command("shepherd info -t vm -D ".(7000+$join_node[0]), 1); + &command("shepherd debug -o release_vdi test".int(rand($vdi))); + &command("shepherd info -t vm -D ".(7000+$join_node[1]), 1); + } elsif ($op == 7) { # update_epoch + next; + } elsif ($op == 8) { # get_node_list + + printf("** get node list test **\n"); + + my $epoch = $min_epoch + int(rand($max_epoch - $min_epoch + 1)); + &command("shepherd info -t dog -e $epoch -D 7000 -D ".(7000+$join_node[0])); + } elsif ($op == 9) { # make fs + next; + } +} diff --git a/script/start-puppies b/script/start-puppies new file mode 100755 index 0000000..3ca100b --- /dev/null +++ b/script/start-puppies @@ -0,0 +1,65 @@ +#!/usr/bin/perl + +# Examples +# +# run-dogs.pl -n=5 -d=/tmp/1203 + +$sport = 9000; +$dport = 7000; +$nr = 1; + at hosts = (); +$home = "."; + +$dir = "/tmp/".rand(100); + +while (@ARGV && $ARGV[0] =~ m/^-/) { + $_ = shift(@ARGV); + + if (m/^-n=([0-9]*)$/) { + $nr = $1; + } elsif (m/^-d=(.*)$/) { + $dir = $1; + } elsif (m/^-h=(.*)$/) { + @hosts = &expand(split ':', $1); + } elsif (m/^-H=(.*)$/) { + $home = $1; + } +} + +print("killing all dogs and sheeps...\n\n"); +system("$home/script/stop-puppies [0-100]"); + +my %count; + +foreach $host (grep {!$count{$_}++} @hosts) { + system("$home/script/stop-puppies [0-100]"); +} + +for ($i = 0; $i < $nr; $i++, $sport++, $dport++) { + $_dir = $dir.$i; + if ($hosts[$i]) { + print("ssh $hosts[$i] $home/sheep/sheep --dport $dport --sport $sport $_dir -d\n"); + system("ssh $hosts[$i] $home/sheep/sheep --dport $dport --sport $sport $_dir -d"); + print("ssh $hosts[$i] $home/puppy/puppy --dport $dport --sport $sport -d\n"); + system("ssh $hosts[$i] $home/puppy/puppy --dport $dport --sport $sport -d"); + } else { + print("$home/sheep/sheep --dport $dport --sport $sport $_dir -d\n"); + system("$home/sheep/sheep --dport $dport --sport $sport $_dir -d"); + print("$home/puppy/puppy --dport $dport --sport $sport -d\n"); + system("$home/puppy/puppy --dport $dport --sport $sport -d"); + } +} + +sub expand { + my @hosts = @_; + my @ret = (); + for my $host (@hosts) { + if ($host =~ /\[(\d+)-(\d+)\]/) { + push @ret, &expand(map { $` . $_ . $' } ($1..$2)); + } else { + push @ret, $host; + } + } + return @ret; +} + diff --git a/script/stop-puppies b/script/stop-puppies new file mode 100755 index 0000000..ff10250 --- /dev/null +++ b/script/stop-puppies @@ -0,0 +1,33 @@ +#!/usr/bin/perl + +# Examples +# +# stop-dogs.pl 0 3 4 +# stop-dogs.pl [0-100] + + at index_list = @ARGV; +if (@index_list == 0) { + @index_list = (0); +} + +$dport = 7000; + +foreach $proc (`ps -o pid,args -C sheep -C puppy`) { + foreach $i (@index_list) { + if ($i =~ /\[(\d+)-(\d+)\]/) { + &stop_dog($dport + $_) foreach ($1..$2); + } else { + &stop_dog($dport + $i); + } + } +} + +sub stop_dog { + my ($dport) = @_; + if ($proc =~ /dport $dport/) { + $proc =~ s/^\s+(.*)/$1/; + ($pid, @cmd) = split /\s/, $proc; + print "kill -9 $pid (@cmd)\n"; + system "kill -9 $pid"; + } +} -- 1.5.6.5 |