From 1b118858229a08f00b76ab2105779c814f0363d0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20B=C3=A9daride?= Date: Thu, 23 May 2013 15:06:31 +0200 Subject: [PATCH 1/1] Add scala masterslave bypass and kill --- buildtools/Cmake/AddTests.cmake | 2 + buildtools/Cmake/DefinePackages.cmake | 2 + buildtools/Cmake/MakeExe.cmake | 2 + .../scala/master_slave_bypass/CMakeLists.txt | 46 +++++++++++++++++++ .../master_slave_bypass/FinalizeTask.scala | 11 +++++ .../scala/master_slave_bypass/Master.scala | 39 ++++++++++++++++ .../scala/master_slave_bypass/MsBypass.scala | 34 ++++++++++++++ .../scala/master_slave_bypass/Slave.scala | 23 ++++++++++ .../scala/master_slave_bypass/bypass.tesh | 11 +++++ .../scala/master_slave_bypass/platform.xml | 29 ++++++++++++ .../scala/master_slave_kill/CMakeLists.txt | 46 +++++++++++++++++++ .../master_slave_kill/FinalizeTask.scala | 13 ++++++ examples/scala/master_slave_kill/Master.scala | 42 +++++++++++++++++ examples/scala/master_slave_kill/MsKill.scala | 37 +++++++++++++++ examples/scala/master_slave_kill/Slave.scala | 34 ++++++++++++++ examples/scala/master_slave_kill/kill.tesh | 13 ++++++ examples/scala/master_slave_kill/platform.xml | 29 ++++++++++++ 17 files changed, 413 insertions(+) create mode 100644 examples/scala/master_slave_bypass/CMakeLists.txt create mode 100644 examples/scala/master_slave_bypass/FinalizeTask.scala create mode 100644 examples/scala/master_slave_bypass/Master.scala create mode 100644 examples/scala/master_slave_bypass/MsBypass.scala create mode 100644 examples/scala/master_slave_bypass/Slave.scala create mode 100644 examples/scala/master_slave_bypass/bypass.tesh create mode 100644 examples/scala/master_slave_bypass/platform.xml create mode 100644 examples/scala/master_slave_kill/CMakeLists.txt create mode 100644 examples/scala/master_slave_kill/FinalizeTask.scala create mode 100644 examples/scala/master_slave_kill/Master.scala create mode 100644 examples/scala/master_slave_kill/MsKill.scala create mode 100644 examples/scala/master_slave_kill/Slave.scala create mode 100644 examples/scala/master_slave_kill/kill.tesh create mode 100644 examples/scala/master_slave_kill/platform.xml diff --git a/buildtools/Cmake/AddTests.cmake b/buildtools/Cmake/AddTests.cmake index a9f938e9c8..b9d48b4332 100644 --- a/buildtools/Cmake/AddTests.cmake +++ b/buildtools/Cmake/AddTests.cmake @@ -445,6 +445,8 @@ if(NOT enable_memcheck) # Scala examples if(enable_scala) set(TESH_CLASSPATH "${CMAKE_BINARY_DIR}/examples/scala/:${SIMGRID_JAR}:${SCALA_JARS}") + ADD_TEST(scala-bypass ${CMAKE_BINARY_DIR}/bin/tesh ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/scala --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/scala ${CMAKE_HOME_DIRECTORY}/examples/scala/master_slave_bypass/bypass.tesh) + ADD_TEST(scala-kill ${CMAKE_BINARY_DIR}/bin/tesh ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/scala --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/scala ${CMAKE_HOME_DIRECTORY}/examples/scala/master_slave_kill/kill.tesh) ADD_TEST(scala-masterslave ${CMAKE_BINARY_DIR}/bin/tesh ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/scala --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/scala ${CMAKE_HOME_DIRECTORY}/examples/scala/masterslave/masterslave.tesh) endif() diff --git a/buildtools/Cmake/DefinePackages.cmake b/buildtools/Cmake/DefinePackages.cmake index 9e426e0914..f2b449aa50 100644 --- a/buildtools/Cmake/DefinePackages.cmake +++ b/buildtools/Cmake/DefinePackages.cmake @@ -834,6 +834,8 @@ set(EXAMPLES_CMAKEFILES_TXT examples/java/tracing/CMakeLists.txt examples/scala/CMakeLists.txt examples/scala/masterslave/CMakeLists.txt + examples/scala/master_slave_bypass/CMakeLists.txt + examples/scala/master_slave_kill/CMakeLists.txt examples/lua/CMakeLists.txt examples/msg/CMakeLists.txt examples/msg/actions/CMakeLists.txt diff --git a/buildtools/Cmake/MakeExe.cmake b/buildtools/Cmake/MakeExe.cmake index 7a6d9f463c..33e9e2e36a 100644 --- a/buildtools/Cmake/MakeExe.cmake +++ b/buildtools/Cmake/MakeExe.cmake @@ -54,6 +54,8 @@ add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/java/tracing) add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/scala) add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/scala/masterslave) +add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/scala/master_slave_bypass) +add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/scala/master_slave_kill) add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/msg/properties) add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/msg/actions) diff --git a/examples/scala/master_slave_bypass/CMakeLists.txt b/examples/scala/master_slave_bypass/CMakeLists.txt new file mode 100644 index 0000000000..f5c954ad9b --- /dev/null +++ b/examples/scala/master_slave_bypass/CMakeLists.txt @@ -0,0 +1,46 @@ +cmake_minimum_required(VERSION 2.6) + +set(example scala_master_slave_bypass) +set(sources + ${CMAKE_CURRENT_SOURCE_DIR}/FinalizeTask.scala + ${CMAKE_CURRENT_SOURCE_DIR}/Master.scala + ${CMAKE_CURRENT_SOURCE_DIR}/MsBypass.scala + ${CMAKE_CURRENT_SOURCE_DIR}/Slave.scala + ) + +if(enable_scala) + add_custom_command( + COMMENT "Building ${example}..." + OUTPUT ${example}_compiled + DEPENDS ${sources} SG_java_jar ${SIMGRID_JAR} + COMMAND ${SCALA_COMPILE} -cp ${SIMGRID_JAR} + -d ${CMAKE_CURRENT_BINARY_DIR}/.. ${sources} + COMMAND ${CMAKE_COMMAND} -E remove ${example}_compiled + COMMAND ${CMAKE_COMMAND} -E touch ${example}_compiled + ) + add_custom_target(${example} ALL DEPENDS ${example}_compiled) +endif() + +set(tesh_files + ${tesh_files} + ${CMAKE_CURRENT_SOURCE_DIR}/bypass.tesh + PARENT_SCOPE + ) +set(xml_files + ${xml_files} + ${CMAKE_CURRENT_SOURCE_DIR}/platform.xml + PARENT_SCOPE + ) +set(examples_src + ${examples_src} + ${sources} + PARENT_SCOPE + ) +set(bin_files + ${bin_files} + PARENT_SCOPE + ) +set(txt_files + ${txt_files} + PARENT_SCOPE + ) diff --git a/examples/scala/master_slave_bypass/FinalizeTask.scala b/examples/scala/master_slave_bypass/FinalizeTask.scala new file mode 100644 index 0000000000..d83759dd0e --- /dev/null +++ b/examples/scala/master_slave_bypass/FinalizeTask.scala @@ -0,0 +1,11 @@ +/* + * Copyright 2006-2012. The SimGrid Team. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. + */ + +package master_slave_bypass +import org.simgrid.msg.Task + +class FinalizeTask extends Task("finalize",0,0) {} diff --git a/examples/scala/master_slave_bypass/Master.scala b/examples/scala/master_slave_bypass/Master.scala new file mode 100644 index 0000000000..5e2fbee647 --- /dev/null +++ b/examples/scala/master_slave_bypass/Master.scala @@ -0,0 +1,39 @@ +/* + * Master of a basic master/slave example in Java + * + * Copyright 2006-2012 The SimGrid Team. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. + */ + +package master_slave_bypass + +import Stream._ +import org.simgrid.msg.HostNotFoundException +import org.simgrid.msg.Msg +import org.simgrid.msg.MsgException +import org.simgrid.msg.Process +import org.simgrid.msg.Task + +class Master(hostname:String, name:String) extends Process(hostname,name) { + + def main(args:Array[String]) { + Msg.info("Master Hello!") + + //Create a slave on host "alice" + try { + Msg.info("Create process on host 'alice'") + new Slave("alice","process2").start() + } catch { + case e:MsgException => println("Process2!") + } + + //Wait for slave "alice" + continually({Task.receive("alice")}) + .takeWhile(!_.isInstanceOf[FinalizeTask]) + .force // to force the list to be compute + + Msg.info("Received Finalize. I'm done. See you!") + } +} diff --git a/examples/scala/master_slave_bypass/MsBypass.scala b/examples/scala/master_slave_bypass/MsBypass.scala new file mode 100644 index 0000000000..563f2501c7 --- /dev/null +++ b/examples/scala/master_slave_bypass/MsBypass.scala @@ -0,0 +1,34 @@ +/* + * Copyright 2006-2012. The SimGrid Team. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. + */ + +package master_slave_bypass + +import org.simgrid.msg.Msg +import org.simgrid.msg.MsgException +import org.simgrid.msg.NativeException + +object MsBypass extends App { + /* This only contains the launcher. If you do nothing more than than you can run + * scala simgrid.msg.Msg + * which also contains such a launcher + */ + + /* initialize the MSG simulation. Must be done before anything else (even logging). */ + Msg.init(args) + Msg.createEnvironment(args(0)) + + /* bypass deployment */ + try { + new Master("bob","process1").start() + } + catch { + case e:MsgException => println("Create processes failed!") + } + + /* execute the simulation. */ + Msg.run() +} diff --git a/examples/scala/master_slave_bypass/Slave.scala b/examples/scala/master_slave_bypass/Slave.scala new file mode 100644 index 0000000000..d8538c43dd --- /dev/null +++ b/examples/scala/master_slave_bypass/Slave.scala @@ -0,0 +1,23 @@ +/* + * Copyright 2006-2012. The SimGrid Team. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. + */ +package master_slave_bypass + +import org.simgrid.msg.HostFailureException +import org.simgrid.msg.HostNotFoundException +import org.simgrid.msg.Msg +import org.simgrid.msg.TimeoutException +import org.simgrid.msg.TransferFailureException +import org.simgrid.msg.Process + +class Slave(hostname:String, name:String) extends Process(hostname, name) { + def main(args:Array[String]) { + Msg.info("Slave Hello!") + val task = new FinalizeTask() + Msg.info("Send finalize!") + task.send("alice") + } +} diff --git a/examples/scala/master_slave_bypass/bypass.tesh b/examples/scala/master_slave_bypass/bypass.tesh new file mode 100644 index 0000000000..6b28603de1 --- /dev/null +++ b/examples/scala/master_slave_bypass/bypass.tesh @@ -0,0 +1,11 @@ +#! tesh + +! output sort +$ java -cp ${classpath:=.} master_slave_bypass/MsBypass ${srcdir:=.}/master_slave_bypass/platform.xml +> [0.000000] [jmsg/INFO] Using regular java threads. Coroutines could speed your simulation up. +> [0.013010] [jmsg/INFO] MSG_main finished; Cleaning up the simulation... +> [alice:process2:(2) 0.000000] [jmsg/INFO] Slave Hello! +> [alice:process2:(2) 0.000000] [jmsg/INFO] Send finalize! +> [bob:process1:(1) 0.000000] [jmsg/INFO] Master Hello! +> [bob:process1:(1) 0.000000] [jmsg/INFO] Create process on host 'alice' +> [bob:process1:(1) 0.013010] [jmsg/INFO] Received Finalize. I'm done. See you! diff --git a/examples/scala/master_slave_bypass/platform.xml b/examples/scala/master_slave_bypass/platform.xml new file mode 100644 index 0000000000..d0faf97219 --- /dev/null +++ b/examples/scala/master_slave_bypass/platform.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/scala/master_slave_kill/CMakeLists.txt b/examples/scala/master_slave_kill/CMakeLists.txt new file mode 100644 index 0000000000..ca978c6449 --- /dev/null +++ b/examples/scala/master_slave_kill/CMakeLists.txt @@ -0,0 +1,46 @@ +cmake_minimum_required(VERSION 2.6) + +set(example scala_master_slave_kill) +set(sources + ${CMAKE_CURRENT_SOURCE_DIR}/FinalizeTask.scala + ${CMAKE_CURRENT_SOURCE_DIR}/Master.scala + ${CMAKE_CURRENT_SOURCE_DIR}/MsKill.scala + ${CMAKE_CURRENT_SOURCE_DIR}/Slave.scala + ) + +if(enable_scala) + add_custom_command( + COMMENT "Building ${example}..." + OUTPUT ${example}_compiled + DEPENDS ${sources} SG_java_jar ${SIMGRID_JAR} + COMMAND ${SCALA_COMPILE} -cp ${SIMGRID_JAR} + -d ${CMAKE_CURRENT_BINARY_DIR}/.. ${sources} + COMMAND ${CMAKE_COMMAND} -E remove ${example}_compiled + COMMAND ${CMAKE_COMMAND} -E touch ${example}_compiled + ) + add_custom_target(${example} ALL DEPENDS ${example}_compiled) +endif() + +set(tesh_files + ${tesh_files} + ${CMAKE_CURRENT_SOURCE_DIR}/kill.tesh + PARENT_SCOPE + ) +set(xml_files + ${xml_files} + ${CMAKE_CURRENT_SOURCE_DIR}/platform.xml + PARENT_SCOPE + ) +set(examples_src + ${examples_src} + ${sources} + PARENT_SCOPE + ) +set(bin_files + ${bin_files} + PARENT_SCOPE + ) +set(txt_files + ${txt_files} + PARENT_SCOPE + ) diff --git a/examples/scala/master_slave_kill/FinalizeTask.scala b/examples/scala/master_slave_kill/FinalizeTask.scala new file mode 100644 index 0000000000..452860b88a --- /dev/null +++ b/examples/scala/master_slave_kill/FinalizeTask.scala @@ -0,0 +1,13 @@ +/* + * Copyright 2006-2012. The SimGrid Team. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. + */ + +package master_slave_kill + +import org.simgrid.msg.Task + +class FinalizeTask extends Task("finalize",0,0) {} + diff --git a/examples/scala/master_slave_kill/Master.scala b/examples/scala/master_slave_kill/Master.scala new file mode 100644 index 0000000000..01dca86b11 --- /dev/null +++ b/examples/scala/master_slave_kill/Master.scala @@ -0,0 +1,42 @@ +/* + * Master of a basic master/slave example in Java + * + * Copyright 2006-2012 The SimGrid Team. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. + */ + +package master_slave_kill + +import Stream._ +import org.simgrid.msg.HostNotFoundException +import org.simgrid.msg.Msg +import org.simgrid.msg.MsgException +import org.simgrid.msg.Process +import org.simgrid.msg.Task + +class Master(hostname:String, name:String) extends Process(hostname, name) { + def main(args:Array[String]) { + Msg.info("Master Hello!") + var process2:Slave = null + + //Create a slave on host "alice" + try { + Msg.info("Create process on host 'alice'") + process2 = new Slave("alice","slave") + process2.start() + } catch { + case e:MsgException => println("Process2!") + } + + //Wait for slave "alice" + continually({Task.receive("mail1")}) + .takeWhile(!_.isInstanceOf[FinalizeTask]) + .force // to force the list to be compute + + Msg.info("Received mail1!") + process2.kill() + Msg.info("Process2 is now killed, should exit now") + } +} diff --git a/examples/scala/master_slave_kill/MsKill.scala b/examples/scala/master_slave_kill/MsKill.scala new file mode 100644 index 0000000000..ec69031c2c --- /dev/null +++ b/examples/scala/master_slave_kill/MsKill.scala @@ -0,0 +1,37 @@ +/* + * Copyright 2006-2012. The SimGrid Team. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. + */ + +package master_slave_kill; + +import org.simgrid.msg.Msg; +import org.simgrid.msg.MsgException; +import org.simgrid.msg.NativeException; + +object MsKill extends App{ + + /* This only contains the launcher. If you do nothing more than than you can run + * scala simgrid.msg.Msg + * which also contains such a launcher + */ + + + /* initialize the MSG simulation. Must be done before anything else (even logging). */ + Msg.init(args) + Msg.createEnvironment(args(0)) + + /* bypass deploymemt */ + try { + val process1 = new Master("bob","master") + process1.start() + } + catch { + case e:MsgException => println("Create processes failed!") + } + + /* execute the simulation. */ + Msg.run() +} diff --git a/examples/scala/master_slave_kill/Slave.scala b/examples/scala/master_slave_kill/Slave.scala new file mode 100644 index 0000000000..38c266a00a --- /dev/null +++ b/examples/scala/master_slave_kill/Slave.scala @@ -0,0 +1,34 @@ +/* + * Copyright 2006-2012. The SimGrid Team. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. + */ +package master_slave_kill + +import org.simgrid.msg.HostFailureException +import org.simgrid.msg.HostNotFoundException +import org.simgrid.msg.Msg +import org.simgrid.msg.MsgException +import org.simgrid.msg.Task +import org.simgrid.msg.TimeoutException +import org.simgrid.msg.TransferFailureException +import org.simgrid.msg.Process + +class Slave(hostname:String, name:String) extends Process(hostname, name) { + def main(args:Array[String]) { + Msg.info("Slave Hello!") + + val task = new FinalizeTask(); + Msg.info("Send Mail1!"); + task.send("mail1"); + + try { + Task.receive("mail2"); + } catch { + case e:MsgException => {Msg.debug("Received failed") + return} + } + Msg.info("Receive Mail2!") + } +} diff --git a/examples/scala/master_slave_kill/kill.tesh b/examples/scala/master_slave_kill/kill.tesh new file mode 100644 index 0000000000..f22d582f9e --- /dev/null +++ b/examples/scala/master_slave_kill/kill.tesh @@ -0,0 +1,13 @@ +#! tesh + +! output sort + +$ java -cp ${classpath:=.} master_slave_kill/MsKill ${srcdir:=.}/master_slave_kill/platform.xml +> [0.000000] [jmsg/INFO] Using regular java threads. Coroutines could speed your simulation up. +> [0.013010] [jmsg/INFO] MSG_main finished; Cleaning up the simulation... +> [alice:slave:(2) 0.000000] [jmsg/INFO] Slave Hello! +> [alice:slave:(2) 0.000000] [jmsg/INFO] Send Mail1! +> [bob:master:(1) 0.000000] [jmsg/INFO] Master Hello! +> [bob:master:(1) 0.000000] [jmsg/INFO] Create process on host 'alice' +> [bob:master:(1) 0.013010] [jmsg/INFO] Received mail1! +> [bob:master:(1) 0.013010] [jmsg/INFO] Process2 is now killed, should exit now diff --git a/examples/scala/master_slave_kill/platform.xml b/examples/scala/master_slave_kill/platform.xml new file mode 100644 index 0000000000..a37f9c87fc --- /dev/null +++ b/examples/scala/master_slave_kill/platform.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- 2.20.1