Commit b02089e9 authored by Azat Khuziyakhmetov's avatar Azat Khuziyakhmetov
Browse files

modified data.py to comply with recent changes

parent 70b1e1ce
#! /usr/bin/env python3
import argparse
import json
import db.getproc
import db.getnode
import db.getjob
import db.metrics
import argparse
import db.aggregator as aggregator
import postexec.exportjobinfo as xjob
import conf.config as conf
from format import format
def format_output(job_id, proc, job, nodes, alloc_cu):
nodenames = list(nodes.keys())
nodes_concat = []
for n in nodenames:
cc = {db.metrics.APInames.NODE_NAME: n, **proc[n], **nodes[n]}
# add allocated cu info
m = db.metrics.metrics_node["alloc_cu"]["apiname"]
if n in alloc_cu:
cc[m] = alloc_cu[n]
nodes_concat.append(cc)
o = {
"job_id": None,
"general": {},
"nodes": []
}
def print_job_info(job_id, type):
aggr = aggregator.get_aggregator(job_id, type)
formatted = format.format(aggr, type)
o["job_id"] = job_id
o["general"] = job
o["nodes"] = nodes_concat
print(json.dumps(formatted))
return o
def print_job_info(job_id):
proc = db.getproc.get_proc_data(job_id)
job, alloc_cu = db.getjob.get_job_data(job_id)
nodenames = list(proc.keys())
nodes = db.getnode.get_node_data(nodenames)
if conf.DEBUG:
print("jobinfo from INFLUXDB and REMOTE: {:s}".format(json.dumps(nodes)))
print("jobinfo from BATCH: {:s}".format(json.dumps(job)))
output = format_output(job_id, proc, job, nodes, alloc_cu)
print(json.dumps(output))
def main():
parser = argparse.ArgumentParser(description="""
Gets the job information required for generating an ASCII report
Gets the job information required for generating ASCII or PDF reports
and outputs it in JSON format.
Optionaly it stores the job info in DB.
""")
""", formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("-s", "--save", help="save batch info of the job in DB",
action="store_true")
parser.add_argument("-t", "--type", help="type of the output",
choices=['ascii', 'pdf'], default="ascii")
parser.add_argument("JOBID",
help="job ID used in the batch system")
......@@ -76,7 +41,7 @@ def main():
print("Job {} was exported".format(job_id))
return 0
print_job_info(job_id)
print_job_info(job_id, args.type)
return 0
......
from .influxdb_fetchjob import get_job_data
from .influxdb_fetchproc import get_proc_data
from .influxdb_fetchnode import get_node_data
from ..data import *
from ..aggrstruct import *
def fetch_all(job_id, type):
data = {}
......
# this script contains the main function format to format the data ready to
# output
from db import data
from db.aggrstruct import *
from .formats_json import OutputSchemes
def get_value(agg, path, **ids):
......@@ -73,14 +73,28 @@ def format_ascii(agg):
return result
def format_pdf(agg):
scheme = OutputSchemes.ascii
result = {}
result = format_scheme(agg, scheme)
result = format_acsii_nonstd(agg, result)
return result
def format(agg, type="ascii"):
if type(agg) is not Aggregator:
if not isinstance(agg, Aggregator):
raise RuntimeError("No aggregator in the format method")
assert type in ["ascii", "pdf"]
if type == "ascii":
format_ascii(agg)
formatted = format_ascii(agg)
elif type == "pdf":
format_pdf(agg)
formatted = format_pdf(agg)
return formatted
def format_acsii_nonstd(agg, result):
# TODO: format alloc_cu
......
......@@ -6,8 +6,8 @@ from datetime import datetime
from io import StringIO
import requests
from requests.auth import HTTPBasicAuth
from db import common
from db.metrics import MType
from db.influx import common
from db.influx.metrics import MType
import conf.config as conf
import conf.influxdb as confdb
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment