diff --git a/scripts/cost_calculation.painless b/scripts/cost_calculation.painless new file mode 100644 index 0000000..301ac00 --- /dev/null +++ b/scripts/cost_calculation.painless @@ -0,0 +1,36 @@ +{ + "_id": "cost_calculation", + "found": true, + "script": { + "lang": "painless", + "source": """ + if(doc['cpu_hours'].value != null) { + def hours = 0; + def total_gpus = 0; + if(doc['gres_req.keyword'].value != null) { + def m = /^PER_NODE:gpu:([0-9]+)$/.matcher(doc['gres_req.keyword'].value); + if(m.matches()) { + total_gpus = Integer.parseInt(m.group(1)) * doc['total_nodes'].value + } + } else if(doc['gres_alloc.keyword'].value != null && total_gpus == 0) { + def m = /^gpu:([0-9]+)$/.matcher(doc['gres_alloc.keyword'].value); + if(m.matches()) { + total_gpus = Integer.parseInt(m.group(1)) + } + } + + if (total_gpus == 0) { + hours = doc['cpu_hours'].value + } else { + hours = total_gpus *(doc['cpu_hours'].value/doc['total_cpus'].value); + } + + def cluster = doc['cluster.keyword'].value; + if (params.factors[cluster] != null) { + return hours * params.factors[cluster] + } + } + return 0 +""" + } +}