#!/usr/bin/env bash

runSets="X1"
for run in $runSets ; do

   MID="messung-$run"
   PR="-loglevel=3 -distancestep=75"
   PE="-poolhandle=PoolOne -calcapp -rereginterval=3333 -policy=LeastUsedDPF:0.00001 -capmaxjobs=5 -loglevel=3"
   PU="-poolhandle=PoolOne -jobinterval=7.5 -jobsize=1000000 -loglevel=3"


   # ------ Registrars ------------------------------------------------------
   echo "`date` ========== $MID: Phase S1 - Starting PRs =========="
   ./three-regions-scenario "$MID" "$PR" "$PE" "$PU" start europe pr
   ./three-regions-scenario "$MID" "$PR" "$PE" "$PU" start america pr
   ./three-regions-scenario "$MID" "$PR" "$PE" "$PU" start asia pr
   sleep 30

   # ------ PEs -------------------------------------------------------------
   echo "`date` ========== $MID: Phase S2 - Starting PEs =========="
   ./three-regions-scenario "$MID" "$PR" "$PE" "$PU" start europe pe 5
   ./three-regions-scenario "$MID" "$PR" "$PE" "$PU" start america pe 5
   ./three-regions-scenario "$MID" "$PR" "$PE" "$PU" start asia pe 5
   sleep 30

   # ------ PUs -------------------------------------------------------------
   echo "`date` ========== $MID: Phase S3 - Starting PUs =========="
   ./three-regions-scenario "$MID" "$PR" "$PE" "$PU" start europe pu 15
   ./three-regions-scenario "$MID" "$PR" "$PE" "$PU" start america pu 15
   ./three-regions-scenario "$MID" "$PR" "$PE" "$PU" start asia pu 15

   # ========================================================================
   sleep 120   # *** Wartezeit ***


   # ========================================================================

   # ------ Shutdown --------------------------------------------------------
   echo "`date` ========== $MID: Phase E1 - Stopping all components  =========="
   ./three-regions-scenario "$MID" "$PR" "$M2PE" "$M2PU" stop europe pu
   ./three-regions-scenario "$MID" "$PR" "$M2PE" "$M2PU" stop america pu
   ./three-regions-scenario "$MID" "$PR" "$M2PE" "$M2PU" stop asia pu
   sleep 10

   ./three-regions-scenario "$MID" "$PR" "$M2PE" "$M2PU" stop europe pe
   ./three-regions-scenario "$MID" "$PR" "$M2PE" "$M2PU" stop america pe
   ./three-regions-scenario "$MID" "$PR" "$M2PE" "$M2PU" stop asia pe
   sleep 10

   ./three-regions-scenario "$MID" "$PR" "$PE" "$PU" stop europe pr
   ./three-regions-scenario "$MID" "$PR" "$PE" "$PU" stop america pr
   ./three-regions-scenario "$MID" "$PR" "$PE" "$PU" stop asia pr
   sleep 10

   # ------ Get results -----------------------------------------------------
   echo "`date` ========== $MID: Phase E2 - Fetching results  =========="
   rm -rf $MID/
   ./three-regions-scenario "$MID" "$PR" "$PE" "$PU" results

   echo "`date` ========== $MID: Completed! ============================"
   echo ""
   echo ""

done
