#!/bin/bash
# Emulate dw_wlm_cli (Cray's DataWarp interface) for testing purposes
# See "Flags=EmulateCray" in burst_buffer.conf man page
if [ $2 == "create_persistent" ]; then
   echo 'created'
fi
if [ $2 == "data_in" ]; then
   sleep 100
#   echo 'badness...'
#   exit 1
fi
if [ $2 == "data_out" ]; then
   sleep 1
#   echo 'badness...'
#   exit 1
fi
if [ $2 == "destroy_persistent" ]; then
   sleep 0.1
fi
if [ $2 == "job_process" ]; then
   sleep 0.1
fi
if [ $2 == "paths" ]; then
   if [ $7 == "--pathfile" ]; then
      echo 'DWPATHS=/tmp/dw' > $8
   fi
fi
if [ $2 == "pre_run" ]; then
   sleep 0.1
#   echo 'badness...'
#   exit 1
fi
if [ $2 == "post_run" ]; then
   sleep 0.1
fi
if [ $2 == "pools" ]; then
#   echo '{ "pools": [ { "id":"dwcache", "units":"bytes", "granularity":16777216, "quantity":2048, "free":2048 } ] }'
   echo '{ "pools": [ { "id":"dwcache", "units":"bytes", "granularity":16777216, "quantity":2048, "free":2048 }, { "id":"test_pool", "units":"bytes", "granularity":16777216, "quantity":2048, "free":2048 } ] }'

fi
if [ "$2" = "real_size" ] ; then
   echo '{ "token":"job.1234", "capacity":17592186044416, "units":"bytes" }'
fi
if [ $2 == "setup" ]; then
   sleep 0.1
fi
if [ $2 == "show_configurations" ]; then
   echo '{ "configurations": [ ] }'
fi
if [ $2 == "show_instances" ]; then
   echo '{ "instances": [
{"capacity": {"bytes": 1099511627776, "nodes": 2}, "created": 1478231657, "expiration": 0, "expired": false, "id": 74, "intact": true, "label": "alpha", "limits": {"write_window_length": 86400, "write_window_multiplier": 10}, "links": {"configurations": [72], "session": 74}, "public": true, "state": {"actualized": true, "fuse_blown": false, "goal": "create", "mixed": false, "transitioning": false}},
 {"capacity": {"bytes": 1099511627776, "nodes": 2}, "created": 1478232104, "expiration": 0, "expired": false, "id": 75, "intact": true, "label": "I75-0", "limits": {"write_window_length": 86400, "write_window_multiplier": 10}, "links": {"configurations": [73], "session": 75}, "public": false, "state": {"actualized": true, "fuse_blown": false, "goal": "create", "mixed": false, "transitioning": false}}
] }'
fi

# Create a job with ID 347 or the buffer will get torn down at slurmctld startup
if [ $2 == "show_sessions" ]; then
   echo '{ "sessions": [
 {"created": 1478231657, "creator": "CLI", "expiration": 0, "expired": false, "id": 74, "links": {"client_nodes": []}, "owner": 1001, "state": {"actualized": true, "fuse_blown": false, "goal": "create", "mixed": false, "transitioning": false}, "token": "alpha"},
{"created": 1478232104, "creator": "SLURM", "expiration": 0, "expired": false, "id": 75, "links": {"client_nodes": ["nid00039"]}, "owner": 1001, "state": {"actualized": true, "fuse_blown": false, "goal": "create", "mixed": false, "transitioning": false}, "token": "347"}
] }'
fi
if [ $2 == "teardown" ]; then
   sleep 0.1
# exit 1
fi

exit 0
