| 1 | #! /bin/shscip-shell filesystem . . `/bin/sh`. |
| 2 | |
| 3 | #set -x |
| 4 | |
| 5 | # The type of host. Could be : |
| 6 | # - server |
| 7 | # - frontend |
| 8 | # - node |
| 9 | SCRIPT_PREFIX=oar_resources_setup_as_ |
| 10 | SCRIPT_BASENAME=$(basenamescip-shell system . . basename. $0) |
| 11 | TYPE=${SCRIPT_BASENAME##$SCRIPT_PREFIX} |
| 12 | |
| 13 | THIS_HOSTNAME=$1 |
| 14 | shift |
| 15 | |
| 16 | # The first node is the server |
| 17 | SERVER_HOSTNAME=$1 |
| 18 | shift |
| 19 | |
| 20 | # The second node is the frontend |
| 21 | FRONTEND_HOSTNAME=$1 |
| 22 | shift |
| 23 | |
| 24 | # the other nodes are compute nodes. |
| 25 | NODE_HOSTNAME_LISTFILE=$1 |
| 26 | shift |
| 27 | |
| 28 | CORE_FACTOR=$1 |
| 29 | shift |
| 30 | |
| 31 | CPU_FACTOR=$1 |
| 32 | shift |
| 33 | |
| 34 | |
| 35 | openssh_cmdscip-shell shell shell-project 0.0.0 openssh_cmd().() { |
| 36 | host=$1 |
| 37 | shift |
| 38 | cmd=$* |
| 39 | suscip-shell system . . su. - oar -c "ssh -p 6667 $host $cmd" |
| 40 | } |
| 41 | |
| 42 | # |
| 43 | # Set oar with "normal ressources" |
| 44 | # |
| 45 | normal_resources_setupscip-shell shell shell-project 0.0.0 normal_resources_setup().() { |
| 46 | if [scip-shell system . . `[`. ! -f "$NODE_HOSTNAME_LISTFILE" ]; then |
| 47 | echoscip-shell system . . echo. "Unable to read the node file list"; |
| 48 | fi |
| 49 | |
| 50 | catscip-shell system . . cat. "$NODE_HOSTNAME_LISTFILE" > /tmp/compute_nodesscip-shell filesystem . . `/tmp/compute_nodes`. |
| 51 | oar_resources_init /tmp/compute_nodesscip-shell filesystem . . `/tmp/compute_nodes`. << EOF |
| 52 | yes |
| 53 | yes |
| 54 | EOF |
| 55 | shscip-shell system . . sh. /tmp/oar_resources_init.txtscip-shell filesystem . . `/tmp/oar_resources_init.txt`. |
| 56 | } |
| 57 | |
| 58 | dummy_resources_setupscip-shell shell shell-project 0.0.0 dummy_resources_setup().() { |
| 59 | if [scip-shell system . . `[`. ! -f "$NODE_HOSTNAME_LISTFILE" ]; then |
| 60 | echoscip-shell system . . echo. "Unable to read the node file list"; |
| 61 | fi |
| 62 | |
| 63 | tot_cpt_cpu=0 |
| 64 | tot_cpt_core=0 |
| 65 | |
| 66 | tmp_res=$(mktempscip-shell system . . mktemp.) |
| 67 | chownscip-shell system . . chown. oar:oar $tmp_res |
| 68 | |
| 69 | PATH=/usr/local/sbin:/usr/sbin:$PATH |
| 70 | oarproperty -a cpu |
| 71 | oarproperty -a core |
| 72 | oarproperty -c -a host |
| 73 | oarproperty -a cpuset |
| 74 | oarproperty -a mem |
| 75 | |
| 76 | echoscip-shell system . . echo. -n "[" > $tmp_res |
| 77 | for HOST in `catscip-shell system . . cat. $NODE_HOSTNAME_LISTFILE|sortscip-shell system . . sort. -u` ; do |
| 78 | CPUS=$(openssh_cmdscip-shell shell shell-project 0.0.0 openssh_cmd(). $HOST lscpu -p | tailscip-shell system . . tail. -n+5 | cutscip-shell system . . cut. -d',' -f 3 | uniqscip-shell system . . uniq. | wcscip-shell system . . wc. -l) |
| 79 | TOTAL_CORES=$(openssh_cmdscip-shell shell shell-project 0.0.0 openssh_cmd(). $HOST lscpu -p | tailscip-shell system . . tail. -n+5 | cutscip-shell system . . cut. -d',' -f 2 | uniqscip-shell system . . uniq. | wcscip-shell system . . wc. -l) |
| 80 | CORES=$(($TOTAL_CORES / $CPUS)) |
| 81 | EMUL_CPUS=$(($CPUS * $CPU_FACTOR)) |
| 82 | EMUL_CORES=$(($CORES * $CORE_FACTOR)) |
| 83 | |
| 84 | for cpt_cpu in $(seqscip-shell system . . seq. `exprscip-shell system . . expr. $tot_cpt_cpu` 1 `exprscip-shell system . . expr. $EMUL_CPUS + $tot_cpt_cpu - 1`); do |
| 85 | for cpt_core in $(seqscip-shell system . . seq. `exprscip-shell system . . expr. $tot_cpt_core` 1 `exprscip-shell system . . expr. $EMUL_CORES + $tot_cpt_core - 1`); do |
| 86 | |
| 87 | echoscip-shell system . . echo. -n "{\"hostname\":\"$HOST\", \"cpu\":\"$cpt_cpu\", \"core\":\"$cpt_core\", \"cpuset\":\"$(exprscip-shell system . . expr. $cpt_core % $TOTAL_CORES)\"}," >> $tmp_res |
| 88 | |
| 89 | tot_cpt_core=`exprscip-shell system . . expr. $tot_cpt_core + 1` |
| 90 | done ; |
| 91 | tot_cpt_cpu=`exprscip-shell system . . expr. $tot_cpt_cpu + 1` |
| 92 | done ; |
| 93 | done |
| 94 | sedscip-shell system . . sed. -e 's/,$/]/' -i $tmp_res |
| 95 | suscip-shell system . . su. - oar -c "curl -x '' -i http://$FRONTEND_HOSTNAME/oarapi/resources -H'Content-Type: application/json' -d @$tmp_res" > /dev/nullscip-shell filesystem . . `/dev/null`. |
| 96 | |
| 97 | } |
| 98 | |
| 99 | |
| 100 | case $TYPE in |
| 101 | normal) |
| 102 | normal_resources_setupscip-shell shell shell-project 0.0.0 normal_resources_setup(). |
| 103 | ;; |
| 104 | dummy) |
| 105 | dummy_resources_setupscip-shell shell shell-project 0.0.0 dummy_resources_setup(). |
| 106 | ;; |
| 107 | *) |
| 108 | echoscip-shell system . . echo. "$0: the type $TYPE is invalid. It could be currently only 'normal'. Failing." |
| 109 | exit 1 |
| 110 | ;; |
| 111 | esac |